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