From a0df8a6a0bc32c3fd601581c8dd0ae807af94475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Sat, 25 May 2019 13:48:10 +0200 Subject: [PATCH] wifi: Use uint32_t instead of double for band bandwidth expressed in Hz --- .../model/wifi-spectrum-value-helper.cc | 25 +++++++++---------- .../model/wifi-spectrum-value-helper.h | 6 ++--- src/wifi/model/spectrum-wifi-phy.cc | 4 +-- src/wifi/model/spectrum-wifi-phy.h | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/spectrum/model/wifi-spectrum-value-helper.cc b/src/spectrum/model/wifi-spectrum-value-helper.cc index 9042175d2..1c18402e8 100644 --- a/src/spectrum/model/wifi-spectrum-value-helper.cc +++ b/src/spectrum/model/wifi-spectrum-value-helper.cc @@ -83,7 +83,7 @@ operator < (const WifiSpectrumModelId& a, const WifiSpectrumModelId& b) static std::map > g_wifiSpectrumModelMap; ///< static initializer for the class Ptr -WifiSpectrumValueHelper::GetSpectrumModel (uint32_t centerFrequency, uint16_t channelWidth, double bandBandwidth, uint16_t guardBandwidth) +WifiSpectrumValueHelper::GetSpectrumModel (uint32_t centerFrequency, uint16_t channelWidth, uint32_t bandBandwidth, uint16_t guardBandwidth) { NS_LOG_FUNCTION (centerFrequency << channelWidth << bandBandwidth << guardBandwidth); Ptr ret; @@ -137,7 +137,7 @@ WifiSpectrumValueHelper::CreateDsssTxPowerSpectralDensity (uint32_t centerFreque { NS_LOG_FUNCTION (centerFrequency << txPowerW << +guardBandwidth); uint16_t channelWidth = 22; // DSSS channels are 22 MHz wide - double bandBandwidth = 312500; + uint32_t bandBandwidth = 312500; Ptr c = Create (GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth)); Values::iterator vit = c->ValuesBegin (); Bands::const_iterator bit = c->ConstBandsBegin (); @@ -160,7 +160,7 @@ Ptr WifiSpectrumValueHelper::CreateOfdmTxPowerSpectralDensity (uint32_t centerFrequency, uint16_t channelWidth, double txPowerW, uint16_t guardBandwidth) { NS_LOG_FUNCTION (centerFrequency << channelWidth << txPowerW << guardBandwidth); - double bandBandwidth = 0; + uint32_t bandBandwidth = 0; uint32_t innerSlopeWidth = 0; switch (channelWidth) { @@ -213,7 +213,7 @@ Ptr WifiSpectrumValueHelper::CreateHtOfdmTxPowerSpectralDensity (uint32_t centerFrequency, uint16_t channelWidth, double txPowerW, uint16_t guardBandwidth) { NS_LOG_FUNCTION (centerFrequency << channelWidth << txPowerW << guardBandwidth); - double bandBandwidth = 312500; + uint32_t bandBandwidth = 312500; Ptr c = Create (GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth)); uint32_t nGuardBands = static_cast (((2 * guardBandwidth * 1e6) / bandBandwidth) + 0.5); uint32_t nAllocatedBands = static_cast (((channelWidth * 1e6) / bandBandwidth) + 0.5); @@ -330,7 +330,7 @@ Ptr WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (uint32_t centerFrequency, uint16_t channelWidth, double txPowerW, uint16_t guardBandwidth) { NS_LOG_FUNCTION (centerFrequency << channelWidth << txPowerW << guardBandwidth); - double bandBandwidth = 78125; + uint32_t bandBandwidth = 78125; Ptr c = Create (GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth)); uint32_t nGuardBands = static_cast (((2 * guardBandwidth * 1e6) / bandBandwidth) + 0.5); uint32_t nAllocatedBands = static_cast (((channelWidth * 1e6) / bandBandwidth) + 0.5); @@ -359,7 +359,7 @@ WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (uint32_t centerFreq innerSlopeWidth = static_cast ((5e5 / bandBandwidth) + 0.5); // [-10.25;-9.75] & [9.75;10.25] // skip the guard band and 6 subbands, then place power in 121 subbands, then // skip 3 DC, then place power in 121 subbands, then skip - // the final 6 subbands and the guard band. + // the final 5 subbands and the guard band. start1 = (nGuardBands / 2) + 6; stop1 = start1 + 121 - 1; start2 = stop1 + 4; @@ -372,7 +372,7 @@ WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (uint32_t centerFreq txPowerPerBandW = txPowerW / 484; // skip the guard band and 12 subbands, then place power in 242 subbands, then // skip 5 DC, then place power in 242 subbands, then skip - // the final 12 subbands and the guard band. + // the final 11 subbands and the guard band. start1 = (nGuardBands / 2) + 12; stop1 = start1 + 242 - 1; start2 = stop1 + 6; @@ -385,7 +385,7 @@ WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (uint32_t centerFreq txPowerPerBandW = txPowerW / 996; // skip the guard band and 12 subbands, then place power in 498 subbands, then // skip 5 DC, then place power in 498 subbands, then skip - // the final 12 subbands and the guard band. + // the final 11 subbands and the guard band. start1 = (nGuardBands / 2) + 12; stop1 = start1 + 498 - 1; start2 = stop1 + 6; @@ -424,7 +424,7 @@ WifiSpectrumValueHelper::CreateHeOfdmTxPowerSpectralDensity (uint32_t centerFreq } Ptr -WifiSpectrumValueHelper::CreateNoisePowerSpectralDensity (uint32_t centerFrequency, uint16_t channelWidth, double bandBandwidth, double noiseFigure, uint16_t guardBandwidth) +WifiSpectrumValueHelper::CreateNoisePowerSpectralDensity (uint32_t centerFrequency, uint16_t channelWidth, uint32_t bandBandwidth, double noiseFigure, uint16_t guardBandwidth) { Ptr model = GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth); return CreateNoisePowerSpectralDensity (noiseFigure, model); @@ -449,14 +449,13 @@ WifiSpectrumValueHelper::CreateNoisePowerSpectralDensity (double noiseFigureDb, } Ptr -WifiSpectrumValueHelper::CreateRfFilter (uint32_t centerFrequency, uint16_t channelWidth, double bandGranularity, uint16_t guardBandwidth) +WifiSpectrumValueHelper::CreateRfFilter (uint32_t centerFrequency, uint16_t channelWidth, uint32_t bandBandwidth, uint16_t guardBandwidth) { - NS_LOG_FUNCTION (centerFrequency << channelWidth << bandGranularity << guardBandwidth); - Ptr c = Create (GetSpectrumModel (centerFrequency, channelWidth, bandGranularity, guardBandwidth)); + NS_LOG_FUNCTION (centerFrequency << channelWidth << bandBandwidth << guardBandwidth); + Ptr c = Create (GetSpectrumModel (centerFrequency, channelWidth, bandBandwidth, guardBandwidth)); size_t numBands = c->GetSpectrumModel ()->GetNumBands (); Bands::const_iterator bit = c->ConstBandsBegin (); Values::iterator vit = c->ValuesBegin (); - uint32_t bandBandwidth = static_cast (bandGranularity); size_t numBandsInFilter = static_cast (channelWidth * 1e6 / bandBandwidth); if (channelWidth % bandBandwidth != 0) { diff --git a/src/spectrum/model/wifi-spectrum-value-helper.h b/src/spectrum/model/wifi-spectrum-value-helper.h index 0971f368f..3d26ccdcf 100644 --- a/src/spectrum/model/wifi-spectrum-value-helper.h +++ b/src/spectrum/model/wifi-spectrum-value-helper.h @@ -57,7 +57,7 @@ public: * \return the static SpectrumModel instance corresponding to the * given carrier frequency and channel width configuration. */ - static Ptr GetSpectrumModel (uint32_t centerFrequency, uint16_t channelWidth, double bandBandwidth, uint16_t guardBandwidth); + static Ptr GetSpectrumModel (uint32_t centerFrequency, uint16_t channelWidth, uint32_t bandBandwidth, uint16_t guardBandwidth); /** * Create a transmit power spectral density corresponding to DSSS @@ -123,7 +123,7 @@ public: * \param guardBandwidth width of the guard band (MHz) * \return a pointer to a newly allocated SpectrumValue representing the noise Power Spectral Density in W/Hz for each Band */ - static Ptr CreateNoisePowerSpectralDensity (uint32_t centerFrequency, uint16_t channelWidth, double bandBandwidth, double noiseFigure, uint16_t guardBandwidth); + static Ptr CreateNoisePowerSpectralDensity (uint32_t centerFrequency, uint16_t channelWidth, uint32_t bandBandwidth, double noiseFigure, uint16_t guardBandwidth); /** * Create a thermal noise power spectral density @@ -145,7 +145,7 @@ public: * \return a pointer to a SpectrumValue representing the RF filter applied * to an received power spectral density */ - static Ptr CreateRfFilter (uint32_t centerFrequency, uint16_t channelWidth, double bandBandwidth, uint16_t guardBandwidth); + static Ptr CreateRfFilter (uint32_t centerFrequency, uint16_t channelWidth, uint32_t bandBandwidth, uint16_t guardBandwidth); /** * typedef for a pair of start and stop sub-band indexes diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index ef0d309b3..3bbd6ed9e 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -329,10 +329,10 @@ SpectrumWifiPhy::StartTx (Ptr packet, WifiTxVector txVector, Time txDura m_channel->StartTx (txParams); } -double +uint32_t SpectrumWifiPhy::GetBandBandwidth (void) const { - double bandBandwidth = 0; + uint32_t bandBandwidth = 0; switch (GetStandard ()) { case WIFI_PHY_STANDARD_80211a: diff --git a/src/wifi/model/spectrum-wifi-phy.h b/src/wifi/model/spectrum-wifi-phy.h index 8fccfed2f..4cedbf457 100644 --- a/src/wifi/model/spectrum-wifi-phy.h +++ b/src/wifi/model/spectrum-wifi-phy.h @@ -128,7 +128,7 @@ public: /** * \return the width of each band (Hz) */ - double GetBandBandwidth (void) const; + uint32_t GetBandBandwidth (void) const; /** * \param currentChannelWidth channel width of the current transmission (MHz)