From 199c85629d1056fd01404915e1f1df60da1fbfda Mon Sep 17 00:00:00 2001 From: Danny Goossen Date: Thu, 11 Aug 2022 04:06:30 -0400 Subject: [PATCH 1/3] LoRaWAN AS923 Add SUB_REGION AS1..AS4 --- .../lorawan/lorastack/phy/LoRaPHYAS923.cpp | 74 +++++++++++++++++++ connectivity/lorawan/mbed_lib.json | 4 + 2 files changed, 78 insertions(+) diff --git a/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp b/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp index e5e37e8f84b..66981a3e25d 100644 --- a/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp +++ b/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp @@ -37,6 +37,80 @@ */ #define AS923_NUMB_DEFAULT_CHANNELS 2 +/*! + * Set default SUB region if not defined + */ +#ifndef MBED_CONF_LORA_PHY_AS923_SUB_REGION +#define MBED_CONF_LORA_PHY_AS923_SUB_REGION AS1 +#warning "MBED_CONF_LORA_PHY_AS923_SUB_REGION is not set in mbed_app.json, default to `AS1`!" +#endif + +/*! + * Define the SUB-REGION's + */ +#define LORA_AS923_SUB_REGION_AS1 0x01 +#define LORA_AS923_SUB_REGION_AS2 0x02 +#define LORA_AS923_SUB_REGION_AS3 0x03 +#define LORA_AS923_SUB_REGION_AS4 0x04 + +/*! + * Parse SUB-REGION config + */ +#define mbed_lora_concat_(x) LORA_AS923_SUB_REGION_##x +#define mbed_lora_concat(x) mbed_lora_concat_(x) +#define LORA_AS923_SUB_REGION mbed_lora_concat(MBED_CONF_LORA_PHY_AS923_SUB_REGION) + + +/*! + * Define the Frequencies for teh SUB REGION within AS923 for AS1,AS2, AS3,AS4. + */ +#if ( LORA_AS923_SUB_REGION == LORA_AS923_SUB_REGION_AS1 ) + // Singapore, Japan, Malaysia, Myanmar .... + // Historical AS923 =>RP002-1.0.0 LoRaWAN - 923..928Mhz + /*! + * Default transmit channel frequency's definition. + */ + #define AS923_LC1_FREQ 923200000 + #define AS923_LC2_FREQ 923400000 + /*! + * channel frequnetie range. + */ + #define AS923_LOWER_FREQ 923000000 + #define AS923_UPPER_FREQ 928000000 + /*! + * Second reception window channel frequency definition. + */ + #define AS923_RX_WND_2_FREQ 923200000 +#elif ( LORA_AS923_SUB_REGION == LORA_AS923_SUB_REGION_AS2 ) + // Brunei, Hong Kong, Indonesia, Laos, Cambodia, Thaland, Taiwan, Vietnam + // OFFSET -1.8 MHz AS923-1 =>RP002-1.0.1 LoRaWAN - 920..923Mhz + #define AS923_LC1_FREQ 921400000 + #define AS923_LC2_FREQ 921600000 + #define AS923_LOWER_FREQ 920000000 + #define AS923_UPPER_FREQ 923000000 + #define AS923_RX_WND_2_FREQ 921400000 +#elif ( LORA_AS923_SUB_REGION == LORA_AS923_SUB_REGION_AS3 ) + // Philipines, Quatar, Switzerland, Hungary, Cuba, Denmark .... 18 countries + // OFFSET -6.6Mhz AS923-1 =>RP002-1.0.1 LoRaWAN - 915..921Mhz + #define AS923_LC1_FREQ 916600000 + #define AS923_LC2_FREQ 916800000 + #define AS923_LOWER_FREQ 915000000 + #define AS923_UPPER_FREQ 921000000 + #define AS923_RX_WND_2_FREQ 916600000 +#elif ( LORA_AS923_SUB_REGION == LORA_AS923_SUB_REGION_AS4 ) + // Israel + // OFFSET -5.9MHz AS923-1 =>RP002-1.0.3 LoRaWAN - 917..920Mhz + #define AS923_LC1_FREQ 917300000 + #define AS923_LC2_FREQ 917500000 + #define AS923_LOWER_FREQ 917000000 + #define AS923_UPPER_FREQ 920000000 + #define AS923_RX_WND_2_FREQ 917300000 +#else + #error "Invalid SUB region configuration, update mbed_app.json with correct MBED_CONF_LORA_PHY_AS923_SUB_REGION value" +#endif + + + /*! * Number of channels to apply for the CF list */ diff --git a/connectivity/lorawan/mbed_lib.json b/connectivity/lorawan/mbed_lib.json index 04201a94c8f..3b8bcbb58e1 100644 --- a/connectivity/lorawan/mbed_lib.json +++ b/connectivity/lorawan/mbed_lib.json @@ -6,6 +6,10 @@ "help": "LoRa PHY region: EU868, AS923, AU915, CN470, CN779, EU433, IN865, KR920, US915", "value": "EU868" }, + "phy-as923-sub-region" : { + "help": "AS923 sub region: AS1, AS2, AS3, AS4", + "value": "AS1" + }, "over-the-air-activation": { "help": "When set to 1 the application uses the Over-the-Air activation procedure, default: true", "value": true From 30a156056ccb675345d914c5c9b3ed472f66afc9 Mon Sep 17 00:00:00 2001 From: Danny Goossen Date: Thu, 11 Aug 2022 11:08:40 -0400 Subject: [PATCH 2/3] fix styling with astyle for LoRaPHYAS923.cpp --- .../lorawan/lorastack/phy/LoRaPHYAS923.cpp | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp b/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp index 66981a3e25d..399a5c2b908 100644 --- a/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp +++ b/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp @@ -65,48 +65,48 @@ * Define the Frequencies for teh SUB REGION within AS923 for AS1,AS2, AS3,AS4. */ #if ( LORA_AS923_SUB_REGION == LORA_AS923_SUB_REGION_AS1 ) - // Singapore, Japan, Malaysia, Myanmar .... - // Historical AS923 =>RP002-1.0.0 LoRaWAN - 923..928Mhz - /*! - * Default transmit channel frequency's definition. - */ - #define AS923_LC1_FREQ 923200000 - #define AS923_LC2_FREQ 923400000 - /*! - * channel frequnetie range. - */ - #define AS923_LOWER_FREQ 923000000 - #define AS923_UPPER_FREQ 928000000 - /*! - * Second reception window channel frequency definition. - */ - #define AS923_RX_WND_2_FREQ 923200000 +// Singapore, Japan, Malaysia, Myanmar .... +// Historical AS923 =>RP002-1.0.0 LoRaWAN - 923..928Mhz +/*! +* Default transmit channel frequency's definition. +*/ +#define AS923_LC1_FREQ 923200000 +#define AS923_LC2_FREQ 923400000 +/*! +* channel frequnetie range. +*/ +#define AS923_LOWER_FREQ 923000000 +#define AS923_UPPER_FREQ 928000000 +/*! +* Second reception window channel frequency definition. +*/ +#define AS923_RX_WND_2_FREQ 923200000 #elif ( LORA_AS923_SUB_REGION == LORA_AS923_SUB_REGION_AS2 ) - // Brunei, Hong Kong, Indonesia, Laos, Cambodia, Thaland, Taiwan, Vietnam - // OFFSET -1.8 MHz AS923-1 =>RP002-1.0.1 LoRaWAN - 920..923Mhz - #define AS923_LC1_FREQ 921400000 - #define AS923_LC2_FREQ 921600000 - #define AS923_LOWER_FREQ 920000000 - #define AS923_UPPER_FREQ 923000000 - #define AS923_RX_WND_2_FREQ 921400000 +// Brunei, Hong Kong, Indonesia, Laos, Cambodia, Thaland, Taiwan, Vietnam +// OFFSET -1.8 MHz AS923-1 =>RP002-1.0.1 LoRaWAN - 920..923Mhz +#define AS923_LC1_FREQ 921400000 +#define AS923_LC2_FREQ 921600000 +#define AS923_LOWER_FREQ 920000000 +#define AS923_UPPER_FREQ 923000000 +#define AS923_RX_WND_2_FREQ 921400000 #elif ( LORA_AS923_SUB_REGION == LORA_AS923_SUB_REGION_AS3 ) - // Philipines, Quatar, Switzerland, Hungary, Cuba, Denmark .... 18 countries - // OFFSET -6.6Mhz AS923-1 =>RP002-1.0.1 LoRaWAN - 915..921Mhz - #define AS923_LC1_FREQ 916600000 - #define AS923_LC2_FREQ 916800000 - #define AS923_LOWER_FREQ 915000000 - #define AS923_UPPER_FREQ 921000000 - #define AS923_RX_WND_2_FREQ 916600000 +// Philipines, Quatar, Switzerland, Hungary, Cuba, Denmark .... 18 countries +// OFFSET -6.6Mhz AS923-1 =>RP002-1.0.1 LoRaWAN - 915..921Mhz +#define AS923_LC1_FREQ 916600000 +#define AS923_LC2_FREQ 916800000 +#define AS923_LOWER_FREQ 915000000 +#define AS923_UPPER_FREQ 921000000 +#define AS923_RX_WND_2_FREQ 916600000 #elif ( LORA_AS923_SUB_REGION == LORA_AS923_SUB_REGION_AS4 ) - // Israel - // OFFSET -5.9MHz AS923-1 =>RP002-1.0.3 LoRaWAN - 917..920Mhz - #define AS923_LC1_FREQ 917300000 - #define AS923_LC2_FREQ 917500000 - #define AS923_LOWER_FREQ 917000000 - #define AS923_UPPER_FREQ 920000000 - #define AS923_RX_WND_2_FREQ 917300000 +// Israel +// OFFSET -5.9MHz AS923-1 =>RP002-1.0.3 LoRaWAN - 917..920Mhz +#define AS923_LC1_FREQ 917300000 +#define AS923_LC2_FREQ 917500000 +#define AS923_LOWER_FREQ 917000000 +#define AS923_UPPER_FREQ 920000000 +#define AS923_RX_WND_2_FREQ 917300000 #else - #error "Invalid SUB region configuration, update mbed_app.json with correct MBED_CONF_LORA_PHY_AS923_SUB_REGION value" +#error "Invalid SUB region configuration, update mbed_app.json with correct MBED_CONF_LORA_PHY_AS923_SUB_REGION value" #endif @@ -411,8 +411,8 @@ int8_t LoRaPHYAS923::get_alternate_DR(uint8_t nb_trials) } lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t *next_channel_prams, - uint8_t *channel, lorawan_time_t *time, - lorawan_time_t *aggregate_timeoff) + uint8_t *channel, lorawan_time_t *time, + lorawan_time_t *aggregate_timeoff) { uint8_t next_channel_idx = 0; uint8_t nb_enabled_channels = 0; @@ -436,8 +436,8 @@ lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t *next // Search how many channels are enabled nb_enabled_channels = enabled_channel_count(next_channel_prams->current_datarate, - channel_mask, - enabled_channels, &delay_tx); + channel_mask, + enabled_channels, &delay_tx); } else { delay_tx++; next_tx_delay = next_channel_prams->aggregate_timeoff - _lora_time->get_elapsed_time(next_channel_prams->last_aggregate_tx_time); From 3508ec2b7194aa09f1ed8e5e4f3b4a25ee9ea5ba Mon Sep 17 00:00:00 2001 From: Danny Goossen Date: Thu, 18 Aug 2022 00:25:21 -0400 Subject: [PATCH 3/3] apply astyle patch --- connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp b/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp index 399a5c2b908..41d7053053f 100644 --- a/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp +++ b/connectivity/lorawan/lorastack/phy/LoRaPHYAS923.cpp @@ -411,8 +411,8 @@ int8_t LoRaPHYAS923::get_alternate_DR(uint8_t nb_trials) } lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t *next_channel_prams, - uint8_t *channel, lorawan_time_t *time, - lorawan_time_t *aggregate_timeoff) + uint8_t *channel, lorawan_time_t *time, + lorawan_time_t *aggregate_timeoff) { uint8_t next_channel_idx = 0; uint8_t nb_enabled_channels = 0; @@ -436,8 +436,8 @@ lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t *next // Search how many channels are enabled nb_enabled_channels = enabled_channel_count(next_channel_prams->current_datarate, - channel_mask, - enabled_channels, &delay_tx); + channel_mask, + enabled_channels, &delay_tx); } else { delay_tx++; next_tx_delay = next_channel_prams->aggregate_timeoff - _lora_time->get_elapsed_time(next_channel_prams->last_aggregate_tx_time);