diff --git a/src/wifi/model/wifi-spectrum-value-helper.cc b/src/wifi/model/wifi-spectrum-value-helper.cc index c7e02e09b..f10fd378b 100644 --- a/src/wifi/model/wifi-spectrum-value-helper.cc +++ b/src/wifi/model/wifi-spectrum-value-helper.cc @@ -787,16 +787,27 @@ WifiSpectrumValueHelper::DbmToW(double dBm) double WifiSpectrumValueHelper::GetBandPowerW(Ptr psd, const WifiSpectrumBandIndices& band) { - double powerWattPerHertz = 0.0; auto valueIt = psd->ConstValuesBegin() + band.first; auto end = psd->ConstValuesBegin() + band.second; - auto bandIt = psd->ConstBandsBegin() + band.first; + auto bandIt = psd->ConstBandsBegin() + band.first; // all bands have same width + const auto bandWidth = (bandIt->fh - bandIt->fl); + NS_ASSERT_MSG(bandWidth >= 0.0, + "Invalid width for subband [" << bandIt->fl << ";" << bandIt->fh << "]"); + uint32_t index{0}; + auto powerWattPerHertz{0.0}; while (valueIt <= end) { + NS_ASSERT_MSG(*valueIt >= 0.0, + "Invalid power value " << *valueIt << " in subband " << index); powerWattPerHertz += *valueIt; ++valueIt; + ++index; } - return powerWattPerHertz * (bandIt->fh - bandIt->fl); + const auto power = powerWattPerHertz * bandWidth; + NS_ASSERT_MSG(power >= 0.0, + "Invalid calculated power " << power << " for band [" << band.first << ";" + << band.second << "]"); + return power; } bool