From 7e38a912d49dda133e2fc4c9cbc70bfec856fd2d Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Wed, 24 Jul 2024 18:27:41 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]crc32=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third_party/message/rssp_code.go | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/third_party/message/rssp_code.go b/third_party/message/rssp_code.go index 466cdd5..877f8e6 100644 --- a/third_party/message/rssp_code.go +++ b/third_party/message/rssp_code.go @@ -8,9 +8,9 @@ var ( // crc16多项式为G(x)=X16+X11+X4+1 RSSP_I_CRC16 = crc.NewHash(&crc.Parameters{Width: 16, Polynomial: 0x0811, Init: 0x0, ReflectIn: true, ReflectOut: true, FinalXor: 0x0}) // 通道1 crc32多项式为0x100d4e63 - RSSP_I_C1_CRC32 = crc.NewHash(&crc.Parameters{Width: 32, Polynomial: 0x100d4e63, Init: 0x0, ReflectIn: true, ReflectOut: true, FinalXor: 0x0}) + RSSP_I_C1_CRC32 = crc.NewHash(&crc.Parameters{Width: 32, Polynomial: 0x100d4e63, Init: 0x0, ReflectIn: false, ReflectOut: true, FinalXor: 0x0}) // 通道2 crc32多项式为0x8ce56011 - RSSP_I_C2_CRC32 = crc.NewHash(&crc.Parameters{Width: 32, Polynomial: 0x8ce56011, Init: 0x0, ReflectIn: true, ReflectOut: true, FinalXor: 0x0}) + RSSP_I_C2_CRC32 = crc.NewHash(&crc.Parameters{Width: 32, Polynomial: 0x8ce56011, Init: 0x0, ReflectIn: false, ReflectOut: true, FinalXor: 0x0}) ) // Rssp_I_Crc16计算 @@ -20,27 +20,27 @@ func Rssp_I_Crc16(data []byte) uint16 { // 通道1的crc32 func Rssp_I_Crc32C1(data []byte) uint32 { - newData := reverseBitsInByte(data) - return uint32(RSSP_I_C1_CRC32.CalculateCRC(newData)) + //newData := reverseBitsInByte(data) + return uint32(RSSP_I_C1_CRC32.CalculateCRC(data)) } // 通道2的crc32 func Rssp_I_Crc32C2(data []byte) uint32 { - newData := reverseBitsInByte(data) - return uint32(RSSP_I_C2_CRC32.CalculateCRC(newData)) + //newData := reverseBitsInByte(data) + return uint32(RSSP_I_C2_CRC32.CalculateCRC(data)) } -func reverseBitsInByte(data []byte) []byte { - var result byte - newData := make([]byte, len(data)) - for i, b := range data { - result = 0 - for i := 0; i < 8; i++ { - result <<= 1 - result |= b & 1 - b >>= 1 - } - newData[i] = result - } - return newData -} +//func reverseBitsInByte(data []byte) []byte { +// var result byte +// newData := make([]byte, len(data)) +// for i, b := range data { +// result = 0 +// for i := 0; i < 8; i++ { +// result <<= 1 +// result |= b & 1 +// b >>= 1 +// } +// newData[i] = result +// } +// return newData +//}