![]() |
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 <WNS/service/phy/phymode/PhyModeInterface.hpp> 00029 #include <WNS/service/phy/phymode/SNR2MIInterface.hpp> 00030 #include <WNS/service/phy/phymode/MI2PERInterface.hpp> 00031 #include <RISE/plmapping/PhyMode.hpp> 00032 #include <WNS/StaticFactory.hpp> 00033 00034 using namespace rise::plmapping; 00035 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(PhyMode, 00037 wns::service::phy::phymode::PhyModeInterface, 00038 "rise.PhyMode.PhyMode", 00039 wns::PyConfigViewCreator); 00040 00041 STATIC_FACTORY_REGISTER(PhyMode, 00042 wns::service::phy::phymode::PhyModeInterface, 00043 "rise.PhyMode.Empty"); 00044 00045 PhyMode::PhyMode() : 00046 snr2miMapper(NULL), 00047 coderMapper(NULL), 00048 subCarriersPerSubChannelKnown(false), 00049 subCarriersPerSubChannel(1), 00050 symbolDurationKnown(false), 00051 symbolDuration(0.0), 00052 dataRateKnown(false), 00053 dataRate(0.0) 00054 { 00055 coding = UNDEFINED_CODING; 00056 modulation = UNDEFINED_MODULATION; 00057 //std::cout << "PhyMode::PhyMode(UNDEFINED)"<< std::endl; 00058 } 00059 00061 PhyMode::PhyMode(const wns::pyconfig::View& config) : 00062 snr2miMapper(wns::service::phy::phymode::SNR2MIInterface::getSNR2MImapper(config.get("snr2miMapping"))), // unique object pointer 00063 coderMapper(wns::service::phy::phymode::CoderFullMappingInterface::getCoderFullMapping(config.get("mi2perMapper"))), // unique object pointer 00064 modulation(rise::plmapping::Modulations::fromString(config.get<std::string>("modulation"))), 00065 coding(coderMapper->fromString(config.get<std::string>("coding"))), 00066 subCarriersPerSubChannelKnown(false), 00067 subCarriersPerSubChannel(1), 00068 symbolDurationKnown(false), 00069 symbolDuration(0.0), 00070 dataRateKnown(false), 00071 dataRate(0.0) 00072 { 00073 assure(modulation > UNDEFINED_MODULATION, "UNDEFINED_MODULATION"); 00074 assure(modulation <= MAX_MODULATIONS, "MAX_MODULATIONS exceeded"); 00075 assure(coderMapper != NULL, "invalid coderMapper"); 00076 assure(coding <= coderMapper->getMaxCodeIndex(), "MaxCodeIndex exceeded"); 00077 if (config.knows("symbolDuration") && !config.isNone("symbolDuration")) { 00078 symbolDuration = config.get<simTimeType>("symbolDuration"); 00079 symbolDurationKnown = true; 00080 } 00081 if (config.knows("subCarriersPerSubChannel") && !config.isNone("subCarriersPerSubChannel")) { 00082 subCarriersPerSubChannel = config.get<unsigned int>("subCarriersPerSubChannel"); 00083 subCarriersPerSubChannelKnown = true; 00084 } 00085 calculateDataRate(); 00086 //std::cout << "PhyMode::PhyMode("<<getstd::string()<<") = " << dataRate << std::endl; 00087 } 00088 00089 00091 PhyMode::PhyMode(Modulation _modulation, rise::plmapping::Coding _coding, wns::service::phy::phymode::SNR2MIInterface* _snr2miMapper, wns::service::phy::phymode::CoderFullMappingInterface* _coderMapper) : 00092 snr2miMapper(_snr2miMapper), 00093 coderMapper(_coderMapper), 00094 subCarriersPerSubChannelKnown(false), 00095 subCarriersPerSubChannel(1), 00096 symbolDurationKnown(false), 00097 symbolDuration(0.0), 00098 dataRateKnown(false), 00099 dataRate(0.0) 00100 { 00101 assure(_modulation <=MAX_MODULATIONS, "MAX_MODULATIONS exceeded"); 00102 assure(snr2miMapper != NULL, "invalid sinr2miMapper"); 00103 assure(coderMapper != NULL, "invalid coderMapper"); 00104 assure(_coding <= coderMapper->getMaxCodeIndex(), "MaxCodeIndex exceeded: "<<coding<<" vs "<<coderMapper->getMaxCodeIndex()); 00105 coding = _coding; modulation = _modulation; 00106 //std::cout << "PhyMode::PhyMode("<<modulation<<","<<coding<<":"<<getstd::string()<<") = " << dataRate << std::endl; 00107 } 00108 00109 PhyMode::~PhyMode() {} 00110 00111 void 00112 PhyMode::setSubCarriersPerSubChannel(unsigned int _subCarriersPerSubChannel) 00113 { 00114 subCarriersPerSubChannel = _subCarriersPerSubChannel; 00115 subCarriersPerSubChannelKnown = true; 00116 //std::cout << "PhyMode::setSubCarriersPerSubChannel("<<getstd::string()<<","<<subCarriersPerSubChannel<<")"<< std::endl; 00117 calculateDataRate(); 00118 } 00119 00120 void 00121 PhyMode::setSymbolDuration(simTimeType _symbolDuration) 00122 { 00123 symbolDuration = _symbolDuration; 00124 symbolDurationKnown = true; 00125 //std::cout << "PhyMode::setSymbolDuration("<<getstd::string()<<","<<symbolDuration<<")"<< std::endl; 00126 calculateDataRate(); 00127 } 00128 00129 void 00130 PhyMode::cloneParameters(const PhyMode& other) 00131 { 00132 assure(other.dataRateIsValid(),"cloneParameters() requires fully parameterized PhyMode"); 00133 subCarriersPerSubChannel = other.subCarriersPerSubChannel; 00134 subCarriersPerSubChannelKnown = true; 00135 symbolDuration = other.symbolDuration; 00136 symbolDurationKnown = true; 00137 calculateDataRate(); 00138 } 00139 00140 bool 00141 PhyMode::isValid() const 00142 { 00143 return (modulation>UNDEFINED_MODULATION) 00144 && (modulation<=MAX_MODULATIONS) 00145 && (coding>UNDEFINED_CODING) 00146 && (coderMapper!=NULL); 00147 } 00148 00150 bool 00151 PhyMode::dataRateIsValid() const 00152 { 00153 return isValid() && dataRateKnown; 00154 } 00155 00156 rise::plmapping::Modulation 00157 PhyMode::getModulation() const { 00158 //if (this->isValid() == false) throw (UndefinedException()); 00159 return modulation; 00160 } 00161 00162 rise::plmapping::Coding 00163 PhyMode::getCoding() const { 00164 //if (this->isValid() == false) throw (UndefinedException()); 00165 return coding; 00166 } 00167 00169 double 00170 PhyMode::getCodeRate() const 00171 { 00172 assure(coderMapper != NULL, "invalid coderMapper"); 00173 if (this->isValid() == false) throw (UndefinedException()); 00174 return coderMapper->getRate(coding); 00175 } 00176 00178 double 00179 PhyMode::getBitsPerSymbol() const 00180 { 00181 assure(coderMapper != NULL, "invalid coderMapper"); 00182 return coderMapper->getRate(coding) * modulation; 00183 } 00184 00186 /* 00187 unsigned int 00188 PhyMode::getBitCapacity(double numberOfOFDMSymbols) const 00189 { 00190 assure(coderMapper != NULL, "invalid coderMapper"); 00191 return (unsigned int) (coderMapper->getRate(coding) * modulation * numberOfOFDMSymbols + 0.5); 00192 }; 00193 */ 00194 00195 double 00196 PhyMode::getDataRate(double _symbolRate, unsigned int _subCarriersPerSubChannel) const 00197 { 00198 return getBitsPerSymbol() * _symbolRate * _subCarriersPerSubChannel; 00199 } 00200 00201 double 00202 PhyMode::getDataRate() const 00203 { 00204 assure(dataRateKnown,"getDataRate(): cannot get dataRate for "<<getString()); 00205 return dataRate; 00206 } 00207 00208 double PhyMode::getSINR2MI(const wns::Ratio& sinr) const 00209 { 00210 assure(snr2miMapper != NULL, "invalid snr2miMapper"); 00211 return snr2miMapper->convertSNR2MI(sinr,*this); 00212 } 00213 double PhyMode::getSINR2MIB(const wns::Ratio& sinr) const 00214 { 00215 assure(snr2miMapper != NULL, "invalid snr2miMapper"); 00216 return snr2miMapper->convertSNR2MIB(sinr,*this); 00217 } 00218 double PhyMode::getMI2PER(const double mib, unsigned int bits) const 00219 { 00220 assure(coderMapper != NULL, "invalid coderMapper"); 00221 return coderMapper->mapMI2PER(mib,bits,coding); 00222 } 00223 double PhyMode::getSINR2PER(const wns::Ratio& sinr, unsigned int bits) const 00224 { 00225 assure(coderMapper != NULL, "invalid coderMapper"); 00226 return coderMapper->mapMI2PER(snr2miMapper->convertSNR2MIB(sinr,*this),bits,coding); 00227 } 00228 00229 wns::Ratio 00230 PhyMode::getMIB2SINR(const double& mib) const 00231 { 00232 assure(coderMapper != NULL, "invalid coderMapper"); 00233 return snr2miMapper->convertMIB2SNR(mib, getModulation()); 00234 } 00235 00236 unsigned int 00237 PhyMode::getBitCapacityFractional(simTimeType duration) const 00238 { 00239 // calculate the capacity of this burst [bits] 00240 //static double epsilon = 1e-6; // to combat precision errors 00241 assure(dataRateKnown,"unknown dataRate"); 00242 double capacity = dataRate * duration; 00243 return int(capacity+0.5); 00244 } 00245 00246 // attention: symbolDuration here means fullSymbolDuration = 1/symbolRateOFDM = OFDMsymbolDuration+cyclicPrefixDuration 00247 // duration is also counted INCLUDING cyclic prefic 00248 unsigned int 00249 PhyMode::getBitCapacity(simTimeType duration) const 00250 { 00251 // calculate the capacity of this burst [bits] 00252 static double epsilon = 1e-6; 00253 assure(subCarriersPerSubChannelKnown,"unknown subCarriersPerSubChannel"); 00254 assure(symbolDurationKnown,"unknown symbolDuration"); 00255 int OFDMsymbols = (int)(duration / symbolDuration + epsilon); 00256 // the following "if" is a quickhack to avoid assert failure in winprost::PhyUser 00257 // because duration = (phyCommand->local.stop - phyCommand->local.start) is too short 00258 if ((OFDMsymbols == 0) // very_short_duration, bad idea of caller! 00259 && (duration > 0.0)) // there is at least some small time 00260 OFDMsymbols = 1; // return at least the capacity of one OFDM symbol length 00261 double capacity = OFDMsymbols 00262 * subCarriersPerSubChannel 00263 * getBitsPerSymbol(); 00264 return int(capacity+epsilon); // to combat precision errors 00265 } 00266 00267 std::string 00268 PhyMode::getModulationString() const 00269 { 00270 if (modulation != UNDEFINED_MODULATION) { 00271 return rise::plmapping::Modulations::toString(modulation); 00272 } else { 00273 return std::string("UNDEFINED_MODULATION"); 00274 } 00275 } 00276 00277 std::string 00278 PhyMode::getCodingString() const 00279 { 00280 if (!this->isValid()) 00281 return std::string("UNDEFINED_CODING"); 00282 00283 assure(coderMapper != NULL, "invalid coderMapper"); 00284 return coderMapper->getString(coding); 00285 } 00286 00287 std::string 00288 PhyMode::getString() const 00289 { 00290 return getModulationString()+"-"+getCodingString(); 00291 } 00292 00293 bool 00294 PhyMode::nameMatches(const std::string& name) const 00295 { 00296 return (getString().compare(name) == 0); 00297 } 00298 00299 unsigned int 00300 PhyMode::toInt() const 00301 { 00302 return ((unsigned int)coding << MOD_BITS) + modulation; 00303 } 00304 00305 void 00306 PhyMode::calculateDataRate() 00307 { 00308 if (subCarriersPerSubChannelKnown && symbolDurationKnown) { 00309 // attention: symbolDuration here means fullSymbolDuration = 1/symbolRateOFDM = OFDMsymbolDuration+cyclicPrefixDuration 00310 dataRate = getBitsPerSymbol() * subCarriersPerSubChannel / symbolDuration; 00311 dataRateKnown = true; 00312 } 00313 } 00314
1.5.5