MiXiM  2.3

A simple linear model of battery consumption. More...

#include <SimpleBattery.h>

Inheritance diagram for SimpleBattery:
Collaboration diagram for SimpleBattery:

List of all members.

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.
virtual HostState::States getState () const
 Current state of the battery.
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 () const
 get voltage (future support for non-voltage regulated h/w
double estimateResidualRelative () const
 current state of charge of the battery, relative to its rated nominal capacity [0..1]
double estimateResidualAbs () const
 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.
DeviceEntrydevices
 Array of different power consuming devices.
int registeredDevices
 Amount of currently registered devices.
simtime_t lastUpdateTime
cModule * host
 Pointer to host module.
battery parameters
double capmAh
 Actual capacity.
double nominalCapmAh
 Nominal capacity.
double voltage
 Voltage.
publishing of capacity to BatteryStats via the BB.
cMessage * publish
double publishDelta
simtime_t publishTime
BatteryStatebatteryState
 Holds the state of the battery.
publish of host failure notification

everyone should subscribe to this

HostState hostState
INTERNAL state
double capacity
double nominalCapacity
double residualCapacity
double lastPublishCapacity
simtime_t lifetime

Private Member Functions

 SimpleBattery (const SimpleBattery &)
 Copy constructor is not allowed.
SimpleBatteryoperator= (const SimpleBattery &)
 Assignment operator is not allowed.

Detailed Description

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.

Author:
Laura Marie Feeney
Karl Wessel (port for MiXiM)

Member Function Documentation

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.

{
  //does nothing yet
}
void SimpleBattery::initialize ( int  stage) [virtual]

Basic initialization for all modules.

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

References batteryState, capmAh, BatteryStats::catBatteryStateSignal, BaseModule::catHostStateSignal, devices, BaseModule::findHost(), host, simsignalwrap_t::initialize(), nominalCapmAh, numDevices, registeredDevices, residualVec, resolution, BatteryState::set(), HostState::set(), 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" << std::endl;
    debugEV << "publishDelta = " << publishDelta * 100 << "%, publishTime = "
    << publishTime << "s, resolution = " << resolution << "sec"
    << std::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
    // periodically publish residual capacity on batteryCat
    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();

    host = findHost();
  }
  else if (stage == 1) {
    hostState.set(HostState::ACTIVE);
    emit(catHostStateSignal.initialize(), &hostState);

    if (publishDelta < 1 || publishTime> 0 ) {
      batteryState->set(residualCapacity);
      emit(BatteryStats::catBatteryStateSignal.initialize(), batteryState);
    }
    else {
      BatteryStats::catBatteryStateSignal.initialize();
    }
  }
}

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