From a4680b084ff6831f2405e5caf3db4b9eeafdaf1d Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:15:18 +0000 Subject: [PATCH 01/34] Make polygon type public --- src/peripherals/geofence.c | 39 ------------------------- src/peripherals/geofence.h | 60 ++++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index c18a07398..52eb4757e 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -34,45 +34,6 @@ /* Global variables definitions go here */ -// GEOFENCE variables -/* The world is split into polygons e.g. EU863870_EUROPE_polygon. - * Multiple polygons can have the same LoRa region settings. E.g. LORAMAC_REGION_EU868. - * Keeps track of which polygon the tracker is in, and if it changes to another polygon, - * all LoRa settings are reinitialised when the balloon enters another polygon. - * - */ - -/*! - * Polygon region enumeration - */ -typedef enum polygon_t -{ - AS920923_PHILIPPINES_polygon, - US902928_NAMERICA_polygon, - AS923925_BRUNEI_polygon, - AS923925_TAIWAN_polygon, - AS923925_INDONESIA_polygon, - AS923925_THAILAND_polygon, - US902928_ARGENTINA_polygon, - AU915928_BRAZIL_polygon, - AU915928_CHILE_polygon, - CN779787_CHINA_polygon, - IN865867_INDIA_polygon, - AS920923_JAPAN_polygon, - KR920923_SKOREA_polygon, - AS920923_MALAYSIASG_polygon, - AU915928_AUSTRALIA_polygon, - RU864870_RUSSIA_polygon, - EU863870_EUROPE_polygon, - US902928_GUAM_polygon, - US902928_ANTARTICA_polygon, - AS920923_ISRAEL_polygon, - US902928_MALDIVES_polygon, - EU863870_UKRAINE_polygon, - OUTSIDE_polygon, - n_polygons, -} Polygon_t; - /** * @brief Transmission enable/disable mask for each region. Each * boolean value corresponds to each enum value in Polygon_t. diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index 95d24fad0..f7bb9e56d 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -1,16 +1,16 @@ /** - ****************************************************************************** - * @file : geofence.h - * @brief : Algorithms for geofencing - ****************************************************************************** - * Imperial College Space Society - * Medad Newman, Richard Ibbotson - * Modified from TT7's code - * https://github.com/TomasTT7/TT7F-Float-Tracker - * The following coordinates are autogenerated from a kml file containing all the polygons. - * - ****************************************************************************** - */ + ****************************************************************************** + * @file : geofence.h + * @brief : Algorithms for geofencing + ****************************************************************************** + * Imperial College Space Society + * Medad Newman, Richard Ibbotson + * Modified from TT7's code + * https://github.com/TomasTT7/TT7F-Float-Tracker + * The following coordinates are autogenerated from a kml file containing all the polygons. + * + ****************************************************************************** + */ #ifdef __cplusplus extern "C" @@ -56,6 +56,42 @@ extern "C" } geofence_status_t; + /* The world is split into polygons e.g. EU863870_EUROPE_polygon. + * Multiple polygons can have the same LoRa region settings. E.g. LORAMAC_REGION_EU868. + * Keeps track of which polygon the tracker is in, and if it changes to another polygon, + * all LoRa settings are reinitialised when the balloon enters another polygon. + */ + /*! + * Polygon region enumeration + */ + typedef enum polygon_t + { + AS920923_PHILIPPINES_polygon, + US902928_NAMERICA_polygon, + AS923925_BRUNEI_polygon, + AS923925_TAIWAN_polygon, + AS923925_INDONESIA_polygon, + AS923925_THAILAND_polygon, + US902928_ARGENTINA_polygon, + AU915928_BRAZIL_polygon, + AU915928_CHILE_polygon, + CN779787_CHINA_polygon, + IN865867_INDIA_polygon, + AS920923_JAPAN_polygon, + KR920923_SKOREA_polygon, + AS920923_MALAYSIASG_polygon, + AU915928_AUSTRALIA_polygon, + RU864870_RUSSIA_polygon, + EU863870_EUROPE_polygon, + US902928_GUAM_polygon, + US902928_ANTARTICA_polygon, + AS920923_ISRAEL_polygon, + US902928_MALDIVES_polygon, + EU863870_UKRAINE_polygon, + OUTSIDE_polygon, + n_polygons, + } Polygon_t; + /* ==================================================================== */ /* ======================= public functions =========================== */ /* ==================================================================== */ From df262bef37d060d040dbc17410c83f44f8c30473 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:16:46 +0000 Subject: [PATCH 02/34] delete unneeded tests --- tests/geofence_ut.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index 78ba0c31e..49aed9b9a 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -522,14 +522,6 @@ void teardown() } ; -/** - * @brief Ensure the #define N_POLYGONS is the same as the enum n_polygons - * - */ -TEST(test_update_geofence_settings, MUST_PASS_ensure_n_polygons_is_correct) -{ - CHECK_EQUAL(N_POLYGONS, get_n_polygons()); -} /** * @brief Test by default if it disables tx over Ukraine. From b9cb7927d2221a6ea6bcd95f51915153368ed294 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:17:49 +0000 Subject: [PATCH 03/34] Use new n_polygons --- src/peripherals/bsp.c | 2 +- src/peripherals/eeprom_settings_manager.h | 5 ++--- tests/geofence_ut.cpp | 4 ++-- tests/test_eeprom_settings_manager.cpp | 2 +- tests/uplink_commands_ut.cpp | 6 +++--- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/peripherals/bsp.c b/src/peripherals/bsp.c index c609547d2..b1e69aff3 100644 --- a/src/peripherals/bsp.c +++ b/src/peripherals/bsp.c @@ -352,7 +352,7 @@ void BSP_sensor_Init(void) IWDG_reset(); // Initialise the geofence permissions mask - bool values[N_POLYGONS]; + bool values[n_polygons]; read_geofence_settings_in_eeprom(values); playback_hw_init(); diff --git a/src/peripherals/eeprom_settings_manager.h b/src/peripherals/eeprom_settings_manager.h index 4e77bd925..b1ab4ece5 100644 --- a/src/peripherals/eeprom_settings_manager.h +++ b/src/peripherals/eeprom_settings_manager.h @@ -19,6 +19,7 @@ extern "C" #include "stdint.h" #include "stdbool.h" #include "LoRaWAN_config_switcher.h" +#include "geofence.h" typedef struct { @@ -26,11 +27,9 @@ extern "C" uint32_t Crc32; } tx_interval_eeprom_t; -#define N_POLYGONS 23 - typedef struct { - bool values[N_POLYGONS]; + bool values[n_polygons]; uint32_t Crc32; } geofence_settings_t; diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index 49aed9b9a..98e6f0f30 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -12,7 +12,7 @@ extern "C" TEST_GROUP(test_get_current_lorawan_region){ void setup(){ - bool values[N_POLYGONS]; + bool values[n_polygons]; read_geofence_settings_in_eeprom(values); } @@ -511,7 +511,7 @@ TEST(test_get_current_lorawan_region, Ukraine) TEST_GROUP(test_update_geofence_settings){ void setup(){ - bool values[N_POLYGONS]; + bool values[n_polygons]; read_geofence_settings_in_eeprom(values); } diff --git a/tests/test_eeprom_settings_manager.cpp b/tests/test_eeprom_settings_manager.cpp index 596926462..cb0bd2f42 100644 --- a/tests/test_eeprom_settings_manager.cpp +++ b/tests/test_eeprom_settings_manager.cpp @@ -54,7 +54,7 @@ TEST(test_eeprom_settings_manager, test_eeprom_unchanged_crc) uint8_t before_crc = get_settings_crc(); // Geofence settings are still default values - bool geofence_settings[N_POLYGONS] = {true, true, true, true, true, + bool geofence_settings[n_polygons] = {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, diff --git a/tests/uplink_commands_ut.cpp b/tests/uplink_commands_ut.cpp index aa40e7f42..021344b5a 100644 --- a/tests/uplink_commands_ut.cpp +++ b/tests/uplink_commands_ut.cpp @@ -288,10 +288,10 @@ TEST(uplink_commands, verify_geofence_mask_is_changed_correctly) * transmissions over Ukraine * */ - uint8_t length_of_uplink = N_POLYGONS * sizeof(bool); + uint8_t length_of_uplink = n_polygons * sizeof(bool); uint8_t simulated_downlink_from_ground[length_of_uplink]; - bool instructions[N_POLYGONS] = { + bool instructions[n_polygons] = { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, @@ -317,7 +317,7 @@ TEST(uplink_commands, verify_geofence_mask_is_changed_correctly) */ OnRxData(&appData, &LmHandlerRxParams); - bool values[N_POLYGONS]; + bool values[n_polygons]; read_geofence_settings_in_eeprom(values); update_geofence_position(50.4501, 30.5234); // Ukraine From 7a63410a6a078f38736c3e6faf6c5f8b50c89176 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:18:57 +0000 Subject: [PATCH 04/34] Use n_polygons param --- src/peripherals/eeprom_settings_manager.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/peripherals/eeprom_settings_manager.c b/src/peripherals/eeprom_settings_manager.c index 81b47dbc4..93765b651 100644 --- a/src/peripherals/eeprom_settings_manager.c +++ b/src/peripherals/eeprom_settings_manager.c @@ -60,7 +60,7 @@ bool update_geofence_settings_in_eeprom(uint8_t *settings_bytes, uint16_t size) /** * @brief Reads and initialised the geofence module with the tx enable/disable settings * from EEPROM. Fills passed buffer with the settings. Ensure buffer passed is - * of size N_POLYGONS * sizeof(bool) + * of size n_polygons * sizeof(bool) * * @param values Pointer to buffer that will be filled with the bool enable/disable setting */ @@ -73,17 +73,17 @@ void read_geofence_settings_in_eeprom(bool *values) // Use eeprom stored values only if CRC is correct. Else assume the default settings if (is_crc_correct(sizeof(geofence_settings_t), (void *)&geofence_settings)) { - memcpy(values, geofence_settings.values, N_POLYGONS * sizeof(bool)); + memcpy(values, geofence_settings.values, n_polygons * sizeof(bool)); } else { - bool default_geofence_settings[N_POLYGONS] = {true, true, true, true, true, true, + bool default_geofence_settings[n_polygons] = {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, false}; - memcpy(values, default_geofence_settings, N_POLYGONS * sizeof(bool)); + memcpy(values, default_geofence_settings, n_polygons * sizeof(bool)); } geofence_init_with_settings(values); @@ -220,7 +220,7 @@ uint8_t get_settings_crc() } // CRC of tx enable/disable settings for different regions. - bool values[N_POLYGONS]; + bool values[n_polygons]; read_geofence_settings_in_eeprom(values); crc = Crc8Update(crc, (uint8_t *)values, sizeof(values)); From c00051d2809436967447b2324037fed35df74363 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:27:37 +0000 Subject: [PATCH 05/34] Use correct number of polygons --- src/peripherals/eeprom_settings_manager.c | 32 ++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/peripherals/eeprom_settings_manager.c b/src/peripherals/eeprom_settings_manager.c index 93765b651..b43dd5e49 100644 --- a/src/peripherals/eeprom_settings_manager.c +++ b/src/peripherals/eeprom_settings_manager.c @@ -19,6 +19,32 @@ #include "bsp.h" #include "eeprom_settings_manager.h" +static const bool default_geofence_settings[n_polygons] = { + [AS920923_PHILIPPINES_polygon] = true, + [US902928_NAMERICA_polygon] = true, + [AS923925_BRUNEI_polygon] = true, + [AS923925_TAIWAN_polygon] = true, + [AS923925_INDONESIA_polygon] = true, + [AS923925_THAILAND_polygon] = true, + [US902928_ARGENTINA_polygon] = true, + [AU915928_BRAZIL_polygon] = true, + [AU915928_CHILE_polygon] = true, + [CN779787_CHINA_polygon] = true, + [IN865867_INDIA_polygon] = true, + [AS920923_JAPAN_polygon] = true, + [KR920923_SKOREA_polygon] = true, + [AS920923_MALAYSIASG_polygon] = true, + [AU915928_AUSTRALIA_polygon] = true, + [RU864870_RUSSIA_polygon] = true, + [EU863870_EUROPE_polygon] = true, + [US902928_GUAM_polygon] = true, + [US902928_ANTARTICA_polygon] = true, + [AS920923_ISRAEL_polygon] = true, + [US902928_MALDIVES_polygon] = true, + [EU863870_UKRAINE_polygon] = true, + [OUTSIDE_polygon] = false, +}; + /** * @brief Get the eeprom stored lorwan region * @@ -77,12 +103,6 @@ void read_geofence_settings_in_eeprom(bool *values) } else { - - bool default_geofence_settings[n_polygons] = {true, true, true, true, true, true, - true, true, true, true, true, true, - true, true, true, true, true, true, - true, true, true, false, false}; - memcpy(values, default_geofence_settings, n_polygons * sizeof(bool)); } From cedb5b7046560b71f2ad59d1b8fe86731652920f Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:33:57 +0000 Subject: [PATCH 06/34] revert --- src/peripherals/geofence.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index f7bb9e56d..8d466e836 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -1,16 +1,18 @@ /** - ****************************************************************************** - * @file : geofence.h - * @brief : Algorithms for geofencing - ****************************************************************************** - * Imperial College Space Society - * Medad Newman, Richard Ibbotson + ****************************************************************************** + * @file : geofence.h + * @brief : Algorithms for geofencing + ****************************************************************************** + * Imperial College Space Society + * Medad Newman, Richard Ibbotson + * Modified from TT7's code * Modified from TT7's code - * https://github.com/TomasTT7/TT7F-Float-Tracker - * The following coordinates are autogenerated from a kml file containing all the polygons. - * - ****************************************************************************** - */ + * Modified from TT7's code + * https://github.com/TomasTT7/TT7F-Float-Tracker + * The following coordinates are autogenerated from a kml file containing all the polygons. + * + ****************************************************************************** + */ #ifdef __cplusplus extern "C" From acb72add974866d450ad0173cf3108275486c9c8 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:35:23 +0000 Subject: [PATCH 07/34] revert --- src/peripherals/geofence.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index 8d466e836..ef2327057 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -6,8 +6,6 @@ * Imperial College Space Society * Medad Newman, Richard Ibbotson * Modified from TT7's code - * Modified from TT7's code - * Modified from TT7's code * https://github.com/TomasTT7/TT7F-Float-Tracker * The following coordinates are autogenerated from a kml file containing all the polygons. * From 0916ec46db5d31449f9a42732246c0c926375827 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:44:02 +0000 Subject: [PATCH 08/34] Simulate disabling tx over Ukraine --- tests/uplink_commands_ut.cpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/tests/uplink_commands_ut.cpp b/tests/uplink_commands_ut.cpp index 021344b5a..39eb0d0dc 100644 --- a/tests/uplink_commands_ut.cpp +++ b/tests/uplink_commands_ut.cpp @@ -284,18 +284,38 @@ TEST(uplink_commands, verify_geofence_mask_is_changed_correctly) { /** - * @brief Simulate a downlink from ground containing a message to enable + * @brief Simulate a downlink from ground containing a message to disable * transmissions over Ukraine * */ uint8_t length_of_uplink = n_polygons * sizeof(bool); uint8_t simulated_downlink_from_ground[length_of_uplink]; - bool instructions[n_polygons] = { - true, true, true, true, true, true, - true, true, true, true, true, true, - true, true, true, true, true, true, - true, true, true, true, false}; + static const bool instructions[n_polygons] = { + [AS920923_PHILIPPINES_polygon] = true, + [US902928_NAMERICA_polygon] = true, + [AS923925_BRUNEI_polygon] = true, + [AS923925_TAIWAN_polygon] = true, + [AS923925_INDONESIA_polygon] = true, + [AS923925_THAILAND_polygon] = true, + [US902928_ARGENTINA_polygon] = true, + [AU915928_BRAZIL_polygon] = true, + [AU915928_CHILE_polygon] = true, + [CN779787_CHINA_polygon] = true, + [IN865867_INDIA_polygon] = true, + [AS920923_JAPAN_polygon] = true, + [KR920923_SKOREA_polygon] = true, + [AS920923_MALAYSIASG_polygon] = true, + [AU915928_AUSTRALIA_polygon] = true, + [RU864870_RUSSIA_polygon] = true, + [EU863870_EUROPE_polygon] = true, + [US902928_GUAM_polygon] = true, + [US902928_ANTARTICA_polygon] = true, + [AS920923_ISRAEL_polygon] = true, + [US902928_MALDIVES_polygon] = true, + [EU863870_UKRAINE_polygon] = false, + [OUTSIDE_polygon] = false, + }; /** * @brief Set the simulated downlink @@ -321,5 +341,5 @@ TEST(uplink_commands, verify_geofence_mask_is_changed_correctly) read_geofence_settings_in_eeprom(values); update_geofence_position(50.4501, 30.5234); // Ukraine - CHECK_EQUAL(TX_OK, get_current_tx_permission()); + CHECK_EQUAL(TX_NOT_OK, get_current_tx_permission()); } From 1f183779137a3019d47aeece1be851c147650c3a Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:46:43 +0000 Subject: [PATCH 09/34] allow Ukraine tx ok --- tests/geofence_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index 98e6f0f30..ea194d51b 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -506,7 +506,7 @@ TEST(test_get_current_lorawan_region, Ukraine) update_geofence_position(50.4501, 30.5234); LoRaMacRegion_t region = get_current_loramac_region(); CHECK_EQUAL(LORAMAC_REGION_EU868, region); - CHECK_EQUAL(TX_NOT_OK, get_current_tx_permission()); + CHECK_EQUAL(TX_OK, get_current_tx_permission()); } TEST_GROUP(test_update_geofence_settings){ From 6a6985b743e36b0af2d71dfa681fa86f3bb7f84e Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:48:52 +0000 Subject: [PATCH 10/34] use nicer polygon shape --- tests/test_eeprom_settings_manager.cpp | 31 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/test_eeprom_settings_manager.cpp b/tests/test_eeprom_settings_manager.cpp index cb0bd2f42..6685b76ba 100644 --- a/tests/test_eeprom_settings_manager.cpp +++ b/tests/test_eeprom_settings_manager.cpp @@ -54,12 +54,31 @@ TEST(test_eeprom_settings_manager, test_eeprom_unchanged_crc) uint8_t before_crc = get_settings_crc(); // Geofence settings are still default values - bool geofence_settings[n_polygons] = {true, true, true, true, true, - true, true, true, true, true, - true, true, true, true, true, - true, true, true, true, true, - true, false, false}; - + static const bool geofence_settings[n_polygons] = { + [AS920923_PHILIPPINES_polygon] = true, + [US902928_NAMERICA_polygon] = true, + [AS923925_BRUNEI_polygon] = true, + [AS923925_TAIWAN_polygon] = true, + [AS923925_INDONESIA_polygon] = true, + [AS923925_THAILAND_polygon] = true, + [US902928_ARGENTINA_polygon] = true, + [AU915928_BRAZIL_polygon] = true, + [AU915928_CHILE_polygon] = true, + [CN779787_CHINA_polygon] = true, + [IN865867_INDIA_polygon] = true, + [AS920923_JAPAN_polygon] = true, + [KR920923_SKOREA_polygon] = true, + [AS920923_MALAYSIASG_polygon] = true, + [AU915928_AUSTRALIA_polygon] = true, + [RU864870_RUSSIA_polygon] = true, + [EU863870_EUROPE_polygon] = true, + [US902928_GUAM_polygon] = true, + [US902928_ANTARTICA_polygon] = true, + [AS920923_ISRAEL_polygon] = true, + [US902928_MALDIVES_polygon] = true, + [EU863870_UKRAINE_polygon] = true, + [OUTSIDE_polygon] = false, + }; update_geofence_settings_in_eeprom((uint8_t *)geofence_settings, sizeof(geofence_settings)); /* Get the crc8 and confirm that it has the same CRC */ From 88b0700ab4053c5f8a1db9dd77e9e0174e192349 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 17:53:08 +0000 Subject: [PATCH 11/34] Enable over north korea test --- tests/geofence_ut.cpp | 47 +++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index ea194d51b..73e6664c1 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -544,25 +544,42 @@ TEST(test_update_geofence_settings, check_defaults_mask_tx_enabled_location) } /** - * @brief Test after enabling tx over a region(Ukraine) - * whether it is allowed again. + * @brief Test after enabling tx over a region(North Korea) + * whether it is allowed again. */ -TEST(test_update_geofence_settings, check_enable_later_Ukraine) -{ - geofence_settings_t enabled_ukraine = { - .values = {true, true, true, - true, true, true, - true, true, true, - true, true, true, - true, true, true, - true, true, true, - true, true, true, - true, false}, +TEST(test_update_geofence_settings, check_enable_later_north_korea) +{ + geofence_settings_t enabled_north_korea = { + .values = { + [AS920923_PHILIPPINES_polygon] = true, + [US902928_NAMERICA_polygon] = true, + [AS923925_BRUNEI_polygon] = true, + [AS923925_TAIWAN_polygon] = true, + [AS923925_INDONESIA_polygon] = true, + [AS923925_THAILAND_polygon] = true, + [US902928_ARGENTINA_polygon] = true, + [AU915928_BRAZIL_polygon] = true, + [AU915928_CHILE_polygon] = true, + [CN779787_CHINA_polygon] = true, + [IN865867_INDIA_polygon] = true, + [AS920923_JAPAN_polygon] = true, + [KR920923_SKOREA_polygon] = true, + [AS920923_MALAYSIASG_polygon] = true, + [AU915928_AUSTRALIA_polygon] = true, + [RU864870_RUSSIA_polygon] = true, + [EU863870_EUROPE_polygon] = true, + [US902928_GUAM_polygon] = true, + [US902928_ANTARTICA_polygon] = true, + [AS920923_ISRAEL_polygon] = true, + [US902928_MALDIVES_polygon] = true, + [EU863870_UKRAINE_polygon] = false, + [OUTSIDE_polygon] = false, + }, .Crc32 = 100, // dummy CRC }; - geofence_init_with_settings(enabled_ukraine.values); + geofence_init_with_settings(enabled_north_korea.values); - update_geofence_position(50.4501, 30.5234); // Ukraine + update_geofence_position(39.0392, 125.7625); // Pyongyang CHECK_EQUAL(TX_OK, get_current_tx_permission()); } From 4e289a26be127623e1c33f53617f26df7d6080bf Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:02:08 +0000 Subject: [PATCH 12/34] comment --- src/peripherals/geofence.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index ef2327057..259bf23bb 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -44,7 +44,7 @@ extern "C" typedef enum { - TX_OK = 0, + TX_OK = 0, // default of 0 falls back to TX_OK. This is required to ensure by default, we can transmit if not specified. TX_NOT_OK } tx_permission_t; From 3c60cf0777bca974d4616e287f0086c8e78f1530 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:02:51 +0000 Subject: [PATCH 13/34] use tx_permission_t type even in eeprom --- src/peripherals/geofence.c | 2 +- tests/geofence_ut.cpp | 79 +++++++++++++++++++++++--------------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index 52eb4757e..b6b5dbdeb 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -40,7 +40,7 @@ * By default, transmissions are disabled over the UKRAINE and * and region outside of the geofence regions. */ -bool tx_permissions_for_regions[n_polygons]; +tx_permission_t tx_permissions_for_regions[n_polygons]; geofence_status_t current_geofence_status = { diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index 73e6664c1..b0c110e5d 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -551,29 +551,29 @@ TEST(test_update_geofence_settings, check_enable_later_north_korea) { geofence_settings_t enabled_north_korea = { .values = { - [AS920923_PHILIPPINES_polygon] = true, - [US902928_NAMERICA_polygon] = true, - [AS923925_BRUNEI_polygon] = true, - [AS923925_TAIWAN_polygon] = true, - [AS923925_INDONESIA_polygon] = true, - [AS923925_THAILAND_polygon] = true, - [US902928_ARGENTINA_polygon] = true, - [AU915928_BRAZIL_polygon] = true, - [AU915928_CHILE_polygon] = true, - [CN779787_CHINA_polygon] = true, - [IN865867_INDIA_polygon] = true, - [AS920923_JAPAN_polygon] = true, - [KR920923_SKOREA_polygon] = true, - [AS920923_MALAYSIASG_polygon] = true, - [AU915928_AUSTRALIA_polygon] = true, - [RU864870_RUSSIA_polygon] = true, - [EU863870_EUROPE_polygon] = true, - [US902928_GUAM_polygon] = true, - [US902928_ANTARTICA_polygon] = true, - [AS920923_ISRAEL_polygon] = true, - [US902928_MALDIVES_polygon] = true, - [EU863870_UKRAINE_polygon] = false, - [OUTSIDE_polygon] = false, + [AS920923_PHILIPPINES_polygon] = TX_OK, + [US902928_NAMERICA_polygon] = TX_OK, + [AS923925_BRUNEI_polygon] = TX_OK, + [AS923925_TAIWAN_polygon] = TX_OK, + [AS923925_INDONESIA_polygon] = TX_OK, + [AS923925_THAILAND_polygon] = TX_OK, + [US902928_ARGENTINA_polygon] = TX_OK, + [AU915928_BRAZIL_polygon] = TX_OK, + [AU915928_CHILE_polygon] = TX_OK, + [CN779787_CHINA_polygon] = TX_OK, + [IN865867_INDIA_polygon] = TX_OK, + [AS920923_JAPAN_polygon] = TX_OK, + [KR920923_SKOREA_polygon] = TX_OK, + [AS920923_MALAYSIASG_polygon] = TX_OK, + [AU915928_AUSTRALIA_polygon] = TX_OK, + [RU864870_RUSSIA_polygon] = TX_OK, + [EU863870_EUROPE_polygon] = TX_OK, + [US902928_GUAM_polygon] = TX_OK, + [US902928_ANTARTICA_polygon] = TX_OK, + [AS920923_ISRAEL_polygon] = TX_OK, + [US902928_MALDIVES_polygon] = TX_OK, + [EU863870_UKRAINE_polygon] = TX_NOT_OK, + [OUTSIDE_polygon] = TX_NOT_OK, }, .Crc32 = 100, // dummy CRC }; @@ -590,14 +590,31 @@ TEST(test_update_geofence_settings, check_enable_later_north_korea) TEST(test_update_geofence_settings, check_disable_later_Philipines) { geofence_settings_t disabled_phillipines = { - .values = {false, true, true, - true, true, true, - true, true, true, - true, true, true, - true, true, true, - true, true, true, - true, true, true, - false, false}, + .values = { + [AS920923_PHILIPPINES_polygon] = TX_NOT_OK, + [US902928_NAMERICA_polygon] = TX_OK, + [AS923925_BRUNEI_polygon] = TX_OK, + [AS923925_TAIWAN_polygon] = TX_OK, + [AS923925_INDONESIA_polygon] = TX_OK, + [AS923925_THAILAND_polygon] = TX_OK, + [US902928_ARGENTINA_polygon] = TX_OK, + [AU915928_BRAZIL_polygon] = TX_OK, + [AU915928_CHILE_polygon] = TX_OK, + [CN779787_CHINA_polygon] = TX_OK, + [IN865867_INDIA_polygon] = TX_OK, + [AS920923_JAPAN_polygon] = TX_OK, + [KR920923_SKOREA_polygon] = TX_OK, + [AS920923_MALAYSIASG_polygon] = TX_OK, + [AU915928_AUSTRALIA_polygon] = TX_OK, + [RU864870_RUSSIA_polygon] = TX_OK, + [EU863870_EUROPE_polygon] = TX_OK, + [US902928_GUAM_polygon] = TX_OK, + [US902928_ANTARTICA_polygon] = TX_OK, + [AS920923_ISRAEL_polygon] = TX_OK, + [US902928_MALDIVES_polygon] = TX_OK, + [EU863870_UKRAINE_polygon] = TX_OK, + [OUTSIDE_polygon] = TX_NOT_OK, + }, .Crc32 = 100, // dummy CRC }; geofence_init_with_settings(disabled_phillipines.values); From 7b498d93fdabc28ae1c2596670e910944ea4c2dc Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:05:23 +0000 Subject: [PATCH 14/34] use correct type --- src/peripherals/eeprom_settings_manager.c | 46 +++++++++++------------ tests/test_eeprom_settings_manager.cpp | 46 +++++++++++------------ tests/uplink_commands_ut.cpp | 46 +++++++++++------------ 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/peripherals/eeprom_settings_manager.c b/src/peripherals/eeprom_settings_manager.c index b43dd5e49..424c68a7d 100644 --- a/src/peripherals/eeprom_settings_manager.c +++ b/src/peripherals/eeprom_settings_manager.c @@ -20,29 +20,29 @@ #include "eeprom_settings_manager.h" static const bool default_geofence_settings[n_polygons] = { - [AS920923_PHILIPPINES_polygon] = true, - [US902928_NAMERICA_polygon] = true, - [AS923925_BRUNEI_polygon] = true, - [AS923925_TAIWAN_polygon] = true, - [AS923925_INDONESIA_polygon] = true, - [AS923925_THAILAND_polygon] = true, - [US902928_ARGENTINA_polygon] = true, - [AU915928_BRAZIL_polygon] = true, - [AU915928_CHILE_polygon] = true, - [CN779787_CHINA_polygon] = true, - [IN865867_INDIA_polygon] = true, - [AS920923_JAPAN_polygon] = true, - [KR920923_SKOREA_polygon] = true, - [AS920923_MALAYSIASG_polygon] = true, - [AU915928_AUSTRALIA_polygon] = true, - [RU864870_RUSSIA_polygon] = true, - [EU863870_EUROPE_polygon] = true, - [US902928_GUAM_polygon] = true, - [US902928_ANTARTICA_polygon] = true, - [AS920923_ISRAEL_polygon] = true, - [US902928_MALDIVES_polygon] = true, - [EU863870_UKRAINE_polygon] = true, - [OUTSIDE_polygon] = false, + [AS920923_PHILIPPINES_polygon] = TX_OK, + [US902928_NAMERICA_polygon] = TX_OK, + [AS923925_BRUNEI_polygon] = TX_OK, + [AS923925_TAIWAN_polygon] = TX_OK, + [AS923925_INDONESIA_polygon] = TX_OK, + [AS923925_THAILAND_polygon] = TX_OK, + [US902928_ARGENTINA_polygon] = TX_OK, + [AU915928_BRAZIL_polygon] = TX_OK, + [AU915928_CHILE_polygon] = TX_OK, + [CN779787_CHINA_polygon] = TX_OK, + [IN865867_INDIA_polygon] = TX_OK, + [AS920923_JAPAN_polygon] = TX_OK, + [KR920923_SKOREA_polygon] = TX_OK, + [AS920923_MALAYSIASG_polygon] = TX_OK, + [AU915928_AUSTRALIA_polygon] = TX_OK, + [RU864870_RUSSIA_polygon] = TX_OK, + [EU863870_EUROPE_polygon] = TX_OK, + [US902928_GUAM_polygon] = TX_OK, + [US902928_ANTARTICA_polygon] = TX_OK, + [AS920923_ISRAEL_polygon] = TX_OK, + [US902928_MALDIVES_polygon] = TX_OK, + [EU863870_UKRAINE_polygon] = TX_OK, + [OUTSIDE_polygon] = TX_NOT_OK, }; /** diff --git a/tests/test_eeprom_settings_manager.cpp b/tests/test_eeprom_settings_manager.cpp index 6685b76ba..3384ea304 100644 --- a/tests/test_eeprom_settings_manager.cpp +++ b/tests/test_eeprom_settings_manager.cpp @@ -55,29 +55,29 @@ TEST(test_eeprom_settings_manager, test_eeprom_unchanged_crc) // Geofence settings are still default values static const bool geofence_settings[n_polygons] = { - [AS920923_PHILIPPINES_polygon] = true, - [US902928_NAMERICA_polygon] = true, - [AS923925_BRUNEI_polygon] = true, - [AS923925_TAIWAN_polygon] = true, - [AS923925_INDONESIA_polygon] = true, - [AS923925_THAILAND_polygon] = true, - [US902928_ARGENTINA_polygon] = true, - [AU915928_BRAZIL_polygon] = true, - [AU915928_CHILE_polygon] = true, - [CN779787_CHINA_polygon] = true, - [IN865867_INDIA_polygon] = true, - [AS920923_JAPAN_polygon] = true, - [KR920923_SKOREA_polygon] = true, - [AS920923_MALAYSIASG_polygon] = true, - [AU915928_AUSTRALIA_polygon] = true, - [RU864870_RUSSIA_polygon] = true, - [EU863870_EUROPE_polygon] = true, - [US902928_GUAM_polygon] = true, - [US902928_ANTARTICA_polygon] = true, - [AS920923_ISRAEL_polygon] = true, - [US902928_MALDIVES_polygon] = true, - [EU863870_UKRAINE_polygon] = true, - [OUTSIDE_polygon] = false, + [AS920923_PHILIPPINES_polygon] = TX_OK, + [US902928_NAMERICA_polygon] = TX_OK, + [AS923925_BRUNEI_polygon] = TX_OK, + [AS923925_TAIWAN_polygon] = TX_OK, + [AS923925_INDONESIA_polygon] = TX_OK, + [AS923925_THAILAND_polygon] = TX_OK, + [US902928_ARGENTINA_polygon] = TX_OK, + [AU915928_BRAZIL_polygon] = TX_OK, + [AU915928_CHILE_polygon] = TX_OK, + [CN779787_CHINA_polygon] = TX_OK, + [IN865867_INDIA_polygon] = TX_OK, + [AS920923_JAPAN_polygon] = TX_OK, + [KR920923_SKOREA_polygon] = TX_OK, + [AS920923_MALAYSIASG_polygon] = TX_OK, + [AU915928_AUSTRALIA_polygon] = TX_OK, + [RU864870_RUSSIA_polygon] = TX_OK, + [EU863870_EUROPE_polygon] = TX_OK, + [US902928_GUAM_polygon] = TX_OK, + [US902928_ANTARTICA_polygon] = TX_OK, + [AS920923_ISRAEL_polygon] = TX_OK, + [US902928_MALDIVES_polygon] = TX_OK, + [EU863870_UKRAINE_polygon] = TX_OK, + [OUTSIDE_polygon] = TX_NOT_OK, }; update_geofence_settings_in_eeprom((uint8_t *)geofence_settings, sizeof(geofence_settings)); diff --git a/tests/uplink_commands_ut.cpp b/tests/uplink_commands_ut.cpp index 39eb0d0dc..0c42cc932 100644 --- a/tests/uplink_commands_ut.cpp +++ b/tests/uplink_commands_ut.cpp @@ -292,29 +292,29 @@ TEST(uplink_commands, verify_geofence_mask_is_changed_correctly) uint8_t simulated_downlink_from_ground[length_of_uplink]; static const bool instructions[n_polygons] = { - [AS920923_PHILIPPINES_polygon] = true, - [US902928_NAMERICA_polygon] = true, - [AS923925_BRUNEI_polygon] = true, - [AS923925_TAIWAN_polygon] = true, - [AS923925_INDONESIA_polygon] = true, - [AS923925_THAILAND_polygon] = true, - [US902928_ARGENTINA_polygon] = true, - [AU915928_BRAZIL_polygon] = true, - [AU915928_CHILE_polygon] = true, - [CN779787_CHINA_polygon] = true, - [IN865867_INDIA_polygon] = true, - [AS920923_JAPAN_polygon] = true, - [KR920923_SKOREA_polygon] = true, - [AS920923_MALAYSIASG_polygon] = true, - [AU915928_AUSTRALIA_polygon] = true, - [RU864870_RUSSIA_polygon] = true, - [EU863870_EUROPE_polygon] = true, - [US902928_GUAM_polygon] = true, - [US902928_ANTARTICA_polygon] = true, - [AS920923_ISRAEL_polygon] = true, - [US902928_MALDIVES_polygon] = true, - [EU863870_UKRAINE_polygon] = false, - [OUTSIDE_polygon] = false, + [AS920923_PHILIPPINES_polygon] = TX_OK, + [US902928_NAMERICA_polygon] = TX_OK, + [AS923925_BRUNEI_polygon] = TX_OK, + [AS923925_TAIWAN_polygon] = TX_OK, + [AS923925_INDONESIA_polygon] = TX_OK, + [AS923925_THAILAND_polygon] = TX_OK, + [US902928_ARGENTINA_polygon] = TX_OK, + [AU915928_BRAZIL_polygon] = TX_OK, + [AU915928_CHILE_polygon] = TX_OK, + [CN779787_CHINA_polygon] = TX_OK, + [IN865867_INDIA_polygon] = TX_OK, + [AS920923_JAPAN_polygon] = TX_OK, + [KR920923_SKOREA_polygon] = TX_OK, + [AS920923_MALAYSIASG_polygon] = TX_OK, + [AU915928_AUSTRALIA_polygon] = TX_OK, + [RU864870_RUSSIA_polygon] = TX_OK, + [EU863870_EUROPE_polygon] = TX_OK, + [US902928_GUAM_polygon] = TX_OK, + [US902928_ANTARTICA_polygon] = TX_OK, + [AS920923_ISRAEL_polygon] = TX_OK, + [US902928_MALDIVES_polygon] = TX_OK, + [EU863870_UKRAINE_polygon] = TX_NOT_OK, + [OUTSIDE_polygon] = TX_NOT_OK, }; /** From 6729d170aaebc5ac0371b57722b12036a636f5a9 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:19:03 +0000 Subject: [PATCH 15/34] Use correct type --- src/peripherals/bsp.c | 2 +- src/peripherals/eeprom_settings_manager.c | 6 +++--- src/peripherals/eeprom_settings_manager.h | 4 ++-- src/peripherals/geofence.c | 4 ++-- tests/geofence_ut.cpp | 4 ++-- tests/uplink_commands_ut.cpp | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/peripherals/bsp.c b/src/peripherals/bsp.c index b1e69aff3..34849629c 100644 --- a/src/peripherals/bsp.c +++ b/src/peripherals/bsp.c @@ -352,7 +352,7 @@ void BSP_sensor_Init(void) IWDG_reset(); // Initialise the geofence permissions mask - bool values[n_polygons]; + tx_permission_t values[n_polygons]; read_geofence_settings_in_eeprom(values); playback_hw_init(); diff --git a/src/peripherals/eeprom_settings_manager.c b/src/peripherals/eeprom_settings_manager.c index 424c68a7d..ae7bfda5c 100644 --- a/src/peripherals/eeprom_settings_manager.c +++ b/src/peripherals/eeprom_settings_manager.c @@ -88,9 +88,9 @@ bool update_geofence_settings_in_eeprom(uint8_t *settings_bytes, uint16_t size) * from EEPROM. Fills passed buffer with the settings. Ensure buffer passed is * of size n_polygons * sizeof(bool) * - * @param values Pointer to buffer that will be filled with the bool enable/disable setting + * @param values Pointer to buffer that will be filled with the tx_permission_t setting */ -void read_geofence_settings_in_eeprom(bool *values) +void read_geofence_settings_in_eeprom(tx_permission_t *values) { // read settings stored in EEPROM geofence_settings_t geofence_settings; @@ -240,7 +240,7 @@ uint8_t get_settings_crc() } // CRC of tx enable/disable settings for different regions. - bool values[n_polygons]; + tx_permission_t values[n_polygons]; read_geofence_settings_in_eeprom(values); crc = Crc8Update(crc, (uint8_t *)values, sizeof(values)); diff --git a/src/peripherals/eeprom_settings_manager.h b/src/peripherals/eeprom_settings_manager.h index b1ab4ece5..5abfe77eb 100644 --- a/src/peripherals/eeprom_settings_manager.h +++ b/src/peripherals/eeprom_settings_manager.h @@ -29,14 +29,14 @@ extern "C" typedef struct { - bool values[n_polygons]; + tx_permission_t values[n_polygons]; uint32_t Crc32; } geofence_settings_t; bool update_device_tx_interval_in_eeprom(uint32_t address, uint32_t interval_ms); uint32_t read_tx_interval_in_eeprom(uint32_t address, uint32_t default_value); bool update_geofence_settings_in_eeprom(uint8_t *settings, uint16_t size); - void read_geofence_settings_in_eeprom(bool *values); + void read_geofence_settings_in_eeprom(tx_permission_t *values); void retrieve_eeprom_stored_lorawan_region(void); void set_eeprom_stored_lorwan_region(void); bool update_device_credentials_to_eeprom(network_keys_t keys, registered_devices_t registered_device); diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index b6b5dbdeb..e386eef45 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -1114,7 +1114,7 @@ tx_permission_t get_current_tx_permission() return current_geofence_status.tx_permission; } -void geofence_init_with_settings(bool *settings) +void geofence_init_with_settings(tx_permission_t *settings) { - memcpy(tx_permissions_for_regions, settings, n_polygons * sizeof(bool)); + memcpy(tx_permissions_for_regions, settings, n_polygons * sizeof(tx_permission_t)); } diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index b0c110e5d..d4084d508 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -12,7 +12,7 @@ extern "C" TEST_GROUP(test_get_current_lorawan_region){ void setup(){ - bool values[n_polygons]; + tx_permission_t values[n_polygons]; read_geofence_settings_in_eeprom(values); } @@ -511,7 +511,7 @@ TEST(test_get_current_lorawan_region, Ukraine) TEST_GROUP(test_update_geofence_settings){ void setup(){ - bool values[n_polygons]; + tx_permission_t values[n_polygons]; read_geofence_settings_in_eeprom(values); } diff --git a/tests/uplink_commands_ut.cpp b/tests/uplink_commands_ut.cpp index 0c42cc932..f2616ae95 100644 --- a/tests/uplink_commands_ut.cpp +++ b/tests/uplink_commands_ut.cpp @@ -337,7 +337,7 @@ TEST(uplink_commands, verify_geofence_mask_is_changed_correctly) */ OnRxData(&appData, &LmHandlerRxParams); - bool values[n_polygons]; + tx_permission_t values[n_polygons]; read_geofence_settings_in_eeprom(values); update_geofence_position(50.4501, 30.5234); // Ukraine From 86c01d0c33b0429c7202cad77b0667ea1f425de5 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:20:39 +0000 Subject: [PATCH 16/34] use correct type --- src/peripherals/geofence.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index 259bf23bb..4bb3f3866 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -99,7 +99,7 @@ extern "C" /* Function prototypes for public (external) functions go here */ void update_geofence_position(float latitude, float longitude); - void geofence_init_with_settings(bool *settings); + void geofence_init_with_settings(tx_permission_t *settings); LoRaMacRegion_t get_current_loramac_region(void); as923_subbands_t get_as923_subband(void); void set_current_loramac_region(LoRaMacRegion_t region); From cb655fad2b74dd7ee7f98b53fcdd1ec2adc14d7a Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:33:35 +0000 Subject: [PATCH 17/34] Use correct type and size --- src/peripherals/eeprom_settings_manager.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/peripherals/eeprom_settings_manager.c b/src/peripherals/eeprom_settings_manager.c index ae7bfda5c..8eb2c8eb3 100644 --- a/src/peripherals/eeprom_settings_manager.c +++ b/src/peripherals/eeprom_settings_manager.c @@ -92,18 +92,20 @@ bool update_geofence_settings_in_eeprom(uint8_t *settings_bytes, uint16_t size) */ void read_geofence_settings_in_eeprom(tx_permission_t *values) { + // todo: check non-null // read settings stored in EEPROM geofence_settings_t geofence_settings; NvmmRead((uint8_t *)&geofence_settings, TX_PERMISSIONS_LEN, TX_PERMISSIONS_ADDR); + uint16_t sizeof_values = sizeof(geofence_settings.values); // Use eeprom stored values only if CRC is correct. Else assume the default settings if (is_crc_correct(sizeof(geofence_settings_t), (void *)&geofence_settings)) { - memcpy(values, geofence_settings.values, n_polygons * sizeof(bool)); + memcpy(values, geofence_settings.values, sizeof_values); } else { - memcpy(values, default_geofence_settings, n_polygons * sizeof(bool)); + memcpy(values, default_geofence_settings, sizeof_values); } geofence_init_with_settings(values); From ed92336d69d1d6e8b917b6cbe9157c238f2c38d8 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:38:05 +0000 Subject: [PATCH 18/34] fix return type --- src/peripherals/geofence.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index e386eef45..59857eec3 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -999,10 +999,7 @@ Polygon_t get_polygon(float latitude, float longitude) tx_permission_t get_permissions(Polygon_t currentpoly) { // then lookup value. Danger, there is no bounds validation for current poly. Can cause corruption. - bool can_transmit = tx_permissions_for_regions[currentpoly]; - - // then return permission - return can_transmit ? TX_OK : TX_NOT_OK; + return tx_permissions_for_regions[currentpoly]; } static void set_current_loramac_region_from_polygon(Polygon_t current_poly) From a4a322a20f93c43207bdb76dfa4c19eeb2edfdbe Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:40:00 +0000 Subject: [PATCH 19/34] default over north korea --- tests/geofence_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index d4084d508..32968ac1f 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -524,12 +524,12 @@ void teardown() /** - * @brief Test by default if it disables tx over Ukraine. + * @brief Test by default if it disables tx over North Korea. * */ TEST(test_update_geofence_settings, check_defaults_mask_tx_disabled_location) { - update_geofence_position(50.4501, 30.5234); // Ukraine + update_geofence_position(39.0392, 125.7625); // Pyongyang CHECK_EQUAL(TX_NOT_OK, get_current_tx_permission()); } From 4bc59182bf6e89df042122a443c96ed3ecc13912 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Tue, 17 Jan 2023 18:42:37 +0000 Subject: [PATCH 20/34] north korea --- tests/geofence_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index 32968ac1f..025ebd4a9 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -572,8 +572,8 @@ TEST(test_update_geofence_settings, check_enable_later_north_korea) [US902928_ANTARTICA_polygon] = TX_OK, [AS920923_ISRAEL_polygon] = TX_OK, [US902928_MALDIVES_polygon] = TX_OK, - [EU863870_UKRAINE_polygon] = TX_NOT_OK, - [OUTSIDE_polygon] = TX_NOT_OK, + [EU863870_UKRAINE_polygon] = TX_OK, + [OUTSIDE_polygon] = TX_OK, // North Korea does not have a dedicated polygon. Its considered in the outside region }, .Crc32 = 100, // dummy CRC }; From 2a09b6d1fe0b8137eecc1a9c356432f0ec02791f Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 16:27:05 +0000 Subject: [PATCH 21/34] Add a north korea polygon --- util_scripts/geofence.kml | 524 ++++++++++++++++++++------------------ 1 file changed, 273 insertions(+), 251 deletions(-) diff --git a/util_scripts/geofence.kml b/util_scripts/geofence.kml index c06bcb14d..eaca404b1 100644 --- a/util_scripts/geofence.kml +++ b/util_scripts/geofence.kml @@ -2,10 +2,9 @@ geofence - + - + normal - #__managed_style_0BA4C42C3C206C5C2FAB + #__managed_style_1122557EAC26FB17ACA0 highlight - #__managed_style_12CE4D92CE206C5C2FAB + #__managed_style_26643AE47026FB17ACA0 - - - + + + normal + #poly-000000-1200-77-nodesc-normal + + + highlight + #poly-000000-1200-77-nodesc-highlight + + + - + + - + normal - #poly-FFEA00-2000-77-nodesc-normal + #poly-1A237E-2000-77-nodesc-normal highlight - #poly-FFEA00-2000-77-nodesc-highlight + #poly-1A237E-2000-77-nodesc-highlight - + + + + + + + + + normal - #poly-000000-1200-77-nodesc-normal + #__managed_style_1D68A668DB26FB17AC9F highlight - #poly-000000-1200-77-nodesc-highlight + #__managed_style_20260B40BC26FB17AC9F - - + - - - - normal - #poly-CE93D8-2000-77-nodesc-normal - - - highlight - #poly-CE93D8-2000-77-nodesc-highlight - - - - - - - normal - #poly-7CB342-2000-77-nodesc-normal - - - highlight - #poly-7CB342-2000-77-nodesc-highlight - - - - - normal - #poly-87CEAC-2000-77-nodesc-normal - - - highlight - #poly-87CEAC-2000-77-nodesc-highlight - - - - - - - - - - - - - normal - #poly-9C27B0-1200-77-nodesc-normal - - - highlight - #poly-9C27B0-1200-77-nodesc-highlight - - - + normal - #poly-880E4F-2000-77-nodesc-normal + #poly-CE93D8-2000-77-nodesc-normal highlight - #poly-880E4F-2000-77-nodesc-highlight + #poly-CE93D8-2000-77-nodesc-highlight - + normal - #__managed_style_1F2CE66292206C5C2FA9 + #poly-B2EBF2-2000-77-nodesc-normal highlight - #__managed_style_261BA41B02206C5C2FA9 + #poly-B2EBF2-2000-77-nodesc-highlight - - - + normal - #poly-1A237E-2000-77-nodesc-normal + #poly-880E4F-2000-77-nodesc-normal highlight - #poly-1A237E-2000-77-nodesc-highlight + #poly-880E4F-2000-77-nodesc-highlight - - + normal - #poly-3949AB-2000-77-nodesc-normal + #poly-7CB342-2000-77-nodesc-normal highlight - #poly-3949AB-2000-77-nodesc-highlight + #poly-7CB342-2000-77-nodesc-highlight - + + + normal + #__managed_style_43AA067DBE26FB17AC9F + + + highlight + #__managed_style_5C4C69B8E126FB17AC9F + + - - - - - - + normal - #poly-B2EBF2-2000-77-nodesc-normal + #poly-87CEAC-2000-77-nodesc-normal highlight - #poly-B2EBF2-2000-77-nodesc-highlight + #poly-87CEAC-2000-77-nodesc-highlight - + + + normal + #poly-FFEA00-2000-77-nodesc-normal + + + highlight + #poly-FFEA00-2000-77-nodesc-highlight + + - + + + normal + #poly-9C27B0-1200-77-nodesc-normal + + + highlight + #poly-9C27B0-1200-77-nodesc-highlight + + - - - normal - #poly-FF5252-2000-77-nodesc-normal - - - highlight - #poly-FF5252-2000-77-nodesc-highlight - - - - - - - normal - #__managed_style_104CDAFF68206C5C2FAA - - - highlight - #__managed_style_2DAF3C1CA4206C5C2FAA - - - - + normal - #poly-000000-2000-77-nodesc-normal + #poly-FF5252-2000-77-nodesc-normal highlight - #poly-000000-2000-77-nodesc-highlight + #poly-FF5252-2000-77-nodesc-highlight @@ -725,7 +725,7 @@ AS920-923_JAPAN - #__managed_style_0BE504CF3C206C5C2FA9 + #__managed_style_016DFEA8EA26FB17AC9F @@ -742,9 +742,8 @@ - 1 - 122.945455,36.600459,0 122.599124,32.473613,0 126.133817,32.605336,0 129.468404,35.184136,0 131.425696,38.217623,0 131.679794,41.620036,0 127.965536,39.816944,0 128.331082,38.53374,0 122.945455,36.600459,0 + 122.945455,36.600459,0 122.599124,32.473613,0 126.133817,32.605336,0 129.468404,35.184136,0 131.425696,38.217623,0 131.8448330756216,41.61508613768319,0 130.9010739199294,42.36039447527702,0 129.6549296368114,40.70373855307114,0 127.965536,39.816944,0 128.331082,38.53374,0 122.945455,36.600459,0 @@ -806,7 +805,7 @@ US902-928_GUAM - #__managed_style_07BECFF910206C5C2FAA + #__managed_style_3B3F9B1A3C26FB17AC9F @@ -842,7 +841,7 @@ 668317.9679750651 absolute - #__managed_style_3776E77E93206C5C2FAA + #__managed_style_0F7485DD8C26FB17ACA0 @@ -865,7 +864,7 @@ 6082097.131372691 absolute - #__managed_style_3776E77E93206C5C2FAA + #__managed_style_0F7485DD8C26FB17ACA0 @@ -888,12 +887,35 @@ 2890758.348155916 absolute - #__managed_style_3776E77E93206C5C2FAA + #__managed_style_0F7485DD8C26FB17ACA0 + + + + + 23.56070334750491,51.52339542849054,-26.54839187682323 23.97834365726641,50.47995531671017,64.76627663048656 22.64804609176132,49.41854974465313,-290.8014189601843 22.08500474074314,48.38806679169764,-555.0203591369122 23.64356970669406,47.8822618021443,181.3243180825767 25.86950314806064,47.65782137554923,1089.438848225812 27.02386202601588,48.3420070542892,-142.7254448976629 28.96877775956812,47.91685077269667,-201.6900173032766 29.96648846831203,46.55167636313,939.4124651912442 28.42077496017039,45.83573220544856,-416.8170037922622 28.16426284029453,45.1234460709101,687.2959801093706 29.87945287690174,44.8200468163233,98.24747623518675 33.17472369395597,44.28230731213979,-1752.893637234473 35.65835802518375,44.40044058872738,-554.4020614174158 38.3572054407473,47.12221088589286,646.1818811160567 40.08039306635287,48.01017315383601,-48.77843790988916 40.53633668095822,49.33750553170302,-30.71691055029555 37.51445855058526,50.40559624661842,126.5269892832724 33.90838849096268,52.44803171543372,427.1710340832335 30.86254270532443,52.20353672504333,919.4949614620284 30.04236666854612,51.63257725263867,475.8350702372484 25.01649289652931,52.03999418857604,224.6433391802126 23.56070334750491,51.52339542849054,-26.54839187682323 + + + + + + + EU863-870_NORTH_KOREA + + 125.6408140213697 + 38.96659963959431 + 203.1580948815654 + 0 + 0 + 35 + 2382946.933434606 + absolute + + #__managed_style_0F7485DD8C26FB17ACA0 - 23.56070334750491,51.52339542849054,-26.54839187682323 23.97834365726641,50.47995531671017,64.76627663048656 22.64804609176132,49.41854974465313,-290.8014189601843 22.08500474074314,48.38806679169764,-555.0203591369122 23.64356970669406,47.8822618021443,181.3243180825767 25.86950314806064,47.65782137554923,1089.438848225812 27.02386202601588,48.3420070542892,-142.7254448976629 28.96877775956812,47.91685077269667,-201.6900173032766 29.96648846831203,46.55167636313001,939.4124651912442 28.42077496017039,45.83573220544856,-416.8170037922622 28.16426284029453,45.1234460709101,687.2959801093706 29.87945287690174,44.8200468163233,98.24747623518675 33.17472369395597,44.28230731213979,-1752.893637234473 35.65835802518375,44.40044058872738,-554.4020614174158 38.3572054407473,47.12221088589286,646.1818811160567 40.08039306635287,48.01017315383601,-48.77843790988916 40.53633668095822,49.33750553170302,-30.71691055029555 37.51445855058526,50.40559624661842,126.5269892832724 33.90838849096268,52.44803171543372,427.1710340832335 30.86254270532443,52.20353672504333,919.4949614620284 30.04236666854612,51.63257725263867,475.8350702372484 25.01649289652931,52.03999418857604,224.6433391802126 23.56070334750491,51.52339542849054,-26.54839187682323 + 124.1670823115053,39.74409177734425,158.1356675107385 124.8661267107351,39.40397557366102,422.2049066238911 124.5688374204719,38.03066677413586,12.20821200580563 125.5952743887899,37.58796806855445,57.78944787374744 128.255182108082,38.53998243512707,328.3884239785185 127.7769152324087,39.27209801788673,161.0219386833381 127.6603827169223,39.736599211547,-270.2362573723619 129.593310882984,40.7351614784365,518.5683842441658 129.9289702910408,41.3665440600562,576.0098750491494 130.757954111428,42.2650936787109,291.7477879241508 130.2457079819154,43.2440622130685,153.7225797622949 124.1670823115053,39.74409177734425,158.1356675107385 From ad6995c40289be45f14ed2635552223d7cf29755 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 16:33:22 +0000 Subject: [PATCH 22/34] add nk polygon --- src/peripherals/geofence.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index 4bb3f3866..69fd855ea 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -88,6 +88,7 @@ extern "C" AS920923_ISRAEL_polygon, US902928_MALDIVES_polygon, EU863870_UKRAINE_polygon, + EU863870_NORTH_KOREA_polygon, OUTSIDE_polygon, n_polygons, } Polygon_t; From 7bda8b8e1ccf9fa3fb9b95f38cedc9486f7e6c90 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 16:35:51 +0000 Subject: [PATCH 23/34] Add north korea polygon --- src/peripherals/geofence.c | 47 ++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index 59857eec3..0cb85deb3 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -386,7 +386,7 @@ static const float AS920923_JAPAN_F[32] = { }; -static const float KR920923_SKOREA_F[18] = { +static const float KR920923_SKOREA_F[22] = { 122.94545, 36.60046, 122.59912, @@ -397,8 +397,12 @@ static const float KR920923_SKOREA_F[18] = { 35.18414, 131.42570, 38.21762, - 131.67979, - 41.62004, + 131.84483, + 41.61509, + 130.90107, + 42.36039, + 129.65493, + 40.70374, 127.96554, 39.81694, 128.33108, @@ -768,6 +772,34 @@ static const float EU863870_UKRAINE_F[46] = { }; +static const float EU863870_NORTH_KOREA_F[24] = { + 124.16708, + 39.74409, + 124.86613, + 39.40398, + 124.56884, + 38.03067, + 125.59527, + 37.58797, + 128.25518, + 38.53998, + 127.77692, + 39.27210, + 127.66038, + 39.73660, + 129.59331, + 40.73516, + 129.92897, + 41.36654, + 130.75795, + 42.26509, + 130.24571, + 43.24406, + 124.16708, + 39.74409, + +}; + /* ==================================================================== */ /* ========================== private data ============================ */ /* ==================================================================== */ @@ -986,6 +1018,11 @@ Polygon_t get_polygon(float latitude, float longitude) current_poly = US902928_MALDIVES_polygon; } + else if (pointInPolygonF(12, EU863870_NORTH_KOREA_F, latitude, longitude) == 1) + { + current_poly = EU863870_NORTH_KOREA_polygon; + } + return current_poly; } @@ -1085,7 +1122,9 @@ static void set_current_loramac_region_from_polygon(Polygon_t current_poly) case EU863870_UKRAINE_polygon: current_geofence_status.current_loramac_region = LORAMAC_REGION_EU868; break; - + case EU863870_NORTH_KOREA_polygon: + current_geofence_status.current_loramac_region = LORAMAC_REGION_EU868; + break; case OUTSIDE_polygon: current_geofence_status.current_loramac_region = LORAMAC_REGION_EU868; break; From 710f1fb1b3d50dc694dc4d299edc98d8daeaba50 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 16:41:20 +0000 Subject: [PATCH 24/34] update tests --- tests/geofence_ut.cpp | 2 ++ tests/test_eeprom_settings_manager.cpp | 1 + tests/uplink_commands_ut.cpp | 1 + 3 files changed, 4 insertions(+) diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index 025ebd4a9..75e5915ac 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -573,6 +573,7 @@ TEST(test_update_geofence_settings, check_enable_later_north_korea) [AS920923_ISRAEL_polygon] = TX_OK, [US902928_MALDIVES_polygon] = TX_OK, [EU863870_UKRAINE_polygon] = TX_OK, + [EU863870_NORTH_KOREA_polygon] = TX_NOT_OK, [OUTSIDE_polygon] = TX_OK, // North Korea does not have a dedicated polygon. Its considered in the outside region }, .Crc32 = 100, // dummy CRC @@ -613,6 +614,7 @@ TEST(test_update_geofence_settings, check_disable_later_Philipines) [AS920923_ISRAEL_polygon] = TX_OK, [US902928_MALDIVES_polygon] = TX_OK, [EU863870_UKRAINE_polygon] = TX_OK, + [EU863870_NORTH_KOREA_polygon] = TX_NOT_OK, [OUTSIDE_polygon] = TX_NOT_OK, }, .Crc32 = 100, // dummy CRC diff --git a/tests/test_eeprom_settings_manager.cpp b/tests/test_eeprom_settings_manager.cpp index 3384ea304..da593c7b1 100644 --- a/tests/test_eeprom_settings_manager.cpp +++ b/tests/test_eeprom_settings_manager.cpp @@ -77,6 +77,7 @@ TEST(test_eeprom_settings_manager, test_eeprom_unchanged_crc) [AS920923_ISRAEL_polygon] = TX_OK, [US902928_MALDIVES_polygon] = TX_OK, [EU863870_UKRAINE_polygon] = TX_OK, + [EU863870_NORTH_KOREA_polygon] = TX_NOT_OK, [OUTSIDE_polygon] = TX_NOT_OK, }; update_geofence_settings_in_eeprom((uint8_t *)geofence_settings, sizeof(geofence_settings)); diff --git a/tests/uplink_commands_ut.cpp b/tests/uplink_commands_ut.cpp index f2616ae95..6de463f88 100644 --- a/tests/uplink_commands_ut.cpp +++ b/tests/uplink_commands_ut.cpp @@ -314,6 +314,7 @@ TEST(uplink_commands, verify_geofence_mask_is_changed_correctly) [AS920923_ISRAEL_polygon] = TX_OK, [US902928_MALDIVES_polygon] = TX_OK, [EU863870_UKRAINE_polygon] = TX_NOT_OK, + [EU863870_NORTH_KOREA_polygon] = TX_NOT_OK, [OUTSIDE_polygon] = TX_NOT_OK, }; From 2245666c1db547a4e7acee440d5c95ca4e8c5106 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 16:44:00 +0000 Subject: [PATCH 25/34] corret default --- src/peripherals/eeprom_settings_manager.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/peripherals/eeprom_settings_manager.c b/src/peripherals/eeprom_settings_manager.c index 8eb2c8eb3..2a7cee51c 100644 --- a/src/peripherals/eeprom_settings_manager.c +++ b/src/peripherals/eeprom_settings_manager.c @@ -42,6 +42,7 @@ static const bool default_geofence_settings[n_polygons] = { [AS920923_ISRAEL_polygon] = TX_OK, [US902928_MALDIVES_polygon] = TX_OK, [EU863870_UKRAINE_polygon] = TX_OK, + [EU863870_NORTH_KOREA_polygon] = TX_NOT_OK, [OUTSIDE_polygon] = TX_NOT_OK, }; From 3e2ae448102e48f8f39ad83215b6bf0527a11cd9 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 17:19:31 +0000 Subject: [PATCH 26/34] dedicater polygon --- tests/geofence_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/geofence_ut.cpp b/tests/geofence_ut.cpp index 75e5915ac..81aa28b32 100644 --- a/tests/geofence_ut.cpp +++ b/tests/geofence_ut.cpp @@ -573,8 +573,8 @@ TEST(test_update_geofence_settings, check_enable_later_north_korea) [AS920923_ISRAEL_polygon] = TX_OK, [US902928_MALDIVES_polygon] = TX_OK, [EU863870_UKRAINE_polygon] = TX_OK, - [EU863870_NORTH_KOREA_polygon] = TX_NOT_OK, - [OUTSIDE_polygon] = TX_OK, // North Korea does not have a dedicated polygon. Its considered in the outside region + [EU863870_NORTH_KOREA_polygon] = TX_OK, + [OUTSIDE_polygon] = TX_NOT_OK, }, .Crc32 = 100, // dummy CRC }; From d2bf406743fe61c046143c502d92aa7ccb9c5ee5 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 17:33:26 +0000 Subject: [PATCH 27/34] use correct type --- src/peripherals/eeprom_settings_manager.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/peripherals/eeprom_settings_manager.c b/src/peripherals/eeprom_settings_manager.c index 2a7cee51c..aa1cadf15 100644 --- a/src/peripherals/eeprom_settings_manager.c +++ b/src/peripherals/eeprom_settings_manager.c @@ -19,7 +19,7 @@ #include "bsp.h" #include "eeprom_settings_manager.h" -static const bool default_geofence_settings[n_polygons] = { +static const tx_permission_t default_geofence_settings[n_polygons] = { [AS920923_PHILIPPINES_polygon] = TX_OK, [US902928_NAMERICA_polygon] = TX_OK, [AS923925_BRUNEI_polygon] = TX_OK, @@ -87,7 +87,7 @@ bool update_geofence_settings_in_eeprom(uint8_t *settings_bytes, uint16_t size) /** * @brief Reads and initialised the geofence module with the tx enable/disable settings * from EEPROM. Fills passed buffer with the settings. Ensure buffer passed is - * of size n_polygons * sizeof(bool) + * of size n_polygons * sizeof(tx_permission_t) * * @param values Pointer to buffer that will be filled with the tx_permission_t setting */ From 92b66d6d550596901b6526683838ec86d1309d8e Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 17:41:05 +0000 Subject: [PATCH 28/34] use sizeof --- src/peripherals/geofence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index 0cb85deb3..fd4a72611 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -1152,5 +1152,5 @@ tx_permission_t get_current_tx_permission() void geofence_init_with_settings(tx_permission_t *settings) { - memcpy(tx_permissions_for_regions, settings, n_polygons * sizeof(tx_permission_t)); + memcpy(tx_permissions_for_regions, settings, sizeof(tx_permissions_for_regions)); } From a9f11a8449c29a0fe46c5647c205d336819d173a Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 17:43:32 +0000 Subject: [PATCH 29/34] Update comment --- src/peripherals/geofence.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peripherals/geofence.h b/src/peripherals/geofence.h index 69fd855ea..025b0a1a9 100644 --- a/src/peripherals/geofence.h +++ b/src/peripherals/geofence.h @@ -44,7 +44,7 @@ extern "C" typedef enum { - TX_OK = 0, // default of 0 falls back to TX_OK. This is required to ensure by default, we can transmit if not specified. + TX_OK = 0, // Default value is TX_OK. If this value is uninitialised, it will failsafe to TX_OK. TX_NOT_OK } tx_permission_t; From 95461ecca1f6d1956a871916e0eb8224c8755654 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 17:49:46 +0000 Subject: [PATCH 30/34] Add bounds check --- src/peripherals/geofence.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index fd4a72611..0540a93e9 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -1036,7 +1036,12 @@ Polygon_t get_polygon(float latitude, float longitude) tx_permission_t get_permissions(Polygon_t currentpoly) { // then lookup value. Danger, there is no bounds validation for current poly. Can cause corruption. - return tx_permissions_for_regions[currentpoly]; + tx_permission_t result = TX_OK; // failsafe by allowing TX + if (currentpoly < n_polygons) + { + result = tx_permissions_for_regions[currentpoly]; + } + return result; } static void set_current_loramac_region_from_polygon(Polygon_t current_poly) From 9dddcae66c42c0e037c2d8e6b3cdb2a956336c72 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 17:50:27 +0000 Subject: [PATCH 31/34] delete unneeded comment --- src/peripherals/geofence.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index 0540a93e9..2671033a2 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -1035,7 +1035,6 @@ Polygon_t get_polygon(float latitude, float longitude) */ tx_permission_t get_permissions(Polygon_t currentpoly) { - // then lookup value. Danger, there is no bounds validation for current poly. Can cause corruption. tx_permission_t result = TX_OK; // failsafe by allowing TX if (currentpoly < n_polygons) { From b5d5602f4e72b6e2eeb2879affd2316ba0a6cb8a Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 18:25:51 +0000 Subject: [PATCH 32/34] correct type --- tests/test_eeprom_settings_manager.cpp | 2 +- tests/uplink_commands_ut.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_eeprom_settings_manager.cpp b/tests/test_eeprom_settings_manager.cpp index da593c7b1..16d0d4062 100644 --- a/tests/test_eeprom_settings_manager.cpp +++ b/tests/test_eeprom_settings_manager.cpp @@ -54,7 +54,7 @@ TEST(test_eeprom_settings_manager, test_eeprom_unchanged_crc) uint8_t before_crc = get_settings_crc(); // Geofence settings are still default values - static const bool geofence_settings[n_polygons] = { + static const tx_permission_t geofence_settings[n_polygons] = { [AS920923_PHILIPPINES_polygon] = TX_OK, [US902928_NAMERICA_polygon] = TX_OK, [AS923925_BRUNEI_polygon] = TX_OK, diff --git a/tests/uplink_commands_ut.cpp b/tests/uplink_commands_ut.cpp index 6de463f88..a64eb1656 100644 --- a/tests/uplink_commands_ut.cpp +++ b/tests/uplink_commands_ut.cpp @@ -291,7 +291,7 @@ TEST(uplink_commands, verify_geofence_mask_is_changed_correctly) uint8_t length_of_uplink = n_polygons * sizeof(bool); uint8_t simulated_downlink_from_ground[length_of_uplink]; - static const bool instructions[n_polygons] = { + static const tx_permission_t instructions[n_polygons] = { [AS920923_PHILIPPINES_polygon] = TX_OK, [US902928_NAMERICA_polygon] = TX_OK, [AS923925_BRUNEI_polygon] = TX_OK, From 19c0e1a2288f001d5a82fbe43eedfbb4624ed8bf Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 18:35:24 +0000 Subject: [PATCH 33/34] use default at root --- src/peripherals/eeprom_settings_manager.c | 7 +----- src/peripherals/geofence.c | 29 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/peripherals/eeprom_settings_manager.c b/src/peripherals/eeprom_settings_manager.c index aa1cadf15..c9f87fdcd 100644 --- a/src/peripherals/eeprom_settings_manager.c +++ b/src/peripherals/eeprom_settings_manager.c @@ -103,13 +103,8 @@ void read_geofence_settings_in_eeprom(tx_permission_t *values) if (is_crc_correct(sizeof(geofence_settings_t), (void *)&geofence_settings)) { memcpy(values, geofence_settings.values, sizeof_values); + geofence_init_with_settings(values); } - else - { - memcpy(values, default_geofence_settings, sizeof_values); - } - - geofence_init_with_settings(values); } /** diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index 2671033a2..8925ff6fd 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -37,10 +37,35 @@ /** * @brief Transmission enable/disable mask for each region. Each * boolean value corresponds to each enum value in Polygon_t. - * By default, transmissions are disabled over the UKRAINE and + * By default, transmissions are disabled over the North Korea and * and region outside of the geofence regions. */ -tx_permission_t tx_permissions_for_regions[n_polygons]; +static const tx_permission_t tx_permissions_for_regions[n_polygons] = { + [AS920923_PHILIPPINES_polygon] = TX_OK, + [US902928_NAMERICA_polygon] = TX_OK, + [AS923925_BRUNEI_polygon] = TX_OK, + [AS923925_TAIWAN_polygon] = TX_OK, + [AS923925_INDONESIA_polygon] = TX_OK, + [AS923925_THAILAND_polygon] = TX_OK, + [US902928_ARGENTINA_polygon] = TX_OK, + [AU915928_BRAZIL_polygon] = TX_OK, + [AU915928_CHILE_polygon] = TX_OK, + [CN779787_CHINA_polygon] = TX_OK, + [IN865867_INDIA_polygon] = TX_OK, + [AS920923_JAPAN_polygon] = TX_OK, + [KR920923_SKOREA_polygon] = TX_OK, + [AS920923_MALAYSIASG_polygon] = TX_OK, + [AU915928_AUSTRALIA_polygon] = TX_OK, + [RU864870_RUSSIA_polygon] = TX_OK, + [EU863870_EUROPE_polygon] = TX_OK, + [US902928_GUAM_polygon] = TX_OK, + [US902928_ANTARTICA_polygon] = TX_OK, + [AS920923_ISRAEL_polygon] = TX_OK, + [US902928_MALDIVES_polygon] = TX_OK, + [EU863870_UKRAINE_polygon] = TX_OK, + [EU863870_NORTH_KOREA_polygon] = TX_NOT_OK, + [OUTSIDE_polygon] = TX_NOT_OK, +}; geofence_status_t current_geofence_status = { From 1c666adaf3d2211f920b7f98b15ed215edf02b29 Mon Sep 17 00:00:00 2001 From: Medad Newman Date: Wed, 18 Jan 2023 18:43:29 +0000 Subject: [PATCH 34/34] remove cost --- src/peripherals/geofence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/peripherals/geofence.c b/src/peripherals/geofence.c index 8925ff6fd..42319c97a 100644 --- a/src/peripherals/geofence.c +++ b/src/peripherals/geofence.c @@ -40,7 +40,7 @@ * By default, transmissions are disabled over the North Korea and * and region outside of the geofence regions. */ -static const tx_permission_t tx_permissions_for_regions[n_polygons] = { +static tx_permission_t tx_permissions_for_regions[n_polygons] = { [AS920923_PHILIPPINES_polygon] = TX_OK, [US902928_NAMERICA_polygon] = TX_OK, [AS923925_BRUNEI_polygon] = TX_OK,