From 0838cf99bb04f888c8b61f0f1c7fea93839873bc Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Fri, 17 May 2019 11:33:17 +0200 Subject: [PATCH] tests/pkg_semtech-loramac: add RX thread for downlink messages --- tests/pkg_semtech-loramac/main.c | 76 ++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/tests/pkg_semtech-loramac/main.c b/tests/pkg_semtech-loramac/main.c index 52547aabc2..235bc0d99a 100644 --- a/tests/pkg_semtech-loramac/main.c +++ b/tests/pkg_semtech-loramac/main.c @@ -20,6 +20,7 @@ #include #include +#include "thread.h" #include "msg.h" #include "shell.h" #include "fmt.h" @@ -27,12 +28,50 @@ #include "net/loramac.h" #include "semtech_loramac.h" +#define LORAMAC_RECV_MSG_QUEUE (4U) +static msg_t _loramac_recv_queue[LORAMAC_RECV_MSG_QUEUE]; + semtech_loramac_t loramac; /* Application key is 16 bytes long (e.g. 32 hex chars), and thus the longest possible size (with application session and network session keys) */ static char print_buf[LORAMAC_APPKEY_LEN * 2 + 1]; +static char _recv_stack[THREAD_STACKSIZE_DEFAULT]; + +static void *_wait_recv(void *arg) +{ + msg_init_queue(_loramac_recv_queue, LORAMAC_RECV_MSG_QUEUE); + + (void)arg; + while (1) { + /* blocks until something is received */ + switch (semtech_loramac_recv(&loramac)) { + case SEMTECH_LORAMAC_RX_DATA: + loramac.rx_data.payload[loramac.rx_data.payload_len] = 0; + printf("Data received: %s, port: %d\n", + (char *)loramac.rx_data.payload, loramac.rx_data.port); + break; + + case SEMTECH_LORAMAC_RX_LINK_CHECK: + printf("Link check information:\n" + " - Demodulation margin: %d\n" + " - Number of gateways: %d\n", + loramac.link_chk.demod_margin, + loramac.link_chk.nb_gateways); + break; + + case SEMTECH_LORAMAC_RX_CONFIRMED: + puts("Received ACK from network"); + break; + + default: + break; + } + } + return NULL; +} + static void _loramac_usage(void) { puts("Usage: loramac