DESERT 3.5.1
Loading...
Searching...
No Matches
uwevologicss2cmodem.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 UWEVOLOGICSS2CSMODEM_H
38#define UWEVOLOGICSS2CSMODEM_H
39
40#include <uwconnector.h>
41#include <uwinterpreters2c.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#include <map>
51
57typedef std::map<int, double> TransmissionDurationLUT;
58
64
66{
71 enum class Config {
72 ATL_GET,
73 ATL_SET,
79 };
80
81public:
85 enum class TransmissionMode { BURST = 0, IM = 1 };
86
92
100
104 virtual ~UwEvoLogicsS2CModem();
105
112 virtual void recv(Packet *p);
113
123 virtual int command(int argc, const char *const *argv);
124
131 virtual int recvSyncClMsg(ClMessage *m);
132
140 virtual double getTxDuration(Packet *p);
141
151 virtual bool configure(Config cmd);
152
157 virtual void initializeLUT();
158
159private:
165 virtual void startTx(Packet *p);
166
173 virtual void startRx(Packet *p);
174
180 virtual void endRx(Packet *p);
181
186 virtual void start();
187
193 virtual void stop();
194
198 virtual void transmittingData();
199
203 virtual void receivingData();
204
212
219 void setFailedTx(Packet *p);
220
226 void createRxPacket(Packet *p);
227
229 std::unique_ptr<UwConnector> p_connector;
231 std::unique_ptr<UwInterpreterS2C> p_interpreter;
232
239 std::mutex status_m;
241 std::mutex tx_status_m;
243 std::mutex tx_queue_m;
245 std::condition_variable status_cv;
247 std::condition_variable tx_status_cv;
249 std::condition_variable tx_queue_cv;
251 std::atomic<bool> receiving;
253 std::atomic<bool> transmitting;
255 std::atomic<bool> im_status_updated;
257 std::thread rx_thread;
259 std::thread tx_thread;
261 std::string rx_payload;
263 const static std::chrono::milliseconds MODEM_TIMEOUT;
266 const static std::chrono::milliseconds WAIT_DELIVERY_IM;
269 const static std::chrono::seconds WAIT_DELIVERY_BURST;
270
272 bool ack_mode;
281 std::string txdur_file_name_;
283 bool initLUT_;
286 static const double EPSILON_S;
290};
291
292#endif
std::mutex status_m
Mutex associated with the state machine of the modem.
int n_rx_failed
Number of failed receptions up to now.
static uint MAX_N_STATUS_QUERIES
Maximum number of time to query the modem transmission status before to discard the transmitted packe...
bool initLUT_
Flag that tells whether the TX duration LUT is loaded or not.
TransmissionMode tx_mode
Either burst or im.
TransmissionState tx_status
Variable holding the current transmission status of the modem.
void setFailedTx(Packet *p)
Method that allows to set the error flag on the packet to notify upper layers about un-tranmsitted pa...
virtual void recv(Packet *p)
Method that handles the reception of packets arriving from upper layers of the network simulator.
std::atomic< bool > transmitting
Atomic boolean variable that controls the transmitting looping thread.
std::condition_variable status_cv
Condition variable to wait for ModemState::AVAILABLE.
std::atomic< bool > im_status_updated
Atomic boolean variable controlling if the modem had responded to ATDI.
int pend_source_level
Pending source level, requested but not set.
std::condition_variable tx_status_cv
Condition variable to wait for TransmissionState::TX_IDLE.
void updateStatus(UwInterpreterS2C::Response cmd)
Method that updates the status of the modem State Machine: state change is triggered by reception of ...
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...
std::thread rx_thread
Object with the rx thread.
UwEvoLogicsS2CModem()
Constructor of the UwEvoLogicsS2CModem class.
std::mutex tx_queue_m
Mutex associated with the transmission queue.
virtual void transmittingData()
Method that detach a thread devoted to sending packets found in tx_queue.
virtual void initializeLUT()
Method that loads the TX LUT into a map.
static const std::chrono::seconds WAIT_DELIVERY_BURST
Time interval tu wait for a burst message tobe confirmed through a DELIVERED response.
bool source_level_change
Flag that tells a new SL value to be applied.
virtual void stop()
Method that stops the driver operations.
static const std::chrono::milliseconds MODEM_TIMEOUT
Maximum time to wait for modem to become ModemState::AVAILABLE.
bool ack_mode
Set to true to enable IM ack.
std::string rx_payload
String that is updated witn each new received messsage.
std::atomic< bool > receiving
Atomic boolean variable that controls the receiving looping thread.
Config
Enum listing the availbale configuration settings.
TransmissionMode
Transmission mode: either IM or BURST See the EvoLogics S2C manuals or reach for www....
TransmissionState
Transmission state: controls the flow of execution for sending commands to the S2C device.
virtual void startRx(Packet *p)
Method that starts a packet reception.
std::condition_variable tx_queue_cv
Condition variable that is linked with the transmitting queue.
virtual void receivingData()
Mehod that detach a thread devoted to receiving data from the connector.
virtual void endRx(Packet *p)
Method that ends a packet reception.
static const double EPSILON_S
Minimum time to wait before to schedule a new event in seconds.
char txdur_token_separator_
TX duration LUT separator.
virtual void start()
Method that starts the driver operations.
double virtual_time_ref
virtual time reference
ModemState status
Variable holding the current status of the modem.
virtual ~UwEvoLogicsS2CModem()
Destructor of the UwEvoLogicsS2CModem class.
TransmissionDurationLUT size2dur_
Map from size [byte] to TX duration [s].
int curr_source_level
Current source level already set in device.
std::string txdur_file_name_
TX duration LUT file name.
virtual bool configure(Config cmd)
Method that sends a written configuration the the EvoLgoics modem.
static const std::chrono::milliseconds WAIT_DELIVERY_IM
Time interval to wait for the modem notifying that there no more IM in its queue and a new IM can be ...
virtual double getTxDuration(Packet *p)
Method that return the duration of a given transmitted packet.
virtual int command(int argc, const char *const *argv)
Tcl command interpreter: Method that maps Tcl commands into C++ methods.
std::unique_ptr< UwInterpreterS2C > p_interpreter
Pointer to Interpreter object to parse device syntax.
std::mutex tx_status_m
Mutex associated with the transmission state machine of the modem.
std::thread tx_thread
Object with the tx thread.
virtual int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
std::unique_ptr< UwConnector > p_connector
Pointer to Connector object that interfaces with the device.
virtual void startTx(Packet *p)
Method that triggers the transmission of a packet through a specified modem.
Response
Enum listing the types of commands that could be received or sent by a S2C device; See the EvoLogics ...
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,...
ModemState
Enum containing the possible statuses of the driver.
std::map< int, double > TransmissionDurationLUT
Lookup table (LUT) containing all the possible transmission times.
Header of the interepreter class: this class is used ot translate form DESERT software to/from EvoLog...
Header of the main class that implements the general interface between DESERT and real acoustic modem...