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