From fa09d0d612f586ff6b9519128ffda89d108fca42 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Tue, 19 Jan 2021 19:07:52 +1000 Subject: [PATCH] lorawan: queriable payload sizes Add the ability for applications to query the maximum size of packets that can be sent. This must be dynamically queried as the sizes change with datarate, region, and as MAC commands are added by the stack. Signed-off-by: Jordan Yates --- include/lorawan/lorawan.h | 13 +++++++++++++ subsys/lorawan/lorawan.c | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/lorawan/lorawan.h b/include/lorawan/lorawan.h index adda8d54b98..5cedb132dd3 100644 --- a/include/lorawan/lorawan.h +++ b/include/lorawan/lorawan.h @@ -205,6 +205,19 @@ void lorawan_enable_adr(bool enable); */ int lorawan_set_datarate(enum lorawan_datarate dr); +/** + * @brief Get the current payload sizes + * + * Query the current payload sizes. The maximum payload size varies with + * datarate, while the current payload size can be less due to MAC layer + * commands which are inserted into uplink packets. + * + * @param max_next_payload_size Maximum payload size for the next transmission + * @param max_payload_size Maximum payload size for this datarate + */ +void lorawan_get_payload_sizes(uint8_t *max_next_payload_size, + uint8_t *max_payload_size); + #ifdef __cplusplus } #endif diff --git a/subsys/lorawan/lorawan.c b/subsys/lorawan/lorawan.c index 9b7914f97d3..62ff897ce34 100644 --- a/subsys/lorawan/lorawan.c +++ b/subsys/lorawan/lorawan.c @@ -349,6 +349,18 @@ int lorawan_set_datarate(enum lorawan_datarate dr) return 0; } +void lorawan_get_payload_sizes(uint8_t *max_next_payload_size, + uint8_t *max_payload_size) +{ + LoRaMacTxInfo_t txInfo; + + /* QueryTxPossible cannot fail */ + (void)LoRaMacQueryTxPossible(0, &txInfo); + + *max_next_payload_size = txInfo.MaxPossibleApplicationDataSize; + *max_payload_size = txInfo.CurrentPossiblePayloadSize; +} + void lorawan_enable_adr(bool enable) { MibRequestConfirm_t mib_req;