diff --git a/src/energy/doc/energy.rst b/src/energy/doc/energy.rst index ca7201b29..6389cd37b 100644 --- a/src/energy/doc/energy.rst +++ b/src/energy/doc/energy.rst @@ -186,6 +186,11 @@ References Energy Framework for Network Simulator 3 (ns-3). Workshop on ns-3 (WNS3), Poster Session, Atlanta, GA, USA. May, 2014. +.. [7] C. Tapparello, H. Ayatollahi and W. Heinzelman. Energy Harvesting + Framework for Network Simulator 3 (ns-3). 2nd International Workshop on + Energy Neutral Sensing Systems (ENSsys), Memphis, TN, USA. November 6, + 2014. + Usage ===== diff --git a/src/energy/helper/li-ion-energy-source-helper.cc b/src/energy/helper/li-ion-energy-source-helper.cc new file mode 100644 index 000000000..1d1f5a918 --- /dev/null +++ b/src/energy/helper/li-ion-energy-source-helper.cc @@ -0,0 +1,53 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014 Wireless Communications and Networking Group (WCNG), + * University of Rochester, Rochester, NY, USA. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Hoda Ayatollahi + * Cristiano Tapparello + */ + +#include "li-ion-energy-source-helper.h" +#include "ns3/energy-source.h" + +namespace ns3 { + +LiIonEnergySourceHelper::LiIonEnergySourceHelper () +{ + m_liIonEnergySource.SetTypeId ("ns3::LiIonEnergySource"); +} + +LiIonEnergySourceHelper::~LiIonEnergySourceHelper () +{ +} + +void +LiIonEnergySourceHelper::Set (std::string name, const AttributeValue &v) +{ + m_liIonEnergySource.Set (name, v); +} + +Ptr +LiIonEnergySourceHelper::DoInstall (Ptr node) const +{ + NS_ASSERT (node != NULL); + Ptr source = m_liIonEnergySource.Create (); + NS_ASSERT (source != NULL); + source->SetNode (node); + return source; +} + +} // namespace ns3 diff --git a/src/energy/helper/li-ion-energy-source-helper.h b/src/energy/helper/li-ion-energy-source-helper.h new file mode 100644 index 000000000..78efc7721 --- /dev/null +++ b/src/energy/helper/li-ion-energy-source-helper.h @@ -0,0 +1,54 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014 Wireless Communications and Networking Group (WCNG), + * University of Rochester, Rochester, NY, USA. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Hoda Ayatollahi + * Cristiano Tapparello + */ + +#ifndef LI_ION_ENERGY_SOURCE_HELPER_H_ +#define LI_ION_ENERGY_SOURCE_HELPER_H_ + +#include "energy-model-helper.h" +#include "ns3/node.h" + +namespace ns3 { + +/** + * \ingroup energy + * \brief Creates a LiIonEnergySource object. + * + */ +class LiIonEnergySourceHelper: public EnergySourceHelper +{ +public: + LiIonEnergySourceHelper (); + ~LiIonEnergySourceHelper (); + + void Set (std::string name, const AttributeValue &v); + +private: + virtual Ptr DoInstall (Ptr node) const; + +private: + ObjectFactory m_liIonEnergySource; + +}; + +} // namespace ns3 + +#endif /* LI_ION_ENERGY_SOURCE_HELPER_H_ */ diff --git a/src/energy/model/rv-battery-model.cc b/src/energy/model/rv-battery-model.cc index 20522f903..4deb9a943 100644 --- a/src/energy/model/rv-battery-model.cc +++ b/src/energy/model/rv-battery-model.cc @@ -95,8 +95,9 @@ RvBatteryModel::GetTypeId (void) RvBatteryModel::RvBatteryModel () { NS_LOG_FUNCTION (this); - m_lastSampleTime = Seconds (0.0); - m_previousLoad = 0.0; + m_lastSampleTime = Simulator::Now (); + m_timeStamps.push_back (m_lastSampleTime); + m_previousLoad = -1.0; m_batteryLevel = 1; // fully charged m_lifetime = Seconds (0.0); } @@ -171,13 +172,12 @@ RvBatteryModel::UpdateEnergySource (void) m_batteryLevel = 0; } - // check if battery is dead. + // check if battery level is below the low battery threshold. if (m_batteryLevel <= m_lowBatteryTh) { - m_lifetime = Simulator::Now (); - NS_LOG_DEBUG ("RvBatteryModel:Battery is dead!"); + m_lifetime = Simulator::Now () - m_timeStamps[0]; + NS_LOG_DEBUG ("RvBatteryModel:Battery level below threshold!"); HandleEnergyDrainedEvent (); - return; // stop periodic sampling } m_previousLoad = currentLoad; @@ -327,19 +327,15 @@ RvBatteryModel::Discharge (double load, Time t) { m_load.push_back (load); m_previousLoad = load; - if (t != Seconds (0.0)) - { - m_timeStamps[m_timeStamps.size () - 1] = m_lastSampleTime; - } - else - { - m_timeStamps.push_back (Seconds (0.0)); - } + m_timeStamps[m_timeStamps.size () - 1] = m_lastSampleTime; m_timeStamps.push_back (t); } else { - m_timeStamps[m_timeStamps.size () - 1] = t; + if (!m_timeStamps.empty()) + { + m_timeStamps[m_timeStamps.size () - 1] = t; + } } m_lastSampleTime = t; diff --git a/src/energy/model/rv-battery-model.h b/src/energy/model/rv-battery-model.h index 8d98898e8..e2e36dbeb 100644 --- a/src/energy/model/rv-battery-model.h +++ b/src/energy/model/rv-battery-model.h @@ -55,7 +55,7 @@ public: virtual ~RvBatteryModel (); /** - * \return Initial energy stored (theoretical capacity) in the battery. + * \return Initial energy stored (theoretical capacity) in the battery, in Joules. * * Implements GetInitialEnergy. */