-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomWifiTxCurrentModel.cc
118 lines (97 loc) · 3.13 KB
/
CustomWifiTxCurrentModel.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* CustomWifiTxCurrentModel.cc
*
* Created on: 26.05.2020
* Author: krassus
*/
#include "ns3/log.h"
#include "ns3/double.h"
#include "ns3/string.h"
#include "CustomWifiTxCurrentModel.h"
#include "ns3/wifi-utils.h"
namespace ns3
{
NS_LOG_COMPONENT_DEFINE("CustomWifiTxCurrentModel");
NS_OBJECT_ENSURE_REGISTERED(CustomWifiTxCurrentModel);
/*
* TypeId getter was taken from LinearWifiTxCurrentModel.cc
*/
TypeId CustomWifiTxCurrentModel::GetTypeId(void)
{
static TypeId tid = TypeId("ns3::CustomWifiTxCurrentModel")
.SetParent<WifiTxCurrentModel>()
.SetGroupName("Wifi")
.AddConstructor<CustomWifiTxCurrentModel>()
.AddAttribute("Eta", "The efficiency of the power amplifier.",
DoubleValue(0.10),
MakeDoubleAccessor(&CustomWifiTxCurrentModel::eta),
MakeDoubleChecker<double>())
.AddAttribute("Voltage", "The supply voltage (in Volts).",
DoubleValue(3.0),
MakeDoubleAccessor(&CustomWifiTxCurrentModel::voltage),
MakeDoubleChecker<double>())
.AddAttribute("IdleCurrent", "The current in the IDLE state (in Ampere).",
DoubleValue(0.273333),
MakeDoubleAccessor(&CustomWifiTxCurrentModel::idleCurrent),
MakeDoubleChecker<double>())
.AddAttribute("Chip", "The chip model to simulate",
StringValue("MAX2831"),
MakeStringAccessor(&CustomWifiTxCurrentModel::chip),
MakeStringChecker());
return tid;
}
CustomWifiTxCurrentModel::CustomWifiTxCurrentModel()
{
NS_LOG_FUNCTION(this);
}
CustomWifiTxCurrentModel::~CustomWifiTxCurrentModel()
{
NS_LOG_FUNCTION(this);
}
double CustomWifiTxCurrentModel::CalcTxCurrent(double txPowerDbm) const
{
NS_LOG_FUNCTION(this << txPowerDbm);
double current = 0;
if (this->chip == "MAX2831") {
current = calcMax2831(txPowerDbm);
} else {
current = DbmToW(txPowerDbm) / (this->voltage * this->eta);
}
return (current + this->idleCurrent);
}
/*
* The formula used in this function to calculate the current TX power in watts
* is taken from the bachelor thesis of Sergio Domínguez.
*/
double CustomWifiTxCurrentModel::calcMax2831(double txPowerDbm) const
{
//0.0007*pow(txPowerDbm,4) - 0.0111*pow(txPowerDbm,3) + 0.0889*pow(txPowerDbm,2) + 0.3483*txPowerDbm + 134.91;
double current = 0;
double txPow = txPowerDbm;
if (txPowerDbm >= 0)
{
current = 134.91 + 0.3483 * txPowerDbm;
txPow *= txPowerDbm; //txPowerDbm^2
current += (0.0889 * txPow);
txPow *= txPowerDbm; //txPowerDbm^3
current += (-0.0111 * txPow);
txPow *= txPowerDbm; //txPowerDbm^4
current += (0.0007 * txPow);
}
else
{
current = 124.4196777 - 2.427503769 * txPow;
txPow *= txPowerDbm;
current += (-0.4798606017 * txPow);
txPow *= txPowerDbm;
current += (-0.03112035853 * txPow);
txPow *= txPowerDbm;
current += (-0.00089877372 * txPow);
txPow *= txPowerDbm;
current += (-0.000009708995023 * txPow);
}
current = current / 1000;
NS_LOG_UNCOND("dBm = " << txPowerDbm << ", Current = " << current << ", volt = " << this->voltage);
return current;
}
}