A Discrete-Event Network Simulator
API
ns3::BasicEnergySource Class Reference

BasicEnergySource decreases/increases remaining energy stored in itself in linearly. More...

#include "basic-energy-source.h"

+ Inheritance diagram for ns3::BasicEnergySource:
+ Collaboration diagram for ns3::BasicEnergySource:

Public Member Functions

 BasicEnergySource ()
 
 ~BasicEnergySource () override
 
double GetEnergyFraction () override
 
Time GetEnergyUpdateInterval () const
 
double GetInitialEnergy () const override
 
double GetRemainingEnergy () override
 
double GetSupplyVoltage () const override
 
void SetEnergyUpdateInterval (Time interval)
 
void SetInitialEnergy (double initialEnergyJ)
 
void SetSupplyVoltage (double supplyVoltageV)
 
void UpdateEnergySource () override
 Implements UpdateEnergySource. More...
 
- Public Member Functions inherited from ns3::EnergySource
 EnergySource ()
 
 ~EnergySource () override
 
void AppendDeviceEnergyModel (Ptr< DeviceEnergyModel > deviceEnergyModelPtr)
 
void ConnectEnergyHarvester (Ptr< EnergyHarvester > energyHarvesterPtr)
 
void DisposeDeviceModels ()
 Calls Dispose () method of the device energy models. More...
 
DeviceEnergyModelContainer FindDeviceEnergyModels (std::string name)
 
DeviceEnergyModelContainer FindDeviceEnergyModels (TypeId tid)
 
Ptr< NodeGetNode () const
 
void InitializeDeviceModels ()
 Calls Start () method of the device energy models. More...
 
void SetNode (Ptr< Node > node)
 Sets pointer to node containing this EnergySource. More...
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
 ~Object () override
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose ()
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one. More...
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object. More...
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object. More...
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object. More...
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized () const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o[[maybe_unused]])
 Copy constructor. More...
 
uint32_t GetReferenceCount () const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= (const SimpleRefCount &o[[maybe_unused]])
 Assignment operator. More...
 
void Ref () const
 Increment the reference count. More...
 
void Unref () const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::EnergySource
static TypeId GetTypeId ()
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type. More...
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID. More...
 

Private Member Functions

void CalculateRemainingEnergy ()
 Calculates remaining energy. More...
 
void DoDispose () override
 Defined in ns3::Object. More...
 
void DoInitialize () override
 Defined in ns3::Object. More...
 
void HandleEnergyDrainedEvent ()
 Handles the remaining energy going to zero event. More...
 
void HandleEnergyRechargedEvent ()
 Handles the remaining energy exceeding the high threshold after it went below the low threshold. More...
 

Private Attributes

bool m_depleted
 set to true when the remaining energy goes below the low threshold, set to false again when the remaining energy exceeds the high threshold More...
 
EventId m_energyUpdateEvent
 energy update event More...
 
Time m_energyUpdateInterval
 energy update interval More...
 
double m_highBatteryTh
 high battery threshold, as a fraction of the initial energy More...
 
double m_initialEnergyJ
 initial energy, in Joules More...
 
Time m_lastUpdateTime
 last update time More...
 
double m_lowBatteryTh
 low battery threshold, as a fraction of the initial energy More...
 
TracedValue< double > m_remainingEnergyJ
 remaining energy, in Joules More...
 
double m_supplyVoltageV
 supply voltage, in Volts More...
 

Additional Inherited Members

- Protected Member Functions inherited from ns3::EnergySource
void BreakDeviceEnergyModelRefCycle ()
 This function is called to break reference cycle between EnergySource and DeviceEnergyModel. More...
 
double CalculateTotalCurrent ()
 
void NotifyEnergyChanged ()
 This function notifies all DeviceEnergyModel of energy changed event. More...
 
void NotifyEnergyDrained ()
 This function notifies all DeviceEnergyModel of energy depletion event. More...
 
void NotifyEnergyRecharged ()
 This function notifies all DeviceEnergyModel of energy recharged event. More...
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object. More...
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated. More...
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes. More...
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed. More...
 

Detailed Description

BasicEnergySource decreases/increases remaining energy stored in itself in linearly.

Definition at line 38 of file basic-energy-source.h.

Constructor & Destructor Documentation

◆ BasicEnergySource()

ns3::BasicEnergySource::BasicEnergySource ( )

Definition at line 78 of file basic-energy-source.cc.

References m_depleted, m_lastUpdateTime, NS_LOG_FUNCTION, and ns3::Seconds().

+ Here is the call graph for this function:

◆ ~BasicEnergySource()

ns3::BasicEnergySource::~BasicEnergySource ( )
override

Definition at line 85 of file basic-energy-source.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ CalculateRemainingEnergy()

void ns3::BasicEnergySource::CalculateRemainingEnergy ( )
private

Calculates remaining energy.

This function uses the total current from all device models to calculate the amount of energy to decrease. The energy to decrease is given by: energy to decrease = total current * supply voltage * time duration This function subtracts the calculated energy to decrease from remaining energy.

Definition at line 221 of file basic-energy-source.cc.

References ns3::EnergySource::CalculateTotalCurrent(), ns3::Time::IsPositive(), m_lastUpdateTime, m_remainingEnergyJ, m_supplyVoltageV, ns3::Simulator::Now(), NS_ASSERT, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

Referenced by UpdateEnergySource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoDispose()

void ns3::BasicEnergySource::DoDispose ( void  )
overrideprivatevirtual

Defined in ns3::Object.

Reimplemented from ns3::Object.

Definition at line 198 of file basic-energy-source.cc.

References ns3::EnergySource::BreakDeviceEnergyModelRefCycle(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ DoInitialize()

void ns3::BasicEnergySource::DoInitialize ( void  )
overrideprivatevirtual

Defined in ns3::Object.

Reimplemented from ns3::Object.

Definition at line 191 of file basic-energy-source.cc.

References NS_LOG_FUNCTION, and UpdateEnergySource().

+ Here is the call graph for this function:

◆ GetEnergyFraction()

double ns3::BasicEnergySource::GetEnergyFraction ( )
overridevirtual
Returns
Energy fraction.

Implements GetEnergyFraction.

Implements ns3::EnergySource.

Definition at line 144 of file basic-energy-source.cc.

References m_initialEnergyJ, m_remainingEnergyJ, NS_LOG_FUNCTION, and UpdateEnergySource().

+ Here is the call graph for this function:

◆ GetEnergyUpdateInterval()

Time ns3::BasicEnergySource::GetEnergyUpdateInterval ( ) const
Returns
The interval between each energy update.

Definition at line 114 of file basic-energy-source.cc.

References m_energyUpdateInterval, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ GetInitialEnergy()

double ns3::BasicEnergySource::GetInitialEnergy ( ) const
overridevirtual
Returns
Initial energy stored in energy source, in Joules.

Implements GetInitialEnergy.

Implements ns3::EnergySource.

Definition at line 128 of file basic-energy-source.cc.

References m_initialEnergyJ, and NS_LOG_FUNCTION.

Referenced by BasicEnergyHarvesterTestCase::DoRun(), GetTypeId(), and BasicEnergyUpdateTest::StateSwitchTest().

+ Here is the caller graph for this function:

◆ GetRemainingEnergy()

double ns3::BasicEnergySource::GetRemainingEnergy ( )
overridevirtual
Returns
Remaining energy in energy source, in Joules

Implements GetRemainingEnergy.

Implements ns3::EnergySource.

Definition at line 135 of file basic-energy-source.cc.

References m_remainingEnergyJ, NS_LOG_FUNCTION, and UpdateEnergySource().

Referenced by AnimationRemainingEnergyTestCase::CheckLogic(), BasicEnergyHarvesterTestCase::DoRun(), and BasicEnergyUpdateTest::StateSwitchTest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetSupplyVoltage()

double ns3::BasicEnergySource::GetSupplyVoltage ( ) const
overridevirtual
Returns
Supply voltage at the energy source.

Implements GetSupplyVoltage.

Implements ns3::EnergySource.

Definition at line 121 of file basic-energy-source.cc.

References m_supplyVoltageV, and NS_LOG_FUNCTION.

Referenced by GetTypeId(), and BasicEnergyUpdateTest::StateSwitchTest().

+ Here is the caller graph for this function:

◆ GetTypeId()

◆ HandleEnergyDrainedEvent()

void ns3::BasicEnergySource::HandleEnergyDrainedEvent ( )
private

Handles the remaining energy going to zero event.

This function notifies all the energy models aggregated to the node about the energy being depleted. Each energy model is then responsible for its own handler.

Definition at line 205 of file basic-energy-source.cc.

References ns3::EnergySource::NotifyEnergyDrained(), NS_LOG_DEBUG, and NS_LOG_FUNCTION.

Referenced by UpdateEnergySource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleEnergyRechargedEvent()

void ns3::BasicEnergySource::HandleEnergyRechargedEvent ( )
private

Handles the remaining energy exceeding the high threshold after it went below the low threshold.

This function notifies all the energy models aggregated to the node about the energy being recharged. Each energy model is then responsible for its own handler.

Definition at line 213 of file basic-energy-source.cc.

References ns3::EnergySource::NotifyEnergyRecharged(), NS_LOG_DEBUG, and NS_LOG_FUNCTION.

Referenced by UpdateEnergySource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetEnergyUpdateInterval()

void ns3::BasicEnergySource::SetEnergyUpdateInterval ( Time  interval)
Parameters
intervalEnergy update interval.

This function sets the interval between each energy update.

Definition at line 107 of file basic-energy-source.cc.

References m_energyUpdateInterval, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ SetInitialEnergy()

void ns3::BasicEnergySource::SetInitialEnergy ( double  initialEnergyJ)
Parameters
initialEnergyJInitial energy, in Joules

Sets initial energy stored in the energy source. Note that initial energy is assumed to be set before simulation starts and is set only once per simulation.

Definition at line 91 of file basic-energy-source.cc.

References m_initialEnergyJ, m_remainingEnergyJ, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by GetTypeId(), AnimationRemainingEnergyTestCase::PrepareNetwork(), and BasicEnergyUpdateTest::StateSwitchTest().

+ Here is the caller graph for this function:

◆ SetSupplyVoltage()

void ns3::BasicEnergySource::SetSupplyVoltage ( double  supplyVoltageV)
Parameters
supplyVoltageVSupply voltage at the energy source, in Volts.

Sets supply voltage of the energy source.

Definition at line 100 of file basic-energy-source.cc.

References m_supplyVoltageV, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ UpdateEnergySource()

Member Data Documentation

◆ m_depleted

bool ns3::BasicEnergySource::m_depleted
private

set to true when the remaining energy goes below the low threshold, set to false again when the remaining energy exceeds the high threshold

Definition at line 151 of file basic-energy-source.h.

Referenced by BasicEnergySource(), and UpdateEnergySource().

◆ m_energyUpdateEvent

EventId ns3::BasicEnergySource::m_energyUpdateEvent
private

energy update event

Definition at line 153 of file basic-energy-source.h.

Referenced by UpdateEnergySource().

◆ m_energyUpdateInterval

Time ns3::BasicEnergySource::m_energyUpdateInterval
private

energy update interval

Definition at line 155 of file basic-energy-source.h.

Referenced by GetEnergyUpdateInterval(), SetEnergyUpdateInterval(), and UpdateEnergySource().

◆ m_highBatteryTh

double ns3::BasicEnergySource::m_highBatteryTh
private

high battery threshold, as a fraction of the initial energy

Definition at line 146 of file basic-energy-source.h.

Referenced by GetTypeId(), and UpdateEnergySource().

◆ m_initialEnergyJ

double ns3::BasicEnergySource::m_initialEnergyJ
private

initial energy, in Joules

Definition at line 143 of file basic-energy-source.h.

Referenced by GetEnergyFraction(), GetInitialEnergy(), SetInitialEnergy(), and UpdateEnergySource().

◆ m_lastUpdateTime

Time ns3::BasicEnergySource::m_lastUpdateTime
private

last update time

Definition at line 154 of file basic-energy-source.h.

Referenced by BasicEnergySource(), CalculateRemainingEnergy(), and UpdateEnergySource().

◆ m_lowBatteryTh

double ns3::BasicEnergySource::m_lowBatteryTh
private

low battery threshold, as a fraction of the initial energy

Definition at line 145 of file basic-energy-source.h.

Referenced by GetTypeId(), and UpdateEnergySource().

◆ m_remainingEnergyJ

TracedValue<double> ns3::BasicEnergySource::m_remainingEnergyJ
private

◆ m_supplyVoltageV

double ns3::BasicEnergySource::m_supplyVoltageV
private

supply voltage, in Volts

Definition at line 144 of file basic-energy-source.h.

Referenced by CalculateRemainingEnergy(), GetSupplyVoltage(), and SetSupplyVoltage().


The documentation for this class was generated from the following files: