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

33 lines
1013 B
Go
Raw Normal View History

package message
import (
"fmt"
"github.com/snksoft/crc"
"testing"
)
func TestRssp_I_Crc16(t *testing.T) {
bytes := []byte{0x01, 0x80, 0x3a, 0x30, 0x9e, 0x30, 0x24, 0x85, 00, 00, 0x23, 00, 0x3b, 0x2b, 0xb1, 0x08, 0xf8, 0xc0, 0x6c, 0x16, 0x80, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}
crc := Rssp_I_Crc16(bytes)
fmt.Printf("crc16: %x\n", crc)
}
func BenchmarkRssp_I_Crc32C1(b *testing.B) {
var params = &crc.Parameters{
Width: 32,
Polynomial: 0x100d4e63,
ReflectIn: true,
ReflectOut: true,
Init: 0,
FinalXor: 0,
}
hash := crc.NewHash(params)
bytes := []byte{0x01, 0x80, 0x3a, 0x30, 0x9e, 0x30, 0x24, 0x85, 00, 00, 0x23, 00, 0x3b, 0x2b, 0xb1, 0x08, 0xf8, 0xc0, 0x6c, 0x16, 0x80, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00}
for i := 0; i < b.N; i++ {
hash.CalculateCRC(bytes)
}
//for i := 0; i < b.N; i++ {
// crc.CalculateCRC(params, bytes)
//}
}