rts-sim-module/sys/circuit_sys/signal_3xh4.go
2023-10-12 16:13:56 +08:00

112 lines
3.6 KiB
Go

package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
type Signal3XH4System struct {
query *ecs.Query
}
func NewSignal3XH4System() *Signal3XH4System {
return &Signal3XH4System{query: ecs.NewQuery(filter.Contains(
component.Signal3XH4ElectronicType,
component.Signal3XH4LsqType,
component.Signal3XH4LscType,
component.SignalLightsType))}
}
// Update world 执行
func (s *Signal3XH4System) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
state := component.Signal3XH4ElectronicType.Get(entry)
lsq := component.Signal3XH4LsqType.Get(entry)
lsc := component.Signal3XH4LscType.Get(entry)
lights := component.SignalLightsType.Get(entry)
Z3XH4_H := lights.GetLightByTag(component.HdTag)
Z3XH4_L := lights.GetLightByTag(component.LdTag)
Z3XH4_U := lights.GetLightByTag(component.UdTag)
//
s.calculateLsq(state, lsq)
s.calculateU(state, Z3XH4_U)
s.calculateL(state, Z3XH4_L)
s.calculateH(state, Z3XH4_H)
s.calculateDJ(state, Z3XH4_H, Z3XH4_L, Z3XH4_U)
s.calculateLsc(state, lsc)
})
}
// 联锁驱
func (s *Signal3XH4System) calculateLsq(state *component.Signal3XH4Electronic, lsq *component.Signal3XH4Lsq) {
ddj := component.RelayDriveType.Get(state.Z3XH4_DDJ)
lxj := component.RelayDriveType.Get(state.Z3XH4_LXJ)
zxj := component.RelayDriveType.Get(state.Z3XH4_ZXJ)
//
ddjQ := lsq.Z3XH4_DDJ_Q
ddj.Td = ddjQ
ddj.Xq = ddjQ
//
lxjQ := lsq.Z3XH4_LXJ_Q
lxj.Td = lxjQ
lxj.Xq = lxjQ
//
zxjQ := lsq.Z3XH4_ZXJ_Q
zxj.Td = zxjQ
zxj.Xq = zxjQ
}
// 联锁采
func (s *Signal3XH4System) calculateLsc(state *component.Signal3XH4Electronic, lsc *component.Signal3XH4Lsc) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
dj := component.BitStateType.Get(state.Z3XH4_DJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
//
lsc.Z3XH4_DJ_Xq = dj.Val
lsc.Z3XH4_DDJ_Lx = !ddj.Val
lsc.Z3XH4_LXJ_Xq = lxj.Val
lsc.Z3XH4_ZXJ_Xq = zxj.Val
}
func (s *Signal3XH4System) calculateU(state *component.Signal3XH4Electronic, Z3XH4_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isU := !ddj.Val && lxj.Val && !zxj.Val
driveU := component.LightDriveType.Get(Z3XH4_U)
driveU.Td = isU
}
func (s *Signal3XH4System) calculateL(state *component.Signal3XH4Electronic, Z3XH4_L *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
isL := !ddj.Val && lxj.Val && zxj.Val
driveL := component.LightDriveType.Get(Z3XH4_L)
driveL.Td = isL
}
func (s *Signal3XH4System) calculateH(state *component.Signal3XH4Electronic, Z3XH4_H *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
isH := !ddj.Val && !lxj.Val
driveH := component.LightDriveType.Get(Z3XH4_H)
driveH.Td = isH
}
func (s *Signal3XH4System) calculateDJ(state *component.Signal3XH4Electronic, Z3XH4_H *ecs.Entry, Z3XH4_L *ecs.Entry, Z3XH4_U *ecs.Entry) {
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
hd := component.BitStateType.Get(Z3XH4_H)
ld := component.BitStateType.Get(Z3XH4_L)
ud := component.BitStateType.Get(Z3XH4_U)
isDJ := ud.Val && !ddj.Val && lxj.Val && !zxj.Val ||
ld.Val && !ddj.Val && lxj.Val && zxj.Val ||
hd.Val && !ddj.Val && !lxj.Val
drive := component.RelayDriveType.Get(state.Z3XH4_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}