package circuit_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" ) // ibp 系统 type IBPSys struct { empQuery *ecs.Query spksQuery *ecs.Query } // ibp盘系统 func NewIBPSys() *IBPSys { return &IBPSys{ empQuery: ecs.NewQuery(filter.Contains(component.EmpElectronicType)), spksQuery: ecs.NewQuery(filter.Contains(component.SpkElectronicType)), } } // 控制电路更新 func (ibp *IBPSys) Update(w ecs.World) { ibp.empQuery.Each(w, func(entry *ecs.Entry) { empState := component.EmpElectronicType.Get(entry) ibp.empControl(entry, empState) ibp.empState(entry, empState) }) ibp.spksQuery.Each(w, func(entry *ecs.Entry) { spkState := component.SpkElectronicType.Get(entry) ibp.spkControl(entry, spkState) ibp.spksState(entry, spkState) }) } // 人员防护继电器控制电路逻辑 func (ibp *IBPSys) spkControl(entry *ecs.Entry, spkState *component.SpkElectronic) { spksxplaBtn := getIbpBtnVal(spkState.SPKSXPLA_BTN) // spksxplaj setRelayTdVal(spkState.SPKSXPLAJ, spksxplaBtn) // spksx1j 通电状态 setRelayTdVal(spkState.SPKSX1J, getRelayXqVal(spkState.SPKSXPLAJ) || getIbpKeyVal(spkState.SPKSX1J_KEY)) // spksx3j 通电状态 setRelayTdVal(spkState.SPKSX3J, getRelayXqVal(spkState.SPKSXPLAJ) || getIbpKeyVal(spkState.SPKSX3J_KEY)) spkssplaBtn := getIbpBtnVal(spkState.SPKSSPLA_BTN) // spkssplaj setRelayTdVal(spkState.SPKSSPLAJ, spkssplaBtn) // spkss2j 通电状态 setRelayTdVal(spkState.SPKSS2J, getRelayXqVal(spkState.SPKSSPLAJ) || getIbpKeyVal(spkState.SPKSS2J_KEY)) // spkss4j 通电状态 setRelayTdVal(spkState.SPKSS4J, getRelayXqVal(spkState.SPKSSPLAJ) || getIbpKeyVal(spkState.SPKSS4J_KEY)) } // 人员防护表示状态电路逻辑 func (ibp *IBPSys) spksState(entry *ecs.Entry, spkState *component.SpkElectronic) { sda := getIbpBtnVal(spkState.SDA) // SPKSXPLAJ if spkState.SPKSXPLA_BTN.HasComponent(component.SingleLightType) { singleLight := component.SingleLightType.Get(spkState.SPKSXPLA_BTN) setLightTdVal(singleLight.Light, sda || getRelayXqVal(spkState.SPKSXPLAJ)) } // SPKSSPLAJ if spkState.SPKSSPLA_BTN.HasComponent(component.SingleLightType) { singleLight := component.SingleLightType.Get(spkState.SPKSSPLA_BTN) setLightTdVal(singleLight.Light, sda || getRelayXqVal(spkState.SPKSSPLAJ)) } // SPKSX1J setLightTdVal(spkState.SPKSX1D, sda || !getRelayXqVal(spkState.SPKSX1J)) // SPKSX3J setLightTdVal(spkState.SPKSX3D, sda || !getRelayXqVal(spkState.SPKSX3J)) // SPKSS2J setLightTdVal(spkState.SPKSS2D, sda || !getRelayXqVal(spkState.SPKSS2J)) // SPKSS4J setLightTdVal(spkState.SPKSS4D, sda || !getRelayXqVal(spkState.SPKSS4J)) } // 紧急关闭控制电路 func (ibp *IBPSys) empControl(entry *ecs.Entry, s *component.EmpElectronic) { for _, e := range s.EMPJMap { empfab := getIbpBtnVal(e.EMPFA_BTN) empj := component.RelayDriveType.Get(e.EMPJ) // empfab接通或者按钮组接通并且empj继电器吸起状态 empBtnStatus := true for _, b := range e.EMP_BTNS { if !empBtnStatus { break } empBtnStatus = !getIbpBtnVal(b) } empj.Td = empfab || (getRelayXqVal(e.EMPJ) && empBtnStatus) } } // 紧急关闭表示电路 func (ibp *IBPSys) empState(entry *ecs.Entry, s *component.EmpElectronic) { sda := getIbpBtnVal(s.SDA) xq, lx := true, false for _, e := range s.EMPJMap { empj := getRelayXqVal(e.EMPJ) setLightTdVal(e.EMPD, sda || !empj) xq = xq && empj lx = lx || !empj } qba := getIbpBtnVal(s.QBA) if qba { setAlarmTdVal(s.Alarm, xq) } else { setAlarmTdVal(s.Alarm, lx) } } // 获取按钮状态 func getIbpBtnVal(entry *ecs.Entry) bool { btn := component.BitStateType.Get(entry) //旁路后返回之前的值 /* if btn.BypassEnable { return btn.OldVal }*/ return btn.Val } // 获取按钮状态 func getIbpKeyVal(entry *ecs.Entry) bool { btn := component.GearStateType.Get(entry) //旁路后返回之前的值 /* if btn.BypassEnable { return btn.OldVal }*/ return btn.Val == 0 } // 设置继电器通电状态 func setRelayTdVal(entry *ecs.Entry, val bool) { relay := component.RelayDriveType.Get(entry) relay.Td = val } // 获取继电器吸起状态 func getRelayXqVal(entry *ecs.Entry) bool { relay := component.BitStateType.Get(entry) return relay.Val } // 设置信号灯通电状态 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 }