22 #include "ns3/double.h"
23 #include "ns3/simulator.h"
24 #include "ns3/trace-source-accessor.h"
25 #include "ns3/pointer.h"
41 .AddConstructor<WifiRadioEnergyModel> ()
42 .AddAttribute (
"IdleCurrentA",
43 "The default radio Idle current in Ampere.",
47 MakeDoubleChecker<double> ())
48 .AddAttribute (
"CcaBusyCurrentA",
49 "The default radio CCA Busy State current in Ampere.",
53 MakeDoubleChecker<double> ())
54 .AddAttribute (
"TxCurrentA",
55 "The radio Tx current in Ampere.",
59 MakeDoubleChecker<double> ())
60 .AddAttribute (
"RxCurrentA",
61 "The radio Rx current in Ampere.",
65 MakeDoubleChecker<double> ())
66 .AddAttribute (
"SwitchingCurrentA",
67 "The default radio Channel Switch current in Ampere.",
71 MakeDoubleChecker<double> ())
72 .AddAttribute (
"SleepCurrentA",
73 "The radio Sleep current in Ampere.",
77 MakeDoubleChecker<double> ())
78 .AddAttribute (
"TxCurrentModel",
"A pointer to the attached tx current model.",
81 MakePointerChecker<WifiTxCurrentModel> ())
82 .AddTraceSource (
"TotalEnergyConsumption",
83 "Total energy consumption of the radio device.",
85 "ns3::TracedValue::DoubleCallback")
225 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Setting NULL energy depletion callback!");
237 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Setting NULL energy recharged callback!");
266 double energyToDecrease = 0.0;
267 double supplyVoltage =
m_source->GetSupplyVoltage ();
316 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Total energy consumption is " <<
329 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Energy is depleted!");
341 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Energy is recharged!");
396 std::string stateName;
403 stateName =
"CCA_BUSY";
412 stateName =
"SWITCHING";
418 NS_LOG_DEBUG (
"WifiRadioEnergyModel:Switching to state: " << stateName <<
458 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
470 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
481 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
492 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Update tx current callback not set!");
497 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
511 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
525 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
539 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
551 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
566 NS_FATAL_ERROR (
"WifiRadioEnergyModelPhyListener:Change state callback not set!");
void SetWifiRadioState(const WifiPhy::State state)
Simulation virtual time values and global simulation resolution.
static TypeId GetTypeId(void)
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void HandleEnergyRecharged(void)
Handles energy recharged.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
TracedValue< double > m_totalEnergyConsumption
Base class for device energy models.
The PHY layer has sense the medium busy through the CCA mechanism.
bool IsNull(void) const
Check for null implementation.
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the tx current stored in WifiRadioEnergyModel 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...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void ChangeState(int newState)
Changes state of the WifiRadioEnergyMode.
The PHY layer is sleeping.
#define NS_FATAL_ERROR(msg)
Fatal error handling.
WifiRadioEnergyModelPhyListener * m_listener
virtual ~WifiRadioEnergyModelPhyListener()
double GetSleepCurrentA(void) const
void SetSleepCurrentA(double sleepCurrentA)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
virtual double GetTotalEnergyConsumption(void) const
WifiRadioEnergyModelPhyListener * GetPhyListener(void)
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update tx current callback.
void SwitchToIdle(void)
A helper function that makes scheduling m_changeStateCallback possible.
void SetRxCurrentA(double rxCurrentA)
virtual void NotifyRxEndOk(void)
Switches the WifiRadioEnergyModel back to IDLE state.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void SetCcaBusyCurrentA(double ccaBusyCurrentA)
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
double GetCcaBusyCurrentA(void) const
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
WifiPhy::State m_currentState
Ptr< WifiTxCurrentModel > m_txCurrentModel
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Ptr< EnergySource > m_source
virtual void NotifySwitchingStart(Time duration)
virtual void NotifyMaybeCcaBusyStart(Time duration)
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the tx current model to compute the tx current based on such model...
void SetEnergyRechargedCallback(WifiRadioEnergyRechargedCallback callback)
WifiRadioEnergyModelPhyListener()
virtual void NotifyRxEndError(void)
Switches the WifiRadioEnergyModel back to IDLE state.
The PHY layer is receiving a packet.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
WifiPhy::State GetCurrentState(void) const
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the WifiRadioEnergyModel of a state change.
The PHY layer is sending a packet.
The PHY layer is switching to other channel.
EventId m_switchToIdleEvent
virtual void NotifyTxStart(Time duration, double txPowerDbm)
Switches the WifiRadioEnergyModel to TX state and switches back to IDLE after TX duration.
virtual void SetEnergySource(Ptr< EnergySource > source)
Sets pointer to EnergySouce installed on node.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr.
virtual void NotifyWakeup(void)
Defined in ns3::WifiPhyListener.
double GetTxCurrentA(void) const
double GetRxCurrentA(void) const
A WifiPhy listener class for notifying the WifiRadioEnergyModel of Wifi radio state change...
static Time Now(void)
Return the current simulation virtual time.
void SetTxCurrentA(double txCurrentA)
virtual void NotifySleep(void)
Defined in ns3::WifiPhyListener.
virtual void NotifyRxStart(Time duration)
Switches the WifiRadioEnergyModel to RX state.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
void SetEnergyDepletionCallback(WifiRadioEnergyDepletionCallback callback)
void DoDispose(void)
Destructor implementation.
uint8_t m_nPendingChangeState
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
WifiRadioEnergyDepletionCallback m_energyDepletionCallback
Time Seconds(double value)
Construct a Time in the indicated unit.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
double GetIdleCurrentA(void) const
void Nullify(void)
Discard the implementation, set it to null.
virtual void ChangeState(int newState)=0
void SetSwitchingCurrentA(double switchingCurrentA)
double m_switchingCurrentA
virtual double DoGetCurrentA(void) const
bool m_isSupersededChangeState
State
The state of the PHY layer.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
virtual ~WifiRadioEnergyModel()
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void SetIdleCurrentA(double idleCurrentA)
WifiRadioEnergyRechargedCallback m_energyRechargedCallback
double GetSwitchingCurrentA(void) const
virtual void HandleEnergyDepletion(void)
Handles energy depletion.
void SetTxCurrentModel(Ptr< WifiTxCurrentModel > model)