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 +}