![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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/antenna/Antenna.hpp> 00029 #include <RISE/RISE.hpp> 00030 #include <RISE/stations/station.hpp> 00031 #include <WNS/pyconfig/View.hpp> 00032 00033 #include <fstream> 00034 00035 using namespace rise::antenna; 00036 00037 Antenna::Antenna(): 00038 log("Antenna"), 00039 radius(0), 00040 drawPattern(false), 00041 patternOutputFile(), 00042 pd_station(0), 00043 pd_positionOffset(), 00044 position(), 00045 id(counter++) 00046 {} 00047 00050 Antenna::Antenna(const wns::pyconfig::View& pyConfigView, 00051 Station* const station) : 00052 log("Antenna"), 00053 radius(0), 00054 drawPattern(pyConfigView.get<bool>("drawAntennaPattern")), 00055 patternOutputFile(), 00056 pd_station(station), 00057 pd_positionOffset(), 00058 position(), 00059 id(counter++) 00060 { 00061 if(RISE::getPyConfigView().get<bool>("debug.antennas")) 00062 { 00063 log.switchOn(); 00064 } else { 00065 log.switchOff(); 00066 } 00067 00068 typedef std::vector<double> container; 00069 container coords = pyConfigView.getSequence<container>("coordOffset"); 00070 assure( coords.size() == 3, 00071 "Wrong declaration of CoordOffset = [x, y, z] in ConfigFile"); 00072 pd_positionOffset = wns::PositionOffset(coords.at(0), 00073 coords.at(1), 00074 coords.at(2)); 00075 radius = pyConfigView.get<double>("radius"); 00076 MESSAGE_BEGIN(NORMAL, log, m,"New Antenna created ("); 00077 m << pyConfigView.get<std::string>("__plugin__") << ")"; 00078 MESSAGE_END(); 00079 00080 this->startObserving(this->pd_station); 00081 00082 if (drawPattern == true) 00083 { 00084 std::string outputDir = wns::simulator::getConfiguration().get<std::string>("outputDir"); 00085 patternOutputFile = outputDir + "/" + pyConfigView.get<std::string>("patternOutputFile"); 00086 preparePatternOutputFile(); 00087 MESSAGE_SINGLE(NORMAL,log,"Writing Antenna Pattern into "<<patternOutputFile); 00088 } 00089 } 00090 00091 Antenna::~Antenna() 00092 {} 00093 00094 void Antenna::drawRadiationPattern() const 00095 { 00096 const unsigned long int resolution = 360; 00097 double step = 2 * M_PI / resolution; 00098 double zero_dB_length = radius, length = 0, angle = 0; 00099 wns::Ratio gain = wns::Ratio::from_dB(0), 00100 gain_min = wns::Ratio::from_dB(-10); 00101 std::fstream outfile; 00102 outfile.open(patternOutputFile.c_str(), std::ios::out | std::ios::app); 00103 if (!outfile.is_open()) 00104 { 00105 MESSAGE_BEGIN(NORMAL, log, m,"File "); 00106 m << patternOutputFile + " could not be opened." + " Simulation will continue.\n"; 00107 MESSAGE_END(); 00108 return; 00109 } 00110 wns::PositionOffset pOffset; 00111 wns::Position position, myPosition = getPosition(); 00112 for (unsigned long int k=0; k<resolution; k++) 00113 { 00114 angle = step * k; 00115 pOffset.setPolar(1, angle, M_PI/2); 00116 position = myPosition + pOffset; 00117 gain = getGain(position, PatternPtr()); 00118 if (gain<gain_min) 00119 length = 0; 00120 else 00121 length = (zero_dB_length /(-gain_min.get_dB())) * gain.get_dB() 00122 + zero_dB_length; 00123 outfile << myPosition.getX() + length * cos(angle) << " " 00124 << myPosition.getY() + length * sin(angle) << std::endl; 00125 } 00126 outfile << "\n"; 00127 outfile.close(); 00128 } 00129 00130 rise::Station* Antenna::getStation() const 00131 { 00132 return pd_station; 00133 } 00134 00135 void Antenna::positionChanged() 00136 { 00137 position = pd_station->getPosition() + pd_positionOffset; 00138 } 00139 00140 void Antenna::preparePatternOutputFile() 00141 { 00142 if(patternOutputFilePrepared.find(patternOutputFile) == patternOutputFilePrepared.end()) { 00143 std::fstream outfile; 00144 outfile.open(patternOutputFile.c_str(), std::ios::out|std::ios::trunc); 00145 outfile.close(); 00146 patternOutputFilePrepared.insert(patternOutputFile); 00147 00148 MESSAGE_BEGIN(NORMAL, log, m,"Antenna pattern will be written to: "); 00149 m << patternOutputFile; 00150 MESSAGE_END(); 00151 } 00152 } 00153 00154 00155 unsigned long int Antenna::counter = 0; 00156 std::set<std::string> Antenna::patternOutputFilePrepared = std::set<std::string>(); 00157 00158
1.5.5