From b24e3d4ac73841b096b1addabdcf7e33c4ec39e1 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 12 Feb 2013 10:47:12 -0300 Subject: [PATCH] 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. --- tools/atrf-txrx/atrf-txrx.c | 39 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/tools/atrf-txrx/atrf-txrx.c b/tools/atrf-txrx/atrf-txrx.c index 774e116..1f1d838 100644 --- a/tools/atrf-txrx/atrf-txrx.c +++ b/tools/atrf-txrx/atrf-txrx.c @@ -1,8 +1,8 @@ /* * atrf-txrx/atrf-txrx.c - ben-wpan AT86RF230 TX/RX * - * Written 2010-2011 by Werner Almesberger - * Copyright 2010-2011 Werner Almesberger + * Written 2010-2011, 2013 by Werner Almesberger + * Copyright 2010-2011, 2013 Werner Almesberger * * 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 @@ -62,6 +62,14 @@ enum rx_res { rx_timeout, }; +enum mode { + mode_msg, + mode_hmac, + mode_per, + mode_ping, + mode_cont_tx, +}; + 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) { - enum { - mode_msg, - mode_hmac, - mode_per, - mode_ping, - mode_cont_tx, - } mode = mode_msg; + enum mode mode = mode_msg; const char *driver = NULL; int channel = DEFAULT_CHANNEL; double power = DEFAULT_POWER; @@ -547,7 +560,7 @@ int main(int argc, char *const *argv) usage(*argv); break; case 'H': - mode = mode_hmac; + set_mode(&mode, mode_hmac); break; case 'o': pcap_file = optarg; @@ -584,16 +597,16 @@ int main(int argc, char *const *argv) usage(*argv); break; case 'E': - mode = mode_per; + set_mode(&mode, mode_per); pause_s = strtof(optarg, &end); if (*end) usage(*argv); break; case 'P': - mode = mode_ping; + set_mode(&mode, mode_ping); break; case 'T': - mode = mode_cont_tx; + set_mode(&mode, mode_cont_tx); if (!strcmp(optarg, "-2")) cont_tx = CONT_TX_M2M; else if (!strcmp(optarg, "-0.5"))