bug fix: NMEA/AIS/SeaTalk: cast functions with std::unique_ptr resulted in undefined...
[marnav.git] / src / marnav / ais / message_05.cpp
blob9e38070ff11c07de8d2a85778becd1ef3a23c5e6
1 #include "message_05.hpp"
3 namespace marnav
5 namespace ais
7 MARNAV_AIS_DEFINE_MESSAGE_PARSE_FUNC(message_05)
9 message_05::message_05()
10 : message(ID)
11 , callsign("@@@@@@@")
12 , shipname("@@@@@@@@@@@@@@@@@@@@")
13 , destination("@@@@@@@@@@@@@@@@@@@@")
17 /// @todo also handle message with length of 420 and 422 bits
18 message_05::message_05(const raw & bits)
19 : message(ID)
20 , callsign("@@@@@@@")
21 , shipname("@@@@@@@@@@@@@@@@@@@@")
22 , destination("@@@@@@@@@@@@@@@@@@@@")
24 if (bits.size() != SIZE_BITS)
25 throw std::invalid_argument{"invalid number of bits in message_05"};
26 read_data(bits);
29 void message_05::read_data(const raw & bits)
31 get(bits, repeat_indicator);
32 get(bits, mmsi);
33 get(bits, ais_version);
34 get(bits, imo_number);
35 get(bits, callsign);
36 get(bits, shipname);
37 get(bits, shiptype);
38 get(bits, to_bow);
39 get(bits, to_stern);
40 get(bits, to_port);
41 get(bits, to_starboard);
42 get(bits, epfd_fix);
43 get(bits, eta_month);
44 get(bits, eta_day);
45 get(bits, eta_hour);
46 get(bits, eta_minute);
47 get(bits, draught);
48 get(bits, destination);
49 get(bits, dte);
52 raw message_05::get_data() const
54 raw bits{SIZE_BITS};
56 bits.set(type(), 0, 6);
57 set(bits, repeat_indicator);
58 set(bits, mmsi);
59 set(bits, ais_version);
60 set(bits, imo_number);
61 set(bits, callsign);
62 set(bits, shipname);
63 set(bits, shiptype);
64 set(bits, to_bow);
65 set(bits, to_stern);
66 set(bits, to_port);
67 set(bits, to_starboard);
68 set(bits, epfd_fix);
69 set(bits, eta_month);
70 set(bits, eta_day);
71 set(bits, eta_hour);
72 set(bits, eta_minute);
73 set(bits, draught);
74 set(bits, destination);
75 set(bits, dte);
77 return bits;
80 std::string message_05::get_callsign() const
82 return trim_ais_string(callsign);
85 std::string message_05::get_shipname() const
87 return trim_ais_string(shipname);
90 std::string message_05::get_destination() const
92 return trim_ais_string(destination);
95 void message_05::set_callsign(const std::string & t)
97 if (t.size() > 7) {
98 callsign = t.substr(0, 7);
99 } else {
100 callsign = t;
104 void message_05::set_shipname(const std::string & t)
106 if (t.size() > 20) {
107 shipname = t.substr(0, 20);
108 } else {
109 shipname = t;
113 void message_05::set_destination(const std::string & t)
115 if (t.size() > 20) {
116 destination = t.substr(0, 20);
117 } else {
118 destination = t;