Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crc16.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type Table struct {
var IBMTable = makeTable(IBM)

// CCITTTable is the table for the CCITT polynomial.
var CCITTTable = makeTable(CCITT)
//var CCITTTable = makeTable(CCITT)
var CCITTTable = MakeTableNoXOR(CCITT)

// CCITTFalseTable is the table for CCITT-FALSE.
var CCITTFalseTable = makeBitsReversedTable(CCITTFalse)
Expand Down
16 changes: 15 additions & 1 deletion crc16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestModbus(t *testing.T) {
{[]byte("123456789"), 0x4B37},
{[]byte{0x0D, 0x01, 0x00, 0x62, 0x00, 0x33}, 0x0DDD},
{[]byte{0x01, 0x03, 0x00, 0x85, 0x00, 0x01}, 0xE395},
}
}
for _, testcase := range tests {
result := ^ChecksumIBM(testcase.Message)
if testcase.CRC != result {
Expand All @@ -60,9 +60,23 @@ func TestCCITTFalse(t *testing.T) {
target := uint16(0xDC7C)

actual := ChecksumCCITTFalse(data)
if actual != target {
t.Fatalf("CCITTFalse checksum did not return the correct value, expected %x, received %x", target, actual)
}
}

func TestCCITT(t *testing.T) {
data := []byte("1234567890")
target := uint16(0x286B)

actual := ChecksumCCITT(data)
if actual != target {
t.Fatalf("CCITT checksum did not return the correct value, expected %x, received %x", target, actual)
}
data = append(data, 0x6B, 0x28)
if res := ChecksumCCITT(data); res != 0 {
t.Fatalf("CCITT checksum inc cksum did not return 0, received %x", res)
}
}

func TestBinaryMarshal(t *testing.T) {
Expand Down