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 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.

Author
Levente Meszaros

Constructor & Destructor Documentation

inet::power::AlternatingEpEnergyConsumer::~AlternatingEpEnergyConsumer ( )
virtual
27 {
28  cancelAndDelete(timer);
29 }
cMessage * timer
Definition: AlternatingEpEnergyConsumer.h:40

Member Function Documentation

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.

56 { return energySource; }
IEpEnergySource * energySource
Definition: AlternatingEpEnergyConsumer.h:39
virtual W inet::power::AlternatingEpEnergyConsumer::getPowerConsumption ( ) const
inlineoverridevirtual

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

Implements inet::power::IEpEnergyConsumer.

57 { return powerConsumption; }
W powerConsumption
Definition: AlternatingEpEnergyConsumer.h:44
void inet::power::AlternatingEpEnergyConsumer::handleMessage ( cMessage *  message)
overrideprotectedvirtual
48 {
49  if (message == timer) {
53  }
54  else
55  throw cRuntimeError("Unknown message");
56 }
virtual void scheduleIntervalTimer()
Definition: AlternatingEpEnergyConsumer.cc:64
bool isSleeping
Definition: AlternatingEpEnergyConsumer.h:43
cMessage * timer
Definition: AlternatingEpEnergyConsumer.h:40
virtual void updatePowerConsumption()
Definition: AlternatingEpEnergyConsumer.cc:58
void inet::power::AlternatingEpEnergyConsumer::initialize ( int  stage)
overrideprotectedvirtual
32 {
33  if (stage == INITSTAGE_LOCAL) {
34  const char *energySourceModule = par("energySourceModule");
35  energySource = dynamic_cast<IEpEnergySource *>(getModuleByPath(energySourceModule));
36  if (!energySource)
37  throw cRuntimeError("Energy source module '%s' not found", energySourceModule);
38  timer = new cMessage("timer");
42  WATCH(isSleeping);
43  WATCH(powerConsumption);
44  }
45 }
virtual void addEnergyConsumer(const IEnergyConsumer *energyConsumer)=0
Adds a new energy consumer to the energy source.
virtual void scheduleIntervalTimer()
Definition: AlternatingEpEnergyConsumer.cc:64
bool isSleeping
Definition: AlternatingEpEnergyConsumer.h:43
IEpEnergySource * energySource
Definition: AlternatingEpEnergyConsumer.h:39
W powerConsumption
Definition: AlternatingEpEnergyConsumer.h:44
Local initializations.
Definition: InitStages.h:35
cMessage * timer
Definition: AlternatingEpEnergyConsumer.h:40
virtual void updatePowerConsumption()
Definition: AlternatingEpEnergyConsumer.cc:58
void inet::power::AlternatingEpEnergyConsumer::scheduleIntervalTimer ( )
protectedvirtual

Referenced by handleMessage(), and initialize().

65 {
66  scheduleAt(simTime() + (isSleeping ? par("sleepInterval") : par("consumptionInterval")), timer);
67 }
bool isSleeping
Definition: AlternatingEpEnergyConsumer.h:43
cMessage * timer
Definition: AlternatingEpEnergyConsumer.h:40
void inet::power::AlternatingEpEnergyConsumer::updatePowerConsumption ( )
protectedvirtual

Referenced by handleMessage(), and initialize().

59 {
60  powerConsumption = isSleeping ? W(0) : W(par("powerConsumption"));
62 }
const value_type & get() const
Definition: Units.h:89
bool isSleeping
Definition: AlternatingEpEnergyConsumer.h:43
static simsignal_t powerConsumptionChangedSignal
The signal that is used to publish power consumption changes.
Definition: IEpEnergySource.h:43
compose< J, pow< s,-1 > > W
Definition: Units.h:770
W powerConsumption
Definition: AlternatingEpEnergyConsumer.h:44

Member Data Documentation

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

Referenced by initialize().

bool inet::power::AlternatingEpEnergyConsumer::isSleeping = false
protected
W inet::power::AlternatingEpEnergyConsumer::powerConsumption = W(NaN)
protected
cMessage* inet::power::AlternatingEpEnergyConsumer::timer = nullptr
protected

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