INET Framework for OMNeT++/OMNEST
inet::power::AlternatingEpEnergyConsumer Class Reference

This class implements a simple power based alternating energy consumer. More...

#include <AlternatingEpEnergyConsumer.h>

Inheritance diagram for inet::power::AlternatingEpEnergyConsumer:
inet::power::IEpEnergyConsumer inet::power::IEnergyConsumer

Public Member Functions

virtual ~AlternatingEpEnergyConsumer ()
 
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...
 
- 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 void handleMessage (cMessage *message) override
 
virtual void updatePowerConsumption ()
 
virtual void scheduleIntervalTimer ()
 

Protected Attributes

IEpEnergySourceenergySource = nullptr
 
cMessage * timer = nullptr
 
bool isSleeping = false
 
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 class implements a simple power based alternating energy consumer.

See the corresponding NED file for more details.

Constructor & Destructor Documentation

◆ ~AlternatingEpEnergyConsumer()

inet::power::AlternatingEpEnergyConsumer::~AlternatingEpEnergyConsumer ( )
virtual
17 {
18  cancelAndDelete(timer);
19 }

Member Function Documentation

◆ getEnergySource()

virtual IEnergySource* inet::power::AlternatingEpEnergyConsumer::getEnergySource ( ) const
inlineoverridevirtual

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

This function never returns nullptr.

Implements inet::power::IEnergyConsumer.

46 { return energySource; }

◆ getPowerConsumption()

virtual W inet::power::AlternatingEpEnergyConsumer::getPowerConsumption ( ) const
inlineoverridevirtual

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

Implements inet::power::IEpEnergyConsumer.

47 { return powerConsumption; }

◆ handleMessage()

void inet::power::AlternatingEpEnergyConsumer::handleMessage ( cMessage *  message)
overrideprotectedvirtual
39 {
40  if (message == timer) {
44  }
45  else
46  throw cRuntimeError("Unknown message");
47 }

◆ initialize()

void inet::power::AlternatingEpEnergyConsumer::initialize ( int  stage)
overrideprotectedvirtual
22 {
23  if (stage == INITSTAGE_LOCAL) {
24  const char *energySourceModule = par("energySourceModule");
25  energySource = dynamic_cast<IEpEnergySource *>(getModuleByPath(energySourceModule));
26  if (!energySource)
27  throw cRuntimeError("Energy source module '%s' not found", energySourceModule);
28  timer = new cMessage("timer");
31  WATCH(isSleeping);
32  WATCH(powerConsumption);
33  }
34  else if (stage == INITSTAGE_POWER)
36 }

◆ numInitStages()

virtual int inet::power::AlternatingEpEnergyConsumer::numInitStages ( ) const
inlineoverrideprotectedvirtual
36 { return NUM_INIT_STAGES; }

◆ scheduleIntervalTimer()

void inet::power::AlternatingEpEnergyConsumer::scheduleIntervalTimer ( )
protectedvirtual
56 {
57  scheduleAfter((isSleeping ? par("sleepInterval") : par("consumptionInterval")), timer);
58 }

Referenced by handleMessage(), and initialize().

◆ updatePowerConsumption()

void inet::power::AlternatingEpEnergyConsumer::updatePowerConsumption ( )
protectedvirtual
50 {
51  powerConsumption = isSleeping ? W(0) : W(par("powerConsumption"));
53 }

Referenced by handleMessage(), and initialize().

Member Data Documentation

◆ energySource

IEpEnergySource* inet::power::AlternatingEpEnergyConsumer::energySource = nullptr
protected

Referenced by initialize().

◆ isSleeping

bool inet::power::AlternatingEpEnergyConsumer::isSleeping = false
protected

◆ powerConsumption

W inet::power::AlternatingEpEnergyConsumer::powerConsumption = W(NaN)
protected

◆ timer

cMessage* inet::power::AlternatingEpEnergyConsumer::timer = nullptr
protected

The documentation for this class was generated from the following files:
inet::INITSTAGE_POWER
INET_API InitStage INITSTAGE_POWER
Initialization of the power model: energy storage, energy consumer, energy generator,...
inet::units::units::W
compose< J, pow< s, -1 > > W
Definition: Units.h:939
inet::power::IEnergySource::addEnergyConsumer
virtual void addEnergyConsumer(const IEnergyConsumer *energyConsumer)=0
Adds a new energy consumer to the energy source.
inet::power::AlternatingEpEnergyConsumer::updatePowerConsumption
virtual void updatePowerConsumption()
Definition: AlternatingEpEnergyConsumer.cc:49
inet::power::AlternatingEpEnergyConsumer::energySource
IEpEnergySource * energySource
Definition: AlternatingEpEnergyConsumer.h:28
inet::power::AlternatingEpEnergyConsumer::scheduleIntervalTimer
virtual void scheduleIntervalTimer()
Definition: AlternatingEpEnergyConsumer.cc:55
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::power::AlternatingEpEnergyConsumer::timer
cMessage * timer
Definition: AlternatingEpEnergyConsumer.h:29
inet::units::value::get
const value_type & get() const
Definition: Units.h:108
inet::power::IEpEnergySource::powerConsumptionChangedSignal
static simsignal_t powerConsumptionChangedSignal
The signal that is used to publish power consumption changes.
Definition: IEpEnergySource.h:32
inet::power::AlternatingEpEnergyConsumer::isSleeping
bool isSleeping
Definition: AlternatingEpEnergyConsumer.h:32
inet::power::AlternatingEpEnergyConsumer::powerConsumption
W powerConsumption
Definition: AlternatingEpEnergyConsumer.h:33