NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / nmea.hpp
blob21033f33ada2a1e0c34ca85046f240a08f0c1877
1 #ifndef __MARNAV__NMEA__NMEA__HPP__
2 #define __MARNAV__NMEA__NMEA__HPP__
4 #include <memory>
5 #include <string>
6 #include <vector>
7 #include <marnav/nmea/sentence_id.hpp>
9 namespace marnav
11 /// @brief Contains everything to encode and decode NMEA sentences.
12 ///
13 /// This is provides all NMEA sentences and supporting functions.
14 ///
15 /// **Example:** list all supported NMEA sentences
16 /// @code
17 /// using namespace marnav;
18 ///
19 /// for (auto const & s : nmea::get_supported_sentences_str()) {
20 /// std::cout << s << "\n";
21 /// }
22 /// @endcode
23 ///
24 /// **Example:** create a sentence from a given string
25 /// @code
26 /// using namespace marnav;
27 ///
28 /// auto s = nmea::make_sentence("$GPBOD,099.3,T,105.6,M,POINTB,*01");
29 ///
30 /// if (s->id() == nmea::sentence_id::BOD) {
31 /// auto bod = nmea::sentence_cast<nmea::bod>(s);
32 /// std::cout << bod->get_waypoint_from() << " -> " << bod->get_waypoint_to() << "\n";
33 /// }
34 /// @endcode
35 ///
36 /// **Example:** create a specific sentence from a given string
37 /// @code
38 /// using namespace marnav;
39 ///
40 /// const auto bod = nmea::create_sentence<nmea::bod>("$GPBOD,099.3,T,105.6,M,POINTB,*01");
41 /// std::cout << bod.get_waypoint_from() << " -> " << bod.get_waypoint_to() << "\n";
42 /// @endcode
43 ///
44 /// **Example:** create a sentence and encode it to a string
45 /// @code
46 /// using namespace marnav;
47 ///
48 /// nmea::bod bod;
49 /// bod.set_waypoint_from("POINT1");
50 /// bod.set_waypoint_to("POINT2");
51 ///
52 /// std::cout << nmea::to_string(bod) << "\n";
53 /// @endcode
54 ///
55 namespace nmea
57 /// @brief Exception to be thrown if a NMEA sentence is not known/supported.
58 class unknown_sentence : public std::logic_error
60 public:
61 using logic_error::logic_error;
64 class sentence; // forward declaration
66 std::unique_ptr<sentence> make_sentence(const std::string & s, bool ignore_checksum = false);
68 sentence_id extract_id(const std::string & s);
70 std::vector<std::string> get_supported_sentences_str();
71 std::vector<sentence_id> get_supported_sentences_id();
72 std::string to_string(sentence_id id);
73 sentence_id tag_to_id(const std::string & tag);
77 #endif