mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #11736 from jia200x/pr/sx127x_netops
sx127x: add several NETOPT for GNRC LoRaWAN
This commit is contained in:
commit
6c271f6927
@ -351,6 +351,16 @@ static int _get(netdev_t *netdev, netopt_t opt, void *val, size_t max_len)
|
||||
*((int16_t*) val) = (int16_t)sx127x_get_tx_power(dev);
|
||||
return sizeof(int16_t);
|
||||
|
||||
case NETOPT_SYNCWORD:
|
||||
assert(max_len >= sizeof(uint8_t));
|
||||
*((uint8_t*) val) = (uint8_t) sx127x_get_syncword(dev);
|
||||
return sizeof(uint8_t);
|
||||
|
||||
case NETOPT_RANDOM:
|
||||
assert(max_len >= sizeof(uint32_t));
|
||||
*((uint32_t*) val) = (uint32_t) sx127x_random(dev);
|
||||
return sizeof(uint32_t);
|
||||
|
||||
case NETOPT_IQ_INVERT:
|
||||
assert(max_len >= sizeof(uint8_t));
|
||||
*((netopt_enable_t*) val) = sx127x_get_iq_invert(dev) ? NETOPT_ENABLE : NETOPT_DISABLE;
|
||||
@ -450,6 +460,11 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
|
||||
sx127x_set_rx_single(dev, *((const netopt_enable_t*) val) ? true : false);
|
||||
return sizeof(netopt_enable_t);
|
||||
|
||||
case NETOPT_RX_SYMBOL_TIMEOUT:
|
||||
assert(len <= sizeof(uint16_t));
|
||||
sx127x_set_symbol_timeout(dev, *((const uint16_t*) val));
|
||||
return sizeof(uint16_t);
|
||||
|
||||
case NETOPT_RX_TIMEOUT:
|
||||
assert(len <= sizeof(uint32_t));
|
||||
sx127x_set_rx_timeout(dev, *((const uint32_t*) val));
|
||||
@ -480,6 +495,11 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
|
||||
sx127x_set_preamble_length(dev, *((const uint16_t*) val));
|
||||
return sizeof(uint16_t);
|
||||
|
||||
case NETOPT_SYNCWORD:
|
||||
assert(len <= sizeof(uint8_t));
|
||||
sx127x_set_syncword(dev, *((uint8_t*) val));
|
||||
return sizeof(uint8_t);
|
||||
|
||||
case NETOPT_IQ_INVERT:
|
||||
assert(len <= sizeof(netopt_enable_t));
|
||||
sx127x_set_iq_invert(dev, *((const netopt_enable_t*) val) ? true : false);
|
||||
|
@ -645,6 +645,23 @@ typedef enum {
|
||||
*/
|
||||
NETOPT_LORAWAN_MIN_RX_SYMBOL,
|
||||
|
||||
/**
|
||||
* @brief (uint8_t*) phy layer syncword
|
||||
*/
|
||||
NETOPT_SYNCWORD,
|
||||
|
||||
/**
|
||||
* @brief (uint32_t) Get a random value from the device
|
||||
*
|
||||
* Nothing happens when set
|
||||
*/
|
||||
NETOPT_RANDOM,
|
||||
|
||||
/**
|
||||
* @brief (uint8_t) Get or set the number of PHY symbols before assuming there's no data
|
||||
*/
|
||||
NETOPT_RX_SYMBOL_TIMEOUT,
|
||||
|
||||
/* add more options if needed */
|
||||
|
||||
/**
|
||||
|
@ -106,6 +106,9 @@ static const char *_netopt_strmap[] = {
|
||||
[NETOPT_LORAWAN_RX2_FREQ] = "NETOPT_LORAWAN_RX2_FREQ",
|
||||
[NETOPT_LORAWAN_MAX_RX_ERROR] = "NETOPT_LORAWAN_MAX_RX_ERROR",
|
||||
[NETOPT_LORAWAN_MIN_RX_SYMBOL] = "NETOPT_LORAWAN_MIN_RX_SYMBOL",
|
||||
[NETOPT_SYNCWORD] = "NETOPT_SYNCWORD",
|
||||
[NETOPT_RANDOM] = "NETOPT_RANDOM",
|
||||
[NETOPT_RX_SYMBOL_TIMEOUT] = "NETOPT_RX_SYMBOL_TIMEOUT",
|
||||
[NETOPT_NUMOF] = "NETOPT_NUMOF",
|
||||
};
|
||||
|
||||
|
@ -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 <get|set>");
|
||||
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 <syncword>");
|
||||
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 <get|set>");
|
||||
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 <get|set>");
|
||||
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 <rx_timeout>");
|
||||
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 },
|
||||
|
Loading…
Reference in New Issue
Block a user