telegram_handler.cpp
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 
32 
39 namespace io {
40 
41  void TelegramHandler::handleTelegram(const std::shared_ptr<Telegram>& telegram)
42  {
43  switch (telegram->type)
44  {
45  case telegram_type::SBF:
46  {
47  handleSbf(telegram);
48  break;
49  }
51  {
52  handleNmea(telegram);
53  break;
54  }
56  {
57  handleNmea(telegram);
58  break;
59  }
61  {
62  handleResponse(telegram);
63  break;
64  }
66  {
67  handleResponse(telegram);
68  break;
69  }
71  {
72  handleCd(telegram);
73  break;
74  }
76  {
77  std::string block_in_string(telegram->message.begin(),
78  telegram->message.end());
79 
80  node_->log(log_level::DEBUG, "A message received: " + block_in_string);
81  if (block_in_string.find("ReceiverCapabilities") != std::string::npos)
82  {
83  if (block_in_string.find("INS") != std::string::npos)
84  {
85  node_->setIsIns();
86  }
87 
88  if (block_in_string.find("Heading") != std::string::npos)
89  {
91  }
93  }
94  break;
95  }
96  default:
97  {
99  "TelegramHandler received an invalid message to handle");
100  break;
101  }
102  }
103  }
104 
105  void TelegramHandler::handleSbf(const std::shared_ptr<Telegram>& telegram)
106  {
107  messageHandler_.parseSbf(telegram);
108  }
109 
110  void TelegramHandler::handleNmea(const std::shared_ptr<Telegram>& telegram)
111  {
112  messageHandler_.parseNmea(telegram);
113  }
114 
115  void TelegramHandler::handleResponse(const std::shared_ptr<Telegram>& telegram)
116  {
117  std::string block_in_string(telegram->message.begin(),
118  telegram->message.end());
119 
120  if (telegram->type == telegram_type::ERROR_RESPONSE)
121  {
122  node_->log(
124  "Invalid command just sent to the Rx! The Rx's response contains " +
125  std::to_string(block_in_string.size()) + " bytes and reads:\n " +
126  block_in_string);
127 
128  if (block_in_string ==
129  std::string(
130  "$R? setGNSSAttitude: Argument 'Source' is invalid!\r\n"))
131  {
132  node_->log(
134  "Rx does not support dual antenna mode, set parameter multi_antenna to false and/or disable publishing of atteuler.");
135  }
136  } else
137  {
138  node_->log(log_level::DEBUG, "The Rx's response contains " +
139  std::to_string(block_in_string.size()) +
140  " bytes and reads:\n " +
141  block_in_string);
142  }
144  }
145 
146  void TelegramHandler::handleCd(const std::shared_ptr<Telegram>& telegram)
147  {
149  "handleCd: " + std::string(telegram->message.begin(),
150  telegram->message.end()));
151  if (telegram->message.back() == CONNECTION_DESCRIPTOR_FOOTER)
152  {
154  std::string(telegram->message.begin(), telegram->message.end() - 1);
155 
157  }
158  }
159 } // namespace io
log_level::DEBUG
@ DEBUG
Definition: typedefs.hpp:172
io::TelegramHandler::handleNmea
void handleNmea(const std::shared_ptr< Telegram > &telegram)
Definition: telegram_handler.cpp:110
telegram_type::NMEA_INS
@ NMEA_INS
Definition: telegram.hpp:96
ROSaicNodeBase::log
void log(log_level::LogLevel logLevel, const std::string &s) const
Log function to provide abstraction of ROS loggers.
Definition: typedefs.hpp:257
io::TelegramHandler::node_
ROSaicNodeBase * node_
Pointer to Node.
Definition: telegram_handler.hpp:155
telegram_type::ERROR_RESPONSE
@ ERROR_RESPONSE
Definition: telegram.hpp:98
telegram_type::NMEA
@ NMEA
Definition: telegram.hpp:95
io::TelegramHandler::handleResponse
void handleResponse(const std::shared_ptr< Telegram > &telegram)
Definition: telegram_handler.cpp:115
io::TelegramHandler::mainConnectionDescriptor_
std::string mainConnectionDescriptor_
Definition: telegram_handler.hpp:163
telegram_type::CONNECTION_DESCRIPTOR
@ CONNECTION_DESCRIPTOR
Definition: telegram.hpp:99
io::MessageHandler::parseNmea
void parseNmea(const std::shared_ptr< Telegram > &telegram)
Parse NMEA block.
Definition: message_handler.cpp:2754
io
Definition: async_manager.hpp:83
io::TelegramHandler::capabilitiesSemaphore_
Semaphore capabilitiesSemaphore_
Definition: telegram_handler.hpp:162
telegram_type::RESPONSE
@ RESPONSE
Definition: telegram.hpp:97
io::TelegramHandler::messageHandler_
MessageHandler messageHandler_
MessageHandler parser.
Definition: telegram_handler.hpp:158
log_level::ERROR
@ ERROR
Definition: typedefs.hpp:175
io::Semaphore::notify
void notify()
Definition: telegram_handler.hpp:81
telegram_handler.hpp
Handles messages when reading NMEA/SBF/response/error/connection descriptor messages.
telegram_type::UNKNOWN
@ UNKNOWN
Definition: telegram.hpp:100
ROSaicNodeBase::setIsIns
void setIsIns()
Set INS to true.
Definition: typedefs.hpp:379
io::TelegramHandler::handleSbf
void handleSbf(const std::shared_ptr< Telegram > &telegram)
Definition: telegram_handler.cpp:105
io::MessageHandler::parseSbf
void parseSbf(const std::shared_ptr< Telegram > &telegram)
Parse SBF block.
Definition: message_handler.cpp:2203
ROSaicNodeBase::setHasHeading
void setHasHeading()
Set has heading to true.
Definition: typedefs.hpp:384
telegram_type::SBF
@ SBF
Definition: telegram.hpp:94
log_level::WARN
@ WARN
Definition: typedefs.hpp:174
CONNECTION_DESCRIPTOR_FOOTER
static const uint8_t CONNECTION_DESCRIPTOR_FOOTER
0x3E is ASCII for > - end character of connection descriptor
Definition: telegram.hpp:84
io::TelegramHandler::handleCd
void handleCd(const std::shared_ptr< Telegram > &telegram)
Definition: telegram_handler.cpp:146
io::TelegramHandler::cdSemaphore_
Semaphore cdSemaphore_
Definition: telegram_handler.hpp:160
io::TelegramHandler::responseSemaphore_
Semaphore responseSemaphore_
Definition: telegram_handler.hpp:161
io::TelegramHandler::handleTelegram
void handleTelegram(const std::shared_ptr< Telegram > &telegram)
Called every time a telegram is received.
Definition: telegram_handler.cpp:41


septentrio_gnss_driver
Author(s): Tibor Dome
autogenerated on Wed Nov 22 2023 04:04:27