DESERT 3.5.1
Loading...
Searching...
No Matches
UwMODAModem Class Reference

#include <uwmodamodem.h>

Inheritance diagram for UwMODAModem:
Collaboration diagram for UwMODAModem:

Public Types

enum class  ModemState { AVAILABLE = 0 , TRANSMITTING , RECEIVING , CONFIGURING }
 
enum class  ModemResponse { UNDEFINED = 0 , TX_END , RX_BEG , CFG_END }
 
- Public Types inherited from UwModem
enum class  LogLevel { ERROR = 0 , INFO = 1 , DEBUG = 2 }
 

Public Member Functions

 UwMODAModem ()
 
virtual ~UwMODAModem ()
 
virtual void recv (Packet *p)
 
virtual int command (int argc, const char *const *argv)
 
virtual int getModulationType (Packet *p)
 
virtual double getTxDuration (Packet *p)
 
virtual int recvSyncClMsg (ClMessage *m)
 
- Public Member Functions inherited from UwModem
 UwModem ()
 
virtual ~UwModem ()
 
void setModemID (int ID)
 
int getModemID ()
 
void printOnLog (LogLevel log_level, string module, string message)
 
LogLevel getLogLevel ()
 
int getDebug ()
 
std::string getLogFile ()
 
void realTxEnded (Packet *p)
 

Protected Member Functions

virtual void startTx (Packet *p)
 
virtual void startRx (Packet *p)
 
virtual void endRx (Packet *p)
 
- Protected Member Functions inherited from UwModem
virtual void endTx (Packet *p)
 
void checkEvent ()
 

Protected Attributes

ModemState status
 
- Protected Attributes inherited from UwModem
int modemID
 
std::vector< char > data_buffer
 
std::queue< Packet * > tx_queue
 
std::queue< Packet * > rx_queue
 
unsigned int DATA_BUFFER_LEN
 
int MAX_READ_BYTES
 
std::string modem_address
 
int debug_
 
std::ofstream outLog
 
std::string logFile
 
std::string log_suffix
 
LogLevel loglevel_
 
bool log_is_open
 
CheckTimercheckTimer
 
double period
 
std::queue< ModemEventevent_q
 

Private Member Functions

void start ()
 
void stop ()
 
void receivingSignaling ()
 
void receivingData ()
 
void createRxPacket (Packet *p)
 
void transmittingData ()
 
ModemResponse parseSignaling (std::vector< char >::iterator &end_it)
 
void updateStatus (ModemResponse response)
 

Private Attributes

std::mutex status_m
 
std::condition_variable status_cv
 
std::mutex tx_queue_m
 
std::condition_variable tx_queue_cv
 
std::atomic< bool > receiving
 
std::atomic< bool > transmitting
 
std::string rx_payload
 
int rx_size
 
std::thread sig_thread
 
std::thread rx_thread
 
std::thread tx_thread
 
std::unique_ptr< UwConnectorsignal_conn
 
std::unique_ptr< UwConnectordata_conn
 
std::vector< char > signal_buffer
 
const std::string sep = {"::"}
 
const std::string end_delim = {";"}
 
std::string signal_tag
 
std::string signal_address
 
int premodulation
 

Static Private Attributes

static std::vector< std::pair< std::string, ModemResponse > > signaling_dict
 
static std::map< ModemState, std::string > stateToString
 
static const int SIGNALING_ADDRESS = 55006
 
static const int DATA_ADDRESS = 55555
 
static const std::chrono::milliseconds MODEM_TIMEOUT
 

Additional Inherited Members

- Static Public Member Functions inherited from UwModem
static bool string2log (const std::string &ll_string, LogLevel &ll)
 
static bool log2string (LogLevel ll, std::string &ll_string)
 

Detailed Description

Definition at line 51 of file uwmodamodem.h.

Member Enumeration Documentation

◆ ModemResponse

enum class UwMODAModem::ModemResponse
strong

Enum type representing modem responses.

UNDEFINED: unrecognized signaling TX_END: modem signals that it has ended a transmission RX_BEG: modem signals that it has begun receiving data CFG_END: modem signals that it has ended an ongoing configuration

Enumerator
UNDEFINED 
TX_END 
RX_BEG 
CFG_END 

Definition at line 71 of file uwmodamodem.h.

◆ ModemState

enum class UwMODAModem::ModemState
strong

Enum type for the modem general state.

AVAILABLE: immediately available to perform an operation TRANSMITTING: executing a tranmission command: must wait for it ot complete CONFIGURING: executing a configuration command: must wait for it to complete

Enumerator
AVAILABLE 
TRANSMITTING 
RECEIVING 
CONFIGURING 

Definition at line 62 of file uwmodamodem.h.

Constructor & Destructor Documentation

◆ UwMODAModem()

UwMODAModem::UwMODAModem ( )

Constructor of the UwMODAModem class.

Definition at line 87 of file uwmodamodem.cpp.

◆ ~UwMODAModem()

UwMODAModem::~UwMODAModem ( )
virtual

Destructor of the UwMODAModem class.

Definition at line 113 of file uwmodamodem.cpp.

Member Function Documentation

◆ command()

int UwMODAModem::command ( int  argc,
const char *const *  argv 
)
virtual

Tcl command interpreter: Method that maps Tcl commands into C++ methods.

Parameters
argcnumber of arguments in argv
argvarray of strings which are the command parameters (Note that argv[0] is the name of the object).
Returns
TCL_OK or TCL_ERROR whether the command has been dispatched successfully or not

Reimplemented from UwModem.

Definition at line 162 of file uwmodamodem.cpp.

◆ createRxPacket()

void UwMODAModem::createRxPacket ( Packet *  p)
private

Method that creates a packet from the received stream of bytes.

Parameters
pallocated empty packet to fill in with the received bytes

Definition at line 354 of file uwmodamodem.cpp.

◆ endRx()

void UwMODAModem::endRx ( Packet *  p)
protectedvirtual

Method that ends a packet reception.

This method is also in charge of sending the received NS-MIRACLE packet to the upper layers

Parameters
pPacket pointer to the packet being sent

Implements UwModem.

Definition at line 241 of file uwmodamodem.cpp.

◆ getModulationType()

int UwMODAModem::getModulationType ( Packet *  p)
virtual

Method that returns the modulation type used for the packet being transmitted.

Inherited from MPhy, in NS-MIRACLE, could be left empty if no way exists to retrieve this information

Parameters
pPacket pointer to the given packet being transmitted
modulationtype represented by an integer

Reimplemented from UwModem.

Definition at line 176 of file uwmodamodem.cpp.

◆ getTxDuration()

double UwMODAModem::getTxDuration ( Packet *  p)
virtual

Method that returns the duration of a given transmitted packet.

It uses a linear interpolation given the packet size. Inherited from MPhy, in NS-MIRACLE, could be empty if there is no way to retrieve this information.

Parameters
pPacket pointer to the given packet being transmitted
Returns
duration in seconds

Reimplemented from UwModem.

Definition at line 182 of file uwmodamodem.cpp.

◆ parseSignaling()

UwMODAModem::ModemResponse UwMODAModem::parseSignaling ( std::vector< char >::iterator &  end_it)
private

Method that parses the content of the signaling data buffer to retrieve signaling messages.

Definition at line 421 of file uwmodamodem.cpp.

◆ receivingData()

void UwMODAModem::receivingData ( )
private

Method that dispatch a thread dedicated to receiving data from the data connector.

Definition at line 307 of file uwmodamodem.cpp.

◆ receivingSignaling()

void UwMODAModem::receivingSignaling ( )
private

Method that dispacthes a thread dedicated to receiving signaling from the signaling connector Allows to be compliant with modem opeations: if channel fails, driver must stop operations until signaling resumes.

Definition at line 364 of file uwmodamodem.cpp.

◆ recv()

void UwMODAModem::recv ( Packet *  p)
virtual

Method that handles the reception of packets arriving from upper layers of the network simulator.

Parameters
ppointer to the packet that has been received from the simulator upper layers

Implements UwModem.

Definition at line 119 of file uwmodamodem.cpp.

◆ recvSyncClMsg()

int UwMODAModem::recvSyncClMsg ( ClMessage *  m)
virtual

Cross-Layer messages synchronous interpreter.

Parameters
ClMessage*an instance of ClMessage that represent the message received
Returns
0 if successful.

Implements UwModem.

Definition at line 204 of file uwmodamodem.cpp.

◆ start()

void UwMODAModem::start ( )
privatevirtual

Method that starts the driver operations.

It performs all the needed operations to correctly fire up the device's driver.

Implements UwModem.

Definition at line 248 of file uwmodamodem.cpp.

◆ startRx()

void UwMODAModem::startRx ( Packet *  p)
protectedvirtual

Method that starts a packet reception.

This method is also in charge of sending a CrLayerMsg, Phy2MacStartRx(p), to notify the upper layers of the simulator about the start of the reception

Parameters
pPacket pointer to the packet to be received

Implements UwModem.

Definition at line 233 of file uwmodamodem.cpp.

◆ startTx()

void UwMODAModem::startTx ( Packet *  p)
protectedvirtual

Method that triggers the transmission of a packet through a specified modem.

Parameters
pPacket pointer to the packet to be sent

Implements UwModem.

Definition at line 495 of file uwmodamodem.cpp.

◆ stop()

void UwMODAModem::stop ( )
privatevirtual

Method that stops the driver operations.

It performs all the needed operations to correctly stop the device's driver before closing operations.

Implements UwModem.

Definition at line 280 of file uwmodamodem.cpp.

◆ transmittingData()

void UwMODAModem::transmittingData ( )
private

Method that dispatches a thread dedicated to transmitting data through the data connector.

Definition at line 395 of file uwmodamodem.cpp.

◆ updateStatus()

void UwMODAModem::updateStatus ( ModemResponse  response)
private

Method that, based on the received signaling, updates the state machine of the driver.

Parameters
responseModemRresponse response from the modem

Definition at line 467 of file uwmodamodem.cpp.

Member Data Documentation

◆ DATA_ADDRESS

const int UwMODAModem::DATA_ADDRESS = 55555
staticprivate

Port of the data channel.

Definition at line 256 of file uwmodamodem.h.

◆ data_conn

std::unique_ptr<UwConnector> UwMODAModem::data_conn
private

Data connector: used ot retrieve data coming from the modem data socket.

Definition at line 255 of file uwmodamodem.h.

◆ end_delim

const std::string UwMODAModem::end_delim = {";"}
private

String end delimiter used in reception signaling.

Definition at line 267 of file uwmodamodem.h.

◆ MODEM_TIMEOUT

const std::chrono::milliseconds UwMODAModem::MODEM_TIMEOUT
staticprivate
Initial value:
=
std::chrono::milliseconds(3000)

Maximum time to wait for modem to become ModemState::AVAILABLE.

Definition at line 262 of file uwmodamodem.h.

◆ premodulation

int UwMODAModem::premodulation
private

True if premodulation is on, false otherwise.

Definition at line 278 of file uwmodamodem.h.

◆ receiving

std::atomic<bool> UwMODAModem::receiving
private

Atomic boolean variable that controls the receiving looping thread.

Definition at line 225 of file uwmodamodem.h.

◆ rx_payload

std::string UwMODAModem::rx_payload
private

String that is updated with each new received message.

Definition at line 230 of file uwmodamodem.h.

◆ rx_size

int UwMODAModem::rx_size
private

Size of each new received message, coming from signaling.

Definition at line 232 of file uwmodamodem.h.

◆ rx_thread

std::thread UwMODAModem::rx_thread
private

Thread managing the data reception process.

Definition at line 235 of file uwmodamodem.h.

◆ sep

const std::string UwMODAModem::sep = {"::"}
private

String separator used in reception signaling.

Definition at line 265 of file uwmodamodem.h.

◆ sig_thread

std::thread UwMODAModem::sig_thread
private

Thread managing the signaling reception process.

Definition at line 234 of file uwmodamodem.h.

◆ signal_address

std::string UwMODAModem::signal_address
private

Definition at line 276 of file uwmodamodem.h.

◆ signal_buffer

std::vector<char> UwMODAModem::signal_buffer
private

Bytes buffer for the signaling channel (unparsed data)

Definition at line 259 of file uwmodamodem.h.

◆ signal_conn

std::unique_ptr<UwConnector> UwMODAModem::signal_conn
private

Signaling connector: used ot retrieve signaling coming from the modem signaling's channel.

Definition at line 249 of file uwmodamodem.h.

◆ signal_tag

std::string UwMODAModem::signal_tag
private

Signaling tag to recognize signaling from the modem.

It is not necessary but added in case of future additional features that want to use the signaling channel

Definition at line 274 of file uwmodamodem.h.

◆ SIGNALING_ADDRESS

const int UwMODAModem::SIGNALING_ADDRESS = 55006
staticprivate

Port of the signaling channel.

Definition at line 250 of file uwmodamodem.h.

◆ signaling_dict

std::vector< std::pair< std::string, UwMODAModem::ModemResponse > > UwMODAModem::signaling_dict
staticprivate
Initial value:
{
std::make_pair("RX_STARTED", ModemResponse::RX_BEG),
std::make_pair("TX_ENDED", ModemResponse::TX_END),
std::make_pair("CFG_ENDED", ModemResponse::CFG_END)
}

Dictionary of accepted signaling states.

Definition at line 52 of file uwmodamodem.h.

◆ stateToString

std::map< UwMODAModem::ModemState, std::string > UwMODAModem::stateToString
staticprivate
Initial value:
{
std::make_pair(ModemState::AVAILABLE, "AVAILABLE"),
std::make_pair(ModemState::TRANSMITTING, "TRANSMITTING"),
std::make_pair(ModemState::RECEIVING, "RECEIVING"),
std::make_pair(ModemState::CONFIGURING, "CONFIGURING")
}

Dictionary for converting a state to a printable string.

Definition at line 59 of file uwmodamodem.h.

◆ status

ModemState UwMODAModem::status
protected

Variable holding the current status of the modem.

Definition at line 160 of file uwmodamodem.h.

◆ status_cv

std::condition_variable UwMODAModem::status_cv
private

Condition variable that is linked with the status variable.

Definition at line 219 of file uwmodamodem.h.

◆ status_m

std::mutex UwMODAModem::status_m
private

Mutex associated with the state machine of the modem.

Definition at line 217 of file uwmodamodem.h.

◆ transmitting

std::atomic<bool> UwMODAModem::transmitting
private

Atomic boolean variable that controls the transmitting looping thread.

Definition at line 227 of file uwmodamodem.h.

◆ tx_queue_cv

std::condition_variable UwMODAModem::tx_queue_cv
private

Condition variable that is linked with the transmitting queue.

Definition at line 223 of file uwmodamodem.h.

◆ tx_queue_m

std::mutex UwMODAModem::tx_queue_m
private

Mutex associated with the transmission queue.

Definition at line 221 of file uwmodamodem.h.

◆ tx_thread

std::thread UwMODAModem::tx_thread
private

Thread managing the data transmission process.

Definition at line 236 of file uwmodamodem.h.


The documentation for this class was generated from the following files: