Added the LiIonEnergySource helper and RV Battery model bug fixes (Bug 1216)

This commit is contained in:
Cristiano Tapparello
2015-04-30 18:02:42 -04:00
parent bf5ba0c085
commit c044954bb4
5 changed files with 124 additions and 16 deletions

View File

@@ -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
=====

View File

@@ -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

View File

@@ -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_ */

View File

@@ -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;

View File

@@ -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.
*/