telegram.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 #pragma once
32 
33 // C++
34 #include <condition_variable>
35 #include <cstdint>
36 #include <mutex>
37 #include <queue>
38 #include <vector>
39 
40 // ROSaic
41 #ifdef ROS2
43 #endif
44 #ifdef ROS1
46 #endif
47 
49 static const uint8_t SYNC_BYTE_1 = 0x24;
51 static const uint8_t SBF_SYNC_BYTE_2 = 0x40;
53 static const uint8_t NMEA_SYNC_BYTE_2 = 0x47;
55 static const uint8_t NMEA_SYNC_BYTE_3 = 0x50;
57 static const uint8_t NMEA_INS_SYNC_BYTE_2 = 0x49;
59 static const uint8_t NMEA_INS_SYNC_BYTE_3 = 0x4E;
61 static const uint8_t RESPONSE_SYNC_BYTE_2 = 0x52;
63 static const uint8_t RESPONSE_SYNC_BYTE_3 = 0x3A;
65 static const uint8_t RESPONSE_SYNC_BYTE_3a = 0x21;
68 static const uint8_t ERROR_SYNC_BYTE_3 = 0x3F;
70 static const uint8_t CR = 0x0D;
72 static const uint8_t LF = 0x0A;
75 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_I = 0x49;
78 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_C = 0x43;
81 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_U = 0x55;
84 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_N = 0x4E;
87 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_D = 0x44;
89 static const uint8_t CONNECTION_DESCRIPTOR_FOOTER = 0x3E;
90 
91 static const uint16_t SBF_HEADER_SIZE = 8;
92 static const uint16_t MAX_SBF_SIZE = 65535;
93 static const uint16_t MAX_UDP_PACKET_SIZE = 65535;
94 
95 namespace telegram_type {
97  {
99  SBF,
106  };
107 }
108 
109 struct Telegram
110 {
113  std::vector<uint8_t> message;
114 
115  Telegram(size_t preallocate = 3) noexcept :
117  message(std::vector<uint8_t>(preallocate))
118  {
119  }
120 
122 
123  Telegram(const Telegram& other) noexcept :
124  stamp(other.stamp), type(other.type), message(other.message)
125  {
126  }
127 
128  Telegram(Telegram&& other) noexcept :
129  stamp(other.stamp), type(other.type), message(other.message)
130  {
131  }
132 
133  Telegram& operator=(const Telegram& other) noexcept
134  {
135  if (this != &other)
136  {
137  this->stamp = other.stamp;
138  this->type = other.type;
139  this->message = other.message;
140  }
141  return *this;
142  }
143 
144  Telegram& operator=(Telegram&& other) noexcept
145  {
146  if (this != &other)
147  {
148  this->stamp = other.stamp;
149  this->type = other.type;
150  this->message = other.message;
151  }
152  return *this;
153  }
154 };
155 
156 template <typename T>
158 {
159 public:
160  [[nodiscard]] bool empty() const noexcept;
161  [[nodiscard]] size_t size() const noexcept;
162  void push(const T& input) noexcept;
163  void pop(T& output) noexcept;
164 
165 private:
166  std::queue<T> queue_;
167  std::condition_variable cond_;
168  mutable std::mutex mtx_;
169 };
170 
171 template <typename T>
172 [[nodiscard]] bool ConcurrentQueue<T>::empty() const noexcept
173 {
174  std::lock_guard<std::mutex> lck(mtx_);
175  return queue_.empty();
176 }
177 
178 template <typename T>
179 [[nodiscard]] size_t ConcurrentQueue<T>::size() const noexcept
180 {
181  std::lock_guard<std::mutex> lck(mtx_);
182  return queue_.size();
183 }
184 
185 template <typename T>
186 void ConcurrentQueue<T>::push(const T& input) noexcept
187 {
188  {
189  std::lock_guard<std::mutex> lck(mtx_);
190  queue_.push(input);
191  }
192  cond_.notify_one();
193 }
194 
195 template <typename T>
196 void ConcurrentQueue<T>::pop(T& output) noexcept
197 {
198  std::unique_lock<std::mutex> lck(mtx_);
199  cond_.wait(lck, [this] { return !queue_.empty(); });
200  output = queue_.front();
201  queue_.pop();
202 }
203 
Timestamp
uint64_t Timestamp
Definition: typedefs.hpp:101
CONNECTION_DESCRIPTOR_BYTE_D
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_D
Definition: telegram.hpp:87
NMEA_INS_SYNC_BYTE_3
static const uint8_t NMEA_INS_SYNC_BYTE_3
0x4E is ASCII for N - 3rd byte to indicate NMEA-type ASCII message
Definition: telegram.hpp:59
ConcurrentQueue
Definition: telegram.hpp:157
Telegram::Telegram
Telegram(const Telegram &other) noexcept
Definition: telegram.hpp:123
telegram_type::NMEA_INS
@ NMEA_INS
Definition: telegram.hpp:101
Telegram::type
telegram_type::TelegramType type
Definition: telegram.hpp:112
Telegram::operator=
Telegram & operator=(Telegram &&other) noexcept
Definition: telegram.hpp:144
Telegram::Telegram
Telegram(size_t preallocate=3) noexcept
Definition: telegram.hpp:115
Telegram::stamp
Timestamp stamp
Definition: telegram.hpp:111
telegram_type
Definition: telegram.hpp:95
TelegramQueue
ConcurrentQueue< std::shared_ptr< Telegram > > TelegramQueue
Definition: telegram.hpp:204
SYNC_BYTE_1
static const uint8_t SYNC_BYTE_1
0x24 is ASCII for $ - 1st byte in each message
Definition: telegram.hpp:49
CONNECTION_DESCRIPTOR_BYTE_N
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_N
Definition: telegram.hpp:84
telegram_type::ERROR_RESPONSE
@ ERROR_RESPONSE
Definition: telegram.hpp:103
Telegram::message
std::vector< uint8_t > message
Definition: telegram.hpp:113
telegram_type::NMEA
@ NMEA
Definition: telegram.hpp:100
ConcurrentQueue::pop
void pop(T &output) noexcept
Definition: telegram.hpp:196
ConcurrentQueue::empty
bool empty() const noexcept
Definition: telegram.hpp:172
telegram_type::CONNECTION_DESCRIPTOR
@ CONNECTION_DESCRIPTOR
Definition: telegram.hpp:104
SBF_SYNC_BYTE_2
static const uint8_t SBF_SYNC_BYTE_2
0x40 is ASCII for @ - 2nd byte to indicate SBF block
Definition: telegram.hpp:51
ConcurrentQueue::push
void push(const T &input) noexcept
Definition: telegram.hpp:186
telegram_type::RESPONSE
@ RESPONSE
Definition: telegram.hpp:102
ConcurrentQueue::cond_
std::condition_variable cond_
Definition: telegram.hpp:167
Telegram
Definition: telegram.hpp:109
RESPONSE_SYNC_BYTE_3
static const uint8_t RESPONSE_SYNC_BYTE_3
0x3A is ASCII for : - 3rd byte in the response message from the Rx
Definition: telegram.hpp:63
typedefs.hpp
Telegram::~Telegram
~Telegram()
Definition: telegram.hpp:121
CONNECTION_DESCRIPTOR_BYTE_U
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_U
Definition: telegram.hpp:81
RESPONSE_SYNC_BYTE_3a
static const uint8_t RESPONSE_SYNC_BYTE_3a
0x21 is ASCII for ! 3rd byte in the response message from the Rx
Definition: telegram.hpp:65
telegram_type::TelegramType
TelegramType
Definition: telegram.hpp:96
telegram_type::UNKNOWN
@ UNKNOWN
Definition: telegram.hpp:105
SBF_HEADER_SIZE
static const uint16_t SBF_HEADER_SIZE
Definition: telegram.hpp:91
ConcurrentQueue::queue_
std::queue< T > queue_
Definition: telegram.hpp:166
ConcurrentQueue::size
size_t size() const noexcept
Definition: telegram.hpp:179
Telegram::Telegram
Telegram(Telegram &&other) noexcept
Definition: telegram.hpp:128
RESPONSE_SYNC_BYTE_2
static const uint8_t RESPONSE_SYNC_BYTE_2
0x52 is ASCII for R (for "Response") - 2nd byte in each response from the Rx
Definition: telegram.hpp:61
MAX_SBF_SIZE
static const uint16_t MAX_SBF_SIZE
Definition: telegram.hpp:92
std
NMEA_SYNC_BYTE_2
static const uint8_t NMEA_SYNC_BYTE_2
0x47 is ASCII for G - 2nd byte to indicate NMEA-type ASCII message
Definition: telegram.hpp:53
telegram_type::EMPTY
@ EMPTY
Definition: telegram.hpp:98
NMEA_INS_SYNC_BYTE_2
static const uint8_t NMEA_INS_SYNC_BYTE_2
0x49 is ASCII for I - 2nd byte to indicate INS NMEA-type ASCII message
Definition: telegram.hpp:57
telegram_type::SBF
@ SBF
Definition: telegram.hpp:99
Telegram::operator=
Telegram & operator=(const Telegram &other) noexcept
Definition: telegram.hpp:133
typedefs_ros1.hpp
CONNECTION_DESCRIPTOR_FOOTER
static const uint8_t CONNECTION_DESCRIPTOR_FOOTER
0x3E is ASCII for > - end character of connection descriptor
Definition: telegram.hpp:89
CONNECTION_DESCRIPTOR_BYTE_I
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_I
Definition: telegram.hpp:75
CR
static const uint8_t CR
0x0D is ASCII for "Carriage Return", i.e. "Enter"
Definition: telegram.hpp:70
CONNECTION_DESCRIPTOR_BYTE_C
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_C
Definition: telegram.hpp:78
ERROR_SYNC_BYTE_3
static const uint8_t ERROR_SYNC_BYTE_3
Definition: telegram.hpp:68
NMEA_SYNC_BYTE_3
static const uint8_t NMEA_SYNC_BYTE_3
0x50 is ASCII for P - 3rd byte to indicate NMEA-type ASCII message
Definition: telegram.hpp:55
ConcurrentQueue::mtx_
std::mutex mtx_
Definition: telegram.hpp:168
LF
static const uint8_t LF
0x0A is ASCII for "Line Feed", i.e. "New Line"
Definition: telegram.hpp:72
MAX_UDP_PACKET_SIZE
static const uint16_t MAX_UDP_PACKET_SIZE
Definition: telegram.hpp:93


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