|
|
|
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle. |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License version 2 as |
| 7 |
* published by the Free Software Foundation; |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
* |
| 18 |
* Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "ns3/log.h" |
| 22 |
#include "ns3/double.h" |
| 23 |
#include "ns3/simulator.h" |
| 24 |
#include "ns3/trace-source-accessor.h" |
| 25 |
#include "ns3/pointer.h" |
| 26 |
#include "ns3/energy-source.h" |
| 27 |
#include "wifi-radio-energy-model.h" |
| 28 |
#include "wifi-tx-current-model.h" |
| 29 |
|
| 30 |
namespace ns3 { |
| 31 |
|
| 32 |
NS_LOG_COMPONENT_DEFINE ("WifiRadioEnergyModel"); |
| 33 |
|
| 34 |
NS_OBJECT_ENSURE_REGISTERED (WifiRadioEnergyModel); |
| 35 |
|
| 36 |
TypeId |
| 37 |
WifiRadioEnergyModel::GetTypeId (void) |
| 38 |
{ |
| 39 |
static TypeId tid = TypeId ("ns3::WifiRadioEnergyModel") |
| 40 |
.SetParent<DeviceEnergyModel> () |
| 41 |
.SetGroupName ("Energy") |
| 42 |
.AddConstructor<WifiRadioEnergyModel> () |
| 43 |
.AddAttribute ("IdleCurrentA", |
| 44 |
"The default radio Idle current in Ampere.", |
| 45 |
DoubleValue (0.273), // idle mode = 273mA |
| 46 |
MakeDoubleAccessor (&WifiRadioEnergyModel::SetIdleCurrentA, |
| 47 |
&WifiRadioEnergyModel::GetIdleCurrentA), |
| 48 |
MakeDoubleChecker<double> ()) |
| 49 |
.AddAttribute ("CcaBusyCurrentA", |
| 50 |
"The default radio CCA Busy State current in Ampere.", |
| 51 |
DoubleValue (0.273), // default to be the same as idle mode |
| 52 |
MakeDoubleAccessor (&WifiRadioEnergyModel::SetCcaBusyCurrentA, |
| 53 |
&WifiRadioEnergyModel::GetCcaBusyCurrentA), |
| 54 |
MakeDoubleChecker<double> ()) |
| 55 |
.AddAttribute ("TxCurrentA", |
| 56 |
"The radio Tx current in Ampere.", |
| 57 |
DoubleValue (0.380), // transmit at 0dBm = 380mA |
| 58 |
MakeDoubleAccessor (&WifiRadioEnergyModel::SetTxCurrentA, |
| 59 |
&WifiRadioEnergyModel::GetTxCurrentA), |
| 60 |
MakeDoubleChecker<double> ()) |
| 61 |
.AddAttribute ("RxCurrentA", |
| 62 |
"The radio Rx current in Ampere.", |
| 63 |
DoubleValue (0.313), // receive mode = 313mA |
| 64 |
MakeDoubleAccessor (&WifiRadioEnergyModel::SetRxCurrentA, |
| 65 |
&WifiRadioEnergyModel::GetRxCurrentA), |
| 66 |
MakeDoubleChecker<double> ()) |
| 67 |
.AddAttribute ("SwitchingCurrentA", |
| 68 |
"The default radio Channel Switch current in Ampere.", |
| 69 |
DoubleValue (0.273), // default to be the same as idle mode |
| 70 |
MakeDoubleAccessor (&WifiRadioEnergyModel::SetSwitchingCurrentA, |
| 71 |
&WifiRadioEnergyModel::GetSwitchingCurrentA), |
| 72 |
MakeDoubleChecker<double> ()) |
| 73 |
.AddAttribute ("SleepCurrentA", |
| 74 |
"The radio Sleep current in Ampere.", |
| 75 |
DoubleValue (0.033), // sleep mode = 33mA |
| 76 |
MakeDoubleAccessor (&WifiRadioEnergyModel::SetSleepCurrentA, |
| 77 |
&WifiRadioEnergyModel::GetSleepCurrentA), |
| 78 |
MakeDoubleChecker<double> ()) |
| 79 |
.AddAttribute ("TxCurrentModel", "A pointer to the attached tx current model.", |
| 80 |
PointerValue (), |
| 81 |
MakePointerAccessor (&WifiRadioEnergyModel::m_txCurrentModel), |
| 82 |
MakePointerChecker<WifiTxCurrentModel> ()) |
| 83 |
.AddTraceSource ("TotalEnergyConsumption", |
| 84 |
"Total energy consumption of the radio device.", |
| 85 |
MakeTraceSourceAccessor (&WifiRadioEnergyModel::m_totalEnergyConsumption), |
| 86 |
"ns3::TracedValue::DoubleCallback") |
| 87 |
; |
| 88 |
return tid; |
| 89 |
} |
| 90 |
|
| 91 |
WifiRadioEnergyModel::WifiRadioEnergyModel () |
| 92 |
{ |
| 93 |
NS_LOG_FUNCTION (this); |
| 94 |
m_currentState = WifiPhy::IDLE; // initially IDLE |
| 95 |
m_lastUpdateTime = Seconds (0.0); |
| 96 |
m_nPendingChangeState = 0; |
| 97 |
m_isSupersededChangeState = false; |
| 98 |
m_energyDepletionCallback.Nullify (); |
| 99 |
m_source = NULL; |
| 100 |
// set callback for WifiPhy listener |
| 101 |
m_listener = new WifiRadioEnergyModelPhyListener; |
| 102 |
m_listener->SetChangeStateCallback (MakeCallback (&DeviceEnergyModel::ChangeState, this)); |
| 103 |
// set callback for updating the tx current |
| 104 |
m_listener->SetUpdateTxCurrentCallback (MakeCallback (&WifiRadioEnergyModel::SetTxCurrentFromModel, this)); |
| 105 |
} |
| 106 |
|
| 107 |
WifiRadioEnergyModel::~WifiRadioEnergyModel () |
| 108 |
{ |
| 109 |
NS_LOG_FUNCTION (this); |
| 110 |
delete m_listener; |
| 111 |
} |
| 112 |
|
| 113 |
void |
| 114 |
WifiRadioEnergyModel::SetEnergySource (Ptr<EnergySource> source) |
| 115 |
{ |
| 116 |
NS_LOG_FUNCTION (this << source); |
| 117 |
NS_ASSERT (source != NULL); |
| 118 |
m_source = source; |
| 119 |
} |
| 120 |
|
| 121 |
double |
| 122 |
WifiRadioEnergyModel::GetTotalEnergyConsumption (void) const |
| 123 |
{ |
| 124 |
NS_LOG_FUNCTION (this); |
| 125 |
return m_totalEnergyConsumption; |
| 126 |
} |
| 127 |
|
| 128 |
double |
| 129 |
WifiRadioEnergyModel::GetIdleCurrentA (void) const |
| 130 |
{ |
| 131 |
NS_LOG_FUNCTION (this); |
| 132 |
return m_idleCurrentA; |
| 133 |
} |
| 134 |
|
| 135 |
void |
| 136 |
WifiRadioEnergyModel::SetIdleCurrentA (double idleCurrentA) |
| 137 |
{ |
| 138 |
NS_LOG_FUNCTION (this << idleCurrentA); |
| 139 |
m_idleCurrentA = idleCurrentA; |
| 140 |
} |
| 141 |
|
| 142 |
double |
| 143 |
WifiRadioEnergyModel::GetCcaBusyCurrentA (void) const |
| 144 |
{ |
| 145 |
NS_LOG_FUNCTION (this); |
| 146 |
return m_ccaBusyCurrentA; |
| 147 |
} |
| 148 |
|
| 149 |
void |
| 150 |
WifiRadioEnergyModel::SetCcaBusyCurrentA (double CcaBusyCurrentA) |
| 151 |
{ |
| 152 |
NS_LOG_FUNCTION (this << CcaBusyCurrentA); |
| 153 |
m_ccaBusyCurrentA = CcaBusyCurrentA; |
| 154 |
} |
| 155 |
|
| 156 |
double |
| 157 |
WifiRadioEnergyModel::GetTxCurrentA (void) const |
| 158 |
{ |
| 159 |
NS_LOG_FUNCTION (this); |
| 160 |
return m_txCurrentA; |
| 161 |
} |
| 162 |
|
| 163 |
void |
| 164 |
WifiRadioEnergyModel::SetTxCurrentA (double txCurrentA) |
| 165 |
{ |
| 166 |
NS_LOG_FUNCTION (this << txCurrentA); |
| 167 |
m_txCurrentA = txCurrentA; |
| 168 |
} |
| 169 |
|
| 170 |
double |
| 171 |
WifiRadioEnergyModel::GetRxCurrentA (void) const |
| 172 |
{ |
| 173 |
NS_LOG_FUNCTION (this); |
| 174 |
return m_rxCurrentA; |
| 175 |
} |
| 176 |
|
| 177 |
void |
| 178 |
WifiRadioEnergyModel::SetRxCurrentA (double rxCurrentA) |
| 179 |
{ |
| 180 |
NS_LOG_FUNCTION (this << rxCurrentA); |
| 181 |
m_rxCurrentA = rxCurrentA; |
| 182 |
} |
| 183 |
|
| 184 |
double |
| 185 |
WifiRadioEnergyModel::GetSwitchingCurrentA (void) const |
| 186 |
{ |
| 187 |
NS_LOG_FUNCTION (this); |
| 188 |
return m_switchingCurrentA; |
| 189 |
} |
| 190 |
|
| 191 |
void |
| 192 |
WifiRadioEnergyModel::SetSwitchingCurrentA (double switchingCurrentA) |
| 193 |
{ |
| 194 |
NS_LOG_FUNCTION (this << switchingCurrentA); |
| 195 |
m_switchingCurrentA = switchingCurrentA; |
| 196 |
} |
| 197 |
|
| 198 |
double |
| 199 |
WifiRadioEnergyModel::GetSleepCurrentA (void) const |
| 200 |
{ |
| 201 |
NS_LOG_FUNCTION (this); |
| 202 |
return m_sleepCurrentA; |
| 203 |
} |
| 204 |
|
| 205 |
void |
| 206 |
WifiRadioEnergyModel::SetSleepCurrentA (double sleepCurrentA) |
| 207 |
{ |
| 208 |
NS_LOG_FUNCTION (this << sleepCurrentA); |
| 209 |
m_sleepCurrentA = sleepCurrentA; |
| 210 |
} |
| 211 |
|
| 212 |
WifiPhy::State |
| 213 |
WifiRadioEnergyModel::GetCurrentState (void) const |
| 214 |
{ |
| 215 |
NS_LOG_FUNCTION (this); |
| 216 |
return m_currentState; |
| 217 |
} |
| 218 |
|
| 219 |
void |
| 220 |
WifiRadioEnergyModel::SetEnergyDepletionCallback ( |
| 221 |
WifiRadioEnergyDepletionCallback callback) |
| 222 |
{ |
| 223 |
NS_LOG_FUNCTION (this); |
| 224 |
if (callback.IsNull ()) |
| 225 |
{ |
| 226 |
NS_LOG_DEBUG ("WifiRadioEnergyModel:Setting NULL energy depletion callback!"); |
| 227 |
} |
| 228 |
m_energyDepletionCallback = callback; |
| 229 |
} |
| 230 |
|
| 231 |
void |
| 232 |
WifiRadioEnergyModel::SetEnergyRechargedCallback ( |
| 233 |
WifiRadioEnergyRechargedCallback callback) |
| 234 |
{ |
| 235 |
NS_LOG_FUNCTION (this); |
| 236 |
if (callback.IsNull ()) |
| 237 |
{ |
| 238 |
NS_LOG_DEBUG ("WifiRadioEnergyModel:Setting NULL energy recharged callback!"); |
| 239 |
} |
| 240 |
m_energyRechargedCallback = callback; |
| 241 |
} |
| 242 |
|
| 243 |
void |
| 244 |
WifiRadioEnergyModel::SetTxCurrentModel (Ptr<WifiTxCurrentModel> model) |
| 245 |
{ |
| 246 |
m_txCurrentModel = model; |
| 247 |
} |
| 248 |
|
| 249 |
void |
| 250 |
WifiRadioEnergyModel::SetTxCurrentFromModel (double txPowerDbm) |
| 251 |
{ |
| 252 |
if (m_txCurrentModel) |
| 253 |
{ |
| 254 |
m_txCurrentA = m_txCurrentModel->CalcTxCurrent (txPowerDbm); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
void |
| 259 |
WifiRadioEnergyModel::ChangeState (int newState) |
| 260 |
{ |
| 261 |
NS_LOG_FUNCTION (this << newState); |
| 262 |
|
| 263 |
Time duration = Simulator::Now () - m_lastUpdateTime; |
| 264 |
NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid |
| 265 |
|
| 266 |
// energy to decrease = current * voltage * time |
| 267 |
double energyToDecrease = 0.0; |
| 268 |
double supplyVoltage = m_source->GetSupplyVoltage (); |
| 269 |
switch (m_currentState) |
| 270 |
{ |
| 271 |
case WifiPhy::IDLE: |
| 272 |
energyToDecrease = duration.GetSeconds () * m_idleCurrentA * supplyVoltage; |
| 273 |
break; |
| 274 |
case WifiPhy::CCA_BUSY: |
| 275 |
energyToDecrease = duration.GetSeconds () * m_ccaBusyCurrentA * supplyVoltage; |
| 276 |
break; |
| 277 |
case WifiPhy::TX: |
| 278 |
energyToDecrease = duration.GetSeconds () * m_txCurrentA * supplyVoltage; |
| 279 |
break; |
| 280 |
case WifiPhy::RX: |
| 281 |
energyToDecrease = duration.GetSeconds () * m_rxCurrentA * supplyVoltage; |
| 282 |
break; |
| 283 |
case WifiPhy::SWITCHING: |
| 284 |
energyToDecrease = duration.GetSeconds () * m_switchingCurrentA * supplyVoltage; |
| 285 |
break; |
| 286 |
case WifiPhy::SLEEP: |
| 287 |
energyToDecrease = duration.GetSeconds () * m_sleepCurrentA * supplyVoltage; |
| 288 |
break; |
| 289 |
default: |
| 290 |
NS_FATAL_ERROR ("WifiRadioEnergyModel:Undefined radio state: " << m_currentState); |
| 291 |
} |
| 292 |
|
| 293 |
// update total energy consumption |
| 294 |
m_totalEnergyConsumption += energyToDecrease; |
| 295 |
|
| 296 |
// update last update time stamp |
| 297 |
m_lastUpdateTime = Simulator::Now (); |
| 298 |
|
| 299 |
m_nPendingChangeState++; |
| 300 |
|
| 301 |
// notify energy source |
| 302 |
m_source->UpdateEnergySource (); |
| 303 |
|
| 304 |
// in case the energy source is found to be depleted during the last update, a callback might be |
| 305 |
// invoked that might cause a change in the Wifi PHY state (e.g., the PHY is put into SLEEP mode). |
| 306 |
// This in turn causes a new call to this member function, with the consequence that the previous |
| 307 |
// instance is resumed after the termination of the new instance. In particular, the state set |
| 308 |
// by the previous instance is erroneously the final state stored in m_currentState. The check below |
| 309 |
// ensures that previous instances do not change m_currentState. |
| 310 |
|
| 311 |
if (!m_isSupersededChangeState) |
| 312 |
{ |
| 313 |
// update current state & last update time stamp |
| 314 |
SetWifiRadioState ((WifiPhy::State) newState); |
| 315 |
|
| 316 |
// some debug message |
| 317 |
NS_LOG_DEBUG ("WifiRadioEnergyModel:Total energy consumption is " << |
| 318 |
m_totalEnergyConsumption << "J"); |
| 319 |
} |
| 320 |
|
| 321 |
m_isSupersededChangeState = (m_nPendingChangeState > 1); |
| 322 |
|
| 323 |
m_nPendingChangeState--; |
| 324 |
} |
| 325 |
|
| 326 |
void |
| 327 |
WifiRadioEnergyModel::HandleEnergyDepletion (void) |
| 328 |
{ |
| 329 |
NS_LOG_FUNCTION (this); |
| 330 |
NS_LOG_DEBUG ("WifiRadioEnergyModel:Energy is depleted!"); |
| 331 |
// invoke energy depletion callback, if set. |
| 332 |
if (!m_energyDepletionCallback.IsNull ()) |
| 333 |
{ |
| 334 |
m_energyDepletionCallback (); |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
void |
| 339 |
WifiRadioEnergyModel::HandleEnergyRecharged (void) |
| 340 |
{ |
| 341 |
NS_LOG_FUNCTION (this); |
| 342 |
NS_LOG_DEBUG ("WifiRadioEnergyModel:Energy is recharged!"); |
| 343 |
// invoke energy recharged callback, if set. |
| 344 |
if (!m_energyRechargedCallback.IsNull ()) |
| 345 |
{ |
| 346 |
m_energyRechargedCallback (); |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
WifiRadioEnergyModelPhyListener * |
| 351 |
WifiRadioEnergyModel::GetPhyListener (void) |
| 352 |
{ |
| 353 |
NS_LOG_FUNCTION (this); |
| 354 |
return m_listener; |
| 355 |
} |
| 356 |
|
| 357 |
/* |
| 358 |
* Private functions start here. |
| 359 |
*/ |
| 360 |
|
| 361 |
void |
| 362 |
WifiRadioEnergyModel::DoDispose (void) |
| 363 |
{ |
| 364 |
NS_LOG_FUNCTION (this); |
| 365 |
m_source = NULL; |
| 366 |
m_energyDepletionCallback.Nullify (); |
| 367 |
} |
| 368 |
|
| 369 |
double |
| 370 |
WifiRadioEnergyModel::DoGetCurrentA (void) const |
| 371 |
{ |
| 372 |
NS_LOG_FUNCTION (this); |
| 373 |
switch (m_currentState) |
| 374 |
{ |
| 375 |
case WifiPhy::IDLE: |
| 376 |
return m_idleCurrentA; |
| 377 |
case WifiPhy::CCA_BUSY: |
| 378 |
return m_ccaBusyCurrentA; |
| 379 |
case WifiPhy::TX: |
| 380 |
return m_txCurrentA; |
| 381 |
case WifiPhy::RX: |
| 382 |
return m_rxCurrentA; |
| 383 |
case WifiPhy::SWITCHING: |
| 384 |
return m_switchingCurrentA; |
| 385 |
case WifiPhy::SLEEP: |
| 386 |
return m_sleepCurrentA; |
| 387 |
default: |
| 388 |
NS_FATAL_ERROR ("WifiRadioEnergyModel:Undefined radio state:" << m_currentState); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
void |
| 393 |
WifiRadioEnergyModel::SetWifiRadioState (const WifiPhy::State state) |
| 394 |
{ |
| 395 |
NS_LOG_FUNCTION (this << state); |
| 396 |
m_currentState = state; |
| 397 |
std::string stateName; |
| 398 |
switch (state) |
| 399 |
{ |
| 400 |
case WifiPhy::IDLE: |
| 401 |
stateName = "IDLE"; |
| 402 |
break; |
| 403 |
case WifiPhy::CCA_BUSY: |
| 404 |
stateName = "CCA_BUSY"; |
| 405 |
break; |
| 406 |
case WifiPhy::TX: |
| 407 |
stateName = "TX"; |
| 408 |
break; |
| 409 |
case WifiPhy::RX: |
| 410 |
stateName = "RX"; |
| 411 |
break; |
| 412 |
case WifiPhy::SWITCHING: |
| 413 |
stateName = "SWITCHING"; |
| 414 |
break; |
| 415 |
case WifiPhy::SLEEP: |
| 416 |
stateName = "SLEEP"; |
| 417 |
break; |
| 418 |
} |
| 419 |
NS_LOG_DEBUG ("WifiRadioEnergyModel:Switching to state: " << stateName << |
| 420 |
" at time = " << Simulator::Now ()); |
| 421 |
} |
| 422 |
|
| 423 |
// -------------------------------------------------------------------------- // |
| 424 |
|
| 425 |
WifiRadioEnergyModelPhyListener::WifiRadioEnergyModelPhyListener () |
| 426 |
{ |
| 427 |
NS_LOG_FUNCTION (this); |
| 428 |
m_changeStateCallback.Nullify (); |
| 429 |
m_updateTxCurrentCallback.Nullify (); |
| 430 |
} |
| 431 |
|
| 432 |
WifiRadioEnergyModelPhyListener::~WifiRadioEnergyModelPhyListener () |
| 433 |
{ |
| 434 |
NS_LOG_FUNCTION (this); |
| 435 |
} |
| 436 |
|
| 437 |
void |
| 438 |
WifiRadioEnergyModelPhyListener::SetChangeStateCallback (DeviceEnergyModel::ChangeStateCallback callback) |
| 439 |
{ |
| 440 |
NS_LOG_FUNCTION (this << &callback); |
| 441 |
NS_ASSERT (!callback.IsNull ()); |
| 442 |
m_changeStateCallback = callback; |
| 443 |
} |
| 444 |
|
| 445 |
void |
| 446 |
WifiRadioEnergyModelPhyListener::SetUpdateTxCurrentCallback (UpdateTxCurrentCallback callback) |
| 447 |
{ |
| 448 |
NS_LOG_FUNCTION (this << &callback); |
| 449 |
NS_ASSERT (!callback.IsNull ()); |
| 450 |
m_updateTxCurrentCallback = callback; |
| 451 |
} |
| 452 |
|
| 453 |
void |
| 454 |
WifiRadioEnergyModelPhyListener::NotifyRxStart (Time duration) |
| 455 |
{ |
| 456 |
NS_LOG_FUNCTION (this << duration); |
| 457 |
if (m_changeStateCallback.IsNull ()) |
| 458 |
{ |
| 459 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 460 |
} |
| 461 |
m_changeStateCallback (WifiPhy::RX); |
| 462 |
m_switchToIdleEvent.Cancel (); |
| 463 |
} |
| 464 |
|
| 465 |
void |
| 466 |
WifiRadioEnergyModelPhyListener::NotifyRxEndOk (void) |
| 467 |
{ |
| 468 |
NS_LOG_FUNCTION (this); |
| 469 |
if (m_changeStateCallback.IsNull ()) |
| 470 |
{ |
| 471 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 472 |
} |
| 473 |
m_changeStateCallback (WifiPhy::IDLE); |
| 474 |
} |
| 475 |
|
| 476 |
void |
| 477 |
WifiRadioEnergyModelPhyListener::NotifyRxEndError (void) |
| 478 |
{ |
| 479 |
NS_LOG_FUNCTION (this); |
| 480 |
if (m_changeStateCallback.IsNull ()) |
| 481 |
{ |
| 482 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 483 |
} |
| 484 |
m_changeStateCallback (WifiPhy::IDLE); |
| 485 |
} |
| 486 |
|
| 487 |
void |
| 488 |
WifiRadioEnergyModelPhyListener::NotifyTxStart (Time duration, double txPowerDbm) |
| 489 |
{ |
| 490 |
NS_LOG_FUNCTION (this << duration << txPowerDbm); |
| 491 |
if (m_updateTxCurrentCallback.IsNull ()) |
| 492 |
{ |
| 493 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Update tx current callback not set!"); |
| 494 |
} |
| 495 |
m_updateTxCurrentCallback (txPowerDbm); |
| 496 |
if (m_changeStateCallback.IsNull ()) |
| 497 |
{ |
| 498 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 499 |
} |
| 500 |
m_changeStateCallback (WifiPhy::TX); |
| 501 |
// schedule changing state back to IDLE after TX duration |
| 502 |
m_switchToIdleEvent.Cancel (); |
| 503 |
m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyListener::SwitchToIdle, this); |
| 504 |
} |
| 505 |
|
| 506 |
void |
| 507 |
WifiRadioEnergyModelPhyListener::NotifyMaybeCcaBusyStart (Time duration) |
| 508 |
{ |
| 509 |
NS_LOG_FUNCTION (this << duration); |
| 510 |
if (m_changeStateCallback.IsNull ()) |
| 511 |
{ |
| 512 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 513 |
} |
| 514 |
m_changeStateCallback (WifiPhy::CCA_BUSY); |
| 515 |
// schedule changing state back to IDLE after CCA_BUSY duration |
| 516 |
m_switchToIdleEvent.Cancel (); |
| 517 |
m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyListener::SwitchToIdle, this); |
| 518 |
} |
| 519 |
|
| 520 |
void |
| 521 |
WifiRadioEnergyModelPhyListener::NotifySwitchingStart (Time duration) |
| 522 |
{ |
| 523 |
NS_LOG_FUNCTION (this << duration); |
| 524 |
if (m_changeStateCallback.IsNull ()) |
| 525 |
{ |
| 526 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 527 |
} |
| 528 |
m_changeStateCallback (WifiPhy::SWITCHING); |
| 529 |
// schedule changing state back to IDLE after CCA_BUSY duration |
| 530 |
m_switchToIdleEvent.Cancel (); |
| 531 |
m_switchToIdleEvent = Simulator::Schedule (duration, &WifiRadioEnergyModelPhyListener::SwitchToIdle, this); |
| 532 |
} |
| 533 |
|
| 534 |
void |
| 535 |
WifiRadioEnergyModelPhyListener::NotifySleep (void) |
| 536 |
{ |
| 537 |
NS_LOG_FUNCTION (this); |
| 538 |
if (m_changeStateCallback.IsNull ()) |
| 539 |
{ |
| 540 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 541 |
} |
| 542 |
m_changeStateCallback (WifiPhy::SLEEP); |
| 543 |
m_switchToIdleEvent.Cancel (); |
| 544 |
} |
| 545 |
|
| 546 |
void |
| 547 |
WifiRadioEnergyModelPhyListener::NotifyWakeup(void) |
| 548 |
{ |
| 549 |
NS_LOG_FUNCTION (this); |
| 550 |
if (m_changeStateCallback.IsNull ()) |
| 551 |
{ |
| 552 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 553 |
} |
| 554 |
m_changeStateCallback (WifiPhy::IDLE); |
| 555 |
} |
| 556 |
|
| 557 |
/* |
| 558 |
* Private function state here. |
| 559 |
*/ |
| 560 |
|
| 561 |
void |
| 562 |
WifiRadioEnergyModelPhyListener::SwitchToIdle (void) |
| 563 |
{ |
| 564 |
NS_LOG_FUNCTION (this); |
| 565 |
if (m_changeStateCallback.IsNull ()) |
| 566 |
{ |
| 567 |
NS_FATAL_ERROR ("WifiRadioEnergyModelPhyListener:Change state callback not set!"); |
| 568 |
} |
| 569 |
m_changeStateCallback (WifiPhy::IDLE); |
| 570 |
} |
| 571 |
|
| 572 |
} // namespace ns3 |