lorawan: port oriented downlink callbacks

Add downlink callbacks on a per-port basis. A single message will be
handled as many times as users have registered matching ports. Callbacks
will also be run on "meta" downlink packets on port 0, such as confirmed
uplink acknowledgements.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2021-04-21 22:20:14 +10:00 committed by Maureen Helm
commit bbd53dcde0
2 changed files with 56 additions and 8 deletions

View file

@ -13,6 +13,7 @@
*/
#include <device.h>
#include <sys/slist.h>
#ifdef __cplusplus
extern "C" {
@ -103,6 +104,35 @@ struct lorawan_join_config {
enum lorawan_act_type mode;
};
#define LW_RECV_PORT_ANY UINT16_MAX
struct lorawan_downlink_cb {
/* Port to handle messages for:
* Port 0: TX packet acknowledgements
* Ports 1-255: Standard downlink port
* LW_RECV_PORT_ANY: All downlinks
*/
uint16_t port;
/**
* @brief Callback function to run on downlink data
*
* @note Callbacks are run on the system workqueue,
* and should therefore be as short as possible.
*
* @param port Port message was sent on
* @param data_pending Network server has more downlink packets pending
* @param rssi Received signal strength in dBm
* @param snr Signal to Noise ratio in dBm
* @param len Length of data received, will be 0 for ACKs
* @param data Data received, will be NULL for ACKs
*/
void (*cb)(uint8_t port, bool data_pending,
int16_t rssi, int8_t snr,
uint8_t len, const uint8_t *data);
/** Node for callback list */
sys_snode_t node;
};
/**
* @brief Add battery level callback function.
*
@ -121,6 +151,13 @@ struct lorawan_join_config {
*/
int lorawan_set_battery_level_callback(uint8_t (*battery_lvl_cb)(void));
/**
* @brief Register a callback to be run on downlink packets
*
* @param cb Pointer to structure containing callback parameters
*/
void lorawan_register_downlink_callback(struct lorawan_downlink_cb *cb);
/**
* @brief Register a callback to be called when the datarate changes
*