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

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

Issue 57210044: Add support for Wifi SLEEP mode (Closed)
Patch Set: Add an EnergyRecharged callback Created 9 years, 8 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 | « src/energy/model/basic-energy-source.h ('k') | src/energy/model/device-energy-model.h » ('j') | no next file with comments »
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
@@ -54,6 +54,11 @@
DoubleValue (0.10), // as a fraction of the initial energy
MakeDoubleAccessor (&BasicEnergySource::m_lowBatteryTh),
MakeDoubleChecker<double> ())
+ .AddAttribute ("BasicEnergyHighBatteryThreshold",
+ "High battery threshold for basic energy source.",
+ DoubleValue (0.15), // as a fraction of the initial energy
+ MakeDoubleAccessor (&BasicEnergySource::m_highBatteryTh),
+ MakeDoubleChecker<double> ())
.AddAttribute ("PeriodicEnergyUpdateInterval",
"Time between two consecutive periodic energy updates.",
TimeValue (Seconds (1.0)),
@@ -71,6 +76,7 @@
{
NS_LOG_FUNCTION (this);
m_lastUpdateTime = Seconds (0.0);
+ m_depleted = false;
}
BasicEnergySource::~BasicEnergySource ()
@@ -158,10 +164,17 @@
m_lastUpdateTime = Simulator::Now ();
- if (m_remainingEnergyJ <= m_lowBatteryTh * m_initialEnergyJ)
+ if (!m_depleted && m_remainingEnergyJ <= m_lowBatteryTh * m_initialEnergyJ)
{
+ m_depleted = true;
HandleEnergyDrainedEvent ();
- return; // stop periodic update
+// return; // stop periodic update
+ }
+
+ if (m_depleted && m_remainingEnergyJ >= m_highBatteryTh * m_initialEnergyJ)
+ {
+ m_depleted = false;
+ HandleEnergyRechargedEvent ();
}
m_energyUpdateEvent = Simulator::Schedule (m_energyUpdateInterval,
@@ -200,6 +213,14 @@
}
void
+BasicEnergySource::HandleEnergyRechargedEvent (void)
+{
+ NS_LOG_FUNCTION (this);
+ NS_LOG_DEBUG ("BasicEnergySource:Energy recharged!");
+ NotifyEnergyRecharged (); // notify DeviceEnergyModel objects
+}
+
+void
BasicEnergySource::CalculateRemainingEnergy (void)
{
NS_LOG_FUNCTION (this);
« no previous file with comments | « src/energy/model/basic-energy-source.h ('k') | src/energy/model/device-energy-model.h » ('j') | no next file with comments »

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