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

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

#include <StateBasedCcEnergyConsumer.h>

Inheritance diagram for inet::physicallayer::StateBasedCcEnergyConsumer:
inet::power::ICcEnergyConsumer inet::power::IEnergyConsumer

Public Member Functions

virtual IEnergySourcegetEnergySource () const override
 Returns the energy source that provides energy for this energy consumer. More...
 
virtual A getCurrentConsumption () const override
 Returns the current consumption in the range [0, +infinity). More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, long value, cObject *details) override
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, double 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 A computeCurrentConsumption () const
 

Protected Attributes

V minSupplyVoltage = V(NaN)
 
V maxSupplyVoltage = V(NaN)
 
A offCurrentConsumption = A(NaN)
 
A sleepCurrentConsumption = A(NaN)
 
A switchingCurrentConsumption = A(NaN)
 
A receiverIdleCurrentConsumption = A(NaN)
 
A receiverBusyCurrentConsumption = A(NaN)
 
A receiverReceivingCurrentConsumption = A(NaN)
 
A receiverReceivingPreambleCurrentConsumption = A(NaN)
 
A receiverReceivingHeaderCurrentConsumption = A(NaN)
 
A receiverReceivingDataCurrentConsumption = A(NaN)
 
A transmitterIdleCurrentConsumption = A(NaN)
 
A transmitterTransmittingCurrentConsumption = A(NaN)
 
A transmitterTransmittingPreambleCurrentConsumption = A(NaN)
 
A transmitterTransmittingHeaderCurrentConsumption = A(NaN)
 
A transmitterTransmittingDataCurrentConsumption = A(NaN)
 
IRadioradio = nullptr
 
ICcEnergySourceenergySource = nullptr
 
A currentConsumption = A(NaN)
 

Additional Inherited Members

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

Detailed Description

This is a simple radio energy consumer model.

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

Author
Levente Meszaros

Member Function Documentation

A inet::physicallayer::StateBasedCcEnergyConsumer::computeCurrentConsumption ( ) const
protectedvirtual

Referenced by receiveSignal().

89 {
90  IRadio::RadioMode radioMode = radio->getRadioMode();
91  if (radioMode == IRadio::RADIO_MODE_OFF)
92  return offCurrentConsumption;
93  else if (radioMode == IRadio::RADIO_MODE_SLEEP)
95  else if (radioMode == IRadio::RADIO_MODE_SWITCHING)
97  A currentConsumption = A(0);
100  if (radioMode == IRadio::RADIO_MODE_RECEIVER || radioMode == IRadio::RADIO_MODE_TRANSCEIVER) {
101  if (receptionState == IRadio::RECEPTION_STATE_IDLE)
102  currentConsumption += receiverIdleCurrentConsumption;
103  else if (receptionState == IRadio::RECEPTION_STATE_BUSY)
104  currentConsumption += receiverBusyCurrentConsumption;
105  else if (receptionState == IRadio::RECEPTION_STATE_RECEIVING) {
106  auto part = radio->getReceivedSignalPart();
107  if (part == IRadioSignal::SIGNAL_PART_NONE)
108  ;
109  else if (part == IRadioSignal::SIGNAL_PART_WHOLE)
110  currentConsumption += receiverReceivingCurrentConsumption;
111  else if (part == IRadioSignal::SIGNAL_PART_PREAMBLE)
112  currentConsumption += receiverReceivingPreambleCurrentConsumption;
113  else if (part == IRadioSignal::SIGNAL_PART_HEADER)
114  currentConsumption += receiverReceivingHeaderCurrentConsumption;
115  else if (part == IRadioSignal::SIGNAL_PART_DATA)
116  currentConsumption += receiverReceivingDataCurrentConsumption;
117  else
118  throw cRuntimeError("Unknown received signal part");
119  }
120  else if (receptionState != IRadio::RECEPTION_STATE_UNDEFINED)
121  throw cRuntimeError("Unknown radio reception state");
122  }
123  if (radioMode == IRadio::RADIO_MODE_TRANSMITTER || radioMode == IRadio::RADIO_MODE_TRANSCEIVER) {
124  if (transmissionState == IRadio::TRANSMISSION_STATE_IDLE)
125  currentConsumption += transmitterIdleCurrentConsumption;
126  else if (transmissionState == IRadio::TRANSMISSION_STATE_TRANSMITTING) {
127  // TODO: add transmission power?
128  auto part = radio->getTransmittedSignalPart();
129  if (part == IRadioSignal::SIGNAL_PART_NONE)
130  ;
131  else if (part == IRadioSignal::SIGNAL_PART_WHOLE)
132  currentConsumption += transmitterTransmittingCurrentConsumption;
133  else if (part == IRadioSignal::SIGNAL_PART_PREAMBLE)
135  else if (part == IRadioSignal::SIGNAL_PART_HEADER)
137  else if (part == IRadioSignal::SIGNAL_PART_DATA)
138  currentConsumption += transmitterTransmittingDataCurrentConsumption;
139  else
140  throw cRuntimeError("Unknown transmitted signal part");
141  }
142  else if (transmissionState != IRadio::TRANSMISSION_STATE_UNDEFINED)
143  throw cRuntimeError("Unknown radio transmission state");
144  }
145  return currentConsumption;
146 }
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...
A receiverBusyCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:48
The radio medium state is unknown, reception state is meaningless, signal detection is not possible...
Definition: IRadio.h:142
value< double, units::A > A
Definition: Units.h:1051
TransmissionState
This enumeration specifies the transmission state of the radio.
Definition: IRadio.h:167
ReceptionState
This enumeration specifies the reception state of the radio.
Definition: IRadio.h:136
A receiverReceivingDataCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:52
A sleepCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:45
The radio is not transmitting a signal on the radio medium.
Definition: IRadio.h:178
The radio is prepared for frame transmission, frame reception is not possible, power consumption is l...
Definition: IRadio.h:116
A transmitterTransmittingCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:54
A receiverReceivingPreambleCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:50
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
IRadio * radio
Definition: StateBasedCcEnergyConsumer.h:60
virtual RadioMode getRadioMode() const =0
Returns the current radio mode, This is the same mode as the one emitted with the last radioModeChang...
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
A offCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:44
The radio is prepared for frame reception, frame transmission is not possible, power consumption is l...
Definition: IRadio.h:109
A transmitterTransmittingPreambleCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:55
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
A currentConsumption
Definition: StateBasedCcEnergyConsumer.h:64
A transmitterTransmittingDataCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:57
A transmitterTransmittingHeaderCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:56
A receiverIdleCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:47
The transmission state is undefined or meaningless.
Definition: IRadio.h:172
A receiverReceivingHeaderCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:51
The radio is turned off, frame reception or transmission is not possible, power consumption is zero...
Definition: IRadio.h:96
The radio is switching from one mode to another, frame reception or transmission is not possible...
Definition: IRadio.h:129
A receiverReceivingCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:49
virtual TransmissionState getTransmissionState() const =0
Returns the current radio transmission state.
A transmitterIdleCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:53
A switchingCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:46
virtual A inet::physicallayer::StateBasedCcEnergyConsumer::getCurrentConsumption ( ) const
inlineoverridevirtual

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

Implements inet::power::ICcEnergyConsumer.

73 { return currentConsumption; }
A currentConsumption
Definition: StateBasedCcEnergyConsumer.h:64
virtual IEnergySource* inet::physicallayer::StateBasedCcEnergyConsumer::getEnergySource ( ) const
inlineoverridevirtual

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

This function never returns nullptr.

Implements inet::power::IEnergyConsumer.

72 { return energySource; }
ICcEnergySource * energySource
Definition: StateBasedCcEnergyConsumer.h:61
void inet::physicallayer::StateBasedCcEnergyConsumer::initialize ( int  stage)
overrideprotectedvirtual
28 {
29  cSimpleModule::initialize(stage);
30  if (stage == INITSTAGE_LOCAL) {
31  minSupplyVoltage = V(par("minSupplyVoltage"));
32  maxSupplyVoltage = V(par("maxSupplyVoltage"));
33  offCurrentConsumption = A(par("offCurrentConsumption"));
34  sleepCurrentConsumption = A(par("sleepCurrentConsumption"));
35  switchingCurrentConsumption = A(par("switchingCurrentConsumption"));
36  receiverIdleCurrentConsumption = A(par("receiverIdleCurrentConsumption"));
37  receiverBusyCurrentConsumption = A(par("receiverBusyCurrentConsumption"));
38  receiverReceivingCurrentConsumption = A(par("receiverReceivingCurrentConsumption"));
39  receiverReceivingPreambleCurrentConsumption = A(par("receiverReceivingPreambleCurrentConsumption"));
40  receiverReceivingHeaderCurrentConsumption = A(par("receiverReceivingHeaderCurrentConsumption"));
41  receiverReceivingDataCurrentConsumption = A(par("receiverReceivingDataCurrentConsumption"));
42  transmitterIdleCurrentConsumption = A(par("transmitterIdleCurrentConsumption"));
43  transmitterTransmittingCurrentConsumption = A(par("transmitterTransmittingCurrentConsumption"));
44  transmitterTransmittingPreambleCurrentConsumption = A(par("transmitterTransmittingPreambleCurrentConsumption"));
45  transmitterTransmittingHeaderCurrentConsumption = A(par("transmitterTransmittingHeaderCurrentConsumption"));
46  transmitterTransmittingDataCurrentConsumption = A(par("transmitterTransmittingDataCurrentConsumption"));
47  cModule *radioModule = getParentModule();
48  radioModule->subscribe(IRadio::radioModeChangedSignal, this);
49  radioModule->subscribe(IRadio::receptionStateChangedSignal, this);
50  radioModule->subscribe(IRadio::transmissionStateChangedSignal, this);
51  radioModule->subscribe(IRadio::receivedSignalPartChangedSignal, this);
52  radioModule->subscribe(IRadio::transmittedSignalPartChangedSignal, this);
53  radio = check_and_cast<IRadio *>(radioModule);
54  const char *energySourceModule = par("energySourceModule");
55  energySource = check_and_cast<ICcEnergySource *>(getModuleByPath(energySourceModule));
57  check_and_cast<cModule *>(energySource)->subscribe(ICcEnergySource::currentConsumptionChangedSignal, this);
58  currentConsumption = A(0);
59  WATCH(currentConsumption);
60  }
61 }
ICcEnergySource * energySource
Definition: StateBasedCcEnergyConsumer.h:61
A receiverBusyCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:48
value< double, units::A > A
Definition: Units.h:1051
virtual void addEnergyConsumer(const IEnergyConsumer *energyConsumer)=0
Adds a new energy consumer to the energy source.
A receiverReceivingDataCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:52
A sleepCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:45
A transmitterTransmittingCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:54
V maxSupplyVoltage
Definition: StateBasedCcEnergyConsumer.h:43
A receiverReceivingPreambleCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:50
IRadio * radio
Definition: StateBasedCcEnergyConsumer.h:60
Local initializations.
Definition: InitStages.h:35
A offCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:44
compose< W, pow< A,-1 > > V
Definition: Units.h:772
V minSupplyVoltage
Definition: StateBasedCcEnergyConsumer.h:42
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
A transmitterTransmittingPreambleCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:55
static simsignal_t transmittedSignalPartChangedSignal
This signal is emitted every time the transmitted part changes.
Definition: IRadio.h:84
A currentConsumption
Definition: StateBasedCcEnergyConsumer.h:64
static simsignal_t currentConsumptionChangedSignal
The signal that is used to publish current consumption changes.
Definition: ICcEnergySource.h:40
A transmitterTransmittingDataCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:57
A transmitterTransmittingHeaderCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:56
A receiverIdleCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:47
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
A receiverReceivingHeaderCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:51
A receiverReceivingCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:49
A transmitterIdleCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:53
A switchingCurrentConsumption
Definition: StateBasedCcEnergyConsumer.h:46
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
virtual int inet::physicallayer::StateBasedCcEnergyConsumer::numInitStages ( ) const
inlineoverrideprotectedvirtual
67 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::physicallayer::StateBasedCcEnergyConsumer::receiveSignal ( cComponent *  source,
simsignal_t  signal,
long  value,
cObject *  details 
)
overridevirtual
64 {
65  if (signal == IRadio::radioModeChangedSignal ||
70  {
73  }
74  else
75  throw cRuntimeError("Unknown signal");
76 }
virtual A computeCurrentConsumption() const
Definition: StateBasedCcEnergyConsumer.cc:88
const value_type & get() const
Definition: Units.h:89
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
A currentConsumption
Definition: StateBasedCcEnergyConsumer.h:64
static simsignal_t transmissionStateChangedSignal
This signal is emitted every time the radio transmission state changes.
Definition: IRadio.h:72
static simsignal_t currentConsumptionChangedSignal
The signal that is used to publish current consumption changes.
Definition: ICcEnergyConsumer.h:40
static simsignal_t radioModeChangedSignal
This signal is emitted every time the radio mode changes.
Definition: IRadio.h:54
void inet::physicallayer::StateBasedCcEnergyConsumer::receiveSignal ( cComponent *  source,
simsignal_t  signal,
double  value,
cObject *  details 
)
overridevirtual
79 {
83  }
84  else
85  throw cRuntimeError("Unknown signal");
86 }
ICcEnergySource * energySource
Definition: StateBasedCcEnergyConsumer.h:61
virtual void setRadioMode(RadioMode radioMode)=0
Changes the current radio mode.
IRadio * radio
Definition: StateBasedCcEnergyConsumer.h:60
virtual V getOutputVoltage() const =0
Returns the output voltage in the ragne [0, +infinity).
V minSupplyVoltage
Definition: StateBasedCcEnergyConsumer.h:42
static simsignal_t currentConsumptionChangedSignal
The signal that is used to publish current consumption changes.
Definition: ICcEnergySource.h:40
The radio is turned off, frame reception or transmission is not possible, power consumption is zero...
Definition: IRadio.h:96

Member Data Documentation

A inet::physicallayer::StateBasedCcEnergyConsumer::currentConsumption = A(NaN)
protected
ICcEnergySource* inet::physicallayer::StateBasedCcEnergyConsumer::energySource = nullptr
protected

Referenced by initialize(), and receiveSignal().

V inet::physicallayer::StateBasedCcEnergyConsumer::maxSupplyVoltage = V(NaN)
protected

Referenced by initialize().

V inet::physicallayer::StateBasedCcEnergyConsumer::minSupplyVoltage = V(NaN)
protected

Referenced by initialize(), and receiveSignal().

A inet::physicallayer::StateBasedCcEnergyConsumer::offCurrentConsumption = A(NaN)
protected
IRadio* inet::physicallayer::StateBasedCcEnergyConsumer::radio = nullptr
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::receiverBusyCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::receiverIdleCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::receiverReceivingCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::receiverReceivingDataCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::receiverReceivingHeaderCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::receiverReceivingPreambleCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::sleepCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::switchingCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::transmitterIdleCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::transmitterTransmittingCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::transmitterTransmittingDataCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::transmitterTransmittingHeaderCurrentConsumption = A(NaN)
protected
A inet::physicallayer::StateBasedCcEnergyConsumer::transmitterTransmittingPreambleCurrentConsumption = A(NaN)
protected

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