【对联锁接受消息解析】
This commit is contained in:
parent
71f8163cab
commit
5f6a768b35
36
third_party/message/interlock.go
vendored
36
third_party/message/interlock.go
vendored
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user