A Discrete-Event Network Simulator
API
 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"
5 
6 
7 namespace ns3 {
8 
9 NS_OBJECT_ENSURE_REGISTERED (SimpleDeviceEnergyModel);
10 
11 TypeId
13 {
14  static TypeId tid = TypeId ("ns3::SimpleDeviceEnergyModel")
16  .AddConstructor<SimpleDeviceEnergyModel> ()
17  .AddTraceSource ("TotalEnergyConsumption",
18  "Total energy consumption of the radio device.",
20  ;
21  return tid;
22 }
23 
25 {
26  m_lastUpdateTime = Seconds (0.0);
27  m_actualCurrentA = 0.0;
28  m_source = 0;
29 }
30 
32 {
33 }
34 
35 void
37 {
38  NS_ASSERT (source != NULL);
39  m_source = source;
40 }
41 
42 void
44 {
45  NS_ASSERT (node != NULL);
46  m_node = node;
47 }
48 
51 {
52  return m_node;
53 }
54 
55 double
57 {
59 }
60 
61 void
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
74  // notify energy source
76  // update the current drain
77  m_actualCurrentA = current;
78 }
79 
80 void
82 {
83  m_source = 0;
84 }
85 
86 double
88 {
89  return m_actualCurrentA;
90 }
91 
92 } // namespace ns3