package circuit_sys import ( "github.com/yohamta/donburi/filter" "joylink.club/ecs" "joylink.club/rtsssimulation/component" ) type Signal3XH1System struct { query *ecs.Query } func NewSignal3XH1System() *Signal3XH1System { return &Signal3XH1System{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType, component.Signal3XH1FilamentType))} } // Update world 执行 func (s *Signal3XH1System) Update(w ecs.World) { s.query.Each(w, func(e *ecs.Entry) { signal3XH1State := component.Signal3XH1ElectronicType.Get(e) filament := component.Signal3XH1FilamentType.Get(e) // s.calculateU(signal3XH1State, filament) s.calculateL(signal3XH1State, filament) s.calculateH(signal3XH1State, filament) s.calculateDJ(signal3XH1State, filament) s.calculate2DJ(signal3XH1State, filament) }) } // 黄灯点灯电路 // 开放引导信号,黄灯亮且红灯亮 // 开放列车信号且开通侧向,只黄灯亮 func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) { 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) //引导信号 isY := !ddj.Val && !lxj.Val && dj.Val && yxj.Val //侧向行车信号 isLC := !ddj.Val && lxj.Val && !zxj.Val filament.U = filament.Uf && (isY || isLC) } // 绿灯点灯电路 // 开放正线行车信号,只亮绿灯 func (s *Signal3XH1System) calculateL(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) isL := !ddj.Val && lxj.Val && zxj.Val filament.L = filament.Lf && isL } // 红灯点灯电路 // 列车信号禁止时,亮红灯 func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) isH := !ddj.Val && !lxj.Val filament.H = filament.Hf && isH } // DJ 灯丝继电器电路 func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) { ddj := component.BitStateType.Get(state.Z3XH1_DDJ) lxj := component.BitStateType.Get(state.Z3XH1_LXJ) dj := component.BitStateType.Get(state.Z3XH1_DJ) zxj := component.BitStateType.Get(state.Z3XH1_ZXJ) _DJ := dj.Val isDj := filament.Lf && !ddj.Val && lxj.Val && zxj.Val || filament.Uf && !ddj.Val && lxj.Val && !zxj.Val || filament.Hf && !ddj.Val && !lxj.Val //通知继电器进行动作 if _DJ != isDj { drive := component.RelayDriveType.Get(state.Z3XH1_DJ) drive.Td = isDj drive.Xq = isDj } } // 2DJ 灯丝继电器电路 func (s *Signal3XH1System) calculate2DJ(state *component.Signal3XH1Electronic, filament *component.Signal3XH1Filament) { 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) edj := component.BitStateType.Get(state.Z3XH1_2DJ) _2DJ := edj.Val // is2DJ := filament.Uf && !ddj.Val && !lxj.Val && dj.Val && yxj.Val //通知继电器进行动作 if _2DJ != is2DJ { drive := component.RelayDriveType.Get(state.Z3XH1_2DJ) drive.Td = is2DJ drive.Xq = is2DJ } }