diff --git a/entity/loader.go b/entity/loader.go index edc6ad7..706ce8f 100644 --- a/entity/loader.go +++ b/entity/loader.go @@ -4,19 +4,33 @@ import ( "joylink.club/ecs" "joylink.club/rtsssimulation/component/singleton" "joylink.club/rtsssimulation/modelrepo" - "joylink.club/rtsssimulation/modelrepo/model" ) // 加载城轨仿真实体 func Loading(w ecs.World, repo modelrepo.Repo) error { singleton.LoadSingletons(w, repo) + err := loadTrackside(w, repo) + if err != nil { + return err + } + return nil +} + +// 加载轨旁设备实体 +func loadTrackside(w ecs.World, repo modelrepo.Repo) error { for _, s := range repo.GetEcses() { // 加载道岔 - loadPoints(w, s.GetTurnouts()) + for _, p := range s.GetTurnouts() { + NewPoints(w, p) + } // 加载继电器 - loadRelays(w, s.GetRelays()) + for _, r := range s.GetRelays() { + NewRelay(w, r) + } // 加载断相保护器 - loadDbqs(w, s.GetDbqs()) + for _, d := range s.GetDbqs() { + NewDbq(w, d) + } // 加载联锁驱采卡 qckEntry, err := loadCiQck(w, s) if err != nil { @@ -30,21 +44,3 @@ func Loading(w ecs.World, repo modelrepo.Repo) error { } return nil } - -func loadDbqs(w ecs.World, dbqs []model.Dbq) { - for _, d := range dbqs { - NewDbq(w, d) - } -} - -func loadRelays(w ecs.World, relays []model.Relay) { - for _, r := range relays { - NewRelay(w, r) - } -} - -func loadPoints(w ecs.World, points []model.Points) { - for _, p := range points { - NewPoints(w, p) - } -} diff --git a/sys/circuit_sys/psd.go b/sys/circuit_sys/psd.go index 88a47d7..170bd59 100644 --- a/sys/circuit_sys/psd.go +++ b/sys/circuit_sys/psd.go @@ -1,9 +1,10 @@ package circuit_sys // import ( -// "joylink.club/rtsssimulation/repository/model/proto" // "strings" +// "joylink.club/rtsssimulation/repository/model/proto" + // "joylink.club/ecs" // "joylink.club/ecs/filter" // "joylink.club/rtsssimulation/component" @@ -20,104 +21,104 @@ package circuit_sys // } // } -func (p *PsdSys) Update(world ecs.World) { - worldData := entity.GetWorldData(world) - p.query.Each(world, func(entry *ecs.Entry) { - psc := component.PscType.Get(entry) - //更新屏蔽门电路及PSC相关状态 - asdList := component.AsdListType.Get(entry) - psdState := component.PsdStateType.Get(entry) - if entry.HasComponent(component.PsdCircuitType) { //有屏蔽门电路 - psdCircuit := component.PsdCircuitType.Get(entry) - //屏蔽门驱动 - 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 - } +// func (p *PsdSys) Update(world ecs.World) { +// worldData := entity.GetWorldData(world) +// p.query.Each(world, func(entry *ecs.Entry) { +// psc := component.PscType.Get(entry) +// //更新屏蔽门电路及PSC相关状态 +// asdList := component.AsdListType.Get(entry) +// psdState := component.PsdStateType.Get(entry) +// if entry.HasComponent(component.PsdCircuitType) { //有屏蔽门电路 +// psdCircuit := component.PsdCircuitType.Get(entry) +// //屏蔽门驱动 +// 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.MPLJ != nil { - p.driveMPLJ(world, psdCircuit, component.UidType.Get(entry)) - psc.InterlockMPL = component.BitStateType.Get(psdCircuit.MPLJ).Val - } - //间隙探测驱动 - if psdCircuit.QDTCJ != nil && psdCircuit.TZTCJ != nil { - p.exciteQDTCJ(worldData, psdCircuit) - p.exciteTZTCJ(worldData, psdCircuit) - psc.QDTC = component.BitStateType.Get(psdCircuit.QDTCJ).Val - psc.TZTC = component.BitStateType.Get(psdCircuit.TZTCJ).Val - } - //间隙探测 - if psdCircuit.ZAWJ != nil { - p.exciteZAWJ(psdCircuit, asdList) - psdState.Obstacle = component.BitStateType.Get(psdCircuit.ZAWJ).Val - } - } else { - psdState.Close = p.isAllAsdMotorClosed(asdList) - } - //更新站台门控箱电路及PSC相关状态 - 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 - } - } - if pmc.PCBJ != nil { - component.RelayDriveType.Get(pmc.PCBJ).Td = pcbTd - psc.MkxGM = component.BitStateType.Get(pmc.PCBJ).Val - } - 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 - } - } - //设置滑动门电机通断电状态 - repo := entity.GetWorldData(world).Repo - psd := repo.FindPsd(component.UidType.Get(entry).Id) - if psc.MkxKM { //优先门控箱的开门 - p.allKm(asdList) - } else if psc.MkxGM { //其次门控箱的关门 - p.gm(asdList) - } else if !psc.InterlockMPL { //联锁操作没有被旁路 - 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) - } - } - } - } - }) -} +// if psdCircuit.MGJ != nil { +// p.driveMGJ(psdCircuit, asdList) +// psdState.Close = component.BitStateType.Get(psdCircuit.MGJ).Val +// } +// if psdCircuit.MPLJ != nil { +// p.driveMPLJ(world, psdCircuit, component.UidType.Get(entry)) +// psc.InterlockMPL = component.BitStateType.Get(psdCircuit.MPLJ).Val +// } +// //间隙探测驱动 +// if psdCircuit.QDTCJ != nil && psdCircuit.TZTCJ != nil { +// p.exciteQDTCJ(worldData, psdCircuit) +// p.exciteTZTCJ(worldData, psdCircuit) +// psc.QDTC = component.BitStateType.Get(psdCircuit.QDTCJ).Val +// psc.TZTC = component.BitStateType.Get(psdCircuit.TZTCJ).Val +// } +// //间隙探测 +// if psdCircuit.ZAWJ != nil { +// p.exciteZAWJ(psdCircuit, asdList) +// psdState.Obstacle = component.BitStateType.Get(psdCircuit.ZAWJ).Val +// } +// } else { +// psdState.Close = p.isAllAsdMotorClosed(asdList) +// } +// //更新站台门控箱电路及PSC相关状态 +// 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 +// } +// } +// if pmc.PCBJ != nil { +// component.RelayDriveType.Get(pmc.PCBJ).Td = pcbTd +// psc.MkxGM = component.BitStateType.Get(pmc.PCBJ).Val +// } +// 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 +// } +// } +// //设置滑动门电机通断电状态 +// repo := entity.GetWorldData(world).Repo +// psd := repo.FindPsd(component.UidType.Get(entry).Id) +// if psc.MkxKM { //优先门控箱的开门 +// p.allKm(asdList) +// } else if psc.MkxGM { //其次门控箱的关门 +// p.gm(asdList) +// } else if !psc.InterlockMPL { //联锁操作没有被旁路 +// 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 (p *PsdSys) km(start int32, end int32, asdList *component.AsdList) { // for i := start - 1; i < end; i++ { @@ -141,51 +142,51 @@ func (p *PsdSys) Update(world ecs.World) { // } // } -func (p *PsdSys) driveGMJ(data *component.WorldData, circuit *component.PsdCircuit) { - 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) driveGMJ(data *component.WorldData, circuit *component.PsdCircuit) { +// 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 - } - 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) driveKMJ(data *component.WorldData, circuit *component.PsdCircuit, kmj *ecs.Entry) { +// 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) driveMGJ(psdCircuit *component.PsdCircuit, asdList *component.AsdList) { +// component.RelayDriveType.Get(psdCircuit.MGJ).Td = p.isAllAsdMotorClosed(asdList) +// } // // 是否所有滑动门电机都是关闭状态(继电器表示) // func (p *PsdSys) isAllAsdMotorClosed(asdList *component.AsdList) bool { @@ -198,11 +199,11 @@ func (p *PsdSys) driveMGJ(psdCircuit *component.PsdCircuit, asdList *component.A // return true // } -func (p *PsdSys) driveMPLJ(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() +// func (p *PsdSys) driveMPLJ(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(), "上行") { @@ -238,30 +239,30 @@ func (p *PsdSys) driveMPLJ(world ecs.World, circuit *component.PsdCircuit, uid * // } // } -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) 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 - } -} +// 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 +// } +// }