diff --git a/src/contrib/energy/model/basic-energy-source.cc b/src/contrib/energy/model/basic-energy-source.cc index 13e9927da..b10242151 100644 --- a/src/contrib/energy/model/basic-energy-source.cc +++ b/src/contrib/energy/model/basic-energy-source.cc @@ -174,8 +174,6 @@ void BasicEnergySource::DoDispose (void) { NS_LOG_FUNCTION (this); - // calculate remaining energy at the end of simulation - CalculateRemainingEnergy (); BreakDeviceEnergyModelRefCycle (); // break reference cycle } diff --git a/src/contrib/energy/test/basic-energy-model-test.cc b/src/contrib/energy/test/basic-energy-model-test.cc index 0cbce0938..8051a2bf5 100644 --- a/src/contrib/energy/test/basic-energy-model-test.cc +++ b/src/contrib/energy/test/basic-energy-model-test.cc @@ -152,10 +152,14 @@ BasicEnergyUpdateTest::StateSwitchTest (WifiPhy::State state) Simulator::Schedule (Seconds (m_timeS), &WifiRadioEnergyModel::ChangeState, devModel, state); - // run simulation - Simulator::Stop (Seconds (m_timeS * 2)); + // Calculate remaining energy at simulation stop time + Simulator::Schedule (Seconds (m_timeS * 2), + &BasicEnergySource::UpdateEnergySource, source); + + double timeDelta = 0.000000001; // 1 nanosecond + // run simulation; stop just after last scheduled event + Simulator::Stop (Seconds (m_timeS * 2 + timeDelta)); Simulator::Run (); - Simulator::Destroy (); // energy = current * voltage * time