CRC8 calculates CRC8 checksum of the given data.
(data []byte, model CRCModel)
| 25 | |
| 26 | // CRC8 calculates CRC8 checksum of the given data. |
| 27 | func CRC8(data []byte, model CRCModel) uint8 { |
| 28 | table := getTable(model) |
| 29 | crcResult := model.Init |
| 30 | crcResult = addBytes(data, model, crcResult, table) |
| 31 | if model.RefOut { |
| 32 | crcResult = bits.Reverse8(crcResult) |
| 33 | } |
| 34 | return crcResult ^ model.XorOut |
| 35 | } |
| 36 | |
| 37 | // This function get the result of adding the bytes in data to the crc |
| 38 | func addBytes(data []byte, model CRCModel, crcResult uint8, table []uint8) uint8 { |