1 #include "message_01.hpp"
3 #include <marnav/ais/angle.hpp>
9 MARNAV_AIS_DEFINE_MESSAGE_PARSE_FUNC(message_01
)
11 message_01::message_01()
16 message_01::message_01(message_id id
)
21 message_01::message_01(const raw
& bits
)
24 if (bits
.size() != SIZE_BITS
)
25 throw std::invalid_argument
{"invalid number of bits in ais/message_01"};
29 utils::optional
<geo::longitude
> message_01::get_longitude() const
31 if (longitude_minutes
== longitude_not_available
)
32 return utils::make_optional
<geo::longitude
>();
33 return to_geo_longitude(longitude_minutes
, longitude_minutes
.count
, angle_scale::I4
);
36 utils::optional
<geo::latitude
> message_01::get_latitude() const
38 if (latitude_minutes
== latitude_not_available
)
39 return utils::make_optional
<geo::latitude
>();
40 return to_geo_latitude(latitude_minutes
, latitude_minutes
.count
, angle_scale::I4
);
43 void message_01::set_longitude(const utils::optional
<geo::longitude
> & t
)
46 ? to_longitude_minutes(t
.value(), longitude_minutes
.count
, angle_scale::I4
)
47 : longitude_not_available
;
50 void message_01::set_latitude(const utils::optional
<geo::latitude
> & t
)
53 ? to_latitude_minutes(t
.value(), latitude_minutes
.count
, angle_scale::I4
)
54 : latitude_not_available
;
57 /// Returns speed in knots.
58 utils::optional
<double> message_01::get_sog() const noexcept
60 if (sog
== sog_not_available
)
65 void message_01::set_sog(utils::optional
<double> t
) noexcept
67 sog
= !t
? sog_not_available
: static_cast<uint32_t>(std::round(*t
/ 0.1));
70 /// Returns course over ground in degrees true north.
71 utils::optional
<double> message_01::get_cog() const noexcept
73 if (cog
== cog_not_available
)
78 void message_01::set_cog(utils::optional
<double> t
) noexcept
80 cog
= !t
? cog_not_available
: static_cast<uint32_t>(std::round(*t
/ 0.1));
83 /// Returns heading in degrees.
84 utils::optional
<uint32_t> message_01::get_hdg() const noexcept
86 if (hdg
== hdg_not_available
)
91 void message_01::set_hdg(utils::optional
<uint32_t> t
) noexcept
93 hdg
= !t
? hdg_not_available
: *t
;
96 void message_01::read_data(const raw
& bits
)
98 get(bits
, repeat_indicator
);
100 get(bits
, nav_status
);
103 get(bits
, position_accuracy
);
104 get(bits
, longitude_minutes
);
105 get(bits
, latitude_minutes
);
108 get(bits
, timestamp
);
109 get(bits
, maneuver_indicator
);
111 get(bits
, radio_status
);
114 raw
message_01::get_data() const
118 bits
.set(type(), 0, 6);
119 set(bits
, repeat_indicator
);
121 set(bits
, nav_status
);
124 set(bits
, position_accuracy
);
125 set(bits
, longitude_minutes
);
126 set(bits
, latitude_minutes
);
129 set(bits
, timestamp
);
130 set(bits
, maneuver_indicator
);
132 set(bits
, radio_status
);