package circuit_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" ) // ibp 系统 type IBPSys struct { query *ecs.Query } // ibp盘系统 func NewIBPSys() *IBPSys { return &IBPSys{ query: ecs.NewQuery(filter.Contains( component.SpkElectronicType, component.SpkCollectStateType, component.EmpElectronicType, component.EmpCollectStateType, )), } } // 控制电路更新 func (ibp *IBPSys) Update(w ecs.World) { ibp.query.Each(w, func(entry *ecs.Entry) { spkState := component.SpkElectronicType.Get(entry) ibp.spkControl(entry, spkState) ibp.spksState(entry, spkState) ibp.spkCollect(entry, spkState) empState := component.EmpElectronicType.Get(entry) ibp.empControl(entry, empState) ibp.empState(entry, empState) ibp.empCollect(entry, empState) }) } // 人员防护继电器控制电路逻辑 func (ibp *IBPSys) spkControl(entry *ecs.Entry, spkState *component.SpkElectronic) { spksxplaBtn := getBtnVal(spkState.SPKSXPLA_BTN) // spksx1j 通电状态 setRelayTdVal(spkState.SPKSX1J, spksxplaBtn || getBtnVal(spkState.SPKSX1J_KEY)) // spksx3j 通电状态 setRelayTdVal(spkState.SPKSX3J, spksxplaBtn || getBtnVal(spkState.SPKSX3J_KEY)) spkssplaBtn := getBtnVal(spkState.SPKSSPLA_BTN) // spkss2j 通电状态 setRelayTdVal(spkState.SPKSS2J, spkssplaBtn || getBtnVal(spkState.SPKSS2J_KEY)) // spkss4j 通电状态 setRelayTdVal(spkState.SPKSS4J, spkssplaBtn || getBtnVal(spkState.SPKSS4J_KEY)) } // 人员防护表示状态电路逻辑 func (ibp *IBPSys) spksState(entry *ecs.Entry, spkState *component.SpkElectronic) { sda := getBtnVal(spkState.SDA) // SPKSXPLAJ if spkState.SPKSXPLA_BTN.HasComponent(component.SingleLightType) { singleLight := component.SingleLightType.Get(spkState.SPKSXPLA_BTN) spksxplaj := component.RelayDriveType.Get(spkState.SPKSXPLAJ) setLightTdVal(singleLight.Light, sda || spksxplaj.Xq) } // SPKSSPLAJ if spkState.SPKSSPLA_BTN.HasComponent(component.SingleLightType) { singleLight := component.SingleLightType.Get(spkState.SPKSSPLA_BTN) spkssplaj := component.RelayDriveType.Get(spkState.SPKSSPLAJ) setLightTdVal(singleLight.Light, sda || spkssplaj.Xq) } // SPKSX1J spksx1j := component.RelayDriveType.Get(spkState.SPKSX1J) setLightTdVal(spkState.SPKSX1D, sda || !spksx1j.Xq) // SPKSX3J spksx3j := component.RelayDriveType.Get(spkState.SPKSX3J) setLightTdVal(spkState.SPKSX3D, sda || !spksx3j.Xq) // SPKSS2J spkss2j := component.RelayDriveType.Get(spkState.SPKSS2J) setLightTdVal(spkState.SPKSS2D, sda || !spkss2j.Xq) // SPKSS4J spkss4j := component.RelayDriveType.Get(spkState.SPKSS4J) setLightTdVal(spkState.SPKSS4D, sda || !spkss4j.Xq) } // 人员防护继电器采集电路状态逻辑 func (ibp *IBPSys) spkCollect(entry *ecs.Entry, spkState *component.SpkElectronic) { collectState := component.SpkCollectStateType.Get(entry) collectState.SPKSX1J_XQ = getRelayXqVal(spkState.SPKSX1J) collectState.SPKSX3J_XQ = getRelayXqVal(spkState.SPKSX3J) collectState.SPKSS2J_XQ = getRelayXqVal(spkState.SPKSS2J) collectState.SPKSS4J_XQ = getRelayXqVal(spkState.SPKSS4J) collectState.SPKSXPLA_XQ = getRelayXqVal(spkState.SPKSXPLAJ) collectState.SPKSSPLA_XQ = getRelayXqVal(spkState.SPKSSPLAJ) } // 紧急关闭控制电路 func (ibp *IBPSys) empControl(entry *ecs.Entry, s *component.EmpElectronic) { xempfab := getBtnVal(s.XEMPFA_BTN) xempj := component.RelayDriveType.Get(s.XEMPJ) // xempfab接通或者按钮组接通并且xempj继电器吸起状态 xempj.Td = xempfab || (xempj.Xq && getBtnVal(s.EMP1_BTN) && getBtnVal(s.EMP3_BTN) && getBtnVal(s.EMP5_BTN) && getBtnVal(s.EMPX_BTN)) sempfab := getBtnVal(s.SEMPFA_BTN) sempj := component.RelayDriveType.Get(s.SEMPJ) // sempfab接通或者按钮组接通并且sempj继电器吸起状态 sempj.Td = sempfab || (sempj.Xq && getBtnVal(s.EMP2_BTN) && getBtnVal(s.EMP4_BTN) && getBtnVal(s.EMP6_BTN) && getBtnVal(s.EMPS_BTN)) } // 紧急关闭表示电路 func (ibp *IBPSys) empState(entry *ecs.Entry, s *component.EmpElectronic) { sda := getBtnVal(s.SDA) xempj := component.RelayDriveType.Get(s.XEMPJ) setLightTdVal(s.XEMPD, sda || !xempj.Xq) sempj := component.RelayDriveType.Get(s.SEMPJ) setLightTdVal(s.SEMPD, sda || !sempj.Xq) qba := getBtnVal(s.QBA) if qba { setAlarmTdVal(s.Alarm, xempj.Xq && sempj.Xq) } else { setAlarmTdVal(s.Alarm, (!xempj.Xq) || (!sempj.Xq)) } } // 紧急关闭继电器采集电路状态逻辑 func (ibp *IBPSys) empCollect(entry *ecs.Entry, s *component.EmpElectronic) { collectState := component.EmpCollectStateType.Get(entry) collectState.XEMPJ_XQ = getRelayXqVal(s.XEMPJ) collectState.SEMPJ_XQ = getRelayXqVal(s.SEMPJ) } // 获取按钮状态 func getBtnVal(entry *ecs.Entry) bool { btn := component.BitStateType.Get(entry) return btn.Val } // 设置继电器通电状态 func setRelayTdVal(entry *ecs.Entry, val bool) { relay := component.RelayDriveType.Get(entry) relay.Td = val } // 获取继电器吸起状态 func getRelayXqVal(entry *ecs.Entry) bool { relay := component.RelayDriveType.Get(entry) return relay.Xq } // 设置信号灯通电状态 func setLightTdVal(entry *ecs.Entry, val bool) { light := component.LightDriveType.Get(entry) light.Td = val } // 设置蜂鸣器通电状态 func setAlarmTdVal(entry *ecs.Entry, val bool) { fmq := component.AlarmDriveType.Get(entry) fmq.Td = val }