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

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

#include <AlternatingEpEnergyGenerator.h>

Inheritance diagram for inet::power::AlternatingEpEnergyGenerator:
inet::power::IEpEnergyGenerator inet::power::IEnergyGenerator

Public Member Functions

virtual ~AlternatingEpEnergyGenerator ()
 
virtual IEnergySinkgetEnergySink () const override
 Returns the energy sink that absorbs energy from this energy generator. More...
 
virtual W getPowerGeneration () const override
 Returns the power generation in the range [0, +infinity). More...
 
- Public Member Functions inherited from inet::power::IEnergyGenerator
virtual ~IEnergyGenerator ()
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *message) override
 
virtual void updatePowerGeneration ()
 
virtual void scheduleIntervalTimer ()
 

Protected Attributes

IEpEnergySinkenergySink = nullptr
 
cMessage * timer = nullptr
 
bool isSleeping = false
 
W powerGeneration = W(NaN)
 

Additional Inherited Members

- Static Public Attributes inherited from inet::power::IEpEnergyGenerator
static simsignal_t powerGenerationChangedSignal = cComponent::registerSignal("powerGenerationChanged")
 The signal that is used to publish power generation changes. More...
 

Detailed Description

This class implements a simple power based alternating energy generator.

See the corresponding NED file for more details.

Constructor & Destructor Documentation

◆ ~AlternatingEpEnergyGenerator()

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

Member Function Documentation

◆ getEnergySink()

virtual IEnergySink* inet::power::AlternatingEpEnergyGenerator::getEnergySink ( ) const
inlineoverridevirtual

Returns the energy sink that absorbs energy from this energy generator.

This function never returns nullptr.

Implements inet::power::IEnergyGenerator.

46 { return energySink; }

◆ getPowerGeneration()

virtual W inet::power::AlternatingEpEnergyGenerator::getPowerGeneration ( ) const
inlineoverridevirtual

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

Implements inet::power::IEpEnergyGenerator.

47 { return powerGeneration; }

◆ handleMessage()

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

◆ initialize()

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

◆ numInitStages()

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

◆ scheduleIntervalTimer()

void inet::power::AlternatingEpEnergyGenerator::scheduleIntervalTimer ( )
protectedvirtual
58 {
59  scheduleAfter((isSleeping ? par("sleepInterval") : par("generationInterval")), timer);
60 }

Referenced by handleMessage(), and initialize().

◆ updatePowerGeneration()

void inet::power::AlternatingEpEnergyGenerator::updatePowerGeneration ( )
protectedvirtual
50 {
51  powerGeneration = isSleeping ? W(0) : W(par("powerGeneration"));
53  auto text = "power: " + powerGeneration.str();
54  getDisplayString().setTagArg("t", 0, text.c_str());
55 }

Referenced by handleMessage(), and initialize().

Member Data Documentation

◆ energySink

IEpEnergySink* inet::power::AlternatingEpEnergyGenerator::energySink = nullptr
protected

Referenced by initialize().

◆ isSleeping

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

◆ powerGeneration

W inet::power::AlternatingEpEnergyGenerator::powerGeneration = W(NaN)
protected

◆ timer

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

The documentation for this class was generated from the following files:
inet::units::value::str
std::string str() const
Definition: Units.h:101
inet::INITSTAGE_POWER
INET_API InitStage INITSTAGE_POWER
Initialization of the power model: energy storage, energy consumer, energy generator,...
inet::power::AlternatingEpEnergyGenerator::timer
cMessage * timer
Definition: AlternatingEpEnergyGenerator.h:29
inet::units::units::W
compose< J, pow< s, -1 > > W
Definition: Units.h:939
inet::power::AlternatingEpEnergyGenerator::isSleeping
bool isSleeping
Definition: AlternatingEpEnergyGenerator.h:32
inet::power::AlternatingEpEnergyGenerator::updatePowerGeneration
virtual void updatePowerGeneration()
Definition: AlternatingEpEnergyGenerator.cc:49
inet::power::IEnergySink::addEnergyGenerator
virtual void addEnergyGenerator(const IEnergyGenerator *energyGenerator)=0
Adds a new energy generator to the energy sink.
inet::power::AlternatingEpEnergyGenerator::energySink
IEpEnergySink * energySink
Definition: AlternatingEpEnergyGenerator.h:28
inet::power::AlternatingEpEnergyGenerator::powerGeneration
W powerGeneration
Definition: AlternatingEpEnergyGenerator.h:33
inet::power::AlternatingEpEnergyGenerator::scheduleIntervalTimer
virtual void scheduleIntervalTimer()
Definition: AlternatingEpEnergyGenerator.cc:57
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::units::value::get
const value_type & get() const
Definition: Units.h:108
inet::power::IEpEnergySink::powerGenerationChangedSignal
static simsignal_t powerGenerationChangedSignal
The signal that is used to publish power generation changes.
Definition: IEpEnergySink.h:29