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