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/range.h>
00031 #include <novatel_gps_driver/parsers/header.h>
00032
00033 #include <boost/make_shared.hpp>
00034
00035 const std::string novatel_gps_driver::RangeParser::MESSAGE_NAME = "RANGE";
00036
00037 uint32_t novatel_gps_driver::RangeParser::GetMessageId() const
00038 {
00039 return MESSAGE_ID;
00040 }
00041
00042 const std::string novatel_gps_driver::RangeParser::GetMessageName() const
00043 {
00044 return MESSAGE_NAME;
00045 }
00046
00047 novatel_gps_msgs::RangePtr
00048 novatel_gps_driver::RangeParser::ParseBinary(const novatel_gps_driver::BinaryMessage& bin_msg) throw(ParseException)
00049 {
00050 uint32_t num_obs = ParseUInt32(&bin_msg.data_[0]);
00051 if (bin_msg.data_.size() != (BINARY_OBSERVATION_SIZE * num_obs) + 4)
00052 {
00053 std::stringstream error;
00054 error << "Unexpected range message size: " << bin_msg.data_.size();
00055 throw ParseException(error.str());
00056 }
00057 novatel_gps_msgs::RangePtr ros_msg = boost::make_shared<novatel_gps_msgs::Range>();
00058 HeaderParser h_parser;
00059 ros_msg->novatel_msg_header = h_parser.ParseBinary(bin_msg);
00060 ros_msg->novatel_msg_header.message_name = "RANGE";
00061
00062 ros_msg->numb_of_observ = num_obs;
00063 ros_msg->info.reserve(num_obs);
00064 for(int i = 0; i < num_obs; i++)
00065 {
00066 size_t obs_offset = 4 + i * BINARY_OBSERVATION_SIZE;
00067
00068 novatel_gps_msgs::RangeInformation info;
00069
00070 info.prn_number = ParseUInt16(&bin_msg.data_[obs_offset]);
00071 info.glofreq = ParseUInt16(&bin_msg.data_[obs_offset+2]);
00072 info.psr = ParseDouble(&bin_msg.data_[obs_offset+4]);
00073 info.psr_std = ParseFloat(&bin_msg.data_[obs_offset+12]);
00074 info.adr = ParseDouble(&bin_msg.data_[obs_offset+16]);
00075 info.adr_std = ParseFloat(&bin_msg.data_[obs_offset+24]);
00076 info.dopp = ParseFloat(&bin_msg.data_[obs_offset+28]);
00077 info.noise_density_ratio = ParseFloat(&bin_msg.data_[obs_offset+32]);
00078 info.locktime = ParseFloat(&bin_msg.data_[obs_offset+36]);
00079 info.tracking_status = ParseUInt32(&bin_msg.data_[obs_offset+40]);
00080
00081 ros_msg->info.push_back(info);
00082 }
00083 return ros_msg;
00084 }
00085
00086 novatel_gps_msgs::RangePtr
00087 novatel_gps_driver::RangeParser::ParseAscii(const novatel_gps_driver::NovatelSentence& sentence) throw(ParseException)
00088 {
00089 novatel_gps_msgs::RangePtr msg = boost::make_shared<novatel_gps_msgs::Range>();
00090 HeaderParser h_parser;
00091 msg->novatel_msg_header = h_parser.ParseAscii(sentence);
00092 if (!ParseInt32(sentence.body[0], msg->numb_of_observ, 10))
00093 {
00094 std::stringstream error;
00095 error << "Unable to parse number of observations in RANGE log.";
00096 throw ParseException(error.str());
00097 }
00098 uint32_t numb_of_observ = static_cast<uint32_t>(msg->numb_of_observ);
00099 if (sentence.body.size() != 1 + numb_of_observ * ASCII_FIELDS)
00100 {
00101 std::stringstream error;
00102 error << "Did not find expected number of observations in RANGE log.";
00103 throw ParseException(error.str());
00104 }
00105 bool valid = true;
00106 valid &= ParseInt32(sentence.body[0], msg->numb_of_observ, 10);
00107 msg->info.resize(numb_of_observ);
00108 for (int i = 0, index = 0; index < numb_of_observ; i += 10, index++)
00109 {
00110 valid &= ParseUInt16(sentence.body[i + 1], msg->info[index].prn_number, 10);
00111 valid &= ParseUInt16(sentence.body[i + 2], msg->info[index].glofreq, 10);
00112 valid &= ParseDouble(sentence.body[i + 3], msg->info[index].psr);
00113 valid &= ParseFloat(sentence.body[i + 4], msg->info[index].psr_std);
00114 valid &= ParseDouble(sentence.body[i + 5], msg->info[index].adr);
00115 valid &= ParseFloat(sentence.body[i + 6], msg->info[index].adr_std);
00116 valid &= ParseFloat(sentence.body[i + 7], msg->info[index].dopp);
00117 valid &= ParseFloat(sentence.body[i + 8], msg->info[index].noise_density_ratio);
00118 valid &= ParseFloat(sentence.body[i + 9], msg->info[index].locktime);
00119 std::string track = "0x" + sentence.body[i + 10];
00120 valid &= ParseUInt32(track, msg->info[index].tracking_status, 16);
00121 }
00122 if (!valid)
00123 {
00124 throw ParseException("Error parsing RANGE log.");
00125 }
00126 return msg;
00127 }