mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/sx127x: several fixes
- fix style - remove global netdev
This commit is contained in:
parent
7365e41337
commit
0a8590c78b
@ -49,7 +49,6 @@ static kernel_pid_t _recv_pid;
|
||||
|
||||
static char message[32];
|
||||
static sx127x_t sx127x;
|
||||
static netdev_t *netdev;
|
||||
|
||||
int lora_setup_cmd(int argc, char **argv) {
|
||||
|
||||
@ -120,6 +119,7 @@ int random_cmd(int argc, char **argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
netdev_t *netdev = (netdev_t*) &sx127x;
|
||||
printf("random: number from sx127x: %u\n",
|
||||
(unsigned int) sx127x_random((sx127x_t*) netdev));
|
||||
|
||||
@ -141,6 +141,7 @@ int register_cmd(int argc, char **argv)
|
||||
puts("usage: register get <all | allinline | regnum>");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp(argv[2], "all") == 0) {
|
||||
puts("- listing all registers -");
|
||||
uint8_t reg = 0, data = 0;
|
||||
@ -157,7 +158,8 @@ int register_cmd(int argc, char **argv)
|
||||
}
|
||||
puts("-done-");
|
||||
return 0;
|
||||
} else if (strcmp(argv[2], "allinline") == 0) {
|
||||
}
|
||||
else if (strcmp(argv[2], "allinline") == 0) {
|
||||
puts("- listing all registers in one line -");
|
||||
/* Listing registers map */
|
||||
for (uint16_t reg = 0; reg < 256; reg++) {
|
||||
@ -165,24 +167,29 @@ int register_cmd(int argc, char **argv)
|
||||
}
|
||||
puts("- done -");
|
||||
return 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
long int num = 0;
|
||||
/* Register number in hex */
|
||||
if (strstr(argv[2], "0x") != NULL) {
|
||||
num = strtol(argv[2], NULL, 16);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
num = atoi(argv[2]);
|
||||
}
|
||||
|
||||
if (num >= 0 && num <= 255) {
|
||||
printf("[regs] 0x%02X = 0x%02X\n",
|
||||
(uint8_t) num,
|
||||
sx127x_reg_read(&sx127x, (uint8_t) num));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
puts("regs: invalid register number specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else if (strstr(argv[1], "set") != NULL) {
|
||||
}
|
||||
else if (strstr(argv[1], "set") != NULL) {
|
||||
if (argc < 4) {
|
||||
puts("usage: register set <regnum> <value>");
|
||||
return -1;
|
||||
@ -193,14 +200,16 @@ int register_cmd(int argc, char **argv)
|
||||
/* Register number in hex */
|
||||
if (strstr(argv[2], "0x") != NULL) {
|
||||
num = strtol(argv[2], NULL, 16);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
num = atoi(argv[2]);
|
||||
}
|
||||
|
||||
/* Register value in hex */
|
||||
if (strstr(argv[3], "0x") != NULL) {
|
||||
val = strtol(argv[3], NULL, 16);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
val = atoi(argv[3]);
|
||||
}
|
||||
|
||||
@ -229,6 +238,7 @@ int send_cmd(int argc, char **argv)
|
||||
.iol_len = (strlen(argv[1]) + 1)
|
||||
};
|
||||
|
||||
netdev_t *netdev = (netdev_t*) &sx127x;
|
||||
if (netdev->driver->send(netdev, &iolist) == -ENOTSUP) {
|
||||
puts("Cannot send: radio is still transmitting");
|
||||
}
|
||||
@ -241,6 +251,7 @@ int listen_cmd(int argc, char **argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
netdev_t *netdev = (netdev_t*) &sx127x;
|
||||
/* Switch to continuous listen mode */
|
||||
const netopt_enable_t single = false;
|
||||
netdev->driver->set(netdev, NETOPT_SINGLE_RECEIVE, &single, sizeof(single));
|
||||
@ -263,6 +274,7 @@ int channel_cmd(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
netdev_t *netdev = (netdev_t*) &sx127x;
|
||||
uint32_t chan;
|
||||
if (strstr(argv[1], "get") != NULL) {
|
||||
netdev->driver->get(netdev, NETOPT_CHANNEL_FREQUENCY, &chan, sizeof(chan));
|
||||
@ -321,15 +333,19 @@ static void _event_cb(netdev_t *dev, netdev_event_t event)
|
||||
packet_info.rssi, (int)packet_info.snr,
|
||||
sx127x_get_time_on_air((const sx127x_t*)dev, len));
|
||||
break;
|
||||
|
||||
case NETDEV_EVENT_TX_COMPLETE:
|
||||
sx127x_set_sleep(&sx127x);
|
||||
puts("Transmission completed");
|
||||
break;
|
||||
|
||||
case NETDEV_EVENT_CAD_DONE:
|
||||
break;
|
||||
|
||||
case NETDEV_EVENT_TX_TIMEOUT:
|
||||
sx127x_set_sleep(&sx127x);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Unexpected netdev event received: %d\n", event);
|
||||
break;
|
||||
@ -360,7 +376,7 @@ void *_recv_thread(void *arg)
|
||||
int main(void)
|
||||
{
|
||||
memcpy(&sx127x.params, sx127x_params, sizeof(sx127x_params));
|
||||
netdev = (netdev_t*) &sx127x;
|
||||
netdev_t *netdev = (netdev_t*) &sx127x;
|
||||
netdev->driver = &sx127x_driver;
|
||||
netdev->driver->init(netdev);
|
||||
netdev->event_callback = _event_cb;
|
||||
|
Loading…
Reference in New Issue
Block a user