2 #include <marnav/nmea/checks.hpp>
3 #include <marnav/nmea/io.hpp>
9 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(apb
)
11 constexpr const char * apb::TAG
;
14 : sentence(ID
, TAG
, talker_id::global_positioning_system
)
18 apb::apb(talker talk
, fields::const_iterator first
, fields::const_iterator last
)
19 : sentence(ID
, TAG
, talk
)
21 const auto size
= std::distance(first
, last
);
22 if ((size
< 14) || (size
> 15))
23 throw std::invalid_argument
{"invalid number of fields in apb"};
25 read(*(first
+ 0), loran_c_blink_warning
);
26 read(*(first
+ 1), loran_c_cycle_lock_warning
);
27 read(*(first
+ 2), cross_track_error_magnitude
);
28 read(*(first
+ 3), direction_to_steer
);
29 read(*(first
+ 4), cross_track_unit
);
30 read(*(first
+ 5), status_arrival
);
31 read(*(first
+ 6), status_perpendicular_passing
);
32 read(*(first
+ 7), bearing_origin_to_destination
);
33 read(*(first
+ 8), bearing_origin_to_destination_ref
);
34 read(*(first
+ 9), waypoint_id
);
35 read(*(first
+ 10), bearing_pos_to_destination
);
36 read(*(first
+ 11), bearing_pos_to_destination_ref
);
37 read(*(first
+ 12), heading_to_steer_to_destination
);
38 read(*(first
+ 13), heading_to_steer_to_destination_ref
);
41 read(*(first
+ 14), mode_ind
);
46 void apb::set_bearing_origin_to_destination(double t
, reference ref
)
48 check_value(bearing_origin_to_destination_ref
, {reference::TRUE
, reference::MAGNETIC
},
49 "bearing_origin_to_destination_ref");
50 bearing_origin_to_destination
= t
;
51 bearing_origin_to_destination_ref
= ref
;
54 void apb::set_bearing_pos_to_destination(double t
, reference ref
)
56 check_value(bearing_pos_to_destination_ref
, {reference::TRUE
, reference::MAGNETIC
},
57 "bearing_pos_to_destination_ref");
58 bearing_pos_to_destination
= t
;
59 bearing_pos_to_destination_ref
= ref
;
62 void apb::set_heading_to_steer_to_destination(double t
, reference ref
)
64 check_value(heading_to_steer_to_destination_ref
, {reference::TRUE
, reference::MAGNETIC
},
65 "heading_to_steer_to_destination_ref");
66 heading_to_steer_to_destination
= t
;
67 heading_to_steer_to_destination_ref
= ref
;
70 void apb::set_mode_indicator(mode_indicator t
)
73 {mode_indicator::invalid
, mode_indicator::autonomous
, mode_indicator::differential
},
78 void apb::check() const
80 check_status(loran_c_blink_warning
, "loran_c_blink_warning");
81 check_status(loran_c_cycle_lock_warning
, "loran_c_cycle_lock_warning");
83 check_value(direction_to_steer
, {side::left
, side::right
}, "direction_to_steer");
84 check_value(cross_track_unit
, {unit::distance::nm
}, "cross_talk_unit");
85 check_status(status_arrival
, "status_arrival");
86 check_status(status_perpendicular_passing
, "status_perpendicular_passing");
88 if (bearing_origin_to_destination
&& !bearing_origin_to_destination_ref
)
89 throw std::invalid_argument
{"missing bearing_origin_to_destination_ref"};
90 check_value(bearing_origin_to_destination_ref
, {reference::TRUE
, reference::MAGNETIC
},
91 "bearing_origin_to_destination_ref");
93 if (bearing_pos_to_destination
&& !bearing_pos_to_destination_ref
)
94 throw std::invalid_argument
{"missing bearing_pos_to_destination_ref"};
95 check_value(bearing_pos_to_destination_ref
, {reference::TRUE
, reference::MAGNETIC
},
96 "bearing_pos_to_destination_ref");
98 if (heading_to_steer_to_destination
&& !heading_to_steer_to_destination_ref
)
99 throw std::invalid_argument
{"missing heading_to_steer_to_destination_ref"};
100 check_value(heading_to_steer_to_destination_ref
, {reference::TRUE
, reference::MAGNETIC
},
101 "heading_to_steer_to_destination_ref");
103 check_value(mode_ind
,
104 {mode_indicator::invalid
, mode_indicator::autonomous
, mode_indicator::differential
},
108 std::vector
<std::string
> apb::get_data() const
110 return {to_string(loran_c_blink_warning
), to_string(loran_c_cycle_lock_warning
),
111 format(cross_track_error_magnitude
, 2), to_string(direction_to_steer
),
112 to_string(cross_track_unit
), to_string(status_arrival
),
113 to_string(status_perpendicular_passing
), format(bearing_origin_to_destination
, 1),
114 to_string(bearing_origin_to_destination_ref
), to_string(waypoint_id
),
115 format(bearing_pos_to_destination
, 1), to_string(bearing_pos_to_destination_ref
),
116 format(heading_to_steer_to_destination
, 1),
117 to_string(heading_to_steer_to_destination_ref
), to_string(mode_ind
)};