rts-sim-testing-service/third_party/interlock/beijing11/msg.go
thesai cac309f4b1
All checks were successful
local-test分支打包构建docker并发布运行 / Docker-Build (push) Successful in 1m31s
[新增]11号线联锁通信所属线路配置;11号线联锁通信原始数据及解析后的json数据日志
2024-05-29 17:20:51 +08:00

340 lines
9.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package beijing11
import (
"encoding/binary"
"fmt"
"joylink.club/bj-rtsts-server/sys_error"
)
// FromInterlockFrame 来自联锁的数据帧
type FromInterlockFrame struct {
Len uint16
InterlockCode uint16 //联锁ID
WaysideCode uint16 //轨旁ID
TurnoutData *DeviceData //道岔数据
PSDData *DeviceData //屏蔽门数据
ESBData *ESBData //紧急停车按钮数据
HoldTrainData *HoldTrainData //扣车按钮数据
SignalData *DeviceData //信号机数据
AxleSectionData *DeviceData //计轴区段数据
WrzfData *DeviceData //无人折返数据
FymData *DeviceData //防淹门数据
SPKSData *SPKSData //SPKS数据
CkmData *DeviceData //车库门数据
XcjData *DeviceData //洗车机数据
}
func (f *FromInterlockFrame) Decode(data []byte) error {
f.Len = binary.BigEndian.Uint16(data[1:3])
if int(f.Len) != len(data)-3 {
return sys_error.New(fmt.Sprintf("%s数据长度不对[%d:%d]", logTag, f.Len, len(data)-3))
}
f.InterlockCode = binary.BigEndian.Uint16(data[3:5])
f.WaysideCode = binary.BigEndian.Uint16(data[5:7])
turnoutData, i := decodeDeviceData(data, 7)
f.TurnoutData = turnoutData
psdData, i := decodeDeviceData(data, i)
f.PSDData = psdData
esbData, i := decodeESBData(data, i)
f.ESBData = esbData
holdTrainData, i := decodeHoldTrainData(data, i)
f.HoldTrainData = holdTrainData
signalData, i := decodeDeviceData(data, i)
f.SignalData = signalData
axleSectionData, i := decodeDeviceData(data, i)
f.AxleSectionData = axleSectionData
wrzfData, i := decodeDeviceData(data, i)
f.WrzfData = wrzfData
fymData, i := decodeDeviceData(data, i)
f.FymData = fymData
spksData, i := decodeSPKSData(data, i)
f.SPKSData = spksData
ckmData, i := decodeDeviceData(data, i)
f.CkmData = ckmData
xcjData, i := decodeDeviceData(data, i)
f.XcjData = xcjData
return nil
}
func decodeDeviceData(data []byte, index uint16) (*DeviceData, uint16) {
data = data[index:]
num := binary.BigEndian.Uint16(data[0:2])
i := 2 + 3*num
data = data[2:i]
var cmdList []*DeviceCmd
for i := 0; i < len(data); i += 3 {
cmdList = append(cmdList, &DeviceCmd{
Id: binary.BigEndian.Uint16(data[i : i+2]),
Cmd: data[i+2],
})
}
deviceData := &DeviceData{
Num: num,
CmdList: cmdList,
}
return deviceData, index + i
}
func decodeESBData(data []byte, index uint16) (*ESBData, uint16) {
data = data[index:]
num := binary.BigEndian.Uint16(data[0:2])
nextIndex := 2 + 6*num
data = data[2:nextIndex]
var cmdList []*ESBCmd
for i := 0; i < len(data); i += 6 {
cmdList = append(cmdList, &ESBCmd{
Id: binary.BigEndian.Uint16(data[i : i+2]),
JjtcCmd: data[i+2],
JjtcplCmd: data[i+3],
JjtcfmqCmd: data[i+4],
Ess1Cmd: data[i+5],
})
}
deviceData := &ESBData{
Num: num,
CmdList: cmdList,
}
return deviceData, index + nextIndex
}
func decodeHoldTrainData(data []byte, index uint16) (*HoldTrainData, uint16) {
data = data[index:]
num := binary.BigEndian.Uint16(data[0:2])
nextIndex := 2 + 6*num
data = data[2:nextIndex]
var cmdList []*HoldTrainCmd
for i := 0; i < len(data); i += 6 {
cmdList = append(cmdList, &HoldTrainCmd{
Id: binary.BigEndian.Uint16(data[i : i+2]),
KcCmd: data[i+2],
KcplCmd: data[i+3],
Kc2Cmd: data[i+4],
Kcpl2Cmd: data[i+5],
})
}
deviceData := &HoldTrainData{
Num: num,
CmdList: cmdList,
}
return deviceData, index + nextIndex
}
func decodeSPKSData(data []byte, index uint16) (*SPKSData, uint16) {
data = data[index:]
num := binary.BigEndian.Uint16(data[0:2])
nextIndex := 2 + 4*num
data = data[2:nextIndex]
var cmdList []*SPKSCmd
for i := 0; i < len(data); i += 4 {
cmdList = append(cmdList, &SPKSCmd{
Id: binary.BigEndian.Uint16(data[i : i+2]),
SPKSCmd: data[i+2],
SPKSPLCmd: data[i+3],
})
}
deviceData := &SPKSData{
Num: num,
CmdList: cmdList,
}
return deviceData, index + nextIndex
}
type DeviceData struct {
Num uint16 //设备数量
CmdList []*DeviceCmd
}
type ESBData struct {
Num uint16 //紧急停车按钮的数量
CmdList []*ESBCmd
}
type HoldTrainData struct {
Num uint16 //扣车的数量
CmdList []*HoldTrainCmd
}
type SPKSData struct {
Num uint16 //SPKS的数量
CmdList []*SPKSCmd
}
type ESBCmd struct {
Id uint16 //紧急停车ID
JjtcCmd byte //紧急停车按钮命令
JjtcplCmd byte //紧急停车旁路按钮命令
JjtcfmqCmd byte //紧急停车蜂鸣器命令
Ess1Cmd byte //Ess1指示灯状态
}
type HoldTrainCmd struct {
Id uint16 //扣车ID
KcCmd byte //扣车命令
KcplCmd byte //扣车旁路命令
Kc2Cmd byte //2号扣车命令
Kcpl2Cmd byte //2号扣车旁路命令
}
type SPKSCmd struct {
Id uint16 //SPKS ID
SPKSCmd byte //SPKS按钮
SPKSPLCmd byte //SPKSPL按钮
}
type DeviceCmd struct {
Id uint16 //设备ID
Cmd byte //设备命令
}
// ToInterlockFrame 发往联锁的数据帧
type ToInterlockFrame struct {
Len uint16
WaysideCode uint16
InterlockCode uint16
TurnoutData *ToInterlockTurnoutData //道岔数据
PSDData *ToInterlockPSDData //屏蔽门数据
ESBData *ToInterlockESBData //紧急停车按钮数据
HoldTrainData *ToInterlockHoldTrainData //扣车按钮数据
SignalData *ToInterlockSignalData //信号机数据
AxleSectionData *ToInterlockAxleSectionData //计轴区段数据
WrzfData *ToInterlockWrzfData //无人折返数据
FymData *ToInterlockFymData //防淹门数据
SPKSData *ToInterlockSPKSData //SPKS数据
CkmData *ToInterlockCkmData //车库门数据
XcjData *ToInterlockXcjData //洗车机数据
}
type ToInterlockTurnoutData struct {
Num uint16 //该联锁集中区包含的道岔数量
StateList []*TurnoutState
}
type ToInterlockPSDData struct {
Num uint16 //该联锁集中区包含的屏蔽门数量
StateList []*PSDState
}
type ToInterlockESBData struct {
Num uint16 //紧急停车按钮数量
StateList []*ESBState
}
type ToInterlockHoldTrainData struct {
Num uint16 //扣车数量
StateList []*HoldTrainState
}
type ToInterlockSignalData struct {
Num uint16 //该联锁集中区信号机的数量
StateList []*SignalState
}
type ToInterlockAxleSectionData struct {
Num uint16 //该联锁集中区计轴区段的数量
StateList []*AxleSectionState
}
type ToInterlockWrzfData struct {
Num uint16 //该联锁集中区无人折返的数量
StateList []*WrzfState
}
type ToInterlockFymData struct {
Num uint16 //该联锁集中区防<E58CBA><E998B2>门的数量
StateList []*FymState
}
type ToInterlockSPKSData struct {
Num uint16 //SPKS数量
StateList []*SPKSState
}
type ToInterlockCkmData struct {
Num uint16 //车库门数量
StateList []*CkmState
}
type ToInterlockXcjData struct {
Num uint16 //洗车机数量
StateList []*XcjState
}
type TurnoutState struct {
Id uint16 //道岔ID
State byte //道岔的采集状态
Alarm byte //道岔的报警状态
Current1 byte //转辙机1电流值单位A
Current2 byte //转辙机2电流值单位A
}
type PSDState struct {
Id uint16 //屏蔽门ID
State byte //屏蔽门开关门状态
Hsjc byte //互锁解除状态
PCB byte //PCB状态
POB byte //POB状态
DPB byte //DPB状态
}
type ESBState struct {
Id uint16 //紧急停车ID
State byte //紧急停车按钮状态
PlState byte //紧急停车按钮旁路状态
ESS byte //ESS状态按下55抬起aa
}
type HoldTrainState struct {
Id uint16 //扣车ID
State byte //扣车按钮状态按下55抬起aa
PlState byte //扣车按钮旁路状态按下55抬起aa
State2 byte //2号扣车按钮状态55开启aa关闭
PlState2 byte //2号扣车按钮旁路状态55开启aa关闭
}
type SignalState struct {
Id uint16 //信号机ID
State byte //信号机的采集状态
Current byte //信号机当前亮灯的电流值
}
type AxleSectionState struct {
Id uint16 //计轴区段Id
State byte //计轴区段的采集状态
}
type WrzfState struct {
Id uint16 //无人折返ID
State byte //无人折返的采集状态
}
type FymState struct {
Id uint16 //防淹门ID
OpenAndLock byte //防淹门打开锁闭状态
CloseReq byte //防淹门关闭请求状态
}
type SPKSState struct {
Id uint16 //SPKS ID
State byte //SPKS按钮状态
PlState byte //SPKSPL按钮状态
}
type CkmState struct {
Id uint16 //车库门ID
State byte //车库门采集状态
ModeState byte //车库门模式状态
FaultState byte //车库门故障状态
}
type XcjState struct {
Id uint16 //洗车机ID
Ready byte //洗车机就绪状态
ResponseConfirm byte //回复确认状态
GoState1 byte //出发状态1
GoState2 byte //出发状态2
StopState byte //急停状态
BackConfirm byte //返回确认状态
BackMode byte //模式
}