24 #ifndef GOBY_UTIL_AIS_DECODE_H
25 #define GOBY_UTIL_AIS_DECODE_H
34 #include <boost/algorithm/string/classification.hpp>
35 #include <boost/algorithm/string/predicate_facade.hpp>
36 #include <boost/algorithm/string/trim.hpp>
37 #include <boost/units/base_unit.hpp>
38 #include <boost/units/base_units/metric/knot.hpp>
39 #include <boost/units/operators.hpp>
40 #include <boost/units/systems/angle/degrees.hpp>
41 #include <boost/units/systems/si/length.hpp>
65 Decoder(
const std::vector<NMEASentence>& nmeas);
70 bool complete() {
return ais_msg_ !=
nullptr; }
75 return ais_msg_->message_id;
114 std::string trim_ais_string(std::string in)
116 boost::trim_if(in, boost::algorithm::is_space() || boost::algorithm::is_any_of(
"@"));
120 template <
typename LibAisMessage>
121 void set_shared_fields(goby::util::ais::protobuf::Voyage& ,
const LibAisMessage& ais,
126 voy_.set_message_id(ais.message_id);
127 voy_.set_mmsi(ais.mmsi);
131 std::string name = trim_ais_string(ais.name);
135 else if (part_num == 1)
137 std::string callsign = trim_ais_string(ais.callsign);
138 if (!callsign.empty())
139 voy_.set_callsign(callsign);
141 if (protobuf::Voyage::ShipType_IsValid(ais.type_and_cargo))
142 voy_.set_type(
static_cast<protobuf::Voyage::ShipType
>(ais.type_and_cargo));
143 voy_.set_to_bow_with_units(ais.dim_a * si::meters);
144 voy_.set_to_stern_with_units(ais.dim_b * si::meters);
145 voy_.set_to_port_with_units(ais.dim_c * si::meters);
146 voy_.set_to_starboard_with_units(ais.dim_d * si::meters);
150 template <
typename LibAisMessage>
151 void set_shared_fields(goby::util::ais::protobuf::Position& pos,
const LibAisMessage& ais)
154 pos.set_message_id(ais.message_id);
155 pos.set_mmsi(ais.mmsi);
156 metric::knot_base_unit::unit_type knots;
157 pos.set_speed_over_ground_with_units(ais.sog * knots);
158 pos.set_lat_with_units(ais.position.lat_deg * degree::degrees);
159 pos.set_lon_with_units(ais.position.lng_deg * degree::degrees);
160 pos.set_course_over_ground_with_units(ais.cog * degree::degrees);
161 if (ais.true_heading >= 0 && ais.true_heading < 360)
162 pos.set_true_heading_with_units(ais.true_heading * degree::degrees);
163 pos.set_report_second_with_units(ais.timestamp * si::seconds);
164 pos.set_raim(ais.raim);
166 if (protobuf::Position::PositionAccuracy_IsValid(ais.position_accuracy))
167 pos_.set_position_accuracy(
168 static_cast<protobuf::Position::PositionAccuracy
>(ais.position_accuracy));
171 void decode_position();
172 void decode_voyage();
175 libais::VdmStream ais_stream_decoder_;
176 std::unique_ptr<libais::AisMsg> ais_msg_;
178 goby::util::ais::protobuf::Voyage voy_;
179 goby::util::ais::protobuf::Position pos_;
DecoderException(const std::string &what)
libais::AisMsg & as_libais_msg()
bool push(const NMEASentence &nmea)
goby::util::ais::protobuf::Position as_position()
Decoder(const NMEASentence &nmea)
Decoder(const std::vector< NMEASentence > &nmeas)
goby::util::ais::protobuf::Voyage as_voyage()
ostream & operator<<(ostream &os, Decoder::ParsedType t)
The global namespace for the Goby project.