24 #include "ns3/energy-source.h"
26 #include "ns3/pointer.h"
27 #include "ns3/simulator.h"
40 TypeId(
"ns3::WifiRadioEnergyModel")
42 .SetGroupName(
"Energy")
44 .AddAttribute(
"IdleCurrentA",
45 "The default radio Idle current in Ampere.",
49 MakeDoubleChecker<double>())
50 .AddAttribute(
"CcaBusyCurrentA",
51 "The default radio CCA Busy State current in Ampere.",
55 MakeDoubleChecker<double>())
56 .AddAttribute(
"TxCurrentA",
57 "The radio TX current in Ampere.",
61 MakeDoubleChecker<double>())
62 .AddAttribute(
"RxCurrentA",
63 "The radio RX current in Ampere.",
67 MakeDoubleChecker<double>())
68 .AddAttribute(
"SwitchingCurrentA",
69 "The default radio Channel Switch current in Ampere.",
73 MakeDoubleChecker<double>())
74 .AddAttribute(
"SleepCurrentA",
75 "The radio Sleep current in Ampere.",
79 MakeDoubleChecker<double>())
80 .AddAttribute(
"TxCurrentModel",
81 "A pointer to the attached TX current model.",
84 MakePointerChecker<WifiTxCurrentModel>())
86 "TotalEnergyConsumption",
87 "Total energy consumption of the radio device.",
89 "ns3::TracedValueCallback::Double");
97 m_nPendingChangeState(0)
102 m_listener = std::make_shared<WifiRadioEnergyModelPhyListener>();
139 double supplyVoltage =
m_source->GetSupplyVoltage();
245 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Setting NULL energy depletion callback!");
256 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Setting NULL energy recharged callback!");
283 double remainingEnergy =
m_source->GetRemainingEnergy();
284 double supplyVoltage =
m_source->GetSupplyVoltage();
286 return Seconds(remainingEnergy / (current * supplyVoltage));
317 double supplyVoltage =
m_source->GetSupplyVoltage();
322 NS_ASSERT(m_totalEnergyConsumption <= m_source->GetInitialEnergy());
354 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Energy is depleted!");
366 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Energy is recharged!");
378 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Energy is changed!");
390 std::shared_ptr<WifiRadioEnergyModelPhyListener>
429 NS_FATAL_ERROR(
"WifiRadioEnergyModel: undefined radio state " << state);
443 std::string stateName;
450 stateName =
"CCA_BUSY";
459 stateName =
"SWITCHING";
468 NS_LOG_DEBUG(
"WifiRadioEnergyModel:Switching to state: " << stateName
509 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
521 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
532 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
543 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Update tx current callback not set!");
548 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
560 const std::vector<Time>& )
565 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
580 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
595 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
607 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
618 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
630 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
641 NS_FATAL_ERROR(
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
void Nullify()
Discard the implementation, set it to null.
bool IsNull() const
Check for null implementation.
Base class for device energy models.
virtual void ChangeState(int newState)=0
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
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.
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.
A WiFi radio energy model.
double GetStateA(int state) const
void HandleEnergyChanged() override
Handles energy changed.
double GetCcaBusyCurrentA() const
Gets CCA busy current in Amperes.
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
double m_idleCurrentA
idle current in Amperes
WifiPhyState GetCurrentState() const
double m_ccaBusyCurrentA
CCA busy current in Amperes.
void ChangeState(int newState) override
Changes state of the WifiRadioEnergyMode.
void SetCcaBusyCurrentA(double ccaBusyCurrentA)
Sets CCA busy current in Amperes.
Time GetMaximumTimeInState(int state) const
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
double m_sleepCurrentA
sleep current in Amperes
Ptr< EnergySource > m_source
energy source
TracedValue< double > m_totalEnergyConsumption
This variable keeps track of the total energy consumed by this model in watts.
void SetTxCurrentModel(const Ptr< WifiTxCurrentModel > model)
EventId m_switchToOffEvent
switch to off event
void DoDispose() override
Destructor implementation.
void SetRxCurrentA(double rxCurrentA)
Sets receive current in Amperes.
double GetTotalEnergyConsumption() const override
double m_txCurrentA
transmit current in Amperes
void HandleEnergyRecharged() override
Handles energy recharged.
Time m_lastUpdateTime
time stamp of previous energy update
void SetTxCurrentA(double txCurrentA)
Sets transmit current in Amperes.
double GetRxCurrentA() const
Gets receive current in Amperes.
double GetTxCurrentA() const
Gets transmit current in Amperes.
std::shared_ptr< WifiRadioEnergyModelPhyListener > m_listener
WifiPhy listener.
void HandleEnergyDepletion() override
Handles energy depletion.
static TypeId GetTypeId()
Get the type ID.
double GetIdleCurrentA() const
Gets idle current in Amperes.
~WifiRadioEnergyModel() override
void SetSwitchingCurrentA(double switchingCurrentA)
Sets switching current in Amperes.
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the TX current model to compute the TX current based on such model.
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
std::shared_ptr< WifiRadioEnergyModelPhyListener > GetPhyListener()
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current in Amperes.
double m_rxCurrentA
receive current in Amperes
WifiPhyState m_currentState
current state the radio is in
void SetWifiRadioState(const WifiPhyState state)
double GetSleepCurrentA() const
Gets sleep current in Amperes.
Ptr< WifiTxCurrentModel > m_txCurrentModel
current model
double GetSwitchingCurrentA() const
Gets switching current in Amperes.
void SetIdleCurrentA(double idleCurrentA)
Sets idle current in Amperes.
double DoGetCurrentA() const override
void SetEnergySource(const Ptr< EnergySource > source) override
Sets pointer to EnergySource installed on node.
void SetEnergyRechargedCallback(WifiRadioEnergyRechargedCallback callback)
double m_switchingCurrentA
switching current in Amperes
uint8_t m_nPendingChangeState
pending state change
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
WifiRadioEnergyModelPhyListener()
void NotifyTxStart(Time duration, double txPowerDbm) override
void NotifySleep() override
Notify listeners that we went to sleep.
~WifiRadioEnergyModelPhyListener() override
void NotifyOff() override
Notify listeners that we went to switch off.
void NotifyRxStart(Time duration) override
void NotifyRxEndOk() override
We have received the last bit of a packet for which NotifyRxStart was invoked first and,...
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the TX current stored in WifiRadioEnergyModel based on the nominal TX power u...
void NotifyRxEndError() override
We have received the last bit of a packet for which NotifyRxStart was invoked first and,...
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update TX current callback.
void NotifySwitchingStart(Time duration) override
void SwitchToIdle()
A helper function that makes scheduling m_changeStateCallback possible.
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
void NotifyWakeup() override
Notify listeners that we woke up.
EventId m_switchToIdleEvent
switch to idle event
void NotifyOn() override
Notify listeners that we went to switch on.
void NotifyCcaBusyStart(Time duration, WifiChannelListType channelType, const std::vector< Time > &per20MhzDurations) override
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#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.
WifiChannelListType
Enumeration of the possible channel-list parameter elements defined in Table 8-5 of IEEE 802....
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 AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
@ IDLE
Channel is IDLE, no packet is being transmitted.
WifiPhyState
The state of the PHY layer.
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ SWITCHING
The PHY layer is switching to other channel.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ OFF
The PHY layer is switched off.
@ SLEEP
The PHY layer is sleeping.
@ IDLE
The PHY layer is IDLE.