From 497bbad8ed3d791bcbc3bcd988ea771d547d6623 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Fri, 31 May 2024 14:25:59 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]11=E5=8F=B7=E7=BA=BF?= =?UTF-8?q?=E8=81=94=E9=94=81=E6=95=B0=E6=8D=AE=E8=A7=A3=E6=9E=90=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=B4=97=E8=BD=A6=E6=9C=BA=E6=95=B0=E6=8D=AE=EF=BC=9B?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=B4=A7=E6=80=A5=E5=81=9C=E8=BD=A6=E5=90=8E?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third_party/interlock/beijing11/msg.go | 30 ++++++++++----------- third_party/interlock/beijing11/msg_test.go | 8 ++++-- 2 files changed, 21 insertions(+), 17 deletions(-) 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() //}