DESERT 3.5.1
Loading...
Searching...
No Matches
mS2C_Evo_lowlev.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2016 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
36#include "mS2C_Evo_lowlev.h"
37
42static class MS2C_Evo_lowlev_TclClass : public TclClass
43{
44 // Variable to read the path to the device
45 std::string pToDevice_;
46
47public:
49 : TclClass("Module/UW/MPhy_modem/S2CLowLevel")
50 {
51 }
52
53 TclObject *
54 create(int args, const char *const *argv)
55 {
56 pToDevice_ = (std::string) argv[4];
57 return (new MS2C_Evo_lowlev(pToDevice_));
58 }
59
61
62MS2C_Evo_lowlev::MS2C_Evo_lowlev(std::string pToDevice_)
63 : UWMPhy_modem(pToDevice_)
64 , checkTmr(this)
65 , mDriver(this)
66 , dropTmr(this)
67{
68
70 // Two steps configurations
71 bind("bitrate_index", (int *) &bitrate_i);
72 bind("SL", (int *) &SL);
73 bind("msg_bitlength", (int *) &msg_bitlen);
77}
78
82
83int
85{
86 return MPhy::recvSyncClMsg(m);
87}
88
91{
92 modem_state_t modemStatus_old = pmDriver->getStatus();
93 modem_state_t modemStatus = pmDriver->updateStatus();
94 std::stringstream sstr("");
95 string strlog;
96 sstr << "CHECK_MODEM::TRANSITION_FROM_" << modemStatus_old << "_TO_"
97 << modemStatus;
98 sstr >> strlog;
99 pmDriver->printOnLog(LOG_LEVEL_INFO, "UWMPHY_MODEM", strlog);
100
101 if (modemStatus == MODEM_IDLE && modemStatus_old == MODEM_TX) {
102 endTx(popTxBuff());
103 } else if (modemStatus == MODEM_RX && modemStatus_old == MODEM_IDLE)
104 startRx(PktRx);
105
106 else if (modemStatus == MODEM_IDLE_RX && modemStatus_old == MODEM_RX)
107 endRx(PktRx);
108
109 else if (modemStatus == MODEM_IDLE_RX && modemStatus_old == MODEM_TX_RX) {
110 endTx(popTxBuff());
111 startRx(PktRx);
112 endRx(PktRx);
113 }
114
115 return modemStatus;
116}
Class to create the Otcl shadow object for an object of the class MS2C_Evo_lowlev.
TclObject * create(int args, const char *const *argv)
Class that implements the interface between ns2/NS-Miracle and the S2C EvoLogics modem using low leve...
MdriverS2C_Evo_lowlev mDriver
Object which drives the modem operations.
virtual int recvSyncClMsg(ClMessage *m)
Receive Sync CrossLayer Messages.
~MS2C_Evo_lowlev()
Class destructor.
DropTimer dropTmr
Object which sets the modem queue to reset status.
MS2C_Evo_lowlev(std::string)
Class constructor.
CheckTimer checkTmr
Object which schedules the check-modem events.
virtual modem_state_t check_modem()
Check the state of the modem and update its status.
void setBitrate(int index)
Method to set the bitrate that will be sent to the modem config.
void setPktBitLen(int bitlen)
Method to set the msg bitlength that will be received by rx.
void setSourceLevel(int level)
Method to set the source level that will be sent to the modem config.
The main class implementing the module used to implement the interface between ns2/NS-Miracle and rea...
Packet * popTxBuff()
Method to pop the oldest packet in the TX buffer or to delete after a tx or to drop it.
virtual void startRx(Packet *)
Method to start a packet reception.
UWMdriver * pmDriver
Pointer to an object to drive the modem operations.
Packet * PktRx
Transmission buffer's index; it must be in {-1, 0, 1, ..., _MTBL-1}.
virtual void endRx(Packet *)
Method to end a packet reception.
virtual void endTx(Packet *)
Method to end a packet transmission.
void setConnections(CheckTimer *, UWMdriver *, DropTimer *)
Link connector.
modem_state_t getStatus()
Method to return the modem's status.
void printOnLog(log_level_t log_level, std::string module, std::string message)
virtual modem_state_t updateStatus()=0
Method to update modem status.
MS2C_Evo_lowlev_TclClass class_module_s2cevologics
Header of the main class that implements the general interface between ns2/NS-Miracle and the S2C Evo...