mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-22 19:47:29 +02:00
tools/atrf-txrx/atrf-txrx.c (main): perform mode changes via function
This allows us to check for duplicate mode settings and allows for future extensions.
This commit is contained in:
parent
1d069a1019
commit
b24e3d4ac7
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* atrf-txrx/atrf-txrx.c - ben-wpan AT86RF230 TX/RX
|
* atrf-txrx/atrf-txrx.c - ben-wpan AT86RF230 TX/RX
|
||||||
*
|
*
|
||||||
* Written 2010-2011 by Werner Almesberger
|
* Written 2010-2011, 2013 by Werner Almesberger
|
||||||
* Copyright 2010-2011 Werner Almesberger
|
* Copyright 2010-2011, 2013 Werner Almesberger
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -62,6 +62,14 @@ enum rx_res {
|
|||||||
rx_timeout,
|
rx_timeout,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum mode {
|
||||||
|
mode_msg,
|
||||||
|
mode_hmac,
|
||||||
|
mode_per,
|
||||||
|
mode_ping,
|
||||||
|
mode_cont_tx,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static volatile int run = 1;
|
static volatile int run = 1;
|
||||||
|
|
||||||
@ -501,15 +509,20 @@ static void usage(const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void set_mode(enum mode *mode, enum mode new)
|
||||||
|
{
|
||||||
|
if (*mode == mode_msg) {
|
||||||
|
*mode = new;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "multiple mode selections\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *const *argv)
|
int main(int argc, char *const *argv)
|
||||||
{
|
{
|
||||||
enum {
|
enum mode mode = mode_msg;
|
||||||
mode_msg,
|
|
||||||
mode_hmac,
|
|
||||||
mode_per,
|
|
||||||
mode_ping,
|
|
||||||
mode_cont_tx,
|
|
||||||
} mode = mode_msg;
|
|
||||||
const char *driver = NULL;
|
const char *driver = NULL;
|
||||||
int channel = DEFAULT_CHANNEL;
|
int channel = DEFAULT_CHANNEL;
|
||||||
double power = DEFAULT_POWER;
|
double power = DEFAULT_POWER;
|
||||||
@ -547,7 +560,7 @@ int main(int argc, char *const *argv)
|
|||||||
usage(*argv);
|
usage(*argv);
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
mode = mode_hmac;
|
set_mode(&mode, mode_hmac);
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
pcap_file = optarg;
|
pcap_file = optarg;
|
||||||
@ -584,16 +597,16 @@ int main(int argc, char *const *argv)
|
|||||||
usage(*argv);
|
usage(*argv);
|
||||||
break;
|
break;
|
||||||
case 'E':
|
case 'E':
|
||||||
mode = mode_per;
|
set_mode(&mode, mode_per);
|
||||||
pause_s = strtof(optarg, &end);
|
pause_s = strtof(optarg, &end);
|
||||||
if (*end)
|
if (*end)
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
mode = mode_ping;
|
set_mode(&mode, mode_ping);
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
mode = mode_cont_tx;
|
set_mode(&mode, mode_cont_tx);
|
||||||
if (!strcmp(optarg, "-2"))
|
if (!strcmp(optarg, "-2"))
|
||||||
cont_tx = CONT_TX_M2M;
|
cont_tx = CONT_TX_M2M;
|
||||||
else if (!strcmp(optarg, "-0.5"))
|
else if (!strcmp(optarg, "-0.5"))
|
||||||
|
Loading…
Reference in New Issue
Block a user