[bug]修改联锁通信逻辑中的编码bug

This commit is contained in:
thesai 2024-05-23 19:14:10 +08:00
parent a4b761f720
commit 42f299f553
2 changed files with 22 additions and 9 deletions

@ -1 +1 @@
Subproject commit aac1484a6f64cc43146cabd89784b92c933a0298 Subproject commit 189cabea725167f98c15d0971ee20d01b044ce05

View File

@ -1,6 +1,9 @@
package message package message
import "fmt" import (
"fmt"
"math"
)
// 消息包头解析 // 消息包头解析
type interlockMsgPkgHeader struct { type interlockMsgPkgHeader struct {
@ -81,15 +84,25 @@ func (m *InterlockSendMsgPkg) SetSerialNumber(serialNumber uint8) {
func (m *InterlockSendMsgPkg) Encode() []byte { func (m *InterlockSendMsgPkg) Encode() []byte {
var data []byte var data []byte
data = append(data, m.header.encode()...) data = append(data, m.header.encode()...)
for index, length, cycles := 0, len(m.info), len(m.info)/boolsToByteArrLen; index < cycles; index++ { bitLen := len(m.info)
startIndex := index * boolsToByteArrLen byteLen := int(math.Ceil(float64(bitLen) / 8))
toByteArr := [8]bool{} infoBytes := make([]byte, byteLen)
for i := 0; i < boolsToByteArrLen && startIndex < length; i++ { for i, b := range m.info {
startIndex = startIndex + i if b {
toByteArr[i] = m.info[startIndex+i] infoBytes[i/8] = infoBytes[i/8] + (1 << (i % 8))
} }
data = append(data, boolsToByte(toByteArr))
} }
data = append(data, infoBytes...)
//for index, length, cycles := 0, len(m.info), len(m.info)/boolsToByteArrLen; index < cycles; index++ {
// startIndex := index * boolsToByteArrLen
// toByteArr := [8]bool{}
// for i := 0; i < boolsToByteArrLen && startIndex < length; i++ {
// startIndex = startIndex + i
// toByteArr[i] = m.info[startIndex+i]
// }
// data = append(data, boolsToByte(toByteArr))
//}
data = append(data, m.tail.encode()...) data = append(data, m.tail.encode()...)
return data return data
} }