Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <novatel_gps_driver/parsers/gprmc.h>
00031 #include <boost/make_shared.hpp>
00032 #include <swri_string_util/string_util.h>
00033
00034 const std::string novatel_gps_driver::GprmcParser::MESSAGE_NAME = "GPRMC";
00035
00036 uint32_t novatel_gps_driver::GprmcParser::GetMessageId() const
00037 {
00038 return 0;
00039 }
00040
00041 const std::string novatel_gps_driver::GprmcParser::GetMessageName() const
00042 {
00043 return MESSAGE_NAME;
00044 }
00045
00046 novatel_gps_msgs::GprmcPtr novatel_gps_driver::GprmcParser::ParseAscii(const novatel_gps_driver::NmeaSentence& sentence) throw(ParseException)
00047 {
00048
00049
00050 const size_t EXPECTED_LEN_OEM6 = 13;
00051 const size_t EXPECTED_LEN_OEM4 = 12;
00052
00053 if (sentence.body.size() != EXPECTED_LEN_OEM4 &&
00054 sentence.body.size() != EXPECTED_LEN_OEM6)
00055 {
00056 std::stringstream error;
00057 error << "Expected GPRMC lengths = "
00058 << EXPECTED_LEN_OEM4 << " (for OEM4), "
00059 << EXPECTED_LEN_OEM6 << " (for OEM6), "
00060 << "actual length = " << sentence.body.size();
00061 throw ParseException(error.str());
00062 }
00063
00064 bool success = true;
00065 novatel_gps_msgs::GprmcPtr msg = boost::make_shared<novatel_gps_msgs::Gprmc>();
00066 msg->message_id = sentence.body[0];
00067
00068 if (sentence.body[1].empty() || sentence.body[1] == "0")
00069 {
00070 msg->utc_seconds = 0;
00071 }
00072 else
00073 {
00074 double utc_float;
00075 if (swri_string_util::ToDouble(sentence.body[1], utc_float))
00076 {
00077 msg->utc_seconds = UtcFloatToSeconds(utc_float);
00078 }
00079 else
00080 {
00081 throw ParseException("Error parsing UTC seconds in GPRMC log.");
00082 }
00083 }
00084
00085 msg->position_status = sentence.body[2];
00086
00087 success &= (sentence.body[2].compare("A") == 0);
00088 success &= !(sentence.body[3].empty() || sentence.body[5].empty());
00089
00090 bool valid = true;
00091
00092 double latitude = 0.0;
00093 valid = valid && ParseDouble(sentence.body[3], latitude);
00094 msg->lat = ConvertDmsToDegrees(latitude);
00095
00096 double longitude = 0.0;
00097 valid = valid && ParseDouble(sentence.body[5], longitude);
00098 msg->lon = ConvertDmsToDegrees(longitude);
00099
00100 msg->lat_dir = sentence.body[4];
00101 msg->lon_dir = sentence.body[6];
00102
00103 valid = valid && ParseFloat(sentence.body[7], msg->speed);
00104 msg->speed *= KNOTS_TO_MPS;
00105
00106 valid = valid && ParseFloat(sentence.body[8], msg->track);
00107
00108 std::string date_str = sentence.body[9];
00109 if (!date_str.empty())
00110 {
00111 msg->date = std::string("20") + date_str.substr(4, 2) +
00112 std::string("-") + date_str.substr(2, 2) +
00113 std::string("-") + date_str.substr(0, 2);
00114 }
00115 valid = valid && ParseFloat(sentence.body[10], msg->mag_var);
00116 msg->mag_var_direction = sentence.body[11];
00117 if (sentence.body.size() == EXPECTED_LEN_OEM6) {
00118 msg->mode_indicator = sentence.body[12];
00119 }
00120
00121 if (!valid)
00122 {
00123 was_last_gps_valid_ = false;
00124 throw ParseException("Error parsing GPRMC message.");
00125 }
00126
00127 was_last_gps_valid_ = success;
00128
00129 return msg;
00130 }
00131
00132 bool novatel_gps_driver::GprmcParser::WasLastGpsValid() const
00133 {
00134 return was_last_gps_valid_;
00135 }