rts-sim-module/sys/circuit_sys/ibp.go
2023-10-23 14:32:25 +08:00

155 lines
5.2 KiB
Go

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 := getIbpBtnVal(spkState.SPKSXPLA_BTN)
// spksx1j 通电状态
setRelayTdVal(spkState.SPKSX1J, spksxplaBtn || getIbpKeyVal(spkState.SPKSX1J_KEY))
// spksx3j 通电状态
setRelayTdVal(spkState.SPKSX3J, spksxplaBtn || getIbpKeyVal(spkState.SPKSX3J_KEY))
spkssplaBtn := getIbpBtnVal(spkState.SPKSSPLA_BTN)
// spkss2j 通电状态
setRelayTdVal(spkState.SPKSS2J, spkssplaBtn || getIbpKeyVal(spkState.SPKSS2J_KEY))
// spkss4j 通电状态
setRelayTdVal(spkState.SPKSS4J, spkssplaBtn || 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) 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 := getIbpBtnVal(s.XEMPFA_BTN)
xempj := component.RelayDriveType.Get(s.XEMPJ)
// xempfab接通或者按钮组接通并且xempj继电器吸起状态
xempj.Td = xempfab || (getRelayXqVal(s.XEMPJ) && getIbpBtnVal(s.EMP1_BTN) && getIbpBtnVal(s.EMP3_BTN) && getIbpBtnVal(s.EMP5_BTN) && getIbpBtnVal(s.EMPX_BTN))
sempfab := getIbpBtnVal(s.SEMPFA_BTN)
sempj := component.RelayDriveType.Get(s.SEMPJ)
// sempfab接通或者按钮组接通并且sempj继电器吸起状态
sempj.Td = sempfab || (getRelayXqVal(s.SEMPJ) && getIbpBtnVal(s.EMP2_BTN) && getIbpBtnVal(s.EMP4_BTN) && getIbpBtnVal(s.EMP6_BTN) && getIbpBtnVal(s.EMPS_BTN))
}
// 紧急关闭表示电路
func (ibp *IBPSys) empState(entry *ecs.Entry, s *component.EmpElectronic) {
sda := getIbpBtnVal(s.SDA)
xempj := getRelayXqVal(s.XEMPJ)
setLightTdVal(s.XEMPD, sda || !xempj)
sempj := getRelayXqVal(s.SEMPJ)
setLightTdVal(s.SEMPD, sda || !sempj)
qba := getIbpBtnVal(s.QBA)
if qba {
setAlarmTdVal(s.Alarm, xempj && sempj)
} else {
setAlarmTdVal(s.Alarm, (!xempj) || (!sempj))
}
}
// 紧急关闭继电器采集电路状态逻辑
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 getIbpBtnVal(entry *ecs.Entry) bool {
btn := component.BitStateType.Get(entry)
return btn.Val
}
// 获取按钮状态
func getIbpKeyVal(entry *ecs.Entry) bool {
btn := component.GearStateType.Get(entry)
return btn.Val == 1
}
// 设置继电器通电状态
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
}