2023-10-12 17:55:40 +08:00
|
|
|
package circuit_sys
|
|
|
|
|
|
|
|
import (
|
2023-12-08 18:03:12 +08:00
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
2023-12-06 16:43:29 +08:00
|
|
|
"strings"
|
|
|
|
|
2023-10-12 17:55:40 +08:00
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/ecs/filter"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
2023-11-01 16:52:03 +08:00
|
|
|
"joylink.club/rtsssimulation/entity"
|
2023-10-12 17:55:40 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type PsdSys struct {
|
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPsdSys() *PsdSys {
|
|
|
|
return &PsdSys{
|
2023-11-01 16:52:03 +08:00
|
|
|
query: ecs.NewQuery(filter.Contains(entity.PsdBaseComponentTypeArr...)),
|
2023-10-12 17:55:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PsdSys) Update(world ecs.World) {
|
2023-11-09 10:53:18 +08:00
|
|
|
worldData := entity.GetWorldData(world)
|
2023-10-12 17:55:40 +08:00
|
|
|
p.query.Each(world, func(entry *ecs.Entry) {
|
2023-11-01 16:52:03 +08:00
|
|
|
psc := component.PscType.Get(entry)
|
|
|
|
//更新屏蔽门电路及PSC相关状态
|
|
|
|
asdList := component.AsdListType.Get(entry)
|
2023-11-09 10:53:18 +08:00
|
|
|
psdState := component.PsdStateType.Get(entry)
|
2023-10-20 16:12:42 +08:00
|
|
|
if entry.HasComponent(component.PsdCircuitType) { //有屏蔽门电路
|
|
|
|
psdCircuit := component.PsdCircuitType.Get(entry)
|
2023-11-09 14:38:35 +08:00
|
|
|
//屏蔽门驱动
|
2023-12-08 16:46:49 +08:00
|
|
|
if psdCircuit.GMJ != nil {
|
2023-11-09 10:53:18 +08:00
|
|
|
p.exciteGMJ(worldData, psdCircuit)
|
2023-11-09 14:38:35 +08:00
|
|
|
psc.InterlockGM = component.BitStateType.Get(psdCircuit.GMJ).Val
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-12-08 16:46:49 +08:00
|
|
|
for group, kmj := range psdCircuit.KMJMap {
|
|
|
|
p.exciteKMJ(worldData, psdCircuit, kmj)
|
|
|
|
psc.InterlockKmGroup[group] = component.BitStateType.Get(kmj).Val
|
|
|
|
}
|
|
|
|
|
2023-11-01 16:52:03 +08:00
|
|
|
if psdCircuit.MGJ != nil {
|
|
|
|
p.exciteMGJ(psdCircuit, asdList)
|
2023-11-09 10:53:18 +08:00
|
|
|
psdState.Close = component.BitStateType.Get(psdCircuit.MGJ).Val
|
|
|
|
}
|
|
|
|
if psdCircuit.MPLJ != nil {
|
|
|
|
p.exciteMPLJ(world, psdCircuit, component.UidType.Get(entry))
|
|
|
|
psc.InterlockMPL = component.BitStateType.Get(psdCircuit.MPLJ).Val
|
|
|
|
}
|
2023-11-09 14:38:35 +08:00
|
|
|
//间隙探测
|
|
|
|
if psdCircuit.QDTCJ != nil && psdCircuit.TZTCJ != nil {
|
2023-11-09 10:53:18 +08:00
|
|
|
p.exciteQDTCJ(worldData, psdCircuit)
|
|
|
|
p.exciteTZTCJ(worldData, psdCircuit)
|
2023-11-09 14:38:35 +08:00
|
|
|
psc.QDTC = component.BitStateType.Get(psdCircuit.QDTCJ).Val
|
2023-11-09 10:53:18 +08:00
|
|
|
psc.TZTC = component.BitStateType.Get(psdCircuit.TZTCJ).Val
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
psdState.Close = p.isAllAsdMotorClosed(asdList)
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
|
|
|
//更新站台门控箱电路及PSC相关状态
|
2023-12-07 16:13:34 +08:00
|
|
|
if entry.HasComponent(component.PlatformMkxCircuitType) {
|
|
|
|
pmc := component.PlatformMkxCircuitType.Get(entry)
|
|
|
|
var pcbTd bool
|
|
|
|
var pobTd bool
|
|
|
|
var pabTd bool
|
|
|
|
for _, mkxEntry := range pmc.MkxList {
|
|
|
|
mkx := component.MkxType.Get(mkxEntry)
|
|
|
|
if mkx.PCB != nil && component.BitStateType.Get(mkx.PCB).Val {
|
|
|
|
pcbTd = true
|
|
|
|
}
|
|
|
|
if mkx.POB != nil && component.BitStateType.Get(mkx.POB).Val {
|
|
|
|
pobTd = true
|
|
|
|
}
|
|
|
|
if mkx.PAB != nil && component.BitStateType.Get(mkx.PAB).Val {
|
|
|
|
pabTd = true
|
|
|
|
}
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-12-07 16:13:34 +08:00
|
|
|
if pmc.PCBJ != nil {
|
|
|
|
component.RelayDriveType.Get(pmc.PCBJ).Td = pcbTd
|
|
|
|
psc.MkxGM = component.BitStateType.Get(pmc.PCBJ).Val
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-12-07 16:13:34 +08:00
|
|
|
if pmc.POBJ != nil {
|
|
|
|
component.RelayDriveType.Get(pmc.POBJ).Td = pobTd
|
|
|
|
psc.MkxKM = component.BitStateType.Get(pmc.POBJ).Val
|
|
|
|
}
|
|
|
|
if pmc.PABJ != nil {
|
|
|
|
component.RelayDriveType.Get(pmc.PABJ).Td = pabTd
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//设置滑动门电机通断电状态
|
|
|
|
repo := entity.GetWorldData(world).Repo
|
|
|
|
psd := repo.FindPsd(component.UidType.Get(entry).Id)
|
2023-11-06 13:53:59 +08:00
|
|
|
if psc.MkxKM { //优先门控箱的开门
|
2023-12-08 18:03:12 +08:00
|
|
|
p.allKm(asdList)
|
2023-12-07 16:09:04 +08:00
|
|
|
} else if psc.MkxGM { //其次门控箱的关门
|
2023-11-06 13:53:59 +08:00
|
|
|
p.gm(asdList)
|
2023-11-01 16:52:03 +08:00
|
|
|
} else if !psc.InterlockMPL { //联锁操作没有被旁路
|
|
|
|
if psc.InterlockGM {
|
|
|
|
p.gm(asdList)
|
2023-12-08 16:46:49 +08:00
|
|
|
} else {
|
|
|
|
for group, km := range psc.InterlockKmGroup {
|
|
|
|
if km {
|
2023-12-08 18:03:12 +08:00
|
|
|
var asdGroup *proto.AsdGroup
|
|
|
|
if group == 0 {
|
|
|
|
asdGroup = psd.FindFirstAsdGroup()
|
|
|
|
} else {
|
|
|
|
asdGroup = psd.FindAsdGroup(group)
|
|
|
|
}
|
2023-12-08 16:46:49 +08:00
|
|
|
p.km(asdGroup.Start, asdGroup.End, asdList)
|
|
|
|
}
|
|
|
|
}
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-10-20 16:12:42 +08:00
|
|
|
}
|
2023-10-12 17:55:40 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-11-01 16:52:03 +08:00
|
|
|
func (p *PsdSys) km(start int32, end int32, asdList *component.AsdList) {
|
2023-11-02 15:49:52 +08:00
|
|
|
for i := start - 1; i < end; i++ {
|
2023-11-01 16:52:03 +08:00
|
|
|
asd := asdList.List[i]
|
|
|
|
component.AsdMotorStateType.Get(asd).TD = true
|
|
|
|
component.AsdMotorStateType.Get(asd).KM = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 18:03:12 +08:00
|
|
|
func (p *PsdSys) allKm(asdList *component.AsdList) {
|
|
|
|
for _, asd := range asdList.List {
|
|
|
|
component.AsdMotorStateType.Get(asd).TD = true
|
|
|
|
component.AsdMotorStateType.Get(asd).KM = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 16:52:03 +08:00
|
|
|
func (p *PsdSys) gm(asdList *component.AsdList) {
|
|
|
|
for _, asd := range asdList.List {
|
|
|
|
component.AsdMotorStateType.Get(asd).TD = true
|
|
|
|
component.AsdMotorStateType.Get(asd).KM = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-09 10:53:18 +08:00
|
|
|
func (p *PsdSys) exciteGMJ(data *component.WorldData, circuit *component.PsdCircuit) {
|
2023-11-09 14:38:35 +08:00
|
|
|
bit, err := data.QueryQdBit(component.UidType.Get(circuit.GMJ).Id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-11-09 10:53:18 +08:00
|
|
|
if bit { //驱动
|
|
|
|
component.RelayDriveType.Get(circuit.GMJ).Td = true
|
2023-12-08 16:46:49 +08:00
|
|
|
} 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
|
|
|
|
}
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-12-08 16:46:49 +08:00
|
|
|
//自保持
|
|
|
|
component.RelayDriveType.Get(circuit.GMJ).Td = true
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-10-20 16:12:42 +08:00
|
|
|
}
|
|
|
|
|
2023-12-08 16:46:49 +08:00
|
|
|
func (p *PsdSys) exciteKMJ(data *component.WorldData, circuit *component.PsdCircuit, kmj *ecs.Entry) {
|
|
|
|
bit, err := data.QueryQdBit(component.UidType.Get(kmj).Id)
|
2023-11-09 14:38:35 +08:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-11-09 10:53:18 +08:00
|
|
|
if bit { //驱动
|
2023-12-08 16:46:49 +08:00
|
|
|
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
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-12-08 16:46:49 +08:00
|
|
|
for _, entry := range circuit.KMJMap {
|
|
|
|
if entry != kmj && component.BitStateType.Get(entry).Val {
|
|
|
|
component.RelayDriveType.Get(kmj).Td = false
|
|
|
|
return
|
|
|
|
}
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-12-08 16:46:49 +08:00
|
|
|
//自保持
|
|
|
|
component.RelayDriveType.Get(kmj).Td = true
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
2023-10-12 17:55:40 +08:00
|
|
|
}
|
|
|
|
|
2023-11-01 16:52:03 +08:00
|
|
|
func (p *PsdSys) exciteMGJ(psdCircuit *component.PsdCircuit, asdList *component.AsdList) {
|
2023-11-09 10:53:18 +08:00
|
|
|
component.BitStateType.Get(psdCircuit.MGJ).Val = p.isAllAsdMotorClosed(asdList)
|
2023-10-13 18:20:15 +08:00
|
|
|
}
|
|
|
|
|
2023-11-09 10:53:18 +08:00
|
|
|
// 是否所有滑动门电机都是关闭状态(继电器表示)
|
|
|
|
func (p *PsdSys) isAllAsdMotorClosed(asdList *component.AsdList) bool {
|
2023-11-01 16:52:03 +08:00
|
|
|
for _, asdEntry := range asdList.List {
|
2023-11-09 10:53:18 +08:00
|
|
|
asdMotor := component.AsdMotorStateType.Get(asdEntry)
|
|
|
|
if !asdMotor.MG {
|
|
|
|
return false
|
2023-11-01 16:52:03 +08:00
|
|
|
}
|
|
|
|
}
|
2023-11-09 10:53:18 +08:00
|
|
|
return true
|
2023-10-13 18:20:15 +08:00
|
|
|
}
|
|
|
|
|
2023-11-01 16:52:03 +08:00
|
|
|
func (p *PsdSys) exciteMPLJ(world ecs.World, circuit *component.PsdCircuit, uid *component.Uid) {
|
|
|
|
data := entity.GetWorldData(world)
|
|
|
|
psd := data.Repo.FindPsd(uid.Id)
|
|
|
|
platform := psd.Platform()
|
|
|
|
station := platform.Station()
|
|
|
|
|
|
|
|
var buttonCode string
|
|
|
|
if strings.Contains(platform.Code(), "上行") {
|
|
|
|
buttonCode = "S旁路"
|
|
|
|
} else if strings.Contains(platform.Code(), "下行") {
|
|
|
|
buttonCode = "X旁路"
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
}
|
2023-12-06 16:43:29 +08:00
|
|
|
for _, button := range station.SpksButtons() {
|
2023-11-01 16:52:03 +08:00
|
|
|
if button.Code() != buttonCode {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
btnEntry, ok := entity.GetEntityByUid(world, button.Id())
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
component.RelayDriveType.Get(circuit.MPLJ).Td = component.BitStateType.Get(btnEntry).Val
|
|
|
|
}
|
2023-10-12 17:55:40 +08:00
|
|
|
}
|
2023-11-09 10:53:18 +08:00
|
|
|
|
|
|
|
func (p *PsdSys) exciteQDTCJ(data *component.WorldData, circuit *component.PsdCircuit) {
|
2023-11-09 14:38:35 +08:00
|
|
|
bit, err := data.QueryQdBit(component.UidType.Get(circuit.QDTCJ).Id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-11-09 10:53:18 +08:00
|
|
|
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) {
|
2023-11-09 14:38:35 +08:00
|
|
|
bit, err := data.QueryQdBit(component.UidType.Get(circuit.TZTCJ).Id)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-11-09 10:53:18 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|