User Manual, Developers Guide and API Documentation

station.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/stations/station.hpp>
00029 #include <RISE/manager/systemmanager.hpp>
00030 #include <RISE/RISE.hpp>
00031 #include <RISE/scenario/scenerymap/SceneryMap.hpp>
00032 #include <RISE/antenna/Antenna.hpp>
00033 #include <RISE/antenna/Static.hpp>
00034 #include <RISE/antenna/ITUAntenna.hpp>
00035 #include <RISE/antenna/ITUAntennaWithWrap.hpp>
00036 #include <RISE/antenna/Beamforming.hpp>
00037 #include <RISE/scenario/mobility/Mobility.hpp>
00038 #include <RISE/scenario/sceneryfile/SceneryFile.hpp>
00039 
00040 #include <WNS/Assure.hpp>
00041 
00042 #include <stdexcept>
00043 
00044 using namespace rise;
00045 
00046 Station::Station(const wns::pyconfig::View& _pyConfigView) :
00047     pd_antenna(0),
00048     pyConfigView(_pyConfigView),
00049     log(_pyConfigView.getView("logger")),
00050     initialized(false),
00051     stationId(-1), // set later by systemmanager
00052     pathlossMap(NULL),
00053     interpolatedPathlossMap(NULL),
00054     shadowingMap(NULL),
00055     interpolatedShadowingMap(NULL),
00056     mobility(NULL)
00057 {
00058     createAntenna();
00059 }
00060 
00061 Station::~Station()
00062 {
00063     delete pd_antenna;
00064 }
00065 
00066 void
00067 Station::createAntenna()
00068 {
00069     wns::pyconfig::View antennaView = pyConfigView.getView("antennas", 0);
00070     assure(pyConfigView.len("antennas") == 1, "Only one antenna supported at the moment!");
00071     std::string s = antennaView.get<std::string>("__plugin__");
00072     // this could be done by a factory pattern
00073     if (s=="Internal"|| s=="Antenna3D"|| s=="Planet")
00074     {
00075         pd_antenna = new antenna::Static(antennaView, this);
00076     }
00077     else
00078     {
00079         if (s=="ITU")
00080         {
00081             pd_antenna = new antenna::ITUAntenna(antennaView, this);
00082         }
00083         else
00084         {
00085             if(s=="ITUwithWrap")
00086             {
00087                 pd_antenna =  new antenna::ITUAntennaWithWrap(antennaView, this);
00088             }
00089             else
00090             {
00091                 wns::Exception e;
00092                 e << "No such antenna type";
00093                 throw e;
00094             }
00095         }
00096     }
00097 }
00098 
00099 
00100 void
00101 Station::setMobility(rise::scenario::mobility::MobilityInterface* _mobility)
00102 {
00103     assure(!mobility, "Mobility Already set.");
00104     mobility = _mobility;
00105     this->startObserving(this->mobility);
00106 
00107     this->positionChanged();
00108 
00109     // Now everything is complete, so we can say:
00110     MESSAGE_BEGIN(NORMAL, log, m, "Created at position ");
00111     m << this->getPosition();
00112     MESSAGE_END();
00113 }
00114 
00115 scenario::mobility::MobilityInterface*
00116 Station::getMobility() const
00117 {
00118     assure(mobility, "Mobility Not set.");
00119     return mobility;
00120 }
00121 
00122 const wns::Position& Station::getPosition() const
00123 {
00124     // forward from mobility
00125     assure(mobility, "Mobility Not set.");
00126     return mobility->getPosition();
00127 }
00128 
00129 double Station::getDistance(PositionableInterface* p)
00130 {
00131     // forward from mobility
00132     assure(mobility, "Mobility Not set.");
00133     return mobility->getDistance(p);
00134 }
00135 
00136 double Station::getDistance(const PositionableInterface& p)
00137 {
00138     // forward from mobility
00139     assure(mobility, "Mobility Not set.");
00140     return mobility->getDistance(p);
00141 }
00142 
00143 double Station::getAngle(const PositionableInterface& p)
00144 {
00145     // forward from mobility
00146     assure(mobility, "Mobility Not set.");
00147     return mobility->getAngle(p);
00148 }
00149 
00150 
00151 void Station::positionWillChange()
00152 {
00153     // forward from mobility
00154     this->sendNotifies(&PositionObserver::positionWillChange);
00155 }
00156 
00157 void Station::positionChanged()
00158 {
00159     // forward from mobility
00160     this->sendNotifies(&PositionObserver::positionChanged);
00161 }
00162 
00163 void Station::initialize()
00164 {
00165     initializePathlossMap();
00166     initializeShadowingMap();
00167     initialized = true;
00168 }
00169 
00170 long int Station::getStationId() const
00171 {
00172     assure(stationId >= 0, "Station ID not set yet!");
00173     return stationId;
00174 }
00175 
00176 void Station::setStationId(long int id)
00177 {
00178     assure(id >= 0, "Only station IDs >= 0 allowed!");
00179     stationId = id;
00180 }
00181 
00182 antenna::Antenna* Station::getAntenna() const
00183 {
00184     assure(pd_antenna, "Antenna not set so far!");
00185     return pd_antenna;
00186 }
00187 
00188 bool Station::isInitialized() const
00189 {
00190     return initialized;
00191 }
00192 
00193 void
00194 Station::moveTo(const wns::Position& p)
00195 {
00196     assure(mobility, "Mobility Not set.");
00197     mobility->moveTo(p);
00198 }
00199 
00200 void
00201 Station::moveTo(const wns::PositionOffset& p)
00202 {
00203     assure(mobility, "Mobility Not set.");
00204     mobility->moveTo(p);
00205 }
00206 
00207 bool
00208 Station::hasPathlossMap() const
00209 {
00210     return (pathlossMap != NULL);
00211 }
00212 
00213 const scenario::scenerymap::PathlossMap2D&
00214 Station::getPathlossMap() const
00215 {
00216     assure(isInitialized(), "You must initialize() your station!");
00217     if (pathlossMap != NULL) std::logic_error("Cannot access non-existent pathloss map.");
00218     return *pathlossMap;
00219 }
00220 
00221 const scenario::scenerymap::Interpolation2D&
00222 Station::getInterpolatedPathlossMap() const
00223 {
00224     assure(isInitialized(), "You must initialize() your station!");
00225     if (interpolatedPathlossMap != NULL) std::logic_error("Cannot access non-existent pathloss map interpolation.");
00226     return *interpolatedPathlossMap;
00227 }
00228 
00229 bool
00230 Station::hasShadowingMap() const
00231 {
00232     return (shadowingMap != NULL);
00233 }
00234 
00235 const scenario::scenerymap::ShadowingMap2D&
00236 Station::getShadowingMap() const
00237 {
00238     assure(isInitialized(), "You must Initialize() your station!");
00239     if (shadowingMap != NULL) std::logic_error("Cannot access non-existent shadowing map.");
00240     return *shadowingMap;
00241 }
00242 
00243 const scenario::scenerymap::Interpolation2D&
00244 Station::getInterpolatedShadowingMap() const
00245 {
00246     assure(isInitialized(), "You must Initialize() your station!");
00247     if (interpolatedShadowingMap != NULL) std::logic_error("Cannot access non-existent shadowing map interpolation.");
00248     return *interpolatedShadowingMap;
00249 }
00250 
00251 void Station::initializePathlossMap()
00252 {
00253     if (!pyConfigView.isNone("pathlossMap")) {
00254         scenario::Scenario& scenario = *(getSystemManager()->getScenario());
00255         const std::string fn = pyConfigView.get<std::string>("pathlossMap");
00256         scenario.openSceneryFile(fn, "SC");
00257         pathlossMap = &(scenario.getSceneryFile(fn).getPathlossMap()[stationId]);
00258 
00259         const std::string interpolationType = pyConfigView.get<std::string>("pathlossInterpolation");
00260         if (interpolationType == "NearestNeighbour")
00261             interpolatedPathlossMap = new scenario::scenerymap::NearestNeighbour2D(*pathlossMap);
00262         else if (interpolationType == "Bilinear")
00263             interpolatedPathlossMap = new scenario::scenerymap::Bilinear(*pathlossMap);
00264         else std::logic_error("Unsupported 'pathlossInterpolation'");
00265     }
00266 }
00267 
00268 void Station::initializeShadowingMap()
00269 {
00270     if (!pyConfigView.isNone("shadowingMap")) {
00271         scenario::Scenario& scenario = *(getSystemManager()->getScenario());
00272         const std::string fn = pyConfigView.get<std::string>("shadowingMap");
00273         scenario.openSceneryFile(fn, "SC");
00274         shadowingMap = &(scenario.getSceneryFile(fn).getShadowingMap());
00275 
00276         const std::string interpolationType = pyConfigView.get<std::string>("shadowingInterpolation");
00277         if (interpolationType == "NearestNeighbour")
00278             interpolatedShadowingMap = new scenario::scenerymap::NearestNeighbour2D(*shadowingMap);
00279         else if (interpolationType == "Bilinear")
00280             interpolatedShadowingMap = new scenario::scenerymap::Bilinear(*shadowingMap);
00281         else std::logic_error("Unsupported 'shadowingInterpolation'");
00282     }
00283 }
00284 

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