CSD logic shared between V1 and V2

This commit is contained in:
soypat
2024-01-14 12:39:10 -03:00
parent 5b6571350d
commit 2f85c8bd04
5 changed files with 311 additions and 108 deletions
-16
View File
@@ -27,19 +27,3 @@ func TestCRC(t *testing.T) {
}
}
}
func CRC16(buf []byte) (sum uint16) {
const poly uint16 = 0x1021 // Generator polynomial G(x) = x^16 + x^12 + x^5 + 1
var crc uint16 = 0x0000 // Initial value
for _, b := range buf {
crc ^= (uint16(b) << 8) // Shift byte into MSB of crc
for i := 0; i < 8; i++ { // Process each bit
if crc&0x8000 != 0 {
crc = (crc << 1) ^ poly
} else {
crc <<= 1
}
}
}
return crc
}