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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Andrea Sacco <andrea.sacco85@gmail.com>
7 */
8
10
11#include "energy-source.h"
12
13#include "ns3/log.h"
14#include "ns3/simulator.h"
15#include "ns3/trace-source-accessor.h"
16
17namespace ns3
18{
19namespace energy
20{
21
22NS_LOG_COMPONENT_DEFINE("SimpleDeviceEnergyModel");
23NS_OBJECT_ENSURE_REGISTERED(SimpleDeviceEnergyModel);
24
25TypeId
27{
28 static TypeId tid = TypeId("ns3::energy::SimpleDeviceEnergyModel")
29 .AddDeprecatedName("ns3::SimpleDeviceEnergyModel")
31 .SetGroupName("Energy")
32 .AddConstructor<SimpleDeviceEnergyModel>()
33 .AddTraceSource("TotalEnergyConsumption",
34 "Total energy consumption of the radio device.",
37 "ns3::TracedValueCallback::Double");
38 return tid;
39}
40
48
53
54void
56{
57 NS_LOG_FUNCTION(this << source);
58 NS_ASSERT(source);
59 m_source = source;
60}
61
62void
64{
65 NS_LOG_FUNCTION(this << node);
66 NS_ASSERT(node);
67 m_node = node;
68}
69
72{
73 NS_LOG_FUNCTION(this);
74 return m_node;
75}
76
77double
79{
80 NS_LOG_FUNCTION(this);
82
83 double energyToDecrease = 0.0;
84 double supplyVoltage = m_source->GetSupplyVoltage();
85 energyToDecrease = duration.GetSeconds() * m_actualCurrentA * supplyVoltage;
86
87 m_source->UpdateEnergySource();
88
89 return m_totalEnergyConsumption + energyToDecrease;
90}
91
92void
94{
95 NS_LOG_FUNCTION(this << current);
97
98 double energyToDecrease = 0.0;
99 double supplyVoltage = m_source->GetSupplyVoltage();
100 energyToDecrease = duration.GetSeconds() * m_actualCurrentA * supplyVoltage;
101
102 // update total energy consumption
103 m_totalEnergyConsumption += energyToDecrease;
104 // update last update time stamp
106 // update the current drain
107 m_actualCurrentA = current;
108 // notify energy source
109 m_source->UpdateEnergySource();
110}
111
112void
114{
115 NS_LOG_FUNCTION(this);
116 m_source = nullptr;
117}
118
119double
125
126} // namespace energy
127} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
a unique identifier for an interface.
Definition type-id.h:48
TypeId AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
Definition type-id.cc:862
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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.
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:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
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.