diff --git a/src/wifi/model/phy-entity.cc b/src/wifi/model/phy-entity.cc index 35e4252fa..ea97da3dc 100644 --- a/src/wifi/model/phy-entity.cc +++ b/src/wifi/model/phy-entity.cc @@ -979,7 +979,10 @@ void PhyEntity::StartPreambleDetectionPeriod(Ptr event) { NS_LOG_FUNCTION(this << *event); - NS_LOG_DEBUG("Sync to signal (power=" << WToDbm(GetRxPowerWForPpdu(event)) << "dBm)"); + const auto rxPower = GetRxPowerWForPpdu(event); + NS_LOG_DEBUG("Sync to signal (power=" << (rxPower > 0.0 + ? std::to_string(WToDbm(rxPower)) + "dBm)" + : std::to_string(rxPower) + "W)")); m_wifiPhy->m_interference->NotifyRxStart( m_wifiPhy->GetCurrentFrequencyRange()); // We need to notify it now so that it starts // recording events diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index 2f6e74486..328640e5a 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -525,8 +525,10 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, rxPowerPerBandW *= rxGainRatio; rxPowerW.insert({band, rxPowerPerBandW}); NS_LOG_DEBUG("Signal power received after antenna gain for " - << bw << " MHz channel band " << index << ": " << rxPowerPerBandW << " W (" - << WToDbm(rxPowerPerBandW) << " dBm)"); + << bw << " MHz channel band " << index << ": " << rxPowerPerBandW << " W" + << (rxPowerPerBandW > 0.0 + ? " (" + std::to_string(WToDbm(rxPowerPerBandW)) + " dBm)" + : "")); if (bw <= 20) { totalRxPowerW += rxPowerPerBandW; @@ -548,14 +550,19 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, } } - NS_LOG_DEBUG("Total signal power received after antenna gain: " - << totalRxPowerW << " W (" << WToDbm(totalRxPowerW) << " dBm)"); + NS_LOG_DEBUG( + "Total signal power received after antenna gain: " + << totalRxPowerW << " W" + << (totalRxPowerW > 0.0 ? " (" + std::to_string(WToDbm(totalRxPowerW)) + " dBm)" : "")); Ptr wifiRxParams = DynamicCast(rxParams); // Log the signal arrival to the trace source - m_signalCb(rxParams, senderNodeId, WToDbm(totalRxPowerW), rxDuration); + if (totalRxPowerW > 0.0) + { + m_signalCb(rxParams, senderNodeId, WToDbm(totalRxPowerW), rxDuration); + } if (!wifiRxParams) { @@ -593,7 +600,10 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, const auto ppdu = GetRxPpduFromTxPpdu(wifiRxParams->ppdu); if (totalRxPowerW < DbmToW(GetRxSensitivity()) * (ppdu->GetTxChannelWidth() / 20.0)) { - NS_LOG_INFO("Received signal too weak to process: " << WToDbm(totalRxPowerW) << " dBm"); + NS_LOG_INFO( + "Received signal too weak to process: " + << totalRxPowerW << " W" + << (totalRxPowerW > 0.0 ? " (" + std::to_string(WToDbm(totalRxPowerW)) + " dBm)" : "")); m_interference->Add(ppdu, rxDuration, rxPowerW, GetCurrentFrequencyRange()); SwitchMaybeToCcaBusy(nullptr); return; diff --git a/src/wifi/model/threshold-preamble-detection-model.cc b/src/wifi/model/threshold-preamble-detection-model.cc index 44bde448e..10b5db0a2 100644 --- a/src/wifi/model/threshold-preamble-detection-model.cc +++ b/src/wifi/model/threshold-preamble-detection-model.cc @@ -68,6 +68,10 @@ ThresholdPreambleDetectionModel::IsPreambleDetected(double rssi, double snr, ChannelWidthMhz channelWidth) const { + if (rssi == 0.0) + { + return false; + } NS_LOG_FUNCTION(this << WToDbm(rssi) << RatioToDb(snr) << channelWidth); if (WToDbm(rssi) >= m_rssiMin) { diff --git a/src/wifi/model/wifi-utils.cc b/src/wifi/model/wifi-utils.cc index 169cbca27..18a25dd0d 100644 --- a/src/wifi/model/wifi-utils.cc +++ b/src/wifi/model/wifi-utils.cc @@ -47,6 +47,7 @@ DbmToW(double dBm) double WToDbm(double w) { + NS_ASSERT(w > 0.); return 10.0 * std::log10(w) + 30.0; } diff --git a/src/wifi/test/spectrum-wifi-phy-test.cc b/src/wifi/test/spectrum-wifi-phy-test.cc index beb061138..faf90d149 100644 --- a/src/wifi/test/spectrum-wifi-phy-test.cc +++ b/src/wifi/test/spectrum-wifi-phy-test.cc @@ -553,10 +553,11 @@ SpectrumWifiPhyFilterTest::~SpectrumWifiPhyFilterTest() void SpectrumWifiPhyFilterTest::RxCallback(Ptr p, RxPowerWattPerChannelBand rxPowersW) { - for (const auto& pair : rxPowersW) + for (const auto& [band, powerW] : rxPowersW) { - NS_LOG_INFO("band: (" << pair.first << ") -> powerW=" << pair.second << " (" - << WToDbm(pair.second) << " dBm)"); + NS_LOG_INFO( + "band: (" << band << ") -> powerW=" << powerW + << (powerW > 0.0 ? " (" + std::to_string(WToDbm(powerW)) + " dBm)" : "")); } size_t numBands = rxPowersW.size();