ROSaic
Public Member Functions | Static Public Attributes | Private Attributes
rosaic_driver::GpggaParser Class Reference

Derived class for parsing GGA messages. More...

#include <gpgga.hpp>

Inheritance diagram for rosaic_driver::GpggaParser:
Inheritance graph
[legend]
Collaboration diagram for rosaic_driver::GpggaParser:
Collaboration graph
[legend]

Public Member Functions

 GpggaParser ()
 Constructor of the class GpggaParser. More...
 
const std::string GetMessageID () const override
 Returns the ASCII message ID, here "$GPGGA". More...
 
rosaic::GpggaPtr ParseASCII (const NMEASentence &sentence) noexcept(false) override
 Parses one GGA message. More...
 
bool WasLastGPGGAValid () const
 Tells us whether the last GGA message was valid or not. More...
 
- Public Member Functions inherited from rosaic_driver::BaseParser< rosaic::GpggaPtr >
 BaseParser ()=default
 Default constructor of the class BaseParser. More...
 
virtual ~BaseParser ()=default
 Default destructor of the class BaseParser. More...
 
rosaic::GpggaPtr ParseBinary (const SBFStructT &bin_msg) noexcept(false)
 Converts bin_msg into a ROS message pointer (e.g. nmea_msgs::GpggaPtr) and returns it. More...
 

Static Public Attributes

static const std::string MESSAGE_ID = "$GPGGA"
 Declares the string MESSAGE_ID. More...
 

Private Attributes

bool was_last_gpgga_valid_
 Declares a boolean representing whether or not the last GPGGA message was valid. More...
 

Detailed Description

Derived class for parsing GGA messages.

Date
13/08/20

Definition at line 86 of file gpgga.hpp.

Constructor & Destructor Documentation

◆ GpggaParser()

rosaic_driver::GpggaParser::GpggaParser ( )
inline

Constructor of the class GpggaParser.

Definition at line 93 of file gpgga.hpp.

References GetMessageID(), ParseASCII(), and WasLastGPGGAValid().

93 : BaseParser<rosaic::GpggaPtr>(), was_last_gpgga_valid_(false) {}
bool was_last_gpgga_valid_
Declares a boolean representing whether or not the last GPGGA message was valid.
Definition: gpgga.hpp:123
Here is the call graph for this function:

Member Function Documentation

◆ GetMessageID()

const std::string rosaic_driver::GpggaParser::GetMessageID ( ) const
overridevirtual

Returns the ASCII message ID, here "$GPGGA".

Returns
The message ID

Implements rosaic_driver::BaseParser< rosaic::GpggaPtr >.

Definition at line 41 of file gpgga.cpp.

References MESSAGE_ID.

Referenced by GpggaParser().

42 {
44 }
static const std::string MESSAGE_ID
Declares the string MESSAGE_ID.
Definition: gpgga.hpp:117
Here is the caller graph for this function:

◆ ParseASCII()

rosaic::GpggaPtr rosaic_driver::GpggaParser::ParseASCII ( const NMEASentence sentence)
overridevirtualnoexcept

Parses one GGA message.

Parameters
[in]sentenceThe GGA message to be parsed
Returns
A ROS message pointer of ROS type rosaic::GpggaPtr

Caution: Due to the occurrence of the throw keyword, this method ParseASCII should be called within a try / catch framework... Note: This method is called from within the read() method of the mosaicMessage class by including the checksum part in the argument "sentence" here, though the checksum is never parsed: It would be sentence.get_body()[15] if anybody ever needs it.

Reimplemented from rosaic_driver::BaseParser< rosaic::GpggaPtr >.

Definition at line 51 of file gpgga.cpp.

References rosaic_driver::ConvertDMSToDegrees(), frame_id, rosaic_driver::ParseDouble(), rosaic_driver::ParseFloat(), rosaic_driver::ParseUInt32(), string_utilities::ToDouble(), rosaic_driver::UTCDoubleToSeconds(), rosaic_driver::UTCtoUnix(), and was_last_gpgga_valid_.

Referenced by GpggaParser(), and io_comm_mosaic::mosaicMessage::Read().

52 {
53  //ROS_DEBUG("Just testing that first entry is indeed what we expect it to: %s", sentence.get_body()[0].c_str());
54  // Check the length first, which should be 16 elements.
55  const size_t LEN = 16;
56  if (sentence.get_body().size() > LEN || sentence.get_body().size() < LEN)
57  {
58  std::stringstream error;
59  error << "GGA parsing failed: Expected GPGGA length is " << LEN << ", but actual length is " << sentence.get_body().size();
60  throw ParseException(error.str());
61  }
62 
63  rosaic::GpggaPtr msg = boost::make_shared<rosaic::Gpgga>();
64  msg->header.frame_id = frame_id;
65 
66  msg->message_id = sentence.get_body()[0];
67 
68  if (sentence.get_body()[1].empty() || sentence.get_body()[1] == "0")
69  {
70  msg->utc_seconds = 0;
71  }
72  else
73  {
74  double utc_double;
75  if (string_utilities::ToDouble(sentence.get_body()[1], utc_double))
76  {
77  //ROS_DEBUG("utc_double is %f", (float) utc_double);
78  msg->utc_seconds = UTCDoubleToSeconds(utc_double);
79 
80  // The Header's Unix Epoch time stamp
81  time_t unix_time_seconds = UTCtoUnix(utc_double);
82  // The following assumes that there are two digits after the decimal point in utc_double, i.e. in the NMEA UTC time.
83  uint32_t unix_time_nanoseconds = (static_cast<uint32_t>(utc_double*100)%100)*10000;
84  msg->header.stamp.sec = unix_time_seconds;
85  msg->header.stamp.nsec = unix_time_nanoseconds;
86  }
87  else
88  {
89  throw rosaic_driver::ParseException("Error parsing UTC seconds in GPGGA"); // E.g. if one of the fields of the NMEA UTC string is empty
90  }
91  }
92 
93  bool valid = true;
94 
95  double latitude = 0.0;
96  valid = valid && rosaic_driver::ParseDouble(sentence.get_body()[2], latitude);
97  msg->lat = ConvertDMSToDegrees(latitude);
98 
99  double longitude = 0.0;
100  valid = valid && rosaic_driver::ParseDouble(sentence.get_body()[4], longitude);
101  msg->lon = ConvertDMSToDegrees(longitude);
102 
103  msg->lat_dir = sentence.get_body()[3];
104  msg->lon_dir = sentence.get_body()[5];
105  valid = valid && rosaic_driver::ParseUInt32(sentence.get_body()[6], msg->gps_qual);
106  valid = valid && rosaic_driver::ParseUInt32(sentence.get_body()[7], msg->num_sats);
107  //ROS_INFO("Valid is %s so far with number of satellites in use being %s", valid ? "true" : "false", sentence.get_body()[7].c_str());
108 
109  valid = valid && rosaic_driver::ParseFloat(sentence.get_body()[8], msg->hdop);
110  valid = valid && rosaic_driver::ParseFloat(sentence.get_body()[9], msg->alt);
111  msg->altitude_units = sentence.get_body()[10];
112  valid = valid && rosaic_driver::ParseFloat(sentence.get_body()[11], msg->undulation);
113  msg->undulation_units = sentence.get_body()[12];
114  double diff_age_temp;
115  valid = valid && rosaic_driver::ParseDouble(sentence.get_body()[13], diff_age_temp);
116  msg->diff_age = static_cast<uint32_t>(round(diff_age_temp));
117  msg->station_id = sentence.get_body()[14];
118 
119  if (!valid)
120  {
121  was_last_gpgga_valid_ = false;
122  throw ParseException("GPGGA message was invalid.");
123  }
124 
125  // If we made it this far, we successfully parsed the message and will consider it to be valid.
126  was_last_gpgga_valid_ = true;
127 
128  return msg;
129 }
time_t UTCtoUnix(double utc_double)
Converts UTC time from the without-colon-delimiter format, type double, to Unix Epoch time (a number-...
bool ToDouble(const std::string &string, double &value)
Interprets the contents of "string" as a floating point number of type double, stores its value in "v...
float ParseFloat(const uint8_t *buffer)
Converts a 4-byte-buffer into a float.
double ParseDouble(const uint8_t *buffer)
Converts an 8-byte-buffer into a double.
std::string frame_id
The frame ID used in the header of every published ROS message.
bool was_last_gpgga_valid_
Declares a boolean representing whether or not the last GPGGA message was valid.
Definition: gpgga.hpp:123
double UTCDoubleToSeconds(double utc_double)
Converts the UTC time from the without-colon-delimiter format, type double, to the number-of-seconds-...
uint32_t ParseUInt32(const uint8_t *buffer)
Converts a 4-byte-buffer into an unsigned 32-bit integer.
Ćlass to declare error message format when parsing, derived from the public class "std::runtime_error...
double ConvertDMSToDegrees(double dms)
Converts latitude or longitude from the DMS notation (in the without-colon-delimiter format)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WasLastGPGGAValid()

bool rosaic_driver::GpggaParser::WasLastGPGGAValid ( ) const

Tells us whether the last GGA message was valid or not.

Returns
True if last GGA message was valid, false if not

Definition at line 131 of file gpgga.cpp.

References was_last_gpgga_valid_.

Referenced by GpggaParser().

132 {
133  return was_last_gpgga_valid_;
134 }
bool was_last_gpgga_valid_
Declares a boolean representing whether or not the last GPGGA message was valid.
Definition: gpgga.hpp:123
Here is the caller graph for this function:

Field Documentation

◆ MESSAGE_ID

const std::string rosaic_driver::GpggaParser::MESSAGE_ID = "$GPGGA"
static

Declares the string MESSAGE_ID.

Definition at line 117 of file gpgga.hpp.

Referenced by GetMessageID().

◆ was_last_gpgga_valid_

bool rosaic_driver::GpggaParser::was_last_gpgga_valid_
private

Declares a boolean representing whether or not the last GPGGA message was valid.

Definition at line 123 of file gpgga.hpp.

Referenced by ParseASCII(), and WasLastGPGGAValid().


The documentation for this class was generated from the following files: