mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
89 lines
2.4 KiB
C
89 lines
2.4 KiB
C
/*
|
|
* Copyright (C) 2017 Inria
|
|
* 2017 Inria Chile
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
* directory for more details.
|
|
*/
|
|
|
|
/**
|
|
* @ingroup tests
|
|
*
|
|
* @file
|
|
* @brief Semtech LoRaMAC test application
|
|
*
|
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
* @author Jose Alamos <jose.alamos@inria.cl>
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef MODULE_SEMTECH_LORAMAC_RX
|
|
#include "thread.h"
|
|
#include "msg.h"
|
|
#endif
|
|
|
|
#include "shell.h"
|
|
#include "semtech_loramac.h"
|
|
|
|
extern semtech_loramac_t loramac;
|
|
|
|
#ifdef MODULE_SEMTECH_LORAMAC_RX
|
|
#define LORAMAC_RECV_MSG_QUEUE (4U)
|
|
static msg_t _loramac_recv_queue[LORAMAC_RECV_MSG_QUEUE];
|
|
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;
|
|
|
|
case SEMTECH_LORAMAC_TX_SCHEDULE:
|
|
puts("The Network Server has pending data");
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
#endif
|
|
|
|
/* loramac shell command handler is implemented in
|
|
sys/shell/commands/sc_loramac.c */
|
|
|
|
int main(void)
|
|
{
|
|
#ifdef MODULE_SEMTECH_LORAMAC_RX
|
|
thread_create(_recv_stack, sizeof(_recv_stack),
|
|
THREAD_PRIORITY_MAIN - 1, 0, _wait_recv, NULL, "recv thread");
|
|
#endif
|
|
|
|
puts("All up, running the shell now");
|
|
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
|
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
|
|
}
|