User Manual, Developers Guide and API Documentation

transmitter.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 <RISE/transceiver/transmitter.hpp>
00029 #include <RISE/medium/PhysicalResource.hpp>
00030 #include <RISE/medium/Medium.hpp>
00031 #include <RISE/RISE.hpp>
00032 #include <RISE/stations/station.hpp>
00033 
00034 #include <WNS/Functor.hpp>
00035 #include <WNS/pyconfig/View.hpp>
00036 
00037 #include <sstream>
00038 
00039 using namespace rise;
00040 
00041 Transmitter::Transmitter(const wns::pyconfig::View& config, Station* s, antenna::Antenna* a)
00042     : PropagationCharacteristic(config),
00043       txPwr(),
00044       transmitterId(nextid++),
00045       maxTxPwr(),
00046       prc(),
00047       antenna(a),
00048       midFrequency(0),
00049       log(config.getView("logger")),
00050       active(false)
00051 {
00052     if (RISE::getPyConfigView().get<bool>("debug.transmitter"))
00053     {
00054         log.switchOn();
00055     } else {
00056         log.switchOff();
00057     }
00058 
00059     MESSAGE_SINGLE(NORMAL, log, "rise::Transmitter created");
00060     this->startObserving(s);
00061 }
00062 
00063 Transmitter::~Transmitter() {
00064     MESSAGE_BEGIN(NORMAL, log, m, "Shutting down ...");
00065     MESSAGE_END();
00066 }
00067 
00068 void Transmitter::startTransmitting(TransmissionObjectPtr transmissionObject, long int subCarrier)
00069 {
00070     assure(prc.at(subCarrier), "SubCarrier with id " << subCarrier << " does not exist");
00071     prc[subCarrier]->startTransmission(transmissionObject);
00072 
00073     MESSAGE_BEGIN(NORMAL, log, m, "Starting transmission");
00074     m << " on subBand=" << subCarrier
00075       << ", f=" << transmissionObject->getPhysicalResource()->getFrequency()
00076       << ", b=" << transmissionObject->getPhysicalResource()->getBandwidth();
00077     if (transmissionObject->getPhyModePtr()) // != NULL
00078         m << ", m&c=" << transmissionObject->getPhyModePtr()->getString();
00079     MESSAGE_END();
00080 }
00081 
00082 void Transmitter::stopTransmitting(TransmissionObjectPtr transmissionObject)
00083 {
00084     PhysicalResourceIterator itr, itrEND;
00085     itr = prc.begin();
00086     itrEND = prc.end();
00087     int subCarrier= 0;
00088     while( (!(*itr)->contains(transmissionObject)) && itr!=itrEND)
00089     {
00090         ++itr;
00091         ++subCarrier;
00092     }
00093     // assert that we have found the matching physicalResource
00094     assure(itr!=itrEND, "Cannot find physicalResource with given transmissionObject");
00095 
00096     MESSAGE_BEGIN(NORMAL, log, m, "Stopping transmission. PhysicalResource: ");
00097     m << "f=" << transmissionObject->getPhysicalResource()->getFrequency()
00098       << ", b=" << transmissionObject->getPhysicalResource()->getBandwidth()
00099       << ", sc=" << subCarrier;
00100     if (transmissionObject->getPhyModePtr()) // != NULL
00101         m << ", m&c=" << transmissionObject->getPhyModePtr()->getString();
00102         //<< " " << transmissionObject.getPtr();
00103     MESSAGE_END();
00104     // here it goes on with the transmission
00105     // see PhysicalResource::stopTransmission()
00106     // this calls PhysicalResource::notifyReceivers()
00107     (*itr)->stopTransmission(transmissionObject);
00108 }
00109 
00110 void Transmitter::tune(double f,double b,long int numberOfSubCarriers)
00111 {
00112     MESSAGE_SINGLE(NORMAL, log, "Transmitter::tune(f="<<f<<",b="<<b<<",#SC="<<numberOfSubCarriers<<")");
00113 
00114     assure(!active, "Tune not possible. Transmitter still active.");
00115     assure(f>0, "No negative frequencies allowed.");
00116     assure(b>0, "No negative bandwidth allowed.");
00117     assure(numberOfSubCarriers>=0, "No negative number of sub-carriers allowed.");
00118 
00119     // complete retuning is only supported by now
00120     prc.clear();
00121 
00122     double carrierBandwidth = b/numberOfSubCarriers;
00123     double lowestFrequency = f - b/2;
00124     double firstCarrierMidFrequency = lowestFrequency + carrierBandwidth/2;
00125 
00126     for(long int i=0; i<numberOfSubCarriers; ++i) {
00127         double midFrequency = firstCarrierMidFrequency + i*carrierBandwidth;
00128         medium::Medium* m = medium::Medium::getInstance();
00129         medium::PhysicalResource* p = m->getPhysicalResource(midFrequency, carrierBandwidth);
00130         prc.push_back(p);
00131     }
00132 }
00133 
00134 std::string Transmitter::getDebugInfo()
00135 {
00136     std::stringstream ss;
00137     // this throws "pure virtual method called - Segmentation fault" when called in the constructor
00138     assure(getStation() != NULL, "unknown station");
00139     ss << "Transmitter (" << transmitterId << ") belongs to Station (" << getStation()->getStationId() << ")";
00140     return ss.str();
00141 }
00142 
00143 void Transmitter::positionChanged()
00144 {
00145     /* do nothing */
00146 }
00147 
00148 void Transmitter::positionWillChange()
00149 {
00150     std::for_each(
00151         prc.begin(),
00152         prc.end(),
00153         std::bind2nd(
00154             std::mem_fun(
00155                 &medium::PhysicalResource::mobilityUpdate),
00156             this));
00157 }
00158 
00159 long int Transmitter::nextid = 0;
00160 
00161 

Generated on Sun May 27 03:31:58 2012 for openWNS by  doxygen 1.5.5