lorawan: services: frag transport: refactor status

to no longer be a long-lived status variable because we already map it into
is_active and this reduces the number of states the transport can be in.

It also helps us prepare for being able to plug in more decoders by
removing implementation specific bits from the general transport interface.

Signed-off-by: Lucas Romero <luqasn@gmail.com>
This commit is contained in:
Lucas Romero 2024-06-11 10:04:25 +02:00 committed by Johan Hedberg
parent ff5df12af8
commit ff906974b8

View file

@ -81,7 +81,6 @@ struct frag_transport_context {
/* variables required for FragDecoder.h */ /* variables required for FragDecoder.h */
FragDecoderCallbacks_t decoder_callbacks; FragDecoderCallbacks_t decoder_callbacks;
int32_t decoder_process_status;
}; };
/* /*
@ -100,6 +99,7 @@ static void frag_transport_package_callback(uint8_t port, bool data_pending, int
uint8_t tx_pos = 0; uint8_t tx_pos = 0;
uint8_t rx_pos = 0; uint8_t rx_pos = 0;
int ans_delay = 0; int ans_delay = 0;
int decoder_process_status;
__ASSERT(port == LORAWAN_PORT_FRAG_TRANSPORT, "Wrong port %d", port); __ASSERT(port == LORAWAN_PORT_FRAG_TRANSPORT, "Wrong port %d", port);
@ -207,7 +207,6 @@ static void frag_transport_package_callback(uint8_t port, bool data_pending, int
frag_flash_init(ctx.frag_size); frag_flash_init(ctx.frag_size);
ctx.is_active = true; ctx.is_active = true;
ctx.decoder_process_status = FRAG_SESSION_ONGOING;
} }
tx_buf[tx_pos++] = FRAG_TRANSPORT_CMD_FRAG_SESSION_SETUP; tx_buf[tx_pos++] = FRAG_TRANSPORT_CMD_FRAG_SESSION_SETUP;
@ -245,23 +244,21 @@ static void frag_transport_package_callback(uint8_t port, bool data_pending, int
break; break;
} }
if (ctx.decoder_process_status == FRAG_SESSION_ONGOING) { if (frag_counter > ctx.nb_frag) {
if (frag_counter > ctx.nb_frag) { /* Additional fragments have to be cached in RAM for recovery
/* Additional fragments have to be cached in RAM for * algorithm.
* recovery algorithm. */
*/ frag_flash_use_cache();
frag_flash_use_cache();
}
ctx.decoder_process_status = FragDecoderProcess(
frag_counter, (uint8_t *)&rx_buf[rx_pos]);
} }
decoder_process_status = FragDecoderProcess(
frag_counter, (uint8_t *)&rx_buf[rx_pos]);
LOG_INF("DataFragment %u of %u (%u lost), session: %u, decoder result: %d", LOG_INF("DataFragment %u of %u (%u lost), session: %u, decoder result: %d",
frag_counter, ctx.nb_frag, frag_counter - ctx.nb_frag_received, frag_counter, ctx.nb_frag, frag_counter - ctx.nb_frag_received,
index, ctx.decoder_process_status); index, decoder_process_status);
if (ctx.decoder_process_status >= 0) { if (decoder_process_status >= 0) {
/* Positive status corresponds to number of lost (but recovered) /* Positive status corresponds to number of lost (but recovered)
* fragments. Value >= 0 means the transport is done. * fragments. Value >= 0 means the transport is done.
*/ */
@ -273,9 +270,8 @@ static void frag_transport_package_callback(uint8_t port, bool data_pending, int
finished_cb(); finished_cb();
} }
ctx.is_active = false;
/* avoid processing further fragments */ /* avoid processing further fragments */
ctx.decoder_process_status = FRAG_SESSION_NOT_STARTED; ctx.is_active = false;
} }
rx_pos += ctx.frag_size; rx_pos += ctx.frag_size;
@ -301,9 +297,6 @@ int lorawan_frag_transport_run(void (*transport_finished_cb)(void))
{ {
finished_cb = transport_finished_cb; finished_cb = transport_finished_cb;
/* initialize non-zero static variables */
ctx.decoder_process_status = FRAG_SESSION_NOT_STARTED;
lorawan_register_downlink_callback(&downlink_cb); lorawan_register_downlink_callback(&downlink_cb);
return 0; return 0;