NMEA: changed type of talker id from 'std::string' to its own type.
[marnav.git] / src / marnav / nmea / detail.cpp
blobf0d200c18ae85fc5b9548b9accfcf158ceb2edf7
1 #include "detail.hpp"
2 #include <marnav/nmea/split.hpp>
4 namespace marnav
6 namespace nmea
8 /// @cond DEV
9 namespace detail
11 /// Performs checks on the specified raw NMEA sentence and extracts
12 /// information for further processing.
13 ///
14 /// This is separated into this function in order to prevent bloat
15 /// of the template function create_sentence.
16 ///
17 /// @param[in] s The raw NMEA sentence.
18 /// @param[in] ignore_checksum Option to ignore the checksum.
19 /// @return A tuple containing:
20 /// - The `talker` extracted from the raw NMEA sentence.
21 /// - The `tag` extracted from the raw NMEA sentence.
22 /// - Extracted `fields` from the raw NMEA sentence.
23 ///
24 std::tuple<talker, std::string, std::vector<std::string>> extract_sentence_information(
25 const std::string & s, bool ignore_checksum)
27 detail::check_raw_sentence(s);
29 // extract all fields, skip start token
30 std::vector<std::string> fields = detail::parse_fields(s);
31 if (fields.size() < 2) // at least address and checksum must be present
32 throw std::invalid_argument{"malformed sentence in nmea/make_sentence"};
34 if (!ignore_checksum)
35 detail::ensure_checksum(s, fields.back());
37 // extract address and posibly talker_id and tag.
38 // check for vendor extension is necessary because the address field of this extensions
39 // to not follow the pattern talker_id/tag
40 talker talk{talker_id::none};
41 std::string tag;
42 std::tie(talk, tag) = detail::parse_address(fields.front());
44 return std::make_tuple(talk, tag, fields);
47 /// @endcond