INET Framework for OMNeT++/OMNEST
inet::physicallayer::StateBasedEpEnergyConsumer Class Reference

This is a simple radio power consumer model. More...

#include <StateBasedEpEnergyConsumer.h>

Inheritance diagram for inet::physicallayer::StateBasedEpEnergyConsumer:
inet::power::IEpEnergyConsumer inet::power::IEnergyConsumer

Public Member Functions

virtual IEnergySourcegetEnergySource () const override
 Returns the energy source that provides energy for this energy consumer. More...
 
virtual W getPowerConsumption () const override
 Returns the power consumption in the range [0, +infinity). More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, long value, cObject *details) override
 
- Public Member Functions inherited from inet::power::IEnergyConsumer
virtual ~IEnergyConsumer ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual W computePowerConsumption () const
 

Protected Attributes

W offPowerConsumption = W(NaN)
 
W sleepPowerConsumption = W(NaN)
 
W switchingPowerConsumption = W(NaN)
 
W receiverIdlePowerConsumption = W(NaN)
 
W receiverBusyPowerConsumption = W(NaN)
 
W receiverReceivingPowerConsumption = W(NaN)
 
W receiverReceivingPreamblePowerConsumption = W(NaN)
 
W receiverReceivingHeaderPowerConsumption = W(NaN)
 
W receiverReceivingDataPowerConsumption = W(NaN)
 
W transmitterIdlePowerConsumption = W(NaN)
 
W transmitterTransmittingPowerConsumption = W(NaN)
 
W transmitterTransmittingPreamblePowerConsumption = W(NaN)
 
W transmitterTransmittingHeaderPowerConsumption = W(NaN)
 
W transmitterTransmittingDataPowerConsumption = W(NaN)
 
IRadioradio = nullptr
 
IEpEnergySourceenergySource = nullptr
 
W powerConsumption = W(NaN)
 

Additional Inherited Members

- Static Public Attributes inherited from inet::power::IEpEnergyConsumer
static simsignal_t powerConsumptionChangedSignal = cComponent::registerSignal("powerConsumptionChanged")
 The signal that is used to publish power consumption changes. More...
 

Detailed Description

This is a simple radio power consumer model.

The power consumption is determined by the radio mode, the transmitter state and the receiver state using constant parameters.

Author
Levente Meszaros

Member Function Documentation

W inet::physicallayer::StateBasedEpEnergyConsumer::computePowerConsumption ( ) const
protectedvirtual

Referenced by receiveSignal().

75 {
76  IRadio::RadioMode radioMode = radio->getRadioMode();
77  if (radioMode == IRadio::RADIO_MODE_OFF)
78  return offPowerConsumption;
79  else if (radioMode == IRadio::RADIO_MODE_SLEEP)
80  return sleepPowerConsumption;
81  else if (radioMode == IRadio::RADIO_MODE_SWITCHING)
83  W powerConsumption = W(0);
86  if (radioMode == IRadio::RADIO_MODE_RECEIVER || radioMode == IRadio::RADIO_MODE_TRANSCEIVER) {
87  if (receptionState == IRadio::RECEPTION_STATE_IDLE)
88  powerConsumption += receiverIdlePowerConsumption;
89  else if (receptionState == IRadio::RECEPTION_STATE_BUSY)
90  powerConsumption += receiverBusyPowerConsumption;
91  else if (receptionState == IRadio::RECEPTION_STATE_RECEIVING) {
92  auto part = radio->getReceivedSignalPart();
94  ;
95  else if (part == IRadioSignal::SIGNAL_PART_WHOLE)
96  powerConsumption += receiverReceivingPowerConsumption;
97  else if (part == IRadioSignal::SIGNAL_PART_PREAMBLE)
99  else if (part == IRadioSignal::SIGNAL_PART_HEADER)
100  powerConsumption += receiverReceivingHeaderPowerConsumption;
101  else if (part == IRadioSignal::SIGNAL_PART_DATA)
102  powerConsumption += receiverReceivingDataPowerConsumption;
103  else
104  throw cRuntimeError("Unknown received signal part");
105  }
106  else if (receptionState != IRadio::RECEPTION_STATE_UNDEFINED)
107  throw cRuntimeError("Unknown radio reception state");
108  }
109  if (radioMode == IRadio::RADIO_MODE_TRANSMITTER || radioMode == IRadio::RADIO_MODE_TRANSCEIVER) {
110  if (transmissionState == IRadio::TRANSMISSION_STATE_IDLE)
111  powerConsumption += transmitterIdlePowerConsumption;
112  else if (transmissionState == IRadio::TRANSMISSION_STATE_TRANSMITTING) {
113  // TODO: add transmission power?
114  auto part = radio->getTransmittedSignalPart();
115  if (part == IRadioSignal::SIGNAL_PART_NONE)
116  ;
117  else if (part == IRadioSignal::SIGNAL_PART_WHOLE)
118  powerConsumption += transmitterTransmittingPowerConsumption;
119  else if (part == IRadioSignal::SIGNAL_PART_PREAMBLE)
121  else if (part == IRadioSignal::SIGNAL_PART_HEADER)
123  else if (part == IRadioSignal::SIGNAL_PART_DATA)
125  else
126  throw cRuntimeError("Unknown transmitted signal part");
127  }
128  else if (transmissionState != IRadio::TRANSMISSION_STATE_UNDEFINED)
129  throw cRuntimeError("Unknown radio transmission state");
130  }
131  return powerConsumption;
132 }
The radio medium is busy, a signal strong enough to receive is detected.
Definition: IRadio.h:161
virtual IRadioSignal::SignalPart getReceivedSignalPart() const =0
Returns the signal part of the ongoing reception that the receiver is currently receiving or -1 if no...
W receiverReceivingPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:47
The radio medium state is unknown, reception state is meaningless, signal detection is not possible...
Definition: IRadio.h:142
TransmissionState
This enumeration specifies the transmission state of the radio.
Definition: IRadio.h:167
W transmitterIdlePowerConsumption
Definition: StateBasedEpEnergyConsumer.h:51
ReceptionState
This enumeration specifies the reception state of the radio.
Definition: IRadio.h:136
W transmitterTransmittingHeaderPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:54
W receiverReceivingHeaderPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:49
W transmitterTransmittingPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:52
W offPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:42
The radio is not transmitting a signal on the radio medium.
Definition: IRadio.h:178
W transmitterTransmittingDataPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:55
W switchingPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:44
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
W sleepPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:43
compose< J, pow< s,-1 > > W
Definition: Units.h:770
The radio is sleeping, frame reception or transmission is not possible, power consumption is minimal...
Definition: IRadio.h:102
The radio medium is busy, a signal is detected but it is not strong enough to receive.
Definition: IRadio.h:155
RadioMode
This enumeration specifies the requested operational mode of the radio.
Definition: IRadio.h:91
virtual RadioMode getRadioMode() const =0
Returns the current radio mode, This is the same mode as the one emitted with the last radioModeChang...
W transmitterTransmittingPreamblePowerConsumption
Definition: StateBasedEpEnergyConsumer.h:53
The radio medium is busy, the radio is currently transmitting a signal.
Definition: IRadio.h:183
The radio medium is free, no signal is detected.
Definition: IRadio.h:148
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
IRadio * radio
Definition: StateBasedEpEnergyConsumer.h:58
virtual IRadioSignal::SignalPart getTransmittedSignalPart() const =0
Returns the signal part of the ongoing transmission that the transmitter is currently transmitting or...
virtual ReceptionState getReceptionState() const =0
Returns the current radio reception state.
The radio is prepared for simultaneous frame reception and transmission, power consumption is low whe...
Definition: IRadio.h:123
W receiverIdlePowerConsumption
Definition: StateBasedEpEnergyConsumer.h:45
The transmission state is undefined or meaningless.
Definition: IRadio.h:172
The radio is turned off, frame reception or transmission is not possible, power consumption is zero...
Definition: IRadio.h:96
W receiverReceivingDataPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:50
The radio is switching from one mode to another, frame reception or transmission is not possible...
Definition: IRadio.h:129
virtual TransmissionState getTransmissionState() const =0
Returns the current radio transmission state.
W receiverBusyPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:46
W powerConsumption
Definition: StateBasedEpEnergyConsumer.h:62
W receiverReceivingPreamblePowerConsumption
Definition: StateBasedEpEnergyConsumer.h:48
virtual IEnergySource* inet::physicallayer::StateBasedEpEnergyConsumer::getEnergySource ( ) const
inlineoverridevirtual

Returns the energy source that provides energy for this energy consumer.

This function never returns nullptr.

Implements inet::power::IEnergyConsumer.

70 { return energySource; }
IEpEnergySource * energySource
Definition: StateBasedEpEnergyConsumer.h:59
virtual W inet::physicallayer::StateBasedEpEnergyConsumer::getPowerConsumption ( ) const
inlineoverridevirtual

Returns the power consumption in the range [0, +infinity).

Implements inet::power::IEpEnergyConsumer.

71 { return powerConsumption; }
W powerConsumption
Definition: StateBasedEpEnergyConsumer.h:62
void inet::physicallayer::StateBasedEpEnergyConsumer::initialize ( int  stage)
overrideprotectedvirtual
28 {
29  cSimpleModule::initialize(stage);
30  if (stage == INITSTAGE_LOCAL) {
31  offPowerConsumption = W(par("offPowerConsumption"));
32  sleepPowerConsumption = W(par("sleepPowerConsumption"));
33  switchingPowerConsumption = W(par("switchingPowerConsumption"));
34  receiverIdlePowerConsumption = W(par("receiverIdlePowerConsumption"));
35  receiverBusyPowerConsumption = W(par("receiverBusyPowerConsumption"));
36  receiverReceivingPowerConsumption = W(par("receiverReceivingPowerConsumption"));
37  receiverReceivingPreamblePowerConsumption = W(par("receiverReceivingPreamblePowerConsumption"));
38  receiverReceivingHeaderPowerConsumption = W(par("receiverReceivingHeaderPowerConsumption"));
39  receiverReceivingDataPowerConsumption = W(par("receiverReceivingDataPowerConsumption"));
40  transmitterIdlePowerConsumption = W(par("transmitterIdlePowerConsumption"));
41  transmitterTransmittingPowerConsumption = W(par("transmitterTransmittingPowerConsumption"));
42  transmitterTransmittingPreamblePowerConsumption = W(par("transmitterTransmittingPreamblePowerConsumption"));
43  transmitterTransmittingHeaderPowerConsumption = W(par("transmitterTransmittingHeaderPowerConsumption"));
44  transmitterTransmittingDataPowerConsumption = W(par("transmitterTransmittingDataPowerConsumption"));
45  cModule *radioModule = getParentModule();
46  radioModule->subscribe(IRadio::radioModeChangedSignal, this);
47  radioModule->subscribe(IRadio::receptionStateChangedSignal, this);
48  radioModule->subscribe(IRadio::transmissionStateChangedSignal, this);
49  radioModule->subscribe(IRadio::receivedSignalPartChangedSignal, this);
50  radioModule->subscribe(IRadio::transmittedSignalPartChangedSignal, this);
51  radio = check_and_cast<IRadio *>(radioModule);
52  powerConsumption = W(0);
53  energySource = getModuleFromPar<IEpEnergySource>(par("energySourceModule"), this);
55  WATCH(powerConsumption);
56  }
57 }
W receiverReceivingPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:47
virtual void addEnergyConsumer(const IEnergyConsumer *energyConsumer)=0
Adds a new energy consumer to the energy source.
W transmitterIdlePowerConsumption
Definition: StateBasedEpEnergyConsumer.h:51
W transmitterTransmittingHeaderPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:54
W receiverReceivingHeaderPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:49
W transmitterTransmittingPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:52
W offPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:42
W transmitterTransmittingDataPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:55
W switchingPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:44
W sleepPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:43
compose< J, pow< s,-1 > > W
Definition: Units.h:770
IEpEnergySource * energySource
Definition: StateBasedEpEnergyConsumer.h:59
W transmitterTransmittingPreamblePowerConsumption
Definition: StateBasedEpEnergyConsumer.h:53
Local initializations.
Definition: InitStages.h:35
static simsignal_t receptionStateChangedSignal
This signal is emitted every time the radio reception state changes.
Definition: IRadio.h:66
static simsignal_t receivedSignalPartChangedSignal
This signal is emitted every time the received part changes.
Definition: IRadio.h:78
static simsignal_t transmittedSignalPartChangedSignal
This signal is emitted every time the transmitted part changes.
Definition: IRadio.h:84
IRadio * radio
Definition: StateBasedEpEnergyConsumer.h:58
W receiverIdlePowerConsumption
Definition: StateBasedEpEnergyConsumer.h:45
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
W receiverReceivingDataPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:50
W receiverBusyPowerConsumption
Definition: StateBasedEpEnergyConsumer.h:46
W powerConsumption
Definition: StateBasedEpEnergyConsumer.h:62
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
W receiverReceivingPreamblePowerConsumption
Definition: StateBasedEpEnergyConsumer.h:48
virtual int inet::physicallayer::StateBasedEpEnergyConsumer::numInitStages ( ) const
inlineoverrideprotectedvirtual
65 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::physicallayer::StateBasedEpEnergyConsumer::receiveSignal ( cComponent *  source,
simsignal_t  signal,
long  value,
cObject *  details 
)
overridevirtual
60 {
61  if (signal == IRadio::radioModeChangedSignal ||
66  {
69  }
70  else
71  throw cRuntimeError("Unknown signal");
72 }
const value_type & get() const
Definition: Units.h:89
static simsignal_t powerConsumptionChangedSignal
The signal that is used to publish power consumption changes.
Definition: IEpEnergyConsumer.h:43
static simsignal_t receptionStateChangedSignal
This signal is emitted every time the radio reception state changes.
Definition: IRadio.h:66
static simsignal_t receivedSignalPartChangedSignal
This signal is emitted every time the received part changes.
Definition: IRadio.h:78
static simsignal_t transmittedSignalPartChangedSignal
This signal is emitted every time the transmitted part changes.
Definition: IRadio.h:84
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
virtual W computePowerConsumption() const
Definition: StateBasedEpEnergyConsumer.cc:74
W powerConsumption
Definition: StateBasedEpEnergyConsumer.h:62
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54

Member Data Documentation

IEpEnergySource* inet::physicallayer::StateBasedEpEnergyConsumer::energySource = nullptr
protected

Referenced by initialize().

W inet::physicallayer::StateBasedEpEnergyConsumer::offPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::powerConsumption = W(NaN)
protected
IRadio* inet::physicallayer::StateBasedEpEnergyConsumer::radio = nullptr
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::receiverBusyPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::receiverIdlePowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::receiverReceivingDataPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::receiverReceivingHeaderPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::receiverReceivingPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::receiverReceivingPreamblePowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::sleepPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::switchingPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::transmitterIdlePowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::transmitterTransmittingDataPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::transmitterTransmittingHeaderPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::transmitterTransmittingPowerConsumption = W(NaN)
protected
W inet::physicallayer::StateBasedEpEnergyConsumer::transmitterTransmittingPreamblePowerConsumption = W(NaN)
protected

The documentation for this class was generated from the following files: