novatel_message_extractor.h
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2017, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL SOUTHWEST RESEARCH INSTITUTE BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #ifndef NOVTEL_OEM628_NOVATEL_MESSAGE_PARSER_H_
00031 #define NOVTEL_OEM628_NOVATEL_MESSAGE_PARSER_H_
00032 
00033 #include <limits>
00034 #include <sstream>
00035 #include <string>
00036 #include <vector>
00037 
00038 #include <gps_common/GPSFix.h>
00039 #include <novatel_gps_msgs/Gpgga.h>
00040 #include <novatel_gps_msgs/Gpgsa.h>
00041 #include <novatel_gps_msgs/Gpgsv.h>
00042 #include <novatel_gps_msgs/Gprmc.h>
00043 #include <novatel_gps_msgs/NovatelCorrectedImuData.h>
00044 #include <novatel_gps_msgs/NovatelPosition.h>
00045 #include <novatel_gps_msgs/NovatelMessageHeader.h>
00046 #include <novatel_gps_msgs/NovatelReceiverStatus.h>
00047 #include <novatel_gps_msgs/NovatelVelocity.h>
00048 #include <novatel_gps_msgs/Range.h>
00049 #include <novatel_gps_msgs/Time.h>
00050 #include <novatel_gps_msgs/Trackstat.h>
00051 
00052 #include <novatel_gps_driver/binary_message.h>
00053 #include <novatel_gps_driver/nmea_sentence.h>
00054 #include <novatel_gps_driver/novatel_sentence.h>
00055 
00056 namespace novatel_gps_driver
00057 {
00058   class NovatelMessageExtractor
00059   {
00060   public:
00079     bool ExtractCompleteMessages(
00080         const std::string input,
00081         std::vector<NmeaSentence>& nmea_sentences,
00082         std::vector<NovatelSentence>& novatel_sentences,
00083         std::vector<BinaryMessage>& binary_messages,
00084         std::string& remaining,
00085         bool keep_nmea_container = false);
00086 
00093     double GetMostRecentUtcTime(const std::vector<NmeaSentence>& sentences);
00094 
00103     void GetGpsFixMessage(
00104         const novatel_gps_msgs::Gprmc& gprmc,
00105         const novatel_gps_msgs::Gpgga& gpgga,
00106         gps_common::GPSFixPtr gps_fix);
00107 
00108   private:
00109     // Constants for parsing message structures
00111     static const std::string CHECKSUM_FLAG;
00113     static const std::string FIELD_SEPARATOR;
00115     static const std::string HEADER_SEPARATOR;
00117     static const std::string NMEA_SENTENCE_FLAG;
00119     static const std::string NOVATEL_SENTENCE_FLAG;
00121     static const std::string NOVATEL_ASCII_FLAGS;
00123     static const std::string NOVATEL_BINARY_SYNC_BYTES;
00125     static const std::string NOVATEL_ENDLINE;
00126 
00127     static constexpr uint32_t NOVATEL_CRC32_POLYNOMIAL = 0xEDB88320L;
00128 
00129     // From Novatel OEMV® Family Firmware Reference Manual
00136     uint32_t CalculateBlockCRC32(
00137         uint32_t ulCount,
00138         const uint8_t* ucBuffer);
00139 
00145     uint32_t CRC32Value(int32_t i);
00146 
00147 
00167     void FindAsciiSentence(const std::string& sentence,
00168                            size_t current_idx,
00169                            size_t& start_idx,
00170                            size_t& end_idx,
00171                            size_t& invalid_char_idx);
00172 
00182     int32_t GetBinaryMessage(const std::string& str,
00183                              size_t start_idx,
00184                              BinaryMessage& msg);
00185 
00194     bool GetNovatelMessageParts(
00195         const std::string& sentence,
00196         std::string& message_id,
00197         std::vector<std::string>& header,
00198         std::vector<std::string>& body);
00199 
00211     int32_t GetNmeaSentence(
00212         const std::string& str,
00213         size_t start_idx,
00214         std::string& sentence,
00215         bool keep_container = false);
00216 
00226     int32_t GetNovatelSentence(
00227         const std::string& str,
00228         size_t start_idx,
00229         std::string& sentence);
00230 
00237     size_t GetSentenceChecksumStart(
00238         const std::string& str,
00239         size_t start_idx);
00240 
00246     uint8_t NmeaChecksum(const std::string& sentence);
00247 
00255     bool VectorizeNovatelSentence(
00256         const std::string& data,
00257         NovatelSentence& sentence);
00258 
00266     void VectorizeNmeaSentence(
00267         const std::string& sentence,
00268         NmeaSentence& vectorized_message);
00269 
00277     void VectorizeString(
00278         const std::string& str,
00279         std::vector<std::string>& vectorized_message,
00280         const std::string& delimiters);
00281   };
00282 }
00283 
00284 #endif  // NOVATEL_OEM628_NOVATEL_MESSAGE_PARSER_H_


novatel_gps_driver
Author(s):
autogenerated on Sun Oct 8 2017 02:40:29