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

#include <SimpleCcBattery.h>

Inheritance diagram for inet::power::SimpleCcBattery:
inet::power::CcEnergyStorageBase inet::power::CcEnergySourceBase inet::power::CcEnergySinkBase inet::power::ICcEnergyStorage inet::power::IEnergyStorage inet::power::ICcEnergySink inet::power::ICcEnergySource inet::power::ICcEnergySink inet::power::EnergySinkBase inet::power::ICcEnergySource inet::power::EnergySourceBase

Public Member Functions

virtual V getNominalVoltage () const override
 Returns the open circuit voltage in the range [0, +infinity). More...
 
virtual V getOutputVoltage () const override
 Returns the output voltage in the ragne [0, +infinity). More...
 
virtual A getTotalCurrentConsumption () const override
 Returns the total current consumption in the range [0, +infinity). More...
 
virtual A getTotalCurrentGeneration () const override
 Returns the total current generation in the range [0, +infinity). More...
 
virtual C getNominalChargeCapacity () const override
 Returns the nominal charge capacity in the range [0, +infinity). More...
 
virtual C getResidualChargeCapacity () const override
 Returns the residual charge capacity in the range [0, nominalCapacity]. More...
 
- Public Member Functions inherited from inet::power::CcEnergyStorageBase
virtual void addEnergyConsumer (const IEnergyConsumer *energyConsumer) override
 Adds a new energy consumer to the energy source. More...
 
virtual void removeEnergyConsumer (const IEnergyConsumer *energyConsumer) override
 Removes a previously added energy consumer from this energy source. More...
 
virtual void addEnergyGenerator (const IEnergyGenerator *energyGenerator) override
 Adds a new energy generator to the energy sink. More...
 
virtual void removeEnergyGenerator (const IEnergyGenerator *energyGenerator) override
 Removes a previously added energy generator from this energy sink. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, double value, cObject *details) override
 
- Public Member Functions inherited from inet::power::EnergySourceBase
virtual int getNumEnergyConsumers () const override
 Returns the number of energy consumers in the range [0, +infinity). More...
 
virtual const IEnergyConsumergetEnergyConsumer (int index) const override
 Returns the energy consumer for the provided index. More...
 
- Public Member Functions inherited from inet::power::IEnergySource
virtual ~IEnergySource ()
 
- Public Member Functions inherited from inet::power::EnergySinkBase
virtual int getNumEnergyGenerators () const override
 Returns the number of energy generators in the range [0, +infinity). More...
 
virtual const IEnergyGeneratorgetEnergyGenerator (int index) const override
 Returns the energy generator for the provided index. More...
 
- Public Member Functions inherited from inet::power::IEnergySink
virtual ~IEnergySink ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void updateTotalCurrentConsumption () override
 
virtual void updateTotalCurrentGeneration () override
 
virtual void setResidualCapacity (C newResidualCapacity)
 
virtual void updateResidualCapacity ()
 
virtual void executeNodeOperation (C newResidualCapacity)
 
- Protected Member Functions inherited from inet::power::CcEnergyStorageBase
void initialize (int stage) override
 
- Protected Member Functions inherited from inet::power::CcEnergySourceBase
virtual A computeTotalCurrentConsumption () const
 
- Protected Member Functions inherited from inet::power::CcEnergySinkBase
virtual A computeTotalCurrentGeneration () const
 

Protected Attributes

C nominalCapacity = C(NaN)
 
V nominalVoltage = V(NaN)
 
Ohm internalResistance = Ohm(NaN)
 
C residualCapacity = C(NaN)
 
simtime_t lastResidualCapacityUpdate = -1
 
LifecycleControllerlifecycleController = nullptr
 
cModule * networkNode = nullptr
 
NodeStatusnodeStatus = nullptr
 
- Protected Attributes inherited from inet::power::CcEnergySourceBase
A totalCurrentConsumption = A(NaN)
 
- Protected Attributes inherited from inet::power::EnergySourceBase
std::vector< const IEnergyConsumer * > energyConsumers
 
- Protected Attributes inherited from inet::power::CcEnergySinkBase
A totalCurrentGeneration = A(NaN)
 
- Protected Attributes inherited from inet::power::EnergySinkBase
std::vector< const IEnergyGenerator * > energyGenerators
 

Additional Inherited Members

- Static Public Attributes inherited from inet::power::ICcEnergySource
static simsignal_t currentConsumptionChangedSignal = cComponent::registerSignal("currentConsumptionChanged")
 The signal that is used to publish current consumption changes. More...
 
- Static Public Attributes inherited from inet::power::ICcEnergySink
static simsignal_t currentGenerationChangedSignal = cComponent::registerSignal("currentGenerationChanged")
 The signal that is used to publish current generation changes. More...
 
- Static Public Attributes inherited from inet::power::ICcEnergyStorage
static simsignal_t residualChargeCapacityChangedSignal = cComponent::registerSignal("residualChargeCapacityChanged")
 The signal that is used to publish residual charge capacity changes also including when the energy storage becomes completely depleted or charged. More...
 

Member Function Documentation

void inet::power::SimpleCcBattery::executeNodeOperation ( C  newResidualCapacity)
protectedvirtual

Referenced by setResidualCapacity().

89 {
90  if (nodeStatus->getState() == NodeStatus::UP && newResidualCapacity <= C(0)) {
91  EV_WARN << "Battery failed" << endl;
93  NodeCrashOperation *operation = new NodeCrashOperation();
94  operation->initialize(networkNode, params);
96  }
97 }
std::map< std::string, std::string > StringMap
Definition: LifecycleOperation.h:37
compose< s, A > C
Definition: Units.h:771
LifecycleController * lifecycleController
Definition: SimpleCcBattery.h:40
NodeStatus * nodeStatus
Definition: SimpleCcBattery.h:42
cModule * networkNode
Definition: SimpleCcBattery.h:41
virtual bool initiateOperation(LifecycleOperation *operation, IDoneCallback *completionCallback=nullptr)
Initiate an operation.
Definition: LifecycleController.cc:87
virtual State getState() const
Definition: NodeStatus.h:48
Definition: NodeStatus.h:40
virtual C inet::power::SimpleCcBattery::getNominalChargeCapacity ( ) const
inlineoverridevirtual

Returns the nominal charge capacity in the range [0, +infinity).

It specifies the maximum amount of charge that the energy storage can contain.

Implements inet::power::ICcEnergyStorage.

62 { return nominalCapacity; }
C nominalCapacity
Definition: SimpleCcBattery.h:32
virtual V inet::power::SimpleCcBattery::getNominalVoltage ( ) const
inlineoverridevirtual

Returns the open circuit voltage in the range [0, +infinity).

Implements inet::power::ICcEnergySource.

56 { return nominalVoltage; }
V nominalVoltage
Definition: SimpleCcBattery.h:33
virtual V inet::power::SimpleCcBattery::getOutputVoltage ( ) const
inlineoverridevirtual

Returns the output voltage in the ragne [0, +infinity).

Implements inet::power::ICcEnergySource.

Ohm internalResistance
Definition: SimpleCcBattery.h:34
A totalCurrentGeneration
Definition: CcEnergySinkBase.h:32
V nominalVoltage
Definition: SimpleCcBattery.h:33
A totalCurrentConsumption
Definition: CcEnergySourceBase.h:32
virtual C inet::power::SimpleCcBattery::getResidualChargeCapacity ( ) const
inlineoverridevirtual

Returns the residual charge capacity in the range [0, nominalCapacity].

It specifies the amount of charge that the energy storage contains at the moment.

Implements inet::power::ICcEnergyStorage.

63 { return residualCapacity; }
C residualCapacity
Definition: SimpleCcBattery.h:37
virtual A inet::power::SimpleCcBattery::getTotalCurrentConsumption ( ) const
inlineoverridevirtual

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

Reimplemented from inet::power::CcEnergySourceBase.

59 { return totalCurrentConsumption; }
A totalCurrentConsumption
Definition: CcEnergySourceBase.h:32
virtual A inet::power::SimpleCcBattery::getTotalCurrentGeneration ( ) const
inlineoverridevirtual

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

Reimplemented from inet::power::CcEnergySinkBase.

60 { return totalCurrentGeneration; }
A totalCurrentGeneration
Definition: CcEnergySinkBase.h:32
void inet::power::SimpleCcBattery::initialize ( int  stage)
overrideprotectedvirtual
30 {
32  if (stage == INITSTAGE_LOCAL) {
33  nominalCapacity = C(par("nominalCapacity"));
34  nominalVoltage = V(par("nominalVoltage"));
35  internalResistance = Ohm(par("internalResistance"));
37  if (networkNode != nullptr) {
38  nodeStatus = dynamic_cast<NodeStatus *>(networkNode->getSubmodule("status"));
39  if (!nodeStatus)
40  throw cRuntimeError("Cannot find node status");
41  lifecycleController = dynamic_cast<LifecycleController *>(getModuleByPath("lifecycleController"));
43  throw cRuntimeError("Cannot find lifecycle controller");
44  }
45  setResidualCapacity(C(par("initialCapacity")));
46  WATCH(residualCapacity);
47  }
48 }
virtual void setResidualCapacity(C newResidualCapacity)
Definition: SimpleCcBattery.cc:62
Ohm internalResistance
Definition: SimpleCcBattery.h:34
compose< s, A > C
Definition: Units.h:771
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
void initialize(int stage) override
Definition: CcEnergyStorageBase.cc:24
V nominalVoltage
Definition: SimpleCcBattery.h:33
compose< W, pow< A,-1 > > V
Definition: Units.h:772
LifecycleController * lifecycleController
Definition: SimpleCcBattery.h:40
compose< V, pow< A,-1 > > Ohm
Definition: Units.h:774
NodeStatus * nodeStatus
Definition: SimpleCcBattery.h:42
C nominalCapacity
Definition: SimpleCcBattery.h:32
cModule * networkNode
Definition: SimpleCcBattery.h:41
C residualCapacity
Definition: SimpleCcBattery.h:37
void inet::power::SimpleCcBattery::setResidualCapacity ( C  newResidualCapacity)
protectedvirtual

Referenced by initialize(), and updateResidualCapacity().

63 {
64  residualCapacity = newResidualCapacity;
65  lastResidualCapacityUpdate = simTime();
66  if (residualCapacity == C(0))
67  EV_WARN << "Battery depleted" << endl;
69  EV_INFO << "Battery charged" << endl;
70  if (networkNode != nullptr)
71  executeNodeOperation(newResidualCapacity);
73 }
static simsignal_t residualChargeCapacityChangedSignal
The signal that is used to publish residual charge capacity changes also including when the energy st...
Definition: ICcEnergyStorage.h:43
const value_type & get() const
Definition: Units.h:89
compose< s, A > C
Definition: Units.h:771
virtual void executeNodeOperation(C newResidualCapacity)
Definition: SimpleCcBattery.cc:88
simtime_t lastResidualCapacityUpdate
Definition: SimpleCcBattery.h:38
C nominalCapacity
Definition: SimpleCcBattery.h:32
cModule * networkNode
Definition: SimpleCcBattery.h:41
C residualCapacity
Definition: SimpleCcBattery.h:37
void inet::power::SimpleCcBattery::updateResidualCapacity ( )
protectedvirtual

Referenced by updateTotalCurrentConsumption(), and updateTotalCurrentGeneration().

76 {
77  simtime_t currentTime = simTime();
78  if (currentTime != lastResidualCapacityUpdate) {
79  C newResidualCapacity = residualCapacity + s((currentTime - lastResidualCapacityUpdate).dbl()) * (totalCurrentGeneration - totalCurrentConsumption);
80  if (newResidualCapacity < C(0))
81  newResidualCapacity = C(0);
82  else if (newResidualCapacity > nominalCapacity)
83  newResidualCapacity = nominalCapacity;
84  setResidualCapacity(newResidualCapacity);
85  }
86 }
virtual void setResidualCapacity(C newResidualCapacity)
Definition: SimpleCcBattery.cc:62
A totalCurrentGeneration
Definition: CcEnergySinkBase.h:32
compose< s, A > C
Definition: Units.h:771
simtime_t lastResidualCapacityUpdate
Definition: SimpleCcBattery.h:38
C nominalCapacity
Definition: SimpleCcBattery.h:32
value< double, units::s > s
Definition: Units.h:1049
A totalCurrentConsumption
Definition: CcEnergySourceBase.h:32
C residualCapacity
Definition: SimpleCcBattery.h:37
void inet::power::SimpleCcBattery::updateTotalCurrentConsumption ( )
overrideprotectedvirtual

Reimplemented from inet::power::CcEnergyStorageBase.

51 {
54 }
virtual void updateResidualCapacity()
Definition: SimpleCcBattery.cc:75
virtual void updateTotalCurrentConsumption() override
Definition: CcEnergyStorageBase.cc:34
void inet::power::SimpleCcBattery::updateTotalCurrentGeneration ( )
overrideprotectedvirtual

Reimplemented from inet::power::CcEnergyStorageBase.

57 {
60 }
virtual void updateResidualCapacity()
Definition: SimpleCcBattery.cc:75
virtual void updateTotalCurrentGeneration() override
Definition: CcEnergyStorageBase.cc:40

Member Data Documentation

Ohm inet::power::SimpleCcBattery::internalResistance = Ohm(NaN)
protected

Referenced by initialize().

simtime_t inet::power::SimpleCcBattery::lastResidualCapacityUpdate = -1
protected
LifecycleController* inet::power::SimpleCcBattery::lifecycleController = nullptr
protected

Referenced by executeNodeOperation(), and initialize().

cModule* inet::power::SimpleCcBattery::networkNode = nullptr
protected
NodeStatus* inet::power::SimpleCcBattery::nodeStatus = nullptr
protected

Referenced by executeNodeOperation(), and initialize().

C inet::power::SimpleCcBattery::nominalCapacity = C(NaN)
protected
V inet::power::SimpleCcBattery::nominalVoltage = V(NaN)
protected

Referenced by initialize().

C inet::power::SimpleCcBattery::residualCapacity = C(NaN)
protected

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