DESERT 3.5.1
Loading...
Searching...
No Matches
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:
66
73
81
85 virtual ~UwAhoiModem();
86
93 virtual void recv(Packet *p);
94
101 virtual int recvSyncClMsg(ClMessage *m);
102
112 virtual int command(int argc, const char *const *argv);
113
114private:
120 virtual void startTx(Packet *p);
121
128 virtual void startRx(Packet *p);
129
135 virtual void endRx(Packet *p);
136
141 virtual void start();
142
148 virtual void stop();
149
153 virtual void transmittingData();
154
158 virtual void receivingData();
159
166 void updateStatus(std::shared_ptr<ahoi::packet_t> packet);
167
172 ahoi::packet_t fillAhoiPkt(Packet *p);
173
179 void createRxPacket(Packet *p);
180
187 bool parseFooter(std::shared_ptr<ahoi::footer_t> footer);
188
196 bool storePacketInfo(std::shared_ptr<ahoi::packet_t> header, Packet *p);
197
201 void updateSN();
202
204 std::unique_ptr<UwConnector> p_connector;
205
207 std::unique_ptr<UwInterpreterAhoi> p_interpreter;
208
215 std::mutex status_m;
217 std::mutex tx_status_m;
219 std::mutex tx_queue_m;
221 std::condition_variable status_cv;
223 std::condition_variable tx_status_cv;
225 std::condition_variable tx_queue_cv;
227 std::atomic<bool> receiving;
229 std::atomic<bool> transmitting;
231 std::thread rx_thread;
233 std::thread tx_thread;
235 std::string rx_payload;
237 const static std::chrono::milliseconds MODEM_TIMEOUT;
238
239 static uint MAX_RETX;
242 static uint8_t sn;
248 static const double EPSILON_S;
249
252 std::chrono::milliseconds WAIT_DELIVERY;
253
257 static uint WAIT_DELIVERY_INT;
258
260 ahoi::packet_t tmpPacket;
261
263 uint id;
264
273
274 // Parameters values retrieved from each packet footer
276 uint power;
278 uint rssi;
287};
288
289#endif
The ahoi! modems are an underwater acoustic modems developed by TUUH University, Hamburg by the Smart...
Definition uwahoimodem.h:57
void updateSN()
Method for Sequence Number (SN) update.
int stop_bit
flag for stop bit
virtual void endRx(Packet *p)
Method that ends a packet reception.
UwAhoiModem()
Constructor of the UwAhoiModem class.
TransmissionState
Enum type for the trasnmission state.
Definition uwahoimodem.h:72
uint id
Modem ID, to be set in simulation.
ModemState
Enum type for the modem general state.
Definition uwahoimodem.h:65
std::condition_variable tx_status_cv
Condition variable to wait for TransmissionState::TX_IDLE.
virtual void startTx(Packet *p)
Method that triggers the transmission of a packet through a specified modem.
std::mutex tx_queue_m
Mutex associated with the transmission queue.
ahoi::packet_t fillAhoiPkt(Packet *p)
Method that fills the fields of an ahoi! packet with the needed values, so that later it can be seria...
std::unique_ptr< UwConnector > p_connector
Pointer to Connector object that interfaces with the device.
virtual int command(int argc, const char *const *argv)
Tcl command interpreter: Method that maps Tcl commands into C++ methods.
uint rssi
RSSI vs an "ideal packet".
virtual void stop()
Method that stops the driver operations.
double virtual_time_ref
virtual time reference
virtual int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
uint power
Received power (RMSE) ratio and "ideal packet".
virtual void start()
Method that starts the driver operations.
uint agc_max
Maximum gain set by the AGC (if used) in reception of the last packet.
std::mutex tx_status_m
Mutex associated with the state machine of the transmission process.
uint bit_errors
Number of repaired bit errors during reception in the last packet.
void createRxPacket(Packet *p)
Method that fills up a packet with the needed header and payload and makes it ready to be sent to the...
bool storePacketInfo(std::shared_ptr< ahoi::packet_t > header, Packet *p)
Method that extarcts fields from a provided ahoi! packet and save the info values to class field for ...
std::mutex status_m
Mutex associated with the state machine of the modem.
uint agc_mean
Mean gain set by the AGC (if used) in reception of the last packet.
std::atomic< bool > receiving
Atomic boolean variable that controls the receiving looping thread.
static uint MAX_RETX
Maximum number of retransmissions for the same packet.
std::chrono::milliseconds WAIT_DELIVERY
Time interval to wait for the modem notifying the response of a given packet.
ModemState status
Variable holding the current status of the modem.
static uint WAIT_DELIVERY_INT
Time interval matching the WAIT_DELIVERY variable: version of type int to match the chrono one,...
int flow_control
flag for flow control
virtual void transmittingData()
Method that detach a thread devoted to sending packets found in tx_queue.
static const std::chrono::milliseconds MODEM_TIMEOUT
Maximum time to wait for modem to become ModemState::AVAILABLE.
std::condition_variable tx_queue_cv
Condition variable that is linked with the transmitting queue.
virtual ~UwAhoiModem()
Destructor of the UwAhoiModem class.
uint agc_min
Minimum gain set by the AGC (if used) in reception of the last packet.
std::unique_ptr< UwInterpreterAhoi > p_interpreter
Pointer to Interpreter object to parse device syntax.
virtual void startRx(Packet *p)
Method that starts a packet reception.
std::atomic< bool > transmitting
Atomic boolean variable that controls the transmitting looping thread.
std::thread rx_thread
Object with the rx thread.
std::thread tx_thread
Object with the tx thread.
static const double EPSILON_S
minimum time to wait before to schedule a new event in seconds
int parity_bit
flag for parity bit
std::condition_variable status_cv
Condition variable to wait for ModemState::AVAILABLE.
void updateStatus(std::shared_ptr< ahoi::packet_t > packet)
Method that updates the status of the modem State Machine: state change is triggered by recepting the...
std::string rx_payload
String that is updated witn each new received messsage.
virtual void receivingData()
Mehod that detach a thread devoted to receiving data from the connector.
TransmissionState tx_status
Variable holding the current transmission status of the modem.
int baud_rate
Integer for port baud rate.
ahoi::packet_t tmpPacket
Packet to be checked to unlock state machine.
static uint8_t sn
Sequence number, which follows all the packets transmitted to the modem.
bool parseFooter(std::shared_ptr< ahoi::footer_t > footer)
Method that extarcts fields from a provided ahoi! packet and save the info values to class field for ...
virtual void recv(Packet *p)
Method that handles the reception of packets arriving from upper layers of the network simulator.
Class that implements the interface to DESERT, as used through Tcl scripts.
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...