Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(500)

Unified Diff: src/energy/model/basic-energy-source.cc

Issue 332610043: Stop wifi transmissions and receptions when energy is depleted
Patch Set: First proposal Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/energy/model/device-energy-model.h » ('j') | src/wifi/model/wifi-phy.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/energy/model/basic-energy-source.cc
===================================================================
--- a/src/energy/model/basic-energy-source.cc
+++ b/src/energy/model/basic-energy-source.cc
@@ -162,6 +162,7 @@
m_energyUpdateEvent.Cancel ();
+ double remainingEnergy = m_remainingEnergyJ;
CalculateRemainingEnergy ();
m_lastUpdateTime = Simulator::Now ();
@@ -171,12 +172,15 @@
m_depleted = true;
HandleEnergyDrainedEvent ();
}
-
- if (m_depleted && m_remainingEnergyJ > m_highBatteryTh * m_initialEnergyJ)
+ else if (m_depleted && m_remainingEnergyJ > m_highBatteryTh * m_initialEnergyJ)
{
m_depleted = false;
HandleEnergyRechargedEvent ();
}
+ else if (m_remainingEnergyJ != remainingEnergy)
+ {
+ NotifyEnergyChanged ();
+ }
m_energyUpdateEvent = Simulator::Schedule (m_energyUpdateInterval,
&BasicEnergySource::UpdateEnergySource,
@@ -223,19 +227,11 @@
NS_LOG_FUNCTION (this);
double totalCurrentA = CalculateTotalCurrent ();
Time duration = Simulator::Now () - m_lastUpdateTime;
- NS_ASSERT (duration.GetSeconds () >= 0);
+ NS_ASSERT (duration.IsPositive ());
// energy = current * voltage * time
- double energyToDecreaseJ = totalCurrentA * m_supplyVoltageV * duration.GetSeconds ();
-
- if (m_remainingEnergyJ < energyToDecreaseJ)
- {
- m_remainingEnergyJ = 0; // energy never goes below 0
- }
- else
- {
- m_remainingEnergyJ -= energyToDecreaseJ;
- }
-
+ double energyToDecreaseJ = (totalCurrentA * m_supplyVoltageV * duration.GetNanoSeconds ()) / 1e9;
+ NS_ASSERT (m_remainingEnergyJ >= energyToDecreaseJ);
+ m_remainingEnergyJ -= energyToDecreaseJ;
NS_LOG_DEBUG ("BasicEnergySource:Remaining energy = " << m_remainingEnergyJ);
}
« no previous file with comments | « no previous file | src/energy/model/device-energy-model.h » ('j') | src/wifi/model/wifi-phy.cc » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b