wifi: Add sanity checks in wifi spectrum value helper

This commit is contained in:
Sébastien Deronne
2024-04-09 08:24:49 +02:00
parent 5e10b47d18
commit fdf18e5b09

View File

@@ -787,16 +787,27 @@ WifiSpectrumValueHelper::DbmToW(double dBm)
double
WifiSpectrumValueHelper::GetBandPowerW(Ptr<SpectrumValue> 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