Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ChannelControl Class Reference

#include <ChannelControl.h>

List of all members.


Detailed Description

Monitors which hosts are "in range".

Author:
Andras Varga
See also:
ChannelAccess


Public Types

typedef HostEntryHostRef
typedef std::vector< cModule * > ModuleList

Public Member Functions

HostRef registerHost (cModule *host, const Coord &initialPos)
 Registers the given host.
HostRef lookupHost (cModule *host)
 Returns the "handle" of a previously registered host.
void updateHostPosition (HostRef h, const Coord &pos)
 To be called when the host moved; updates proximity info.
const CoordgetHostPosition (HostRef h)
 Returns the host's position.
const ModuleListgetNeighbors (HostRef h)
 Get the list of modules in range of the given host.
double getCommunicationRange (HostRef h)
 Reads init parameters and calculates a maximal interference distance.
const CoordgetPgs ()
 Returns the playground size.

Protected Member Functions

void updateConnections (HostRef h)
virtual double calcInterfDist ()
 Calculate interference distance.
void updateDisplayString (cModule *playgroundMod)
 Set up playground module's display string.
virtual void initialize ()
 Reads init parameters and calculates a maximal interference distance.

Protected Attributes

typedef std::list< HostEntryHostList
HostList hosts
bool coreDebug
 Set debugging for the basic module.
Coord playgroundSize
 x and y size of the area the nodes are in (in meters)
double maxInterferenceDistance
 the biggest interference distance in the network.

Friends

std::ostream & operator<< (std::ostream &, const HostEntry &)

Classes

struct  HostEntry


Member Typedef Documentation

typedef HostEntry* ChannelControl::HostRef
 

typedef std::vector<cModule*> ChannelControl::ModuleList
 


Member Function Documentation

double ChannelControl::calcInterfDist  )  [protected, virtual]
 

Calculate interference distance.

Calculation of the interference distance based on the transmitter power, wavelength, pathloss coefficient and a threshold for the minimal receive Power

You may want to overwrite this function in order to do your own interference calculation

00081 {
00082     double SPEED_OF_LIGHT = 300000000.0;
00083     double interfDistance;
00084 
00085     //the carrier frequency used
00086     double carrierFrequency = par("carrierFrequency");
00087     //maximum transmission power possible
00088     double pMax = par("pMax");
00089     //signal attenuation threshold
00090     double sat = par("sat");
00091     //path loss coefficient
00092     double alpha = par("alpha");
00093 
00094     double waveLength = (SPEED_OF_LIGHT / carrierFrequency);
00095     //minimum power level to be able to physically receive a signal
00096     double minReceivePower = pow(10.0, sat / 10.0);
00097 
00098     interfDistance = pow(waveLength * waveLength * pMax /
00099                          (16.0 * M_PI * M_PI * minReceivePower), 1.0 / alpha);
00100 
00101     coreEV << "max interference distance:" << interfDistance << endl;
00102 
00103     return interfDistance;
00104 }

double ChannelControl::getCommunicationRange HostRef  h  )  [inline]
 

Reads init parameters and calculates a maximal interference distance.

00098                                             {
00099         return maxInterferenceDistance; // FIXME this is rather the max...
00100     }

const Coord& ChannelControl::getHostPosition HostRef  h  )  [inline]
 

Returns the host's position.

00092 {return h->pos;}

const ChannelControl::ModuleList & ChannelControl::getNeighbors HostRef  h  ) 
 

Get the list of modules in range of the given host.

00129 {
00130     if (!h->isModuleListValid)
00131     {
00132         h->neighborModules.clear();
00133         for (std::set<HostRef>::const_iterator it = h->neighbors.begin(); it != h->neighbors.end(); it++)
00134             h->neighborModules.push_back((*it)->host);
00135         h->isModuleListValid = true;
00136     }
00137     return h->neighborModules;
00138 }

const Coord* ChannelControl::getPgs  )  [inline]
 

Returns the playground size.

00103 {return &playgroundSize;}

void ChannelControl::initialize  )  [protected, virtual]
 

Reads init parameters and calculates a maximal interference distance.

Sets up the playgroundSize and calculates the maxInterferenceDistance

calcInterfDist

00043 {
00044     coreDebug = hasPar("coreDebug") ? (bool) par("coreDebug") : false;
00045 
00046     coreEV << "initializing ChannelControl\n";
00047 
00048     playgroundSize.x = par("playgroundSizeX");
00049     playgroundSize.y = par("playgroundSizeY");
00050 
00051     maxInterferenceDistance = calcInterfDist();
00052 
00053     WATCH(maxInterferenceDistance);
00054     WATCH_LIST(hosts);
00055 
00056     updateDisplayString(parentModule());
00057 }

ChannelControl::HostRef ChannelControl::lookupHost cModule *  host  ) 
 

Returns the "handle" of a previously registered host.

00121 {
00122     for (HostList::iterator it = hosts.begin(); it != hosts.end(); it++)
00123         if (it->host == host)
00124             return &(*it);
00125     return 0;
00126 }

ChannelControl::HostRef ChannelControl::registerHost cModule *  host,
const Coord initialPos
 

Registers the given host.

00107 {
00108     if (lookupHost(host) != NULL)
00109         error("ChannelControl::registerHost(): host (%s)%s already registered",
00110               host->className(), host->fullPath().c_str());
00111 
00112     HostEntry he;
00113     he.host = host;
00114     he.pos = initialPos;
00115     he.isModuleListValid = false;
00116     hosts.push_back(he);
00117     return &hosts.back(); // last element
00118 }

void ChannelControl::updateConnections HostRef  h  )  [protected]
 

00141 {
00142     Coord& hpos = h->pos;
00143     double maxDistSquared = maxInterferenceDistance * maxInterferenceDistance;
00144     for (HostList::iterator it = hosts.begin(); it != hosts.end(); ++it)
00145     {
00146         HostEntry *hi = &(*it);
00147         if (hi == h)
00148             continue;
00149 
00150         // get the distance between the two hosts.
00151         // (omitting the square root (calling sqrdist() instead of distance()) saves about 5% CPU)
00152         bool inRange = hpos.sqrdist(hi->pos) < maxDistSquared;
00153 
00154         if (inRange)
00155         {
00156             // nodes within communication range: connect
00157             if (h->neighbors.insert(hi).second == true)
00158             {
00159                 hi->neighbors.insert(h);
00160                 h->isModuleListValid = hi->isModuleListValid = false;
00161             }
00162         }
00163         else
00164         {
00165             // out of range: disconnect
00166             if (h->neighbors.erase(hi))
00167             {
00168                 hi->neighbors.erase(h);
00169                 h->isModuleListValid = hi->isModuleListValid = false;
00170             }
00171         }
00172     }
00173 }

void ChannelControl::updateDisplayString cModule *  playgroundMod  )  [protected]
 

Set up playground module's display string.

Sets up background size by adding the following tags: "p=0,0;b=$playgroundSizeX,$playgroundSizeY"

00064 {
00065     cDisplayString& d = playgroundMod->backgroundDisplayString();
00066     d.setTagArg("p", 0, 0L);
00067     d.setTagArg("p", 1, 0L);
00068     d.setTagArg("b", 0, playgroundSize.x);
00069     d.setTagArg("b", 1, playgroundSize.y);
00070 }

void ChannelControl::updateHostPosition HostRef  h,
const Coord pos
[inline]
 

To be called when the host moved; updates proximity info.

00086                                                          {
00087         h->pos = pos;
00088         updateConnections(h);
00089     }


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  os,
const HostEntry h
[friend]
 

00029 {
00030     os << h.host->fullPath() << " (x=" << h.pos.x << ",y=" << h.pos.y << "), "
00031        << h.neighbors.size() << " neighbor(s)";
00032     return os;
00033 }


Member Data Documentation

bool ChannelControl::coreDebug [protected]
 

Set debugging for the basic module.

struct typedef std::list<HostEntry> ChannelControl::HostList [protected]
 

HostList ChannelControl::hosts [protected]
 

double ChannelControl::maxInterferenceDistance [protected]
 

the biggest interference distance in the network.

Coord ChannelControl::playgroundSize [protected]
 

x and y size of the area the nodes are in (in meters)


The documentation for this class was generated from the following files:
Generated on Sat Apr 1 20:52:21 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.1