45#include <underwater-mpropagation.h>
70 : TclClass(
"Module/MPhy/Underwater/WKUP")
96 : PacketHeaderClass(
"PacketHeader/WKUP", sizeof(
hdr_wkup))
109 , droppedPktsTxPending(0)
128 Tcl &tcl = Tcl::instance();
131 if (strcasecmp(argv[1],
"getDroppedPktsTxPending") == 0) {
136 return (MPhy::command(argc, argv));
149 hdr_MPhy *ph = HDR_MPHY(p);
151 assert(propagation_);
157 double freq = ph->srcSpectralMask->getFreq();
158 double bw = ph->srcSpectralMask->getBandwidth();
166 UnderwaterMPropagation *uwmp =
167 dynamic_cast<UnderwaterMPropagation *
>(propagation_);
169 double noiseSPDdBperHz = uwmp->uw.getNoise(freq / 1000.0);
170 double noisepow = bw * pow(10, noiseSPDdBperHz / 10.0);
178 return spectralmask_;
185 cout << NOW <<
" MPhy_WakeUp::startTx() tx a TONE";
189 hdr_MPhy *ph = HDR_MPHY(
PktRx);
199 cout <<
", aborting ongoing rx at time = " << ph->rxtime;
220 hdr_MPhy *ph = HDR_MPHY(p);
221 double rx_time = ph->rxtime;
222 double tx_time = ph->txtime;
224 if (ph->modulationType ==
modid) {
226 double snr_dB = 10 * log10(ph->Pr / ph->Pn);
239 cout << NOW <<
" MPhy_WakeUp::startRx() rx a TONE" << endl;
249 cout << NOW <<
" MPhy_WakeUp::startRx() rx a TONE but "
265 hdr_MPhy *phrx = HDR_MPHY(
PktRx);
273 <<
" MPhy_WakeUp::startRx() rx a chain-synched TONE"
281 cout << NOW <<
" MPhy_WakeUp::startRx() rx a TONE but "
294 cout << NOW <<
" MPhy_WakeUp::startRx() rx a TONE but while tx"
306 cout << NOW <<
" MPhy_WakeUp::startRx() rx a PKT but wrong MODID"
318 hdr_cmn *ch = HDR_CMN(p);
319 hdr_MPhy *ph = HDR_MPHY(p);
321 if (ph->modulationType ==
modid) {
335 per_n =
getPER(ph->Pr / ph->Pn, nbits);
336 per_ni =
getPER(ph->Pr / (ph->Pn + ph->Pi), nbits);
340 double x = RNG::defaultrng()->uniform_double();
341 bool error_ni = x <= per_ni;
342 bool error_n = x <= per_n;
344 ch->error() = error_ni || error_n;
347 incrErrorPktsNoise();
348 }
else if (error_ni) {
349 incrErrorPktsInterf();
357 }
else if (
PktRx != 0) {
359 hdr_cmn *rxch = HDR_CMN(
PktRx);
361 if (ch->error() ==
false) {
362 double min_start_time =
364 double max_end_time =
468 double ber = 0.5 * erfc(sqrt(snr * 0.5));
469 double per = 1 - pow(1 - ber, nbits);
476 std::string response;
477 std::cout <<
"Press Enter to continue";
478 std::getline(std::cin, response);
Class that represents the binding with the tcl configuration script.
MPhy_WakeUpClass()
Constructor of the class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
Class that describes the WakeUp PHY layer for T-LOHI MAC protocol.
virtual double getTxDuration(Packet *p)
Returns the duration of the transmission for the specified packet.
virtual void endRx(Packet *p)
Notify to the MAC protocol that the reception is finished and send the packet to it.
virtual void endTx(Packet *p)
Notify to the MAC protocol that the transmission has been finished.
virtual ~MPhy_WakeUp()
Class destructor.
MPhy_WakeUp()
Class contructor.
Packet * PktRx
Pointer to the packeti in reception.
double MaxTxRange_
Maximum Transmission Range.
virtual void startRx(Packet *p)
Notify to the MAC protocol the start of a reception.
virtual double getPER(double snr, int nbits)
Returns the PER for a certain SNR and a dimension of packet.
virtual MSpectralMask * getTxSpectralMask(Packet *p)
Gets the Transmission Spectral Mask for the Packet p.
virtual void waitForUser()
Used for debug purposes.
virtual double getNoisePower(Packet *p)
Returns the Power of the noise for a packet.
virtual int getDroppedPktsTxPending()
Gets the number of Tx Pending dropped packets.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
static bool initialized
used to register the modulation type only once
double ToneDuration_
predefined tone duration
virtual void startTx(Packet *p)
Starts to transmit a Packet.
virtual int getModulationType(Packet *)
Returns the Modulation type.
static int modid
modulation type id
double AcquisitionThreshold_dB_
How many dB over noise are required for a signal to trigger acquisition (i.e., a RX attempt)
virtual void dropPacket(Packet *p)
Drops a packet.
Class that describes the PacketHeader for WakeUp Tone class.
WkUpPktClass()
Constructor of the class.
Header of the Wake Up Tone.
double startRx_time
Start Reception Time.
static int offset_
Required by PacketManagerHeader class.
double endRx_time
End Reception Time.
WkUpPktClass class_wkup_pkt
MPhy_WakeUpClass class_MPhy_WakeUp
@ WKUP_DROPPED_REASON_CHAIN_SYNC
@ WKUP_DROPPED_REASON_NOISE
@ WKUP_DROPPED_REASON_NOT_SET
@ WKUP_DROPPED_REASON_WRONG_MODID
@ WKUP_DROPPED_REASON_TX_PENDING
@ WKUP_DROPPED_REASON_DEAFNESS
Provides the declaration of WakeUp PHY.
#define UW_WAKEUP_MODNAME