21 #include "basic-energy-source.h"
23 #include "ns3/assert.h"
24 #include "ns3/double.h"
25 #include "ns3/trace-source-accessor.h"
26 #include "ns3/simulator.h"
32 NS_OBJECT_ENSURE_REGISTERED (BasicEnergySource);
35 BasicEnergySource::GetTypeId (
void)
37 static TypeId tid = TypeId (
"ns3::BasicEnergySource")
38 .SetParent<EnergySource> ()
39 .AddConstructor<BasicEnergySource> ()
40 .AddAttribute (
"BasicEnergySourceInitialEnergyJ",
41 "Initial energy stored in basic energy source.",
45 MakeDoubleChecker<double> ())
46 .AddAttribute (
"BasicEnergySupplyVoltageV",
47 "Initial supply voltage for basic energy source.",
51 MakeDoubleChecker<double> ())
52 .AddAttribute (
"PeriodicEnergyUpdateInterval",
53 "Time between two consecutive periodic energy updates.",
58 .AddTraceSource (
"RemainingEnergy",
59 "Remaining energy at BasicEnergySource.",
65 BasicEnergySource::BasicEnergySource ()
68 m_lastUpdateTime =
Seconds (0.0);
71 BasicEnergySource::~BasicEnergySource ()
81 m_initialEnergyJ = initialEnergyJ;
82 m_remainingEnergyJ = m_initialEnergyJ;
89 m_supplyVoltageV = supplyVoltageV;
96 m_energyUpdateInterval = interval;
103 return m_energyUpdateInterval;
110 return m_supplyVoltageV;
117 return m_initialEnergyJ;
126 return m_remainingEnergyJ;
135 return m_remainingEnergyJ / m_initialEnergyJ;
142 NS_LOG_DEBUG (
"BasicEnergySource:Updating remaining energy.");
150 m_energyUpdateEvent.
Cancel ();
154 if (m_remainingEnergyJ <= 0)
191 m_remainingEnergyJ = 0;
202 double energyToDecreaseJ = totalCurrentA * m_supplyVoltageV * duration.
GetSeconds ();
203 m_remainingEnergyJ -= energyToDecreaseJ;
204 NS_LOG_DEBUG (
"BasicEnergySource:Remaining energy = " << m_remainingEnergyJ);
void CalculateRemainingEnergy(void)
#define NS_LOG_FUNCTION(parameters)
Time GetEnergyUpdateInterval(void) const
virtual double GetSupplyVoltage(void) const
virtual double GetRemainingEnergy(void)
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual void UpdateEnergySource(void)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
void HandleEnergyDrainedEvent(void)
void BreakDeviceEnergyModelRefCycle(void)
double GetSeconds(void) const
virtual double GetInitialEnergy(void) const
void DoDispose(void)
Defined in ns3::Object.
double CalculateTotalCurrent(void)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void DoInitialize(void)
Defined in ns3::Object.
void NotifyEnergyDrained(void)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
void SetSupplyVoltage(double supplyVoltageV)
void SetEnergyUpdateInterval(Time interval)
#define NS_LOG_DEBUG(msg)
static bool IsFinished(void)
void SetInitialEnergy(double initialEnergyJ)
virtual double GetEnergyFraction(void)