DESERT 4.0.0
UwMODAModem Class Reference

#include <uwmodamodem.h>

Inheritance diagram for UwMODAModem:
Inheritance graph
Collaboration diagram for UwMODAModem:
Collaboration graph

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)
 

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 

◆ 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 

Constructor & Destructor Documentation

◆ UwMODAModem()

UwMODAModem::UwMODAModem ( )

Constructor of the UwMODAModem class

References UwModem::data_buffer, data_conn, premodulation, and signal_conn.

◆ ~UwMODAModem()

UwMODAModem::~UwMODAModem ( )
virtual

Destructor of the UwMODAModem class

References stop().

Here is the call graph for this function:

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.

References UwModem::command(), and signal_address.

Here is the call graph for this function:

◆ 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

References hdr_uwal::binPkt(), hdr_uwal::binPktLength(), and rx_payload.

Referenced by receivingData().

Here is the call graph for this function:

◆ 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.

References UwModem::INFO, and UwModem::printOnLog().

Referenced by recv().

Here is the call graph for this function:

◆ 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.

Referenced by recv().

◆ 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.

References hdr_uwal::binPktLength(), and premodulation.

Referenced by recv(), and recvSyncClMsg().

Here is the call graph for this function:

◆ 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

References end_delim, RX_BEG, rx_size, sep, signal_buffer, signal_tag, signaling_dict, and UNDEFINED.

Referenced by receivingSignaling().

◆ receivingData()

void UwMODAModem::receivingData ( )
private

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

References AVAILABLE, createRxPacket(), UwModem::data_buffer, UwModem::DATA_BUFFER_LEN, data_conn, UwModem::DEBUG, UwModem::event_q, UwModem::MAX_READ_BYTES, MODEM_TIMEOUT, UwModem::printOnLog(), receiving, UwModem::recv(), rx_payload, rx_size, status, status_cv, and status_m.

Referenced by start().

Here is the call graph for this function:

◆ 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

References UwModem::DATA_BUFFER_LEN, UwModem::MAX_READ_BYTES, parseSignaling(), receiving, signal_buffer, signal_conn, UNDEFINED, and updateStatus().

Referenced by start().

Here is the call graph for this function:

◆ 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.

References UwModem::DEBUG, endRx(), getModulationType(), getTxDuration(), UwModem::printOnLog(), startRx(), UwModem::tx_queue, tx_queue_cv, and tx_queue_m.

Here is the call graph for this function:

◆ 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.

References getTxDuration(), UwModem::INFO, and UwModem::printOnLog().

Here is the call graph for this function:

◆ 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.

References UwModem::CheckTimer, UwModem::checkTimer, data_conn, UwModem::DEBUG, UwModem::ERROR, UwModem::modem_address, UwModem::period, UwModem::printOnLog(), receiving, receivingData(), receivingSignaling(), rx_thread, sig_thread, signal_address, signal_conn, transmitting, transmittingData(), and tx_thread.

Here is the call graph for this function:

◆ 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.

References UwModem::INFO, and UwModem::printOnLog().

Referenced by recv().

Here is the call graph for this function:

◆ 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.

References hdr_uwal::binPkt(), hdr_uwal::binPktLength(), data_conn, UwModem::ERROR, UwModem::event_q, UwModem::INFO, MODEM_TIMEOUT, UwModem::printOnLog(), UwModem::realTxEnded(), status, status_cv, status_m, and TRANSMITTING.

Referenced by transmittingData().

Here is the call graph for this function:

◆ 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.

References UwModem::checkTimer, data_conn, UwModem::ERROR, UwModem::printOnLog(), receiving, rx_thread, sig_thread, signal_conn, status_cv, transmitting, tx_queue_cv, and tx_thread.

Referenced by ~UwMODAModem().

Here is the call graph for this function:

◆ transmittingData()

void UwMODAModem::transmittingData ( )
private

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

References UwModem::DEBUG, UwModem::printOnLog(), startTx(), transmitting, UwModem::tx_queue, tx_queue_cv, and tx_queue_m.

Referenced by start().

Here is the call graph for this function:

◆ 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

References AVAILABLE, CFG_END, UwModem::DEBUG, UwModem::ERROR, UwModem::printOnLog(), RECEIVING, RX_BEG, stateToString, status, status_cv, status_m, and TX_END.

Referenced by receivingSignaling().

Here is the call graph for this function:

Member Data Documentation

◆ DATA_ADDRESS

const int UwMODAModem::DATA_ADDRESS = 55555
staticprivate

Port of the data channel

◆ data_conn

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

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

Referenced by receivingData(), start(), startTx(), stop(), and UwMODAModem().

◆ end_delim

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

String end delimiter used in reception signaling

Referenced by parseSignaling().

◆ 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

Referenced by receivingData(), and startTx().

◆ premodulation

int UwMODAModem::premodulation
private

True if premodulation is on, false otherwise

Referenced by getTxDuration(), and UwMODAModem().

◆ receiving

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

Atomic boolean variable that controls the receiving looping thread

Referenced by receivingData(), receivingSignaling(), start(), and stop().

◆ rx_payload

std::string UwMODAModem::rx_payload
private

String that is updated with each new received message

Referenced by createRxPacket(), and receivingData().

◆ rx_size

int UwMODAModem::rx_size
private

Size of each new received message, coming from signaling

Referenced by parseSignaling(), and receivingData().

◆ rx_thread

std::thread UwMODAModem::rx_thread
private

Thread managing the data reception process

Referenced by start(), and stop().

◆ sep

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

String separator used in reception signaling

Referenced by parseSignaling().

◆ sig_thread

std::thread UwMODAModem::sig_thread
private

Thread managing the signaling reception process

Referenced by start(), and stop().

◆ signal_address

std::string UwMODAModem::signal_address
private

Referenced by command(), and start().

◆ signal_buffer

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

Bytes buffer for the signaling channel (unparsed data)

Referenced by parseSignaling(), and receivingSignaling().

◆ signal_conn

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

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

Referenced by receivingSignaling(), start(), stop(), and UwMODAModem().

◆ 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

Referenced by parseSignaling().

◆ SIGNALING_ADDRESS

const int UwMODAModem::SIGNALING_ADDRESS = 55006
staticprivate

Port of the signaling channel

◆ 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

Referenced by parseSignaling().

◆ 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

Referenced by updateStatus().

◆ status

ModemState UwMODAModem::status
protected

Variable holding the current status of the modem

Referenced by receivingData(), startTx(), and updateStatus().

◆ status_cv

std::condition_variable UwMODAModem::status_cv
private

Condition variable that is linked with the status variable

Referenced by receivingData(), startTx(), stop(), and updateStatus().

◆ status_m

std::mutex UwMODAModem::status_m
private

Mutex associated with the state machine of the modem

Referenced by receivingData(), startTx(), and updateStatus().

◆ transmitting

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

Atomic boolean variable that controls the transmitting looping thread

Referenced by start(), stop(), and transmittingData().

◆ tx_queue_cv

std::condition_variable UwMODAModem::tx_queue_cv
private

Condition variable that is linked with the transmitting queue

Referenced by recv(), stop(), and transmittingData().

◆ tx_queue_m

std::mutex UwMODAModem::tx_queue_m
private

Mutex associated with the transmission queue

Referenced by recv(), and transmittingData().

◆ tx_thread

std::thread UwMODAModem::tx_thread
private

Thread managing the data transmission process

Referenced by start(), and stop().


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