NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / checksum.cpp
blob04dde9d3fc079a9abbf862dec5ca6a4c696d8878
1 #include "checksum.hpp"
3 namespace marnav
5 namespace nmea
7 checksum_error::checksum_error(uint8_t expected, uint8_t actual)
8 : expected(expected)
9 , actual(actual)
11 snprintf(
12 text, sizeof(text), "checksum error (actual:%02X, expected:%02X)", actual, expected);
15 /// @cond DEV
16 namespace detail
18 static constexpr char hex_digit(unsigned int t) noexcept
20 return "0123456789ABCDEF"[t & 0xf];
23 /// @endcond
25 /// Returns the specified checksum as string.
26 ///
27 /// @param[in] sum The checksum to render as string.
28 /// @return The checksum as string. This string is always two characters.
29 ///
30 std::string checksum_to_string(uint8_t sum)
32 char buf[3]{detail::hex_digit(sum >> 4), detail::hex_digit(sum), '\0'};
33 return buf;