SX1302_HAL/packet_forwarder
Michael Coracin 2c14708bdb v2.0.0
> #### New features

* Added support for USB interface between the HOST and the concentrator,
for sx1250 based concentrator only.
* Added support for Listen-Before-Talk for AS923 region, using the additional
sx1261 radio from the Semtech Corecell reference design v3.
* Added support for Spectral Scan with additional sx1261 radio from the Semtech
Corecell reference design v3.
* Added support for SX1303 chip, for further Fine Timestamping support.
* Merged the master-fdd-cn490 branch to bring support for CN490 Full-Duplex
reference design. It is an integration of the releases v1.1.0, v1.1.1, v1.1.2
described below.

> #### Changes

* HAL: Reworked the complete communication layer. A new loragw_com module has
been introduced to handle switching from a USB or a SPI communication interface,
aligned function prototypes for sx125x, sx1250 and sx1261 radios. For USB, a
mode has been added to group SPI write commands request to the STM32 MCU, in
order to optimize latency during time critical configuration phases.
* HAL: Added preliminary support for Fine Timestamping for TDOA localization.
* HAL: Updated AGC firmware to v6: add configurable delay for PA to start, add
Listen-Before-Talk support.
* HAL: Added new API function lgw_demod_setconf() to set global demodulator
settings.
* HAL: Added new API functions for Spectral Scan.
* Packet Forwarder: The type of interface is configurable in the
global_conf.json file: com_type can be "USB" or "SPI".
* Packet Forwarder: Changed the parameters to configure fine timestamping in the
global_conf.json.
* Packet Forwarder: Added sections to configure the spectral scan and
Listen-Before-Talk features.
* Packet Forwarder: Added a new thread for background spectral scan example,
to show how to use the spectral scan API provided by the HAL, without
interfering with the main tasks of the gateway (aka Receive uplinks and transmit
downlinks).
* Packet Forwarder: Added "nhdr" field parsing from "txpk" JSON downlink request
in order to be able to send beacon request from Network Server.
* Packet Forwarder: Added chan_multiSF_All in global_conf.json to choose which
spreading factors to enable for multi-sf demodulators.
* Packet Forwarder: Updated PROTOCOL.md to v1.6.
* Tools: added util_spectral_scan, a standalone spectral scanner utility.

> #### Notes

* This release has been validated on the Semtech Corecell reference design v3
with USB interface.

v1.1.2

> Integrated in ***v2.0.0*** from ***master-fdd-cn490*** branch.

* packet forwarder: updated global_conf.json.sx1255.CN490.full-duplex with RSSI
temperature compensation coefficients, and updated RSSI offset for radio 1.

v1.1.1

> Integrated in ***v2.0.0*** from ***master-fdd-cn490*** branch.

* HAL: Updated SX1302 LNA/PA LUT configuration for Full Duplex CN490 reference
design.
* test_loragw_hal_rx/tx: added --fdd option to enable Full Duplex
* packet forwarder: updated global_conf.json.sx1255.CN490.full-duplex for CN490
reference design.

v1.1.0

> Integrated in ***v2.0.0*** from ***master-fdd-cn490*** branch.

* HAL: Added support for CN490 full duplex reference design.
2020-12-09 09:21:09 +01:00
..
inc v1.0.0 2019-07-12 15:40:13 +02:00
src v2.0.0 2020-12-09 09:21:09 +01:00
Makefile v2.0.0 2020-12-09 09:21:09 +01:00
PROTOCOL.md v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1250.AS923.USB v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1250.CN490 v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1250.CN490.USB v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1250.EU868 v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1250.EU868.USB v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1250.US915 v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1250.US915.USB v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1255.CN490.full-duplex v2.0.0 2020-12-09 09:21:09 +01:00
global_conf.json.sx1257.EU868 v2.0.0 2020-12-09 09:21:09 +01:00
readme.md v2.0.0 2020-12-09 09:21:09 +01:00

readme.md

 / _____)             _              | |
( (____  _____ ____ _| |_ _____  ____| |__
 \____ \| ___ |    (_   _) ___ |/ ___)  _ \
 _____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
  (C)2019 Semtech

SX1302 packet forwarder

1. Introduction

The packet forwarder is a program running on the host of a Lora gateway that forwards RF packets receive by the concentrator to a server through a IP/UDP link, and emits RF packets that are sent by the server. It can also emit a network-wide GPS-synchronous beacon signal used for coordinating all nodes of the network.

To learn more about the network protocol between the gateway and the server, please read the PROTOCOL.TXT document.

2. System schematic and definitions

((( Y )))
    |
    |
+- -|- - - - - - - - - - - - -+        xxxxxxxxxxxx          +--------+
|+--+-----------+     +------+|       xx x  x     xxx        |        |
||              |     |      ||      xx  Internet  xx        |        |
|| Concentrator |<----+ Host |<------xx     or    xx-------->|        |
||              | SPI |      ||      xx  Intranet  xx        | Server |
|+--------------+     +------+|       xxxx   x   xxxx        |        |
|   ^                    ^    |           xxxxxxxx           |        |
|   | PPS  +-----+  NMEA |    |                              |        |
|   +------| GPS |-------+    |                              +--------+
|          +-----+            |
|                             |
|            Gateway          |
+- - - - - - - - - - - - - - -+

Concentrator: radio RX/TX board, based on Semtech multichannel modems (SX130x), transceivers (SX135x) and/or low-power stand-alone modems (SX127x).

Host: embedded computer on which the packet forwarder is run. Drives the concentrator through a SPI link.

Gateway: a device composed of at least one radio concentrator, a host, some network connection to the internet or a private network (Ethernet, 3G, Wifi, microwave link), and optionally a GPS receiver for synchronization.

Server: an abstract computer that will process the RF packets received and forwarded by the gateway, and issue RF packets in response that the gateway will have to emit.

3. Dependencies

This program uses the Parson library (http://kgabis.github.com/parson/) by Krzysztof Gabis for JSON parsing. Many thanks to him for that very practical and well written library.

This program is statically linked with the libloragw Lora concentrator library. It was tested with v1.3.0 of the library but should work with any later version provided the API is v1 or a later backward-compatible API. Data structures of the received packets are accessed by name (ie. not at a binary level) so new functionalities can be added to the API without affecting that program at all.

This program follows the v1.3 version of the gateway-to-server protocol.

The last dependency is the hardware concentrator (based on FPGA or SX130x chips) that must be matched with the proper version of the HAL.

4. Usage

  • Pick the global_conf.json file that fit with your platform, region and feature need.
  • Update the JSON configuration (global and local) files, as explained below.
  • Run: ./lora_pkt_fwd -c global_conf.json

To stop the application, press Ctrl+C. Unless it is manually stopped or encounter a critical error, the program will run forever.

The way the program takes configuration files into account is the following:

  • if a specific configuration file is given as program argument, use the one specified.
  • if there is a global_conf.json parse it.

The global configuration file should be exactly the same throughout your network, contain all global parameters (parameters for "sensor" radio channels) and preferably default "safe" values for parameters that are specific for each gateway (eg. specify a default MAC address).

In each configuration file, the program looks for a JSON object named "SX130x_conf" that should contain the parameters for the Lora concentrator board (RF channels definition, modem parameters, etc) and another JSON object called "gateway_conf" that should contain the gateway parameters (gateway MAC address, IP address of the server, keep-alive time, etc).

To learn more about the JSON configuration format, read the provided JSON files and the libloragw API documentation.

Every X seconds (parameter settable in the configuration files) the program display statistics on the RF packets received and sent, and the network datagrams received and sent. The program also send some statistics to the server in JSON format.

The LoRa concentrator can have only one TX packet programmed for departure at a time. The actual departure of a downlink packet will be done based on its timestamp, when the concentrator internal counter reaches timestamps value. The departure of a beacon will be done based on a GPS PPS event. It may happen that, due to network variable latency, the gateway receives one or many downlink packets from the server while a TX is already programmed in the concentrator. The packet forwarder has to store and order incoming downlink packets (in a queue), so that they can all be programmed in the concentrator at the proper time and sent over the air. Possible failures that may occur and that have to be reported to the server are:

  • It is too early or too late to send a given packet
  • A packet collides with another packet already queued
  • A packet collides with a beacon
  • TX RF parameters (frequency, power) are not supported by gateway
  • Gateways GPS is unlocked, so cannot process Class B downlink It is called "Just-in-Time" (JiT) scheduling, because the packet forwarder will program a downlink or a beacon packet in the concentrator just before it has to be sent over the air. Another benefit of JiT is to optimize the gateway downlink capacity by avoiding to keep the concentrator TX buffer busy for too long.

In order to achieve "Just-in-Time" scheduling, the following software elements have been added:

  • A JiT queue, with associated enqueue/peek/dequeue functions and packet acceptance criterias. It is where downlink packets are stored, waiting to be sent.
  • A JiT thread, which regularly checks if there is a packet in the JiT queue ready to be programmed in the concentrator, based on current concentrator internal time.

5.1. Concentrator vs GPS time synchronization

There are 2 cases for which we need to convert a GPS time to concentrator counter: - Class B downlink: when the “time” field of JSON “txpk” is filled instead of the “tmst” field, we need to be able to determine if the packet can be queued in JiT queue or not, based on its corresponding concentrator counter value. Note: even if a Class-B downlink is given with a GPS timestamp, the concentrator TX mode is configured as “TIMESTAMP”, and not “ON_GPS”. So at the end, it is the counter value which will be used for transmission. - Beacons: beacons transmission time is based on GPS clock, and the concentrator TX mode is configured as “ON_GPS” for accurate beacon transmission on GPS PPS event. In this case, the concentrator does not need the packet counter to be set. But, as the JiT thread decides if a packet has to be peeked or not, based on its concentrator counter, we need to have the beacon packet counter set (see next chapter for more details on JiT scheduling). We also need to convert a SX1302 counter value to GPS UTC time when we receive an uplink, in order to fill the “time” field of JSON “rxpk” structure.

5.2. TX scheduling

The JiT queue implemented is a static array of nodes, where each node contains: - the downlink packet, with its type (beacon, downlink class A, B or C) - a “pre delay” which depends on packet type (BEACON_GUARD, TX_START_DELAY…) - a “post delay” which depends on packet type (“time on air” of this packet computed based on its size, datarate and coderate, or BEACON_RESERVED)

Several functions are implemented to manipulate this queue or get info from it: - init: initialize array with default values - is full / is empty: gives queue status - enqueue: checks if the given packet can be queued or not, based on several criterias - peek: checks if the queue contains a packet that must be passed immediately to the concentrator for transmission and returns corresponding index if any. - dequeue: actually removes from the queue the packet at index given by peek function

The queue is always kept sorted on ascending timestamp order.

The JiT thread will regularly check in the JiT queue if there is a packet to be sent soon. If a packet is matching, it is dequeued and programmed in the concentrator TX buffer.

5.3. Fine tuning parameters

There are few parameters of the JiT queue which could be tweaked to adapt to different system constraints.

- inc/jitqueue.h:
    JIT_QUEUE_MAX: The maximum number of nodes in the queue.
- src/jitqueue.c:
    TX_JIT_DELAY: The number of milliseconds a packet is programmed in the
                  concentrator TX buffer before its actual departure time.
    TX_MARGIN_DELAY: Packet collision check margin

6. License

Copyright (C) 2019, SEMTECH S.A. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the Semtech corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

7. License for Parson library

Parson ( http://kgabis.github.com/parson/ ) Copyright (C) 2012 Krzysztof Gabis

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

EOF