User Manual, Developers Guide and API Documentation

MeasurementAspect.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <OFDMAPHY/receiver/MeasurementAspect.hpp>
00029 #include <OFDMAPHY/Station.hpp>
00030 
00031 #include <RISE/transceiver/transmitter.hpp>
00032 
00033 using namespace ofdmaphy::receiver;
00034 
00035 // constructor
00036 MeasurementAspect::MeasurementAspect(const wns::pyconfig::View& config) :
00037     doMeasurementUpdates(config.get<bool>("doMeasurementUpdates")),
00038     measurementUpdateInterval(0.0),
00039     measurementUpdateOffset(0.0)
00040 {
00041     // somehow ReceiverBase(config) does not initialize the logger
00042     if (logger.getModuleName().compare("unspecified")==0)
00043         logger=wns::logger::Logger(config.getView("logger")); // workaround.
00044 
00045     if (doMeasurementUpdates)
00046     {
00047         // can also be done if ftfading == NULL
00048         if (!config.isNone("measurementUpdateInterval")) 
00049         {
00050             measurementUpdateInterval = config.get<simTimeType>("measurementUpdateInterval");
00051 
00052             if (measurementUpdateInterval==0.0) 
00053             {
00054                 doMeasurementUpdates=false;
00055             }
00056             measurementUpdateOffset = config.get<simTimeType>("measurementUpdateOffset");
00057         }
00058         else
00059         {
00060             assure(false,"no measurementUpdateInterval in config");
00061         }
00062     }
00063     else
00064     {
00065         measurementUpdateInterval=0.0;
00066     }
00067 }
00068 
00069 // destructor
00070 MeasurementAspect::~MeasurementAspect()
00071 {
00072 }
00073 
00074 void
00075 MeasurementAspect::startRegularMeasurementUpdates()
00076 {
00077     // trigger event scheduler
00078     assure (measurementUpdateInterval>0.0,
00079             "wrong measurementUpdateInterval");
00080     assure (measurementUpdateInterval+measurementUpdateOffset>=0.0,
00081             "wrong measurementUpdateOffset");
00082 
00083     // the first measurement comes at this absolute time
00084     setTimeout(measurementUpdateOffset+measurementUpdateInterval);
00085 }
00086 
00087 void
00088 MeasurementAspect::onTimeout()
00089 {
00090     doMeasurementsNow();
00091     setTimeout(measurementUpdateInterval); // schedule next event
00092 }
00093 
00094 void
00095 MeasurementAspect::registerSource(wns::node::Interface* source)
00096 {
00097     if (not doMeasurementUpdates)
00098     {
00099         return;
00100     }
00101 
00102     assure(source!=NULL,"source==NULL");
00103 
00104     int numberOfSubChannels = getCurrentNumberOfSubCarriers();
00105     PerSourceMap::iterator perSourceMapFound = perSourceMap.find(source);
00106 
00107     if (perSourceMapFound == perSourceMap.end())
00108     {
00109         // not found
00110         MESSAGE_SINGLE(NORMAL, logger, "registerSource("<<source->getName()<<") successful");
00111 
00112         PerSourceContainer myPerSourceContainer;
00113         myPerSourceContainer.packetCount = 0;
00114         myPerSourceContainer.ftfading = NULL;
00115         myPerSourceContainer.quasiStaticPathLoss = wns::Ratio::from_dB(0.0);
00116         wns::Power interferenceTemplate = getNoisePerSubChannel();
00117         myPerSourceContainer.interferenceVector = std::vector<wns::Power>(numberOfSubChannels,interferenceTemplate);
00118         perSourceMap[source] = myPerSourceContainer; // insert (copy)
00119     }
00120 }
00121 
00122 wns::node::Interface*
00123 MeasurementAspect::registerSource(rise::TransmissionObjectPtr t)
00124 {
00125     rise::Transmitter* transmitter = t->getTransmitter();
00126     assure(transmitter!=NULL,"transmitter==NULL");
00127 
00128     Station* sourceStation = dynamic_cast<Station*>(transmitter->getStation());
00129     assure(sourceStation!=NULL,"sourceStation==NULL");
00130 
00131     wns::node::Interface* sourceNode = sourceStation->getNode();
00132     registerSource(sourceNode);
00133     return sourceNode;
00134 }
00135 
00136 PerSourceContainer&
00137 MeasurementAspect::getPerSourceContainer(wns::node::Interface* source)
00138 {
00139     assure(source!=NULL,"source==NULL");
00140 
00141     PerSourceMap::iterator perSourceMapFound = perSourceMap.find(source);
00142     assure(perSourceMapFound!= perSourceMap.end(),
00143            "cannot find source "<<source->getName()<<" in perSourceMap");
00144 
00145     PerSourceContainer& myPerSourceContainer = (*perSourceMapFound).second; // no copy, just reference
00146     return myPerSourceContainer;
00147 }
00148 
00149 void
00150 MeasurementAspect::saveMeasuredFlatPathloss(wns::node::Interface* source, wns::Ratio pathloss)
00151 {
00152     assure(source!=NULL,"source==NULL");
00153 
00154     PerSourceMap::iterator perSourceMapFound = perSourceMap.find(source);
00155 
00156     if (perSourceMapFound!= perSourceMap.end())
00157     {
00158         PerSourceContainer& myPerSourceContainer = (*perSourceMapFound).second;
00159         myPerSourceContainer.quasiStaticPathLoss = pathloss;
00160         myPerSourceContainer.packetCount++;
00161         MESSAGE_SINGLE(NORMAL, logger, "saveMeasuredFlatPathloss("<<source->getName()<<","<<pathloss<<"): count="<<myPerSourceContainer.packetCount);
00162     }
00163     else
00164     {
00165         MESSAGE_SINGLE(NORMAL, logger, "saveMeasuredFlatPathloss("<<source->getName()<<","<<pathloss<<"): unregistered source");
00166     }
00167 }

Generated on Fri May 25 03:32:19 2012 for openWNS by  doxygen 1.5.5