Public Member Functions | Protected Member Functions | Protected Attributes

SamplePhyLayer Class Reference
[phyLayer - physical layer modulesAnalogueModels example - Classes from the AnalogueModels example]

Simple PhyLayer sub class which is just responsible for creating and initialising its own AnalogueModels and Decider. More...

#include <SamplePhyLayer.h>

Inherits PhyLayer.

Collaboration diagram for SamplePhyLayer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void initialize (int stage)
 OMNeT++ initialization function.
virtual void handleMessage (cMessage *msg)
 Normally a sub-classed phy-layer doesn't has to implement this method. We are only doing this to display some messages telling the current state.

Protected Member Functions

virtual AnalogueModelgetAnalogueModelFromName (std::string name, ParameterMap &params)
 This method is called by the PhyLayer to initialize the AnalogueModels read from the config.xml.
AnalogueModelcreateRandomFreqTimeModel (ParameterMap &params)
 Creates and initializes a RandomFreqTimeModel with the passed parameter values.
AnalogueModelcreateRandomFrequencyOnlyModel (ParameterMap &params)
 Creates and initializes a RandomFreqOnlyModel with the passed parameter values.
virtual DecidergetDeciderFromName (std::string name, ParameterMap &params)
 This method is called by the PhyLayer to initialize the Decider read from the config.xml.
void log (std::string msg)
template<class T >
std::string toString (const T &v)

Protected Attributes

int myIndex

Detailed Description

Simple PhyLayer sub class which is just responsible for creating and initialising its own AnalogueModels and Decider.

Initializing own AnalogueModels or Decider is the only task a PhyLayer- subclass will normally have to do. Everything else should be already done by the PhyLayer or should be implemented by writing your own Decider or AnalogueModels.

Definition at line 19 of file SamplePhyLayer.h.


Member Function Documentation

AnalogueModel * SamplePhyLayer::getAnalogueModelFromName ( std::string  name,
ParameterMap params 
) [protected, virtual]

This method is called by the PhyLayer to initialize the AnalogueModels read from the config.xml.

Every AnalogueModel which should be used by a Simulation using this class has to be known (and initialized) by either this method or one of the base methods (which means this method should call the base method to make them able to load the AnalogueModels known by them).

Reimplemented from PhyLayer.

Definition at line 97 of file SamplePhyLayer.cc.

References createRandomFreqTimeModel(), and createRandomFrequencyOnlyModel().

                                                                                            {

  if(name == "RandomFreqTimeModel")
    return createRandomFreqTimeModel(params);
  else if(name == "RandomFrequencyOnlyModel")
    return createRandomFrequencyOnlyModel(params);

  //If we couldn't create the passed analogue model, call the method
  //of our base class.
  //Note: even if all models defined in the xml-config can be handled
  //by this class method, there will be at least the call to create
  //the RadioStateAnalogueModel which in almost every case has to be done
  //by the PhyLayer.
  return PhyLayer::getAnalogueModelFromName(name, params);
}

Decider * SamplePhyLayer::getDeciderFromName ( std::string  name,
ParameterMap params 
) [protected, virtual]

This method is called by the PhyLayer to initialize the Decider read from the config.xml.

Every Decider which should be usable by a Simulation using this class has to be known by either this method or (one of) the base mthods.

Reimplemented from PhyLayer.

Definition at line 113 of file SamplePhyLayer.cc.

                                                                                {

  if(name == "ThresholdDecider"){
    ParameterMap::iterator it = params.find("threshold");
    if(it == params.end()){
      log("ERROR: No threshold parameter defined for ThresholdDecider!");
      return 0;
    }

    /*
     * The value for the deciders threshold should be checked here against
     * the value specified in ConnectionManager that stores the max/min valid value.
     *
     */

    return new ThresholdDecider(this, myIndex, it->second.doubleValue());
  }

  return 0;
}

void SamplePhyLayer::handleMessage ( cMessage *  msg  )  [virtual]

Normally a sub-classed phy-layer doesn't has to implement this method. We are only doing this to display some messages telling the current state.

Note: IF a subclass overrides this method it should make sure to call the base method.

Reimplemented from BasePhyLayer.

Definition at line 22 of file SamplePhyLayer.cc.

References BasePhyLayer::END_RECEIVE, BasePhyLayer::RECEIVING, and BasePhyLayer::START_RECEIVE.

                                                {
  if(msg->getKind() == AIR_FRAME) {
    AirFrame* frame = static_cast<AirFrame*>(msg);

    //normally a subclassed phylayer doesn't has to care about these
    //events, we only catch them to display some messages telling the
    //current state of the receiving process
    switch(frame->getState()) {
    case START_RECEIVE:
      if(frame->getSignal().getSignalStart() != simTime())
        log("Received delayed AirFrame (state=START_RECEIVE). Proceeding it directly to RECEIVING state");
      else
        log("Received AirFrame (state=START_RECEIVE). Proceeding it directly to RECEIVING state");
      break;

    case RECEIVING:
      log("Received scheduled AirFrame for further processing through the decider.");
      break;

    case END_RECEIVE:
      log("Last receive of scheduled AirFrame because AirFrame transmission is over. (state=END_RECEIVE");
      break;

    default:
      break;
    }
  }

  //IF a subclass of PhyLayer overrides the handleMessage method it should
  //make sure to call the base method.
  PhyLayer::handleMessage(msg);
}

void SamplePhyLayer::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 10 of file SamplePhyLayer.cc.

References BaseModule::findHost().

                                         {
  //call BasePhy's initialize
  PhyLayer::initialize(stage);

  if(stage == 0) {
    myIndex = findHost()->getIndex();

  } else if(stage == 1) {
    //Decider and AnalogueModels are created by the PhyLayer in this stage
  }
}

template<class T >
std::string SamplePhyLayer::toString ( const T &  v  )  [inline, protected]

Converts the passed value to a string. There has to be an implementation of the << operator for the type of the variable and std::ostream:

std::ostream& operator<<(std::ostream& o, const T& v)

Definition at line 58 of file SamplePhyLayer.h.

                                                   {
    std::ostringstream o;
    o << v;
    return o.str();
  };


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