User Manual, Developers Guide and API Documentation

PhyMode.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * WiMeMac                                                                    *
00003  * This file is part of openWNS (open Wireless Network Simulator)
00004  * _____________________________________________________________________________
00005  *
00006  * Copyright (C) 2004-2011
00007  * Chair of Communication Networks (ComNets)
00008  * Kopernikusstr. 5, D-52074 Aachen, Germany
00009  * phone: ++49-241-80-27910,
00010  * fax: ++49-241-80-22242
00011  * email: info@openwns.org
00012  * www: http://www.openwns.org
00013  * _____________________________________________________________________________
00014  *
00015  * openWNS is free software; you can redistribute it and/or modify it under the
00016  * terms of the GNU Lesser General Public License version 2 as published by the
00017  * Free Software Foundation;
00018  *
00019  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00020  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00021  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00022  * details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00026  *
00027  ******************************************************************************/
00028 
00029 #include <WIMEMAC/convergence/PhyMode.hpp>
00030 
00031 #include <WNS/Assure.hpp>
00032 #include <WNS/Exception.hpp>
00033 
00034 using namespace wimemac::convergence;
00035 
00036 MCS::MCS():
00037     //modulation("ERROR"),
00038     //codingRate("ERROR"),
00039     nIBP6S(),
00040     SymbolDuration(),
00041     minRX(),
00042     minSINR(),
00043     index(0)
00044 {}
00045 
00046 MCS::MCS(const MCS& other):
00047     //modulation(other.modulation),
00048     //codingRate(other.codingRate),
00049     nIBP6S(other.nIBP6S),
00050     SymbolDuration(other.SymbolDuration),
00051     nominator(other.nominator),
00052     denominator(other.denominator),
00053     index(other.index),
00054     minRX(other.minRX),
00055     minSINR(other.minSINR)
00056 {}
00057 
00058 MCS::MCS(const wns::pyconfig::View& config) :
00059     nIBP6S(config.get<unsigned int>("nIBP6S")),
00060     SymbolDuration(312.5E-9),
00061     minRX(config.get<wns::Power>("minRX")),
00062     minSINR(config.get<wns::Ratio>("minSINR")),
00063     index(0),
00064     nominator(1),
00065     denominator(1)
00066 {}
00067 
00068 void MCS::setModulation(const std::string& modulation)
00069 {
00070     assure(modulation == "BPSK" or modulation == "QPSK" or modulation == "QAM16" or modulation == "QAM64",
00071            "Unknown modulation" << modulation);
00072 
00073     if(modulation == "QPSK")
00074     {
00075         nominator = 2;
00076     }
00077     if(modulation == "QAM16")
00078     {
00079         nominator = 4;
00080     }
00081     if(modulation == "QAM64")
00082     {
00083         nominator = 6;
00084     }
00085 }
00086 
00087 void MCS::setCodingRate(const std::string codingRate)
00088 {
00089     assure(codingRate == "1/2" or codingRate == "2/3" or codingRate == "3/4" or codingRate == "5/6",
00090            "Unknown coding rate" << codingRate);
00091 
00092     if(codingRate == "1/2")
00093     {
00094         denominator = 2;
00095     }
00096     if(codingRate == "2/3")
00097     {
00098         nominator *= 2;
00099         denominator = 3;
00100     }
00101     if(codingRate == "3/4")
00102     {
00103         nominator *= 3;
00104         denominator = 4;
00105     }
00106     if(codingRate == "5/6")
00107     {
00108         nominator *= 5;
00109         denominator = 6;
00110     }
00111 }
00112 
00113 float MCS::getDataRate()
00114 {
00115     float dataRate_ = float(nIBP6S) / 6 / SymbolDuration;
00116     dataRate_ = dataRate_ / 1E6;
00117     std::stringstream ss;
00118     ss.precision(4);
00119     ss << dataRate_;
00120     ss >> dataRate_;
00121 
00122     return dataRate_;
00123 }
00124 
00125 bool MCS::operator <(const MCS& rhs) const
00126 {
00127     return(nIBP6S < rhs.nIBP6S);
00128 }
00129 
00130 bool MCS::operator ==(const MCS& rhs) const
00131 {
00132     return(nIBP6S == rhs.nIBP6S); /* and
00133            nominator == rhs.nominator and
00134            denominator == rhs.denominator); */
00135 }
00136 
00137 bool MCS::operator !=(const MCS& rhs) const
00138 {
00139     return(nIBP6S != rhs.nIBP6S); /* or
00140            nominator != rhs.nominator or
00141            denominator != rhs.denominator); */
00142 }
00143 
00144 PhyMode::PhyMode():
00145     mcs(),
00146     numberOfSpatialStreams(0),
00147     numberOfDataSubcarriers(0),
00148     plcpMode("ERROR"),
00149     guardIntervalDuration(0)
00150 {}
00151 
00152 PhyMode::PhyMode(const wns::pyconfig::View& config) :
00153     mcs(config),
00154     numberOfSpatialStreams(config.get<unsigned int>("numberOfSpatialStreams")),
00155     numberOfDataSubcarriers(config.get<unsigned int>("numberOfDataSubcarriers")),
00156     plcpMode(config.get<std::string>("plcpMode")),
00157     guardIntervalDuration(config.get<wns::simulator::Time>("guardIntervalDuration"))
00158 {
00159     assure(numberOfSpatialStreams >= 1,
00160            "cannot have less than 1 spatial stream");
00161     assure(plcpMode == "STANDARD" or plcpMode == "BURST",
00162             "Unknown plcpMode : " << plcpMode);
00163     assure(guardIntervalDuration == 0.8e-6 or guardIntervalDuration == 0.4e-6,
00164            "Unknown guard interval");
00165     assure(numberOfDataSubcarriers > 0,
00166            "cannot have less than 1 data subcarriers");
00167 }
00168 
00169 Bit PhyMode::getDataBitsPerSymbol() const
00170 {
00171     assure(mcs.modulation != "ERROR",
00172            "modulation not set");
00173     assure(mcs.codingRate != "ERROR",
00174            "codingRate not set");
00175     assure(numberOfSpatialStreams > 0,
00176            "number of spatial streams not set");
00177     assure(numberOfDataSubcarriers > 0,
00178            "cannot have less than 1 data subcarriers");
00179 
00180     return(numberOfDataSubcarriers * numberOfSpatialStreams * mcs.nominator / mcs.denominator);
00181 }
00182 
00183 Bit PhyMode::getInfoBitsPer6Symbols() const
00184 {
00185     return (mcs.nIBP6S);
00186 }
00187 
00188 float PhyMode::getDataRate()
00189 {
00190     float dataRate_ = float(mcs.nIBP6S) / 6 / mcs.SymbolDuration;
00191     dataRate_ = dataRate_ / 1E6;
00192     std::stringstream ss;
00193     ss.precision(4);
00194     ss << dataRate_;
00195     ss >> dataRate_;
00196 
00197     return dataRate_;
00198 }
00199 
00200 bool PhyMode::operator <(const PhyMode& rhs) const
00201 {
00202     return(this->getInfoBitsPer6Symbols() < rhs.getInfoBitsPer6Symbols());
00203 }
00204 
00205 bool PhyMode::operator ==(const PhyMode& rhs) const
00206 {
00207     assure(mcs.modulation != "ERROR", "modulation not set in lhs");
00208     assure(mcs.codingRate != "ERROR", "codingRate not set in lhs");
00209     assure(numberOfSpatialStreams > 0, "number of spatial streams not set in lhs");
00210     assure(numberOfDataSubcarriers > 0, "number of DataSubcarriers not set in lhs");
00211     assure(plcpMode != "ERROR", "plcpMode not set in lhs");
00212 
00213     assure(rhs.mcs.modulation != "ERROR", "modulation not set in rhs");
00214     assure(rhs.mcs.codingRate != "ERROR", "codingRate not set in rhs");
00215     assure(rhs.numberOfSpatialStreams > 0, "number of spatial streams not set in rhs");
00216     assure(rhs.numberOfDataSubcarriers > 0, "number of DataSubcarriers not set in rhs");
00217     assure(rhs.plcpMode != "ERROR", "plcpMode not set in rhs");
00218 
00219 
00220     return((mcs == rhs.mcs) and
00221            (numberOfSpatialStreams == rhs.numberOfSpatialStreams) and
00222            (numberOfDataSubcarriers == rhs.numberOfDataSubcarriers) and
00223            (plcpMode == rhs.plcpMode));
00224 }
00225 
00226 bool PhyMode::operator !=(const PhyMode& rhs) const
00227 {
00228     return(not this->operator==(rhs));
00229 }

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