DESERT 3.5.1
Loading...
Searching...
No Matches
uwmodamodem.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
36#ifndef UWMODAMODEM_H
37#define UWMODAMODEM_H
38
39#include <uwmodem.h>
40#include <uwconnector.h>
41#include <uwsocket.h>
42
43#include <thread>
44#include <atomic>
45#include <condition_variable>
46#include <mutex>
47#include <vector>
48#include <map>
49#include <string>
50
51class UwMODAModem : public UwModem
53
54public:
55
63
71 enum class ModemResponse {
72 UNDEFINED = 0,
73 TX_END,
74 RX_BEG,
76 };
77
82
86 virtual ~UwMODAModem();
87
94 virtual void recv(Packet *p);
95
105 virtual int command(int argc, const char *const *argv);
106
114 virtual int
115 getModulationType(Packet *p);
116
125 virtual double getTxDuration(Packet *p);
126
134 virtual int recvSyncClMsg(ClMessage *m);
135
136protected:
137
143 virtual void startTx(Packet *p);
144
151 virtual void startRx(Packet *p);
152
158 virtual void endRx(Packet *p);
159
162private:
163
168 void start();
169
175 void stop();
176
183 void receivingSignaling();
184
189 void receivingData();
190
195 void createRxPacket(Packet *p);
196
201 void transmittingData();
202
207 ModemResponse parseSignaling(std::vector<char>::iterator& end_it);
208
214 void updateStatus(ModemResponse response);
215
217 std::mutex status_m;
219 std::condition_variable status_cv;
221 std::mutex tx_queue_m;
223 std::condition_variable tx_queue_cv;
225 std::atomic<bool> receiving;
227 std::atomic<bool> transmitting;
228
230 std::string rx_payload;
233
234 std::thread sig_thread;
235 std::thread rx_thread;
236 std::thread tx_thread;
239 static std::vector<std::pair<std::string, ModemResponse> > signaling_dict;
240
241
243 static std::map<ModemState, std::string> stateToString;
244
249 std::unique_ptr<UwConnector> signal_conn;
250 static const int SIGNALING_ADDRESS;
255 std::unique_ptr<UwConnector> data_conn;
256 static const int DATA_ADDRESS;
259 std::vector<char> signal_buffer;
260
262 const static std::chrono::milliseconds MODEM_TIMEOUT;
263
265 const std::string sep = {"::"};
267 const std::string end_delim = {";"};
268
274 std::string signal_tag;
275
276 std::string signal_address;
277
279};
280
281#endif
std::thread rx_thread
Thread managing the data reception process.
virtual int getModulationType(Packet *p)
Method that returns the modulation type used for the packet being transmitted.
int premodulation
True if premodulation is on, false otherwise.
void createRxPacket(Packet *p)
Method that creates a packet from the received stream of bytes.
const std::string sep
String separator used in reception signaling.
virtual void endRx(Packet *p)
Method that ends a packet reception.
ModemState status
Variable holding the current status of the modem.
void receivingSignaling()
Method that dispacthes a thread dedicated to receiving signaling from the signaling connector Allows ...
ModemResponse parseSignaling(std::vector< char >::iterator &end_it)
Method that parses the content of the signaling data buffer to retrieve signaling messages.
void receivingData()
Method that dispatch a thread dedicated to receiving data from the data connector.
std::mutex status_m
Mutex associated with the state machine of the modem.
static const int SIGNALING_ADDRESS
Port of the signaling channel.
virtual void recv(Packet *p)
Method that handles the reception of packets arriving from upper layers of the network simulator.
std::thread tx_thread
Thread managing the data transmission process.
virtual double getTxDuration(Packet *p)
Method that returns the duration of a given transmitted packet.
void updateStatus(ModemResponse response)
Method that, based on the received signaling, updates the state machine of the driver.
std::string rx_payload
String that is updated with each new received message.
void start()
Method that starts the driver operations.
std::thread sig_thread
Thread managing the signaling reception process.
std::atomic< bool > receiving
Atomic boolean variable that controls the receiving looping thread.
virtual void startTx(Packet *p)
Method that triggers the transmission of a packet through a specified modem.
std::condition_variable status_cv
Condition variable that is linked with the status variable.
std::mutex tx_queue_m
Mutex associated with the transmission queue.
ModemResponse
Enum type representing modem responses.
Definition uwmodamodem.h:71
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.
static std::vector< std::pair< std::string, ModemResponse > > signaling_dict
Dictionary of accepted signaling states.
Definition uwmodamodem.h:52
void stop()
Method that stops the driver operations.
void transmittingData()
Method that dispatches a thread dedicated to transmitting data through the data connector.
virtual int command(int argc, const char *const *argv)
Tcl command interpreter: Method that maps Tcl commands into C++ methods.
static std::map< ModemState, std::string > stateToString
Dictionary for converting a state to a printable string.
Definition uwmodamodem.h:59
std::string signal_tag
Signaling tag to recognize signaling from the modem.
UwMODAModem()
Constructor of the UwMODAModem class.
const std::string end_delim
String end delimiter used in reception signaling.
std::vector< char > signal_buffer
Bytes buffer for the signaling channel (unparsed data)
ModemState
Enum type for the modem general state.
Definition uwmodamodem.h:62
virtual void startRx(Packet *p)
Method that starts a packet reception.
virtual ~UwMODAModem()
Destructor of the UwMODAModem class.
int rx_size
Size of each new received message, coming from signaling.
std::unique_ptr< UwConnector > signal_conn
Signaling connector: used ot retrieve signaling coming from the modem signaling's channel.
virtual int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
static const int DATA_ADDRESS
Port of the data channel.
std::atomic< bool > transmitting
Atomic boolean variable that controls the transmitting looping thread.
std::string signal_address
std::unique_ptr< UwConnector > data_conn
Data connector: used ot retrieve data coming from the modem data socket.
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,...
Header of the main class that implements the general interface between DESERT and real acoustic modem...
Class that implements a connector and, specifically, the socket connector. BSD sockets are used,...