psrdop2.cpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (C) 2019 All Right Reserved, Southwest Research Institute® (SwRI®)
4 //
5 // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
6 // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
7 // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
8 // PARTICULAR PURPOSE.
9 //
10 // *****************************************************************************
11 
14 #include <sstream>
15 #include <boost/make_shared.hpp>
16 
17 const std::string novatel_gps_driver::Psrdop2Parser::MESSAGE_NAME = "PSRDOP2";
18 
20 {
21  return MESSAGE_ID;
22 }
23 
25 {
26  return MESSAGE_NAME;
27 }
28 
29 novatel_gps_msgs::NovatelPsrdop2Ptr
31 {
32  uint32_t num_systems = ParseUInt32(&bin_msg.data_[16]);
33  if (bin_msg.data_.size() != (BINARY_SYSTEM_LENGTH * num_systems) + BINARY_BODY_LENGTH)
34  {
35  std::stringstream error;
36  error << "Unexpected PSRDOP2 message size: " << bin_msg.data_.size();
37  throw ParseException(error.str());
38  }
39 
40  auto ros_msg = boost::make_shared<novatel_gps_msgs::NovatelPsrdop2>();
41 
42  HeaderParser header_parser;
43  ros_msg->novatel_msg_header = header_parser.ParseBinary(bin_msg);
44  ros_msg->novatel_msg_header.message_name = MESSAGE_NAME;
45 
46  ros_msg->gdop = ParseFloat(&bin_msg.data_[0]);
47 
48  ros_msg->pdop = ParseFloat(&bin_msg.data_[4]);
49 
50  ros_msg->hdop = ParseFloat(&bin_msg.data_[8]);
51 
52  ros_msg->vdop = ParseFloat(&bin_msg.data_[12]);
53 
54  ros_msg->systems.reserve(num_systems);
55  for (uint32_t i = 0; i < num_systems; i++)
56  {
57  size_t system_offset = BINARY_BODY_LENGTH + i * BINARY_SYSTEM_LENGTH;
58  novatel_gps_msgs::NovatelPsrdop2System system;
59 
60  system.system = GetSystemName(ParseUInt32(&bin_msg.data_[system_offset]));
61  system.tdop = ParseFloat(&bin_msg.data_[system_offset+4]);
62 
63  ros_msg->systems.push_back(system);
64  }
65 
66  return ros_msg;
67 }
68 
69 novatel_gps_msgs::NovatelPsrdop2Ptr
71 {
72  if (sentence.body.size() < ASCII_BODY_FIELDS)
73  {
74  std::stringstream error;
75  error << "Unexpected number of body fields in PSRDOP2 log: " << sentence.body.size();
76  throw ParseException(error.str());
77  }
78 
79  uint32_t num_systems = 0;
80  ParseUInt32(sentence.body[4], num_systems);
81 
82  if (sentence.body.size() != ASCII_BODY_FIELDS + num_systems * ASCII_SYSTEM_FIELDS)
83  {
84  std::stringstream error;
85  error << "Size of PSRDOP2 log (" << sentence.body.size() << ") did not match expected size ("
86  << ASCII_BODY_FIELDS + num_systems * ASCII_SYSTEM_FIELDS << ").";
87  throw ParseException(error.str());
88  }
89 
90  bool valid = true;
91  auto msg = boost::make_shared<novatel_gps_msgs::NovatelPsrdop2>();
92  HeaderParser h_parser;
93  msg->novatel_msg_header = h_parser.ParseAscii(sentence);
94  valid &= ParseFloat(sentence.body[0], msg->gdop);
95  valid &= ParseFloat(sentence.body[1], msg->pdop);
96  valid &= ParseFloat(sentence.body[2], msg->hdop);
97  valid &= ParseFloat(sentence.body[3], msg->vdop);
98 
99  msg->systems.reserve(num_systems);
100  for (size_t i = 0; i < num_systems; i++)
101  {
102  novatel_gps_msgs::NovatelPsrdop2System system;
103  size_t offset = 5 + i * ASCII_SYSTEM_FIELDS;
104  system.system = sentence.body[offset];
105  valid &= ParseFloat(sentence.body[offset+1], system.tdop);
106  msg->systems.push_back(system);
107  }
108 
109  if (!valid)
110  {
111  std::stringstream error;
112  error << "Error parsing PSRDOP2 log.";
113  throw ParseException(error.str());
114  }
115  return msg;
116 }
117 
119 {
120  switch (system_id)
121  {
122  case 0:
123  return "GPS";
124  case 1:
125  return "GLONASS";
126  case 2:
127  return "GALILEO";
128  case 3:
129  return "BEIDOU";
130  case 4:
131  return "NAVIC";
132  case 99:
133  return "AUTO";
134  default:
135  return "UNKNOWN";
136  }
137 }
msg
static constexpr size_t ASCII_BODY_FIELDS
Definition: psrdop2.h:53
static constexpr size_t BINARY_BODY_LENGTH
Definition: psrdop2.h:56
static constexpr size_t ASCII_SYSTEM_FIELDS
Definition: psrdop2.h:54
static constexpr size_t BINARY_SYSTEM_LENGTH
Definition: psrdop2.h:55
novatel_gps_msgs::NovatelPsrdop2Ptr ParseAscii(const NovatelSentence &sentence) override
Converts sentence into a ROS message pointer and returns it.
Definition: psrdop2.cpp:70
std::string GetSystemName(uint32_t system_id)
Definition: psrdop2.cpp:118
uint32_t GetMessageId() const override
Definition: psrdop2.cpp:19
uint32_t ParseUInt32(const uint8_t *buffer)
Converts a buffer containing 4 bytes into an unsigned 32-bit int.
const std::string GetMessageName() const override
Definition: psrdop2.cpp:24
float ParseFloat(const uint8_t *buffer)
Converts a buffer containing 4 bytes into a float.
std::vector< std::string > body
static const std::string MESSAGE_NAME
Definition: psrdop2.h:57
novatel_gps_msgs::NovatelPsrdop2Ptr ParseBinary(const BinaryMessage &bin_msg) override
Converts bin_msg into a ROS message pointer and returns it.
Definition: psrdop2.cpp:30
static constexpr uint16_t MESSAGE_ID
Definition: psrdop2.h:52
std::vector< uint8_t > data_


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