2023-10-08 16:00:05 +08:00
|
|
|
package circuit_sys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
2023-10-09 13:23:34 +08:00
|
|
|
"joylink.club/ecs/filter"
|
2023-10-08 16:00:05 +08:00
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Signal3XH1System struct {
|
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSignal3XH1System() *Signal3XH1System {
|
2023-10-12 13:54:53 +08:00
|
|
|
return &Signal3XH1System{query: ecs.NewQuery(filter.Contains(
|
|
|
|
component.Signal3XH1ElectronicType,
|
|
|
|
component.Signal3XH1LsqType,
|
|
|
|
component.Signal3XH1LscType,
|
|
|
|
component.SignalLightsType))}
|
2023-10-08 16:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update world 执行
|
|
|
|
func (s *Signal3XH1System) Update(w ecs.World) {
|
2023-10-12 13:54:53 +08:00
|
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
|
|
state := component.Signal3XH1ElectronicType.Get(entry)
|
|
|
|
lsq := component.Signal3XH1LsqType.Get(entry)
|
|
|
|
lsc := component.Signal3XH1LscType.Get(entry)
|
|
|
|
lights := component.SignalLightsType.Get(entry)
|
|
|
|
Z3XH1_L := lights.GetLightByTag(component.LdTag)
|
|
|
|
Z3XH1_H := lights.GetLightByTag(component.HdTag)
|
|
|
|
Z3XH1_U := lights.GetLightByTag(component.UdTag)
|
2023-10-08 16:00:05 +08:00
|
|
|
//
|
2023-10-12 13:54:53 +08:00
|
|
|
s.calculateLsq(state, lsq)
|
|
|
|
s.calculateU(state, Z3XH1_U)
|
|
|
|
s.calculateL(state, Z3XH1_L)
|
|
|
|
s.calculateH(state, Z3XH1_H)
|
|
|
|
s.calculateDJ(state, Z3XH1_H, Z3XH1_L, Z3XH1_U)
|
|
|
|
s.calculate2DJ(state, Z3XH1_U)
|
|
|
|
s.calculateLsc(state, lsc)
|
2023-10-08 16:00:05 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-12 13:54:53 +08:00
|
|
|
// 联锁驱
|
|
|
|
func (s *Signal3XH1System) calculateLsq(state *component.Signal3XH1Electronic, lsq *component.Signal3XH1Lsq) {
|
|
|
|
ddj := component.RelayDriveType.Get(state.Z3XH1_DDJ)
|
|
|
|
lxj := component.RelayDriveType.Get(state.Z3XH1_LXJ)
|
|
|
|
zxj := component.RelayDriveType.Get(state.Z3XH1_ZXJ)
|
|
|
|
yxj := component.RelayDriveType.Get(state.Z3XH1_YXJ)
|
|
|
|
//
|
|
|
|
ddjQ := lsq.Z3XH1_DDJ_Q
|
|
|
|
ddj.Td = ddjQ
|
|
|
|
ddj.Xq = ddjQ
|
|
|
|
//
|
|
|
|
lxjQ := lsq.Z3XH1_LXJ_Q
|
|
|
|
lxj.Td = lxjQ
|
|
|
|
lxj.Xq = lxjQ
|
|
|
|
//
|
|
|
|
zxjQ := lsq.Z3XH1_ZXJ_Q
|
|
|
|
zxj.Td = zxjQ
|
|
|
|
zxj.Xq = zxjQ
|
|
|
|
//
|
|
|
|
yxjQ := lsq.Z3XH1_YXJ_Q
|
|
|
|
yxj.Td = yxjQ
|
|
|
|
yxj.Xq = yxjQ
|
|
|
|
}
|
|
|
|
|
|
|
|
// 联锁采
|
|
|
|
func (s *Signal3XH1System) calculateLsc(state *component.Signal3XH1Electronic, lsc *component.Signal3XH1Lsc) {
|
|
|
|
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
|
|
|
|
dj := component.BitStateType.Get(state.Z3XH1_DJ)
|
|
|
|
edj := component.BitStateType.Get(state.Z3XH1_2DJ)
|
|
|
|
yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
|
|
|
|
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
|
|
|
|
//
|
|
|
|
lsc.Z3XH1_2DJ_Xq = edj.Val
|
|
|
|
lsc.Z3XH1_DJ_Xq = dj.Val
|
|
|
|
lsc.Z3XH1_DDJ_Lx = !ddj.Val
|
|
|
|
lsc.Z3XH1_LXJ_Xq = lxj.Val
|
|
|
|
lsc.Z3XH1_YXJ_Xq = yxj.Val
|
|
|
|
lsc.Z3XH1_ZXJ_Xq = zxj.Val
|
|
|
|
}
|
|
|
|
|
2023-10-08 16:00:05 +08:00
|
|
|
// 黄灯点灯电路
|
|
|
|
// 开放引导信号,黄灯亮且红灯亮
|
|
|
|
// 开放列车信号且开通侧向,只黄灯亮
|
2023-10-12 13:54:53 +08:00
|
|
|
func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic, Z3XH1_U *ecs.Entry) {
|
2023-10-08 16:00:05 +08:00
|
|
|
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
|
|
|
|
dj := component.BitStateType.Get(state.Z3XH1_DJ)
|
|
|
|
yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
|
|
|
|
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
|
2023-10-12 13:54:53 +08:00
|
|
|
driveU := component.LightDriveType.Get(Z3XH1_U)
|
2023-10-08 16:00:05 +08:00
|
|
|
//引导信号
|
|
|
|
isY := !ddj.Val && !lxj.Val && dj.Val && yxj.Val
|
|
|
|
//侧向行车信号
|
|
|
|
isLC := !ddj.Val && lxj.Val && !zxj.Val
|
2023-10-11 16:57:48 +08:00
|
|
|
isU := isY || isLC
|
2023-10-11 17:11:13 +08:00
|
|
|
driveU.Td = isU
|
2023-10-08 16:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 绿灯点灯电路
|
|
|
|
// 开放正线行车信号,只亮绿灯
|
2023-10-12 13:54:53 +08:00
|
|
|
func (s *Signal3XH1System) calculateL(state *component.Signal3XH1Electronic, Z3XH1_L *ecs.Entry) {
|
2023-10-08 16:00:05 +08:00
|
|
|
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
|
|
|
|
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
|
2023-10-12 13:54:53 +08:00
|
|
|
driveL := component.LightDriveType.Get(Z3XH1_L)
|
2023-10-08 16:00:05 +08:00
|
|
|
isL := !ddj.Val && lxj.Val && zxj.Val
|
2023-10-11 17:11:13 +08:00
|
|
|
driveL.Td = isL
|
2023-10-08 16:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 红灯点灯电路
|
|
|
|
// 列车信号禁止时,亮红灯
|
2023-10-12 13:54:53 +08:00
|
|
|
func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic, Z3XH1_H *ecs.Entry) {
|
2023-10-08 16:00:05 +08:00
|
|
|
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
|
2023-10-12 13:54:53 +08:00
|
|
|
driveH := component.LightDriveType.Get(Z3XH1_H)
|
2023-10-08 16:00:05 +08:00
|
|
|
isH := !ddj.Val && !lxj.Val
|
2023-10-11 17:11:13 +08:00
|
|
|
driveH.Td = isH
|
2023-10-08 16:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// DJ 灯丝继电器电路
|
2023-10-12 13:54:53 +08:00
|
|
|
func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic, Z3XH1_H *ecs.Entry, Z3XH1_L *ecs.Entry, Z3XH1_U *ecs.Entry) {
|
2023-10-08 16:00:05 +08:00
|
|
|
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
|
|
|
|
zxj := component.BitStateType.Get(state.Z3XH1_ZXJ)
|
2023-10-12 13:54:53 +08:00
|
|
|
ld := component.BitStateType.Get(Z3XH1_L)
|
|
|
|
hd := component.BitStateType.Get(Z3XH1_H)
|
|
|
|
ud := component.BitStateType.Get(Z3XH1_U)
|
2023-10-11 16:57:48 +08:00
|
|
|
isDj := ld.Val && !ddj.Val && lxj.Val && zxj.Val || //绿灯亮
|
|
|
|
ud.Val && !ddj.Val && lxj.Val && !zxj.Val || //黄灯亮
|
|
|
|
hd.Val && !ddj.Val && !lxj.Val //红灯亮
|
2023-10-08 16:00:05 +08:00
|
|
|
//通知继电器进行动作
|
2023-10-11 16:57:48 +08:00
|
|
|
drive := component.RelayDriveType.Get(state.Z3XH1_DJ)
|
|
|
|
drive.Td = isDj
|
|
|
|
drive.Xq = isDj
|
2023-10-08 16:00:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 2DJ 灯丝继电器电路
|
2023-10-12 13:54:53 +08:00
|
|
|
func (s *Signal3XH1System) calculate2DJ(state *component.Signal3XH1Electronic, Z3XH1_U *ecs.Entry) {
|
2023-10-08 16:00:05 +08:00
|
|
|
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
|
|
|
|
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
|
|
|
|
dj := component.BitStateType.Get(state.Z3XH1_DJ)
|
|
|
|
yxj := component.BitStateType.Get(state.Z3XH1_YXJ)
|
2023-10-12 13:54:53 +08:00
|
|
|
ud := component.BitStateType.Get(Z3XH1_U)
|
2023-10-08 16:00:05 +08:00
|
|
|
//
|
2023-10-11 16:57:48 +08:00
|
|
|
is2DJ := ud.Val && !ddj.Val && !lxj.Val && dj.Val && yxj.Val
|
2023-10-08 16:00:05 +08:00
|
|
|
//通知继电器进行动作
|
2023-10-11 16:57:48 +08:00
|
|
|
drive := component.RelayDriveType.Get(state.Z3XH1_2DJ)
|
|
|
|
drive.Td = is2DJ
|
|
|
|
drive.Xq = is2DJ
|
2023-10-08 16:00:05 +08:00
|
|
|
}
|