package circuit_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" ) type Signal3XH1System struct { query *ecs.Query } func NewSignal3XH1System() *Signal3XH1System { return &Signal3XH1System{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType))} } // Update world 执行 func (s *Signal3XH1System) Update(w ecs.World) { s.query.Each(w, func(e *ecs.Entry) { signal3XH1State := component.Signal3XH1ElectronicType.Get(e) // s.calculateU(signal3XH1State) s.calculateL(signal3XH1State) s.calculateH(signal3XH1State) s.calculateDJ(signal3XH1State) s.calculate2DJ(signal3XH1State) }) } // 黄灯点灯电路 // 开放引导信号,黄灯亮且红灯亮 // 开放列车信号且开通侧向,只黄灯亮 func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic) { 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(state.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) { 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(state.Z3XH1_L) isL := !ddj.Val && lxj.Val && zxj.Val driveL.Td = isL } // 红灯点灯电路 // 列车信号禁止时,亮红灯 func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) driveH := component.LightDriveType.Get(state.Z3XH1_H) isH := !ddj.Val && !lxj.Val driveH.Td = isH } // DJ 灯丝继电器电路 func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic) { 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(state.Z3XH1_L) hd := component.BitStateType.Get(state.Z3XH1_H) ud := component.BitStateType.Get(state.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) { 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(state.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 }