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