A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
simple-device-energy-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Andrea Sacco
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Andrea Sacco <andrea.sacco85@gmail.com>
18 */
19
21
22#include "energy-source.h"
23
24#include "ns3/log.h"
25#include "ns3/simulator.h"
26#include "ns3/trace-source-accessor.h"
27
28namespace ns3
29{
30namespace energy
31{
32
33NS_LOG_COMPONENT_DEFINE("SimpleDeviceEnergyModel");
35
36TypeId
38{
39 static TypeId tid = TypeId("ns3::SimpleDeviceEnergyModel")
41 .SetGroupName("Energy")
42 .AddConstructor<SimpleDeviceEnergyModel>()
43 .AddTraceSource("TotalEnergyConsumption",
44 "Total energy consumption of the radio device.",
47 "ns3::TracedValueCallback::Double");
48 return tid;
49}
50
52{
53 NS_LOG_FUNCTION(this);
55 m_actualCurrentA = 0.0;
56 m_source = nullptr;
57}
58
60{
61 NS_LOG_FUNCTION(this);
62}
63
64void
66{
67 NS_LOG_FUNCTION(this << source);
68 NS_ASSERT(source);
69 m_source = source;
70}
71
72void
74{
75 NS_LOG_FUNCTION(this << node);
76 NS_ASSERT(node);
77 m_node = node;
78}
79
82{
83 NS_LOG_FUNCTION(this);
84 return m_node;
85}
86
87double
89{
90 NS_LOG_FUNCTION(this);
92
93 double energyToDecrease = 0.0;
94 double supplyVoltage = m_source->GetSupplyVoltage();
95 energyToDecrease = duration.GetSeconds() * m_actualCurrentA * supplyVoltage;
96
97 m_source->UpdateEnergySource();
98
99 return m_totalEnergyConsumption + energyToDecrease;
100}
101
102void
104{
105 NS_LOG_FUNCTION(this << current);
106 Time duration = Simulator::Now() - m_lastUpdateTime;
107
108 double energyToDecrease = 0.0;
109 double supplyVoltage = m_source->GetSupplyVoltage();
110 energyToDecrease = duration.GetSeconds() * m_actualCurrentA * supplyVoltage;
111
112 // update total energy consumption
113 m_totalEnergyConsumption += energyToDecrease;
114 // update last update time stamp
116 // update the current drain
117 m_actualCurrentA = current;
118 // notify energy source
119 m_source->UpdateEnergySource();
120}
121
122void
124{
125 NS_LOG_FUNCTION(this);
126 m_source = nullptr;
127}
128
129double
131{
132 NS_LOG_FUNCTION(this);
133 return m_actualCurrentA;
134}
135
136} // namespace energy
137} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Introspection did not find any typical Config paths.
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:403
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Base class for device energy models.
A simple device energy model where current drain can be set by the user.
virtual Ptr< Node > GetNode() const
Gets pointer to node.
double m_actualCurrentA
actual curred (in Ampere)
void SetEnergySource(Ptr< EnergySource > source) override
Sets pointer to EnergySource installed on node.
void DoDispose() override
Destructor implementation.
static TypeId GetTypeId()
Get the type ID.
virtual void SetNode(Ptr< Node > node)
Sets pointer to node.
Ptr< EnergySource > m_source
Energy source.
TracedValue< double > m_totalEnergyConsumption
Total energy consumption trace.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.