A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
gateway-lora-phy.cc
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 * Author: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20#include "gateway-lora-phy.h"
21
22#include "lora-tag.h"
23
24#include "ns3/log-macros-enabled.h"
25#include "ns3/log.h"
26#include "ns3/simulator.h"
27
28namespace ns3
29{
30namespace lorawan
31{
32
33NS_LOG_COMPONENT_DEFINE("GatewayLoraPhy");
34
35NS_OBJECT_ENSURE_REGISTERED(GatewayLoraPhy);
36
37/**************************************
38 * ReceptionPath implementation *
39 **************************************/
41 : m_available(true),
42 m_event(nullptr),
43 m_endReceiveEventId(EventId())
44{
46}
47
49{
51}
52
53bool
55{
56 return m_available;
57}
58
59void
61{
62 m_available = true;
63 m_event = nullptr;
64 m_endReceiveEventId = EventId();
65}
66
67void
69{
70 m_available = false;
71 m_event = event;
72}
73
74void
76{
77 m_event = event;
78}
79
82{
83 return m_event;
84}
85
88{
89 return m_endReceiveEventId;
90}
91
92void
94{
95 m_endReceiveEventId = endReceiveEventId;
96}
97
98/***********************************************************************
99 * Implementation of gateway methods *
100 ***********************************************************************/
101
102TypeId
104{
105 static TypeId tid =
106 TypeId("ns3::GatewayLoraPhy")
108 .SetGroupName("lorawan")
109 .AddTraceSource(
110 "NoReceptionBecauseTransmitting",
111 "Trace source indicating a packet "
112 "could not be correctly received because"
113 "the gateway is in transmission mode",
115 "ns3::Packet::TracedCallback")
116 .AddTraceSource("LostPacketBecauseNoMoreReceivers",
117 "Trace source indicating a packet "
118 "could not be correctly received because"
119 "there are no more demodulators available",
121 "ns3::Packet::TracedCallback")
122 .AddTraceSource("OccupiedReceptionPaths",
123 "Number of currently occupied reception paths",
125 "ns3::TracedValueCallback::Int");
126 return tid;
127}
128
130 : m_isTransmitting(false)
131{
133}
134
136{
138}
139
140// Uplink sensitivity (Source: SX1301 datasheet)
141// {SF7, SF8, SF9, SF10, SF11, SF12}
142const double GatewayLoraPhy::sensitivity[6] = {-130.0, -132.5, -135.0, -137.5, -140.0, -142.5};
143
144void
146{
148
149 m_receptionPaths.push_back(Create<GatewayLoraPhy::ReceptionPath>());
150}
151
152void
154{
155 NS_LOG_FUNCTION(this);
156
157 m_receptionPaths.clear();
158}
159
160void
162{
163 m_isTransmitting = false;
164}
165
166bool
168{
169 return m_isTransmitting;
170}
171
172void
174{
175 NS_LOG_FUNCTION(this << frequencyMHz);
176
177 m_frequencies.push_back(frequencyMHz);
178
179 NS_ASSERT(m_frequencies.size() <= 8);
180}
181
182bool
184{
185 NS_LOG_FUNCTION(this << frequencyMHz);
186
187 // Look into our list of frequencies
188 for (auto& f : m_frequencies)
189 {
190 if (f == frequencyMHz)
191 {
192 return true;
193 }
194 }
195 return false;
196}
197} // namespace lorawan
198} // namespace ns3
An identifier for simulation events.
Definition: event-id.h:56
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
EventId GetEndReceive()
Get the EventId of the EndReceive call associated to this ReceptionPath's packet.
void SetEvent(Ptr< LoraInterferenceHelper::Event > event)
Set the event this reception path is currently on.
Ptr< LoraInterferenceHelper::Event > GetEvent()
Get the event this reception path is currently on.
void Free()
Set this reception path as available.
void SetEndReceive(EventId endReceiveEventId)
Set the EventId of the EndReceive call associated to this ReceptionPath's packet.
void LockOnEvent(Ptr< LoraInterferenceHelper::Event > event)
Set this reception path as not available and lock it on the provided event.
bool IsAvailable() const
Query whether this reception path is available to lock on a signal.
GatewayLoraPhy()
Default constructor.
bool m_isTransmitting
Flag indicating whether a transmission is going on.
void AddFrequency(double frequencyMHz)
Add a frequency to the list of frequencies we are listening to.
TracedValue< int > m_occupiedReceptionPaths
The number of occupied reception paths.
bool IsTransmitting() override
Whether this device is transmitting or not.
static const double sensitivity[6]
A vector containing the sensitivities required to correctly decode different spreading factors.
std::list< double > m_frequencies
List of frequencies the GatewayLoraPhy is listening to.
TracedCallback< Ptr< const Packet >, uint32_t > m_noReceptionBecauseTransmitting
Trace source fired when a packet cannot be received because the gateway is in transmission state.
bool IsOnFrequency(double frequencyMHz) override
Check whether the GatewayLoraPhy is currently listening to the specified frequency.
~GatewayLoraPhy() override
Destructor.
void ResetReceptionPaths()
Reset the list of reception paths.
static TypeId GetTypeId()
Register this type.
void TxFinished(Ptr< const Packet > packet) override
Signals the end of a transmission by the GatewayLoraPhy.
std::list< Ptr< ReceptionPath > > m_receptionPaths
A list containing the various parallel receivers that are managed by this gateway.
TracedCallback< Ptr< const Packet >, uint32_t > m_noMoreDemodulators
Trace source fired when a packet cannot be received because all available ReceivePath instances are b...
void AddReceptionPath()
Add a reception path, locked on a specific frequency.
Base class for PHY layers implementing the LoRa modulation scheme.
Definition: lora-phy.h:76
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.