A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-radio-energy-model.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
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 * Authors: Romagnolo Stefano <romagnolostefano93@gmail.com>
18 * Davide Magrin <magrinda@dei.unipd.it>
19 */
20
21#ifndef LORA_RADIO_ENERGY_MODEL_H
22#define LORA_RADIO_ENERGY_MODEL_H
23
24#include "end-device-lora-phy.h"
26
27#include "ns3/device-energy-model.h"
28#include "ns3/traced-value.h"
29
30namespace ns3
31{
32namespace lorawan
33{
34
35using namespace energy;
36
37/**
38 * \ingroup lorawan
39 *
40 * Installable listener for LoRa physiscal layer state changes
41 */
43{
44 public:
45 /**
46 * Callback type for updating the transmit current based on the nominal tx power.
47 */
49
50 LoraRadioEnergyModelPhyListener(); //!< Default constructor
51 ~LoraRadioEnergyModelPhyListener() override; //!< Destructor
52
53 /**
54 * Sets the change state callback. Used by helper class.
55 *
56 * \param callback Change state callback.
57 */
59
60 /**
61 * Sets the update tx current callback.
62 *
63 * \param callback Update tx current callback.
64 */
66
67 /**
68 * Switches the LoraRadioEnergyModel to RX state.
69 *
70 * Defined in ns3::LoraEndDevicePhyListener.
71 */
72 void NotifyRxStart() override;
73
74 /**
75 * Switches the LoraRadioEnergyModel to TX state and switches back to
76 * STANDBY after TX duration.
77 *
78 * \param txPowerDbm The nominal tx power in dBm.
79 *
80 * Defined in ns3::LoraEndDevicePhyListener.
81 */
82 void NotifyTxStart(double txPowerDbm) override;
83
84 /**
85 * Defined in ns3::LoraEndDevicePhyListener.
86 */
87 void NotifySleep() override;
88
89 /**
90 * Defined in ns3::LoraEndDevicePhyListener.
91 */
92 void NotifyStandby() override;
93
94 private:
95 /**
96 * A helper function that makes scheduling m_changeStateCallback possible.
97 */
98 void SwitchToStandby();
99
100 /**
101 * Change state callback used to notify the LoraRadioEnergyModel of a state
102 * change.
103 */
105
106 /**
107 * Callback used to update the tx current stored in LoraRadioEnergyModel based on
108 * the nominal tx power used to transmit the current frame.
109 */
111};
112
113/**
114 * \ingroup lorawan
115 *
116 * A LoRa radio energy model.
117 *
118 * 4 states are defined for the radio: TX, RX, STANDBY, SLEEP. Default state is
119 * STANDBY.
120 * The different types of transactions that are defined are:
121 * 1. Tx: State goes from STANDBY to TX, radio is in TX state for TX_duration,
122 * then state goes from TX to STANDBY.
123 * 2. Rx: State goes from STANDBY to RX, radio is in RX state for RX_duration,
124 * then state goes from RX to STANDBY.
125 * 3. Go_to_Sleep: State goes from STANDBY to SLEEP.
126 * 4. End_of_Sleep: State goes from SLEEP to STANDBY.
127 * The class keeps track of what state the radio is currently in.
128 *
129 * Energy calculation: For each transaction, this model notifies EnergySource
130 * object. The EnergySource object will query this model for the total current.
131 * Then the EnergySource object uses the total current to calculate energy.
132 */
134{
135 public:
136 /**
137 * Callback type for energy depletion handling.
138 */
140
141 /**
142 * Callback type for energy recharged handling.
143 */
145
146 /**
147 * Register this type.
148 * \return The object TypeId.
149 */
150 static TypeId GetTypeId();
151
153 ~LoraRadioEnergyModel() override; //!< Destructor
154
155 /**
156 * Sets pointer to EnergySouce installed on node.
157 *
158 * \param source Pointer to EnergySource installed on node.
159 *
160 * Implements DeviceEnergyModel::SetEnergySource.
161 */
162 void SetEnergySource(Ptr<EnergySource> source) override;
163
164 /**
165 * \return Total energy consumption of the wifi device.
166 *
167 * Implements DeviceEnergyModel::GetTotalEnergyConsumption.
168 */
169 double GetTotalEnergyConsumption() const override;
170
171 // Setter & getters for state power consumption.
172 /**
173 * Gets idle current.
174 *
175 * \return Idle current [A] of the lora device.
176 */
177 double GetStandbyCurrentA() const;
178 /**
179 * Sets idle current.
180 *
181 * \param idleCurrentA The idle current [A].
182 */
183 void SetStandbyCurrentA(double idleCurrentA);
184 /**
185 * Gets transmit current.
186 *
187 * \return Transmit current [A] of the lora device.
188 */
189 double GetTxCurrentA() const;
190 /**
191 * Sets transmit current.
192 *
193 * \param txCurrentA The transmit current [A].
194 */
195 void SetTxCurrentA(double txCurrentA);
196 /**
197 * Gets receive current.
198 *
199 * \return Receive current [A] of the lora device.
200 */
201 double GetRxCurrentA() const;
202 /**
203 * Sets receive current.
204 *
205 * \param rxCurrentA The receive current [A].
206 */
207 void SetRxCurrentA(double rxCurrentA);
208 /**
209 * Gets sleep current.
210 *
211 * \return Sleep current [A] of the lora device.
212 */
213 double GetSleepCurrentA() const;
214 /**
215 * Sets sleep current.
216 *
217 * \param sleepCurrentA The sleep current [A].
218 */
219 void SetSleepCurrentA(double sleepCurrentA);
220
221 /**
222 * \return Current state.
223 */
225
226 /**
227 * \param callback Callback function.
228 *
229 * Sets callback for energy depletion handling.
230 */
232
233 /**
234 * \param callback Callback function.
235 *
236 * Sets callback for energy recharged handling.
237 */
239
240 /**
241 * \param model The model used to compute the lora tx current.
242 */
243 // NOTICE VERY WELL: Current Model linear or constant as possible choices
245
246 /**
247 * Calls the CalcTxCurrent method of the tx current model to
248 * compute the tx current based on such model.
249 *
250 * \param txPowerDbm The nominal tx power in dBm.
251 */
252 // NOTICE VERY WELL: Current Model linear or constant as possible choices
253 void SetTxCurrentFromModel(double txPowerDbm);
254
255 /**
256 * Changes state of the LoraRadioEnergyMode.
257 *
258 * \param newState New state the lora radio is in.
259 *
260 * Implements DeviceEnergyModel::ChangeState.
261 */
262 void ChangeState(int newState) override;
263
264 /**
265 * Handles energy depletion.
266 *
267 * Implements DeviceEnergyModel::HandleEnergyDepletion.
268 */
269 void HandleEnergyDepletion() override;
270
271 /**
272 * Handles energy recharged.
273 *
274 * Implements DeviceEnergyModel::HandleEnergyChanged.
275 */
276 void HandleEnergyChanged() override;
277
278 /**
279 * Handles energy recharged.
280 *
281 * Implements DeviceEnergyModel::HandleEnergyRecharged.
282 */
283 void HandleEnergyRecharged() override;
284
285 /**
286 * \return Pointer to the PHY listener.
287 */
289
290 private:
291 void DoDispose() override;
292
293 /**
294 * \return Current draw of device, at current state.
295 *
296 * Implements DeviceEnergyModel::GetCurrentA.
297 */
298 double DoGetCurrentA() const override;
299
300 /**
301 * \param state New state the radio device is currently in.
302 *
303 * Sets current state. This function is private so that only the energy model
304 * can change its own state.
305 */
307
308 Ptr<EnergySource> m_source; ///< energy source
309
310 // Member variables for current draw in different radio modes.
311 double m_txCurrentA; ///< transmit current
312 double m_rxCurrentA; ///< receive current
313 double m_idleCurrentA; ///< idle current
314 double m_sleepCurrentA; ///< sleep current
315 // NOTICE VERY WELL: Current Model linear or constant as possible choices
317
318 /// This variable keeps track of the total energy consumed by this model.
320
321 // State variables.
322 EndDeviceLoraPhy::State m_currentState; ///< current state the radio is in
323 Time m_lastUpdateTime; ///< time stamp of previous energy update
324
325 uint8_t m_nPendingChangeState; ///< pending state change
326 bool m_isSupersededChangeState; ///< superseded change state
327
328 /// Energy depletion callback
330
331 /// Energy recharged callback
333
334 /// EndDeviceLoraPhy listener
336};
337
338} // namespace lorawan
339
340} // namespace ns3
341#endif /* LORA_RADIO_ENERGY_MODEL_H */
Callback template class.
Definition: callback.h:438
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
Base class for device energy models.
State
An enumeration of the possible states of an EndDeviceLoraPhy.
Receive notifications about PHY events.
LoraRadioEnergyModelPhyListener * m_listener
EndDeviceLoraPhy listener.
LoraRadioEnergyModelPhyListener * GetPhyListener()
void HandleEnergyChanged() override
Handles energy recharged.
Callback< void > LoraRadioEnergyDepletionCallback
Callback type for energy depletion handling.
uint8_t m_nPendingChangeState
pending state change
void SetEnergySource(Ptr< EnergySource > source) override
Sets pointer to EnergySouce installed on node.
double GetTxCurrentA() const
Gets transmit current.
void ChangeState(int newState) override
Changes state of the LoraRadioEnergyMode.
double GetTotalEnergyConsumption() const override
double GetRxCurrentA() const
Gets receive current.
void SetStandbyCurrentA(double idleCurrentA)
Sets idle current.
void SetTxCurrentFromModel(double txPowerDbm)
Calls the CalcTxCurrent method of the tx current model to compute the tx current based on such model.
LoraRadioEnergyDepletionCallback m_energyDepletionCallback
Energy depletion callback.
void DoDispose() override
Destructor implementation.
EndDeviceLoraPhy::State m_currentState
current state the radio is in
bool m_isSupersededChangeState
superseded change state
void HandleEnergyRecharged() override
Handles energy recharged.
void HandleEnergyDepletion() override
Handles energy depletion.
void SetEnergyRechargedCallback(LoraRadioEnergyRechargedCallback callback)
void SetLoraRadioState(const EndDeviceLoraPhy::State state)
Time m_lastUpdateTime
time stamp of previous energy update
double GetStandbyCurrentA() const
Gets idle current.
Ptr< LoraTxCurrentModel > m_txCurrentModel
current model
Callback< void > LoraRadioEnergyRechargedCallback
Callback type for energy recharged handling.
void SetEnergyDepletionCallback(LoraRadioEnergyDepletionCallback callback)
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current.
void SetRxCurrentA(double rxCurrentA)
Sets receive current.
Ptr< EnergySource > m_source
energy source
void SetTxCurrentA(double txCurrentA)
Sets transmit current.
double GetSleepCurrentA() const
Gets sleep current.
void SetTxCurrentModel(Ptr< LoraTxCurrentModel > model)
static TypeId GetTypeId()
Register this type.
EndDeviceLoraPhy::State GetCurrentState() const
LoraRadioEnergyRechargedCallback m_energyRechargedCallback
Energy recharged callback.
TracedValue< double > m_totalEnergyConsumption
This variable keeps track of the total energy consumed by this model.
Installable listener for LoRa physiscal layer state changes.
void NotifyTxStart(double txPowerDbm) override
Switches the LoraRadioEnergyModel to TX state and switches back to STANDBY after TX duration.
DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the LoraRadioEnergyModel of a state change.
void NotifyStandby() override
Defined in ns3::LoraEndDevicePhyListener.
void NotifySleep() override
Defined in ns3::LoraEndDevicePhyListener.
void SetChangeStateCallback(DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
Callback< void, double > UpdateTxCurrentCallback
Callback type for updating the transmit current based on the nominal tx power.
void SetUpdateTxCurrentCallback(UpdateTxCurrentCallback callback)
Sets the update tx current callback.
void SwitchToStandby()
A helper function that makes scheduling m_changeStateCallback possible.
void NotifyRxStart() override
Switches the LoraRadioEnergyModel to RX state.
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the tx current stored in LoraRadioEnergyModel based on the nominal tx power u...
Every class exported by the ns3 library is enclosed in the ns3 namespace.