From 5f6a768b35d1d533e7bba8d64f01586f8238800e Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 30 Oct 2023 15:23:56 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=AF=B9=E8=81=94=E9=94=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=97=E6=B6=88=E6=81=AF=E8=A7=A3=E6=9E=90=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third_party/message/interlock.go | 36 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/third_party/message/interlock.go b/third_party/message/interlock.go index 4edc56a..3868239 100644 --- a/third_party/message/interlock.go +++ b/third_party/message/interlock.go @@ -90,11 +90,19 @@ type InterlockReceiveMsgPkg struct { toagent_len int32 et_out_num int32 tcc_output_len int32 - Header *InterlockMsgPkgHeader // 包头 - SyncZone []bool // 同步区状态 - DriveInfo []bool // 驱动数据 - TccInfo []bool // 应答器报文 - Tail *InterlockMsgPkgTail // 包尾 + Header *InterlockMsgPkgHeader // 包头 + SyncZone []byte // 同步区状态 + DriveInfo []bool // 驱动数据 + TccInfo []*InterlockResponderMsgPkg // 应答器报文 + Tail *InterlockMsgPkgTail // 包尾 +} + +// 应答器数据格式 +type InterlockResponderMsgPkg struct { + Index byte + InternalIndex byte + Reserve byte + MsgInfo []byte } // ET_OUT_NUM、TOAGENTLEN、TCC_OUTPUT_LEN(应答器数量*131)的具体数值取决于数据配置。 @@ -115,7 +123,7 @@ func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error { // 同步区状态 preIndex = lastIndex lastIndex = lastIndex + t.toagent_len - t.parseByte(t.SyncZone, buf, preIndex, lastIndex) + t.SyncZone = buf[preIndex:lastIndex] // 驱动数据 preIndex = lastIndex lastIndex = lastIndex + t.et_out_num @@ -123,7 +131,7 @@ func (t *InterlockReceiveMsgPkg) Decode(buf []byte) error { // 应答器报文 preIndex = lastIndex lastIndex = lastIndex + t.tcc_output_len - t.parseByte(t.TccInfo, buf, preIndex, lastIndex) + t.TccInfo = parseResponder(buf, preIndex, lastIndex) // 包尾 t.Tail.Decode(buf) return nil @@ -137,3 +145,17 @@ func (t *InterlockReceiveMsgPkg) parseByte(r []bool, buf []byte, start, end int3 } } } + +func parseResponder(buf []byte, start, end int32) []*InterlockResponderMsgPkg { + var msgs []*InterlockResponderMsgPkg + for i := start; i < end; i = i + 128 { + b := buf[i : i+128] + msgs = append(msgs, &InterlockResponderMsgPkg{ + Index: b[0], + InternalIndex: b[1], + Reserve: b[2], + MsgInfo: b[3:], + }) + } + return msgs +}