From 398cf6648f905a6bcc569cd5bb0fbde2ff266151 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Tue, 25 Jun 2019 16:40:33 +0200 Subject: [PATCH] tests/sx127x: add handlers for new NETOPTs --- tests/driver_sx127x/main.c | 68 +++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/tests/driver_sx127x/main.c b/tests/driver_sx127x/main.c index ad9599322e..025b8f1f93 100644 --- a/tests/driver_sx127x/main.c +++ b/tests/driver_sx127x/main.c @@ -41,6 +41,8 @@ #include "sx127x_params.h" #include "sx127x_netdev.h" +#include "fmt.h" + #define SX127X_LORA_MSG_QUEUE (16U) #define SX127X_STACKSIZE (THREAD_STACKSIZE_DEFAULT) @@ -123,8 +125,10 @@ int random_cmd(int argc, char **argv) (void)argv; netdev_t *netdev = (netdev_t *)&sx127x; + uint32_t rand; + netdev->driver->get(netdev, NETOPT_RANDOM, &rand, sizeof(rand)); printf("random: number from sx127x: %u\n", - (unsigned int)sx127x_random((sx127x_t *)netdev)); + (unsigned int)rand); /* reinit the transceiver to default values */ sx127x_init_radio_settings((sx127x_t *)netdev); @@ -270,6 +274,39 @@ int listen_cmd(int argc, char **argv) return 0; } +int syncword_cmd(int argc, char **argv) +{ + if (argc < 2) { + puts("usage: syncword "); + return -1; + } + + netdev_t *netdev = (netdev_t *)&sx127x; + uint8_t syncword; + if (strstr(argv[1], "get") != NULL) { + netdev->driver->get(netdev, NETOPT_SYNCWORD, &syncword, + sizeof(syncword)); + printf("Syncword: 0x%02x\n", syncword); + return 0; + } + + if (strstr(argv[1], "set") != NULL) { + if (argc < 3) { + puts("usage: syncword set "); + return -1; + } + syncword = fmt_hex_byte(argv[2]); + netdev->driver->set(netdev, NETOPT_SYNCWORD, &syncword, + sizeof(syncword)); + printf("Syncword set to %02x\n", syncword); + } + else { + puts("usage: syncword "); + return -1; + } + + return 0; +} int channel_cmd(int argc, char **argv) { if (argc < 2) { @@ -304,9 +341,38 @@ int channel_cmd(int argc, char **argv) return 0; } +int rx_timeout_cmd(int argc, char **argv) +{ + if (argc < 2) { + puts("usage: channel "); + return -1; + } + + netdev_t *netdev = (netdev_t *)&sx127x; + uint16_t rx_timeout; + if (strstr(argv[1], "set") != NULL) { + if (argc < 3) { + puts("usage: rx_timeout set "); + return -1; + } + rx_timeout = atoi(argv[2]); + netdev->driver->set(netdev, NETOPT_RX_SYMBOL_TIMEOUT, &rx_timeout, + sizeof(rx_timeout)); + printf("rx_timeout set to %i\n", rx_timeout); + } + else { + puts("usage: rx_timeout set"); + return -1; + } + + return 0; +} + static const shell_command_t shell_commands[] = { { "setup", "Initialize LoRa modulation settings", lora_setup_cmd }, { "random", "Get random number from sx127x", random_cmd }, + { "syncword", "Get/Set the syncword", syncword_cmd }, + { "rx_timeout", "Set the RX timeout", rx_timeout_cmd }, { "channel", "Get/Set channel frequency (in Hz)", channel_cmd }, { "register", "Get/Set value(s) of registers of sx127x", register_cmd }, { "send", "Send raw payload string", send_cmd },