From 69c5ef96659bcc734c66d12a45f6ae050b128f47 Mon Sep 17 00:00:00 2001 From: Lucas Romero Date: Tue, 11 Jun 2024 10:47:10 +0200 Subject: [PATCH] lorawan: services: frag transport: prepare for pluggable decoder by wrapping decoder implementation specific bits in #ifdefs Signed-off-by: Lucas Romero --- modules/loramac-node/CMakeLists.txt | 2 +- subsys/lorawan/services/Kconfig | 12 ++++++++++++ subsys/lorawan/services/frag_transport.c | 25 ++++++++++++++++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/modules/loramac-node/CMakeLists.txt b/modules/loramac-node/CMakeLists.txt index 9e0bdbc9877..a711ab3e5fe 100644 --- a/modules/loramac-node/CMakeLists.txt +++ b/modules/loramac-node/CMakeLists.txt @@ -55,7 +55,7 @@ zephyr_library_sources_ifdef(CONFIG_HAS_SEMTECH_LORAMAC ${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/mac/LoRaMacSerializer.c ) -zephyr_library_sources_ifdef(CONFIG_LORAWAN_FRAG_TRANSPORT +zephyr_library_sources_ifdef(CONFIG_LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH ${ZEPHYR_LORAMAC_NODE_MODULE_DIR}/src/apps/LoRaMac/common/LmHandler/packages/FragDecoder.c ) diff --git a/subsys/lorawan/services/Kconfig b/subsys/lorawan/services/Kconfig index 95905a7cbff..591ba3ad60a 100644 --- a/subsys/lorawan/services/Kconfig +++ b/subsys/lorawan/services/Kconfig @@ -65,6 +65,18 @@ config LORAWAN_FRAG_TRANSPORT The used default port for this service is 201. +choice LORAWAN_FRAG_TRANSPORT_DECODER + bool "Fragmented Data Block Transport decoder implementation" + depends on LORAWAN_FRAG_TRANSPORT + default LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH + +config LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH + bool "Semtech" + help + The default decoder implementation from LoRaMAC-node. + +endchoice # LORAWAN_FRAG_TRANSPORT_DECODER + DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition config LORAWAN_FRAG_TRANSPORT_IMAGE_SIZE diff --git a/subsys/lorawan/services/frag_transport.c b/subsys/lorawan/services/frag_transport.c index 73055461a90..2efe5213992 100644 --- a/subsys/lorawan/services/frag_transport.c +++ b/subsys/lorawan/services/frag_transport.c @@ -13,7 +13,10 @@ #include "lorawan_services.h" #include +#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH #include +#endif + #include #include #include @@ -79,8 +82,10 @@ struct frag_transport_context { /** Application-specific descriptor for the data block, e.g. firmware version */ uint32_t descriptor; +#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH /* variables required for FragDecoder.h */ FragDecoderCallbacks_t decoder_callbacks; +#endif }; /* @@ -127,8 +132,11 @@ static void frag_transport_package_callback(uint8_t port, bool data_pending, int uint8_t missing_frag = CLAMP(ctx.nb_frag - ctx.nb_frag_received, 0, 255); + uint8_t memory_error = 0; +#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH FragDecoderStatus_t decoder_status = FragDecoderGetStatus(); - uint8_t memory_error = decoder_status.MatrixError; + memory_error = decoder_status.MatrixError; +#endif if (participants == 1 || missing_frag > 0) { tx_buf[tx_pos++] = FRAG_TRANSPORT_CMD_FRAG_STATUS; @@ -183,15 +191,22 @@ static void frag_transport_package_callback(uint8_t port, bool data_pending, int status |= BIT(0); } - if (ctx.nb_frag > FRAG_MAX_NB || ctx.frag_size > FRAG_MAX_SIZE || - ctx.nb_frag * ctx.frag_size > FragDecoderGetMaxFileSize()) { + if (ctx.nb_frag > FRAG_MAX_NB || ctx.frag_size > FRAG_MAX_SIZE) { /* Not enough memory */ status |= BIT(1); } +#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH + if (ctx.nb_frag * ctx.frag_size > FragDecoderGetMaxFileSize()) { + /* Not enough memory */ + status |= BIT(1); + } +#endif + /* Descriptor not used: Ignore Wrong Descriptor error */ if ((status & 0x1F) == 0) { +#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH /* * Assign callbacks after initialization to prevent the FragDecoder * from writing byte-wise 0xFF to the entire flash. Instead, erase @@ -204,7 +219,7 @@ static void frag_transport_package_callback(uint8_t port, bool data_pending, int ctx.decoder_callbacks.FragDecoderWrite = frag_flash_write; ctx.decoder_callbacks.FragDecoderRead = frag_flash_read; - +#endif frag_flash_init(ctx.frag_size); ctx.is_active = true; } @@ -251,8 +266,10 @@ static void frag_transport_package_callback(uint8_t port, bool data_pending, int frag_flash_use_cache(); } +#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH decoder_process_status = FragDecoderProcess( frag_counter, (uint8_t *)&rx_buf[rx_pos]); +#endif LOG_INF("DataFragment %u of %u (%u lost), session: %u, decoder result: %d", frag_counter, ctx.nb_frag, frag_counter - ctx.nb_frag_received,