58 const size_t LEN_MIN = 13;
59 const size_t LEN_MAX = 14;
61 if (sentence.get_body().size() > LEN_MAX ||
62 sentence.get_body().size() < LEN_MIN)
64 std::stringstream error;
65 error <<
"Expected GPRMC length is between " << LEN_MIN <<
" and " 66 << LEN_MAX <<
". The actual length is " << sentence.get_body().size();
70 rosaic::GprmcPtr msg = boost::make_shared<rosaic::Gprmc>();
74 msg->message_id = sentence.get_body()[0];
76 if (sentence.get_body()[1].empty() || sentence.get_body()[1] ==
"0")
91 uint32_t unix_time_nanoseconds = (
static_cast<uint32_t
>(utc_double*100)%100)*10000;
92 msg->header.stamp.sec = unix_time_seconds;
93 msg->header.stamp.nsec = unix_time_nanoseconds;
98 time_obj = ros::Time::now();
99 msg->header.stamp.sec = time_obj.sec;
100 msg->header.stamp.nsec = time_obj.nsec;
109 bool to_be_ignored =
false;
111 msg->position_status = sentence.get_body()[2];
113 to_be_ignored &= !(sentence.get_body()[2].compare(
"A") == 0);
114 to_be_ignored &= (sentence.get_body()[3].empty() || sentence.get_body()[5].empty());
116 double latitude = 0.0;
120 double longitude = 0.0;
124 msg->lat_dir = sentence.get_body()[4];
125 msg->lon_dir = sentence.get_body()[6];
132 std::string date_str = sentence.get_body()[9];
133 if (!date_str.empty())
135 msg->date = std::string(
"20") + date_str.substr(4, 2) +
136 std::string(
"-") + date_str.substr(2, 2) +
137 std::string(
"-") + date_str.substr(0, 2);
140 msg->mag_var_direction = sentence.get_body()[11];
141 if (sentence.get_body().size() == LEN_MAX)
143 msg->mode_indicator = sentence.get_body()[12];
const std::string getMessageID() const override
Returns the ASCII message ID, here "$GPRMC".
std::string g_frame_id
The frame ID used in the header of every published ROS message.
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...
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.
static constexpr double KNOTS_TO_MPS
double convertDMSToDegrees(double dms)
Converts latitude or longitude from the DMS notation (in the without-colon-delimiter format)...
Derived class for parsing RMC messages.
bool was_last_gprmc_valid_
Declares a boolean representing whether or not the last GPRMC message was valid.
time_t convertUTCtoUnix(double utc_double)
Converts UTC time from the without-colon-delimiter format to Unix Epoch time (a number-of-seconds-sin...
Struct to split an NMEA sentence into its ID and its body, the latter tokenized into a vector of stri...
Class to declare error message format when parsing, derived from the public class "std::runtime_error...
double parseDouble(const uint8_t *buffer)
Converts an 8-byte-buffer into a double.
rosaic::GprmcPtr parseASCII(const NMEASentence &sentence) noexcept(false) override
Parses one RMC message.