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 1/2] =?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 } From 9fbc60e93a095a99144861a3011ad47b33d7fc43 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Thu, 23 May 2024 19:19:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]=E8=81=94=E9=94=81?= =?UTF-8?q?=E9=80=9A=E4=BF=A1=E6=97=A5=E5=BF=97=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third_party/interlock/beijing12/interlock.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/interlock/beijing12/interlock.go b/third_party/interlock/beijing12/interlock.go index 0af4c7a..13e8198 100644 --- a/third_party/interlock/beijing12/interlock.go +++ b/third_party/interlock/beijing12/interlock.go @@ -53,7 +53,7 @@ type interlockProxy struct { // 驱动信息进行转发 func (i *interlockProxy) handleDriverInfo(b []byte) { - slog.Info("收到联锁驱动继电器数据:", fmt.Sprintf("%x", b)) + slog.Info(fmt.Sprintf("收到联锁驱动继电器数据:%x", b)) handler := i.manager if handler != nil { handler.HandleInterlockDriverInfo(i.runConfig.Code, b) @@ -106,7 +106,7 @@ func (i *interlockProxy) collectInfoStateTask(ctx context.Context) { if err != nil { slog.Error("向联锁发送继电器状态失败:", err) } else { - slog.Error("向联锁发送继电器数据成功:", fmt.Sprintf("%x", collectInfoState.Encode())) + slog.Error(fmt.Sprintf("向联锁发送继电器数据成功:%x", collectInfoState.Encode())) } } time.Sleep(time.Millisecond * InterlockMessageSendInterval)