2023-10-09 11:09:29 +08:00
|
|
|
package circuit_sys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
2023-10-09 13:23:34 +08:00
|
|
|
"joylink.club/ecs/filter"
|
2023-10-09 11:09:29 +08:00
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SignalJDXHSystem struct {
|
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSignalJDXHSystem() *SignalJDXHSystem {
|
2023-10-13 09:31:49 +08:00
|
|
|
return &SignalJDXHSystem{query: ecs.NewQuery(filter.Contains(
|
|
|
|
component.SignalJDXHElectronicType,
|
|
|
|
component.SignalJDXHLsqType,
|
|
|
|
component.SignalJDXHLscType,
|
|
|
|
component.SignalLightsType))}
|
2023-10-09 11:09:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update world 执行
|
|
|
|
func (s *SignalJDXHSystem) Update(w ecs.World) {
|
2023-10-13 09:31:49 +08:00
|
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
|
|
state := component.SignalJDXHElectronicType.Get(entry)
|
|
|
|
lsq := component.SignalJDXHLsqType.Get(entry)
|
|
|
|
lsc := component.SignalJDXHLscType.Get(entry)
|
|
|
|
lights := component.SignalLightsType.Get(entry)
|
|
|
|
JDXH_H := lights.GetLightByTag(component.HdTag)
|
|
|
|
JDXH_L := lights.GetLightByTag(component.LdTag)
|
|
|
|
JDXH_U := lights.GetLightByTag(component.UdTag)
|
2023-10-09 11:09:29 +08:00
|
|
|
//
|
2023-10-13 09:31:49 +08:00
|
|
|
s.calculateLsq(state, lsq)
|
|
|
|
s.calculateL(state, JDXH_L)
|
|
|
|
s.calculateU(state, JDXH_U)
|
|
|
|
s.calculateH(state, JDXH_H)
|
|
|
|
s.calculateDJ(state, JDXH_L, JDXH_H)
|
|
|
|
s.calculate2DJ(state, JDXH_U)
|
|
|
|
s.calculateLsc(state, lsc)
|
2023-10-09 11:09:29 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-13 09:31:49 +08:00
|
|
|
// 联锁驱
|
|
|
|
func (s *SignalJDXHSystem) calculateLsq(state *component.SignalJDXHElectronic, lsq *component.SignalJDXHLsq) {
|
|
|
|
lxj := component.RelayDriveType.Get(state.JDXH_LXJ)
|
|
|
|
yzhj := component.RelayDriveType.Get(state.JDXH_YZHJ)
|
|
|
|
//
|
|
|
|
lxjQ := lsq.JDXH_LXJ_Q
|
|
|
|
lxj.Td = lxjQ
|
|
|
|
lxj.Xq = lxjQ
|
|
|
|
//
|
|
|
|
yzhjQ := lsq.JDXH_YZHJ_Q
|
|
|
|
yzhj.Td = yzhjQ
|
|
|
|
yzhj.Xq = yzhjQ
|
|
|
|
}
|
|
|
|
|
|
|
|
// 联锁采
|
|
|
|
func (s *SignalJDXHSystem) calculateLsc(state *component.SignalJDXHElectronic, lsc *component.SignalJDXHLsc) {
|
|
|
|
edj := component.BitStateType.Get(state.JDXH_2DJ)
|
|
|
|
dj := component.BitStateType.Get(state.JDXH_DJ)
|
|
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
|
|
yxj := component.BitStateType.Get(state.JDXH_YXJ)
|
|
|
|
yzhj := component.BitStateType.Get(state.JDXH_YZHJ)
|
|
|
|
//
|
|
|
|
lsc.JDXH_2DJ_Xq = edj.Val
|
|
|
|
lsc.JDXH_DJ_Xq = dj.Val
|
|
|
|
lsc.JDXH_LXJ_Xq = lxj.Val
|
|
|
|
lsc.JDXH_YZHJ_YXJ_Xq = yxj.Val && yzhj.Val
|
|
|
|
}
|
|
|
|
func (s *SignalJDXHSystem) calculateU(state *component.SignalJDXHElectronic, JDXH_U *ecs.Entry) {
|
2023-10-09 11:09:29 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
|
|
dj := component.BitStateType.Get(state.JDXH_DJ)
|
|
|
|
yxj := component.BitStateType.Get(state.JDXH_YXJ)
|
2023-10-13 09:31:49 +08:00
|
|
|
isU := !lxj.Val && dj.Val && yxj.Val
|
|
|
|
driveU := component.LightDriveType.Get(JDXH_U)
|
|
|
|
driveU.Td = isU
|
2023-10-09 11:09:29 +08:00
|
|
|
}
|
|
|
|
|
2023-10-13 09:31:49 +08:00
|
|
|
func (s *SignalJDXHSystem) calculateL(state *component.SignalJDXHElectronic, JDXH_L *ecs.Entry) {
|
2023-10-09 11:09:29 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
2023-10-13 09:31:49 +08:00
|
|
|
isL := lxj.Val
|
|
|
|
driveL := component.LightDriveType.Get(JDXH_L)
|
|
|
|
driveL.Td = isL
|
2023-10-09 11:09:29 +08:00
|
|
|
}
|
|
|
|
|
2023-10-13 09:31:49 +08:00
|
|
|
func (s *SignalJDXHSystem) calculateH(state *component.SignalJDXHElectronic, JDXH_H *ecs.Entry) {
|
2023-10-09 11:09:29 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
2023-10-13 09:31:49 +08:00
|
|
|
isH := !lxj.Val
|
|
|
|
driveH := component.LightDriveType.Get(JDXH_H)
|
|
|
|
driveH.Td = isH
|
2023-10-09 11:09:29 +08:00
|
|
|
}
|
|
|
|
|
2023-10-13 09:31:49 +08:00
|
|
|
func (s *SignalJDXHSystem) calculateDJ(state *component.SignalJDXHElectronic, JDXH_L *ecs.Entry, JDXH_H *ecs.Entry) {
|
2023-10-09 11:09:29 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
2023-10-13 09:31:49 +08:00
|
|
|
hd := component.BitStateType.Get(JDXH_H)
|
|
|
|
ld := component.BitStateType.Get(JDXH_L)
|
|
|
|
isDJ := ld.Val && lxj.Val || hd.Val && !lxj.Val
|
|
|
|
drive := component.RelayDriveType.Get(state.JDXH_DJ)
|
|
|
|
drive.Td = isDJ
|
|
|
|
drive.Xq = isDJ
|
2023-10-09 11:09:29 +08:00
|
|
|
}
|
2023-10-13 09:31:49 +08:00
|
|
|
func (s *SignalJDXHSystem) calculate2DJ(state *component.SignalJDXHElectronic, JDXH_U *ecs.Entry) {
|
2023-10-09 11:09:29 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
|
|
dj := component.BitStateType.Get(state.JDXH_DJ)
|
|
|
|
yxj := component.BitStateType.Get(state.JDXH_YXJ)
|
2023-10-13 09:31:49 +08:00
|
|
|
ud := component.BitStateType.Get(JDXH_U)
|
|
|
|
is2DJ := ud.Val && !lxj.Val && dj.Val && yxj.Val
|
|
|
|
drive := component.RelayDriveType.Get(state.JDXH_2DJ)
|
|
|
|
drive.Td = is2DJ
|
|
|
|
drive.Xq = is2DJ
|
2023-10-09 11:09:29 +08:00
|
|
|
}
|