11#include "ns3/energy-source.h"
13#include "ns3/pointer.h"
14#include "ns3/simulator.h"
29 TypeId(
"ns3::LoraRadioEnergyModel")
31 .SetGroupName(
"Energy")
33 .AddAttribute(
"StandbyCurrentA",
34 "The default radio Standby current in Ampere.",
39 .AddAttribute(
"TxCurrentA",
40 "The radio Tx current in Ampere.",
45 .AddAttribute(
"RxCurrentA",
46 "The radio Rx current in Ampere.",
51 .AddAttribute(
"SleepCurrentA",
52 "The radio Sleep current in Ampere.",
57 .AddAttribute(
"TxCurrentModel",
58 "A pointer to the attached tx current model.",
63 "TotalEnergyConsumption",
64 "Total energy consumption of the radio device.",
66 "ns3::TracedValueCallback::Double");
177 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Setting NULL energy depletion callback!");
188 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Setting NULL energy recharged callback!");
217 double energyToDecrease = 0.0;
218 double supplyVoltage =
m_source->GetSupplyVoltage();
274 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Energy is depleted!");
293 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Energy is recharged!");
344 std::string stateName;
348 stateName =
"STANDBY";
360 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Switching to state: "
361 << stateName <<
" at time = " <<
Simulator::Now().GetSeconds() <<
" s");
401 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
412 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Update tx current callback not set!");
417 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
428 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
439 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
454 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
void Nullify()
Discard the implementation, set it to null.
bool IsNull() const
Check for null implementation.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Base class for device energy models.
virtual void ChangeState(int newState)=0
State
An enumeration of the possible states of an EndDeviceLoraPhy.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ SLEEP
The PHY layer is sleeping.
@ STANDBY
The PHY layer is in STANDBY.
A LoRa radio energy model.
LoraRadioEnergyModelPhyListener * m_listener
EndDeviceLoraPhy listener.
LoraRadioEnergyModelPhyListener * GetPhyListener()
double m_txCurrentA
transmit current
void HandleEnergyChanged() override
Handles energy recharged.
double m_sleepCurrentA
sleep current
double DoGetCurrentA() const override
double m_rxCurrentA
receive current
double m_idleCurrentA
idle current
uint8_t m_nPendingChangeState
pending state change
void SetEnergySource(Ptr< EnergySource > source) override
Sets pointer to EnergySouce installed on node.
double GetTxCurrentA() const
Gets transmit current.
void ChangeState(int newState) override
Changes state of the LoraRadioEnergyMode.
double GetTotalEnergyConsumption() const override
double GetRxCurrentA() const
Gets receive current.
void SetStandbyCurrentA(double idleCurrentA)
Sets idle current.
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the tx current model to compute the tx current based on such model.
LoraRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
void DoDispose() override
Destructor implementation.
EndDeviceLoraPhy::State m_currentState
current state the radio is in
bool m_isSupersededChangeState
superseded change state
void HandleEnergyRecharged() override
Handles energy recharged.
void HandleEnergyDepletion() override
Handles energy depletion.
~LoraRadioEnergyModel() override
Destructor.
void SetEnergyRechargedCallback(LoraRadioEnergyRechargedCallback callback)
void SetLoraRadioState(const EndDeviceLoraPhy::State state)
Time m_lastUpdateTime
time stamp of previous energy update
double GetStandbyCurrentA() const
Gets idle current.
Ptr< LoraTxCurrentModel > m_txCurrentModel
current model
void SetEnergyDepletionCallback(LoraRadioEnergyDepletionCallback callback)
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current.
void SetRxCurrentA(double rxCurrentA)
Sets receive current.
Ptr< EnergySource > m_source
energy source
void SetTxCurrentA(double txCurrentA)
Sets transmit current.
double GetSleepCurrentA() const
Gets sleep current.
void SetTxCurrentModel(Ptr< LoraTxCurrentModel > model)
static TypeId GetTypeId()
Register this type.
EndDeviceLoraPhy::State GetCurrentState() const
LoraRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
TracedValue< double > m_totalEnergyConsumption
This variable keeps track of the total energy consumed by this model.
Installable listener for LoRa physiscal layer state changes.
void NotifyTxStart(double txPowerDbm) override
Switches the LoraRadioEnergyModel to TX state and switches back to STANDBY after TX duration.
~LoraRadioEnergyModelPhyListener() override
Destructor.
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the LoraRadioEnergyModel of a state change.
void NotifyStandby() override
Defined in ns3::LoraEndDevicePhyListener.
void NotifySleep() override
Defined in ns3::LoraEndDevicePhyListener.
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update tx current callback.
void SwitchToStandby()
A helper function that makes scheduling m_changeStateCallback possible.
void NotifyRxStart() override
Switches the LoraRadioEnergyModel to RX state.
LoraRadioEnergyModelPhyListener()
Default constructor.
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the tx current stored in LoraRadioEnergyModel based on the nominal tx power u...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#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.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)