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/inscov.h>
00031 #include <novatel_gps_driver/parsers/header.h>
00032 #include <boost/make_shared.hpp>
00033
00034 const std::string novatel_gps_driver::InscovParser::MESSAGE_NAME = "INSCOV";
00035
00036 uint32_t novatel_gps_driver::InscovParser::GetMessageId() const
00037 {
00038 return MESSAGE_ID;
00039 }
00040
00041 const std::string novatel_gps_driver::InscovParser::GetMessageName() const
00042 {
00043 return MESSAGE_NAME;
00044 }
00045
00046 novatel_gps_msgs::InscovPtr
00047 novatel_gps_driver::InscovParser::ParseBinary(const BinaryMessage& bin_msg) throw(ParseException)
00048 {
00049 if (bin_msg.data_.size() != BINARY_LENGTH)
00050 {
00051 std::stringstream error;
00052 error << "Unexpected inscov message size: " << bin_msg.data_.size();
00053 throw ParseException(error.str());
00054 }
00055 novatel_gps_msgs::InscovPtr ros_msg = boost::make_shared<novatel_gps_msgs::Inscov>();
00056 HeaderParser h_parser;
00057 ros_msg->novatel_msg_header = h_parser.ParseBinary(bin_msg);
00058 ros_msg->novatel_msg_header.message_name = GetMessageName();
00059
00060 ros_msg->week = ParseUInt32(&bin_msg.data_[0]);
00061 ros_msg->seconds = ParseDouble(&bin_msg.data_[4]);
00062 int offset = 12;
00063 for (int i = 0; i < 9; i++, offset += 8)
00064 {
00065 ros_msg->position_covariance[i] = ParseDouble(&bin_msg.data_[offset]);
00066 }
00067 for (int i = 0; i < 9; i++, offset += 8)
00068 {
00069 ros_msg->attitude_covariance[i] = ParseDouble(&bin_msg.data_[offset]);
00070 }
00071 for (int i = 0; i < 9; i++, offset += 8)
00072 {
00073 ros_msg->velocity_covariance[i] = ParseDouble(&bin_msg.data_[offset]);
00074 }
00075 return ros_msg;
00076 }
00077
00078 novatel_gps_msgs::InscovPtr
00079 novatel_gps_driver::InscovParser::ParseAscii(const NovatelSentence& sentence) throw(ParseException)
00080 {
00081 if (sentence.body.size() != ASCII_FIELDS)
00082 {
00083 std::stringstream error;
00084 error << "Unexpected number of fields in INSCOV log: " << sentence.body.size();
00085 throw ParseException(error.str());
00086 }
00087 novatel_gps_msgs::InscovPtr ros_msg = boost::make_shared<novatel_gps_msgs::Inscov>();
00088 HeaderParser h_parser;
00089 ros_msg->novatel_msg_header = h_parser.ParseAscii(sentence);
00090
00091 bool valid = true;
00092
00093 valid &= ParseUInt32(sentence.body[0], ros_msg->week);
00094 valid &= ParseDouble(sentence.body[1], ros_msg->seconds);
00095
00096 int offset = 2;
00097 for (int i = 0; i < 9; i++, offset++)
00098 {
00099 valid &= ParseDouble(sentence.body[offset], ros_msg->position_covariance[i]);
00100 }
00101 for (int i = 0; i < 9; i++, offset++)
00102 {
00103 valid &= ParseDouble(sentence.body[offset], ros_msg->attitude_covariance[i]);
00104 }
00105 for (int i = 0; i < 9; i++, offset++)
00106 {
00107 valid &= ParseDouble(sentence.body[offset], ros_msg->velocity_covariance[i]);
00108 }
00109
00110 if (!valid)
00111 {
00112 throw ParseException("Error parsing INSCOV log.");
00113 }
00114
00115 return ros_msg;
00116 }