From 42f299f55340a251ea01e15652b80f5c4d9da4e6 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Thu, 23 May 2024 19:14:10 +0800 Subject: [PATCH] =?UTF-8?q?[bug]=E4=BF=AE=E6=94=B9=E8=81=94=E9=94=81?= =?UTF-8?q?=E9=80=9A=E4=BF=A1=E9=80=BB=E8=BE=91=E4=B8=AD=E7=9A=84=E7=BC=96?= =?UTF-8?q?=E7=A0=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rts-sim-testing-message | 2 +- third_party/message/interlock.go | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/rts-sim-testing-message b/rts-sim-testing-message index aac1484..189cabe 160000 --- a/rts-sim-testing-message +++ b/rts-sim-testing-message @@ -1 +1 @@ -Subproject commit aac1484a6f64cc43146cabd89784b92c933a0298 +Subproject commit 189cabea725167f98c15d0971ee20d01b044ce05 diff --git a/third_party/message/interlock.go b/third_party/message/interlock.go index 305eccf..2e077a4 100644 --- a/third_party/message/interlock.go +++ b/third_party/message/interlock.go @@ -1,6 +1,9 @@ package message -import "fmt" +import ( + "fmt" + "math" +) // 消息包头解析 type interlockMsgPkgHeader struct { @@ -81,15 +84,25 @@ func (m *InterlockSendMsgPkg) SetSerialNumber(serialNumber uint8) { func (m *InterlockSendMsgPkg) Encode() []byte { var data []byte data = append(data, m.header.encode()...) - 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] + bitLen := len(m.info) + byteLen := int(math.Ceil(float64(bitLen) / 8)) + infoBytes := make([]byte, byteLen) + for i, b := range m.info { + if b { + 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()...) return data }