Merge pull request #14509 from jia200x/pr/lora_implicit_mode
sx127x: add support for implicit header mode
This commit is contained in:
commit
224e2c977d
@ -455,6 +455,11 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *val, size_t len)
|
|||||||
sx127x_set_fixed_header_len_mode(dev, *((const netopt_enable_t*) val) ? true : false);
|
sx127x_set_fixed_header_len_mode(dev, *((const netopt_enable_t*) val) ? true : false);
|
||||||
return sizeof(netopt_enable_t);
|
return sizeof(netopt_enable_t);
|
||||||
|
|
||||||
|
case NETOPT_PDU_SIZE:
|
||||||
|
assert(len <= sizeof(uint16_t));
|
||||||
|
sx127x_set_payload_length(dev, *((const uint16_t*) val));
|
||||||
|
return sizeof(uint16_t);
|
||||||
|
|
||||||
case NETOPT_PREAMBLE_LENGTH:
|
case NETOPT_PREAMBLE_LENGTH:
|
||||||
assert(len <= sizeof(uint16_t));
|
assert(len <= sizeof(uint16_t));
|
||||||
sx127x_set_preamble_length(dev, *((const uint16_t*) val));
|
sx127x_set_preamble_length(dev, *((const uint16_t*) val));
|
||||||
|
|||||||
@ -186,6 +186,22 @@ typedef enum {
|
|||||||
* @brief (uint16_t) maximum protocol data unit
|
* @brief (uint16_t) maximum protocol data unit
|
||||||
*/
|
*/
|
||||||
NETOPT_MAX_PDU_SIZE,
|
NETOPT_MAX_PDU_SIZE,
|
||||||
|
/**
|
||||||
|
* @brief (uint16_t) protocol data unit size
|
||||||
|
*
|
||||||
|
* When set, fixes the number of bytes to be received. This is required for
|
||||||
|
* MAC layers with implicit header mode (no packet length information in
|
||||||
|
* PDDU) and predictable packet length (e.g LoRaWAN beacons). The device
|
||||||
|
* driver implementation should attempt to read exactly the expected number
|
||||||
|
* of bytes (possibly filling it up with garbage data if the payload is
|
||||||
|
* smaller).
|
||||||
|
*
|
||||||
|
* When get, returns the number of expected bytes for the next reception.
|
||||||
|
*
|
||||||
|
* In some MAC layers it will only be effective if used in conjunction with
|
||||||
|
* @ref NETOPT_FIXED_HEADER
|
||||||
|
*/
|
||||||
|
NETOPT_PDU_SIZE,
|
||||||
/**
|
/**
|
||||||
* @brief (@ref netopt_enable_t) frame preloading
|
* @brief (@ref netopt_enable_t) frame preloading
|
||||||
*
|
*
|
||||||
|
|||||||
@ -41,6 +41,7 @@ static const char *_netopt_strmap[] = {
|
|||||||
[NETOPT_IPV6_FORWARDING] = "NETOPT_IPV6_FORWARDING",
|
[NETOPT_IPV6_FORWARDING] = "NETOPT_IPV6_FORWARDING",
|
||||||
[NETOPT_IPV6_SND_RTR_ADV] = "NETOPT_IPV6_SND_RTR_ADV",
|
[NETOPT_IPV6_SND_RTR_ADV] = "NETOPT_IPV6_SND_RTR_ADV",
|
||||||
[NETOPT_TX_POWER] = "NETOPT_TX_POWER",
|
[NETOPT_TX_POWER] = "NETOPT_TX_POWER",
|
||||||
|
[NETOPT_PDU_SIZE] = "NETOPT_PDU_SIZE",
|
||||||
[NETOPT_MAX_PDU_SIZE] = "NETOPT_MAX_PDU_SIZE",
|
[NETOPT_MAX_PDU_SIZE] = "NETOPT_MAX_PDU_SIZE",
|
||||||
[NETOPT_PRELOADING] = "NETOPT_PRELOADING",
|
[NETOPT_PRELOADING] = "NETOPT_PRELOADING",
|
||||||
[NETOPT_PROMISCUOUSMODE] = "NETOPT_PROMISCUOUSMODE",
|
[NETOPT_PROMISCUOUSMODE] = "NETOPT_PROMISCUOUSMODE",
|
||||||
|
|||||||
@ -378,8 +378,65 @@ int reset_cmd(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _set_opt(netdev_t *netdev, netopt_t opt, bool val, char* str_help)
|
||||||
|
{
|
||||||
|
netopt_enable_t en = val ? NETOPT_ENABLE : NETOPT_DISABLE;
|
||||||
|
netdev->driver->set(netdev, opt, &en, sizeof(en));
|
||||||
|
printf("Successfully ");
|
||||||
|
if (val) {
|
||||||
|
printf("enabled ");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("disabled ");
|
||||||
|
}
|
||||||
|
printf("%s\n", str_help);
|
||||||
|
}
|
||||||
|
|
||||||
|
int crc_cmd(int argc, char **argv)
|
||||||
|
{
|
||||||
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||||
|
printf("usage: %s set <1|0>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tmp = atoi(argv[2]);
|
||||||
|
_set_opt(netdev, NETOPT_INTEGRITY_CHECK, tmp, "CRC check");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int implicit_cmd(int argc, char **argv)
|
||||||
|
{
|
||||||
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||||
|
printf("usage: %s set <1|0>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tmp = atoi(argv[2]);
|
||||||
|
_set_opt(netdev, NETOPT_FIXED_HEADER, tmp, "implicit header");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int payload_cmd(int argc, char **argv)
|
||||||
|
{
|
||||||
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||||
|
printf("usage: %s set <payload length>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t tmp = atoi(argv[2]);
|
||||||
|
netdev->driver->set(netdev, NETOPT_PDU_SIZE, &tmp, sizeof(tmp));
|
||||||
|
printf("Successfully set payload to %i\n", tmp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const shell_command_t shell_commands[] = {
|
static const shell_command_t shell_commands[] = {
|
||||||
{ "setup", "Initialize LoRa modulation settings", lora_setup_cmd },
|
{ "setup", "Initialize LoRa modulation settings", lora_setup_cmd },
|
||||||
|
{ "implicit", "Enable implicit header", implicit_cmd },
|
||||||
|
{ "crc", "Enable CRC", crc_cmd },
|
||||||
|
{ "payload", "Set payload length (implicit header)", payload_cmd },
|
||||||
{ "random", "Get random number from sx127x", random_cmd },
|
{ "random", "Get random number from sx127x", random_cmd },
|
||||||
{ "syncword", "Get/Set the syncword", syncword_cmd },
|
{ "syncword", "Get/Set the syncword", syncword_cmd },
|
||||||
{ "rx_timeout", "Set the RX timeout", rx_timeout_cmd },
|
{ "rx_timeout", "Set the RX timeout", rx_timeout_cmd },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user