A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
end-device-lora-phy.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: Davide Magrin <magrinda@dei.unipd.it>,
7 * Michele Luvisotto <michele.luvisotto@dei.unipd.it>
8 * Stefano Romagnolo <romagnolostefano93@gmail.com>
9 */
10
11#ifndef END_DEVICE_LORA_PHY_H
12#define END_DEVICE_LORA_PHY_H
13
14#include "lora-phy.h"
15
16#include "ns3/traced-value.h"
17
18namespace ns3
19{
20namespace lorawan
21{
22
23/**
24 * @ingroup lorawan
25 *
26 * Receive notifications about PHY events.
27 */
29{
30 public:
31 virtual ~EndDeviceLoraPhyListener(); //!< Destructor
32
33 /**
34 * We have received the first bit of a packet. We decided
35 * that we could synchronize on this packet. It does not mean
36 * we will be able to successfully receive completely the
37 * whole packet. It means that we will report a BUSY status until
38 * one of the following happens:
39 * - NotifyRxEndOk
40 * - NotifyRxEndError
41 * - NotifyTxStart
42 */
43 virtual void NotifyRxStart() = 0;
44
45 /**
46 * We are about to send the first bit of the packet.
47 * We do not send any event to notify the end of
48 * transmission. Listeners should assume that the
49 * channel implicitly reverts to the idle state
50 * unless they have received a cca busy report.
51 *
52 * @param txPowerDbm The nominal tx power in dBm.
53 */
54 virtual void NotifyTxStart(double txPowerDbm) = 0;
55
56 /**
57 * Notify listeners that we went to sleep.
58 */
59 virtual void NotifySleep() = 0;
60
61 /**
62 * Notify listeners that we woke up.
63 */
64 virtual void NotifyStandby() = 0;
65};
66
67/**
68 * @ingroup lorawan
69 *
70 * Class representing a LoRa transceiver.
71 *
72 * This class inherits some functionality by LoraPhy, like the GetOnAirTime
73 * function, and extends it to represent the behavior of a LoRa chip, like the
74 * SX1272.
75 *
76 * Additional behaviors featured in this class include a State member variable
77 * that expresses the current state of the device (SLEEP, TX, RX or STANDBY),
78 * and a frequency and Spreading Factor this device is listening to when in
79 * STANDBY mode. After transmission and reception, the device returns
80 * automatically to STANDBY mode. The decision of when to go into SLEEP mode
81 * is delegateed to an upper layer, which can modify the state of the device
82 * through the public SwitchToSleep and SwitchToStandby methods. In SLEEP
83 * mode, the device cannot lock on a packet and start reception.
84 *
85 * Peculiarities about the error model and about how errors are handled are
86 * supposed to be handled by classes extending this one, like
87 * SimpleEndDeviceLoraPhy or SpectrumEndDeviceLoraPhy. These classes need to
88 */
90{
91 public:
92 /**
93 * An enumeration of the possible states of an EndDeviceLoraPhy.
94 * It makes sense to define a state for End Devices since there's only one
95 * demodulator which can either send, receive, stay idle or go in a deep
96 * sleep state.
97 */
98 enum class State
99 {
100 /**
101 * The PHY layer is sleeping.
102 * During sleep, the device is not listening for incoming messages.
103 */
105
106 /**
107 * The PHY layer is in STANDBY.
108 * When the PHY is in this state, it's listening to the channel, and
109 * it's also ready to transmit data passed to it by the MAC layer.
110 */
112
113 /**
114 * The PHY layer is sending a packet.
115 * During transmission, the device cannot receive any packet or send
116 * any additional packet.
117 */
119
120 /**
121 * The PHY layer is receiving a packet.
122 * While the device is locked on an incoming packet, transmission is
123 * not possible.
124 */
126 // NOTE: When extending/updating, please update operator<< accordingly.
127 };
128
129 /**
130 * Register this type.
131 * @return The object TypeId.
132 */
133 static TypeId GetTypeId();
134
135 EndDeviceLoraPhy(); //!< Default constructor
136 ~EndDeviceLoraPhy() override; //!< Destructor
137
138 // Implementation of LoraPhy's pure virtual functions
140 double rxPowerDbm,
141 uint8_t sf,
142 Time duration,
143 uint32_t frequencyHz) override = 0;
144
145 // Implementation of LoraPhy's pure virtual functions
147
148 // Implementation of LoraPhy's pure virtual functions
149 void Send(Ptr<Packet> packet,
150 LoraTxParameters txParams,
151 uint32_t frequencyHz,
152 double txPowerDbm) override = 0;
153
154 // Implementation of LoraPhy's pure virtual functions
155 bool IsOnFrequency(uint32_t frequencyHz) override;
156
157 // Implementation of LoraPhy's pure virtual functions
158 bool IsTransmitting() override;
159
160 /**
161 * Set the frequency this end device will listen on.
162 *
163 * Should a packet be transmitted on a frequency different than that the
164 * EndDeviceLoraPhy is listening on, the packet will be discarded.
165 *
166 * @param frequencyHz The frequency [Hz] to listen to.
167 */
168 void SetFrequency(uint32_t frequencyHz);
169
170 /**
171 * Set the Spreading Factor this end device will listen for.
172 *
173 * The EndDeviceLoraPhy object will not be able to lock on transmissions that
174 * use a different spreading factor than the one it's listening for.
175 *
176 * @param sf The spreading factor to listen for.
177 */
178 void SetSpreadingFactor(uint8_t sf);
179
180 /**
181 * Get the Spreading Factor this end device is listening for.
182 *
183 * @return The Spreading Factor we are listening for.
184 */
185 uint8_t GetSpreadingFactor() const;
186
187 /**
188 * Return the state this end device is currently in.
189 *
190 * @return The state this EndDeviceLoraPhy is currently in.
191 */
193
194 /**
195 * Switch to the STANDBY state.
196 */
197 void SwitchToStandby();
198
199 /**
200 * Switch to the SLEEP state.
201 */
202 void SwitchToSleep();
203
204 /**
205 * Add the input listener to the list of objects to be notified of PHY-level
206 * events.
207 *
208 * @param listener The new listener.
209 */
211
212 /**
213 * Remove the input listener from the list of objects to be notified of
214 * PHY-level events.
215 *
216 * @param listener The listener to be unregistered.
217 */
219
220 static const double sensitivity[6]; //!< The sensitivity vector of this device to different SFs
221
222 protected:
223 /**
224 * Signals the end of a transmission by the EndDeviceLoraPhy.
225 *
226 * @param packet A pointer to the Packet transmitted.
227 */
228 void TxFinished(Ptr<const Packet> packet) override;
229
230 /**
231 * Switch to the RX state.
232 */
233 void SwitchToRx();
234
235 /**
236 * Switch to the TX state.
237 *
238 * @param txPowerDbm The transmission power [dBm].
239 */
240 void SwitchToTx(double txPowerDbm);
241
242 /**
243 * Trace source for when a packet is lost because it was using a spreading factor different from
244 * the one this EndDeviceLoraPhy was configured to listen for.
245 */
247
248 /**
249 * Trace source for when a packet is lost because it was transmitted on a
250 * frequency different from the one this EndDeviceLoraPhy was configured to
251 * listen on.
252 */
254
255 TracedValue<State> m_state; //!< The state this PHY is currently in.
256
257 // static const double sensitivity[6]; //!< The sensitivity vector of this device to different
258 // SFs
259
260 uint32_t m_frequencyHz; //!< The frequency [Hz] this device is listening on
261
262 uint8_t m_sf; //!< The Spreading Factor this device is listening for
263
264 /**
265 * typedef for a list of EndDeviceLoraPhyListener.
266 */
267 typedef std::vector<EndDeviceLoraPhyListener*> Listeners;
268 /**
269 * typedef for a list of EndDeviceLoraPhyListener iterator.
270 */
271 typedef std::vector<EndDeviceLoraPhyListener*>::iterator ListenersI;
272
273 Listeners m_listeners; //!< PHY listeners
274};
275
276/**
277 * Overloaded operator to print the value of a EndDeviceLoraPhy::State.
278 *
279 * @param os The output stream
280 * @param state The enum value of the PHY state
281 * @return The output stream with text value of the PHY state
282 */
283std::ostream& operator<<(std::ostream& os, const EndDeviceLoraPhy::State& state);
284
285} // namespace lorawan
286} // namespace ns3
287
288#endif /* END_DEVICE_LORA_PHY_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Forward calls to a chain of Callback.
Trace classes with value semantics.
a unique identifier for an interface.
Definition type-id.h:50
void SwitchToSleep()
Switch to the SLEEP state.
EndDeviceLoraPhy::State GetState()
Return the state this end device is currently in.
void StartReceive(Ptr< Packet > packet, double rxPowerDbm, uint8_t sf, Time duration, uint32_t frequencyHz) override=0
Start receiving a packet.
void Send(Ptr< Packet > packet, LoraTxParameters txParams, uint32_t frequencyHz, double txPowerDbm) override=0
Instruct the PHY to send a packet according to some parameters.
uint8_t GetSpreadingFactor() const
Get the Spreading Factor this end device is listening for.
static const double sensitivity[6]
The sensitivity vector of this device to different SFs.
std::vector< EndDeviceLoraPhyListener * >::iterator ListenersI
typedef for a list of EndDeviceLoraPhyListener iterator.
Listeners m_listeners
PHY listeners.
void RegisterListener(EndDeviceLoraPhyListener *listener)
Add the input listener to the list of objects to be notified of PHY-level events.
bool IsTransmitting() override
Whether this device is transmitting or not.
uint8_t m_sf
The Spreading Factor this device is listening for.
static TypeId GetTypeId()
Register this type.
bool IsOnFrequency(uint32_t frequencyHz) override
Whether this device is listening on the specified frequency or not.
void SwitchToRx()
Switch to the RX state.
void EndReceive(Ptr< Packet > packet, Ptr< LoraInterferenceHelper::Event > event) override=0
Finish reception of a packet.
std::vector< EndDeviceLoraPhyListener * > Listeners
typedef for a list of EndDeviceLoraPhyListener.
void SwitchToStandby()
Switch to the STANDBY state.
EndDeviceLoraPhy()
Default constructor.
~EndDeviceLoraPhy() override
Destructor.
void SetFrequency(uint32_t frequencyHz)
Set the frequency this end device will listen on.
uint32_t m_frequencyHz
The frequency [Hz] this device is listening on.
void SetSpreadingFactor(uint8_t sf)
Set the Spreading Factor this end device will listen for.
TracedValue< State > m_state
The state this PHY is currently in.
TracedCallback< Ptr< const Packet >, uint32_t > m_wrongSf
Trace source for when a packet is lost because it was using a spreading factor different from the one...
void SwitchToTx(double txPowerDbm)
Switch to the TX state.
void UnregisterListener(EndDeviceLoraPhyListener *listener)
Remove the input listener from the list of objects to be notified of PHY-level events.
State
An enumeration of the possible states of an EndDeviceLoraPhy.
@ TX
The PHY layer is sending a packet.
@ STANDBY
The PHY layer is in STANDBY.
@ RX
The PHY layer is receiving a packet.
void TxFinished(Ptr< const Packet > packet) override
Signals the end of a transmission by the EndDeviceLoraPhy.
TracedCallback< Ptr< const Packet >, uint32_t > m_wrongFrequency
Trace source for when a packet is lost because it was transmitted on a frequency different from the o...
Receive notifications about PHY events.
virtual void NotifyStandby()=0
Notify listeners that we woke up.
virtual void NotifyTxStart(double txPowerDbm)=0
We are about to send the first bit of the packet.
virtual void NotifyRxStart()=0
We have received the first bit of a packet.
virtual void NotifySleep()=0
Notify listeners that we went to sleep.
LoraPhy()
Default constructor.
Definition lora-phy.cc:67
std::ostream & operator<<(std::ostream &os, const EndDeviceLoraPhy::State &state)
Overloaded operator to print the value of a EndDeviceLoraPhy::State.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure to collect all parameters that are used to compute the duration of a packet (excluding payl...
Definition lora-phy.h:54