|
|
| 120 |
WifiRadioEnergyModel::GetTotalEnergyConsumption (void) const |
120 |
WifiRadioEnergyModel::GetTotalEnergyConsumption (void) const |
| 121 |
{ |
121 |
{ |
| 122 |
NS_LOG_FUNCTION (this); |
122 |
NS_LOG_FUNCTION (this); |
| 123 |
return m_totalEnergyConsumption; |
123 |
|
|
|
124 |
Time duration = Simulator::Now () - m_lastUpdateTime; |
| 125 |
NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid |
| 126 |
|
| 127 |
// energy to decrease = current * voltage * time |
| 128 |
double energyToDecrease = 0.0; |
| 129 |
double supplyVoltage = m_source->GetSupplyVoltage (); |
| 130 |
switch (m_currentState) |
| 131 |
{ |
| 132 |
case WifiPhy::IDLE: |
| 133 |
energyToDecrease = duration.GetSeconds () * m_idleCurrentA * supplyVoltage; |
| 134 |
break; |
| 135 |
case WifiPhy::CCA_BUSY: |
| 136 |
energyToDecrease = duration.GetSeconds () * m_ccaBusyCurrentA * supplyVoltage; |
| 137 |
break; |
| 138 |
case WifiPhy::TX: |
| 139 |
energyToDecrease = duration.GetSeconds () * m_txCurrentA * supplyVoltage; |
| 140 |
break; |
| 141 |
case WifiPhy::RX: |
| 142 |
energyToDecrease = duration.GetSeconds () * m_rxCurrentA * supplyVoltage; |
| 143 |
break; |
| 144 |
case WifiPhy::SWITCHING: |
| 145 |
energyToDecrease = duration.GetSeconds () * m_switchingCurrentA * supplyVoltage; |
| 146 |
break; |
| 147 |
case WifiPhy::SLEEP: |
| 148 |
energyToDecrease = duration.GetSeconds () * m_sleepCurrentA * supplyVoltage; |
| 149 |
break; |
| 150 |
default: |
| 151 |
NS_FATAL_ERROR ("WifiRadioEnergyModel:Undefined radio state: " << m_currentState); |
| 152 |
} |
| 153 |
|
| 154 |
// notify energy source |
| 155 |
m_source->UpdateEnergySource (); |
| 156 |
|
| 157 |
return m_totalEnergyConsumption + energyToDecrease; |
| 124 |
} |
158 |
} |
| 125 |
|
159 |
|
| 126 |
double |
160 |
double |