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];
138 msg.speed *= KNOTS_TO_MPS;
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];
159 was_last_gprmc_valid_ =
false;
163 was_last_gprmc_valid_ = !to_be_ignored;