range.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/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]; // This number is in hex
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 }


novatel_gps_driver
Author(s):
autogenerated on Sun Oct 8 2017 02:40:29