From ce2239202cf1aee60a01ca19789bcbedef0472e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deronne?= Date: Tue, 29 Oct 2024 16:04:17 +0100 Subject: [PATCH] examples: Fix incorrect energy calculation in wifi power adaptation examples --- examples/wireless/wifi-power-adaptation-distance.cc | 6 +++--- examples/wireless/wifi-power-adaptation-interference.cc | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/wireless/wifi-power-adaptation-distance.cc b/examples/wireless/wifi-power-adaptation-distance.cc index df8194b62..a3082b06f 100644 --- a/examples/wireless/wifi-power-adaptation-distance.cc +++ b/examples/wireless/wifi-power-adaptation-distance.cc @@ -272,9 +272,9 @@ NodeStatistics::PhyCallback(std::string path, Ptr packet, double p if (head.GetType() == WIFI_MAC_DATA) { - m_totalEnergy += pow(10.0, m_currentPower[dest] / 10.0) * - GetCalcTxTime(m_currentRate[dest]).GetSeconds(); - m_totalTime += GetCalcTxTime(m_currentRate[dest]).GetSeconds(); + const auto txTimeSeconds = GetCalcTxTime(m_currentRate[dest]).GetSeconds(); + m_totalEnergy += DbmToW(m_currentPower[dest]) * txTimeSeconds; + m_totalTime += txTimeSeconds; } } diff --git a/examples/wireless/wifi-power-adaptation-interference.cc b/examples/wireless/wifi-power-adaptation-interference.cc index 7d032d579..60cc17cbf 100644 --- a/examples/wireless/wifi-power-adaptation-interference.cc +++ b/examples/wireless/wifi-power-adaptation-interference.cc @@ -293,9 +293,9 @@ NodeStatistics::PhyCallback(std::string path, Ptr packet, double p if (head.GetType() == WIFI_MAC_DATA) { - m_totalEnergy += pow(10.0, m_currentPower[dest] / 10.0) * - GetCalcTxTime(m_currentRate[dest]).GetSeconds(); - m_totalTime += GetCalcTxTime(m_currentRate[dest]).GetSeconds(); + const auto txTimeSeconds = GetCalcTxTime(m_currentRate[dest]).GetSeconds(); + m_totalEnergy += DbmToW(m_currentPower[dest]) * txTimeSeconds; + m_totalTime += txTimeSeconds; } }