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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#include "gateway-lora-phy.h"
10
11#include "lora-tag.h"
12
13#include "ns3/log-macros-enabled.h"
14#include "ns3/log.h"
15#include "ns3/simulator.h"
16
17namespace ns3
18{
19namespace lorawan
20{
21
22NS_LOG_COMPONENT_DEFINE("GatewayLoraPhy");
23
24NS_OBJECT_ENSURE_REGISTERED(GatewayLoraPhy);
25
26/**************************************
27 * ReceptionPath implementation *
28 **************************************/
30 : m_available(true),
31 m_event(nullptr),
32 m_endReceiveEventId(EventId())
33{
35}
36
41
42bool
44{
45 return m_available;
46}
47
48void
50{
51 m_available = true;
52 m_event = nullptr;
53 m_endReceiveEventId = EventId();
54}
55
56void
58{
59 m_available = false;
60 m_event = event;
61}
62
63void
68
71{
72 return m_event;
73}
74
77{
78 return m_endReceiveEventId;
79}
80
81void
83{
84 m_endReceiveEventId = endReceiveEventId;
85}
86
87/***********************************************************************
88 * Implementation of gateway methods *
89 ***********************************************************************/
90
93{
94 static TypeId tid =
95 TypeId("ns3::GatewayLoraPhy")
97 .SetGroupName("lorawan")
98 .AddTraceSource(
99 "NoReceptionBecauseTransmitting",
100 "Trace source indicating a packet "
101 "could not be correctly received because"
102 "the gateway is in transmission mode",
104 "ns3::Packet::TracedCallback")
105 .AddTraceSource("LostPacketBecauseNoMoreReceivers",
106 "Trace source indicating a packet "
107 "could not be correctly received because"
108 "there are no more demodulators available",
110 "ns3::Packet::TracedCallback")
111 .AddTraceSource("OccupiedReceptionPaths",
112 "Number of currently occupied reception paths",
114 "ns3::TracedValueCallback::Int");
115 return tid;
116}
117
123
128
129// Uplink sensitivity (Source: SX1301 datasheet)
130// {SF7, SF8, SF9, SF10, SF11, SF12}
131const double GatewayLoraPhy::sensitivity[6] = {-130.0, -132.5, -135.0, -137.5, -140.0, -142.5};
132
133void
140
141void
148
149void
154
155bool
160
161void
163{
164 NS_LOG_FUNCTION(this << frequencyMHz);
165
166 m_frequencies.push_back(frequencyMHz);
167
168 NS_ASSERT(m_frequencies.size() <= 8);
169}
170
171bool
173{
174 NS_LOG_FUNCTION(this << frequencyMHz);
175
176 // Look into our list of frequencies
177 for (auto& f : m_frequencies)
178 {
179 if (f == frequencyMHz)
180 {
181 return true;
182 }
183 }
184 return false;
185}
186} // namespace lorawan
187} // namespace ns3
An identifier for simulation events.
Definition event-id.h:45
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:65
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
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.