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) s.calculateL(state) s.calculateH(state) s.calculateDJ(state) }) } 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 }