1 #include <marnav/nmea/apa.hpp>
3 #include <marnav/nmea/io.hpp>
9 constexpr sentence_id
apa::ID
;
10 constexpr const char * apa::TAG
;
13 : sentence(ID
, TAG
, talker_id::global_positioning_system
)
17 apa::apa(talker talk
, fields::const_iterator first
, fields::const_iterator last
)
18 : sentence(ID
, TAG
, talk
)
20 if (std::distance(first
, last
) != 10)
21 throw std::invalid_argument
{"invalid number of fields in apa"};
23 read(*(first
+ 0), loran_c_blink_warning_
);
24 read(*(first
+ 1), loran_c_cycle_lock_warning_
);
25 read(*(first
+ 2), cross_track_error_magnitude_
);
26 read(*(first
+ 3), direction_to_steer_
);
27 read(*(first
+ 4), cross_track_unit_
);
28 read(*(first
+ 5), status_arrival_
);
29 read(*(first
+ 6), status_perpendicular_passing_
);
30 read(*(first
+ 7), bearing_origin_to_destination_
);
31 read(*(first
+ 8), bearing_origin_to_destination_ref_
);
32 read(*(first
+ 9), waypoint_id_
);
37 void apa::set_bearing_origin_to_destination(double t
, reference ref
)
39 check_value(bearing_origin_to_destination_ref_
, {reference::TRUE
, reference::MAGNETIC
},
40 "bearing_origin_to_destination_ref");
41 bearing_origin_to_destination_
= t
;
42 bearing_origin_to_destination_ref_
= ref
;
45 void apa::check() const
47 check_status(loran_c_blink_warning_
, "loran_c_blink_warning");
48 check_status(loran_c_cycle_lock_warning_
, "loran_c_cycle_lock_warning");
50 check_value(direction_to_steer_
, {side::left
, side::right
}, "direction_to_steer");
51 check_value(cross_track_unit_
, {unit::distance::nm
}, "cross_talk_unit");
52 check_status(status_arrival_
, "status_arrival");
53 check_status(status_perpendicular_passing_
, "status_perpendicular_passing");
55 if (bearing_origin_to_destination_
&& !bearing_origin_to_destination_ref_
)
56 throw std::invalid_argument
{"missing bearing_origin_to_destination_ref"};
57 check_value(bearing_origin_to_destination_ref_
, {reference::TRUE
, reference::MAGNETIC
},
58 "bearing_origin_to_destination_ref");
61 void apa::append_data_to(std::string
& s
) const
63 append(s
, to_string(loran_c_blink_warning_
));
64 append(s
, to_string(loran_c_cycle_lock_warning_
));
65 append(s
, format(cross_track_error_magnitude_
, 2));
66 append(s
, to_string(direction_to_steer_
));
67 append(s
, to_string(cross_track_unit_
));
68 append(s
, to_string(status_arrival_
));
69 append(s
, to_string(status_perpendicular_passing_
));
70 append(s
, format(bearing_origin_to_destination_
, 1));
71 append(s
, to_string(bearing_origin_to_destination_ref_
));
72 append(s
, to_string(waypoint_id_
));