gpgsa.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 #include <boost/make_shared.hpp>
32 
33 const std::string novatel_gps_driver::GpgsaParser::MESSAGE_NAME = "GPGSA";
34 
36 {
37  return 0;
38 }
39 
41 {
42  return MESSAGE_NAME;
43 }
44 
46 {
47  // Check the length first -- should be 18 elements long
48  const size_t LENGTH = 18;
49  if (sentence.body.size() != LENGTH)
50  {
51  std::stringstream error;
52  error << "Expected GPGSA length " << LENGTH
53  << ", actual length " << sentence.body.size();
54  throw ParseException(error.str());
55  }
56 
57  novatel_gps_msgs::GpgsaPtr msg = boost::make_shared<novatel_gps_msgs::Gpgsa>();
58  msg->message_id = sentence.body[0];
59  msg->auto_manual_mode = sentence.body[1];
60  ParseUInt8(sentence.body[2], msg->fix_mode);
61  // Words 3-14 of the sentence are SV IDs. Copy only the non-null strings.
62  msg->sv_ids.resize(12, 0);
63  size_t n_svs = 0;
64  for (std::vector<std::string>::const_iterator id = sentence.body.begin()+3; id < sentence.body.begin()+15; ++id)
65  {
66  if (! id->empty())
67  {
68  ParseUInt8(*id, msg->sv_ids[n_svs]);
69  ++n_svs;
70  }
71  }
72  msg->sv_ids.resize(n_svs);
73 
74  ParseFloat(sentence.body[15], msg->pdop);
75  ParseFloat(sentence.body[16], msg->hdop);
76  ParseFloat(sentence.body[17], msg->vdop);
77  return msg;
78 }
msg
bool ParseUInt8(const std::string &string, uint8_t &value, int32_t base=10)
Parses a string containing an integer number into a uint16_t.
float ParseFloat(const uint8_t *buffer)
Converts a buffer containing 4 bytes into a float.
const std::string GetMessageName() const override
Definition: gpgsa.cpp:40
static const std::string MESSAGE_NAME
Definition: gpgsa.h:47
uint32_t GetMessageId() const override
Definition: gpgsa.cpp:35
novatel_gps_msgs::GpgsaPtr ParseAscii(const NmeaSentence &sentence) override
Converts sentence into a ROS message pointer and returns it.
Definition: gpgsa.cpp:45


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