lorawan: change downlink callback
Change downlink callback to transport data using flags. Related to Issue #55072 Co-authored-by: Jan Kowalewski <jkowalewski@cthings.co> Signed-off-by: romain pelletant <romainp@kickmaker.net> Signed-off-by: Jan Kowalewski <jkowalewski@cthings.co>
This commit is contained in:
parent
91d3eb9107
commit
866905fd6a
6 changed files with 23 additions and 15 deletions
|
|
@ -103,6 +103,13 @@ enum lorawan_message_type {
|
|||
LORAWAN_MSG_CONFIRMED, /**< Confirmed message */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief LoRaWAN downlink flags.
|
||||
*/
|
||||
enum lorawan_dl_flags {
|
||||
LORAWAN_DATA_PENDING = BIT(0),
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief LoRaWAN join parameters for over-the-Air activation (OTAA)
|
||||
*
|
||||
|
|
@ -181,15 +188,14 @@ struct lorawan_downlink_cb {
|
|||
* 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 flags Downlink data flags (see @ref lorawan_dl_flags)
|
||||
* @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);
|
||||
void (*cb)(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr, uint8_t len,
|
||||
const uint8_t *data);
|
||||
/** Node for callback list */
|
||||
sys_snode_t node;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,11 +27,12 @@ LOG_MODULE_REGISTER(lorawan_class_a);
|
|||
|
||||
char data[] = {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'};
|
||||
|
||||
static void dl_callback(uint8_t port, bool data_pending,
|
||||
static void dl_callback(uint8_t port, uint8_t flags,
|
||||
int16_t rssi, int8_t snr,
|
||||
uint8_t len, const uint8_t *hex_data)
|
||||
{
|
||||
LOG_INF("Port %d, Pending %d, RSSI %ddB, SNR %ddBm", port, data_pending, rssi, snr);
|
||||
LOG_INF("Port %d, Pending %d, RSSI %ddB, SNR %ddBm",
|
||||
port, flags & LORAWAN_DATA_PENDING, rssi, snr);
|
||||
if (hex_data) {
|
||||
LOG_HEXDUMP_INF(hex_data, len, "Payload: ");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ static void mcps_confirm_handler(McpsConfirm_t *mcps_confirm)
|
|||
static void mcps_indication_handler(McpsIndication_t *mcps_indication)
|
||||
{
|
||||
struct lorawan_downlink_cb *cb;
|
||||
uint8_t flags = 0;
|
||||
|
||||
LOG_DBG("Received McpsIndication %d", mcps_indication->McpsIndication);
|
||||
|
||||
|
|
@ -162,15 +163,15 @@ static void mcps_indication_handler(McpsIndication_t *mcps_indication)
|
|||
datarate_observe(false);
|
||||
}
|
||||
|
||||
/* IsUplinkTxPending also indicates pending downlinks */
|
||||
flags |= (mcps_indication->IsUplinkTxPending == 1 ? LORAWAN_DATA_PENDING : 0);
|
||||
|
||||
/* Iterate over all registered downlink callbacks */
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&dl_callbacks, cb, node) {
|
||||
if ((cb->port == LW_RECV_PORT_ANY) ||
|
||||
(cb->port == mcps_indication->Port)) {
|
||||
cb->cb(mcps_indication->Port,
|
||||
/* IsUplinkTxPending also indicates pending downlinks */
|
||||
mcps_indication->IsUplinkTxPending == 1,
|
||||
mcps_indication->Rssi, mcps_indication->Snr,
|
||||
mcps_indication->BufferSize,
|
||||
cb->cb(mcps_indication->Port, flags, mcps_indication->Rssi,
|
||||
mcps_indication->Snr, mcps_indication->BufferSize,
|
||||
mcps_indication->Buffer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ static inline k_timeout_t clock_sync_calc_periodicity(void)
|
|||
return K_SECONDS(ctx.periodicity - 30 + sys_rand32_get() % 61);
|
||||
}
|
||||
|
||||
static void clock_sync_package_callback(uint8_t port, bool data_pending, int16_t rssi, int8_t snr,
|
||||
static void clock_sync_package_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr,
|
||||
uint8_t len, const uint8_t *rx_buf)
|
||||
{
|
||||
uint8_t tx_buf[3 * MAX_CLOCK_SYNC_ANS_LEN];
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ static struct frag_transport_context ctx;
|
|||
/* Callback for notification of finished firmware transfer */
|
||||
static void (*finished_cb)(void);
|
||||
|
||||
static void frag_transport_package_callback(uint8_t port, bool data_pending, int16_t rssi,
|
||||
int8_t snr, uint8_t len, const uint8_t *rx_buf)
|
||||
static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr,
|
||||
uint8_t len, const uint8_t *rx_buf)
|
||||
{
|
||||
uint8_t tx_buf[FRAG_TRANSPORT_MAX_CMDS_PER_PACKAGE * FRAG_TRANSPORT_MAX_ANS_LEN];
|
||||
uint8_t tx_pos = 0;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ static int32_t multicast_schedule_class_c_session(uint8_t id, uint32_t session_t
|
|||
return time_to_start;
|
||||
}
|
||||
|
||||
static void multicast_package_callback(uint8_t port, bool data_pending, int16_t rssi, int8_t snr,
|
||||
static void multicast_package_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr,
|
||||
uint8_t len, const uint8_t *rx_buf)
|
||||
{
|
||||
uint8_t tx_buf[MAX_MULTICAST_CMDS_PER_PACKAGE * MAX_MULTICAST_ANS_LEN];
|
||||
|
|
|
|||
Loading…
Reference in a new issue