novatel_message_extractor.h
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 
30 #ifndef NOVTEL_OEM628_NOVATEL_MESSAGE_PARSER_H_
31 #define NOVTEL_OEM628_NOVATEL_MESSAGE_PARSER_H_
32 
33 #include <limits>
34 #include <sstream>
35 #include <string>
36 #include <vector>
37 
38 #include <gps_common/GPSFix.h>
39 #include <novatel_gps_msgs/Gpgga.h>
40 #include <novatel_gps_msgs/Gpgsa.h>
41 #include <novatel_gps_msgs/Gpgsv.h>
42 #include <novatel_gps_msgs/Gprmc.h>
43 #include <novatel_gps_msgs/NovatelCorrectedImuData.h>
44 #include <novatel_gps_msgs/NovatelPosition.h>
45 #include <novatel_gps_msgs/NovatelMessageHeader.h>
46 #include <novatel_gps_msgs/NovatelReceiverStatus.h>
47 #include <novatel_gps_msgs/NovatelVelocity.h>
48 #include <novatel_gps_msgs/Range.h>
49 #include <novatel_gps_msgs/Time.h>
50 #include <novatel_gps_msgs/Trackstat.h>
51 
55 
56 namespace novatel_gps_driver
57 {
59  {
60  public:
80  const std::string input,
81  std::vector<NmeaSentence>& nmea_sentences,
82  std::vector<NovatelSentence>& novatel_sentences,
83  std::vector<BinaryMessage>& binary_messages,
84  std::string& remaining,
85  bool keep_nmea_container = false);
86 
93  double GetMostRecentUtcTime(const std::vector<NmeaSentence>& sentences);
94 
103  void GetGpsFixMessage(
104  const novatel_gps_msgs::Gprmc& gprmc,
105  const novatel_gps_msgs::Gpgga& gpgga,
106  gps_common::GPSFixPtr gps_fix);
107 
108  private:
109  // Constants for parsing message structures
111  static const std::string CHECKSUM_FLAG;
113  static const std::string FIELD_SEPARATOR;
115  static const std::string HEADER_SEPARATOR;
117  static const std::string NMEA_SENTENCE_FLAG;
119  static const std::string NOVATEL_SENTENCE_FLAG;
121  static const std::string NOVATEL_ASCII_FLAGS;
123  static const std::string NOVATEL_BINARY_SYNC_BYTES;
125  static const std::string NOVATEL_ENDLINE;
126 
127  static constexpr uint32_t NOVATEL_CRC32_POLYNOMIAL = 0xEDB88320L;
128 
129  // From Novatel OEMV® Family Firmware Reference Manual
136  uint32_t CalculateBlockCRC32(
137  uint32_t ulCount,
138  const uint8_t* ucBuffer);
139 
145  uint32_t CRC32Value(int32_t i);
146 
147 
167  void FindAsciiSentence(const std::string& sentence,
168  size_t current_idx,
169  size_t& start_idx,
170  size_t& end_idx,
171  size_t& invalid_char_idx);
172 
182  int32_t GetBinaryMessage(const std::string& str,
183  size_t start_idx,
184  BinaryMessage& msg);
185 
195  const std::string& sentence,
196  std::string& message_id,
197  std::vector<std::string>& header,
198  std::vector<std::string>& body);
199 
211  int32_t GetNmeaSentence(
212  const std::string& str,
213  size_t start_idx,
214  std::string& sentence,
215  bool keep_container = false);
216 
226  int32_t GetNovatelSentence(
227  const std::string& str,
228  size_t start_idx,
229  std::string& sentence);
230 
238  const std::string& str,
239  size_t start_idx);
240 
246  uint8_t NmeaChecksum(const std::string& sentence);
247 
256  const std::string& data,
257  NovatelSentence& sentence);
258 
267  const std::string& sentence,
268  NmeaSentence& vectorized_message);
269 
277  void VectorizeString(
278  const std::string& str,
279  std::vector<std::string>& vectorized_message,
280  const std::string& delimiters);
281  };
282 }
283 
284 #endif // NOVATEL_OEM628_NOVATEL_MESSAGE_PARSER_H_
uint8_t NmeaChecksum(const std::string &sentence)
Calculates the checksum of a NMEA sentence.
void FindAsciiSentence(const std::string &sentence, size_t current_idx, size_t &start_idx, size_t &end_idx, size_t &invalid_char_idx)
Searches for a valid ASCII message within a string.
static const std::string CHECKSUM_FLAG
Precedes checkums in ASCII messages.
bool GetNovatelMessageParts(const std::string &sentence, std::string &message_id, std::vector< std::string > &header, std::vector< std::string > &body)
Splits an ASCII NovAtel message up into header and body parts.
static const std::string FIELD_SEPARATOR
Separates data fields in ASCII messages.
static const std::string HEADER_SEPARATOR
Separates header from body in ASCII NovAtel messages.
int32_t GetBinaryMessage(const std::string &str, size_t start_idx, BinaryMessage &msg)
Extracts a binary message from a data buffer.
double GetMostRecentUtcTime(const std::vector< NmeaSentence > &sentences)
Iterates through the provided messages to find the first GPGGA or GPRMC message with a valid UTC time...
int32_t GetNovatelSentence(const std::string &str, size_t start_idx, std::string &sentence)
Extracts a NovAtel sentence from an input string.
uint32_t CRC32Value(int32_t i)
Calculates the CRC-32 of a single value.
void GetGpsFixMessage(const novatel_gps_msgs::Gprmc &gprmc, const novatel_gps_msgs::Gpgga &gpgga, gps_common::GPSFixPtr gps_fix)
Combines data receives in GPRMC and GPGGA message to produce a gps_common/GPSFixPtr ROS message...
bool VectorizeNovatelSentence(const std::string &data, NovatelSentence &sentence)
Takes a sentence extracted by GetNovatelSentence and converts it into a data structure.
static const std::string NOVATEL_ASCII_FLAGS
Used to search for both types of ASCII messages.
size_t GetSentenceChecksumStart(const std::string &str, size_t start_idx)
Finds the location of the next checksum in a valid ASCII sentence.
static const std::string NMEA_SENTENCE_FLAG
Indicates the beginning of a NMEA sentence.
void VectorizeString(const std::string &str, std::vector< std::string > &vectorized_message, const std::string &delimiters)
void VectorizeNmeaSentence(const std::string &sentence, NmeaSentence &vectorized_message)
Takes a sentence extracted by GetNmeaSentence and converts it into a data structure.
bool ExtractCompleteMessages(const std::string input, std::vector< NmeaSentence > &nmea_sentences, std::vector< NovatelSentence > &novatel_sentences, std::vector< BinaryMessage > &binary_messages, std::string &remaining, bool keep_nmea_container=false)
Extracts messages from a buffer of NovAtel data.
static const std::string NOVATEL_ENDLINE
Indicates the end of an ASCII message.
static const std::string NOVATEL_BINARY_SYNC_BYTES
Indicates the beginning of a binary NovAtel message.
static const std::string NOVATEL_SENTENCE_FLAG
Indicates the beginning of an ASCII NovAtel message.
int32_t GetNmeaSentence(const std::string &str, size_t start_idx, std::string &sentence, bool keep_container=false)
Extracts an NMEA sentence from an input string.
uint32_t CalculateBlockCRC32(uint32_t ulCount, const uint8_t *ucBuffer)
Calculates the CRC-32 of a block of data all at once.


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