DESERT 4.0.0
uwahoimodem.h
Go to the documentation of this file.
1//
2// Copyright (c) 2019 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// 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 University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
37#ifndef UWAHOIMODEM_H
38#define UWAHOIMODEM_H
39
40#include <uwconnector.h>
41#include <uwinterpreterahoi.h>
42#include <uwmodem.h>
43
44#include <atomic>
45#include <condition_variable>
46#include <memory>
47#include <mutex>
48#include <thread>
49#include <vector>
50
56class UwAhoiModem : public UwModem
57{
58public:
67
75
83
87 virtual ~UwAhoiModem();
88
95 virtual void recv(Packet *p);
96
103 virtual int recvSyncClMsg(ClMessage *m);
104
114 virtual int command(int argc, const char *const *argv);
115
116private:
122 virtual void startTx(Packet *p);
123
130 virtual void startRx(Packet *p);
131
137 virtual void endRx(Packet *p);
138
143 virtual void start();
144
150 virtual void stop();
151
155 virtual void transmittingData();
156
160 virtual void receivingData();
161
168 void updateStatus(std::shared_ptr<ahoi::packet_t> packet);
169
174 ahoi::packet_t fillAhoiPkt(Packet *p);
175
181 void createRxPacket(Packet *p);
182
189 bool parseFooter(std::shared_ptr<ahoi::footer_t> footer);
190
198 bool storePacketInfo(std::shared_ptr<ahoi::packet_t> header, Packet *p);
199
203 void updateSN();
204
206 std::unique_ptr<UwConnector> p_connector;
207
209 std::unique_ptr<UwInterpreterAhoi> p_interpreter;
210
217 std::mutex status_m;
219 std::mutex tx_status_m;
221 std::mutex tx_queue_m;
223 std::condition_variable status_cv;
225 std::condition_variable tx_status_cv;
227 std::condition_variable tx_queue_cv;
229 std::atomic<bool> receiving;
231 std::atomic<bool> transmitting;
233 std::thread rx_thread;
235 std::thread tx_thread;
237 std::string rx_payload;
239 const static std::chrono::milliseconds MODEM_TIMEOUT;
240
241 static uint MAX_RETX;
244 static uint8_t sn;
250 static const double EPSILON_S;
251
254 std::chrono::milliseconds WAIT_DELIVERY;
255
259 static uint WAIT_DELIVERY_INT;
260
262 ahoi::packet_t tmpPacket;
263
265 uint id;
266
275
276 // Parameters values retrieved from each packet footer
278 uint power;
280 uint rssi;
289};
290
291#endif
Definition uwahoimodem.h:57
void updateSN()
Definition uwahoimodem.cpp:579
int stop_bit
Definition uwahoimodem.h:270
virtual void endRx(Packet *p)
Definition uwahoimodem.cpp:264
UwAhoiModem()
Definition uwahoimodem.cpp:73
TransmissionState
Definition uwahoimodem.h:74
uint id
Definition uwahoimodem.h:265
ModemState
Definition uwahoimodem.h:66
std::condition_variable tx_status_cv
Definition uwahoimodem.h:225
virtual void startTx(Packet *p)
Definition uwahoimodem.cpp:176
std::mutex tx_queue_m
Definition uwahoimodem.h:221
ahoi::packet_t fillAhoiPkt(Packet *p)
Definition uwahoimodem.cpp:231
std::unique_ptr< UwConnector > p_connector
Definition uwahoimodem.h:206
virtual int command(int argc, const char *const *argv)
Definition uwahoimodem.cpp:164
uint rssi
Definition uwahoimodem.h:280
virtual void stop()
Definition uwahoimodem.cpp:322
double virtual_time_ref
Definition uwahoimodem.h:247
virtual int recvSyncClMsg(ClMessage *m)
Definition uwahoimodem.cpp:170
uint power
Definition uwahoimodem.h:278
virtual void start()
Definition uwahoimodem.cpp:271
uint agc_max
Definition uwahoimodem.h:288
std::mutex tx_status_m
Definition uwahoimodem.h:219
uint bit_errors
Definition uwahoimodem.h:282
void createRxPacket(Packet *p)
Definition uwahoimodem.cpp:452
bool storePacketInfo(std::shared_ptr< ahoi::packet_t > header, Packet *p)
Definition uwahoimodem.cpp:463
std::mutex status_m
Definition uwahoimodem.h:217
uint agc_mean
Definition uwahoimodem.h:284
std::atomic< bool > receiving
Definition uwahoimodem.h:229
static uint MAX_RETX
Definition uwahoimodem.h:241
std::chrono::milliseconds WAIT_DELIVERY
Definition uwahoimodem.h:254
ModemState status
Definition uwahoimodem.h:211
static uint WAIT_DELIVERY_INT
Definition uwahoimodem.h:259
int flow_control
Definition uwahoimodem.h:272
virtual void transmittingData()
Definition uwahoimodem.cpp:342
static const std::chrono::milliseconds MODEM_TIMEOUT
Definition uwahoimodem.h:239
std::condition_variable tx_queue_cv
Definition uwahoimodem.h:227
virtual ~UwAhoiModem()
Definition uwahoimodem.cpp:116
uint agc_min
Definition uwahoimodem.h:286
std::unique_ptr< UwInterpreterAhoi > p_interpreter
Definition uwahoimodem.h:209
virtual void startRx(Packet *p)
Definition uwahoimodem.cpp:257
std::atomic< bool > transmitting
Definition uwahoimodem.h:231
std::thread rx_thread
Definition uwahoimodem.h:233
std::thread tx_thread
Definition uwahoimodem.h:235
static const double EPSILON_S
Definition uwahoimodem.h:250
int parity_bit
Definition uwahoimodem.h:268
std::condition_variable status_cv
Definition uwahoimodem.h:223
void updateStatus(std::shared_ptr< ahoi::packet_t > packet)
Definition uwahoimodem.cpp:506
std::string rx_payload
Definition uwahoimodem.h:237
virtual void receivingData()
Definition uwahoimodem.cpp:395
TransmissionState tx_status
Definition uwahoimodem.h:213
int baud_rate
Definition uwahoimodem.h:274
ahoi::packet_t tmpPacket
Definition uwahoimodem.h:262
static uint8_t sn
Definition uwahoimodem.h:244
bool parseFooter(std::shared_ptr< ahoi::footer_t > footer)
Definition uwahoimodem.cpp:493
virtual void recv(Packet *p)
Definition uwahoimodem.cpp:122
Definition uwmodem.h:62
Generic class that provides a method to interface with the devices. Will be specialized for,...
Interpreter for commands and responses for ahoi! modems, TUHH, Hamburg.
Header of the main class that implements the general interface between DESERT and real acoustic modem...