tests/pkg_semtech-loramac: add RX thread for downlink messages
This commit is contained in:
parent
b7890b3031
commit
0838cf99bb
@ -20,6 +20,7 @@
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#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 <get|set|join|tx|link_check"
|
||||
@ -430,39 +469,7 @@ static int _cmd_loramac(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* wait for receive windows */
|
||||
switch (semtech_loramac_recv(&loramac)) {
|
||||
case SEMTECH_LORAMAC_DATA_RECEIVED:
|
||||
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_DUTYCYCLE_RESTRICTED:
|
||||
puts("Cannot send: dutycycle restriction");
|
||||
return 1;
|
||||
|
||||
case SEMTECH_LORAMAC_BUSY:
|
||||
puts("Cannot send: MAC is busy");
|
||||
return 1;
|
||||
|
||||
case SEMTECH_LORAMAC_TX_ERROR:
|
||||
puts("Cannot send: error");
|
||||
return 1;
|
||||
|
||||
case SEMTECH_LORAMAC_TX_DONE:
|
||||
puts("TX complete, no data received");
|
||||
break;
|
||||
}
|
||||
|
||||
if (loramac.link_chk.available) {
|
||||
printf("Link check information:\n"
|
||||
" - Demodulation margin: %d\n"
|
||||
" - Number of gateways: %d\n",
|
||||
loramac.link_chk.demod_margin,
|
||||
loramac.link_chk.nb_gateways);
|
||||
}
|
||||
|
||||
puts("Message sent with success");
|
||||
return 0;
|
||||
}
|
||||
else if (strcmp(argv[1], "link_check") == 0) {
|
||||
@ -509,6 +516,9 @@ int main(void)
|
||||
{
|
||||
semtech_loramac_init(&loramac);
|
||||
|
||||
thread_create(_recv_stack, sizeof(_recv_stack),
|
||||
THREAD_PRIORITY_MAIN - 1, 0, _wait_recv, NULL, "recv thread");
|
||||
|
||||
puts("All up, running the shell now");
|
||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user