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 <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2021-01-19 19:07:52 +10:00 committed by Anas Nashif
parent 62d4c6947c
commit fa09d0d612
2 changed files with 25 additions and 0 deletions

View File

@ -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

View File

@ -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;