diff --git a/third_party/interlock/beijing11/msg.go b/third_party/interlock/beijing11/msg.go index 4005824..5ea7561 100644 --- a/third_party/interlock/beijing11/msg.go +++ b/third_party/interlock/beijing11/msg.go @@ -19,7 +19,7 @@ type FromInterlockFrame struct { FymData *DeviceData //防淹门数据 SPKSData *SPKSData //SPKS数据 CkmData *DeviceData //车库门数据 - XcjData *DeviceData //洗车机数据 + //XcjData *DeviceData //洗车机数据 } func (f *FromInterlockFrame) Decode(data []byte) error { @@ -50,8 +50,8 @@ func (f *FromInterlockFrame) Decode(data []byte) error { f.SPKSData = spksData ckmData, i := decodeDeviceData(data, i) f.CkmData = ckmData - xcjData, i := decodeDeviceData(data, i) - f.XcjData = xcjData + //xcjData, i := decodeDeviceData(data, i) + //f.XcjData = xcjData return nil } @@ -77,16 +77,16 @@ func decodeDeviceData(data []byte, index uint16) (*DeviceData, uint16) { func decodeESBData(data []byte, index uint16) (*ESBData, uint16) { data = data[index:] num := binary.BigEndian.Uint16(data[0:2]) - nextIndex := 2 + 6*num + nextIndex := 2 + 4*num data = data[2:nextIndex] var cmdList []*ESBCmd - for i := 0; i < len(data); i += 6 { + for i := 0; i < len(data); i += 4 { 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], + 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{ @@ -159,11 +159,11 @@ type SPKSData struct { } type ESBCmd struct { - Id uint16 //紧急停车ID - JjtcCmd byte //紧急停车按钮命令 - JjtcplCmd byte //紧急停车旁路按钮命令 - JjtcfmqCmd byte //紧急停车蜂鸣器命令 - Ess1Cmd byte //Ess1指示灯状态 + Id uint16 //紧急停车ID + JjtcCmd byte //紧急停车按钮命令 + JjtcplCmd byte //紧急停车旁路按钮命令 + //JjtcfmqCmd byte //紧急停车蜂鸣器命令 + //Ess1Cmd byte //Ess1指示灯状态 } type HoldTrainCmd struct { diff --git a/third_party/interlock/beijing11/msg_test.go b/third_party/interlock/beijing11/msg_test.go index c131fc7..6a38504 100644 --- a/third_party/interlock/beijing11/msg_test.go +++ b/third_party/interlock/beijing11/msg_test.go @@ -16,7 +16,7 @@ func TestFromInterlockFrame_Decode(t *testing.T) { data = binary.BigEndian.AppendUint16(data, interlockCode) data = binary.BigEndian.AppendUint16(data, waysideCode) //填充设备数据 - deviceCmdCount := []int{1, 1, 4, 4, 1, 1, 1, 1, 2, 1, 1} + deviceCmdCount := []int{1, 1, 2, 4, 1, 1, 1, 1, 2, 1} for i, count := range deviceCmdCount { data = binary.BigEndian.AppendUint16(data, uint16(i)) //设备数量 for j := 0; j < i; j++ { @@ -26,6 +26,10 @@ func TestFromInterlockFrame_Decode(t *testing.T) { } } } + //保留字节及CRC(先瞎填吧,现在没有校验) + for i := 0; i < 14; i++ { + data = append(data, 0) + } //替换长度 len := uint16(len(data) - 3) data[1] = byte(len >> 8) @@ -38,7 +42,7 @@ func TestFromInterlockFrame_Decode(t *testing.T) { t.FailNow() } marshal, _ := json.Marshal(f) - fmt.Println(marshal) + fmt.Println(string(marshal)) //if f.InterlockCode != interlockCode { // t.Error() //}