message_handler.hpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // © Copyright 2020, Septentrio NV/SA.
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 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // 2. 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 // 3. Neither the name of the copyright holder nor the names of its
14 // contributors may be used to endorse or promote products derived
15 // 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 // *****************************************************************************
30 
31 // *****************************************************************************
32 //
33 // Boost Software License - Version 1.0 - August 17th, 2003
34 //
35 // Permission is hereby granted, free of charge, to any person or organization
36 // obtaining a copy of the software and accompanying documentation covered by
37 // this license (the "Software") to use, reproduce, display, distribute,
38 // execute, and transmit the Software, and to prepare derivative works of the
39 // Software, and to permit third-parties to whom the Software is furnished to
40 // do so, all subject to the following:
41 
42 // The copyright notices in the Software and this entire statement, including
43 // the above license grant, this restriction and the following disclaimer,
44 // must be included in all copies of the Software, in whole or in part, and
45 // all derivative works of the Software, unless such copies or derivative
46 // works are solely in the form of machine-executable object code generated by
47 // a source language processor.
48 //
49 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
52 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
53 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
54 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
55 // DEALINGS IN THE SOFTWARE.
56 //
57 // *****************************************************************************
58 
59 #pragma once
60 
61 // C++ libraries
62 #include <cassert> // for assert
63 #include <cstddef>
64 #include <map>
65 #include <sstream>
66 // Boost includes
67 #include <boost/call_traits.hpp>
68 #include <boost/format.hpp>
69 #include <boost/math/constants/constants.hpp>
70 #include <boost/tokenizer.hpp>
71 // ROSaic includes
72 #ifdef ROS2
74 #endif
75 #ifdef ROS1
77 #endif
85 
91 enum TypeOfPVT_Enum
94 {
105 };
106 
107 enum SbfId
108 {
110  PVT_GEODETIC = 4007,
115  ATT_EULER = 5938,
118  MEAS_EPOCH = 4027,
119  DOP = 4001,
123  QUALITY_IND = 4082,
125  INS_NAV_CART = 4225,
126  INS_NAV_GEOD = 4226,
129  IMU_SETUP = 4224,
134  RF_STATUS = 4092
135 };
136 
137 namespace io {
138 
144  {
145  public:
151  node_(node), settings_(node->settings()), unix_time_(0)
152  {
153  }
154 
156  {
157  // set leap seconds to paramter if reading from file
160  }
161 
166  void parseSbf(const std::shared_ptr<Telegram>& telegram);
167 
172  void parseNmea(const std::shared_ptr<Telegram>& telegram);
173 
174  private:
181  template <typename T>
182  void assembleHeader(const std::string& frameId,
183  const std::shared_ptr<Telegram>& telegram, T& msg) const;
189  template <typename M>
190  void publish(const std::string& topic, const M& msg);
191 
197  void publishTf(const LocalizationMsg& msg);
198 
203 
208 
212  std::unordered_map<std::string, uint8_t> nmeaMap_{
213  {"$GPGGA", 0}, {"$INGGA", 0}, {"$GPRMC", 1}, {"$INRMC", 1},
214  {"$GPGSA", 2}, {"$INGSA", 2}, {"$GAGSV", 3}, {"$INGSV", 3}};
215 
221 
227 
233 
239 
245 
251 
257 
263 
269 
274 
280 
286 
292 
298 
303 
307  bool osnma_info_available_ = false;
308 
313 
317 
319  mutable uint64_t last_pvt_latency_ = 0;
320 
322  int32_t current_leap_seconds_ = -128;
323 
327  void setStatus(uint8_t mode, NavSatFixMsg& msg);
328 
332  void assembleNavSatFix();
333 
337  void setStatus(uint8_t mode, GpsFixMsg& msg);
338 
342  void assembleGpsFix();
343 
349 
355  void assembleDiagnosticArray(const std::shared_ptr<Telegram>& telegram);
356 
362 
368 
373  void assembleImu();
374  bool hasImuMeas_ = false;
375 
381 
387 
395  void assembleLocalizationMsgTwist(double roll, double pitch, double yaw,
396  LocalizationMsg& msg) const;
397 
403  void assembleTwist(bool fromIns = false);
404 
410  void assembleTimeReference(const std::shared_ptr<Telegram>& telegram);
411 
416  void wait(Timestamp time_obj);
417 
421  std::shared_ptr<std::string> fixedUtmZone_;
422 
431  Timestamp timestampSBF(const std::vector<uint8_t>& message) const;
432 
444  Timestamp timestampSBF(uint32_t tow, uint16_t wnc) const;
445  };
446 } // namespace io
evMovingBaseRTKFixed
@ evMovingBaseRTKFixed
Definition: message_handler.hpp:102
Timestamp
uint64_t Timestamp
Definition: typedefs.hpp:101
io::MessageHandler::fixedUtmZone_
std::shared_ptr< std::string > fixedUtmZone_
Fixed UTM zone.
Definition: message_handler.hpp:421
QualityInd
Struct for the SBF block "QualityInd".
Definition: sbf_blocks.hpp:184
evDGPS
@ evDGPS
Definition: message_handler.hpp:97
gprmc.hpp
Derived class for parsing RMC messages.
INSNavCartMsg
septentrio_gnss_driver::msg::INSNavCart INSNavCartMsg
Definition: typedefs.hpp:151
io::MessageHandler::timestampSBF
Timestamp timestampSBF(const std::vector< uint8_t > &message) const
Calculates the timestamp, in the Unix Epoch time format This is either done using the TOW as transmit...
Definition: message_handler.cpp:2074
INS_NAV_CART
@ INS_NAV_CART
Definition: message_handler.hpp:125
ATT_COV_EULER
@ ATT_COV_EULER
Definition: message_handler.hpp:116
RECEIVER_TIME
@ RECEIVER_TIME
Definition: message_handler.hpp:132
INS_NAV_GEOD
@ INS_NAV_GEOD
Definition: message_handler.hpp:126
io::MessageHandler::assembleHeader
void assembleHeader(const std::string &frameId, const std::shared_ptr< Telegram > &telegram, T &msg) const
Header assembling.
Definition: message_handler.cpp:2038
MEAS_EPOCH
@ MEAS_EPOCH
Definition: message_handler.hpp:118
crc.hpp
Declares the functions to compute and validate the CRC of a buffer.
AttEulerMsg
septentrio_gnss_driver::msg::AttEuler AttEulerMsg
Definition: typedefs.hpp:133
gpgga.hpp
Derived class for parsing GGA messages.
POS_COV_GEODETIC
@ POS_COV_GEODETIC
Definition: message_handler.hpp:114
io::MessageHandler::publishTf
void publishTf(const LocalizationMsg &msg)
Publishing function.
Definition: message_handler.cpp:2146
io::MessageHandler::last_rf_status_
RfStatusMsg last_rf_status_
Stores incoming RFStatus block.
Definition: message_handler.hpp:312
POS_COV_CARTESIAN
@ POS_COV_CARTESIAN
Definition: message_handler.hpp:113
io::MessageHandler::last_qualityind_
QualityInd last_qualityind_
Since DiagnosticArray needs QualityInd, incoming QualityInd blocks need to be stored.
Definition: message_handler.hpp:291
VelCovGeodeticMsg
septentrio_gnss_driver::msg::VelCovGeodetic VelCovGeodeticMsg
Definition: typedefs.hpp:142
QUALITY_IND
@ QUALITY_IND
Definition: message_handler.hpp:123
io::MessageHandler::last_receiversetup_
ReceiverSetup last_receiversetup_
Since DiagnosticArray needs ReceiverSetup, incoming ReceiverSetup blocks need to be stored.
Definition: message_handler.hpp:297
io::MessageHandler::last_atteuler_
AttEulerMsg last_atteuler_
Since GPSFix etc. need AttEuler, incoming AttEuler blocks need to be stored.
Definition: message_handler.hpp:232
ATT_EULER
@ ATT_EULER
Definition: message_handler.hpp:115
BASE_VECTOR_CART
@ BASE_VECTOR_CART
Definition: message_handler.hpp:111
IMU_SETUP
@ IMU_SETUP
Definition: message_handler.hpp:129
io::MessageHandler::assemblePoseWithCovarianceStamped
void assemblePoseWithCovarianceStamped()
"Callback" function when constructing PoseWithCovarianceStamped messages
Definition: message_handler.cpp:58
io::MessageHandler::assembleTimeReference
void assembleTimeReference(const std::shared_ptr< Telegram > &telegram)
function when constructing TimeReferenceMsg messages
Definition: message_handler.cpp:2027
EXT_EVENT_INS_NAV_CART
@ EXT_EVENT_INS_NAV_CART
Definition: message_handler.hpp:128
io::MessageHandler::assembleGpsFix
void assembleGpsFix()
"Callback" function when constructing GPSFix messages
Definition: message_handler.cpp:1639
telegram.hpp
io::MessageHandler::last_measepoch_
MeasEpochMsg last_measepoch_
Since GPSFix needs MeasEpoch (for SNRs), incoming MeasEpoch blocks need to be stored.
Definition: message_handler.hpp:268
evStandAlone
@ evStandAlone
Definition: message_handler.hpp:96
io::MessageHandler::current_leap_seconds_
int32_t current_leap_seconds_
Current leap seconds as received, do not use value is -128.
Definition: message_handler.hpp:322
io::MessageHandler::assembleAimAndDiagnosticArray
void assembleAimAndDiagnosticArray()
"Callback" function when constructing RFStatus DiagnosticArrayMsg messages
Definition: message_handler.cpp:474
GAL_AUTH_STATUS
@ GAL_AUTH_STATUS
Definition: message_handler.hpp:133
ROSaicNodeBase
This class is the base class for abstraction.
Definition: typedefs.hpp:192
io::MessageHandler::assembleDiagnosticArray
void assembleDiagnosticArray(const std::shared_ptr< Telegram > &telegram)
"Callback" function when constructing DiagnosticArrayMsg messages
Definition: message_handler.cpp:214
VEL_COV_GEODETIC
@ VEL_COV_GEODETIC
Definition: message_handler.hpp:121
io::MessageHandler::assembleLocalizationMsgTwist
void assembleLocalizationMsgTwist(double roll, double pitch, double yaw, LocalizationMsg &msg) const
function to fill twist part of LocalizationMsg
Definition: message_handler.cpp:1242
EXT_SENSOR_MEAS
@ EXT_SENSOR_MEAS
Definition: message_handler.hpp:131
DOP
Struct for the SBF block "DOP".
io::MessageHandler::settings_
const Settings * settings_
Pointer to settings struct.
Definition: message_handler.hpp:207
io::MessageHandler::nmeaMap_
std::unordered_map< std::string, uint8_t > nmeaMap_
Map of NMEA messgae IDs and uint8_t.
Definition: message_handler.hpp:212
io::MessageHandler::last_pvtgeodetic_
PVTGeodeticMsg last_pvtgeodetic_
Since NavSatFix etc. need PVTGeodetic, incoming PVTGeodetic blocks need to be stored.
Definition: message_handler.hpp:220
PVT_GEODETIC
@ PVT_GEODETIC
Definition: message_handler.hpp:110
io::MessageHandler::setStatus
void setStatus(uint8_t mode, NavSatFixMsg &msg)
Set status of NavSatFix messages.
Definition: message_handler.cpp:1352
evRTKFixed
@ evRTKFixed
Definition: message_handler.hpp:99
io::MessageHandler::last_gal_auth_status_
GalAuthStatusMsg last_gal_auth_status_
Stores incoming GALAuthStatus block.
Definition: message_handler.hpp:302
INSNavGeodMsg
septentrio_gnss_driver::msg::INSNavGeod INSNavGeodMsg
Definition: typedefs.hpp:152
MeasEpochMsg
septentrio_gnss_driver::msg::MeasEpoch MeasEpochMsg
Definition: typedefs.hpp:129
evFixed
@ evFixed
Definition: message_handler.hpp:98
GalAuthStatusMsg
septentrio_gnss_driver::msg::GALAuthStatus GalAuthStatusMsg
Definition: typedefs.hpp:126
io::MessageHandler::parseNmea
void parseNmea(const std::shared_ptr< Telegram > &telegram)
Parse NMEA block.
Definition: message_handler.cpp:2732
Dop
Definition: sbf_blocks.hpp:135
NavSatFixMsg
sensor_msgs::msg::NavSatFix NavSatFixMsg
Definition: typedefs.hpp:115
io
Definition: async_manager.hpp:83
PosCovGeodeticMsg
septentrio_gnss_driver::msg::PosCovGeodetic PosCovGeodeticMsg
Definition: typedefs.hpp:137
io::MessageHandler
Can search buffer for messages, read/parse them, and so on.
Definition: message_handler.hpp:143
io::MessageHandler::assembleNavSatFix
void assembleNavSatFix()
"Callback" function when constructing NavSatFix messages
Definition: message_handler.cpp:1424
TypeOfPVT_Enum
TypeOfPVT_Enum
Definition: message_handler.hpp:93
io::MessageHandler::assembleImu
void assembleImu()
"Callback" function when constructing ImuMsg messages
Definition: message_handler.cpp:576
AttCovEulerMsg
septentrio_gnss_driver::msg::AttCovEuler AttCovEulerMsg
Definition: typedefs.hpp:132
io::MessageHandler::setLeapSeconds
void setLeapSeconds()
Definition: message_handler.hpp:155
io::MessageHandler::assembleLocalizationEcef
void assembleLocalizationEcef()
"Callback" function when constructing LocalizationMsg messages in ECEF
Definition: message_handler.cpp:1088
io::MessageHandler::last_attcoveuler_
AttCovEulerMsg last_attcoveuler_
Since GPSFix etc. need AttCovEuler, incoming AttCovEuler blocks need to be stored.
Definition: message_handler.hpp:238
typedefs.hpp
RECEIVER_SETUP
@ RECEIVER_SETUP
Definition: message_handler.hpp:124
Settings
Settings struct.
Definition: settings.hpp:149
io::MessageHandler::last_pvt_latency_
uint64_t last_pvt_latency_
Last reported PVT processing latency.
Definition: message_handler.hpp:319
io::MessageHandler::osnma_info_available_
bool osnma_info_available_
Wether OSNMA info has been received.
Definition: message_handler.hpp:307
evSBAS
@ evSBAS
Definition: message_handler.hpp:101
PVTGeodeticMsg
septentrio_gnss_driver::msg::PVTGeodetic PVTGeodeticMsg
Definition: typedefs.hpp:135
ChannelStatus
Struct for the SBF block "ChannelStatus".
Definition: sbf_blocks.hpp:120
io::MessageHandler::publish
void publish(const std::string &topic, const M &msg)
Publishing function.
Definition: message_handler.cpp:2117
Settings::read_from_sbf_log
bool read_from_sbf_log
Whether or not we are reading from an SBF file.
Definition: settings.hpp:369
settings
Definition: settings_helpers.hpp:41
PVT_CARTESIAN
@ PVT_CARTESIAN
Definition: message_handler.hpp:109
gpgsa.hpp
Derived class for parsing GSA messages.
io::MessageHandler::parseSbf
void parseSbf(const std::shared_ptr< Telegram > &telegram)
Parse SBF block.
Definition: message_handler.cpp:2172
ReceiverSetup
Struct for the SBF block "ReceiverSetup".
Definition: sbf_blocks.hpp:152
io::MessageHandler::last_dop_
Dop last_dop_
Since GPSFix needs DOP, incoming DOP blocks need to be stored.
Definition: message_handler.hpp:273
evNoPVT
@ evNoPVT
Definition: message_handler.hpp:95
string_utilities.hpp
Declares lower-level string utility functions used when parsing messages.
Settings::leap_seconds
int32_t leap_seconds
The number of leap seconds that have been inserted into the UTC time.
Definition: settings.hpp:367
io::MessageHandler::last_channelstatus_
ChannelStatus last_channelstatus_
Since GPSFix needs ChannelStatus, incoming ChannelStatus blocks need to be stored.
Definition: message_handler.hpp:262
VEL_COV_CARTESIAN
@ VEL_COV_CARTESIAN
Definition: message_handler.hpp:120
RF_STATUS
@ RF_STATUS
Definition: message_handler.hpp:134
BASE_VECTOR_GEOD
@ BASE_VECTOR_GEOD
Definition: message_handler.hpp:112
VEL_SENSOR_SETUP
@ VEL_SENSOR_SETUP
Definition: message_handler.hpp:130
evPPP
@ evPPP
Definition: message_handler.hpp:104
ExtSensorMeasMsg
septentrio_gnss_driver::msg::ExtSensorMeas ExtSensorMeasMsg
Definition: typedefs.hpp:155
io::MessageHandler::last_extsensmeas_
ExtSensorMeasMsg last_extsensmeas_
Since Imu needs ExtSensorMeas, incoming ExtSensorMeas blocks need to be stored.
Definition: message_handler.hpp:256
typedefs_ros1.hpp
EXT_EVENT_INS_NAV_GEOD
@ EXT_EVENT_INS_NAV_GEOD
Definition: message_handler.hpp:127
GpsFixMsg
gps_msgs::msg::GPSFix GpsFixMsg
Definition: typedefs.hpp:113
RfStatusMsg
septentrio_gnss_driver::msg::RFStatus RfStatusMsg
Definition: typedefs.hpp:127
io::MessageHandler::assembleLocalizationUtm
void assembleLocalizationUtm()
"Callback" function when constructing LocalizationMsg messages in UTM
Definition: message_handler.cpp:890
io::MessageHandler::MessageHandler
MessageHandler(ROSaicNodeBase *node)
Constructor of the MessageHandler class.
Definition: message_handler.hpp:150
SbfId
SbfId
Definition: message_handler.hpp:107
evMovingBaseRTKFloat
@ evMovingBaseRTKFloat
Definition: message_handler.hpp:103
io::MessageHandler::last_receiverstatus_
ReceiverStatus last_receiverstatus_
Since DiagnosticArray needs ReceiverStatus, incoming ReceiverStatus blocks need to be stored.
Definition: message_handler.hpp:285
LocalizationMsg
nav_msgs::msg::Odometry LocalizationMsg
Definition: typedefs.hpp:119
evRTKFloat
@ evRTKFloat
Definition: message_handler.hpp:100
RECEIVER_STATUS
@ RECEIVER_STATUS
Definition: message_handler.hpp:122
io::MessageHandler::last_velcovgeodetic_
VelCovGeodeticMsg last_velcovgeodetic_
Since GPSFix needs VelCovGeodetic, incoming VelCovGeodetic blocks need to be stored.
Definition: message_handler.hpp:279
io::MessageHandler::node_
ROSaicNodeBase * node_
Pointer to the node.
Definition: message_handler.hpp:202
ReceiverStatus
Struct for the SBF block "ReceiverStatus".
Definition: sbf_blocks.hpp:208
gpgsv.hpp
Derived class for parsing GSV messages.
io::MessageHandler::last_insnavcart_
INSNavCartMsg last_insnavcart_
Since LoclaizationEcef needs INSNavCart, incoming INSNavCart blocks need to be stored.
Definition: message_handler.hpp:250
io::MessageHandler::last_poscovgeodetic_
PosCovGeodeticMsg last_poscovgeodetic_
Since NavSatFix etc. need PosCovGeodetic, incoming PosCovGeodetic blocks need to be stored.
Definition: message_handler.hpp:226
io::MessageHandler::wait
void wait(Timestamp time_obj)
Waits according to time when reading from file.
Definition: message_handler.cpp:2716
io::MessageHandler::assembleOsnmaDiagnosticArray
void assembleOsnmaDiagnosticArray()
"Callback" function when constructing OSNMA DiagnosticArrayMsg messages
Definition: message_handler.cpp:381
CHANNEL_STATUS
@ CHANNEL_STATUS
Definition: message_handler.hpp:117
io::MessageHandler::unix_time_
Timestamp unix_time_
Definition: message_handler.hpp:316
Settings::read_from_pcap
bool read_from_pcap
Whether or not we are reading from a PCAP file.
Definition: settings.hpp:371
io::MessageHandler::last_insnavgeod_
INSNavGeodMsg last_insnavgeod_
Since NavSatFix, GPSFix, Imu and Pose need INSNavGeod, incoming INSNavGeod blocks need to be stored.
Definition: message_handler.hpp:244
io::MessageHandler::hasImuMeas_
bool hasImuMeas_
Definition: message_handler.hpp:374
io::MessageHandler::assembleTwist
void assembleTwist(bool fromIns=false)
"Callback" function when constructing TwistWithCovarianceStampedMsg messages
Definition: message_handler.cpp:675


septentrio_gnss_driver
Author(s): Tibor Dome, Thomas Emter
autogenerated on Sat May 10 2025 03:03:10