From de3865eea83210c0fd354a9bc7fb6644e0bdb872 Mon Sep 17 00:00:00 2001 From: Mikhail Grushinskiy Date: Tue, 5 Nov 2024 16:32:43 -0500 Subject: [PATCH] Create NmeaChecksum.h --- bbn_m5atomS3_lite_env/NmeaChecksum.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bbn_m5atomS3_lite_env/NmeaChecksum.h diff --git a/bbn_m5atomS3_lite_env/NmeaChecksum.h b/bbn_m5atomS3_lite_env/NmeaChecksum.h new file mode 100644 index 0000000..6db8331 --- /dev/null +++ b/bbn_m5atomS3_lite_env/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