NMEA: explicit specification of copy/move construction and assignment.
[marnav.git] / src / marnav / nmea / vdm.hpp
blob9d163a55bba3b26dd5db581f139a2e8478526fa3
1 #ifndef __NMEA__VDM__HPP__
2 #define __NMEA__VDM__HPP__
4 #include <marnav/nmea/sentence.hpp>
5 #include <marnav/utils/optional.hpp>
7 namespace marnav
9 namespace nmea
11 MARNAV_NMEA_DECLARE_SENTENCE_PARSE_FUNC(vdm)
13 /// @brief VDM - AIS VHF Data-Link Message
14 ///
15 /// @code
16 /// 1 2 3 4 5 6
17 /// | | | | | |
18 /// $--VDM,x,x,x,a,s--s,x*hh<CR><LF>
19 /// @endcode
20 ///
21 /// Field Number:
22 /// 1. Number of fragments
23 /// 2. Fragment number
24 /// 3. Sequence Message ID
25 /// 4. Radio Channel
26 /// - A
27 /// - B
28 /// 5. Payload, 6-bit encoded content, max. 63 characters
29 /// 6. Number of fill bits (0..5)
30 ///
31 class vdm : public sentence
33 MARNAV_NMEA_SENTENCE_FRIENDS(vdm)
35 public:
36 constexpr static const sentence_id ID = sentence_id::VDM;
37 constexpr static const char * TAG = "VDM";
39 vdm();
40 vdm(const vdm &) = default;
41 vdm & operator=(const vdm &) = default;
42 vdm(vdm &&) = default;
43 vdm & operator=(vdm &&) = default;
45 protected:
46 vdm(sentence_id id, const std::string & tag, const std::string & talker);
47 vdm(const std::string & talker, fields::const_iterator first, fields::const_iterator last);
49 virtual std::vector<std::string> get_data() const override;
50 virtual char get_start_token() const override { return start_token_ais; }
52 void read_fields(fields::const_iterator first);
54 private:
55 uint32_t n_fragments = 0;
56 uint32_t fragment = 0;
57 utils::optional<uint32_t> seq_msg_id;
58 utils::optional<ais_channel> radio_channel; // A = 161.975MHz (87B), B = 162.025MHz (88B)
59 std::string payload; // 6bit encoded content
60 uint32_t n_fill_bits = 0; // 0..5
62 public:
63 MARNAV_NMEA_GETTER(n_fragments)
64 MARNAV_NMEA_GETTER(fragment)
65 MARNAV_NMEA_GETTER(seq_msg_id)
66 MARNAV_NMEA_GETTER(radio_channel)
67 MARNAV_NMEA_GETTER(payload)
68 MARNAV_NMEA_GETTER(n_fill_bits)
70 void set_n_fragments(uint32_t t) noexcept { n_fragments = t; }
71 void set_fragment(uint32_t t) noexcept { fragment = t; }
72 void set_seq_msg_id(uint32_t t) { seq_msg_id = t; }
73 void set_radio_channel(ais_channel channel) noexcept { radio_channel = channel; }
74 void set_payload(const std::string & data, uint32_t fill_bits) noexcept
76 payload = data;
77 n_fill_bits = fill_bits;
79 void set_payload(const std::pair<std::string, uint32_t> & data)
81 set_payload(data.first, data.second);
87 #endif