Date:2010-11-08 20:22:39 (9 years 1 month ago)
Author:Werner Almesberger
Commit:a7a94b85cd782d9e56cbbe3f44db29b6f4e0bdbe
Message:Use getopt in atspi-rssi.c

- atspi-rssi/atspi-rssi.c (main): use getopt
- atspi-rssi/atspi-rssi.c (usage, main): introduce option -n to select
number-of-sweeps mode (default)
Files: tools/atspi-rssi/atspi-rssi.c (3 diffs)

Change Details

tools/atspi-rssi/atspi-rssi.c
1313
1414#include <stdlib.h>
1515#include <stdio.h>
16#include <unistd.h>
1617#include <signal.h>
1718#include <sys/time.h>
1819
...... 
3536        /* 150 us, according to AVR2001 section 3.5 */
3637        wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20);
3738
38        /*
39         * No need to explicitly wait for the PPL lock - going USB-SPI
40         * is pretty slow, leaving the transceiver plenty of time.
41         */
4239        gettimeofday(&t, NULL);
4340        rssi = atspi_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK;
4441        t.tv_sec -= t0.tv_sec;
...... 
6057
6158static void usage(const char *name)
6259{
63    fprintf(stderr, "usage: %s sweeps \n", name);
60    fprintf(stderr,
61"usage: %s [-n] sweeps\n", name);
6462    exit(1);
6563}
6664
6765
68int main(int argc, const char **argv)
66int main(int argc, char **argv)
6967{
7068    struct atspi_dsc *dsc;
7169    unsigned long sweeps, i;
7270    char *end;
73
74    if (argc != 2)
75        usage(*argv);
76    sweeps = strtoul(argv[1], &end, 0);
77    if (*end)
71    int c;
72
73    while ((c = getopt(argc, argv, "n")) != EOF)
74        switch (c) {
75        case 'n':
76            break;
77        default:
78            usage(*argv);
79        }
80
81    switch (argc-optind) {
82    case 1:
83        sweeps = strtoul(argv[optind], &end, 0);
84        if (*end)
85            usage(*argv);
86        break;
87    default:
7888        usage(*argv);
89    }
7990
8091    signal(SIGINT, die);
8192

Archive Download the corresponding diff file



interactive