291 lines
8.6 KiB
Go
291 lines
8.6 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
)
|
|
|
|
type PsdSys struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewPsdSys() *PsdSys {
|
|
return &PsdSys{
|
|
query: ecs.NewQuery(filter.Contains(entity.PsdBaseComponentTypeArr...)),
|
|
}
|
|
}
|
|
|
|
func (p *PsdSys) Update(world ecs.World) {
|
|
worldData := entity.GetWorldData(world)
|
|
p.query.Each(world, func(entry *ecs.Entry) {
|
|
psc := component.PscType.Get(entry)
|
|
var psdCircuit *component.PsdCircuit
|
|
if entry.HasComponent(component.PsdCircuitType) {
|
|
psdCircuit = component.PsdCircuitType.Get(entry)
|
|
}
|
|
var mkx *component.Mkx
|
|
if entry.HasComponent(component.PlatformMkxCircuitType) {
|
|
pmc := component.PlatformMkxCircuitType.Get(entry)
|
|
if len(pmc.MkxList) > 0 {
|
|
mkx = component.MkxType.Get(pmc.MkxList[0])
|
|
}
|
|
}
|
|
asdList := component.AsdListType.Get(entry)
|
|
psdState := component.PsdStateType.Get(entry)
|
|
//更新站台门控箱继电器状态
|
|
if mkx != nil {
|
|
pmc := component.PlatformMkxCircuitType.Get(entry)
|
|
mkxBtnDriveRelay(mkx, pmc, psdCircuit)
|
|
}
|
|
//更新屏蔽门电路及PSC相关状态
|
|
if psdCircuit != nil { //有屏蔽门电路
|
|
//屏蔽门关门
|
|
if psdCircuit.GMJ != nil {
|
|
p.driveGMJ(worldData, psdCircuit)
|
|
psc.InterlockGM = component.BitStateType.Get(psdCircuit.GMJ).Val
|
|
}
|
|
//屏蔽门开门
|
|
for group, kmj := range psdCircuit.KMJMap {
|
|
p.driveKMJ(worldData, psdCircuit, kmj)
|
|
psc.InterlockKmGroup[group] = component.BitStateType.Get(kmj).Val
|
|
}
|
|
//屏蔽门关
|
|
if psdCircuit.MGJ != nil {
|
|
p.driveMGJ(psdCircuit, asdList)
|
|
psdState.Close = component.BitStateType.Get(psdCircuit.MGJ).Val
|
|
}
|
|
//间隙探测驱动
|
|
if psdCircuit.QDTCJ != nil && psdCircuit.TZTCJ != nil {
|
|
p.exciteQDTCJ(worldData, psdCircuit)
|
|
p.exciteTZTCJ(worldData, psdCircuit)
|
|
}
|
|
//间隙探测
|
|
if psdCircuit.ZAWJ != nil {
|
|
p.exciteZAWJ(psdCircuit, asdList)
|
|
psdState.Obstacle = component.BitStateType.Get(psdCircuit.ZAWJ).Val
|
|
}
|
|
//互锁解除
|
|
if psdCircuit.MPLJ != nil {
|
|
psdState.InterlockRelease = component.BitStateType.Get(psdCircuit.MPLJ).Val
|
|
}
|
|
} else {
|
|
psdState.Close = p.isAllAsdMotorClosed(asdList)
|
|
if mkx != nil {
|
|
psdState.InterlockRelease = component.BitStateType.Get(mkx.MPL).Val
|
|
}
|
|
}
|
|
|
|
//设置滑动门电机通断电状态
|
|
repo := entity.GetWorldData(world).Repo
|
|
psd := repo.FindPsd(component.UidType.Get(entry).Id)
|
|
if psc.InterlockGM {
|
|
p.gm(asdList)
|
|
} else {
|
|
for group, km := range psc.InterlockKmGroup {
|
|
if km {
|
|
var asdGroup *proto.AsdGroup
|
|
if group == 0 {
|
|
asdGroup = psd.FindFirstAsdGroup()
|
|
} else {
|
|
asdGroup = psd.FindAsdGroup(group)
|
|
}
|
|
p.km(asdGroup.Start, asdGroup.End, asdList)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// 门控箱按钮驱动继电器
|
|
func mkxBtnDriveRelay(mkx *component.Mkx, pmc *component.PlatformMkxCircuit, psdCircuit *component.PsdCircuit) {
|
|
//PCB
|
|
if pmc.PCBJ != nil && mkx.PCB != nil {
|
|
pcb := component.BitStateType.Get(mkx.PCB).Val
|
|
pcbpl := false
|
|
if mkx.PCBPL != nil {
|
|
pcbpl = component.BitStateType.Get(mkx.PCBPL).Val
|
|
}
|
|
component.RelayDriveType.Get(pmc.PCBJ).Td = !pcbpl && pcb
|
|
}
|
|
//POB
|
|
if pmc.POBJ != nil && mkx.POB != nil {
|
|
pob := component.BitStateType.Get(mkx.POB).Val
|
|
pobpl := false
|
|
if mkx.POBPL != nil {
|
|
pobpl = component.BitStateType.Get(mkx.POBPL).Val
|
|
}
|
|
component.RelayDriveType.Get(pmc.POBJ).Td = !pobpl && pob
|
|
}
|
|
//PAB
|
|
if pmc.PABJ != nil && mkx.PAB != nil {
|
|
pab := component.BitStateType.Get(mkx.PAB).Val
|
|
pabpl := false
|
|
if mkx.PABPL != nil {
|
|
pabpl = component.BitStateType.Get(mkx.PABPL).Val
|
|
}
|
|
component.RelayDriveType.Get(pmc.PABJ).Td = !pabpl && pab
|
|
}
|
|
//WRZF
|
|
if pmc.WRZFJ != nil && mkx.WRZF != nil {
|
|
wrzf := component.BitStateType.Get(mkx.WRZF).Val
|
|
wrzfpl := false
|
|
if mkx.WRZFPL != nil {
|
|
wrzfpl = component.BitStateType.Get(mkx.WRZFPL).Val
|
|
}
|
|
component.RelayDriveType.Get(pmc.WRZFJ).Td = !wrzfpl && wrzf
|
|
}
|
|
//QKQR
|
|
if pmc.QKQRJ != nil && mkx.QKQR != nil {
|
|
qkqr := component.BitStateType.Get(mkx.QKQR).Val
|
|
qkqrpl := false
|
|
if mkx.QKQRPL != nil {
|
|
qkqrpl = component.BitStateType.Get(mkx.QKQRPL).Val
|
|
}
|
|
component.RelayDriveType.Get(pmc.QKQRJ).Td = !qkqrpl && qkqr
|
|
}
|
|
//MPL
|
|
if psdCircuit != nil && psdCircuit.MPLJ != nil && mkx.MPL != nil {
|
|
component.RelayDriveType.Get(psdCircuit.MPLJ).Td = component.BitStateType.Get(mkx.MPL).Val
|
|
}
|
|
//JXTCPL
|
|
if psdCircuit != nil && psdCircuit.JXTCPLJ != nil && mkx.JXTCPL != nil {
|
|
component.RelayDriveType.Get(psdCircuit.JXTCPLJ).Td = component.BitStateType.Get(mkx.JXTCPL).Val
|
|
}
|
|
}
|
|
|
|
func (p *PsdSys) km(start int32, end int32, asdList *component.AsdList) {
|
|
for i := start - 1; i < end; i++ {
|
|
asd := asdList.List[i]
|
|
component.AsdMotorStateType.Get(asd).TD = true
|
|
component.AsdMotorStateType.Get(asd).KM = true
|
|
}
|
|
}
|
|
|
|
func (p *PsdSys) allKm(asdList *component.AsdList) {
|
|
for _, asd := range asdList.List {
|
|
component.AsdMotorStateType.Get(asd).TD = true
|
|
component.AsdMotorStateType.Get(asd).KM = true
|
|
}
|
|
}
|
|
|
|
func (p *PsdSys) gm(asdList *component.AsdList) {
|
|
for _, asd := range asdList.List {
|
|
component.AsdMotorStateType.Get(asd).TD = true
|
|
component.AsdMotorStateType.Get(asd).KM = false
|
|
}
|
|
}
|
|
|
|
func (p *PsdSys) driveGMJ(data *component.WorldData, circuit *component.PsdCircuit) {
|
|
bit, err := data.QueryQdBit(component.UidType.Get(circuit.GMJ).Id)
|
|
if err != nil {
|
|
return
|
|
}
|
|
component.RelayDriveType.Get(circuit.GMJ).Td = bit
|
|
|
|
//bit, err := data.QueryQdBit(component.UidType.Get(circuit.GMJ).Id)
|
|
//if err != nil {
|
|
// return
|
|
//}
|
|
//if bit { //驱动
|
|
// component.RelayDriveType.Get(circuit.GMJ).Td = true
|
|
//} else if component.BitStateType.Get(circuit.GMJ).Val { //判断自保持
|
|
// for _, entry := range circuit.KMJMap {
|
|
// if component.BitStateType.Get(entry).Val { //无法自保持
|
|
// component.RelayDriveType.Get(circuit.GMJ).Td = false
|
|
// return
|
|
// }
|
|
// }
|
|
// //自保持
|
|
// component.RelayDriveType.Get(circuit.GMJ).Td = true
|
|
//}
|
|
}
|
|
|
|
func (p *PsdSys) driveKMJ(data *component.WorldData, circuit *component.PsdCircuit, kmj *ecs.Entry) {
|
|
bit, err := data.QueryQdBit(component.UidType.Get(kmj).Id)
|
|
if err != nil {
|
|
return
|
|
}
|
|
component.RelayDriveType.Get(kmj).Td = bit
|
|
|
|
//bit, err := data.QueryQdBit(component.UidType.Get(kmj).Id)
|
|
//if err != nil {
|
|
// return
|
|
//}
|
|
//if bit { //驱动
|
|
// component.RelayDriveType.Get(kmj).Td = true
|
|
//} else if component.BitStateType.Get(kmj).Val { //判断自保持
|
|
// if component.BitStateType.Get(circuit.GMJ).Val {
|
|
// component.RelayDriveType.Get(kmj).Td = false
|
|
// return
|
|
// }
|
|
// for _, entry := range circuit.KMJMap {
|
|
// if entry != kmj && component.BitStateType.Get(entry).Val {
|
|
// component.RelayDriveType.Get(kmj).Td = false
|
|
// return
|
|
// }
|
|
// }
|
|
// //自保持
|
|
// component.RelayDriveType.Get(kmj).Td = true
|
|
//}
|
|
}
|
|
|
|
func (p *PsdSys) driveMGJ(psdCircuit *component.PsdCircuit, asdList *component.AsdList) {
|
|
component.RelayDriveType.Get(psdCircuit.MGJ).Td = p.isAllAsdMotorClosed(asdList)
|
|
}
|
|
|
|
// 是否所有滑动门电机都是关闭状态(继电器表示)
|
|
func (p *PsdSys) isAllAsdMotorClosed(asdList *component.AsdList) bool {
|
|
for _, asdEntry := range asdList.List {
|
|
asdMotor := component.AsdMotorStateType.Get(asdEntry)
|
|
if !asdMotor.MG {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (p *PsdSys) exciteQDTCJ(data *component.WorldData, circuit *component.PsdCircuit) {
|
|
bit, err := data.QueryQdBit(component.UidType.Get(circuit.QDTCJ).Id)
|
|
if err != nil {
|
|
return
|
|
}
|
|
qdtcj := component.BitStateType.Get(circuit.QDTCJ)
|
|
tztcj := component.BitStateType.Get(circuit.TZTCJ)
|
|
if bit { //驱动
|
|
component.RelayDriveType.Get(circuit.QDTCJ).Td = true
|
|
} else if qdtcj.Val { //自保持
|
|
component.RelayDriveType.Get(circuit.QDTCJ).Td = !tztcj.Val
|
|
}
|
|
}
|
|
|
|
func (p *PsdSys) exciteTZTCJ(data *component.WorldData, circuit *component.PsdCircuit) {
|
|
bit, err := data.QueryQdBit(component.UidType.Get(circuit.TZTCJ).Id)
|
|
if err != nil {
|
|
return
|
|
}
|
|
tztcj := component.BitStateType.Get(circuit.TZTCJ)
|
|
qdtcj := component.BitStateType.Get(circuit.QDTCJ)
|
|
if bit { //驱动
|
|
component.RelayDriveType.Get(circuit.TZTCJ).Td = true
|
|
} else if tztcj.Val { //自保持
|
|
component.RelayDriveType.Get(circuit.TZTCJ).Td = !qdtcj.Val
|
|
}
|
|
}
|
|
|
|
func (p *PsdSys) exciteZAWJ(circuit *component.PsdCircuit, asdList *component.AsdList) {
|
|
if component.BitStateType.Get(circuit.QDTCJ).Val {
|
|
for _, asd := range asdList.List {
|
|
if asd.HasComponent(component.AsdHasObstacleTag) {
|
|
component.RelayDriveType.Get(circuit.ZAWJ).Td = true
|
|
return
|
|
}
|
|
}
|
|
component.RelayDriveType.Get(circuit.ZAWJ).Td = false
|
|
} else {
|
|
component.RelayDriveType.Get(circuit.ZAWJ).Td = false
|
|
}
|
|
}
|