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

Derived class for parsing GGA messages. More...

#include <gpgga.hpp>

Inheritance diagram for GpggaParser:
Inheritance graph
[legend]
Collaboration diagram for 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 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 83 of file gpgga.hpp.

Constructor & Destructor Documentation

◆ GpggaParser()

GpggaParser::GpggaParser ( )
inline

Constructor of the class GpggaParser.

Definition at line 90 of file gpgga.hpp.

References getMessageID(), parseASCII(), and wasLastGPGGAValid().

bool was_last_gpgga_valid_
Declares a boolean representing whether or not the last GPGGA message was valid.
Definition: gpgga.hpp:120
Here is the call graph for this function:

Member Function Documentation

◆ getMessageID()

const std::string GpggaParser::getMessageID ( ) const
overridevirtual

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

Returns
The message ID

Implements 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:114
Here is the caller graph for this function:

◆ parseASCII()

rosaic::GpggaPtr 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 RxMessage 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 BaseParser< rosaic::GpggaPtr >.

Definition at line 51 of file gpgga.cpp.

References parsing_utilities::convertDMSToDegrees(), parsing_utilities::convertUTCDoubleToSeconds(), parsing_utilities::convertUTCtoUnix(), g_frame_id, g_use_gnss_time, parsing_utilities::parseDouble(), parsing_utilities::parseFloat(), parsing_utilities::parseUInt32(), string_utilities::toDouble(), and was_last_gpgga_valid_.

Referenced by GpggaParser(), and io_comm_rx::RxMessage::read().

52 {
53  //ROS_DEBUG("Just testing that first entry is indeed what we expect it to be: %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 = g_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  if(g_use_gnss_time)
78  {
79  //ROS_DEBUG("utc_double is %f", (float) utc_double);
80  msg->utc_seconds = parsing_utilities::convertUTCDoubleToSeconds(utc_double);
81 
82  // The Header's Unix Epoch time stamp
83  time_t unix_time_seconds = parsing_utilities::convertUTCtoUnix(utc_double);
84  // The following assumes that there are two digits after the decimal point in utc_double, i.e. in the NMEA UTC time.
85  uint32_t unix_time_nanoseconds = (static_cast<uint32_t>(utc_double*100)%100)*10000;
86  msg->header.stamp.sec = unix_time_seconds;
87  msg->header.stamp.nsec = unix_time_nanoseconds;
88  }
89  else
90  {
91  ros::Time time_obj;
92  time_obj = ros::Time::now();
93  msg->header.stamp.sec = time_obj.sec;
94  msg->header.stamp.nsec = time_obj.nsec;
95  }
96  }
97  else
98  {
99  throw ParseException("Error parsing UTC seconds in GPGGA"); // E.g. if one of the fields of the NMEA UTC string is empty
100  }
101  }
102 
103  bool valid = true;
104 
105  double latitude = 0.0;
106  valid = valid && parsing_utilities::parseDouble(sentence.get_body()[2], latitude);
107  msg->lat = parsing_utilities::convertDMSToDegrees(latitude);
108 
109  double longitude = 0.0;
110  valid = valid && parsing_utilities::parseDouble(sentence.get_body()[4], longitude);
111  msg->lon = parsing_utilities::convertDMSToDegrees(longitude);
112 
113  msg->lat_dir = sentence.get_body()[3];
114  msg->lon_dir = sentence.get_body()[5];
115  valid = valid && parsing_utilities::parseUInt32(sentence.get_body()[6], msg->gps_qual);
116  valid = valid && parsing_utilities::parseUInt32(sentence.get_body()[7], msg->num_sats);
117  //ROS_INFO("Valid is %s so far with number of satellites in use being %s", valid ? "true" : "false", sentence.get_body()[7].c_str());
118 
119  valid = valid && parsing_utilities::parseFloat(sentence.get_body()[8], msg->hdop);
120  valid = valid && parsing_utilities::parseFloat(sentence.get_body()[9], msg->alt);
121  msg->altitude_units = sentence.get_body()[10];
122  valid = valid && parsing_utilities::parseFloat(sentence.get_body()[11], msg->undulation);
123  msg->undulation_units = sentence.get_body()[12];
124  double diff_age_temp;
125  valid = valid && parsing_utilities::parseDouble(sentence.get_body()[13], diff_age_temp);
126  msg->diff_age = static_cast<uint32_t>(round(diff_age_temp));
127  msg->station_id = sentence.get_body()[14];
128 
129  if (!valid)
130  {
131  was_last_gpgga_valid_ = false;
132  throw ParseException("GPGGA message was invalid.");
133  }
134 
135  // If we made it this far, we successfully parsed the message and will consider it to be valid.
136  was_last_gpgga_valid_ = true;
137 
138  return msg;
139 }
std::string g_frame_id
The frame ID used in the header of every published ROS message.
bool toDouble(const std::string &string, double &value)
Interprets the contents of "string" as a floating point number of type double It stores the "string"&#39;...
float parseFloat(const uint8_t *buffer)
Converts a 4-byte-buffer into a float.
std::vector< std::string > get_body() const
double convertUTCDoubleToSeconds(double utc_double)
Converts UTC time from the without-colon-delimiter format to the number-of-seconds-since-midnight for...
uint32_t parseUInt32(const uint8_t *buffer)
Converts a 4-byte-buffer into an unsigned 32-bit integer.
double convertDMSToDegrees(double dms)
Converts latitude or longitude from the DMS notation (in the without-colon-delimiter format)...
time_t convertUTCtoUnix(double utc_double)
Converts UTC time from the without-colon-delimiter format to Unix Epoch time (a number-of-seconds-sin...
Class to declare error message format when parsing, derived from the public class "std::runtime_error...
bool g_use_gnss_time
double parseDouble(const uint8_t *buffer)
Converts an 8-byte-buffer into a double.
bool was_last_gpgga_valid_
Declares a boolean representing whether or not the last GPGGA message was valid.
Definition: gpgga.hpp:120
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wasLastGPGGAValid()

bool 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 141 of file gpgga.cpp.

References was_last_gpgga_valid_.

Referenced by GpggaParser().

142 {
143  return was_last_gpgga_valid_;
144 }
bool was_last_gpgga_valid_
Declares a boolean representing whether or not the last GPGGA message was valid.
Definition: gpgga.hpp:120
Here is the caller graph for this function:

Field Documentation

◆ MESSAGE_ID

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

Declares the string MESSAGE_ID.

Definition at line 114 of file gpgga.hpp.

Referenced by getMessageID().

◆ was_last_gpgga_valid_

bool GpggaParser::was_last_gpgga_valid_
private

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

Definition at line 120 of file gpgga.hpp.

Referenced by parseASCII(), and wasLastGPGGAValid().


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