diff --git a/DuinoCoin_RPI_Arduino_Slave/DuinoCoin_Utils.ino b/DuinoCoin_RPI_Arduino_Slave/DuinoCoin_Utils.ino index fa20c8d..09555d5 100644 --- a/DuinoCoin_RPI_Arduino_Slave/DuinoCoin_Utils.ino +++ b/DuinoCoin_RPI_Arduino_Slave/DuinoCoin_Utils.ino @@ -104,3 +104,27 @@ bool check(String message) } return false; } + +// https://stackoverflow.com/questions/51731313/cross-platform-crc8-function-c-and-python-parity-check +uint8_t crc8( uint8_t *addr, uint8_t len) { + uint8_t crc=0; + for (uint8_t i=0; i>= 1; + if (mix) + crc ^= 0x8C; + inbyte >>= 1; + } + } + return crc; +} + +uint8_t str_crc8( String msg ) +{ + int msg_len = msg.length() + 1; + char char_array[msg_len]; + msg.toCharArray(char_array, msg_len); + return crc8(char_array,msg.length()); +}