31 #include <boost/make_shared.hpp> 50 const size_t EXPECTED_LEN_OEM6 = 13;
51 const size_t EXPECTED_LEN_OEM4 = 12;
53 if (sentence.body.size() != EXPECTED_LEN_OEM4 &&
54 sentence.body.size() != EXPECTED_LEN_OEM6)
56 std::stringstream error;
57 error <<
"Expected GPRMC lengths = " 58 << EXPECTED_LEN_OEM4 <<
" (for OEM4), " 59 << EXPECTED_LEN_OEM6 <<
" (for OEM6), " 60 <<
"actual length = " << sentence.body.size();
65 novatel_gps_msgs::GprmcPtr
msg = boost::make_shared<novatel_gps_msgs::Gprmc>();
66 msg->message_id = sentence.body[0];
68 if (sentence.body[1].empty() || sentence.body[1] ==
"0")
85 msg->position_status = sentence.body[2];
87 success &= (sentence.body[2].compare(
"A") == 0);
88 success &= !(sentence.body[3].empty() || sentence.body[5].empty());
92 double latitude = 0.0;
93 valid = valid &&
ParseDouble(sentence.body[3], latitude);
96 double longitude = 0.0;
97 valid = valid &&
ParseDouble(sentence.body[5], longitude);
100 msg->lat_dir = sentence.body[4];
101 msg->lon_dir = sentence.body[6];
103 valid = valid &&
ParseFloat(sentence.body[7], msg->speed);
106 valid = valid &&
ParseFloat(sentence.body[8], msg->track);
108 std::string date_str = sentence.body[9];
109 if (!date_str.empty())
111 msg->date = std::string(
"20") + date_str.substr(4, 2) +
112 std::string(
"-") + date_str.substr(2, 2) +
113 std::string(
"-") + date_str.substr(0, 2);
115 valid = valid &&
ParseFloat(sentence.body[10], msg->mag_var);
116 msg->mag_var_direction = sentence.body[11];
117 if (sentence.body.size() == EXPECTED_LEN_OEM6) {
118 msg->mode_indicator = sentence.body[12];
static constexpr double KNOTS_TO_MPS
bool WasLastGpsValid() const
const std::string GetMessageName() const override
double ParseDouble(const uint8_t *buffer)
Converts a buffer containing 8 bytes into a double.
novatel_gps_msgs::GprmcPtr ParseAscii(const NmeaSentence &sentence) override
Converts sentence into a ROS message pointer and returns it.
float ParseFloat(const uint8_t *buffer)
Converts a buffer containing 4 bytes into a float.
uint32_t GetMessageId() const override
static const std::string MESSAGE_NAME
double UtcFloatToSeconds(double utc_float)
double ConvertDmsToDegrees(double dms)
bool ToDouble(const std::string &string, double &value)