rts-sim-testing-service/third_party/message/rssp_code.go

47 lines
1.3 KiB
Go
Raw Normal View History

2023-10-30 14:32:49 +08:00
package message
import "github.com/snksoft/crc"
2023-10-30 14:32:49 +08:00
//rssp 协议中crc校验查表法实现
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
2024-07-24 18:27:41 +08:00
RSSP_I_C1_CRC32 = crc.NewHash(&crc.Parameters{Width: 32, Polynomial: 0x100d4e63, Init: 0x0, ReflectIn: false, ReflectOut: true, FinalXor: 0x0})
// 通道2 crc32多项式为0x8ce56011
2024-07-24 18:27:41 +08:00
RSSP_I_C2_CRC32 = crc.NewHash(&crc.Parameters{Width: 32, Polynomial: 0x8ce56011, Init: 0x0, ReflectIn: false, ReflectOut: true, FinalXor: 0x0})
)
2023-10-30 14:32:49 +08:00
// Rssp_I_Crc16计算
func Rssp_I_Crc16(data []byte) uint16 {
return uint16(RSSP_I_CRC16.CalculateCRC(data))
2023-10-30 17:46:52 +08:00
}
// 通道1的crc32
func Rssp_I_Crc32C1(data []byte) uint32 {
2024-07-24 18:27:41 +08:00
//newData := reverseBitsInByte(data)
return uint32(RSSP_I_C1_CRC32.CalculateCRC(data))
2023-10-30 14:32:49 +08:00
}
// 通道2的crc32
func Rssp_I_Crc32C2(data []byte) uint32 {
2024-07-24 18:27:41 +08:00
//newData := reverseBitsInByte(data)
return uint32(RSSP_I_C2_CRC32.CalculateCRC(data))
}
2024-07-24 18:27:41 +08:00
//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
//}