58 const std::string& frame_id,
bool use_gnss_time,
63 const size_t LEN_MIN = 13;
64 const size_t LEN_MAX = 14;
66 if (sentence.get_body().size() > LEN_MAX || sentence.get_body().size() < LEN_MIN)
68 std::stringstream error;
69 error <<
"Expected GPRMC length is between " << LEN_MIN <<
" and " << LEN_MAX
70 <<
". The actual length is " << sentence.get_body().size();
78 msg.message_id = sentence.get_body()[0];
80 if (sentence.get_body()[1].empty() || sentence.get_body()[1] ==
"0")
93 time_t unix_time_seconds =
98 unix_time_seconds * 1000000000 +
99 (
static_cast<Timestamp>(utc_double * 100) % 100) * 10000;
108 "Error parsing UTC seconds in GPRMC");
114 bool to_be_ignored =
false;
116 msg.position_status = sentence.get_body()[2];
118 to_be_ignored &= !(sentence.get_body()[2].compare(
"A") ==
121 (sentence.get_body()[3].empty() || sentence.get_body()[5].empty());
123 double latitude = 0.0;
128 double longitude = 0.0;
133 msg.lat_dir = sentence.get_body()[4];
134 msg.lon_dir = sentence.get_body()[6];
143 std::string date_str = sentence.get_body()[9];
144 if (!date_str.empty())
146 msg.date = std::string(
"20") + date_str.substr(4, 2) + std::string(
"-") +
147 date_str.substr(2, 2) + std::string(
"-") + date_str.substr(0, 2);
151 msg.mag_var_direction = sentence.get_body()[11];
152 if (sentence.get_body().size() == LEN_MAX)
154 msg.mode_indicator = sentence.get_body()[12];
Struct to split an NMEA sentence into its ID and its body, the latter tokenized into a vector of stri...
bool toDouble(const std::string &string, double &value)
Interprets the contents of "string" as a floating point number of type double It stores the "string"'...
float parseFloat(const uint8_t *buffer)
Converts a 4-byte-buffer into a float.
double convertUTCDoubleToSeconds(double utc_double)
Converts UTC time from the without-colon-delimiter format to the number-of-seconds-since-midnight for...
nmea_msgs::Gprmc GprmcMsg
static constexpr double KNOTS_TO_MPS
static const std::string MESSAGE_ID
Declares the string MESSAGE_ID.
bool wasLastGPRMCValid() const
Tells us whether the last RMC message was valid/usable or not.
Class to declare error message format when parsing, derived from the public class "std::runtime_error...
double convertDMSToDegrees(double dms)
Converts latitude or longitude from the DMS notation (in the without-colon-delimiter format)...
Derived class for parsing RMC messages.
const std::string getMessageID() const override
Returns the ASCII message ID, here "$GPRMC".
TimestampRos timestampToRos(Timestamp ts)
Convert nsec timestamp to ROS timestamp.
GprmcMsg parseASCII(const NMEASentence &sentence, const std::string &frame_id, bool use_gnss_time, Timestamp time_obj) noexcept(false) override
Parses one RMC message.
std::time_t convertUTCtoUnix(double utc_double)
Converts UTC time from the without-colon-delimiter format to Unix Epoch time (a number-of-seconds-sin...
double parseDouble(const uint8_t *buffer)
Converts an 8-byte-buffer into a double.
bool was_last_gprmc_valid_
Declares a boolean representing whether or not the last GPRMC message was valid.