A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
simple-device-energy-model.cc
Go to the documentation of this file.
1
#include "ns3/simulator.h"
2
#include "ns3/trace-source-accessor.h"
3
#include "ns3/energy-source.h"
4
#include "
simple-device-energy-model.h
"
5
6
7
namespace
ns3 {
8
9
NS_OBJECT_ENSURE_REGISTERED
(SimpleDeviceEnergyModel);
10
11
TypeId
12
SimpleDeviceEnergyModel::GetTypeId
(
void
)
13
{
14
static
TypeId
tid =
TypeId
(
"ns3::SimpleDeviceEnergyModel"
)
15
.
SetParent
<
DeviceEnergyModel
> ()
16
.AddConstructor<SimpleDeviceEnergyModel> ()
17
.AddTraceSource (
"TotalEnergyConsumption"
,
18
"Total energy consumption of the radio device."
,
19
MakeTraceSourceAccessor
(&
SimpleDeviceEnergyModel::m_totalEnergyConsumption
))
20
;
21
return
tid;
22
}
23
24
SimpleDeviceEnergyModel::SimpleDeviceEnergyModel
()
25
{
26
m_lastUpdateTime
=
Seconds
(0.0);
27
m_actualCurrentA
= 0.0;
28
m_source
= 0;
29
}
30
31
SimpleDeviceEnergyModel::~SimpleDeviceEnergyModel
()
32
{
33
}
34
35
void
36
SimpleDeviceEnergyModel::SetEnergySource
(
Ptr<EnergySource>
source)
37
{
38
NS_ASSERT
(source != NULL);
39
m_source
= source;
40
}
41
42
void
43
SimpleDeviceEnergyModel::SetNode
(
Ptr<Node>
node)
44
{
45
NS_ASSERT
(node != NULL);
46
m_node
= node;
47
}
48
49
Ptr<Node>
50
SimpleDeviceEnergyModel::GetNode
()
const
51
{
52
return
m_node
;
53
}
54
55
double
56
SimpleDeviceEnergyModel::GetTotalEnergyConsumption
(
void
)
const
57
{
58
return
m_totalEnergyConsumption
;
59
}
60
61
void
62
SimpleDeviceEnergyModel::SetCurrentA
(
double
current)
63
{
64
Time
duration =
Simulator::Now
() -
m_lastUpdateTime
;
65
66
double
energyToDecrease = 0.0;
67
double
supplyVoltage =
m_source
->
GetSupplyVoltage
();
68
energyToDecrease = duration.
GetSeconds
() * current * supplyVoltage;
69
70
// update total energy consumption
71
m_totalEnergyConsumption
+= energyToDecrease;
72
// update last update time stamp
73
m_lastUpdateTime
=
Simulator::Now
();
74
// notify energy source
75
m_source
->
UpdateEnergySource
();
76
// update the current drain
77
m_actualCurrentA
= current;
78
}
79
80
void
81
SimpleDeviceEnergyModel::DoDispose
(
void
)
82
{
83
m_source
= 0;
84
}
85
86
double
87
SimpleDeviceEnergyModel::DoGetCurrentA
(
void
)
const
88
{
89
return
m_actualCurrentA
;
90
}
91
92
}
// namespace ns3
src
energy
model
simple-device-energy-model.cc
Generated on Fri Dec 21 2012 19:00:35 for ns-3 by
1.8.1.2