DESERT 3.5.1
Loading...
Searching...
No Matches
DESERT_Addons/uwmphy_modem/uwmdriver.h
Go to the documentation of this file.
1//
2// Copyright (c) 2017 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
39#ifndef UWMDRIVER_H
40#define UWMDRIVER_H
41
42#include "uwmconnector.h"
43#include "uwminterpreter.h"
44
45#include <stdlib.h>
46#include <iostream>
47#include <stdio.h>
48#include <fstream>
49#include <string.h>
50#include <cstring>
51#include <sstream>
52#include <sys/types.h>
53#include <sys/stat.h>
54#include <fcntl.h>
55#include <unistd.h>
56#include <cmath>
57
58#define MAX_LOG_LEVEL 2
59
74
76
78
80
81
82
83// Forward declaration(s)
84class UWMPhy_modem;
85class UWMcodec;
86
95class UWMdriver
96{
97public:
105
110
111 virtual void modemSetID() = 0;
112
118 virtual void start() = 0;
119
125 virtual void stop() = 0;
126
134 virtual void modemTx() = 0;
146
154 inline void
155 setID(int ID_)
156 {
157 ID = ID_;
158 }
159
171
184 void updateTx(int, std::string);
185
202 void updateRx(int, int, std::string);
203
210 int
212 {
213 return ID;
214 }
215
223 {
224 return status;
225 }
226
237 std::string
239 {
240 return payload_rx;
241 }
242
253 int
255 {
256 return src;
257 }
258
269 int
271 {
272 return dstPktRx;
273 }
274
280 inline log_level_t
282 {
283 return (log_level_t) debug_;
284 }
285
290 inline void
291 setModemID(bool set)
292 {
293 SetModemID = set;
294 }
299 inline bool
301 {
302 return SetModemID;
303 }
304
305 inline void
306 setResetModemQueue(bool reset_m_queue)
307 {
308 ResetModemQueue = reset_m_queue;
309 }
310
311 inline bool
313 {
314 return ResetModemQueue;
315 }
323
330 std::string getLogFile();
331
332 void printOnLog(log_level_t log_level, std::string module, std::string message);
333
334protected:
348 int ID;
360 // TX VARIABLES (variables for the next packet to be transmitted)
361 std::string payload_tx;
365 int dest;
371 // RX VARIABLES (variables reffering to the last received packet)
372 std::string payload_rx;
381 int src;
389 int dstPktRx;
395 bool SetModemID;
397 int debug_;
399 std::ofstream outLog;
401 bool ResetModemQueue;
414
421 virtual void modemTxManager() = 0;
422};
423#endif /* UWMDRIVER_H */
enum MODEM_STATES modem_state_t
enum LOG_LEVEL log_level_t
Header of the class needed by UWMPhy_modem to handle the physical connection between NS-Miracle and a...
Header of the class that is in charge of building/parsing the necessary messages to make the UWMdrive...
The main class implementing the module used to implement the interface between ns2/NS-Miracle and rea...
The class needed by UWMPhy_modem to manage string exchange with the modem.
The class needed by UWMPhy_modem to handle the different transmissions cases and corresponding protoc...
void updateRx(int, int, std::string)
Method to write in UWMdriver::payload_rx, UWMdriver::src and UWMdriver::dstPktRx.
UWMdriver(UWMPhy_modem *)
Class constructor.
void updateTx(int, std::string)
Method to update the values of both UWMdriver::payload_tx and UWMdriver::dest.
log_level_t getLogLevel()
Method to return the flag used to enable the printing of log messages in UWMPhy_modem::logFile.
std::string payload_tx
String where to save the payload of the next packet to send via modem.
UWMconnector * pmConnector
pointer to the object that handles the physical transmission and reception of acoustic packets
int getSrc()
Method to access to the ID of the source of the last packet acoustically received.
modem_state_t getStatus()
Method to return the modem's status.
int getDstPktRx()
Method to access to the ID of the destination of the last packet acoustically received.
virtual void stop()=0
Driver stopper.
virtual void modemTxManager()=0
Method to manage modem to host and host to modem communications.
std::string getLogFile()
Method to return the name of the disk-fiel used to print the log messages.
int dest
Variable where to save the destination ID of the next packet to send via modem.
virtual void modemSetID()=0
int debug_
Flag to enable debug mode (i.e., printing of debug messages) if set to 1.
bool SetModemID
Variable to decide whether the interface has to set the acoustic ID of the modem or not.
void printOnLog(log_level_t log_level, std::string module, std::string message)
virtual void modemTx()=0
Method to notify to the driver that there is a packet to be sent via modem.
int src
Variable storing the source ID of the last packet received via modem.
virtual void start()=0
Driver starter.
void setResetModemQueue(bool reset_m_queue)
UWMinterpreter * pmInterpreter
pointer to the object that builds/parses the necessary messages to make UWMdriver able to communicate...
void setConnections(UWMinterpreter *, UWMconnector *)
Link connector.
int dstPktRx
Variable where to save the destination ID of the last packet received via modem.
virtual modem_state_t updateStatus()=0
Method to update modem status.
void resetModemStatus()
Method to reset the modem status.
UWMPhy_modem * pmModem
link to the UWMPhy_modem object that contains this driver
int getID()
Method to return modem ID.
std::string getRxPayload()
Method to access to the payload of the last packet acoustically received.
log_level_t getDebug()
Method to return the flag used to enable debug messages.
std::ofstream outLog
output strem to print into a disk-file log messages.
modem_state_t status
Status of the driver's general state machine.
std::string payload_rx
String where to save the payload of the last packet received via modem.
void setID(int ID_)
Method to change the modem ID.
~UWMdriver()
Class destructor.
This class is in charge of building/parsing the necessary messages to make the UWMdriver able to comm...
log_level
Definition uw-csma-ca.h:86