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

100 lines
3.3 KiB
Go
Raw Normal View History

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-11 16:57:48 +08:00
return &Signal3XH1System{query: ecs.NewQuery(filter.Contains(component.Signal3XH1ElectronicType))}
2023-10-08 16:00:05 +08:00
}
// Update world 执行
func (s *Signal3XH1System) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
signal3XH1State := component.Signal3XH1ElectronicType.Get(e)
//
2023-10-11 16:57:48 +08:00
s.calculateU(signal3XH1State)
s.calculateL(signal3XH1State)
s.calculateH(signal3XH1State)
s.calculateDJ(signal3XH1State)
s.calculate2DJ(signal3XH1State)
2023-10-08 16:00:05 +08:00
})
}
// 黄灯点灯电路
// 开放引导信号,黄灯亮且红灯亮
// 开放列车信号且开通侧向,只黄灯亮
2023-10-11 16:57:48 +08:00
func (s *Signal3XH1System) calculateU(state *component.Signal3XH1Electronic) {
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-11 16:57:48 +08:00
driveU := component.LightDriveType.Get(state.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-11 16:57:48 +08:00
func (s *Signal3XH1System) calculateL(state *component.Signal3XH1Electronic) {
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-11 16:57:48 +08:00
driveL := component.LightDriveType.Get(state.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-11 16:57:48 +08:00
func (s *Signal3XH1System) calculateH(state *component.Signal3XH1Electronic) {
2023-10-08 16:00:05 +08:00
ddj := component.BitStateType.Get(state.Z3XH1_DDJ)
lxj := component.BitStateType.Get(state.Z3XH1_LXJ)
2023-10-11 16:57:48 +08:00
driveH := component.LightDriveType.Get(state.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-11 16:57:48 +08:00
func (s *Signal3XH1System) calculateDJ(state *component.Signal3XH1Electronic) {
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-11 16:57:48 +08:00
ld := component.BitStateType.Get(state.Z3XH1_L)
hd := component.BitStateType.Get(state.Z3XH1_H)
ud := component.BitStateType.Get(state.Z3XH1_U)
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-11 16:57:48 +08:00
func (s *Signal3XH1System) calculate2DJ(state *component.Signal3XH1Electronic) {
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-11 16:57:48 +08:00
ud := component.BitStateType.Get(state.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
}