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

132 lines
4.3 KiB
Go
Raw Normal View History

2023-10-08 18:03:07 +08:00
package circuit_sys
import (
"joylink.club/ecs"
2023-10-09 13:23:34 +08:00
"joylink.club/ecs/filter"
2023-10-08 18:03:07 +08:00
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
2023-10-08 18:03:07 +08:00
)
type Signal3XH4System struct {
query *ecs.Query
}
func NewSignal3XH4System() *Signal3XH4System {
2023-10-12 16:13:56 +08:00
return &Signal3XH4System{query: ecs.NewQuery(filter.Contains(
component.Signal3XH4ElectronicType,
component.Signal3XH4LsqType,
component.Signal3XH4LscType,
component.SignalLightsType))}
2023-10-08 18:03:07 +08:00
}
// Update world 执行
func (s *Signal3XH4System) Update(w ecs.World) {
wd := entity.GetWorldData(w)
2023-10-12 16:13:56 +08:00
s.query.Each(w, func(entry *ecs.Entry) {
circuit := component.Signal3XH4ElectronicType.Get(entry)
excite3xh4ByCiDrive(circuit, wd)
//lsq := component.Signal3XH4LsqType.Get(entry)
//lsc := component.Signal3XH4LscType.Get(entry)
2023-10-12 16:13:56 +08:00
lights := component.SignalLightsType.Get(entry)
Z3XH4_H := lights.GetLightByTag(component.HdTag)
Z3XH4_L := lights.GetLightByTag(component.LdTag)
Z3XH4_U := lights.GetLightByTag(component.UdTag)
2023-10-08 18:03:07 +08:00
//
//s.calculateLsq(circuit, lsq)
s.calculateU(circuit, Z3XH4_U)
s.calculateL(circuit, Z3XH4_L)
s.calculateH(circuit, Z3XH4_H)
s.calculateDJ(circuit, Z3XH4_H, Z3XH4_L, Z3XH4_U)
//s.calculateLsc(circuit, lsc)
2023-10-08 18:03:07 +08:00
})
}
func excite3xh4ByCiDrive(circuit *component.Signal3XH4Electronic, wd *component.WorldData) {
bit, err := wd.QueryQdBit(component.UidType.Get(circuit.Z3XH4_DDJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.Z3XH4_DDJ).Td = bit
}
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH4_LXJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.Z3XH4_LXJ).Td = bit
}
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH4_ZXJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.Z3XH4_ZXJ).Td = bit
}
}
2023-10-12 16:13:56 +08:00
// 联锁驱
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) {
2023-10-08 18:03:07 +08:00
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
2023-10-12 16:13:56 +08:00
isU := !ddj.Val && lxj.Val && !zxj.Val
driveU := component.LightDriveType.Get(Z3XH4_U)
driveU.Td = isU
2023-10-08 18:03:07 +08:00
}
2023-10-12 16:13:56 +08:00
func (s *Signal3XH4System) calculateL(state *component.Signal3XH4Electronic, Z3XH4_L *ecs.Entry) {
2023-10-08 18:03:07 +08:00
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
2023-10-12 16:13:56 +08:00
isL := !ddj.Val && lxj.Val && zxj.Val
driveL := component.LightDriveType.Get(Z3XH4_L)
driveL.Td = isL
2023-10-08 18:03:07 +08:00
}
2023-10-12 16:13:56 +08:00
func (s *Signal3XH4System) calculateH(state *component.Signal3XH4Electronic, Z3XH4_H *ecs.Entry) {
2023-10-08 18:03:07 +08:00
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
2023-10-12 16:13:56 +08:00
isH := !ddj.Val && !lxj.Val
driveH := component.LightDriveType.Get(Z3XH4_H)
driveH.Td = isH
2023-10-08 18:03:07 +08:00
}
2023-10-12 16:13:56 +08:00
func (s *Signal3XH4System) calculateDJ(state *component.Signal3XH4Electronic, Z3XH4_H *ecs.Entry, Z3XH4_L *ecs.Entry, Z3XH4_U *ecs.Entry) {
2023-10-08 18:03:07 +08:00
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
2023-10-12 16:13:56 +08:00
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
2023-10-08 18:03:07 +08:00
}