dual_antenna_heading.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 DualAntennaHeadingParser::MESSAGE_NAME = "DUALANTENNAHEADING";
39 
41  {
42  return MESSAGE_ID;
43  }
44 
45  const std::string DualAntennaHeadingParser::GetMessageName() const
46  {
47  return MESSAGE_NAME;
48  }
49 
50  novatel_gps_msgs::NovatelDualAntennaHeadingPtr DualAntennaHeadingParser::ParseBinary(const BinaryMessage& bin_msg) throw(ParseException)
51  {
52  if (bin_msg.data_.size() != BINARY_LENGTH)
53  {
54  std::stringstream error;
55  error << "Unexpected DUALANTENNAHEADING message length: " << bin_msg.data_.size();
56  throw ParseException(error.str());
57  }
58  novatel_gps_msgs::NovatelDualAntennaHeadingPtr ros_msg =
59  boost::make_shared<novatel_gps_msgs::NovatelDualAntennaHeading>();
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 
73  uint16_t pos_type = ParseUInt16(&bin_msg.data_[4]);
74  if (pos_type > MAX_POSITION_TYPE)
75  {
76  std::stringstream error;
77  error << "Unknown position type: " << pos_type;
78  throw ParseException(error.str());
79  }
80  ros_msg->position_type = POSITION_TYPES[pos_type];
81 
82  ros_msg->baseline_length = ParseFloat(&bin_msg.data_[8]);
83 
84  ros_msg->heading = ParseFloat(&bin_msg.data_[12]);
85  ros_msg->pitch = ParseFloat(&bin_msg.data_[16]);
86 
87  // Bytes 20-23 reserved
88 
89  ros_msg->heading_sigma = ParseFloat(&bin_msg.data_[24]);
90  ros_msg->pitch_sigma = ParseFloat(&bin_msg.data_[28]);
91 
92  ros_msg->station_id.resize(4);
93  std::copy(&bin_msg.data_[32], &bin_msg.data_[36], &ros_msg->station_id[0]);
94 
95  ros_msg->num_satellites_tracked = bin_msg.data_[36];
96  ros_msg->num_satellites_used_in_solution = bin_msg.data_[37];
97  ros_msg->num_satellites_above_elevation_mask_angle = bin_msg.data_[38];
98  ros_msg->num_satellites_above_elevation_mask_angle_l2 = bin_msg.data_[39];
99 
100  ros_msg->solution_source = SolutionSourceToMsgEnum(bin_msg.data_[40]);
101 
102  GetExtendedSolutionStatusMessage(bin_msg.data_[41],
103  ros_msg->extended_solution_status);
104 
105  // Byte 42 is reserved
106 
107  GetSignalsUsed(bin_msg.data_[43], ros_msg->signal_mask);
108 
109  return ros_msg;
110  }
111 
112  novatel_gps_msgs::NovatelDualAntennaHeadingPtr DualAntennaHeadingParser::ParseAscii(const NovatelSentence& sentence) throw(ParseException)
113  {
114  novatel_gps_msgs::NovatelDualAntennaHeadingPtr ros_msg =
115  boost::make_shared<novatel_gps_msgs::NovatelDualAntennaHeading>();
116  HeaderParser h_parser;
117  ros_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 DUALANTENNAHEADING message fields: " << sentence.body.size();
123  throw ParseException(error.str());
124  }
125 
126  bool valid = true;
127 
128  ros_msg->solution_status = sentence.body[0];
129  ros_msg->position_type = sentence.body[1];
130 
131  valid = valid && ParseFloat(sentence.body[2], ros_msg->baseline_length);
132 
133  valid = valid && ParseFloat(sentence.body[3], ros_msg->heading);
134  valid = valid && ParseFloat(sentence.body[4], ros_msg->pitch);
135 
136  // Skip reserved field
137 
138  valid = valid && ParseFloat(sentence.body[6], ros_msg->heading_sigma);
139  valid = valid && ParseFloat(sentence.body[7], ros_msg->pitch_sigma);
140 
141  ros_msg->station_id = sentence.body[8];
142 
143  valid = valid && ParseUInt8(sentence.body[9], ros_msg->num_satellites_tracked);
144  valid = valid && ParseUInt8(sentence.body[10], ros_msg->num_satellites_used_in_solution);
145  valid = valid && ParseUInt8(sentence.body[11], ros_msg->num_satellites_above_elevation_mask_angle);
146  valid = valid && ParseUInt8(sentence.body[12], ros_msg->num_satellites_above_elevation_mask_angle_l2);
147 
148  uint32_t solution_source = 0;
149  valid = valid && ParseUInt32(sentence.body[13], solution_source, 16);
150  ros_msg->solution_source = SolutionSourceToMsgEnum((uint8_t)solution_source);
151 
152  uint32_t extended_solution_status = 0;
153  valid = valid && ParseUInt32(sentence.body[14], extended_solution_status, 16);
155  extended_solution_status, ros_msg->extended_solution_status);
156 
157  // Skip reserved field
158 
159  uint32_t signal_mask = 0;
160  valid = valid && ParseUInt32(sentence.body[16], signal_mask, 16);
161  GetSignalsUsed(signal_mask, ros_msg->signal_mask);
162 
163  if (!valid)
164  {
165  throw ParseException("Invalid field in DUALANTENNAHEADING message");
166  }
167 
168  return ros_msg;
169  }
170 
172  uint8_t source_bits = source_mask & 0b00001100;
173  if (source_mask == 0b0000) {
174  return novatel_gps_msgs::NovatelDualAntennaHeading::SOURCE_PRIMARY_ANTENNA;
175  } else if (source_mask == 0b0100) {
176  return novatel_gps_msgs::NovatelDualAntennaHeading::SOURCE_SECONDARY_ANTENNA;
177  } else {
178  throw ParseException("DUALANTENNAHEADING Solution Source could not be parsed due to unknown source");
179  }
180  }
181 };
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.
const size_t MAX_POSITION_TYPE
Definition: parsing_utils.h:56
novatel_gps_msgs::NovatelDualAntennaHeadingPtr ParseAscii(const NovatelSentence &sentence) override
Converts sentence into a ROS message pointer and returns it.
novatel_gps_msgs::NovatelMessageHeader ParseAscii(const NovatelSentence &sentence) override
Converts sentence into a ROS message pointer and returns it.
Definition: header.cpp:103
novatel_gps_msgs::NovatelDualAntennaHeadingPtr ParseBinary(const BinaryMessage &bin_msg) override
Converts bin_msg into a ROS message pointer and returns it.
const std::string POSITION_TYPES[]
Definition: parsing_utils.h:57
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)
const size_t MAX_SOLUTION_STATUS
Definition: parsing_utils.h:49
novatel_gps_msgs::NovatelMessageHeader ParseBinary(const BinaryMessage &bin_msg) override
Converts bin_msg into a ROS message pointer and returns it.
Definition: header.cpp:44
const std::string GetMessageName() const override


novatel_gps_driver
Author(s):
autogenerated on Wed Jul 3 2019 19:36:46