NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / aam.cpp
blobe8d399091eddf95fcd216365962f5108fe07ad37
1 #include "aam.hpp"
2 #include <marnav/nmea/checks.hpp>
3 #include <marnav/nmea/io.hpp>
5 namespace marnav
7 namespace nmea
9 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(aam)
11 constexpr const char * aam::TAG;
13 aam::aam()
14 : sentence(ID, TAG, talker_id::global_positioning_system)
18 aam::aam(talker talk, fields::const_iterator first, fields::const_iterator last)
19 : sentence(ID, TAG, talk)
21 if (std::distance(first, last) != 5)
22 throw std::invalid_argument{"invalid number of fields in aam"};
24 read(*(first + 0), arrival_circle_entered);
25 read(*(first + 1), perpendicualar_passed);
26 read(*(first + 2), arrival_circle_radius);
27 read(*(first + 3), arrival_circle_radius_unit);
28 read(*(first + 4), waypoint_id);
30 check();
33 void aam::set_arrival_circle_entered(status s)
35 check_status(s, "arrival_circle_entered");
36 arrival_circle_entered = s;
39 void aam::set_perpendicular_passed(status s)
41 check_status(s, "perpendicualar_passed");
42 perpendicualar_passed = s;
45 void aam::set_arrival_circle_radius(double t)
47 if (t < 0.0)
48 throw std::invalid_argument{"invalid argument, arrival radius below zero"};
49 arrival_circle_radius = t;
50 arrival_circle_radius_unit = unit::distance::nm;
53 void aam::check() const
55 check_status(arrival_circle_entered, "arrival_circle_entered");
56 check_status(perpendicualar_passed, "perpendicualar_passed");
57 if (arrival_circle_radius && !arrival_circle_radius_unit)
58 throw std::invalid_argument{"unit missing in sentence"};
59 check_value(arrival_circle_radius_unit, {unit::distance::nm}, "arrival_circle_radius_unit");
62 std::vector<std::string> aam::get_data() const
64 return {to_string(arrival_circle_entered), to_string(perpendicualar_passed),
65 to_string(arrival_circle_radius), to_string(arrival_circle_radius_unit),
66 to_string(waypoint_id)};