DESERT 3.5.1
Loading...
Searching...
No Matches
DESERT_Addons/uwmphy_modem/uwmdriver.cpp
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
37#include "uwmdriver.h"
38#include "uwmphy_modem.h"
39
41{
42
43 pmModem = pmModem_;
44 SetModemID = false;
45 pmInterpreter = NULL;
46 pmConnector = NULL;
47 ID = pmModem->getID();
49 payload_tx = "";
50 dest = -1;
51 payload_rx = "";
52 src = -1;
54
55 if (debug_ > 1) {
56 debug_ = 1;
57 }
58}
59
61{
62}
63
64void
66 UWMinterpreter *pmInterpreter_, UWMconnector *pmConnector_)
67{
68
69 pmInterpreter = pmInterpreter_;
70 pmConnector = pmConnector_;
72}
73
74std::string
76{
77 return pmModem->getLogFile();
78}
79
82{
83 return pmModem->getLogLevel();
84}
85
86void
88{
90}
91
92void
93UWMdriver::updateTx(int d, std::string ptx)
94{
95 dest = d;
96 payload_tx = ptx;
97}
98
99void
100UWMdriver::updateRx(int s, int d, std::string prx)
101{
102 src = s;
103 dstPktRx = d;
104 payload_rx = prx;
105}
106
107void
108UWMdriver::printOnLog(log_level_t log_level, string module, string message)
109{
110 log_level_t actual_log_level = getLogLevel();
111 if (actual_log_level >= log_level) {
112 outLog.open((getLogFile()).c_str(), ios::app);
113 outLog << left << "[" << pmModem->getEpoch() << "]::" << NOW
114 << "::" << module << "(" << ID << ")::" << message << endl;
115 outLog.flush();
116 outLog.close();
117 }
118}
Header of the class needed by UWMPhy_modem to handle the different transmissions cases and correspond...
Header of the main class that implements the general interface between ns2/NS-Miracle and real acoust...
The main class implementing the module used to implement the interface between ns2/NS-Miracle and rea...
unsigned long int getEpoch()
Calculate the epoch of the event.
std::string getLogFile()
Method to return the name of the file where to log messages.
log_level_t getLogLevel()
Method to return the flag used to enable the printing of log messages in UWMPhy_modem::logFile.
int getDebug()
Method to return the flag used to enable debug messages.
The class needed by UWMPhy_modem to manage string exchange with the modem.
void updateRx(int, int, std::string)
Method to write in UWMdriver::payload_rx, UWMdriver::src and UWMdriver::dstPktRx.
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
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.
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)
int src
Variable storing the source ID of the last packet received via modem.
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.
void resetModemStatus()
Method to reset the modem status.
UWMPhy_modem * pmModem
link to the UWMPhy_modem object that contains this driver
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.
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