Skip to content

Commit fa09d0d

Browse files
Jordan Yatesnashif
authored andcommitted
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 <[email protected]>
1 parent 62d4c69 commit fa09d0d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/lorawan/lorawan.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ void lorawan_enable_adr(bool enable);
205205
*/
206206
int lorawan_set_datarate(enum lorawan_datarate dr);
207207

208+
/**
209+
* @brief Get the current payload sizes
210+
*
211+
* Query the current payload sizes. The maximum payload size varies with
212+
* datarate, while the current payload size can be less due to MAC layer
213+
* commands which are inserted into uplink packets.
214+
*
215+
* @param max_next_payload_size Maximum payload size for the next transmission
216+
* @param max_payload_size Maximum payload size for this datarate
217+
*/
218+
void lorawan_get_payload_sizes(uint8_t *max_next_payload_size,
219+
uint8_t *max_payload_size);
220+
208221
#ifdef __cplusplus
209222
}
210223
#endif

subsys/lorawan/lorawan.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ int lorawan_set_datarate(enum lorawan_datarate dr)
349349
return 0;
350350
}
351351

352+
void lorawan_get_payload_sizes(uint8_t *max_next_payload_size,
353+
uint8_t *max_payload_size)
354+
{
355+
LoRaMacTxInfo_t txInfo;
356+
357+
/* QueryTxPossible cannot fail */
358+
(void)LoRaMacQueryTxPossible(0, &txInfo);
359+
360+
*max_next_payload_size = txInfo.MaxPossibleApplicationDataSize;
361+
*max_payload_size = txInfo.CurrentPossiblePayloadSize;
362+
}
363+
352364
void lorawan_enable_adr(bool enable)
353365
{
354366
MibRequestConfirm_t mib_req;

0 commit comments

Comments
 (0)