Extends PhyLayer by adding power consumption for tx, rx and idle. More...
#include <PhyLayerBattery.h>
Inherits PhyLayer.
Public Member Functions | |
virtual void | initialize (int stage) |
OMNeT++ initialization function. | |
virtual void | drawCurrent (double amount, int activity) |
Provides ability to draw power for the Decider. | |
virtual simtime_t | setRadioState (int rs) |
Captures radio switches to adjust power consumption. | |
Protected Types | |
enum | Activities { SLEEP_ACCT = 0, RX_ACCT, TX_ACCT, SWITCHING_ACCT, DECIDER_ACCT } |
Defines the power consuming activities (accounts) of the NIC. Should be the same as defined in the decider. | |
Protected Member Functions | |
virtual Decider * | getDeciderFromName (std::string name, ParameterMap ¶ms) |
Creates and returns an instance of the Decider with the specified name. | |
virtual Decider * | initializeDecider80211Battery (ParameterMap ¶ms) |
Initializes a new Decider80211Battery from the passed parameter map. | |
virtual Decider * | initializeDecider80211MultiChannel (ParameterMap ¶ms) |
Initializes a new Decider80211MultiChannel from the passed parameter map. | |
virtual double | calcTXCurrentForPacket (MacPkt *pkt, MacToPhyControlInfo *cInfo) |
Calculates the current needed for the transmission of the passed MacPkt. | |
virtual void | setRadioCurrent (int rs) |
Updates the actual current drawn for the passed state. | |
virtual void | setSwitchingCurrent (int from, int to) |
Updates the actual current drawn for switching between the passed states. | |
virtual void | handleUpperMessage (cMessage *msg) |
Checks the hosts state and draws txCurrent from battery. | |
virtual void | handleAirFrame (cMessage *msg) |
Checks if the the host state is on and prevents reception of AirFrames if not. | |
virtual void | handleHostState (const HostState &state) |
Captures changes in host state. | |
virtual void | finishRadioSwitching () |
Captures radio switches to adjust power consumption. | |
Protected Attributes | |
int | numActivities |
Number of power consuming activities (accounts). | |
The different currents in mA. | |
double | sleepCurrent |
double | rxCurrent |
double | decodingCurrentDelta |
double | txCurrent |
The different switching state currents in mA. | |
double | setupRxCurrent |
double | setupTxCurrent |
double | rxTxCurrent |
double | txRxCurrent |
Extends PhyLayer by adding power consumption for tx, rx and idle.
Does two things, first before sending messages to the channel or receiving messages from the channel it checks the hosts current state. If the host is not able to send or the receive (e.g. no power) the messages are dropped.
Further it draws a current depending on the current radio state. For this it captures every call to "setRadioState()" and changes the current to previously set default values according to the new radios state. There are different currents for TX, RX, SLEEP and SWITCHING state. Its also possible to override "calcTXCurrentForPacket()" to calculate the current used during TX depending on the actual TX power instead of using the default value.
Does also provide battery access to the Decider by implementing DeciderToPhyInterfaces "drawCurrent()"-method. Using this method the Decider can define a current delta which is applied to the RX current during this radio state. This is meant to be used if the Decider wants to define different currents for "listening" and "decoding" phases in RX state.
Defines initialization for "Decider80211Battery".
Definition at line 53 of file PhyLayerBattery.h.
virtual double PhyLayerBattery::calcTXCurrentForPacket | ( | MacPkt * | pkt, | |
MacToPhyControlInfo * | cInfo | |||
) | [inline, protected, virtual] |
Calculates the current needed for the transmission of the passed MacPkt.
A return value below or equal zero is ignored and the default txCurrent is used instead.
Sub classing modules can override this method if they don't want to use a default TX-current for every transmission but a current depending on the actual used TX power for a packet.
Definition at line 115 of file PhyLayerBattery.h.
Referenced by handleUpperMessage().
{ return -1.0; }
void PhyLayerBattery::drawCurrent | ( | double | amount, | |
int | activity | |||
) | [virtual] |
Provides ability to draw power for the Decider.
Method is defined in "DeciderToPhyInterface".
Note: This method should only be used by the Decider to draw power. The phy layer itself should call instead its protected method BatteryAccess::drawCurrent()!
Reimplemented from BasePhyLayer.
Definition at line 83 of file PhyLayerBattery.cc.
References Radio::getCurrentState(), and BasePhyLayer::radio.
Referenced by handleUpperMessage(), setRadioCurrent(), and setSwitchingCurrent().
{ if(radio->getCurrentState() == Radio::RX) { if(amount != 0.0) { BatteryAccess::drawCurrent(rxCurrent + amount, DECIDER_ACCT + activity); } else { BatteryAccess::drawCurrent(rxCurrent, RX_ACCT); } } else { opp_warning("Decider wanted to change power consumption while radio not in state RX."); } }
Decider * PhyLayerBattery::getDeciderFromName | ( | std::string | name, | |
ParameterMap & | params | |||
) | [protected, virtual] |
Creates and returns an instance of the Decider with the specified name.
Is able to initialize the following Deciders:
Reimplemented from PhyLayer.
Definition at line 48 of file PhyLayerBattery.cc.
References initializeDecider80211Battery(), and initializeDecider80211MultiChannel().
{ if(name == "Decider80211Battery") { return initializeDecider80211Battery(params); } else if(name == "Decider80211MultiChannel") { return initializeDecider80211MultiChannel(params); } return PhyLayer::getDeciderFromName(name, params); }
void PhyLayerBattery::handleAirFrame | ( | cMessage * | msg | ) | [protected, virtual] |
Checks if the the host state is on and prevents reception of AirFrames if not.
Calls the base classes overriden method for normal handling.
Reimplemented from BasePhyLayer.
Definition at line 114 of file PhyLayerBattery.cc.
References HostState::get(), BaseUtility::getHostState(), and BaseModule::utility.
{ if (utility->getHostState().get() == HostState::FAILED) { coreEV<< "host has FAILED, dropping msg " << msg->getName() << endl; delete msg; return; } PhyLayer::handleAirFrame(msg); }
void PhyLayerBattery::handleHostState | ( | const HostState & | state | ) | [protected, virtual] |
Captures changes in host state.
Note: Does not yet cancel any ongoing transmissions if the state changes to off.
Definition at line 126 of file PhyLayerBattery.cc.
References HostState::FAILED, and HostState::get().
{ // handles only battery consumption HostState::States hostState = state.get(); switch (hostState) { case HostState::FAILED: EV<< "t = " << simTime() << " host state FAILED" << endl; // it would be good to create a radioState OFF, as well break; default: break; } }
void PhyLayerBattery::handleUpperMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Checks the hosts state and draws txCurrent from battery.
Prevents sending of AirFrames if the hosts state is not on. Sets current power consumption for TX mode. Calls the base classes overriden method for normal handling.
Reimplemented from BasePhyLayer.
Definition at line 95 of file PhyLayerBattery.cc.
References calcTXCurrentForPacket(), drawCurrent(), HostState::get(), BaseUtility::getHostState(), and BaseModule::utility.
{ if (utility->getHostState().get() == HostState::FAILED) { coreEV<< "host has FAILED, dropping msg " << msg->getName() << endl; delete msg; return; } MacPkt* pkt = static_cast<MacPkt*>(msg); MacToPhyControlInfo* cInfo = static_cast<MacToPhyControlInfo*>(pkt->getControlInfo()); double current = calcTXCurrentForPacket(pkt, cInfo); if(current > 0) { BatteryAccess::drawCurrent(current, TX_ACCT); } PhyLayer::handleUpperMessage(msg); }
void PhyLayerBattery::initialize | ( | int | stage | ) | [virtual] |
OMNeT++ initialization function.
Read simple parameters. Read and parse xml file for decider and analogue models configuration.
Reimplemented from BasePhyLayer.
Definition at line 21 of file PhyLayerBattery.cc.
References Radio::getCurrentState(), numActivities, BasePhyLayer::radio, BatteryAccess::registerWithBattery(), and setRadioCurrent().
{ PhyLayer::initialize(stage); if (stage == 0) { numActivities = hasPar("numActivities") ? par("numActivities").longValue() : 5; /* parameters belong to the NIC, not just phy layer * * if/when variable transmit power is supported, txCurrent * should be specified as an xml table of available transmit * power levels and corresponding txCurrent */ sleepCurrent = rxCurrent = decodingCurrentDelta = txCurrent = 0; setupRxCurrent = setupTxCurrent = rxTxCurrent = txRxCurrent = 0; sleepCurrent = getParentModule()->par( "sleepCurrent" ); rxCurrent = getParentModule()->par( "rxCurrent" ); decodingCurrentDelta = getParentModule()->par( "decodingCurrentDelta" ); txCurrent = getParentModule()->par( "txCurrent" ); setupRxCurrent = getParentModule()->par( "setupRxCurrent" ); setupTxCurrent = getParentModule()->par( "setupTxCurrent" ); rxTxCurrent = getParentModule()->par( "rxTxCurrent" ); txRxCurrent = getParentModule()->par( "txRxCurrent" ); } else { registerWithBattery("physical layer", numActivities); setRadioCurrent(radio->getCurrentState()); //BatteryAccess::drawCurrent(rxCurrent, RX_ACCT); } }