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

87 lines
2.8 KiB
Go
Raw Normal View History

2023-10-08 13:59:15 +08:00
package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
2023-10-08 13:59:15 +08:00
"joylink.club/rtsssimulation/component"
)
type Signal2XH1System struct {
query *ecs.Query
}
func NewSignal2XH1System() *Signal2XH1System {
2023-10-12 11:00:56 +08:00
return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(
component.Signal2XH1ElectronicType,
component.Signal2XH1LsqType,
component.Signal2XH1LscType,
component.SignalLightsType))}
2023-10-08 13:59:15 +08:00
}
// Update world 执行
func (s *Signal2XH1System) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
state := component.Signal2XH1ElectronicType.Get(entry)
2023-10-12 10:07:40 +08:00
lsq := component.Signal2XH1LsqType.Get(entry)
lsc := component.Signal2XH1LscType.Get(entry)
2023-10-12 11:00:56 +08:00
lights := component.SignalLightsType.Get(entry)
Z2XH1_L := lights.GetLightByTag(component.LdTag)
Z2XH1_H := lights.GetLightByTag(component.HdTag)
2023-10-12 10:07:40 +08:00
s.calculateLsq(state, lsq)
2023-10-12 11:00:56 +08:00
s.calculateL(state, Z2XH1_L)
s.calculateH(state, Z2XH1_H)
s.calculateDJ(state, Z2XH1_L, Z2XH1_H)
2023-10-12 10:07:40 +08:00
s.calculateLsc(state, lsc)
2023-10-08 13:59:15 +08:00
})
}
2023-10-12 10:07:40 +08:00
// 联锁驱
func (s *Signal2XH1System) calculateLsq(state *component.Signal2XH1Electronic, lsq *component.Signal2XH1Lsq) {
ddj := component.RelayDriveType.Get(state.Z2XH1_DDJ)
lxj := component.RelayDriveType.Get(state.Z2XH1_LXJ)
//
ddjQ := lsq.Z2XH1_DDJ_Q
ddj.Td = ddjQ
ddj.Xq = ddjQ
//
lxjQ := lsq.Z2XH1_LXJ_Q
lxj.Td = lxjQ
lxj.Xq = lxjQ
}
// 联锁采
func (s *Signal2XH1System) calculateLsc(state *component.Signal2XH1Electronic, lsc *component.Signal2XH1Lsc) {
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
dj := component.BitStateType.Get(state.Z2XH1_DJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
//
lsc.Z2XH1_DDJ_Lx = !ddj.Val
lsc.Z2XH1_DJ_Xq = dj.Val
lsc.Z2XH1_LXJ_Xq = lxj.Val
}
2023-10-12 11:00:56 +08:00
func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic, Z2XH1_L *ecs.Entry) {
driveL := component.LightDriveType.Get(Z2XH1_L)
2023-10-08 13:59:15 +08:00
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
2023-10-11 14:12:51 +08:00
isL := !ddj.Val && lxj.Val
2023-10-11 17:11:13 +08:00
driveL.Td = isL
2023-10-08 13:59:15 +08:00
}
2023-10-12 11:00:56 +08:00
func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic, Z2XH1_H *ecs.Entry) {
driveH := component.LightDriveType.Get(Z2XH1_H)
2023-10-08 13:59:15 +08:00
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
2023-10-11 14:12:51 +08:00
isH := !ddj.Val && !lxj.Val
2023-10-11 17:11:13 +08:00
driveH.Td = isH
2023-10-08 13:59:15 +08:00
}
2023-10-12 11:00:56 +08:00
func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic, Z2XH1_L *ecs.Entry, Z2XH1_H *ecs.Entry) {
2023-10-08 13:59:15 +08:00
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
2023-10-12 11:00:56 +08:00
ld := component.BitStateType.Get(Z2XH1_L)
hd := component.BitStateType.Get(Z2XH1_H)
2023-10-11 16:57:48 +08:00
isDJ := !ddj.Val && lxj.Val && ld.Val || !ddj.Val && !lxj.Val && hd.Val
2023-10-08 13:59:15 +08:00
//通知继电器进行动作
2023-10-11 17:11:13 +08:00
drive := component.RelayDriveType.Get(state.Z2XH1_DJ)
drive.Td = isDJ
drive.Xq = isDJ
2023-10-08 13:59:15 +08:00
}