Added the LiIonEnergySource helper and RV Battery model bug fixes (Bug 1216)
authorCristiano Tapparello <cristiano.tapparello@rochester.edu>
Thu, 30 Apr 2015 18:02:42 -0400
changeset 11341 aba202c0c922
parent 11340 435b74dece97
child 11342 bcdcb8a6750e
Added the LiIonEnergySource helper and RV Battery model bug fixes (Bug 1216)
src/energy/doc/energy.rst
src/energy/helper/li-ion-energy-source-helper.cc
src/energy/helper/li-ion-energy-source-helper.h
src/energy/model/rv-battery-model.cc
src/energy/model/rv-battery-model.h
--- a/src/energy/doc/energy.rst	Mon Apr 27 13:27:02 2015 +0200
+++ b/src/energy/doc/energy.rst	Thu Apr 30 18:02:42 2015 -0400
@@ -186,6 +186,11 @@
    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
 =====
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/energy/helper/li-ion-energy-source-helper.cc	Thu Apr 30 18:02:42 2015 -0400
@@ -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 <hayatoll@ur.rochester.edu>
+ *          Cristiano Tapparello <cristiano.tapparello@rochester.edu>
+ */
+
+#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<EnergySource> 
+LiIonEnergySourceHelper::DoInstall (Ptr<Node> node) const
+{
+  NS_ASSERT (node != NULL);
+  Ptr<EnergySource> source = m_liIonEnergySource.Create<EnergySource> ();
+  NS_ASSERT (source != NULL);
+  source->SetNode (node);
+  return source;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/energy/helper/li-ion-energy-source-helper.h	Thu Apr 30 18:02:42 2015 -0400
@@ -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 <hayatoll@ur.rochester.edu>
+ *          Cristiano Tapparello <cristiano.tapparello@rochester.edu>
+ */
+
+#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<EnergySource> DoInstall (Ptr<Node> node) const;
+
+private:
+  ObjectFactory m_liIonEnergySource;
+
+};
+
+} // namespace ns3
+
+#endif /* LI_ION_ENERGY_SOURCE_HELPER_H_ */
--- a/src/energy/model/rv-battery-model.cc	Mon Apr 27 13:27:02 2015 +0200
+++ b/src/energy/model/rv-battery-model.cc	Thu Apr 30 18:02:42 2015 -0400
@@ -95,8 +95,9 @@
 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 @@
       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 @@
     {
       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;
--- a/src/energy/model/rv-battery-model.h	Mon Apr 27 13:27:02 2015 +0200
+++ b/src/energy/model/rv-battery-model.h	Thu Apr 30 18:02:42 2015 -0400
@@ -55,7 +55,7 @@
   virtual ~RvBatteryModel ();
 
   /**
-   * \return Initial energy stored (theoretical capacity) in the battery.
+   * \return Initial energy stored (theoretical capacity) in the battery, in Joules.
    *
    * Implements GetInitialEnergy.
    */