tests/driver_sx127x: uncrustify code
This commit is contained in:
parent
39094d0833
commit
47bf32ed02
@ -67,6 +67,7 @@ int lora_setup_cmd(int argc, char **argv)
|
|||||||
/* Check bandwidth value */
|
/* Check bandwidth value */
|
||||||
int bw = atoi(argv[1]);
|
int bw = atoi(argv[1]);
|
||||||
uint8_t lora_bw;
|
uint8_t lora_bw;
|
||||||
|
|
||||||
switch (bw) {
|
switch (bw) {
|
||||||
case 125:
|
case 125:
|
||||||
puts("setup: setting 125KHz bandwidth");
|
puts("setup: setting 125KHz bandwidth");
|
||||||
@ -91,6 +92,7 @@ int lora_setup_cmd(int argc, char **argv)
|
|||||||
|
|
||||||
/* Check spreading factor value */
|
/* Check spreading factor value */
|
||||||
uint8_t lora_sf = atoi(argv[2]);
|
uint8_t lora_sf = atoi(argv[2]);
|
||||||
|
|
||||||
if (lora_sf < 7 || lora_sf > 12) {
|
if (lora_sf < 7 || lora_sf > 12) {
|
||||||
puts("[Error] setup: invalid spreading factor value given");
|
puts("[Error] setup: invalid spreading factor value given");
|
||||||
return -1;
|
return -1;
|
||||||
@ -98,6 +100,7 @@ int lora_setup_cmd(int argc, char **argv)
|
|||||||
|
|
||||||
/* Check coding rate value */
|
/* Check coding rate value */
|
||||||
int cr = atoi(argv[3]);
|
int cr = atoi(argv[3]);
|
||||||
|
|
||||||
if (cr < 5 || cr > 8) {
|
if (cr < 5 || cr > 8) {
|
||||||
puts("[Error ]setup: invalid coding rate value given");
|
puts("[Error ]setup: invalid coding rate value given");
|
||||||
return -1;
|
return -1;
|
||||||
@ -106,6 +109,7 @@ int lora_setup_cmd(int argc, char **argv)
|
|||||||
|
|
||||||
/* Configure radio device */
|
/* Configure radio device */
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
|
||||||
netdev->driver->set(netdev, NETOPT_BANDWIDTH,
|
netdev->driver->set(netdev, NETOPT_BANDWIDTH,
|
||||||
&lora_bw, sizeof(lora_bw));
|
&lora_bw, sizeof(lora_bw));
|
||||||
netdev->driver->set(netdev, NETOPT_SPREADING_FACTOR,
|
netdev->driver->set(netdev, NETOPT_SPREADING_FACTOR,
|
||||||
@ -125,6 +129,7 @@ int random_cmd(int argc, char **argv)
|
|||||||
|
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
uint32_t rand;
|
uint32_t rand;
|
||||||
|
|
||||||
netdev->driver->get(netdev, NETOPT_RANDOM, &rand, sizeof(rand));
|
netdev->driver->get(netdev, NETOPT_RANDOM, &rand, sizeof(rand));
|
||||||
printf("random: number from sx127x: %u\n",
|
printf("random: number from sx127x: %u\n",
|
||||||
(unsigned int)rand);
|
(unsigned int)rand);
|
||||||
@ -245,6 +250,7 @@ int send_cmd(int argc, char **argv)
|
|||||||
};
|
};
|
||||||
|
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
|
||||||
if (netdev->driver->send(netdev, &iolist) == -ENOTSUP) {
|
if (netdev->driver->send(netdev, &iolist) == -ENOTSUP) {
|
||||||
puts("Cannot send: radio is still transmitting");
|
puts("Cannot send: radio is still transmitting");
|
||||||
}
|
}
|
||||||
@ -260,12 +266,15 @@ int listen_cmd(int argc, char **argv)
|
|||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
/* Switch to continuous listen mode */
|
/* Switch to continuous listen mode */
|
||||||
const netopt_enable_t single = false;
|
const netopt_enable_t single = false;
|
||||||
|
|
||||||
netdev->driver->set(netdev, NETOPT_SINGLE_RECEIVE, &single, sizeof(single));
|
netdev->driver->set(netdev, NETOPT_SINGLE_RECEIVE, &single, sizeof(single));
|
||||||
const uint32_t timeout = 0;
|
const uint32_t timeout = 0;
|
||||||
|
|
||||||
netdev->driver->set(netdev, NETOPT_RX_TIMEOUT, &timeout, sizeof(timeout));
|
netdev->driver->set(netdev, NETOPT_RX_TIMEOUT, &timeout, sizeof(timeout));
|
||||||
|
|
||||||
/* Switch to RX state */
|
/* Switch to RX state */
|
||||||
netopt_state_t state = NETOPT_STATE_RX;
|
netopt_state_t state = NETOPT_STATE_RX;
|
||||||
|
|
||||||
netdev->driver->set(netdev, NETOPT_STATE, &state, sizeof(state));
|
netdev->driver->set(netdev, NETOPT_STATE, &state, sizeof(state));
|
||||||
|
|
||||||
printf("Listen mode set\n");
|
printf("Listen mode set\n");
|
||||||
@ -282,6 +291,7 @@ int syncword_cmd(int argc, char **argv)
|
|||||||
|
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
uint8_t syncword;
|
uint8_t syncword;
|
||||||
|
|
||||||
if (strstr(argv[1], "get") != NULL) {
|
if (strstr(argv[1], "get") != NULL) {
|
||||||
netdev->driver->get(netdev, NETOPT_SYNCWORD, &syncword,
|
netdev->driver->get(netdev, NETOPT_SYNCWORD, &syncword,
|
||||||
sizeof(syncword));
|
sizeof(syncword));
|
||||||
@ -315,6 +325,7 @@ int channel_cmd(int argc, char **argv)
|
|||||||
|
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
uint32_t chan;
|
uint32_t chan;
|
||||||
|
|
||||||
if (strstr(argv[1], "get") != NULL) {
|
if (strstr(argv[1], "get") != NULL) {
|
||||||
netdev->driver->get(netdev, NETOPT_CHANNEL_FREQUENCY, &chan,
|
netdev->driver->get(netdev, NETOPT_CHANNEL_FREQUENCY, &chan,
|
||||||
sizeof(chan));
|
sizeof(chan));
|
||||||
@ -349,6 +360,7 @@ int rx_timeout_cmd(int argc, char **argv)
|
|||||||
|
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
uint16_t rx_timeout;
|
uint16_t rx_timeout;
|
||||||
|
|
||||||
if (strstr(argv[1], "set") != NULL) {
|
if (strstr(argv[1], "set") != NULL) {
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
puts("usage: rx_timeout set <rx_timeout>");
|
puts("usage: rx_timeout set <rx_timeout>");
|
||||||
@ -372,15 +384,18 @@ int reset_cmd(int argc, char **argv)
|
|||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
|
||||||
puts("resetting sx127x...");
|
puts("resetting sx127x...");
|
||||||
netopt_state_t state = NETOPT_STATE_RESET;
|
netopt_state_t state = NETOPT_STATE_RESET;
|
||||||
|
|
||||||
netdev->driver->set(netdev, NETOPT_STATE, &state, sizeof(netopt_state_t));
|
netdev->driver->set(netdev, NETOPT_STATE, &state, sizeof(netopt_state_t));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _set_opt(netdev_t *netdev, netopt_t opt, bool val, char* str_help)
|
static void _set_opt(netdev_t *netdev, netopt_t opt, bool val, char *str_help)
|
||||||
{
|
{
|
||||||
netopt_enable_t en = val ? NETOPT_ENABLE : NETOPT_DISABLE;
|
netopt_enable_t en = val ? NETOPT_ENABLE : NETOPT_DISABLE;
|
||||||
|
|
||||||
netdev->driver->set(netdev, opt, &en, sizeof(en));
|
netdev->driver->set(netdev, opt, &en, sizeof(en));
|
||||||
printf("Successfully ");
|
printf("Successfully ");
|
||||||
if (val) {
|
if (val) {
|
||||||
@ -395,12 +410,14 @@ static void _set_opt(netdev_t *netdev, netopt_t opt, bool val, char* str_help)
|
|||||||
int crc_cmd(int argc, char **argv)
|
int crc_cmd(int argc, char **argv)
|
||||||
{
|
{
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
|
||||||
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||||
printf("usage: %s set <1|0>\n", argv[0]);
|
printf("usage: %s set <1|0>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tmp = atoi(argv[2]);
|
int tmp = atoi(argv[2]);
|
||||||
|
|
||||||
_set_opt(netdev, NETOPT_INTEGRITY_CHECK, tmp, "CRC check");
|
_set_opt(netdev, NETOPT_INTEGRITY_CHECK, tmp, "CRC check");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -408,12 +425,14 @@ int crc_cmd(int argc, char **argv)
|
|||||||
int implicit_cmd(int argc, char **argv)
|
int implicit_cmd(int argc, char **argv)
|
||||||
{
|
{
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
|
||||||
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||||
printf("usage: %s set <1|0>\n", argv[0]);
|
printf("usage: %s set <1|0>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tmp = atoi(argv[2]);
|
int tmp = atoi(argv[2]);
|
||||||
|
|
||||||
_set_opt(netdev, NETOPT_FIXED_HEADER, tmp, "implicit header");
|
_set_opt(netdev, NETOPT_FIXED_HEADER, tmp, "implicit header");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -421,12 +440,14 @@ int implicit_cmd(int argc, char **argv)
|
|||||||
int payload_cmd(int argc, char **argv)
|
int payload_cmd(int argc, char **argv)
|
||||||
{
|
{
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
|
||||||
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
if (argc < 3 || strcmp(argv[1], "set") != 0) {
|
||||||
printf("usage: %s set <payload length>\n", argv[0]);
|
printf("usage: %s set <payload length>\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t tmp = atoi(argv[2]);
|
uint16_t tmp = atoi(argv[2]);
|
||||||
|
|
||||||
netdev->driver->set(netdev, NETOPT_PDU_SIZE, &tmp, sizeof(tmp));
|
netdev->driver->set(netdev, NETOPT_PDU_SIZE, &tmp, sizeof(tmp));
|
||||||
printf("Successfully set payload to %i\n", tmp);
|
printf("Successfully set payload to %i\n", tmp);
|
||||||
return 0;
|
return 0;
|
||||||
@ -444,7 +465,7 @@ static const shell_command_t shell_commands[] = {
|
|||||||
{ "register", "Get/Set value(s) of registers of sx127x", register_cmd },
|
{ "register", "Get/Set value(s) of registers of sx127x", register_cmd },
|
||||||
{ "send", "Send raw payload string", send_cmd },
|
{ "send", "Send raw payload string", send_cmd },
|
||||||
{ "listen", "Start raw payload listener", listen_cmd },
|
{ "listen", "Start raw payload listener", listen_cmd },
|
||||||
{ "reset", "Reset the sx127x device", reset_cmd},
|
{ "reset", "Reset the sx127x device", reset_cmd },
|
||||||
{ NULL, NULL, NULL }
|
{ NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -502,6 +523,7 @@ void *_recv_thread(void *arg)
|
|||||||
(void)arg;
|
(void)arg;
|
||||||
|
|
||||||
static msg_t _msg_q[SX127X_LORA_MSG_QUEUE];
|
static msg_t _msg_q[SX127X_LORA_MSG_QUEUE];
|
||||||
|
|
||||||
msg_init_queue(_msg_q, SX127X_LORA_MSG_QUEUE);
|
msg_init_queue(_msg_q, SX127X_LORA_MSG_QUEUE);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -521,6 +543,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
sx127x.params = sx127x_params[0];
|
sx127x.params = sx127x_params[0];
|
||||||
netdev_t *netdev = (netdev_t *)&sx127x;
|
netdev_t *netdev = (netdev_t *)&sx127x;
|
||||||
|
|
||||||
netdev->driver = &sx127x_driver;
|
netdev->driver = &sx127x_driver;
|
||||||
|
|
||||||
if (netdev->driver->init(netdev) < 0) {
|
if (netdev->driver->init(netdev) < 0) {
|
||||||
@ -542,6 +565,7 @@ int main(void)
|
|||||||
/* start the shell */
|
/* start the shell */
|
||||||
puts("Initialization successful - starting the shell now");
|
puts("Initialization successful - starting the shell now");
|
||||||
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
||||||
|
|
||||||
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user