bestpos.cpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2017, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL SOUTHWEST RESEARCH INSTITUTE BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // *****************************************************************************
29 
31 
33 
34 #include <boost/make_shared.hpp>
35 
36 namespace novatel_gps_driver
37 {
38  const std::string BestposParser::MESSAGE_NAME = "BESTPOS";
39 
40  uint32_t BestposParser::GetMessageId() const
41  {
42  return MESSAGE_ID;
43  }
44 
45  const std::string BestposParser::GetMessageName() const
46  {
47  return MESSAGE_NAME;
48  }
49 
50  novatel_gps_msgs::NovatelPositionPtr BestposParser::ParseBinary(const BinaryMessage& bin_msg) noexcept(false)
51  {
52  if (bin_msg.data_.size() != BINARY_LENGTH)
53  {
54  std::stringstream error;
55  error << "Unexpected BESTPOS message length: " << bin_msg.data_.size();
56  throw ParseException(error.str());
57  }
58  novatel_gps_msgs::NovatelPositionPtr ros_msg =
59  boost::make_shared<novatel_gps_msgs::NovatelPosition>();
60  HeaderParser header_parser;
61  ros_msg->novatel_msg_header = header_parser.ParseBinary(bin_msg);
62  ros_msg->novatel_msg_header.message_name = MESSAGE_NAME;
63 
64  uint16_t solution_status = ParseUInt16(&bin_msg.data_[0]);
65  if (solution_status > MAX_SOLUTION_STATUS)
66  {
67  std::stringstream error;
68  error << "Unknown solution status: " << solution_status;
69  throw ParseException(error.str());
70  }
71  ros_msg->solution_status = SOLUTION_STATUSES[solution_status];
72  uint16_t pos_type = ParseUInt16(&bin_msg.data_[4]);
73  if (pos_type > MAX_POSITION_TYPE)
74  {
75  std::stringstream error;
76  error << "Unknown position type: " << pos_type;
77  throw ParseException(error.str());
78  }
79  ros_msg->position_type = POSITION_TYPES[pos_type];
80  ros_msg->lat = ParseDouble(&bin_msg.data_[8]);
81  ros_msg->lon = ParseDouble(&bin_msg.data_[16]);
82  ros_msg->height = ParseDouble(&bin_msg.data_[24]);
83  ros_msg->undulation = ParseFloat(&bin_msg.data_[32]);
84  uint16_t datum_id = ParseUInt16(&bin_msg.data_[36]);
85  if (datum_id > MAX_DATUM)
86  {
87  std::stringstream error;
88  error << "Unknown datum: " << datum_id;
89  throw ParseException(error.str());
90  }
91  ros_msg->datum_id = DATUMS[datum_id];
92  ros_msg->lat_sigma = ParseFloat(&bin_msg.data_[40]);
93  ros_msg->lon_sigma = ParseFloat(&bin_msg.data_[44]);
94  ros_msg->height_sigma = ParseFloat(&bin_msg.data_[48]);
95  ros_msg->base_station_id.resize(4);
96  std::copy(&bin_msg.data_[52], &bin_msg.data_[56], &ros_msg->base_station_id[0]);
97  ros_msg->diff_age = ParseFloat(&bin_msg.data_[56]);
98  ros_msg->solution_age = ParseFloat(&bin_msg.data_[60]);
99  ros_msg->num_satellites_tracked = bin_msg.data_[64];
100  ros_msg->num_satellites_used_in_solution = bin_msg.data_[65];
101  ros_msg->num_gps_and_glonass_l1_used_in_solution = bin_msg.data_[66];
102  ros_msg->num_gps_and_glonass_l1_and_l2_used_in_solution = bin_msg.data_[67];
103  GetExtendedSolutionStatusMessage(bin_msg.data_[69],
104  ros_msg->extended_solution_status);
105  GetSignalsUsed(bin_msg.data_[70], ros_msg->signal_mask);
106 
107  return ros_msg;
108  }
109 
110  novatel_gps_msgs::NovatelPositionPtr BestposParser::ParseAscii(const NovatelSentence& sentence) noexcept(false)
111  {
112  novatel_gps_msgs::NovatelPositionPtr msg =
113  boost::make_shared<novatel_gps_msgs::NovatelPosition>();
114  HeaderParser h_parser;
115  msg->novatel_msg_header = h_parser.ParseAscii(sentence);
116 
117  if (sentence.body.size() != ASCII_LENGTH)
118  {
119  std::stringstream error;
120  error << "Unexpected number of BESTPOS message fields: " << sentence.body.size();
121  throw ParseException(error.str());
122  }
123 
124  bool valid = true;
125 
126  msg->solution_status = sentence.body[0];
127  msg->position_type = sentence.body[1];
128  valid = valid && ParseDouble(sentence.body[2], msg->lat);
129  valid = valid && ParseDouble(sentence.body[3], msg->lon);
130  valid = valid && ParseDouble(sentence.body[4], msg->height);
131  valid = valid && ParseFloat(sentence.body[5], msg->undulation);
132  msg->datum_id = sentence.body[6];
133  valid = valid && ParseFloat(sentence.body[7], msg->lat_sigma);
134  valid = valid && ParseFloat(sentence.body[8], msg->lon_sigma);
135  valid = valid && ParseFloat(sentence.body[9], msg->height_sigma);
136  msg->base_station_id = sentence.body[10];
137  valid = valid && ParseFloat(sentence.body[11], msg->diff_age);
138  valid = valid && ParseFloat(sentence.body[12], msg->solution_age);
139  valid = valid && ParseUInt8(sentence.body[13], msg->num_satellites_tracked);
140  valid = valid && ParseUInt8(sentence.body[14], msg->num_satellites_used_in_solution);
141  valid = valid && ParseUInt8(sentence.body[15], msg->num_gps_and_glonass_l1_used_in_solution);
142  valid = valid && ParseUInt8(sentence.body[16], msg->num_gps_and_glonass_l1_and_l2_used_in_solution);
143 
144  // skip reserved field
145  uint32_t extended_solution_status = 0;
146  valid = valid && ParseUInt32(sentence.body[18], extended_solution_status, 16);
148  extended_solution_status, msg->extended_solution_status);
149 
150  // skip reserved field
151  uint32_t signal_mask = 0;
152  valid = valid && ParseUInt32(sentence.body[20], signal_mask, 16);
153  GetSignalsUsed(signal_mask, msg->signal_mask);
154 
155  if (!valid)
156  {
157  throw ParseException("Invalid field in BESTPOS message");
158  }
159 
160  return msg;
161  }
162 }
msg
uint16_t ParseUInt16(const uint8_t *buffer)
Converts a buffer containing 2 bytes into an unsigned 16-bit int.
bool ParseUInt8(const std::string &string, uint8_t &value, int32_t base=10)
Parses a string containing an integer number into a uint16_t.
novatel_gps_msgs::NovatelPositionPtr ParseAscii(const NovatelSentence &sentence) noexcept(false) override
Converts sentence into a ROS message pointer and returns it.
Definition: bestpos.cpp:110
static constexpr size_t ASCII_LENGTH
Definition: bestpos.h:53
const size_t MAX_POSITION_TYPE
Definition: parsing_utils.h:56
uint32_t GetMessageId() const override
Definition: bestpos.cpp:40
novatel_gps_msgs::NovatelMessageHeader ParseAscii(const NovatelSentence &sentence) noexcept(false) override
Converts sentence into a ROS message pointer and returns it.
Definition: header.cpp:103
const std::string DATUMS[]
Definition: parsing_utils.h:76
double ParseDouble(const uint8_t *buffer)
Converts a buffer containing 8 bytes into a double.
const std::string POSITION_TYPES[]
Definition: parsing_utils.h:57
static const std::string MESSAGE_NAME
Definition: bestpos.h:54
uint32_t ParseUInt32(const uint8_t *buffer)
Converts a buffer containing 4 bytes into an unsigned 32-bit int.
float ParseFloat(const uint8_t *buffer)
Converts a buffer containing 4 bytes into a float.
novatel_gps_msgs::NovatelPositionPtr ParseBinary(const BinaryMessage &bin_msg) noexcept(false) override
Converts bin_msg into a ROS message pointer and returns it.
Definition: bestpos.cpp:50
const std::string SOLUTION_STATUSES[]
Definition: parsing_utils.h:50
void GetExtendedSolutionStatusMessage(uint32_t status, novatel_gps_msgs::NovatelExtendedSolutionStatus &msg)
void GetSignalsUsed(uint32_t mask, novatel_gps_msgs::NovatelSignalMask &msg)
novatel_gps_msgs::NovatelMessageHeader ParseBinary(const BinaryMessage &bin_msg) noexcept(false) override
Converts bin_msg into a ROS message pointer and returns it.
Definition: header.cpp:44
const size_t MAX_SOLUTION_STATUS
Definition: parsing_utils.h:49
const size_t MAX_DATUM
Definition: parsing_utils.h:75
const std::string GetMessageName() const override
Definition: bestpos.cpp:45
static constexpr uint16_t MESSAGE_ID
Definition: bestpos.h:51
static constexpr size_t BINARY_LENGTH
Definition: bestpos.h:52


novatel_gps_driver
Author(s):
autogenerated on Thu Jul 16 2020 03:17:30