11#include "ns3/assert.h"
12#include "ns3/double.h"
14#include "ns3/simulator.h"
15#include "ns3/trace-source-accessor.h"
29 TypeId(
"ns3::energy::BasicEnergySource")
32 .SetGroupName(
"Energy")
34 .AddAttribute(
"BasicEnergySourceInitialEnergyJ",
35 "Initial energy stored in basic energy source.",
40 .AddAttribute(
"BasicEnergySupplyVoltageV",
41 "Initial supply voltage for basic energy source.",
46 .AddAttribute(
"BasicEnergyLowBatteryThreshold",
47 "Low battery threshold for basic energy source.",
51 .AddAttribute(
"BasicEnergyHighBatteryThreshold",
52 "High battery threshold for basic energy source.",
56 .AddAttribute(
"PeriodicEnergyUpdateInterval",
57 "Time between two consecutive periodic energy updates.",
62 .AddTraceSource(
"RemainingEnergy",
63 "Remaining energy at BasicEnergySource.",
65 "ns3::TracedValueCallback::Double");
147 NS_LOG_DEBUG(
"BasicEnergySource:Updating remaining energy.");
219 double energyToDecreaseJ = (totalCurrentA *
m_supplyVoltageV * duration).GetSeconds();
This class can be used to hold variables of floating point type such as 'double' or 'float'.
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
bool IsPositive() const
Exactly equivalent to t >= 0.
a unique identifier for an interface.
TypeId AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
BasicEnergySource decreases/increases remaining energy stored in itself in linearly.
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
double m_initialEnergyJ
initial energy, in Joules
Time m_lastUpdateTime
last update time
double GetEnergyFraction() override
static TypeId GetTypeId()
Get the type ID.
double GetSupplyVoltage() const override
double GetRemainingEnergy() override
Time m_energyUpdateInterval
energy update interval
EventId m_energyUpdateEvent
energy update event
void SetInitialEnergy(double initialEnergyJ)
bool m_depleted
set to true when the remaining energy goes below the low threshold, set to false again when the remai...
~BasicEnergySource() override
TracedValue< double > m_remainingEnergyJ
remaining energy, in Joules
void DoDispose() override
Defined in ns3::Object.
void SetSupplyVoltage(double supplyVoltageV)
void SetEnergyUpdateInterval(Time interval)
Time GetEnergyUpdateInterval() const
double GetInitialEnergy() const override
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
void UpdateEnergySource() override
Implements UpdateEnergySource.
void CalculateRemainingEnergy()
Calculates remaining energy.
double m_highBatteryTh
high battery threshold, as a fraction of the initial energy
void HandleEnergyRechargedEvent()
Handles the remaining energy exceeding the high threshold after it went below the low threshold.
void DoInitialize() override
Defined in ns3::Object.
double m_supplyVoltageV
supply voltage, in Volts
Energy source base class.
void BreakDeviceEnergyModelRefCycle()
This function is called to break reference cycle between EnergySource and DeviceEnergyModel.
void NotifyEnergyDrained()
This function notifies all DeviceEnergyModel of energy depletion event.
double CalculateTotalCurrent()
void NotifyEnergyRecharged()
This function notifies all DeviceEnergyModel of energy recharged event.
void NotifyEnergyChanged()
This function notifies all DeviceEnergyModel of energy changed event.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.