inscov.cpp
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2017, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL SOUTHWEST RESEARCH INSTITUTE BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 }


novatel_gps_driver
Author(s):
autogenerated on Wed Jul 3 2019 19:40:37