128 lines
3.9 KiB
Go
128 lines
3.9 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.SpkControlElectronicType,
|
|
component.SpksStateElectronicType,
|
|
component.EmpControlElectronicType,
|
|
component.EmpStateElectronicType,
|
|
)),
|
|
}
|
|
}
|
|
|
|
// 控制电路更新
|
|
func (ibp *IBPSys) Update(w ecs.World) {
|
|
ibp.query.Each(w, func(entry *ecs.Entry) {
|
|
ibp.spkControl(entry)
|
|
ibp.spksState(entry)
|
|
ibp.empControl(entry)
|
|
ibp.empState(entry)
|
|
})
|
|
}
|
|
|
|
// 人员防护继电器控制电路逻辑
|
|
func (ibp *IBPSys) spkControl(entry *ecs.Entry) {
|
|
spkState := component.SpkControlElectronicType.Get(entry)
|
|
spksxplaBtn := getBtnVal(spkState.SPKSXPLA_BTN)
|
|
// spksx1j 通电状态
|
|
setRelayTdVal(spkState.SPKSX1J, spksxplaBtn || getBtnVal(spkState.SPKSX1J_BTN))
|
|
// spksx3j 通电状态
|
|
setRelayTdVal(spkState.SPKSX3J, spksxplaBtn || getBtnVal(spkState.SPKSX3J_BTN))
|
|
spkssplaBtn := getBtnVal(spkState.SPKSSPLA_BTN)
|
|
// spkss2j 通电状态
|
|
setRelayTdVal(spkState.SPKSS2J, spkssplaBtn || getBtnVal(spkState.SPKSS2J_BTN))
|
|
// spkss4j 通电状态
|
|
setRelayTdVal(spkState.SPKSS4J, spkssplaBtn || getBtnVal(spkState.SPKSS4J_BTN))
|
|
}
|
|
|
|
// 人员防护表示状态电路逻辑
|
|
func (ibp *IBPSys) spksState(entry *ecs.Entry) {
|
|
spkState := component.SpksStateElectronicType.Get(entry)
|
|
sda := getBtnVal(spkState.SDA)
|
|
// SPKSXPLAJ
|
|
spksxplaj := component.RelayDriveType.Get(spkState.SPKSXPLAJ)
|
|
setLightTdVal(spkState.SPKSXPLAD, sda || spksxplaj.Xq)
|
|
// SPKSSPLAJ
|
|
spkssplaj := component.RelayDriveType.Get(spkState.SPKSSPLAJ)
|
|
setLightTdVal(spkState.SPKSSPLAD, 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) empControl(entry *ecs.Entry) {
|
|
s := component.EmpControlElectronicType.Get(entry)
|
|
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.EmpStateElectronicType.Get(entry)
|
|
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 {
|
|
setFMQTdVal(s.FMQ, xempj.Xq && sempj.Xq)
|
|
} else {
|
|
setFMQTdVal(s.FMQ, (!xempj.Xq) || (!sempj.Xq))
|
|
}
|
|
}
|
|
|
|
// 获取按钮状态
|
|
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 setLightTdVal(entry *ecs.Entry, val bool) {
|
|
light := component.LightDriveType.Get(entry)
|
|
light.Td = val
|
|
}
|
|
|
|
// 设置蜂鸣器通电状态
|
|
func setFMQTdVal(entry *ecs.Entry, val bool) {
|
|
fmq := component.FMQDriveType.Get(entry)
|
|
fmq.Td = val
|
|
}
|