package circuit_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" ) type Signal2XH1System struct { query *ecs.Query } func NewSignal2XH1System() *Signal2XH1System { return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType))} } // Update world 执行 func (s *Signal2XH1System) Update(w ecs.World) { s.query.Each(w, func(entry *ecs.Entry) { state := component.Signal2XH1ElectronicType.Get(entry) lsq := component.Signal2XH1LsqType.Get(entry) lsc := component.Signal2XH1LscType.Get(entry) s.calculateLsq(state, lsq) s.calculateL(state) s.calculateH(state) s.calculateDJ(state) s.calculateLsc(state, lsc) }) } // 联锁驱 func (s *Signal2XH1System) calculateLsq(state *component.Signal2XH1Electronic, lsq *component.Signal2XH1Lsq) { ddj := component.RelayDriveType.Get(state.Z2XH1_DDJ) lxj := component.RelayDriveType.Get(state.Z2XH1_LXJ) // ddjQ := lsq.Z2XH1_DDJ_Q ddj.Td = ddjQ ddj.Xq = ddjQ // lxjQ := lsq.Z2XH1_LXJ_Q lxj.Td = lxjQ lxj.Xq = lxjQ } // 联锁采 func (s *Signal2XH1System) calculateLsc(state *component.Signal2XH1Electronic, lsc *component.Signal2XH1Lsc) { ddj := component.BitStateType.Get(state.Z2XH1_DDJ) dj := component.BitStateType.Get(state.Z2XH1_DJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) // lsc.Z2XH1_DDJ_Lx = !ddj.Val lsc.Z2XH1_DJ_Xq = dj.Val lsc.Z2XH1_LXJ_Xq = lxj.Val } func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic) { driveL := component.LightDriveType.Get(state.Z2XH1_L) ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) isL := !ddj.Val && lxj.Val driveL.Td = isL } func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic) { driveH := component.LightDriveType.Get(state.Z2XH1_H) ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) isH := !ddj.Val && !lxj.Val driveH.Td = isH } func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic) { ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) ld := component.BitStateType.Get(state.Z2XH1_L) hd := component.BitStateType.Get(state.Z2XH1_H) isDJ := !ddj.Val && lxj.Val && ld.Val || !ddj.Val && !lxj.Val && hd.Val //通知继电器进行动作 drive := component.RelayDriveType.Get(state.Z2XH1_DJ) drive.Td = isDJ drive.Xq = isDJ }