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
42 
44 static const uint8_t SYNC_BYTE_1 = 0x24;
46 static const uint8_t SBF_SYNC_BYTE_2 = 0x40;
48 static const uint8_t NMEA_SYNC_BYTE_2 = 0x47;
50 static const uint8_t NMEA_SYNC_BYTE_3 = 0x50;
52 static const uint8_t NMEA_INS_SYNC_BYTE_2 = 0x49;
54 static const uint8_t NMEA_INS_SYNC_BYTE_3 = 0x4E;
56 static const uint8_t RESPONSE_SYNC_BYTE_2 = 0x52;
58 static const uint8_t RESPONSE_SYNC_BYTE_3 = 0x3A;
60 static const uint8_t RESPONSE_SYNC_BYTE_3a = 0x21;
63 static const uint8_t ERROR_SYNC_BYTE_3 = 0x3F;
65 static const uint8_t CR = 0x0D;
67 static const uint8_t LF = 0x0A;
70 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_I = 0x49;
73 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_C = 0x43;
76 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_U = 0x55;
79 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_N = 0x4E;
82 static const uint8_t CONNECTION_DESCRIPTOR_BYTE_D = 0x44;
84 static const uint8_t CONNECTION_DESCRIPTOR_FOOTER = 0x3E;
85 
86 static const uint16_t SBF_HEADER_SIZE = 8;
87 static const uint16_t MAX_SBF_SIZE = 65535;
88 static const uint16_t MAX_UDP_PACKET_SIZE = 65535;
89 
90 namespace telegram_type {
92  {
94  SBF,
101  };
102 }
103 
104 struct Telegram
105 {
108  std::vector<uint8_t> message;
109 
110  Telegram(size_t preallocate = 3) noexcept :
112  message(std::vector<uint8_t>(preallocate))
113  {
114  }
115 
117 
118  Telegram(const Telegram& other) noexcept :
119  stamp(other.stamp), type(other.type), message(other.message)
120  {
121  }
122 
123  Telegram(Telegram&& other) noexcept :
124  stamp(other.stamp), type(other.type), message(other.message)
125  {
126  }
127 
128  Telegram& operator=(const Telegram& other) noexcept
129  {
130  if (this != &other)
131  {
132  this->stamp = other.stamp;
133  this->type = other.type;
134  this->message = other.message;
135  }
136  return *this;
137  }
138 
139  Telegram& operator=(Telegram&& other) noexcept
140  {
141  if (this != &other)
142  {
143  this->stamp = other.stamp;
144  this->type = other.type;
145  this->message = other.message;
146  }
147  return *this;
148  }
149 };
150 
151 template <typename T>
153 {
154 public:
155  [[nodiscard]] bool empty() const noexcept;
156  [[nodiscard]] size_t size() const noexcept;
157  void push(const T& input) noexcept;
158  void pop(T& output) noexcept;
159 
160 private:
161  std::queue<T> queue_;
162  std::condition_variable cond_;
163  mutable std::mutex mtx_;
164 };
165 
166 template <typename T>
167 [[nodiscard]] bool ConcurrentQueue<T>::empty() const noexcept
168 {
169  std::lock_guard<std::mutex> lck(mtx_);
170  return queue_.empty();
171 }
172 
173 template <typename T>
174 [[nodiscard]] size_t ConcurrentQueue<T>::size() const noexcept
175 {
176  std::lock_guard<std::mutex> lck(mtx_);
177  return queue_.size();
178 }
179 
180 template <typename T>
181 void ConcurrentQueue<T>::push(const T& input) noexcept
182 {
183  {
184  std::lock_guard<std::mutex> lck(mtx_);
185  queue_.push(input);
186  }
187  cond_.notify_one();
188 }
189 
190 template <typename T>
191 void ConcurrentQueue<T>::pop(T& output) noexcept
192 {
193  std::unique_lock<std::mutex> lck(mtx_);
194  cond_.wait(lck, [this] { return !queue_.empty(); });
195  output = queue_.front();
196  queue_.pop();
197 }
198 
Timestamp
uint64_t Timestamp
Definition: typedefs.hpp:92
CONNECTION_DESCRIPTOR_BYTE_D
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_D
Definition: telegram.hpp:82
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:54
ConcurrentQueue
Definition: telegram.hpp:152
Telegram::Telegram
Telegram(const Telegram &other) noexcept
Definition: telegram.hpp:118
telegram_type::NMEA_INS
@ NMEA_INS
Definition: telegram.hpp:96
Telegram::type
telegram_type::TelegramType type
Definition: telegram.hpp:107
Telegram::operator=
Telegram & operator=(Telegram &&other) noexcept
Definition: telegram.hpp:139
Telegram::Telegram
Telegram(size_t preallocate=3) noexcept
Definition: telegram.hpp:110
Telegram::stamp
Timestamp stamp
Definition: telegram.hpp:106
telegram_type
Definition: telegram.hpp:90
TelegramQueue
ConcurrentQueue< std::shared_ptr< Telegram > > TelegramQueue
Definition: telegram.hpp:199
SYNC_BYTE_1
static const uint8_t SYNC_BYTE_1
0x24 is ASCII for $ - 1st byte in each message
Definition: telegram.hpp:44
CONNECTION_DESCRIPTOR_BYTE_N
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_N
Definition: telegram.hpp:79
telegram_type::ERROR_RESPONSE
@ ERROR_RESPONSE
Definition: telegram.hpp:98
Telegram::message
std::vector< uint8_t > message
Definition: telegram.hpp:108
telegram_type::NMEA
@ NMEA
Definition: telegram.hpp:95
ConcurrentQueue::pop
void pop(T &output) noexcept
Definition: telegram.hpp:191
ConcurrentQueue::empty
bool empty() const noexcept
Definition: telegram.hpp:167
telegram_type::CONNECTION_DESCRIPTOR
@ CONNECTION_DESCRIPTOR
Definition: telegram.hpp:99
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:46
ConcurrentQueue::push
void push(const T &input) noexcept
Definition: telegram.hpp:181
telegram_type::RESPONSE
@ RESPONSE
Definition: telegram.hpp:97
ConcurrentQueue::cond_
std::condition_variable cond_
Definition: telegram.hpp:162
Telegram
Definition: telegram.hpp:104
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:58
typedefs.hpp
Telegram::~Telegram
~Telegram()
Definition: telegram.hpp:116
CONNECTION_DESCRIPTOR_BYTE_U
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_U
Definition: telegram.hpp:76
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:60
telegram_type::TelegramType
TelegramType
Definition: telegram.hpp:91
telegram_type::UNKNOWN
@ UNKNOWN
Definition: telegram.hpp:100
SBF_HEADER_SIZE
static const uint16_t SBF_HEADER_SIZE
Definition: telegram.hpp:86
ConcurrentQueue::queue_
std::queue< T > queue_
Definition: telegram.hpp:161
ConcurrentQueue::size
size_t size() const noexcept
Definition: telegram.hpp:174
Telegram::Telegram
Telegram(Telegram &&other) noexcept
Definition: telegram.hpp:123
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:56
MAX_SBF_SIZE
static const uint16_t MAX_SBF_SIZE
Definition: telegram.hpp:87
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:48
telegram_type::EMPTY
@ EMPTY
Definition: telegram.hpp:93
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:52
telegram_type::SBF
@ SBF
Definition: telegram.hpp:94
Telegram::operator=
Telegram & operator=(const Telegram &other) noexcept
Definition: telegram.hpp:128
CONNECTION_DESCRIPTOR_FOOTER
static const uint8_t CONNECTION_DESCRIPTOR_FOOTER
0x3E is ASCII for > - end character of connection descriptor
Definition: telegram.hpp:84
CONNECTION_DESCRIPTOR_BYTE_I
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_I
Definition: telegram.hpp:70
CR
static const uint8_t CR
0x0D is ASCII for "Carriage Return", i.e. "Enter"
Definition: telegram.hpp:65
CONNECTION_DESCRIPTOR_BYTE_C
static const uint8_t CONNECTION_DESCRIPTOR_BYTE_C
Definition: telegram.hpp:73
ERROR_SYNC_BYTE_3
static const uint8_t ERROR_SYNC_BYTE_3
Definition: telegram.hpp:63
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:50
ConcurrentQueue::mtx_
std::mutex mtx_
Definition: telegram.hpp:163
LF
static const uint8_t LF
0x0A is ASCII for "Line Feed", i.e. "New Line"
Definition: telegram.hpp:67
MAX_UDP_PACKET_SIZE
static const uint16_t MAX_UDP_PACKET_SIZE
Definition: telegram.hpp:88


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