From 54f314b5402e4fe3f1af78c51a78bc3c4c698738 Mon Sep 17 00:00:00 2001 From: Mikhail Grushinskiy Date: Wed, 23 Oct 2024 21:50:21 -0400 Subject: [PATCH] Create NmeaChecksum.h --- bbn_m5atomS3_lite_DS18B20/NmeaChecksum.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bbn_m5atomS3_lite_DS18B20/NmeaChecksum.h diff --git a/bbn_m5atomS3_lite_DS18B20/NmeaChecksum.h b/bbn_m5atomS3_lite_DS18B20/NmeaChecksum.h new file mode 100644 index 0000000..6db8331 --- /dev/null +++ b/bbn_m5atomS3_lite_DS18B20/NmeaChecksum.h @@ -0,0 +1,23 @@ +#ifndef NmeaChecksum_h +#define NmeaChecksum_h + +#define NMEA_END_CHAR_1 '\r' + +/* + NMEA-0183 checksum + */ + +uint8_t nmea0183_checksum(const char *sentence); + +uint8_t nmea0183_checksum(const char *sentence) { + const char *n = sentence + 1; + uint8_t chk = 0; + /* While current char isn't '*' or sentence ending (newline) */ + while ('*' != *n && NMEA_END_CHAR_1 != *n && '\0' != *n) { + chk ^= (uint8_t) *n; + n++; + } + return chk; +} + +#endif