|
|
@ -10,8 +10,10 @@ import (
|
|
|
|
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
|
|
|
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
|
|
|
"joylink.club/rtsssimulation/entity"
|
|
|
|
|
|
|
|
"joylink.club/rtsssimulation/fi"
|
|
|
|
"log/slog"
|
|
|
|
"log/slog"
|
|
|
|
"math"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"net"
|
|
|
|
"runtime/debug"
|
|
|
|
"runtime/debug"
|
|
|
|
"sort"
|
|
|
|
"sort"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
@ -31,13 +33,12 @@ var (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type serviceContext struct {
|
|
|
|
type serviceContext struct {
|
|
|
|
cancelFunc context.CancelFunc //用来结束各个协程的函数
|
|
|
|
cancelFunc context.CancelFunc //用来结束各个协程的函数
|
|
|
|
client udp.UdpClient //向联锁发送数据的客户端
|
|
|
|
ioAddr *net.UDPAddr //向联锁发送数据的客户端
|
|
|
|
server udp.UdpServer //接收联锁数据的服务端
|
|
|
|
server udp.UdpServer //接收联锁数据的服务端(同时也是向联锁发送数据的udp客户端)
|
|
|
|
sim *memory.VerifySimulation //启动服务所使用的仿真
|
|
|
|
sim *memory.VerifySimulation //启动服务所使用的仿真
|
|
|
|
iConfig config.InterlockConfig //启动服务使用的联锁配置
|
|
|
|
iConfig config.InterlockConfig //启动服务使用的联锁配置
|
|
|
|
deviceTable *StationDeviceIndexTable //联锁站的设备ID表,key-车站名
|
|
|
|
deviceTable *StationDeviceIndexTable //联锁站的设备ID表,key-车站名
|
|
|
|
driveMsgSlice []*FromInterlockFrame //驱动消息切片
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Start(interlockConfig config.InterlockConfig, simulation *memory.VerifySimulation) {
|
|
|
|
func Start(interlockConfig config.InterlockConfig, simulation *memory.VerifySimulation) {
|
|
|
@ -55,13 +56,16 @@ func Start(interlockConfig config.InterlockConfig, simulation *memory.VerifySimu
|
|
|
|
if serviceCtx != nil {
|
|
|
|
if serviceCtx != nil {
|
|
|
|
panic(fmt.Sprintf("%s重复启动联锁站[%s]通信服务", logTag, interlockConfig.Code))
|
|
|
|
panic(fmt.Sprintf("%s重复启动联锁站[%s]通信服务", logTag, interlockConfig.Code))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//UDP客户端
|
|
|
|
//仿真IO地址
|
|
|
|
client := udp.NewClient(fmt.Sprintf("%s:%d", interlockConfig.Ip, interlockConfig.RemotePort))
|
|
|
|
ioAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", interlockConfig.Ip, interlockConfig.RemotePort))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
panic(fmt.Sprintf("%s解析IP地址出错:%s", logTag, err))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
|
|
|
serviceCtx = &serviceContext{
|
|
|
|
serviceCtx = &serviceContext{
|
|
|
|
cancelFunc: cancelFunc,
|
|
|
|
cancelFunc: cancelFunc,
|
|
|
|
client: client,
|
|
|
|
ioAddr: ioAddr,
|
|
|
|
sim: simulation,
|
|
|
|
sim: simulation,
|
|
|
|
iConfig: interlockConfig,
|
|
|
|
iConfig: interlockConfig,
|
|
|
|
deviceTable: table,
|
|
|
|
deviceTable: table,
|
|
|
@ -69,7 +73,7 @@ func Start(interlockConfig config.InterlockConfig, simulation *memory.VerifySimu
|
|
|
|
//UDP服务端
|
|
|
|
//UDP服务端
|
|
|
|
server := udp.NewServer(fmt.Sprintf(":%d", interlockConfig.LocalPort), serviceCtx.handleDriveMsg)
|
|
|
|
server := udp.NewServer(fmt.Sprintf(":%d", interlockConfig.LocalPort), serviceCtx.handleDriveMsg)
|
|
|
|
serviceCtx.server = server
|
|
|
|
serviceCtx.server = server
|
|
|
|
err := server.Listen()
|
|
|
|
err = server.Listen()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("%s启动UDP服务失败:%s", logTag, err))
|
|
|
|
panic(fmt.Sprintf("%s启动UDP服务失败:%s", logTag, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -86,201 +90,220 @@ func (s *serviceContext) handleDriveMsg(data []byte) {
|
|
|
|
logger().Error("解析数据出错", "error", err)
|
|
|
|
logger().Error("解析数据出错", "error", err)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(s.driveMsgSlice) < 2 {
|
|
|
|
|
|
|
|
if frame.InterlockCode == 0x3c01 || frame.InterlockCode == 0x3c02 {
|
|
|
|
wd := entity.GetWorldData(s.sim.World)
|
|
|
|
s.driveMsgSlice = append(s.driveMsgSlice, frame)
|
|
|
|
for _, cmd := range frame.TurnoutData.CmdList {
|
|
|
|
|
|
|
|
uid := s.deviceTable.TurnoutMap[cmd.Id].uid
|
|
|
|
|
|
|
|
if cmd.Cmd == 0x55 {
|
|
|
|
|
|
|
|
err = fi.DriveTurnoutDCOn(s.sim.World, uid)
|
|
|
|
|
|
|
|
} else if cmd.Cmd == 0xaa {
|
|
|
|
|
|
|
|
err = fi.DriveTurnoutFCOn(s.sim.World, uid)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err = fi.DriveTurnoutDCOff(s.sim.World, uid)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logger().Error("驱动道岔出错", "error", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range frame.PSDData.CmdList {
|
|
|
|
|
|
|
|
row := s.deviceTable.PsdMap[cmd.Id]
|
|
|
|
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
|
|
|
|
circuit := component.PsdCircuitType.Get(entry)
|
|
|
|
|
|
|
|
logger().Info(fmt.Sprintf("屏蔽门命令:%x", cmd.Cmd))
|
|
|
|
|
|
|
|
switch cmd.Cmd {
|
|
|
|
|
|
|
|
case 0xAA: //短编组开门
|
|
|
|
|
|
|
|
wd.SetQdBit(row.relateDeviceMap[S], true)
|
|
|
|
|
|
|
|
wd.SetQdBit(row.relateDeviceMap[L], false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(circuit.GMJ).Id, false)
|
|
|
|
|
|
|
|
case 0xBB: //长编组开门
|
|
|
|
|
|
|
|
wd.SetQdBit(row.relateDeviceMap[S], false)
|
|
|
|
|
|
|
|
wd.SetQdBit(row.relateDeviceMap[L], true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(circuit.GMJ).Id, false)
|
|
|
|
|
|
|
|
case 0x55: //关门
|
|
|
|
|
|
|
|
wd.SetQdBit(row.relateDeviceMap[S], false)
|
|
|
|
|
|
|
|
wd.SetQdBit(row.relateDeviceMap[L], false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(circuit.GMJ).Id, true)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range frame.ESBData.CmdList {
|
|
|
|
|
|
|
|
uid := s.deviceTable.EsbMap[cmd.Id].uid
|
|
|
|
|
|
|
|
esb := s.sim.Repo.FindEsb(uid)
|
|
|
|
|
|
|
|
if cmd.JjtcplCmd == 0x55 {
|
|
|
|
|
|
|
|
err = fi.PressDownButton(s.sim.World, esb.PlaId())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logger().Error("驱动ESB出错", "error", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err = fi.PressUpButton(s.sim.World, esb.PlaId())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logger().Error("驱动ESB出错", "error", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd.JjtcCmd == 0x55 {
|
|
|
|
|
|
|
|
err := fi.DriveRelayDown(s.sim.World, esb.RelayId())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logger().Error("驱动ESB出错", "error", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err := fi.DriveRelayUp(s.sim.World, esb.RelayId())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logger().Error("驱动ESB出错", "error", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range frame.SignalData.CmdList {
|
|
|
|
|
|
|
|
uid := s.deviceTable.SignalMap[cmd.Id].uid
|
|
|
|
|
|
|
|
entry := wd.EntityMap[uid]
|
|
|
|
|
|
|
|
if entry.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机
|
|
|
|
|
|
|
|
signal2XH1 := component.Signal2XH1ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
switch cmd.Cmd {
|
|
|
|
|
|
|
|
case SignalAspect_No:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_DDJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_LXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_H:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_LXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_L:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal2XH1.Z2XH1_LXJ).Id, true)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if entry.HasComponent(component.Signal3XH1ElectronicType) { // 3XH1信号机
|
|
|
|
|
|
|
|
signal3XH1 := component.Signal3XH1ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
switch cmd.Cmd {
|
|
|
|
|
|
|
|
case SignalAspect_No:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_DDJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_ZXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_H:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_ZXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_L:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_LXJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_ZXJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_U:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_LXJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_ZXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_HU:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_ZXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH1.Z3XH1_YXJ).Id, true)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if entry.HasComponent(component.Signal3XH2ElectronicType) { // 3XH2信号机
|
|
|
|
|
|
|
|
signal3XH2 := component.Signal3XH2ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
switch cmd.Cmd {
|
|
|
|
|
|
|
|
case SignalAspect_No:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_DDJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_H:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_L:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_LXJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_HU:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH2.Z3XH2_YXJ).Id, true)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if entry.HasComponent(component.Signal3XH3ElectronicType) { // 3XH3信号机
|
|
|
|
|
|
|
|
signal3XH3 := component.Signal3XH3ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
switch cmd.Cmd {
|
|
|
|
|
|
|
|
case SignalAspect_No:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_DDJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_H:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_U:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_LXJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_YXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_HU:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH3.Z3XH3_YXJ).Id, true)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if entry.HasComponent(component.Signal3XH4ElectronicType) { // 3XH4信号机
|
|
|
|
|
|
|
|
signal3XH4 := component.Signal3XH4ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
switch cmd.Cmd {
|
|
|
|
|
|
|
|
case SignalAspect_No:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_DDJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_ZXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_H:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_LXJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_ZXJ).Id, false)
|
|
|
|
|
|
|
|
case SignalAspect_L:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_LXJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_ZXJ).Id, true)
|
|
|
|
|
|
|
|
case SignalAspect_U:
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_DDJ).Id, false)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_LXJ).Id, true)
|
|
|
|
|
|
|
|
wd.SetQdBit(component.UidType.Get(signal3XH4.Z3XH4_ZXJ).Id, false)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
logger().Error(fmt.Sprintf("信号机[%s]的型号未知", uid))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range frame.AxleSectionData.CmdList {
|
|
|
|
|
|
|
|
if cmd.Cmd == 0x80 {
|
|
|
|
|
|
|
|
uid := s.deviceTable.AxleSectionMap[cmd.Id].uid
|
|
|
|
|
|
|
|
physicalSectionUid := s.sim.Repo.FindAxleCountingSection(uid).PhysicalSection().Id()
|
|
|
|
|
|
|
|
_, err := fi.PhysicalSectionDrstDrive(s.sim.World, physicalSectionUid)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logger().Error(fmt.Sprintf("计轴区段[%s]复位出错:%s", uid, err))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, cmd := range frame.SPKSData.CmdList {
|
|
|
|
|
|
|
|
uid := s.deviceTable.SpksMap[cmd.Id].uid
|
|
|
|
|
|
|
|
spks := s.sim.Repo.FindSpks(uid)
|
|
|
|
|
|
|
|
if cmd.SPKSPLCmd == 0x55 {
|
|
|
|
|
|
|
|
err = fi.PressDownButton(s.sim.World, spks.PlaId())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err = fi.PressUpButton(s.sim.World, spks.PlaId())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if cmd.SPKSCmd == 0x55 {
|
|
|
|
|
|
|
|
err = fi.DriveRelayDown(s.sim.World, spks.Relay())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err = fi.DriveRelayUp(s.sim.World, spks.Relay())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//wd := entity.GetWorldData(s.sim.World)
|
|
|
|
|
|
|
|
////for _, cmd := range frame.TurnoutData.CmdList {
|
|
|
|
|
|
|
|
//// uid := s.deviceTable.TurnoutMap[cmd.Id].uid
|
|
|
|
|
|
|
|
////}
|
|
|
|
|
|
|
|
//for _, cmd := range frame.PSDData.CmdList {
|
|
|
|
|
|
|
|
// row := s.deviceTable.PsdMap[cmd.Id]
|
|
|
|
|
|
|
|
// entry := wd.EntityMap[row.uid]
|
|
|
|
|
|
|
|
// circuit := component.PsdCircuitType.Get(entry)
|
|
|
|
|
|
|
|
// switch cmd.Cmd {
|
|
|
|
|
|
|
|
// case 0xAA: //短编组开门
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(wd.EntityMap[row.relateDeviceMap[S]]).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(wd.EntityMap[row.relateDeviceMap[L]]).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(circuit.GMJ).Td = false
|
|
|
|
|
|
|
|
// case 0xBB: //长编组开门
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(wd.EntityMap[row.relateDeviceMap[S]]).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(wd.EntityMap[row.relateDeviceMap[L]]).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(circuit.GMJ).Td = false
|
|
|
|
|
|
|
|
// case 0x55:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(wd.EntityMap[row.relateDeviceMap[S]]).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(wd.EntityMap[row.relateDeviceMap[L]]).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(circuit.GMJ).Td = true
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//for _, cmd := range frame.ESBData.CmdList {
|
|
|
|
|
|
|
|
// uid := s.deviceTable.EsbMap[cmd.Id].uid
|
|
|
|
|
|
|
|
// esb := s.sim.Repo.FindEsb(uid)
|
|
|
|
|
|
|
|
// if cmd.JjtcplCmd == ON {
|
|
|
|
|
|
|
|
// err := fi.DriveRelayUp(s.sim.World, esb.RelayId())
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// logger().Error("驱动ESB出错", "error", err)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// continue
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if cmd.JjtcCmd == ON {
|
|
|
|
|
|
|
|
// err := fi.DriveRelayDown(s.sim.World, esb.RelayId())
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// logger().Error("驱动ESB出错", "error", err)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// err := fi.DriveRelayUp(s.sim.World, esb.RelayId())
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// logger().Error("驱动ESB出错", "error", err)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//for _, cmd := range frame.SignalData.CmdList {
|
|
|
|
|
|
|
|
// uid := s.deviceTable.SignalMap[cmd.Id].uid
|
|
|
|
|
|
|
|
// entry := wd.EntityMap[uid]
|
|
|
|
|
|
|
|
// if entry.HasComponent(component.Signal2XH1ElectronicType) { // 2XH1信号机
|
|
|
|
|
|
|
|
// signal2XH1 := component.Signal2XH1ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
// switch cmd.Cmd {
|
|
|
|
|
|
|
|
// case SignalAspect_No:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal2XH1.Z2XH1_DDJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal2XH1.Z2XH1_LXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_H:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal2XH1.Z2XH1_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal2XH1.Z2XH1_LXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_L:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal2XH1.Z2XH1_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal2XH1.Z2XH1_LXJ).Td = true
|
|
|
|
|
|
|
|
// default:
|
|
|
|
|
|
|
|
// logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else if entry.HasComponent(component.Signal3XH1ElectronicType) { // 3XH1信号机
|
|
|
|
|
|
|
|
// signal3XH1 := component.Signal3XH1ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
// switch cmd.Cmd {
|
|
|
|
|
|
|
|
// case SignalAspect_No:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_DDJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_ZXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_H:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_ZXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_L:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_LXJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_ZXJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_U:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_LXJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_ZXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_HU:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_ZXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH1.Z3XH1_YXJ).Td = true
|
|
|
|
|
|
|
|
// default:
|
|
|
|
|
|
|
|
// logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else if entry.HasComponent(component.Signal3XH2ElectronicType) { // 3XH2信号机
|
|
|
|
|
|
|
|
// signal3XH2 := component.Signal3XH2ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
// switch cmd.Cmd {
|
|
|
|
|
|
|
|
// case SignalAspect_No:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_DDJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_H:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_L:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_LXJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_HU:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH2.Z3XH2_YXJ).Td = true
|
|
|
|
|
|
|
|
// default:
|
|
|
|
|
|
|
|
// logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else if entry.HasComponent(component.Signal3XH3ElectronicType) { // 3XH3信号机
|
|
|
|
|
|
|
|
// signal3XH3 := component.Signal3XH3ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
// switch cmd.Cmd {
|
|
|
|
|
|
|
|
// case SignalAspect_No:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_DDJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_H:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_U:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_LXJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_YXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_HU:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH3.Z3XH3_YXJ).Td = true
|
|
|
|
|
|
|
|
// default:
|
|
|
|
|
|
|
|
// logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else if entry.HasComponent(component.Signal3XH4ElectronicType) { // 3XH4信号机
|
|
|
|
|
|
|
|
// signal3XH4 := component.Signal3XH4ElectronicType.Get(entry)
|
|
|
|
|
|
|
|
// switch cmd.Cmd {
|
|
|
|
|
|
|
|
// case SignalAspect_No:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_DDJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_ZXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_H:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_LXJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_ZXJ).Td = false
|
|
|
|
|
|
|
|
// case SignalAspect_L:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_LXJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_ZXJ).Td = true
|
|
|
|
|
|
|
|
// case SignalAspect_U:
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_DDJ).Td = false
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_LXJ).Td = true
|
|
|
|
|
|
|
|
// component.RelayDriveType.Get(signal3XH4.Z3XH4_ZXJ).Td = false
|
|
|
|
|
|
|
|
// default:
|
|
|
|
|
|
|
|
// logger().Error(fmt.Sprintf("信号机[%s]无法开放[%x]信号", uid, cmd.Cmd))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// logger().Error(fmt.Sprintf("信号机[%s]的型号未知", uid))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//for _, cmd := range frame.AxleSectionData.CmdList {
|
|
|
|
|
|
|
|
// if cmd.Cmd == 0x80 {
|
|
|
|
|
|
|
|
// uid := s.deviceTable.AxleSectionMap[cmd.Id].uid
|
|
|
|
|
|
|
|
// physicalSectionUid := s.sim.Repo.FindAxleCountingSection(uid).PhysicalSection().Id()
|
|
|
|
|
|
|
|
// _, err := fi.PhysicalSectionDrstDrive(s.sim.World, physicalSectionUid)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// logger().Error(fmt.Sprintf("计轴区段[%s]复位出错:%s", uid, err))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
////for _, cmd := range frame.SPKSData.CmdList {
|
|
|
|
|
|
|
|
//// uid := s.deviceTable.SpksMap[cmd.Id].uid
|
|
|
|
|
|
|
|
////}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Stop(stationCode string) {
|
|
|
|
func Stop(stationCode string) {
|
|
|
|
mu.Lock()
|
|
|
|
mu.Lock()
|
|
|
|
defer mu.Unlock()
|
|
|
|
defer mu.Unlock()
|
|
|
|
context := serviceContextMap[stationCode]
|
|
|
|
serviceContext := serviceContextMap[stationCode]
|
|
|
|
if context != nil {
|
|
|
|
if serviceContext != nil {
|
|
|
|
if context.client != nil {
|
|
|
|
if serviceContext.server != nil {
|
|
|
|
context.client.Close()
|
|
|
|
serviceContext.server.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
if context.server != nil {
|
|
|
|
|
|
|
|
context.server.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete(serviceContextMap, stationCode)
|
|
|
|
delete(serviceContextMap, stationCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -459,47 +482,39 @@ func (s *serviceContext) runCollectTask(ctx context.Context) {
|
|
|
|
case <-ctx.Done():
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
for _, driveMsg := range s.driveMsgSlice {
|
|
|
|
frame := s.collectDeviceState()
|
|
|
|
frame := s.collectDeviceState(driveMsg)
|
|
|
|
data := frame.encode()
|
|
|
|
data := frame.encode()
|
|
|
|
_, err := s.server.WriteToUdp(data, s.ioAddr)
|
|
|
|
err := s.client.Send(data)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logger().Error("向联锁发送数据失败", "error", err)
|
|
|
|
logger().Error("向联锁发送数据失败", "error", err)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
logger().Info(fmt.Sprintf("向联锁发送数据:%x", data))
|
|
|
|
logger().Info(fmt.Sprintf("向联锁发送数据:%x", data))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//frame := s.collectDeviceState()
|
|
|
|
|
|
|
|
//data := frame.encode()
|
|
|
|
|
|
|
|
//err := s.client.Send(data)
|
|
|
|
|
|
|
|
//if err != nil {
|
|
|
|
|
|
|
|
// logger().Error("向联锁发送数据失败", "error", err)
|
|
|
|
|
|
|
|
//} else {
|
|
|
|
|
|
|
|
// logger().Info(fmt.Sprintf("向联锁发送数据:%x", data))
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *serviceContext) collectDeviceState(msg *FromInterlockFrame) *ToInterlockFrame {
|
|
|
|
func (s *serviceContext) collectDeviceState() *ToInterlockFrame {
|
|
|
|
wd := entity.GetWorldData(s.sim.World)
|
|
|
|
wd := entity.GetWorldData(s.sim.World)
|
|
|
|
frame := &ToInterlockFrame{}
|
|
|
|
frame := &ToInterlockFrame{}
|
|
|
|
frame.WaysideCode = waysideCode
|
|
|
|
frame.WaysideCode = waysideCode
|
|
|
|
frame.InterlockCode = msg.InterlockCode
|
|
|
|
frame.InterlockCode = s.deviceTable.InterlockCode
|
|
|
|
//道岔
|
|
|
|
//道岔
|
|
|
|
for _, cmd := range msg.TurnoutData.CmdList {
|
|
|
|
for _, row := range s.deviceTable.TurnoutMap {
|
|
|
|
row := s.deviceTable.TurnoutMap[cmd.Id]
|
|
|
|
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
tp := component.TurnoutPositionType.Get(entry)
|
|
|
|
tp := component.TurnoutPositionType.Get(entry)
|
|
|
|
var stateByte byte
|
|
|
|
var stateByte byte
|
|
|
|
if tp.Dw {
|
|
|
|
if entry.HasComponent(component.TurnoutFaultCiqdType) {
|
|
|
|
stateByte = 0x01
|
|
|
|
stateByte = 0xff
|
|
|
|
} else if tp.Fw {
|
|
|
|
|
|
|
|
stateByte = 0x02
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
stateByte = 0x08
|
|
|
|
if tp.Dw {
|
|
|
|
|
|
|
|
stateByte = 0x01
|
|
|
|
|
|
|
|
} else if tp.Fw {
|
|
|
|
|
|
|
|
stateByte = 0x02
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
stateByte = 0x08
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frame.TurnoutStates = append(frame.TurnoutStates, &TurnoutState{
|
|
|
|
frame.TurnoutStates = append(frame.TurnoutStates, &TurnoutState{
|
|
|
|
Id: row.index,
|
|
|
|
Id: row.index,
|
|
|
@ -510,8 +525,7 @@ func (s *serviceContext) collectDeviceState(msg *FromInterlockFrame) *ToInterloc
|
|
|
|
return frame.TurnoutStates[i].Id < frame.TurnoutStates[j].Id
|
|
|
|
return frame.TurnoutStates[i].Id < frame.TurnoutStates[j].Id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
//屏蔽门
|
|
|
|
//屏蔽门
|
|
|
|
for _, cmd := range msg.PSDData.CmdList {
|
|
|
|
for _, row := range s.deviceTable.PsdMap {
|
|
|
|
row := s.deviceTable.PsdMap[cmd.Id]
|
|
|
|
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
psdState := component.PsdStateType.Get(entry)
|
|
|
|
psdState := component.PsdStateType.Get(entry)
|
|
|
|
mkxBytes := make([]byte, 0, 3)
|
|
|
|
mkxBytes := make([]byte, 0, 3)
|
|
|
@ -521,10 +535,22 @@ func (s *serviceContext) collectDeviceState(msg *FromInterlockFrame) *ToInterloc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mkxBytes = append(mkxBytes, GetStateByte(component.BitStateType.Get(wd.EntityMap[mkxRelayUid]).Val))
|
|
|
|
mkxBytes = append(mkxBytes, GetStateByte(component.BitStateType.Get(wd.EntityMap[mkxRelayUid]).Val))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var state byte
|
|
|
|
|
|
|
|
if psdState.Close {
|
|
|
|
|
|
|
|
state = 0x02
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
state = 0x01
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var hsjc byte
|
|
|
|
|
|
|
|
if psdState.InterlockRelease {
|
|
|
|
|
|
|
|
hsjc = 0xff
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
hsjc = 0xee
|
|
|
|
|
|
|
|
}
|
|
|
|
frame.PsdStates = append(frame.PsdStates, &PSDState{
|
|
|
|
frame.PsdStates = append(frame.PsdStates, &PSDState{
|
|
|
|
Id: row.index,
|
|
|
|
Id: row.index,
|
|
|
|
State: GetStateByte(psdState.Close),
|
|
|
|
State: state,
|
|
|
|
Hsjc: 0xff,
|
|
|
|
Hsjc: hsjc,
|
|
|
|
PCB: mkxBytes[0],
|
|
|
|
PCB: mkxBytes[0],
|
|
|
|
POB: mkxBytes[1],
|
|
|
|
POB: mkxBytes[1],
|
|
|
|
DPB: mkxBytes[2],
|
|
|
|
DPB: mkxBytes[2],
|
|
|
@ -534,8 +560,7 @@ func (s *serviceContext) collectDeviceState(msg *FromInterlockFrame) *ToInterloc
|
|
|
|
return frame.PsdStates[i].Id < frame.PsdStates[j].Id
|
|
|
|
return frame.PsdStates[i].Id < frame.PsdStates[j].Id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
//紧急停车
|
|
|
|
//紧急停车
|
|
|
|
for _, cmd := range msg.ESBData.CmdList {
|
|
|
|
for _, row := range s.deviceTable.EsbMap {
|
|
|
|
row := s.deviceTable.EsbMap[cmd.Id]
|
|
|
|
|
|
|
|
esb := s.sim.Repo.FindEsb(row.uid)
|
|
|
|
esb := s.sim.Repo.FindEsb(row.uid)
|
|
|
|
relay := wd.EntityMap[esb.RelayId()]
|
|
|
|
relay := wd.EntityMap[esb.RelayId()]
|
|
|
|
pla := wd.EntityMap[esb.PlaId()]
|
|
|
|
pla := wd.EntityMap[esb.PlaId()]
|
|
|
@ -543,14 +568,14 @@ func (s *serviceContext) collectDeviceState(msg *FromInterlockFrame) *ToInterloc
|
|
|
|
Id: row.index,
|
|
|
|
Id: row.index,
|
|
|
|
State: GetStateByte(!component.BitStateType.Get(relay).Val),
|
|
|
|
State: GetStateByte(!component.BitStateType.Get(relay).Val),
|
|
|
|
PlState: GetStateByte(component.BitStateType.Get(pla).Val),
|
|
|
|
PlState: GetStateByte(component.BitStateType.Get(pla).Val),
|
|
|
|
|
|
|
|
//PlState: 0x00,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Slice(frame.ESBStates, func(i, j int) bool {
|
|
|
|
sort.Slice(frame.ESBStates, func(i, j int) bool {
|
|
|
|
return frame.ESBStates[i].Id < frame.ESBStates[j].Id
|
|
|
|
return frame.ESBStates[i].Id < frame.ESBStates[j].Id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
//信号机
|
|
|
|
//信号机
|
|
|
|
for _, cmd := range msg.SignalData.CmdList {
|
|
|
|
for _, row := range s.deviceTable.SignalMap {
|
|
|
|
row := s.deviceTable.SignalMap[cmd.Id]
|
|
|
|
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
lights := component.SignalLightsType.Get(entry)
|
|
|
|
lights := component.SignalLightsType.Get(entry)
|
|
|
|
isL := false
|
|
|
|
isL := false
|
|
|
@ -598,11 +623,10 @@ func (s *serviceContext) collectDeviceState(msg *FromInterlockFrame) *ToInterloc
|
|
|
|
return frame.SignalStates[i].Id < frame.SignalStates[j].Id
|
|
|
|
return frame.SignalStates[i].Id < frame.SignalStates[j].Id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
//计轴区段
|
|
|
|
//计轴区段
|
|
|
|
for _, cmd := range msg.AxleSectionData.CmdList {
|
|
|
|
for _, row := range s.deviceTable.AxleSectionMap {
|
|
|
|
row := s.deviceTable.AxleSectionMap[cmd.Id]
|
|
|
|
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
entry := wd.EntityMap[row.uid]
|
|
|
|
sectionState := component.AxleCountingSectionStateType.Get(entry)
|
|
|
|
sectionState := component.AxleCountingSectionStateType.Get(entry)
|
|
|
|
var stateByte byte = 0x40
|
|
|
|
var stateByte byte = 0x00
|
|
|
|
if sectionState.Occupied {
|
|
|
|
if sectionState.Occupied {
|
|
|
|
stateByte = 0x40
|
|
|
|
stateByte = 0x40
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -615,15 +639,15 @@ func (s *serviceContext) collectDeviceState(msg *FromInterlockFrame) *ToInterloc
|
|
|
|
return frame.AxleSectionStates[i].Id < frame.AxleSectionStates[j].Id
|
|
|
|
return frame.AxleSectionStates[i].Id < frame.AxleSectionStates[j].Id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
//SPKS
|
|
|
|
//SPKS
|
|
|
|
for _, cmd := range msg.SPKSData.CmdList {
|
|
|
|
for _, row := range s.deviceTable.SpksMap {
|
|
|
|
row := s.deviceTable.SpksMap[cmd.Id]
|
|
|
|
|
|
|
|
spks := s.sim.Repo.FindSpks(row.uid)
|
|
|
|
spks := s.sim.Repo.FindSpks(row.uid)
|
|
|
|
relay := wd.EntityMap[spks.Relay()]
|
|
|
|
relay := wd.EntityMap[spks.Relay()]
|
|
|
|
pla := wd.EntityMap[spks.PlaId()]
|
|
|
|
pla := wd.EntityMap[spks.PlaId()]
|
|
|
|
frame.SPKSStates = append(frame.SPKSStates, &SPKSState{
|
|
|
|
frame.SPKSStates = append(frame.SPKSStates, &SPKSState{
|
|
|
|
Id: row.index,
|
|
|
|
Id: row.index,
|
|
|
|
State: GetStateByte(component.BitStateType.Get(relay).Val),
|
|
|
|
State: GetStateByte(!component.BitStateType.Get(relay).Val),
|
|
|
|
PlState: GetStateByte(component.BitStateType.Get(pla).Val),
|
|
|
|
PlState: GetStateByte(component.BitStateType.Get(pla).Val),
|
|
|
|
|
|
|
|
//PlState: 0xff,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Slice(frame.SPKSStates, func(i, j int) bool {
|
|
|
|
sort.Slice(frame.SPKSStates, func(i, j int) bool {
|
|
|
@ -632,149 +656,6 @@ func (s *serviceContext) collectDeviceState(msg *FromInterlockFrame) *ToInterloc
|
|
|
|
return frame
|
|
|
|
return frame
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//func (s *serviceContext) collectDeviceState() *ToInterlockFrame {
|
|
|
|
|
|
|
|
// wd := entity.GetWorldData(s.sim.World)
|
|
|
|
|
|
|
|
// frame := &ToInterlockFrame{}
|
|
|
|
|
|
|
|
// frame.WaysideCode = waysideCode
|
|
|
|
|
|
|
|
// frame.InterlockCode = s.deviceTable.InterlockCode
|
|
|
|
|
|
|
|
// //道岔
|
|
|
|
|
|
|
|
// for _, row := range s.deviceTable.TurnoutMap {
|
|
|
|
|
|
|
|
// entry := wd.EntityMap[row.uid]
|
|
|
|
|
|
|
|
// tp := component.TurnoutPositionType.Get(entry)
|
|
|
|
|
|
|
|
// var stateByte byte
|
|
|
|
|
|
|
|
// if tp.Dw {
|
|
|
|
|
|
|
|
// stateByte = 0x01
|
|
|
|
|
|
|
|
// } else if tp.Fw {
|
|
|
|
|
|
|
|
// stateByte = 0x02
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// stateByte = 0x08
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// frame.TurnoutStates = append(frame.TurnoutStates, &TurnoutState{
|
|
|
|
|
|
|
|
// Id: row.index,
|
|
|
|
|
|
|
|
// State: stateByte,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// sort.Slice(frame.TurnoutStates, func(i, j int) bool {
|
|
|
|
|
|
|
|
// return frame.TurnoutStates[i].Id < frame.TurnoutStates[j].Id
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// //屏蔽门
|
|
|
|
|
|
|
|
// for _, row := range s.deviceTable.PsdMap {
|
|
|
|
|
|
|
|
// entry := wd.EntityMap[row.uid]
|
|
|
|
|
|
|
|
// psdState := component.PsdStateType.Get(entry)
|
|
|
|
|
|
|
|
// mkxBytes := make([]byte, 0, 3)
|
|
|
|
|
|
|
|
// for _, mkxRelayUid := range []string{row.relateDeviceMap[POB], row.relateDeviceMap[PCB], row.relateDeviceMap[DPB]} {
|
|
|
|
|
|
|
|
// if mkxRelayUid == "" {
|
|
|
|
|
|
|
|
// continue
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// mkxBytes = append(mkxBytes, GetStateByte(component.BitStateType.Get(wd.EntityMap[mkxRelayUid]).Val))
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// frame.PsdStates = append(frame.PsdStates, &PSDState{
|
|
|
|
|
|
|
|
// Id: row.index,
|
|
|
|
|
|
|
|
// State: GetStateByte(psdState.Close),
|
|
|
|
|
|
|
|
// Hsjc: 0xff,
|
|
|
|
|
|
|
|
// PCB: mkxBytes[0],
|
|
|
|
|
|
|
|
// POB: mkxBytes[1],
|
|
|
|
|
|
|
|
// DPB: mkxBytes[2],
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// sort.Slice(frame.PsdStates, func(i, j int) bool {
|
|
|
|
|
|
|
|
// return frame.PsdStates[i].Id < frame.PsdStates[j].Id
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// //紧急停车
|
|
|
|
|
|
|
|
// for _, row := range s.deviceTable.EsbMap {
|
|
|
|
|
|
|
|
// esb := s.sim.Repo.FindEsb(row.uid)
|
|
|
|
|
|
|
|
// relay := wd.EntityMap[esb.RelayId()]
|
|
|
|
|
|
|
|
// pla := wd.EntityMap[esb.PlaId()]
|
|
|
|
|
|
|
|
// frame.ESBStates = append(frame.ESBStates, &ESBState{
|
|
|
|
|
|
|
|
// Id: row.index,
|
|
|
|
|
|
|
|
// State: GetStateByte(!component.BitStateType.Get(relay).Val),
|
|
|
|
|
|
|
|
// PlState: GetStateByte(component.BitStateType.Get(pla).Val),
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// sort.Slice(frame.ESBStates, func(i, j int) bool {
|
|
|
|
|
|
|
|
// return frame.ESBStates[i].Id < frame.ESBStates[j].Id
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// //信号机
|
|
|
|
|
|
|
|
// for _, row := range s.deviceTable.SignalMap {
|
|
|
|
|
|
|
|
// entry := wd.EntityMap[row.uid]
|
|
|
|
|
|
|
|
// lights := component.SignalLightsType.Get(entry)
|
|
|
|
|
|
|
|
// isL := false
|
|
|
|
|
|
|
|
// isH := false
|
|
|
|
|
|
|
|
// isU := false
|
|
|
|
|
|
|
|
// isA := false
|
|
|
|
|
|
|
|
// isB := false
|
|
|
|
|
|
|
|
// for _, light := range lights.Lights {
|
|
|
|
|
|
|
|
// switch {
|
|
|
|
|
|
|
|
// case light.HasComponent(component.LdTag):
|
|
|
|
|
|
|
|
// isL = component.BitStateType.Get(light).Val
|
|
|
|
|
|
|
|
// case light.HasComponent(component.HdTag):
|
|
|
|
|
|
|
|
// isH = component.BitStateType.Get(light).Val
|
|
|
|
|
|
|
|
// case light.HasComponent(component.UdTag):
|
|
|
|
|
|
|
|
// isU = component.BitStateType.Get(light).Val
|
|
|
|
|
|
|
|
// case light.HasComponent(component.BdTag):
|
|
|
|
|
|
|
|
// isB = component.BitStateType.Get(light).Val
|
|
|
|
|
|
|
|
// case light.HasComponent(component.AdTag):
|
|
|
|
|
|
|
|
// isA = component.BitStateType.Get(light).Val
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// var stateByte byte
|
|
|
|
|
|
|
|
// if isH && isU {
|
|
|
|
|
|
|
|
// stateByte = 0x03
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// switch {
|
|
|
|
|
|
|
|
// case isL:
|
|
|
|
|
|
|
|
// stateByte = 0x04
|
|
|
|
|
|
|
|
// case isH:
|
|
|
|
|
|
|
|
// stateByte = 0x01
|
|
|
|
|
|
|
|
// case isU:
|
|
|
|
|
|
|
|
// stateByte = 0x02
|
|
|
|
|
|
|
|
// case isB:
|
|
|
|
|
|
|
|
// stateByte = 0x08
|
|
|
|
|
|
|
|
// case isA:
|
|
|
|
|
|
|
|
// stateByte = 0x09
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// frame.SignalStates = append(frame.SignalStates, &SignalState{
|
|
|
|
|
|
|
|
// Id: row.index,
|
|
|
|
|
|
|
|
// State: stateByte,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// sort.Slice(frame.SignalStates, func(i, j int) bool {
|
|
|
|
|
|
|
|
// return frame.SignalStates[i].Id < frame.SignalStates[j].Id
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// //计轴区段
|
|
|
|
|
|
|
|
// for _, row := range s.deviceTable.AxleSectionMap {
|
|
|
|
|
|
|
|
// entry := wd.EntityMap[row.uid]
|
|
|
|
|
|
|
|
// sectionState := component.AxleCountingSectionStateType.Get(entry)
|
|
|
|
|
|
|
|
// var stateByte byte = 0x40
|
|
|
|
|
|
|
|
// if sectionState.Occupied {
|
|
|
|
|
|
|
|
// stateByte = 0x40
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// frame.AxleSectionStates = append(frame.AxleSectionStates, &AxleSectionState{
|
|
|
|
|
|
|
|
// Id: row.index,
|
|
|
|
|
|
|
|
// State: stateByte,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// sort.Slice(frame.AxleSectionStates, func(i, j int) bool {
|
|
|
|
|
|
|
|
// return frame.AxleSectionStates[i].Id < frame.AxleSectionStates[j].Id
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// //SPKS
|
|
|
|
|
|
|
|
// for _, row := range s.deviceTable.SpksMap {
|
|
|
|
|
|
|
|
// spks := s.sim.Repo.FindSpks(row.uid)
|
|
|
|
|
|
|
|
// relay := wd.EntityMap[spks.Relay()]
|
|
|
|
|
|
|
|
// pla := wd.EntityMap[spks.PlaId()]
|
|
|
|
|
|
|
|
// frame.SPKSStates = append(frame.SPKSStates, &SPKSState{
|
|
|
|
|
|
|
|
// Id: row.index,
|
|
|
|
|
|
|
|
// State: GetStateByte(component.BitStateType.Get(relay).Val),
|
|
|
|
|
|
|
|
// PlState: GetStateByte(component.BitStateType.Get(pla).Val),
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// sort.Slice(frame.SPKSStates, func(i, j int) bool {
|
|
|
|
|
|
|
|
// return frame.SPKSStates[i].Id < frame.SPKSStates[j].Id
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// return frame
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func logger() *slog.Logger {
|
|
|
|
func logger() *slog.Logger {
|
|
|
|
loggerInit.Do(func() {
|
|
|
|
loggerInit.Do(func() {
|
|
|
|
privateLogger = slog.Default().With("tag", logTag)
|
|
|
|
privateLogger = slog.Default().With("tag", logTag)
|
|
|
|