Brian Silverman | 8cbf833 | 2013-12-11 13:59:42 -0800 | [diff] [blame] | 1 | #ifndef BBB_CRC_H_ |
| 2 | #define BBB_CRC_H_ |
| 3 | |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame] | 4 | #include <string.h> |
Brian Silverman | 8cbf833 | 2013-12-11 13:59:42 -0800 | [diff] [blame] | 5 | #include <stdint.h> |
| 6 | |
Brian Silverman | 04fac62 | 2014-01-26 18:32:15 -0800 | [diff] [blame] | 7 | namespace bbb { |
| 8 | |
| 9 | class ByteReaderInterface; |
| 10 | |
| 11 | } // namespace bbb |
Brian Silverman | 8cbf833 | 2013-12-11 13:59:42 -0800 | [diff] [blame] | 12 | namespace cape { |
| 13 | |
| 14 | // Calculates a CRC32 checksum for data. This is definitely the same one as the |
| 15 | // cape MCU does in hardware which seems to be the same one as Ethernet etc use. |
Brian Silverman | 04fac62 | 2014-01-26 18:32:15 -0800 | [diff] [blame] | 16 | // length is the number of bytes of data to read. It must be a multiple of 4. |
| 17 | // initial can be a previous return value to continue the same checksum over |
| 18 | // more data. |
Brian Silverman | 8dc9fd4 | 2014-02-10 13:35:43 -0800 | [diff] [blame^] | 19 | uint32_t CalculateChecksum(const uint8_t *data, size_t length, |
Brian Silverman | 04fac62 | 2014-01-26 18:32:15 -0800 | [diff] [blame] | 20 | uint32_t initial = 0xFFFFFFFF); |
| 21 | // Reads all data out of reader and does a checksum over all of it in reasonably |
| 22 | // sized pieces. Does all of the reads with a timeout of 0. Stops on the first |
| 23 | // timeout. |
| 24 | uint32_t CalculateChecksum(::bbb::ByteReaderInterface *reader); |
Brian Silverman | 8cbf833 | 2013-12-11 13:59:42 -0800 | [diff] [blame] | 25 | |
| 26 | } // namespace cape |
| 27 | |
| 28 | #endif // BBB_CRC_H_ |