From 874d7d15cb23907ea6fde23eeec4f4c1cb3e0f8c Mon Sep 17 00:00:00 2001 From: Akshai M Date: Fri, 2 Oct 2020 13:55:29 +0530 Subject: [PATCH] gnrc/lorawan : Add RX1DROffset for IN865 region MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Alamos --- .../gnrc/link_layer/lorawan/gnrc_lorawan_region.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan_region.c b/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan_region.c index 439eea7404..31f3d1e009 100644 --- a/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan_region.c +++ b/sys/net/gnrc/link_layer/lorawan/gnrc_lorawan_region.c @@ -12,10 +12,14 @@ * @file * @author José Ignacio Alamos */ +#include "kernel_defines.h" #include "net/gnrc/lorawan/region.h" #define GNRC_LORAWAN_DATARATES_NUMOF (6U) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + static uint8_t dr_sf[GNRC_LORAWAN_DATARATES_NUMOF] = { LORA_SF12, LORA_SF11, LORA_SF10, LORA_SF9, LORA_SF8, LORA_SF7 }; static uint8_t dr_bw[GNRC_LORAWAN_DATARATES_NUMOF] = @@ -38,11 +42,20 @@ int gnrc_lorawan_set_dr(gnrc_lorawan_t *mac, uint8_t datarate) return 0; } +#if (IS_ACTIVE(CONFIG_LORAMAC_REGION_EU_868)) uint8_t gnrc_lorawan_rx1_get_dr_offset(uint8_t dr_up, uint8_t dr_offset) { return (dr_up > dr_offset) ? (dr_up - dr_offset) : 0; } +#elif (IS_ACTIVE(CONFIG_LORAMAC_REGION_IN_865)) +uint8_t gnrc_lorawan_rx1_get_dr_offset(uint8_t dr_up, uint8_t dr_offset) +{ + int dr_eff = dr_offset > 5 ? 5 - dr_offset : dr_offset; + return MIN(5, MAX(0, dr_up - dr_eff)); +} +#endif + static size_t _get_num_used_channels(gnrc_lorawan_t *mac) { size_t count = 0;