DESERT 4.0.0
UwAhoiModem Class Reference

#include <uwahoimodem.h>

Inheritance diagram for UwAhoiModem:
Inheritance graph
Collaboration diagram for UwAhoiModem:
Collaboration graph

Public Types

enum class  ModemState { AVAILABLE = 0 , TRANSMITTING , CONFIGURING }
 
enum class  TransmissionState { TX_IDLE = 0 , TX_WAITING }
 
- Public Types inherited from UwModem
enum class  LogLevel { ERROR = 0 , INFO = 1 , DEBUG = 2 }
 

Public Member Functions

 UwAhoiModem ()
 
virtual ~UwAhoiModem ()
 
virtual void recv (Packet *p)
 
virtual int recvSyncClMsg (ClMessage *m)
 
virtual int command (int argc, const char *const *argv)
 
- Public Member Functions inherited from UwModem
 UwModem ()
 
virtual ~UwModem ()
 
virtual double getTxDuration (Packet *p)
 
virtual int getModulationType (Packet *P)
 
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)
 

Private Member Functions

virtual void startTx (Packet *p)
 
virtual void startRx (Packet *p)
 
virtual void endRx (Packet *p)
 
virtual void start ()
 
virtual void stop ()
 
virtual void transmittingData ()
 
virtual void receivingData ()
 
void updateStatus (std::shared_ptr< ahoi::packet_t > packet)
 
ahoi::packet_t fillAhoiPkt (Packet *p)
 
void createRxPacket (Packet *p)
 
bool parseFooter (std::shared_ptr< ahoi::footer_t > footer)
 
bool storePacketInfo (std::shared_ptr< ahoi::packet_t > header, Packet *p)
 
void updateSN ()
 

Private Attributes

std::unique_ptr< UwConnectorp_connector
 
std::unique_ptr< UwInterpreterAhoip_interpreter
 
ModemState status
 
TransmissionState tx_status
 
std::mutex status_m
 
std::mutex tx_status_m
 
std::mutex tx_queue_m
 
std::condition_variable status_cv
 
std::condition_variable tx_status_cv
 
std::condition_variable tx_queue_cv
 
std::atomic< bool > receiving
 
std::atomic< bool > transmitting
 
std::thread rx_thread
 
std::thread tx_thread
 
std::string rx_payload
 
double virtual_time_ref
 
std::chrono::milliseconds WAIT_DELIVERY
 
ahoi::packet_t tmpPacket
 
uint id
 
int parity_bit
 
int stop_bit
 
int flow_control
 
int baud_rate
 
uint power
 
uint rssi
 
uint bit_errors
 
uint agc_mean
 
uint agc_min
 
uint agc_max
 

Static Private Attributes

static const std::chrono::milliseconds MODEM_TIMEOUT
 
static uint MAX_RETX = 0
 
static uint8_t sn = 0
 
static const double EPSILON_S
 
static uint WAIT_DELIVERY_INT = 3000
 

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)
 
- Protected Member Functions inherited from UwModem
virtual void endTx (Packet *p)
 
void checkEvent ()
 
- 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
 

Detailed Description

The ahoi! modems are an underwater acoustic modems developed by TUUH University, Hamburg by the SmartPORT Group. The reference website can be found here: https://www.tuhh.de/smartport/research/acoustic-modem.html

Member Enumeration Documentation

◆ ModemState

enum class UwAhoiModem::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 
CONFIGURING 

◆ TransmissionState

enum class UwAhoiModem::TransmissionState
strong

Enum type for the trasnmission state. TX_IDLE: the modem is available for transmission of a new packet TX_WAITING: a packet was tranmitted but the command was not acknowledged

Enumerator
TX_IDLE 
TX_WAITING 

Constructor & Destructor Documentation

◆ UwAhoiModem()

UwAhoiModem::UwAhoiModem ( )

Constructor of the UwAhoiModem class

Parameters
addressstring containing the address to connect to
buflenlenght in char of the data buffer
readlen length in char of a signle read from the connector

References baud_rate, UwModem::DATA_BUFFER_LEN, flow_control, UwModem::MAX_READ_BYTES, MAX_RETX, parity_bit, stop_bit, and WAIT_DELIVERY_INT.

◆ ~UwAhoiModem()

UwAhoiModem::~UwAhoiModem ( )
virtual

Destructor of the UwAhoiModem class

References stop().

Here is the call graph for this function:

Member Function Documentation

◆ command()

int UwAhoiModem::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().

Here is the call graph for this function:

◆ createRxPacket()

void UwAhoiModem::createRxPacket ( Packet *  p)
private

Method that fills up a packet with the needed header and payload and makes it ready to be sent to the layer above

Parameters
pinstance of an empty packet to be filled

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

Referenced by updateStatus().

Here is the call graph for this function:

◆ endRx()

void UwAhoiModem::endRx ( Packet *  p)
privatevirtual

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:

◆ fillAhoiPkt()

ahoi::packet_t UwAhoiModem::fillAhoiPkt ( Packet *  p)
private

Method that fills the fields of an ahoi! packet with the needed values, so that later it can be serialized. param p Packet pointer of the DESERT packet

References ahoi::ACK_NONE, hdr_uwal::binPkt(), hdr_uwal::binPktLength(), ahoi::commands_id, UwModem::modemID, ahoi::send, and sn.

Referenced by startTx().

Here is the call graph for this function:

◆ parseFooter()

bool UwAhoiModem::parseFooter ( std::shared_ptr< ahoi::footer_t >  footer)
private

Method that extarcts fields from a provided ahoi! packet and save the info values to class field for later access. Info parameters include values such as received power, RSSI, number of corrupted packets, ecc...

Parameters
packetthe packet from which to extract the values

References agc_max, agc_mean, agc_min, bit_errors, power, and rssi.

◆ receivingData()

void UwAhoiModem::receivingData ( )
privatevirtual

Mehod that detach a thread devoted to receiving data from the connector.

References UwModem::data_buffer, UwModem::DATA_BUFFER_LEN, UwModem::DEBUG, UwModem::ERROR, UwModem::MAX_READ_BYTES, p_connector, p_interpreter, UwModem::printOnLog(), receiving, and updateStatus().

Referenced by start().

Here is the call graph for this function:

◆ recv()

void UwAhoiModem::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(), UwModem::getModulationType(), UwModem::printOnLog(), startRx(), UwModem::tx_queue, tx_queue_cv, and tx_queue_m.

Here is the call graph for this function:

◆ recvSyncClMsg()

int UwAhoiModem::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.

◆ start()

void UwAhoiModem::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 baud_rate, UwModem::CheckTimer, UwModem::checkTimer, UwModem::ERROR, flow_control, UwModem::INFO, UwModem::modem_address, p_connector, parity_bit, UwModem::period, UwModem::printOnLog(), receiving, receivingData(), rx_thread, stop_bit, transmitting, transmittingData(), and tx_thread.

Here is the call graph for this function:

◆ startRx()

void UwAhoiModem::startRx ( Packet *  p)
privatevirtual

Method that starts a packet reception. This method is also in charge of sending a ClMsg, 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 UwAhoiModem::startTx ( Packet *  p)
privatevirtual

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

Parameters
pPacket pointer to the packet to be sent

Implements UwModem.

References UwModem::DEBUG, UwModem::ERROR, fillAhoiPkt(), MAX_RETX, p_connector, p_interpreter, UwModem::printOnLog(), TX_IDLE, tx_status, tx_status_cv, tx_status_m, TX_WAITING, WAIT_DELIVERY, and WAIT_DELIVERY_INT.

Referenced by transmittingData().

Here is the call graph for this function:

◆ stop()

void UwAhoiModem::stop ( )
privatevirtual

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

Implements UwModem.

References UwModem::checkTimer, UwModem::ERROR, UwModem::INFO, p_connector, UwModem::printOnLog(), receiving, rx_thread, transmitting, tx_queue_cv, and tx_thread.

Referenced by ~UwAhoiModem().

Here is the call graph for this function:

◆ storePacketInfo()

bool UwAhoiModem::storePacketInfo ( std::shared_ptr< ahoi::packet_t >  header,
Packet *  p 
)
private

Method that extarcts fields from a provided ahoi! packet and save the info values to class field for later access. Info parameters include values such as received power, RSSI, number of corrupted packets, ecc...

Parameters
headerahoi header the packet from which to extract the values
pns2 packet in which to save the destination address, ecc...

References agc_max, agc_mean, agc_min, bit_errors, UwModem::INFO, power, UwModem::printOnLog(), rssi, rx_payload, and hdr_uwal::srcID().

Referenced by updateStatus().

Here is the call graph for this function:

◆ transmittingData()

void UwAhoiModem::transmittingData ( )
privatevirtual

Method that detach a thread devoted to sending packets found in tx_queue.

References AVAILABLE, UwModem::DEBUG, UwModem::ERROR, UwModem::event_q, MODEM_TIMEOUT, UwModem::printOnLog(), UwModem::realTxEnded(), startTx(), status, status_cv, status_m, TRANSMITTING, transmitting, UwModem::tx_queue, tx_queue_cv, tx_queue_m, and updateSN().

Referenced by start().

Here is the call graph for this function:

◆ updateSN()

void UwAhoiModem::updateSN ( )
private

Method for Sequence Number (SN) update

References UwModem::ERROR, UwModem::printOnLog(), and sn.

Referenced by transmittingData().

Here is the call graph for this function:

◆ updateStatus()

void UwAhoiModem::updateStatus ( std::shared_ptr< ahoi::packet_t >  packet)
private

Method that updates the status of the modem State Machine: state change is triggered by recepting the response packet from the ahoi! modem on the connector interface.

Parameters
packetpacket received on the connector interface

References AVAILABLE, ahoi::commands_id, ahoi::confirm, createRxPacket(), UwModem::DEBUG, UwModem::ERROR, UwModem::event_q, UwModem::modemID, p_interpreter, UwModem::printOnLog(), UwModem::recv(), ahoi::send, sn, status, status_cv, status_m, storePacketInfo(), TX_IDLE, tx_status, tx_status_cv, and tx_status_m.

Referenced by receivingData().

Here is the call graph for this function:

Member Data Documentation

◆ agc_max

uint UwAhoiModem::agc_max
private

Maximum gain set by the AGC (if used) in reception of the last packet

Referenced by parseFooter(), and storePacketInfo().

◆ agc_mean

uint UwAhoiModem::agc_mean
private

Mean gain set by the AGC (if used) in reception of the last packet

Referenced by parseFooter(), and storePacketInfo().

◆ agc_min

uint UwAhoiModem::agc_min
private

Minimum gain set by the AGC (if used) in reception of the last packet

Referenced by parseFooter(), and storePacketInfo().

◆ baud_rate

int UwAhoiModem::baud_rate
private

Integer for port baud rate

Referenced by start(), and UwAhoiModem().

◆ bit_errors

uint UwAhoiModem::bit_errors
private

Number of repaired bit errors during reception in the last packet

Referenced by parseFooter(), and storePacketInfo().

◆ EPSILON_S

const double UwAhoiModem::EPSILON_S
staticprivate

minimum time to wait before to schedule a new event in seconds

◆ flow_control

int UwAhoiModem::flow_control
private

flag for flow control

Referenced by start(), and UwAhoiModem().

◆ id

uint UwAhoiModem::id
private

Modem ID, to be set in simulation

◆ MAX_RETX

uint UwAhoiModem::MAX_RETX = 0
staticprivate

Maximum number of retransmissions for the same packet

Referenced by startTx(), and UwAhoiModem().

◆ MODEM_TIMEOUT

const std::chrono::milliseconds UwAhoiModem::MODEM_TIMEOUT
staticprivate
Initial value:
=
std::chrono::milliseconds(3600)

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

Referenced by transmittingData().

◆ p_connector

std::unique_ptr<UwConnector> UwAhoiModem::p_connector
private

Pointer to Connector object that interfaces with the device

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

◆ p_interpreter

std::unique_ptr<UwInterpreterAhoi> UwAhoiModem::p_interpreter
private

Pointer to Interpreter object to parse device syntax

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

◆ parity_bit

int UwAhoiModem::parity_bit
private

flag for parity bit

Referenced by start(), and UwAhoiModem().

◆ power

uint UwAhoiModem::power
private

Received power (RMSE) ratio and "ideal packet". Above 100 = clipping

Referenced by parseFooter(), and storePacketInfo().

◆ receiving

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

Atomic boolean variable that controls the receiving looping thread

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

◆ rssi

uint UwAhoiModem::rssi
private

RSSI vs an "ideal packet". Above 100 = clipping

Referenced by parseFooter(), and storePacketInfo().

◆ rx_payload

std::string UwAhoiModem::rx_payload
private

String that is updated witn each new received messsage

Referenced by createRxPacket(), and storePacketInfo().

◆ rx_thread

std::thread UwAhoiModem::rx_thread
private

Object with the rx thread

Referenced by start(), and stop().

◆ sn

uint8_t UwAhoiModem::sn = 0
staticprivate

Sequence number, which follows all the packets transmitted to the modem.

Referenced by fillAhoiPkt(), updateSN(), and updateStatus().

◆ status

ModemState UwAhoiModem::status
private

Variable holding the current status of the modem

Referenced by transmittingData(), and updateStatus().

◆ status_cv

std::condition_variable UwAhoiModem::status_cv
private

Condition variable to wait for ModemState::AVAILABLE

Referenced by transmittingData(), and updateStatus().

◆ status_m

std::mutex UwAhoiModem::status_m
private

Mutex associated with the state machine of the modem

Referenced by transmittingData(), and updateStatus().

◆ stop_bit

int UwAhoiModem::stop_bit
private

flag for stop bit

Referenced by start(), and UwAhoiModem().

◆ tmpPacket

ahoi::packet_t UwAhoiModem::tmpPacket
private

Packet to be checked to unlock state machine

◆ transmitting

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

Atomic boolean variable that controls the transmitting looping thread

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

◆ tx_queue_cv

std::condition_variable UwAhoiModem::tx_queue_cv
private

Condition variable that is linked with the transmitting queue

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

◆ tx_queue_m

std::mutex UwAhoiModem::tx_queue_m
private

Mutex associated with the transmission queue

Referenced by recv(), and transmittingData().

◆ tx_status

TransmissionState UwAhoiModem::tx_status
private

Variable holding the current transmission status of the modem

Referenced by startTx(), and updateStatus().

◆ tx_status_cv

std::condition_variable UwAhoiModem::tx_status_cv
private

Condition variable to wait for TransmissionState::TX_IDLE

Referenced by startTx(), and updateStatus().

◆ tx_status_m

std::mutex UwAhoiModem::tx_status_m
private

Mutex associated with the state machine of the transmission process

Referenced by startTx(), and updateStatus().

◆ tx_thread

std::thread UwAhoiModem::tx_thread
private

Object with the tx thread

Referenced by start(), and stop().

◆ virtual_time_ref

double UwAhoiModem::virtual_time_ref
private

virtual time reference

◆ WAIT_DELIVERY

std::chrono::milliseconds UwAhoiModem::WAIT_DELIVERY
private

Time interval to wait for the modem notifying the response of a given packet

Referenced by startTx().

◆ WAIT_DELIVERY_INT

uint UwAhoiModem::WAIT_DELIVERY_INT = 3000
staticprivate

Time interval matching the WAIT_DELIVERY variable: version of type int to match the chrono one, needed because TclObject::bind does not support binding std::chrono variable [milliseconds]

Referenced by startTx(), and UwAhoiModem().


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