A simple linear model of battery consumption. More...
#include <SimpleBattery.h>
Inherits BaseBattery.
Public Member Functions | |
virtual void | initialize (int) |
Basic initialization for all modules. | |
virtual void | handleMessage (cMessage *) |
virtual void | handleHostState (const HostState &state) |
Called whenever the hosts state changes. | |
virtual void | finish () |
virtual int | registerDevice (const std::string &name, int numAccounts) |
Registers a power device by creating a new DeviceEntry for it. | |
virtual void | draw (int drainID, DrawAmount &amount, int activity) |
Draws either a certain amount of energy in mWs or a defined current in mA over time, depending on passed DrawAmount. | |
State-of-charge interface | |
Other host modules should use these interfaces to obtain the state-of-charge of the battery. Do NOT use BatteryState interfaces, which should be used only by Battery Stats modules. | |
double | getVoltage () |
get voltage (future support for non-voltage regulated h/w | |
double | estimateResidualRelative () |
current state of charge of the battery, relative to its rated nominal capacity [0..1] | |
double | estimateResidualAbs () |
current state of charge of the battery (mW-s) | |
Protected Types | |
enum | msgType { AUTO_UPDATE, PUBLISH } |
Self message kinds used by the battery. | |
Protected Member Functions | |
virtual void | deductAndCheck () |
Protected Attributes | |
int | numDevices |
The maximum amount of different power drawing devices. | |
simtime_t | resolution |
Debit battery at least once every resolution seconds. | |
cMessage * | timeout |
cOutVector | residualVec |
Ouput vector tracking the residual capacity. | |
DeviceEntry * | devices |
Array of different power consuming devices. | |
int | registeredDevices |
Amount of currently registered devices. | |
simtime_t | lastUpdateTime |
battery parameters | |
double | capmAh |
Actual capacity. | |
double | nominalCapmAh |
Nominal capacity. | |
double | voltage |
Voltage. | |
publishing of capacity to BatteryStats via the BB. | |
int | batteryCat |
cMessage * | publish |
double | publishDelta |
simtime_t | publishTime |
BatteryState * | batteryState |
Holds the state of the battery. | |
publish of host failure notification | |
int | scopeHost |
int | hostStateCat |
Stores the category of the HostState. | |
HostState | hostState |
INTERNAL state | |
double | capacity |
double | nominalCapacity |
double | residualCapacity |
double | lastPublishCapacity |
simtime_t | lifetime |
A simple linear model of battery consumption.
See SimpleBattery.ned for parameters
Simple Battery receives DrawMsg's from one or more devices, updates residual capacity (total current * voltage * time), publishes HostState notification on battery depletion, and provides time series and summary information to Battery Stats module.
Definition at line 39 of file SimpleBattery.h.
void SimpleBattery::handleHostState | ( | const HostState & | state | ) | [virtual] |
Called whenever the hosts state changes.
Default implementation of this method throws an error whenever the host state changes and the "notAffectedbyHostState" variable is not explicitly set. This is because every module of a host has to make sure to react well to changes in the host state. Or it has to explicitly set its parameter "notAffectedbyHostState" to true.
Reimplemented from BaseModule.
Definition at line 231 of file SimpleBattery.cc.
{
//does nothing yet
}
void SimpleBattery::initialize | ( | int | stage | ) | [virtual] |
Basic initialization for all modules.
Subscription to Blackboard should be in stage==0, and firing notifications in stage==1 or later.
NOTE: You have to call this in the initialize() function of the inherited class!
Reimplemented from BaseModule.
Definition at line 28 of file SimpleBattery.cc.
References batteryState, capmAh, devices, BaseModule::findHost(), Blackboard::getCategory(), hostStateCat, nominalCapmAh, numDevices, Blackboard::publishBBItem(), registeredDevices, residualVec, resolution, BatteryState::set(), HostState::set(), BaseModule::utility, and voltage.
{ BaseBattery::initialize(stage); if (stage == 0) { voltage = par("voltage"); nominalCapmAh = par("nominal"); if (nominalCapmAh <= 0) { error("invalid nominal capacity value"); } capmAh = par("capacity"); // Publish capacity to BatteryStats every publishTime (if > 0) and // whenever capacity has changed by publishDelta (if < 100%). publishTime = 0; publishTime = par("publishTime"); if (publishTime > 0) { publish = new cMessage("publish", PUBLISH); publish->setSchedulingPriority(2000); scheduleAt(simTime() + publishTime, publish); } publishDelta = 1; publishDelta = par("publishDelta"); if (publishDelta < 0 || publishDelta > 1) { error("invalid publishDelta value"); } resolution = par("resolution"); debugEV<< "capacity = " << capmAh << "mA-h (nominal = " << nominalCapmAh << ") at " << voltage << "V" << endl; debugEV << "publishDelta = " << publishDelta * 100 << "%, publishTime = " << publishTime << "s, resolution = " << resolution << "sec" << endl; capacity = capmAh * 60 * 60 * voltage; // use mW-sec internally nominalCapacity = nominalCapmAh * 60 * 60 * voltage; batteryState = new BatteryState(nominalCapacity); residualCapacity = lastPublishCapacity = capacity; lifetime = -1; // -1 means not dead // DISable by default (use BatteryStats for data collection) residualVec.disable(); residualVec.setName("residualCapacity"); residualVec.record(residualCapacity); timeout = new cMessage("auto-update", AUTO_UPDATE); timeout->setSchedulingPriority(500); scheduleAt(simTime() + resolution, timeout); // publish battery depletion on hostStateCat scopeHost = (this->findHost())->getId(); hostStateCat = utility->getCategory(&hostState); // periodically publish residual capacity on batteryCat if (publishDelta < 1 || publishTime> 0) batteryCat = utility->getCategory(batteryState); numDevices = hasPar("numDevices") ? par("numDevices") : 0; if (numDevices == 0) { EV << "Warning: no devices attached to battery\n"; } registeredDevices = 0; devices = new DeviceEntry[numDevices]; lastUpdateTime = simTime(); } if (stage == 1) { hostState.set(HostState::ACTIVE); utility->publishBBItem(hostStateCat, &hostState, scopeHost); if (publishDelta < 1 || publishTime> 0 ) { batteryState->set(residualCapacity); utility->publishBBItem(batteryCat, batteryState, scopeHost); } } }