From 313388634d876ee58e96d079cdd28295fa70f9cd Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Fri, 30 Dec 2016 18:15:20 +0300 Subject: [PATCH] Backed out changeset b025c78789fb --- src/wifi/model/wifi-utils.cc | 52 +++++++++++++++++++++++ src/wifi/model/wifi-utils.h | 81 ++++++++++++++---------------------- src/wifi/wscript | 1 + 3 files changed, 85 insertions(+), 49 deletions(-) create mode 100644 src/wifi/model/wifi-utils.cc diff --git a/src/wifi/model/wifi-utils.cc b/src/wifi/model/wifi-utils.cc new file mode 100644 index 000000000..1edd4c224 --- /dev/null +++ b/src/wifi/model/wifi-utils.cc @@ -0,0 +1,52 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2016 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Sébastien Deronne + */ + +#include "wifi-utils.h" +#include + +namespace ns3 { + +double +DbToRatio (double dB) +{ + double ratio = std::pow (10.0, dB / 10.0); + return ratio; +} + +double +DbmToW (double dBm) +{ + double mW = std::pow (10.0, dBm / 10.0); + return mW / 1000.0; +} + +double +WToDbm (double w) +{ + return 10.0 * std::log10 (w * 1000.0); +} + +double +RatioToDb (double ratio) +{ + return 10.0 * std::log10 (ratio); +} + +} //namespace ns3 diff --git a/src/wifi/model/wifi-utils.h b/src/wifi/model/wifi-utils.h index eb8a776a3..a4613616a 100644 --- a/src/wifi/model/wifi-utils.h +++ b/src/wifi/model/wifi-utils.h @@ -21,57 +21,40 @@ #ifndef WIFI_UTILS_H #define WIFI_UTILS_H -#include - namespace ns3 { -/** - * Convert from dBm to Watts. - * - * \param dbm the power in dBm - * - * \return the equivalent Watts for the given dBm - */ -constexpr double DbmToW (double dbm) -{ - return std::pow (10.0, dbm / 10.0) / 1000.0; -} - -/** - * Convert from dB to ratio. - * - * \param db - * - * \return ratio - */ -constexpr double DbToRatio (double db) -{ - return std::pow (10.0, db / 10.0); -} - -/** - * Convert from Watts to dBm. - * - * \param w the power in Watts - * - * \return the equivalent dBm for the given Watts - */ -constexpr double WToDbm (double w) -{ - return 10.0 * std::log10 (w * 1000.0); -} - -/** - * Convert from ratio to dB. - * - * \param ratio - * - * \return dB - */ -constexpr double RatioToDb (double ratio) -{ - return 10.0 * std::log10 (ratio); -} + /** + * Convert from dBm to Watts. + * + * \param dbm the power in dBm + * + * \return the equivalent Watts for the given dBm + */ + double DbmToW (double dbm); + /** + * Convert from dB to ratio. + * + * \param db + * + * \return ratio + */ + double DbToRatio (double db); + /** + * Convert from Watts to dBm. + * + * \param w the power in Watts + * + * \return the equivalent dBm for the given Watts + */ + double WToDbm (double w); + /** + * Convert from ratio to dB. + * + * \param ratio + * + * \return dB + */ + double RatioToDb (double ratio); } // namespace ns3 diff --git a/src/wifi/wscript b/src/wifi/wscript index 50f051764..29ad75608 100644 --- a/src/wifi/wscript +++ b/src/wifi/wscript @@ -3,6 +3,7 @@ def build(bld): obj = bld.create_ns3_module('wifi', ['network', 'propagation', 'energy', 'spectrum', 'antenna', 'mobility']) obj.source = [ + 'model/wifi-utils.cc', 'model/wifi-information-element.cc', 'model/wifi-information-element-vector.cc', 'model/wifi-channel.cc',