Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
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_totalE nergyConsumption)) | |
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; | |
Tom Henderson
2010/08/14 22:27:11
I don't really see how this is to work. If you se
socket
2010/09/20 14:51:59
The energy model starts by default with a 0.0 curr
| |
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 | |
OLD | NEW |