13#include "ns3/energy-source.h"
14#include "ns3/pointer.h"
15#include "ns3/simulator.h"
61 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
72 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
83 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Update tx current callback not set!");
88 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
99 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
110 NS_FATAL_ERROR(
"LoraRadioEnergyModelPhyListener:Change state callback not set!");
119 TypeId(
"ns3::LoraRadioEnergyModel")
121 .SetGroupName(
"Energy")
123 .AddAttribute(
"SleepCurrentA",
124 "The radio Sleep current in Ampere.",
129 .AddAttribute(
"StandbyCurrentA",
130 "The default radio Standby current in Ampere.",
135 .AddAttribute(
"TxCurrentA",
136 "The radio Tx current in Ampere.",
141 .AddAttribute(
"RxCurrentA",
142 "The radio Rx current in Ampere.",
147 .AddAttribute(
"TxCurrentModel",
148 "A pointer to the attached tx current model.",
153 "TotalEnergyConsumption",
154 "Total energy consumption of the radio device.",
156 "ns3::TracedValueCallback::Double");
169 m_listener = std::make_shared<LoraRadioEnergyModelPhyListener>();
200 const auto supplyVoltage =
m_source->GetSupplyVoltage();
278 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Setting NULL energy depletion callback!");
289 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Setting NULL energy recharged callback!");
321 const auto supplyVoltage =
m_source->GetSupplyVoltage();
358 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Energy is depleted!");
370 NS_LOG_DEBUG(
"LoraRadioEnergyModel:Energy is recharged!");
385std::shared_ptr<LoraRadioEnergyModelPhyListener>
433 NS_LOG_DEBUG(
"LoraRadioEnergyModel: Switching to state: " << state
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.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Callback< void, int > ChangeStateCallback
Callback type for ChangeState function.
Class representing a LoRa transceiver hardware state-machine of a SX1272 LoRa chip (see SX1272/73 Dat...
State
An enumeration of the possible internal states of an EndDeviceLoraPhy.
@ TX
The PHY layer is transmitting a packet.
@ RX_ACTIVE
The PHY layer is actively receiving a transmission after locking onto a preamble.
@ SLEEP
The PHY layer is in low-power sleep state.
@ RX_ENABLED
The PHY layer is listening to the channel for a valid transmission preamble.
@ STANDBY
The PHY layer is in standby mode.
A LoRa radio energy model.
double m_txCurrentA
transmit current
void HandleEnergyChanged() override
Handles energy changed.
double GetStateA(EndDeviceLoraPhy::State state) const
double m_sleepCurrentA
sleep current
Callback< void > LoraRadioEnergyDepletionCallback
Callback type for energy depletion handling.
double DoGetCurrentA() const override
double m_rxCurrentA
receive current
uint8_t m_nPendingChangeState
pending state change
double GetTxCurrentA() const
Gets transmit current.
double m_standbyCurrentA
standby current
void ChangeState(int newState) override
Changes state of the LoraRadioEnergyModel.
double GetTotalEnergyConsumption() const override
double GetRxCurrentA() const
Gets receive current.
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the tx current model to compute the tx current based on such model.
LoraRadioEnergyModel()
Default constructor.
LoraRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
void DoDispose() override
Destructor implementation.
Ptr< energy::EnergySource > m_source
energy source
EndDeviceLoraPhy::State m_currentState
current state the radio is in
void HandleEnergyRecharged() override
Handles energy recharged.
std::shared_ptr< LoraRadioEnergyModelPhyListener > GetPhyListener()
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 standby current.
Ptr< LoraTxCurrentModel > m_txCurrentModel
current model
Callback< void > LoraRadioEnergyRechargedCallback
Callback type for energy recharged handling.
void SetEnergyDepletionCallback(LoraRadioEnergyDepletionCallback callback)
void SetStandbyCurrentA(double standbyCurrentA)
Sets standby current.
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current.
void SetRxCurrentA(double rxCurrentA)
Sets receive current.
void SetTxCurrentA(double txCurrentA)
Sets transmit current.
void SetEnergySource(Ptr< energy::EnergySource > source) override
Sets pointer to EnergySource installed on node.
std::shared_ptr< LoraRadioEnergyModelPhyListener > m_listener
EndDeviceLoraPhy listener.
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.
~LoraRadioEnergyModelPhyListener() override
Destructor.
void NotifyStandby() override
Notify listeners that the device entered STANDBY state.
void NotifySleep() override
Notify listeners that the device entered SLEEP state.
void SetChangeStateCallback(energy::DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
energy::DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the LoraRadioEnergyModel of a state change.
Callback< void, double > UpdateTxCurrentCallback
Callback type for updating the transmit current based on the nominal tx power.
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update tx current callback.
void NotifyRxActive() override
Notify listeners that the device entered RX_ACTIVE state.
LoraRadioEnergyModelPhyListener()
Default constructor.
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the tx current stored in LoraRadioEnergyModel based on the nominal tx power u...
void NotifyRxEnabled() override
Notify listeners that the device entered RX_ENABLED state.
void NotifyTx(double txPowerDbm) override
Notify listeners that the device entered TX state.
#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.
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...
#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.
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 AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)