Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2014 Wireless Communications and Networking Group (WCNG), | 3 * Copyright (c) 2014 Wireless Communications and Networking Group (WCNG), |
4 * University of Rochester, Rochester, NY, USA. | 4 * University of Rochester, Rochester, NY, USA. |
5 * | 5 * |
6 * This program is free software; you can redistribute it and/or modify | 6 * This program is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License version 2 as | 7 * it under the terms of the GNU General Public License version 2 as |
8 * published by the Free Software Foundation; | 8 * published by the Free Software Foundation; |
9 * | 9 * |
10 * This program is distributed in the hope that it will be useful, | 10 * This program is distributed in the hope that it will be useful, |
(...skipping 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 NS_LOG_COMPONENT_DEFINE ("BasicEnergyHarvester"); | 31 NS_LOG_COMPONENT_DEFINE ("BasicEnergyHarvester"); |
32 | 32 |
33 namespace ns3 { | 33 namespace ns3 { |
34 ·· | 34 ·· |
35 NS_OBJECT_ENSURE_REGISTERED (BasicEnergyHarvester); | 35 NS_OBJECT_ENSURE_REGISTERED (BasicEnergyHarvester); |
36 | 36 |
37 TypeId | 37 TypeId |
38 BasicEnergyHarvester::GetTypeId (void) | 38 BasicEnergyHarvester::GetTypeId (void) |
39 { | 39 { |
40 » static TypeId tid = TypeId ("ns3::BasicEnergyHarvester") | 40 static TypeId tid = TypeId ("ns3::BasicEnergyHarvester") |
41 » .SetParent<EnergyHarvester> () | 41 .SetParent<EnergyHarvester> () |
42 » .AddConstructor<BasicEnergyHarvester> () | 42 .AddConstructor<BasicEnergyHarvester> () |
43 » .AddAttribute ("PeriodicHarvestedPowerUpdateInterval", | 43 .AddAttribute ("PeriodicHarvestedPowerUpdateInterval", |
44 » » » » » » » » "Time between t wo consecutive periodic updates of the harvested power. By default, the value is updated every 1 s", | 44 "Time between two consecutive periodic updates of the harvested power. By default, the value is updated every 1 s", |
45 » » » » » » » » TimeValue (Seco nds (1.0)), | 45 TimeValue (Seconds (1.0)), |
46 » » » » » » » » MakeTimeAccesso r (&BasicEnergyHarvester::SetHarvestedPowerUpdateInterval, | 46 MakeTimeAccessor (&BasicEnergyHarvester::SetHarvestedPowerUpdat eInterval, |
47 » » » » » » » » » » » » » » » » » &BasicEnergyHarvester:: GetHarvestedPowerUpdateInterval), | 47 &BasicEnergyHarvester::GetHarvestedPowerUpdat eInterval), |
48 » » » » » » » » MakeTimeChecker ()) | 48 MakeTimeChecker ()) |
49 » .AddAttribute ("HarvestablePower", | 49 .AddAttribute ("HarvestablePower", |
50 » » » » » » » » "The harvestabl e power [Watts] that the energy harvester is allowed to harvest. By default, the model will allow to harvest an amount of power defined by a uniformly distribut ed random variable in 0 and 2.0 Watts", | 50 "The harvestable power [Watts] that the energy harvester is all owed to harvest. By default, the model will allow to harvest an amount of power defined by a uniformly distributed random variable in 0 and 2.0 Watts", |
51 » » » » » » » » StringValue ("n s3::UniformRandomVariable[Min=0.0|Max=2.0]"), | 51 StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=2.0]"), |
52 » » » » » » » » MakePointerAcce ssor (&BasicEnergyHarvester::m_harvestablePower), | 52 MakePointerAccessor (&BasicEnergyHarvester::m_harvestablePower) , |
53 » » » » » » » » MakePointerChec ker<RandomVariableStream> ()) | 53 MakePointerChecker<RandomVariableStream> ()) |
54 » .AddTraceSource ("HarvestedPower", | 54 .AddTraceSource ("HarvestedPower", |
55 » » » » » » » » » "Harves ted power by the BasicEnergyHarvester.", | 55 "Harvested power by the BasicEnergyHarvester.", |
56 » » » » » » » » » MakeTra ceSourceAccessor (&BasicEnergyHarvester::m_harvestedPower)) | 56 MakeTraceSourceAccessor (&BasicEnergyHarvester::m_harvestedPo wer)) |
57 » .AddTraceSource ("TotalEnergyHarvested", | 57 .AddTraceSource ("TotalEnergyHarvested", |
58 » » » » » » » » » "Total energy harvested by the harvester.", | 58 "Total energy harvested by the harvester.", |
59 » » » » » » » » » MakeTra ceSourceAccessor (&BasicEnergyHarvester::m_totalEnergyHarvestedJ)) | 59 MakeTraceSourceAccessor (&BasicEnergyHarvester::m_totalEnergy HarvestedJ)) |
60 » ; | 60 ; |
61 » return tid; | 61 return tid; |
62 } | 62 } |
63 | 63 |
64 BasicEnergyHarvester::BasicEnergyHarvester () | 64 BasicEnergyHarvester::BasicEnergyHarvester () |
65 { | 65 { |
66 » NS_LOG_FUNCTION (this); | 66 NS_LOG_FUNCTION (this); |
67 } | 67 } |
68 | 68 |
69 BasicEnergyHarvester::BasicEnergyHarvester (Time updateInterval) | 69 BasicEnergyHarvester::BasicEnergyHarvester (Time updateInterval) |
70 { | 70 { |
71 » NS_LOG_FUNCTION (this << updateInterval); | 71 NS_LOG_FUNCTION (this << updateInterval); |
72 » m_harvestedPowerUpdateInterval = updateInterval; | 72 m_harvestedPowerUpdateInterval = updateInterval; |
73 } | 73 } |
74 | 74 |
75 BasicEnergyHarvester::~BasicEnergyHarvester () | 75 BasicEnergyHarvester::~BasicEnergyHarvester () |
76 { | 76 { |
77 » NS_LOG_FUNCTION (this); | 77 NS_LOG_FUNCTION (this); |
78 } | 78 } |
79 | 79 |
80 int64_t | 80 int64_t |
81 BasicEnergyHarvester::AssignStreams (int64_t stream) | 81 BasicEnergyHarvester::AssignStreams (int64_t stream) |
82 { | 82 { |
83 » NS_LOG_FUNCTION (this << stream); | 83 NS_LOG_FUNCTION (this << stream); |
84 » m_harvestablePower->SetStream (stream); | 84 m_harvestablePower->SetStream (stream); |
85 » return m_harvestablePower->GetStream (); | 85 return 1; |
Stefano Avallone
2014/09/04 08:41:10
should return the number of assigned stream. In ou
cristiano.tapparello
2014/09/04 17:17:06
Thanks! I was not completely sure about this... I
| |
86 } | 86 } |
87 | 87 |
88 void | 88 void |
89 BasicEnergyHarvester::SetHarvestedPowerUpdateInterval (Time updateInterval) | 89 BasicEnergyHarvester::SetHarvestedPowerUpdateInterval (Time updateInterval) |
90 { | 90 { |
91 » NS_LOG_FUNCTION (this << updateInterval); | 91 NS_LOG_FUNCTION (this << updateInterval); |
92 » m_harvestedPowerUpdateInterval = updateInterval; | 92 m_harvestedPowerUpdateInterval = updateInterval; |
93 } | 93 } |
94 | 94 |
95 Time | 95 Time |
96 BasicEnergyHarvester::GetHarvestedPowerUpdateInterval (void) const | 96 BasicEnergyHarvester::GetHarvestedPowerUpdateInterval (void) const |
97 { | 97 { |
98 » NS_LOG_FUNCTION (this); | 98 NS_LOG_FUNCTION (this); |
99 » return m_harvestedPowerUpdateInterval; | 99 return m_harvestedPowerUpdateInterval; |
100 } | 100 } |
101 | 101 |
102 /* | 102 /* |
103 * Private functions start here. | 103 * Private functions start here. |
104 */ | 104 */ |
105 | 105 |
106 void | 106 void |
107 BasicEnergyHarvester::UpdateHarvestedPower (void) | 107 BasicEnergyHarvester::UpdateHarvestedPower (void) |
108 { | 108 { |
109 » NS_LOG_FUNCTION (this); | 109 NS_LOG_FUNCTION (this); |
110 » NS_LOG_DEBUG (Simulator::Now ().GetSeconds () | 110 NS_LOG_DEBUG (Simulator::Now ().GetSeconds () |
111 » » » » » » » » << "s BasicEnerg yHarvester(" << GetNode ()->GetId () << "): Updating harvesting power."); | 111 << "s BasicEnergyHarvester(" << GetNode ()->GetId () << "): Upda ting harvesting power."); |
112 | 112 |
113 » Time duration = Simulator::Now () - m_lastHarvestingUpdateTime; | 113 Time duration = Simulator::Now () - m_lastHarvestingUpdateTime; |
114 | 114 |
115 » NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is val id | 115 NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid |
116 | 116 |
117 » double energyHarvested = 0.0; | 117 double energyHarvested = 0.0; |
118 | 118 |
119 » // do not update if simulation has finished | 119 // do not update if simulation has finished |
120 » if (Simulator::IsFinished ()) | 120 if (Simulator::IsFinished ()) |
121 » { | 121 { |
122 » » NS_LOG_DEBUG ("BasicEnergyHarvester: Simulation Finished."); | 122 NS_LOG_DEBUG ("BasicEnergyHarvester: Simulation Finished."); |
123 » » return; | 123 return; |
124 » } | 124 } |
125 | 125 |
126 » m_energyHarvestingUpdateEvent.Cancel (); | 126 m_energyHarvestingUpdateEvent.Cancel (); |
127 | 127 |
128 » CalculateHarvestedPower (); | 128 CalculateHarvestedPower (); |
129 | 129 |
130 » energyHarvested = duration.GetSeconds () * m_harvestedPower; | 130 energyHarvested = duration.GetSeconds () * m_harvestedPower; |
131 | 131 |
132 » // update total energy harvested | 132 // update total energy harvested |
133 » m_totalEnergyHarvestedJ += energyHarvested; | 133 m_totalEnergyHarvestedJ += energyHarvested; |
134 | 134 |
135 » // notify energy source | 135 // notify energy source |
136 » GetEnergySource ()->UpdateEnergySource (); | 136 GetEnergySource ()->UpdateEnergySource (); |
137 | 137 |
138 » // update last harvesting time stamp | 138 // update last harvesting time stamp |
139 » m_lastHarvestingUpdateTime = Simulator::Now (); | 139 m_lastHarvestingUpdateTime = Simulator::Now (); |
140 | 140 |
141 » m_energyHarvestingUpdateEvent = Simulator::Schedule (m_harvestedPowerUpd ateInterval, | 141 m_energyHarvestingUpdateEvent = Simulator::Schedule (m_harvestedPowerUpdateInt erval, |
142 » » » » » » » » » » » » » » » » » » » » » » » » » » » &BasicEnergyHarvester:: UpdateHarvestedPower, | 142 &BasicEnergyHarvester::Up dateHarvestedPower, |
143 » » » » » » » » » » » » » » » » » » » » » » » » » » » this); | 143 this); |
144 } | 144 } |
145 | 145 |
146 void | 146 void |
147 BasicEnergyHarvester::DoInitialize (void) | 147 BasicEnergyHarvester::DoInitialize (void) |
148 { | 148 { |
149 » NS_LOG_FUNCTION (this); | 149 NS_LOG_FUNCTION (this); |
150 | 150 |
151 » m_lastHarvestingUpdateTime = Simulator::Now (); | 151 m_lastHarvestingUpdateTime = Simulator::Now (); |
152 | 152 |
153 » UpdateHarvestedPower (); // start periodic harvesting update | 153 UpdateHarvestedPower (); // start periodic harvesting update |
154 } | 154 } |
155 | 155 |
156 void | 156 void |
157 BasicEnergyHarvester::DoDispose (void) | 157 BasicEnergyHarvester::DoDispose (void) |
158 { | 158 { |
159 » NS_LOG_FUNCTION (this); | 159 NS_LOG_FUNCTION (this); |
160 } | 160 } |
161 | 161 |
162 void | 162 void |
163 BasicEnergyHarvester::CalculateHarvestedPower (void) | 163 BasicEnergyHarvester::CalculateHarvestedPower (void) |
164 { | 164 { |
165 » NS_LOG_FUNCTION (this); | 165 NS_LOG_FUNCTION (this); |
166 | 166 |
167 » m_harvestedPower = m_harvestablePower->GetValue (); | 167 m_harvestedPower = m_harvestablePower->GetValue (); |
168 | 168 |
169 » NS_LOG_DEBUG (Simulator::Now ().GetSeconds () | 169 NS_LOG_DEBUG (Simulator::Now ().GetSeconds () |
170 » » » » » » » » << "s BasicEnerg yHarvester:Harvested energy = " << m_harvestedPower); | 170 << "s BasicEnergyHarvester:Harvested energy = " << m_harvestedPo wer); |
171 | |
172 } | 171 } |
173 | 172 |
174 double | 173 double |
175 BasicEnergyHarvester::DoGetPower (void) const | 174 BasicEnergyHarvester::DoGetPower (void) const |
176 { | 175 { |
177 » NS_LOG_FUNCTION (this); | 176 NS_LOG_FUNCTION (this); |
178 » return m_harvestedPower; | 177 return m_harvestedPower; |
179 } | 178 } |
180 ·· | 179 ·· |
181 } // namespace ns3 | 180 } // namespace ns3 |
LEFT | RIGHT |