ROSaic
Data Structures | Functions
rosaic_driver Namespace Reference

Data Structures

class  BaseParser
 Base class for parsing NMEA messages and SBF blocks. More...
 
class  GpggaParser
 Derived class for parsing GGA messages. More...
 
class  NMEASentence
 Struct to split an NMEA sentence into its ID (e.g. the standardized "$GPGGA" or proprietary "$PSSN,HRP") and its body, the latter tokenized into a vector of strings. More...
 
class  ParseException
 Ćlass to declare error message format when parsing, derived from the public class "std::runtime_error". More...
 

Functions

double ParseDouble (const uint8_t *buffer)
 Converts an 8-byte-buffer into a double. More...
 
bool ParseDouble (const std::string &string, double &value)
 Interprets the contents of "string" as a floating point number of type double, stores its value in "value" and returns whether or not all went well. More...
 
float ParseFloat (const uint8_t *buffer)
 Converts a 4-byte-buffer into a float. More...
 
bool ParseFloat (const std::string &string, float &value)
 Interprets the contents of "string" as a floating point number of type float, stores its value in "value" and returns whether or not all went well. More...
 
int16_t ParseInt16 (const uint8_t *buffer)
 Converts a 2-byte-buffer into a signed 16-bit integer. More...
 
bool ParseInt16 (const std::string &string, int16_t &value, int32_t base=10)
 Interprets the contents of "string" as a integer number of type int16_t, stores its value in "value" and returns whether or not all went well. More...
 
int32_t ParseInt32 (const uint8_t *buffer)
 Converts a 4-byte-buffer into a signed 32-bit integer. More...
 
bool ParseInt32 (const std::string &string, int32_t &value, int32_t base=10)
 Interprets the contents of "string" as a integer number of type int32_t, stores its value in "value" and returns whether or not all went well. More...
 
bool ParseUInt8 (const std::string &string, uint8_t &value, int32_t base=10)
 Interprets the contents of "string" as a unsigned integer number of type uint8_t, stores its value in "value" and returns whether or not all went well. More...
 
uint16_t ParseUInt16 (const uint8_t *buffer)
 Converts a 2-byte-buffer into an unsigned 16-bit integer. More...
 
bool ParseUInt16 (const std::string &string, uint16_t &value, int32_t base=10)
 Interprets the contents of "string" as a unsigned integer number of type uint16_t, stores its value in "value" and returns whether or not all went well. More...
 
uint32_t ParseUInt32 (const uint8_t *buffer)
 Converts a 4-byte-buffer into an unsigned 32-bit integer. More...
 
bool ParseUInt32 (const std::string &string, uint32_t &value, int32_t base=10)
 Interprets the contents of "string" as a unsigned integer number of type uint32_t, stores its value in "value" and returns whether or not all went well. More...
 
double UTCDoubleToSeconds (double utc_double)
 Converts the UTC time from the without-colon-delimiter format, type double, to the number-of-seconds-since-midnight format, type double. More...
 
double ConvertDMSToDegrees (double dms)
 Converts latitude or longitude from the DMS notation (in the without-colon-delimiter format), type double, to the pure degree notation, type double. More...
 
time_t UTCtoUnix (double utc_double)
 Converts UTC time from the without-colon-delimiter format, type double, to Unix Epoch time (a number-of-seconds-since-1970/01/01 format), type time_t (usually 32 bits) More...
 

Function Documentation

◆ ConvertDMSToDegrees()

double rosaic_driver::ConvertDMSToDegrees ( double  dms)

Converts latitude or longitude from the DMS notation (in the without-colon-delimiter format), type double, to the pure degree notation, type double.

Recall: One degree is divided into 60 minutes (of arc), and in turn one minute into 60 seconds (of arc). Use of the degrees-minutes-seconds system is also called DMS notation.

Parameters
dmsThe double variable representing latitude or longitude in the DMS notation (in the without-colon-delimiter format)
Returns
The double variable representing latitude or longitude in the pure degree notation

Definition at line 237 of file parsing_utilities.cpp.

Referenced by rosaic_driver::GpggaParser::ParseASCII().

238  {
239  uint32_t whole_degrees = static_cast<uint32_t>(dms) / 100;
240  double minutes = dms - static_cast<double>(whole_degrees * 100);
241  double degrees = static_cast<double>(whole_degrees) + minutes / 60.0;
242  return degrees;
243  }
Here is the caller graph for this function:

◆ ParseDouble() [1/2]

double rosaic_driver::ParseDouble ( const uint8_t *  buffer)

Converts an 8-byte-buffer into a double.

The function assumes that the bytes in the buffer are already arranged with the same endianness as the local platform. It copies the elements in the range [buffer,buffer + sizeof(double)) into the range beginning at reinterpret_cast<uint8_t*>(&x). Recall: data_type *var_name = reinterpret_cast <data_type *>(pointer_variable) converts the pointer type, no return type

Parameters
[in]bufferA pointer to a buffer containing 8 bytes of data
Returns
The double extracted from the data in the buffer

Definition at line 51 of file parsing_utilities.cpp.

Referenced by rosaic_driver::GpggaParser::ParseASCII().

52  {
53  double diff_loc;
54  std::copy(buffer, buffer + sizeof(double), reinterpret_cast<uint8_t*>(&diff_loc));
55  return diff_loc;
56  }
Here is the caller graph for this function:

◆ ParseDouble() [2/2]

bool rosaic_driver::ParseDouble ( const std::string &  string,
double &  value 
)

Interprets the contents of "string" as a floating point number of type double, stores its value in "value" and returns whether or not all went well.

It checks whether an error occurred (via errno) and whether junk characters exist within "string", and returns true if the latter two tests are negative or when the string is empty, false otherwise.

Parameters
[in]stringThe string whose content should be interpreted as a floating point number
[out]valueThe double variable that should be overwritten by the floating point number found in "string"
Returns
True if all went fine, false if not

Definition at line 62 of file parsing_utilities.cpp.

References string_utilities::ToDouble().

63  {
64  return string_utilities::ToDouble(string, value) || string.empty();
65  }
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...
Here is the call graph for this function:

◆ ParseFloat() [1/2]

float rosaic_driver::ParseFloat ( const uint8_t *  buffer)

Converts a 4-byte-buffer into a float.

The function assumes that the bytes in the buffer are already arranged with the same endianness as the local platform. It copies the elements in the range [buffer,buffer + sizeof(double)) into the range beginning at reinterpret_cast<uint8_t*>(&x). Recall: data_type *var_name = reinterpret_cast <data_type *>(pointer_variable) converts the pointer type, no return type

Parameters
[in]bufferA pointer to a buffer containing 4 bytes of data
Returns
The float extracted from the data in the buffer

Definition at line 72 of file parsing_utilities.cpp.

Referenced by rosaic_driver::GpggaParser::ParseASCII().

73  {
74  float diff_loc;
75  std::copy(buffer, buffer + sizeof(float), reinterpret_cast<uint8_t*>(&diff_loc));
76  return diff_loc;
77  }
Here is the caller graph for this function:

◆ ParseFloat() [2/2]

bool rosaic_driver::ParseFloat ( const std::string &  string,
float &  value 
)

Interprets the contents of "string" as a floating point number of type float, stores its value in "value" and returns whether or not all went well.

It checks whether an error occurred (via errno) and whether junk characters exist within "string", and returns true if the latter two tests are negative or when the string is empty, false otherwise.

Parameters
[in]stringThe string whose content should be interpreted as a floating point number
[out]valueThe float variable that should be overwritten by the floating point number found in "string"
Returns
True if all went fine, false if not

Definition at line 83 of file parsing_utilities.cpp.

References string_utilities::ToFloat().

84  {
85  return string_utilities::ToFloat(string, value) || string.empty();
86  }
bool ToFloat(const std::string &string, float &value)
Interprets the contents of "string" as a floating point number of type float, stores its value in "va...
Here is the call graph for this function:

◆ ParseInt16() [1/2]

int16_t rosaic_driver::ParseInt16 ( const uint8_t *  buffer)

Converts a 2-byte-buffer into a signed 16-bit integer.

The function assumes that the bytes in the buffer are already arranged with the same endianness as the local platform. It copies the elements in the range [buffer,buffer + 2) into the range beginning at reinterpret_cast<uint8_t*>(&x). Recall: data_type *var_name = reinterpret_cast <data_type *>(pointer_variable) converts the pointer type, no return type

Parameters
[in]bufferA pointer to a buffer containing 2 bytes of data
Returns
The int16_t value extracted from the data in the buffer

Definition at line 93 of file parsing_utilities.cpp.

94  {
95  int16_t diff_loc;
96  std::copy(buffer, buffer+2, reinterpret_cast<uint8_t*>(&diff_loc));
97  return diff_loc;
98  }

◆ ParseInt16() [2/2]

bool rosaic_driver::ParseInt16 ( const std::string &  string,
int16_t &  value,
int32_t  base 
)

Interprets the contents of "string" as a integer number of type int16_t, stores its value in "value" and returns whether or not all went well.

It checks whether an error occurred (via errno) and whether junk characters exist within "string", and returns true if the latter two tests are negative or when the string is empty, false otherwise.

Parameters
[in]stringThe string whose content should be interpreted as an integer number
[out]valueThe int16_t variable that should be overwritten by the integer number found in "string"
[in]baseThe numerical base of the integer in the string, default being 10
Returns
True if all went fine, false if not

Definition at line 104 of file parsing_utilities.cpp.

References string_utilities::ToInt32().

105  {
106  value = 0;
107  if (string.empty())
108  {
109  return true;
110  }
111 
112  int32_t intermd;
113  if (string_utilities::ToInt32(string, intermd, base) &&
114  intermd <= std::numeric_limits<int16_t>::max() &&
115  intermd >= std::numeric_limits<int16_t>::min())
116  {
117  value = static_cast<int16_t>(intermd);
118  return true;
119  }
120 
121  return false;
122  }
bool ToInt32(const std::string &string, int32_t &value, int32_t base)
Interprets the contents of "string" as a floating point number of whatever integer type your system h...
Here is the call graph for this function:

◆ ParseInt32() [1/2]

int32_t rosaic_driver::ParseInt32 ( const uint8_t *  buffer)

Converts a 4-byte-buffer into a signed 32-bit integer.

The function assumes that the bytes in the buffer are already arranged with the same endianness as the local platform. It copies the elements in the range [buffer,buffer + 4) into the range beginning at reinterpret_cast<uint8_t*>(&x). Recall: data_type *var_name = reinterpret_cast <data_type *>(pointer_variable) converts the pointer type, no return type

Parameters
[in]bufferA pointer to a buffer containing 4 bytes of data
Returns
The int32_t value extracted from the data in the buffer

Definition at line 129 of file parsing_utilities.cpp.

130  {
131  int32_t diff_loc;
132  std::copy(buffer, buffer+4, reinterpret_cast<uint8_t*>(&diff_loc));
133  return diff_loc;
134  }

◆ ParseInt32() [2/2]

bool rosaic_driver::ParseInt32 ( const std::string &  string,
int32_t &  value,
int32_t  base 
)

Interprets the contents of "string" as a integer number of type int32_t, stores its value in "value" and returns whether or not all went well.

It checks whether an error occurred (via errno) and whether junk characters exist within "string", and returns true if the latter two tests are negative or when the string is empty, false otherwise.

Parameters
[in]stringThe string whose content should be interpreted as an integer number
[out]valueThe int32_t variable that should be overwritten by the integer number found in "string"
[in]baseThe numerical base of the integer in the string, default being 10
Returns
True if all went fine, false if not

Definition at line 140 of file parsing_utilities.cpp.

References string_utilities::ToInt32().

141  {
142  return string_utilities::ToInt32(string, value, base) || string.empty();
143  }
bool ToInt32(const std::string &string, int32_t &value, int32_t base)
Interprets the contents of "string" as a floating point number of whatever integer type your system h...
Here is the call graph for this function:

◆ ParseUInt16() [1/2]

uint16_t rosaic_driver::ParseUInt16 ( const uint8_t *  buffer)

Converts a 2-byte-buffer into an unsigned 16-bit integer.

The function assumes that the bytes in the buffer are already arranged with the same endianness as the local platform. It copies the elements in the range [buffer,buffer + 2) into the range beginning at reinterpret_cast<uint8_t*>(&x). Recall: data_type *var_name = reinterpret_cast <data_type *>(pointer_variable) converts the pointer type, no return type

Parameters
[in]bufferA pointer to a buffer containing 2 bytes of data
Returns
The uint16_t value extracted from the data in the buffer

Definition at line 172 of file parsing_utilities.cpp.

173  {
174  uint16_t number;
175  std::copy(buffer, buffer+2, reinterpret_cast<uint8_t*>(&number));
176  return number;
177  }

◆ ParseUInt16() [2/2]

bool rosaic_driver::ParseUInt16 ( const std::string &  string,
uint16_t &  value,
int32_t  base 
)

Interprets the contents of "string" as a unsigned integer number of type uint16_t, stores its value in "value" and returns whether or not all went well.

It checks whether an error occurred (via errno) and whether junk characters exist within "string", and returns true if the latter two tests are negative or when the string is empty, false otherwise.

Parameters
[in]stringThe string whose content should be interpreted as an integer number
[out]valueThe uint16_t variable that should be overwritten by the integer number found in "string"
[in]baseThe numerical base of the integer in the string, default being 10
Returns
True if all went fine, false if not

Definition at line 183 of file parsing_utilities.cpp.

References string_utilities::ToUInt32().

184  {
185  value = 0;
186  if (string.empty())
187  {
188  return true;
189  }
190 
191  uint32_t intermd;
192  if (string_utilities::ToUInt32(string, intermd, base) && intermd <= std::numeric_limits<uint16_t>::max())
193  {
194  value = static_cast<uint16_t>(intermd);
195  return true;
196  }
197 
198  return false;
199  }
bool ToUInt32(const std::string &string, uint32_t &value, int32_t base)
Interprets the contents of "string" as a floating point number of whatever unsigned integer type your...
Here is the call graph for this function:

◆ ParseUInt32() [1/2]

uint32_t rosaic_driver::ParseUInt32 ( const uint8_t *  buffer)

Converts a 4-byte-buffer into an unsigned 32-bit integer.

The function assumes that the bytes in the buffer are already arranged with the same endianness as the local platform. It copies the elements in the range [buffer,buffer + 4) into the range beginning at reinterpret_cast<uint8_t*>(&x). Recall: data_type *var_name = reinterpret_cast <data_type *>(pointer_variable) converts the pointer type, no return type

Parameters
[in]bufferA pointer to a buffer containing 4 bytes of data
Returns
The uint32_t value extracted from the data in the buffer

Definition at line 206 of file parsing_utilities.cpp.

Referenced by rosaic_driver::GpggaParser::ParseASCII().

207  {
208  uint32_t diff_loc;
209  std::copy(buffer, buffer+4, reinterpret_cast<uint8_t*>(&diff_loc));
210  return diff_loc;
211  }
Here is the caller graph for this function:

◆ ParseUInt32() [2/2]

bool rosaic_driver::ParseUInt32 ( const std::string &  string,
uint32_t &  value,
int32_t  base 
)

Interprets the contents of "string" as a unsigned integer number of type uint32_t, stores its value in "value" and returns whether or not all went well.

It checks whether an error occurred (via errno) and whether junk characters exist within "string", and returns true if the latter two tests are negative or when the string is empty, false otherwise.

Parameters
[in]stringThe string whose content should be interpreted as an integer number
[out]valueThe uint32_t variable that should be overwritten by the integer number found in "string"
[in]baseThe numerical base of the integer in the string, default being 10
Returns
True if all went fine, false if not

Definition at line 217 of file parsing_utilities.cpp.

References string_utilities::ToUInt32().

218  {
219  return string_utilities::ToUInt32(string, value, base) || string.empty();
220  }
bool ToUInt32(const std::string &string, uint32_t &value, int32_t base)
Interprets the contents of "string" as a floating point number of whatever unsigned integer type your...
Here is the call graph for this function:

◆ ParseUInt8()

bool rosaic_driver::ParseUInt8 ( const std::string &  string,
uint8_t &  value,
int32_t  base 
)

Interprets the contents of "string" as a unsigned integer number of type uint8_t, stores its value in "value" and returns whether or not all went well.

It checks whether an error occurred (via errno) and whether junk characters exist within "string", and returns true if the latter two tests are negative or when the string is empty, false otherwise.

Parameters
[in]stringThe string whose content should be interpreted as an integer number
[out]valueThe uint8_t variable that should be overwritten by the integer number found in "string"
[in]baseThe numerical base of the integer in the string, default being 10
Returns
True if all went fine, false if not

Definition at line 149 of file parsing_utilities.cpp.

References string_utilities::ToUInt32().

150  {
151  value = 0;
152  if (string.empty())
153  {
154  return true;
155  }
156 
157  uint32_t intermd;
158  if (string_utilities::ToUInt32(string, intermd, base) && intermd <= std::numeric_limits<uint8_t>::max())
159  {
160  value = static_cast<uint8_t>(intermd);
161  return true;
162  }
163 
164  return false;
165  }
bool ToUInt32(const std::string &string, uint32_t &value, int32_t base)
Interprets the contents of "string" as a floating point number of whatever unsigned integer type your...
Here is the call graph for this function:

◆ UTCDoubleToSeconds()

double rosaic_driver::UTCDoubleToSeconds ( double  utc_double)

Converts the UTC time from the without-colon-delimiter format, type double, to the number-of-seconds-since-midnight format, type double.

The UTC precision in NMEA messages is down to a tenth of a second, naturally in both the without-colon-delimiter and the number-of-seconds-since-midnight formats.

Parameters
[in]utc_floatThe double variable representing UTC time in the without-colon-delimiter format
Returns
The double variable representing UTC time in the number-of-seconds-since-midnight format

Definition at line 225 of file parsing_utilities.cpp.

Referenced by rosaic_driver::GpggaParser::ParseASCII().

226  {
227  uint32_t hours = static_cast<uint32_t>(utc_double) / 10000;
228  uint32_t minutes = (static_cast<uint32_t>(utc_double) - hours * 10000) / 100;
229  double seconds = utc_double - static_cast<double>(hours * 10000 + minutes * 100);
230  seconds += static_cast<double> (hours * 3600 + minutes * 60);
231  return seconds;
232  }
Here is the caller graph for this function:

◆ UTCtoUnix()

time_t rosaic_driver::UTCtoUnix ( double  utc_double)

Converts UTC time from the without-colon-delimiter format, type double, to Unix Epoch time (a number-of-seconds-since-1970/01/01 format), type time_t (usually 32 bits)

Time information (hours, minutes, seconds) is extracted from the given double and augmented with the date, which is taken from the current system time on the host computer (i.e. current UTC+some_shift time via time(0)). The date ambiguity is resolved by adding/subtracting a day to the current date if the host time is more than 12 hours behind/ahead the NMEA time (i.e. UTC time). Recall time(0), time(NULL): If argument is a null pointer, the parameter is not used (the function still returns the current calendar time of type time_t). Otherwise, the return value is the same as the one stored in the location pointed by the argument. Note that the function assumes that utc_double has two significant digits after the decimal point, i.e. hhmmss.ss, and rounds the number of seconds to the nearest unsigned integer.

Parameters
[in]utc_floatThe double variable representing UTC time in the without-colon-delimiter format
Returns
The time_t variable representing Unix Epoch time

Definition at line 253 of file parsing_utilities.cpp.

Referenced by rosaic_driver::GpggaParser::ParseASCII(), and io_comm_mosaic::TimestampSBF().

254  {
255  time_t time_now = time(0);
256  struct tm * timeinfo;
257 
258  // The function localtime uses the value pointed by its argument to fill a tm structure with the values that represent the corresponding time, expressed for the local timezone.
259  timeinfo = gmtime(&time_now);
260 
261  uint32_t year = timeinfo->tm_year; // year, starting from 1900
262  uint32_t month = timeinfo->tm_mon; // months since January - [0,11]
263  uint32_t day = timeinfo->tm_mday; //day of the month - [1,31]
264  uint32_t hours = static_cast<uint32_t>(utc_double + 0.5f) / 10000;
265  uint32_t minutes = (static_cast<uint32_t>(utc_double + 0.5f) - hours * 10000) / 100;
266  uint32_t seconds = (static_cast<uint32_t>(utc_double + 0.5f) - hours * 10000 - minutes * 100);
267 
268  //ROS_DEBUG("Checking year %u, month %u, day %u", year, month, day);
269 
270  // Overwriting timeinfo with UTC time as extracted from utc_double..
271  timeinfo->tm_hour = hours; // hours since midnight - [0,23]
272  timeinfo->tm_min = minutes; // minutes after the hour - [0,59]
273  timeinfo->tm_sec = seconds; // seconds after the minute - [0,59]
274 
275  // Inverse of gmtime, the latter converts time_t (Unix time) to tm (UTC time)
276  time_t date = timegm(timeinfo);
277 
278  //ROS_DEBUG("Since 1970/01/01 %jd seconds have passed.\n", (intmax_t) date);
279  return date;
280  }
Here is the caller graph for this function: