rts-sim-module/sys/circuit_sys/ibp.go

148 lines
4.3 KiB
Go
Raw Normal View History

package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// ibp 系统
type IBPSys struct {
2023-12-07 18:07:05 +08:00
empQuery *ecs.Query
spksQuery *ecs.Query
}
// ibp盘系统
func NewIBPSys() *IBPSys {
return &IBPSys{
2023-12-07 18:07:05 +08:00
empQuery: ecs.NewQuery(filter.Contains(component.EmpElectronicType)),
spksQuery: ecs.NewQuery(filter.Contains(component.SpkElectronicType)),
}
}
// 控制电路更新
func (ibp *IBPSys) Update(w ecs.World) {
2023-12-07 18:07:05 +08:00
ibp.empQuery.Each(w, func(entry *ecs.Entry) {
2023-10-12 13:47:57 +08:00
empState := component.EmpElectronicType.Get(entry)
ibp.empControl(entry, empState)
ibp.empState(entry, empState)
})
2023-12-07 18:07:05 +08:00
ibp.spksQuery.Each(w, func(entry *ecs.Entry) {
spkState := component.SpkElectronicType.Get(entry)
ibp.spkControl(entry, spkState)
ibp.spksState(entry, spkState)
})
}
// 人员防护继电器控制电路逻辑
2023-10-12 13:47:57 +08:00
func (ibp *IBPSys) spkControl(entry *ecs.Entry, spkState *component.SpkElectronic) {
2023-10-20 13:13:44 +08:00
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))
2023-10-20 13:13:44 +08:00
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))
}
// 人员防护表示状态电路逻辑
2023-10-12 13:47:57 +08:00
func (ibp *IBPSys) spksState(entry *ecs.Entry, spkState *component.SpkElectronic) {
2023-10-20 13:13:44 +08:00
sda := getIbpBtnVal(spkState.SDA)
// SPKSXPLAJ
2023-10-18 11:17:08 +08:00
if spkState.SPKSXPLA_BTN.HasComponent(component.SingleLightType) {
singleLight := component.SingleLightType.Get(spkState.SPKSXPLA_BTN)
2023-10-23 14:32:25 +08:00
setLightTdVal(singleLight.Light, sda || getRelayXqVal(spkState.SPKSXPLAJ))
2023-10-18 11:17:08 +08:00
}
// SPKSSPLAJ
2023-10-18 11:17:08 +08:00
if spkState.SPKSSPLA_BTN.HasComponent(component.SingleLightType) {
singleLight := component.SingleLightType.Get(spkState.SPKSSPLA_BTN)
2023-10-23 14:32:25 +08:00
setLightTdVal(singleLight.Light, sda || getRelayXqVal(spkState.SPKSSPLAJ))
2023-10-18 11:17:08 +08:00
}
// SPKSX1J
2023-10-23 14:32:25 +08:00
setLightTdVal(spkState.SPKSX1D, sda || !getRelayXqVal(spkState.SPKSX1J))
// SPKSX3J
2023-10-23 14:32:25 +08:00
setLightTdVal(spkState.SPKSX3D, sda || !getRelayXqVal(spkState.SPKSX3J))
// SPKSS2J
2023-10-23 14:32:25 +08:00
setLightTdVal(spkState.SPKSS2D, sda || !getRelayXqVal(spkState.SPKSS2J))
// SPKSS4J
2023-10-23 14:32:25 +08:00
setLightTdVal(spkState.SPKSS4D, sda || !getRelayXqVal(spkState.SPKSS4J))
}
// 紧急关闭控制电路
2023-10-12 13:47:57 +08:00
func (ibp *IBPSys) empControl(entry *ecs.Entry, s *component.EmpElectronic) {
2023-12-06 16:43:29 +08:00
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)
}
}
// 紧急关闭表示电路
2023-10-12 13:47:57 +08:00
func (ibp *IBPSys) empState(entry *ecs.Entry, s *component.EmpElectronic) {
2023-10-20 13:13:44 +08:00
sda := getIbpBtnVal(s.SDA)
2023-12-06 16:43:29 +08:00
xq, lx := true, false
for _, e := range s.EMPJMap {
empj := getRelayXqVal(e.EMPJ)
setLightTdVal(e.EMPD, sda || !empj)
xq = xq && empj
lx = lx || !empj
}
2023-10-20 13:13:44 +08:00
qba := getIbpBtnVal(s.QBA)
if qba {
2023-12-06 16:43:29 +08:00
setAlarmTdVal(s.Alarm, xq)
} else {
2023-12-06 16:43:29 +08:00
setAlarmTdVal(s.Alarm, lx)
}
}
// 获取按钮状态
2023-10-20 13:13:44 +08:00
func getIbpBtnVal(entry *ecs.Entry) bool {
btn := component.BitStateType.Get(entry)
return btn.Val
}
2023-10-20 13:13:44 +08:00
// 获取按钮状态
func getIbpKeyVal(entry *ecs.Entry) bool {
btn := component.GearStateType.Get(entry)
2023-11-02 14:38:17 +08:00
return btn.Val == 0
2023-10-20 13:13:44 +08:00
}
// 设置继电器通电状态
func setRelayTdVal(entry *ecs.Entry, val bool) {
relay := component.RelayDriveType.Get(entry)
relay.Td = val
}
2023-10-12 10:25:01 +08:00
// 获取继电器吸起状态
func getRelayXqVal(entry *ecs.Entry) bool {
2023-10-23 14:32:25 +08:00
relay := component.BitStateType.Get(entry)
return relay.Val
2023-10-12 10:25:01 +08:00
}
// 设置信号灯通电状态
func setLightTdVal(entry *ecs.Entry, val bool) {
light := component.LightDriveType.Get(entry)
light.Td = val
}
// 设置蜂鸣器通电状态
2023-10-12 17:46:43 +08:00
func setAlarmTdVal(entry *ecs.Entry, val bool) {
fmq := component.AlarmDriveType.Get(entry)
fmq.Td = val
}