tests/driver_sx127x: add packet commands

This commit is contained in:
Jose Alamos 2020-07-14 12:39:16 +02:00
parent 84eb2dc30c
commit 5affd72f71

View File

@ -379,8 +379,65 @@ int reset_cmd(int argc, char **argv)
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[] = {
{ "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 },
{ "syncword", "Get/Set the syncword", syncword_cmd },
{ "rx_timeout", "Set the RX timeout", rx_timeout_cmd },