bestutm.cpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2018, 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 BestutmParser::MESSAGE_NAME = "BESTUTM";
39 
40  uint32_t BestutmParser::GetMessageId() const
41  {
42  return MESSAGE_ID;
43  }
44 
45  const std::string BestutmParser::GetMessageName() const
46  {
47  return MESSAGE_NAME;
48  }
49 
50  novatel_gps_msgs::NovatelUtmPositionPtr BestutmParser::ParseBinary(const BinaryMessage& bin_msg) noexcept(false)
51  {
52  if (bin_msg.data_.size() != BINARY_LENGTH)
53  {
54  std::stringstream error;
55  error << "Unexpected BESTUTM message length: " << bin_msg.data_.size();
56  throw ParseException(error.str());
57  }
58  novatel_gps_msgs::NovatelUtmPositionPtr ros_msg =
59  boost::make_shared<novatel_gps_msgs::NovatelUtmPosition>();
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->lon_zone_number = ParseUInt32(&bin_msg.data_[8]);
81  ros_msg->lat_zone_letter = (char)ParseUInt32(&bin_msg.data_[12]);
82  ros_msg->northing = ParseDouble(&bin_msg.data_[16]);
83  ros_msg->easting = ParseDouble(&bin_msg.data_[24]);
84  ros_msg->height = ParseDouble(&bin_msg.data_[32]);
85  ros_msg->undulation = ParseFloat(&bin_msg.data_[40]);
86  uint16_t datum_id = ParseUInt16(&bin_msg.data_[44]);
87  if (datum_id > MAX_DATUM)
88  {
89  std::stringstream error;
90  error << "Unknown datum: " << datum_id;
91  throw ParseException(error.str());
92  }
93  ros_msg->datum_id = DATUMS[datum_id];
94  ros_msg->northing_sigma = ParseFloat(&bin_msg.data_[48]);
95  ros_msg->easting_sigma = ParseFloat(&bin_msg.data_[52]);
96  ros_msg->height_sigma = ParseFloat(&bin_msg.data_[56]);
97  ros_msg->base_station_id.resize(4);
98  std::copy(&bin_msg.data_[60], &bin_msg.data_[64], &ros_msg->base_station_id[0]);
99  ros_msg->diff_age = ParseFloat(&bin_msg.data_[64]);
100  ros_msg->solution_age = ParseFloat(&bin_msg.data_[68]);
101  ros_msg->num_satellites_tracked = bin_msg.data_[72];
102  ros_msg->num_satellites_used_in_solution = bin_msg.data_[73];
103  ros_msg->num_gps_and_glonass_l1_used_in_solution = bin_msg.data_[74];
104  ros_msg->num_gps_and_glonass_l1_and_l2_used_in_solution = bin_msg.data_[75];
105  GetExtendedSolutionStatusMessage(bin_msg.data_[77],
106  ros_msg->extended_solution_status);
107  GetSignalsUsed(bin_msg.data_[78], ros_msg->signal_mask);
108 
109  return ros_msg;
110  }
111 
112  novatel_gps_msgs::NovatelUtmPositionPtr BestutmParser::ParseAscii(const NovatelSentence& sentence) noexcept(false)
113  {
114  novatel_gps_msgs::NovatelUtmPositionPtr msg =
115  boost::make_shared<novatel_gps_msgs::NovatelUtmPosition>();
116  HeaderParser h_parser;
117  msg->novatel_msg_header = h_parser.ParseAscii(sentence);
118 
119  if (sentence.body.size() != ASCII_LENGTH)
120  {
121  std::stringstream error;
122  error << "Unexpected number of BESTUTM message fields: " << sentence.body.size();
123  throw ParseException(error.str());
124  }
125 
126  bool valid = true;
127 
128  msg->solution_status = sentence.body[0];
129  msg->position_type = sentence.body[1];
130  valid = valid && ParseUInt32(sentence.body[2], msg->lon_zone_number);
131  msg->lat_zone_letter = sentence.body[3];
132  valid = valid && ParseDouble(sentence.body[4], msg->northing);
133  valid = valid && ParseDouble(sentence.body[5], msg->easting);
134  valid = valid && ParseDouble(sentence.body[6], msg->height);
135  valid = valid && ParseFloat(sentence.body[7], msg->undulation);
136  msg->datum_id = sentence.body[8];
137  valid = valid && ParseFloat(sentence.body[9], msg->northing_sigma);
138  valid = valid && ParseFloat(sentence.body[10], msg->easting_sigma);
139  valid = valid && ParseFloat(sentence.body[11], msg->height_sigma);
140  msg->base_station_id = sentence.body[12];
141  valid = valid && ParseFloat(sentence.body[13], msg->diff_age);
142  valid = valid && ParseFloat(sentence.body[14], msg->solution_age);
143  valid = valid && ParseUInt8(sentence.body[15], msg->num_satellites_tracked);
144  valid = valid && ParseUInt8(sentence.body[16], msg->num_satellites_used_in_solution);
145  valid = valid && ParseUInt8(sentence.body[17], msg->num_gps_and_glonass_l1_used_in_solution);
146  valid = valid && ParseUInt8(sentence.body[18], msg->num_gps_and_glonass_l1_and_l2_used_in_solution);
147 
148  // skip reserved field
149  uint32_t extended_solution_status = 0;
150  valid = valid && ParseUInt32(sentence.body[20], extended_solution_status, 16);
152  extended_solution_status, msg->extended_solution_status);
153 
154  // skip reserved field (Galileo and BeiDou sig mask)
155  uint32_t signal_mask = 0;
156  valid = valid && ParseUInt32(sentence.body[22], signal_mask, 16);
157  GetSignalsUsed(signal_mask, msg->signal_mask);
158 
159  if (!valid)
160  {
161  throw ParseException("Invalid field in BESTUTM message");
162  }
163 
164  return msg;
165  }
166 }
static constexpr size_t ASCII_LENGTH
Definition: bestutm.h:53
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.
static const std::string MESSAGE_NAME
Definition: bestutm.h:54
uint32_t GetMessageId() const override
Definition: bestutm.cpp:40
const size_t MAX_POSITION_TYPE
Definition: parsing_utils.h:56
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
novatel_gps_msgs::NovatelUtmPositionPtr ParseAscii(const NovatelSentence &sentence) noexcept(false) override
Converts sentence into a ROS message pointer and returns it.
Definition: bestutm.cpp:112
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 constexpr size_t BINARY_LENGTH
Definition: bestutm.h:52
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.
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
novatel_gps_msgs::NovatelUtmPositionPtr ParseBinary(const BinaryMessage &bin_msg) noexcept(false) override
Converts bin_msg into a ROS message pointer and returns it.
Definition: bestutm.cpp:50
const size_t MAX_SOLUTION_STATUS
Definition: parsing_utils.h:49
static constexpr uint16_t MESSAGE_ID
Definition: bestutm.h:51
const size_t MAX_DATUM
Definition: parsing_utils.h:75
const std::string GetMessageName() const override
Definition: bestutm.cpp:45


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