package circuit_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/entity" ) type Signal3XH1System struct { query *ecs.Query } func NewSignal3XH1System() *Signal3XH1System { return &Signal3XH1System{query: ecs.NewQuery(filter.Contains( component.Signal3XH1ElectronicType, component.Signal3XH1LsqType, component.Signal3XH1LscType, component.SignalLightsType))} } // Update world 执行 func (s *Signal3XH1System) Update(w ecs.World) { wd := entity.GetWorldData(w) s.query.Each(w, func(entry *ecs.Entry) { circuit := component.Signal3XH1ElectronicType.Get(entry) excite3xh1ByCiDrive(circuit, wd) //lsq := component.Signal3XH1LsqType.Get(entry) //lsc := component.Signal3XH1LscType.Get(entry) lights := component.SignalLightsType.Get(entry) Z3XH1_L := lights.GetLightByTag(component.LdTag) Z3XH1_H := lights.GetLightByTag(component.HdTag) Z3XH1_U := lights.GetLightByTag(component.UdTag) //s.calculateLsq(circuit, lsq) s.calculateU(circuit, Z3XH1_U) s.calculateL(circuit, Z3XH1_L) s.calculateH(circuit, Z3XH1_H) s.calculateDJ(circuit, Z3XH1_H, Z3XH1_L, Z3XH1_U) s.calculate2DJ(circuit, Z3XH1_U) //s.calculateLsc(circuit, lsc) }) } func excite3xh1ByCiDrive(circuit *component.Signal3XH1Electronic, wd *component.WorldData) { bit, err := wd.QueryQdBit(component.UidType.Get(circuit.Z3XH1_DDJ).Id) if err == nil { component.RelayDriveType.Get(circuit.Z3XH1_DDJ).Td = bit } bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH1_LXJ).Id) if err == nil { component.RelayDriveType.Get(circuit.Z3XH1_LXJ).Td = bit } bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH1_ZXJ).Id) if err == nil { component.RelayDriveType.Get(circuit.Z3XH1_ZXJ).Td = bit } bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH1_YXJ).Id) if err == nil { component.RelayDriveType.Get(circuit.Z3XH1_YXJ).Td = bit } } // 联锁驱 func (s *Signal3XH1System) calculateLsq(state *component.Signal3XH1Electronic, lsq *component.Signal3XH1Lsq) { ddj := component.RelayDriveType.Get(state.Z3XH1_DDJ) lxj := component.RelayDriveType.Get(state.Z3XH1_LXJ) zxj := component.RelayDriveType.Get(state.Z3XH1_ZXJ) yxj := component.RelayDriveType.Get(state.Z3XH1_YXJ) // ddjQ := lsq.Z3XH1_DDJ_Q ddj.Td = ddjQ ddj.Xq = ddjQ // lxjQ := lsq.Z3XH1_LXJ_Q lxj.Td = lxjQ lxj.Xq = lxjQ // zxjQ := lsq.Z3XH1_ZXJ_Q zxj.Td = zxjQ zxj.Xq = zxjQ // yxjQ := lsq.Z3XH1_YXJ_Q yxj.Td = yxjQ yxj.Xq = yxjQ } // 联锁采 func (s *Signal3XH1System) calculateLsc(state *component.Signal3XH1Electronic, lsc *component.Signal3XH1Lsc) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) dj := component.BitStateType.Get(state.Z3XH1_DJ) edj := component.BitStateType.Get(state.Z3XH1_2DJ) yxj := component.BitStateType.Get(state.Z3XH1_YXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) // lsc.Z3XH1_2DJ_Xq = edj.Val lsc.Z3XH1_DJ_Xq = dj.Val lsc.Z3XH1_DDJ_Lx = !ddj.Val lsc.Z3XH1_LXJ_Xq = lxj.Val lsc.Z3XH1_YXJ_Xq = yxj.Val lsc.Z3XH1_ZXJ_Xq = zxj.Val } // 黄灯点灯电路 // 开放引导信号,黄灯亮且红灯亮 // 开放列车信号且开通侧向,只黄灯亮 func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic, Z3XH1_U *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) dj := component.BitStateType.Get(state.Z3XH1_DJ) yxj := component.BitStateType.Get(state.Z3XH1_YXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) driveU := component.LightDriveType.Get(Z3XH1_U) //引导信号 isY := !ddj.Val && !lxj.Val && dj.Val && yxj.Val //侧向行车信号 isLC := !ddj.Val && lxj.Val && !zxj.Val isU := isY || isLC driveU.Td = isU } // 绿灯点灯电路 // 开放正线行车信号,只亮绿灯 func (s *Signal3XH1System) calculateL(state *component.Signal3XH1Electronic, Z3XH1_L *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) driveL := component.LightDriveType.Get(Z3XH1_L) isL := !ddj.Val && lxj.Val && zxj.Val driveL.Td = isL } // 红灯点灯电路 // 列车信号禁止时,亮红灯 func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic, Z3XH1_H *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) driveH := component.LightDriveType.Get(Z3XH1_H) isH := !ddj.Val && !lxj.Val driveH.Td = isH } // DJ 灯丝继电器电路 func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic, Z3XH1_H *ecs.Entry, Z3XH1_L *ecs.Entry, Z3XH1_U *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) ld := component.BitStateType.Get(Z3XH1_L) hd := component.BitStateType.Get(Z3XH1_H) ud := component.BitStateType.Get(Z3XH1_U) isDj := ld.Val && !ddj.Val && lxj.Val && zxj.Val || //绿灯亮 ud.Val && !ddj.Val && lxj.Val && !zxj.Val || //黄灯亮 hd.Val && !ddj.Val && !lxj.Val //红灯亮 //通知继电器进行动作 drive := component.RelayDriveType.Get(state.Z3XH1_DJ) drive.Td = isDj drive.Xq = isDj } // 2DJ 灯丝继电器电路 func (s *Signal3XH1System) calculate2DJ(state *component.Signal3XH1Electronic, Z3XH1_U *ecs.Entry) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) dj := component.BitStateType.Get(state.Z3XH1_DJ) yxj := component.BitStateType.Get(state.Z3XH1_YXJ) ud := component.BitStateType.Get(Z3XH1_U) // is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val //通知继电器进行动作 drive := component.RelayDriveType.Get(state.Z3XH1_2DJ) drive.Td = is2DJ drive.Xq = is2DJ }