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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Romagnolo Stefano <romagnolostefano93@gmail.com>
7 * Davide Magrin <magrinda@dei.unipd.it>
8 */
9
10#ifndef LORA_RADIO_ENERGY_MODEL_H
11#define LORA_RADIO_ENERGY_MODEL_H
12
13#include "end-device-lora-phy.h"
14
15#include "ns3/device-energy-model.h"
16#include "ns3/traced-value.h"
17
18namespace ns3
19{
20namespace lorawan
21{
22
24
25/**
26 * @ingroup lorawan
27 *
28 * A EndDeviceLoraPhy listener class for notifying the LoraRadioEnergyModel of Lora radio
29 * state change.
30 */
32{
33 public:
34 /**
35 * Callback type for updating the transmit current based on the nominal tx power.
36 */
38
39 LoraRadioEnergyModelPhyListener(); //!< Default constructor
40 ~LoraRadioEnergyModelPhyListener() override; //!< Destructor
41
42 /**
43 * @brief Sets the change state callback. Used by helper class.
44 *
45 * @param callback Change state callback.
46 */
48
49 /**
50 * @brief Sets the update tx current callback.
51 *
52 * @param callback Update tx current callback.
53 */
55
56 void NotifySleep() override;
57 void NotifyStandby() override;
58 void NotifyTx(double txPowerDbm) override;
59 void NotifyRxEnabled() override;
60 void NotifyRxActive() override;
61
62 private:
63 /**
64 * Change state callback used to notify the LoraRadioEnergyModel of a state
65 * change.
66 */
68
69 /**
70 * Callback used to update the tx current stored in LoraRadioEnergyModel based on
71 * the nominal tx power used to transmit the current frame.
72 */
74};
75
76/**
77 * @ingroup lorawan
78 *
79 * @brief A LoRa radio energy model.
80 *
81 * 4 energy states are defined for the radio: TX, RX, STANDBY, SLEEP. Default state is STANDBY.
82 * The different types of transactions that are defined are:
83 * 1. Tx: State goes from SLEEP/STANDBY to TX, radio is in TX state,
84 * then state goes from TX to STANDBY.
85 * 2. Rx: State goes from SLEEP/STANDBY to RX, radio is in RX state,
86 * then state goes from RX to STANDBY.
87 * 3. Sleep: State goes from STANDBY to SLEEP.
88 * The class keeps track of what state the radio is currently in.
89 *
90 * Energy calculation: For each transaction, this model notifies EnergySource
91 * object. The EnergySource object will query this model for the total current.
92 * Then the EnergySource object uses the total current to calculate energy.
93 *
94 * Default values for current are based on measurements reported in:
95 *
96 * Semtech Corp., "SX1272/73 Datasheet, Rev. 4, Jan. 2019"
97 *
98 * The default current values in Ampere are:
99 *
100 * \f$ I_{sleep} = 0.0000001 \f$
101 *
102 * \f$ I_{standby} = 0.0014 \f$
103 *
104 * \f$ I_{tx} = 0.028 \f$ (transmit at 13dBm)
105 *
106 * \f$ I_{rx} = 0.0108 \f$
107 *
108 * The dependence of the power consumption in transmission mode on the nominal
109 * transmit power can also be achieved through a LoRa TX current model.
110 *
111 */
113{
114 public:
115 /**
116 * Callback type for energy depletion handling.
117 */
119
120 /**
121 * Callback type for energy recharged handling.
122 */
124
125 /**
126 * Register this type.
127 * @return The object TypeId.
128 */
129 static TypeId GetTypeId();
130
131 LoraRadioEnergyModel(); //!< Default constructor
132 ~LoraRadioEnergyModel() override; //!< Destructor
133
134 /**
135 * @brief Sets pointer to EnergySource installed on node.
136 *
137 * @param source Pointer to EnergySource installed on node.
138 *
139 * Implements energy::DeviceEnergyModel::SetEnergySource.
140 */
141 void SetEnergySource(Ptr<energy::EnergySource> source) override;
142
143 /**
144 * @return Total energy consumption of the wifi device.
145 *
146 * Implements energy::DeviceEnergyModel::GetTotalEnergyConsumption.
147 */
148 double GetTotalEnergyConsumption() const override;
149
150 // Setter & getters for state power consumption.
151 /**
152 * @brief Gets standby current.
153 *
154 * @return Standby current [A] of the lora device.
155 */
156 double GetStandbyCurrentA() const;
157 /**
158 * @brief Sets standby current.
159 *
160 * @param standbyCurrentA The standby current [A].
161 */
162 void SetStandbyCurrentA(double standbyCurrentA);
163 /**
164 * @brief Gets transmit current.
165 *
166 * @return Transmit current [A] of the lora device.
167 */
168 double GetTxCurrentA() const;
169 /**
170 * @brief Sets transmit current.
171 *
172 * @param txCurrentA The transmit current [A].
173 */
174 void SetTxCurrentA(double txCurrentA);
175 /**
176 * @brief Gets receive current.
177 *
178 * @return Receive current [A] of the lora device.
179 */
180 double GetRxCurrentA() const;
181 /**
182 * @brief Sets receive current.
183 *
184 * @param rxCurrentA The receive current [A].
185 */
186 void SetRxCurrentA(double rxCurrentA);
187 /**
188 * @brief Gets sleep current.
189 *
190 * @return Sleep current [A] of the lora device.
191 */
192 double GetSleepCurrentA() const;
193 /**
194 * @brief Sets sleep current.
195 *
196 * @param sleepCurrentA The sleep current [A].
197 */
198 void SetSleepCurrentA(double sleepCurrentA);
199
200 /**
201 * @return Current state.
202 */
204
205 /**
206 * @param callback Callback function.
207 *
208 * Sets callback for energy depletion handling.
209 */
211
212 /**
213 * @param callback Callback function.
214 *
215 * Sets callback for energy recharged handling.
216 */
218
219 /**
220 * @param model The model used to compute the lora TX current.
221 */
223
224 /**
225 * @brief Calls the CalcTxCurrent method of the tx current model to
226 * compute the tx current based on such model.
227 *
228 * @param txPowerDbm The nominal tx power in dBm.
229 */
230 void SetTxCurrentFromModel(double txPowerDbm);
231
232 /**
233 * Changes state of the LoraRadioEnergyModel.
234 *
235 * @param newState New state the lora radio is in.
236 *
237 * Implements energy::DeviceEnergyModel::ChangeState.
238 */
239 void ChangeState(int newState) override;
240
241 /**
242 * Handles energy depletion.
243 *
244 * Implements energy::DeviceEnergyModel::HandleEnergyDepletion.
245 */
246 void HandleEnergyDepletion() override;
247
248 /**
249 * Handles energy recharged.
250 *
251 * Implements energy::DeviceEnergyModel::HandleEnergyRecharged.
252 */
253 void HandleEnergyRecharged() override;
254
255 /**
256 * Handles energy changed.
257 *
258 * Implements energy::DeviceEnergyModel::HandleEnergyChanged.
259 */
260 void HandleEnergyChanged() override;
261
262 /**
263 * @return Pointer to the PHY listener.
264 */
265 std::shared_ptr<LoraRadioEnergyModelPhyListener> GetPhyListener();
266
267 private:
268 void DoDispose() override;
269
270 /**
271 * @param state the lora state
272 * @returns draw of device at given state.
273 */
274 double GetStateA(EndDeviceLoraPhy::State state) const;
275
276 /**
277 * @return Current draw of device, at current state.
278 *
279 * Implements energy::DeviceEnergyModel::GetCurrentA.
280 */
281 double DoGetCurrentA() const override;
282
283 /**
284 * @param state New state the radio device is currently in.
285 *
286 * Sets current state. This function is private so that only the energy model
287 * can change its own state.
288 */
290
292
293 // Member variables for current draw in different radio modes.
294 double m_txCurrentA; //!< transmit current
295 double m_rxCurrentA; //!< receive current
296 double m_standbyCurrentA; //!< standby current
297 double m_sleepCurrentA; //!< sleep current
299
300 /// This variable keeps track of the total energy consumed by this model.
302
303 // State variables.
304 EndDeviceLoraPhy::State m_currentState; ///< current state the radio is in
305 Time m_lastUpdateTime; ///< time stamp of previous energy update
306
307 uint8_t m_nPendingChangeState; ///< pending state change
308
309 /// Energy depletion callback
311
312 /// Energy recharged callback
314
315 /// EndDeviceLoraPhy listener
316 std::shared_ptr<LoraRadioEnergyModelPhyListener> m_listener;
317};
318
319} // namespace lorawan
320} // namespace ns3
321
322#endif /* LORA_RADIO_ENERGY_MODEL_H */
Callback template class.
Definition callback.h:428
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Trace classes with value semantics.
a unique identifier for an interface.
Definition type-id.h:50
Base class for device energy models.
Callback< void, int > ChangeStateCallback
Callback type for ChangeState function.
State
An enumeration of the possible internal states of an EndDeviceLoraPhy.
Receive notifications about PHY internal state changes.
void HandleEnergyChanged() override
Handles energy changed.
double GetStateA(EndDeviceLoraPhy::State state) const
Callback< void > LoraRadioEnergyDepletionCallback
Callback type for energy depletion handling.
uint8_t m_nPendingChangeState
pending state change
double GetTxCurrentA() const
Gets transmit current.
void ChangeState(int newState) override
Changes state of the LoraRadioEnergyModel.
double GetRxCurrentA() const
Gets receive 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.
Ptr< energy::EnergySource > m_source
energy source
EndDeviceLoraPhy::State m_currentState
current state the radio is in
void HandleEnergyRecharged() override
Handles energy recharged.
std::shared_ptr< LoraRadioEnergyModelPhyListener > GetPhyListener()
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 standby current.
Ptr< LoraTxCurrentModel > m_txCurrentModel
current model
Callback< void > LoraRadioEnergyRechargedCallback
Callback type for energy recharged handling.
void SetEnergyDepletionCallback(LoraRadioEnergyDepletionCallback callback)
void SetStandbyCurrentA(double standbyCurrentA)
Sets standby current.
void SetSleepCurrentA(double sleepCurrentA)
Sets sleep current.
void SetRxCurrentA(double rxCurrentA)
Sets receive current.
void SetTxCurrentA(double txCurrentA)
Sets transmit current.
void SetEnergySource(Ptr< energy::EnergySource > source) override
Sets pointer to EnergySource installed on node.
std::shared_ptr< LoraRadioEnergyModelPhyListener > m_listener
EndDeviceLoraPhy listener.
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.
void NotifyStandby() override
Notify listeners that the device entered STANDBY state.
void NotifySleep() override
Notify listeners that the device entered SLEEP state.
void SetChangeStateCallback(energy::DeviceEnergyModel::ChangeStateCallback callback)
Sets the change state callback.
energy::DeviceEnergyModel::ChangeStateCallback m_changeStateCallback
Change state callback used to notify the LoraRadioEnergyModel of a state change.
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 NotifyRxActive() override
Notify listeners that the device entered RX_ACTIVE state.
UpdateTxCurrentCallback m_updateTxCurrentCallback
Callback used to update the tx current stored in LoraRadioEnergyModel based on the nominal tx power u...
void NotifyRxEnabled() override
Notify listeners that the device entered RX_ENABLED state.
void NotifyTx(double txPowerDbm) override
Notify listeners that the device entered TX state.
Model the transmit current as a function of the transmit power and mode.
Every class exported by the ns3 library is enclosed in the ns3 namespace.