Date:2011-06-07 00:33:11 (9 years 2 months ago)
Author:Werner Almesberger
Commit:7a2e09187f7f3e41dfa6f2d9ffdb8bf2af56b9b6
Message:atrf-gpio: option -c to cycle through the pattern sequence with pass/fail input

- atrf-gpio.c: added section titles
- atrf-gpio.c (DEFAULT_DELAY_MS, reg_op, usage): the "delay" command
now accept an optional delay argument
- atrf-gpio.c (old_term, restore_term, raw, pass_fail): make standard
input non-blocking and raw, and poll for pass/fail input
- atrf-gpio.c (usage, main): new option -c to cycle through the
pattern sequence, waiting for pass/fail input
Files: tools/atrf-gpio/atrf-gpio.c (9 diffs)

Change Details

tools/atrf-gpio/atrf-gpio.c
1515#include <stdio.h>
1616#include <unistd.h>
1717#include <string.h>
18#include <termios.h>
19#include <fcntl.h>
20#include <errno.h>
1821
1922#include "at86rf230.h"
2023#include "atrf.h"
...... 
2225#include "atrf-gpio.h"
2326
2427
28#define DEFAULT_DELAY_MS 10
29
30
31/* ----- Board-specific drivers -------------------------------------------- */
32
33
2534static void atben(struct atrf_dsc *dsc, const char *pattern, const char *next)
2635{
2736#ifdef HAVE_ATBEN
...... 
4453}
4554
4655
56/* ----- Commands ---------------------------------------------------------- */
57
58
4759static void bad_reg_op(const char *arg)
4860{
4961    fprintf(stderr, "invalid operation \"%s\"\n", arg);
...... 
6072
6173    if (!strcmp(arg, "delay")) {
6274        if (doit)
63            usleep(10000);
75            usleep(DEFAULT_DELAY_MS*1000);
76        return 1;
77    }
78    if (!strncmp(arg, "delay=", 6)) {
79        value = strtoul(arg+6, &end, 0);
80        if (!value || *end)
81            bad_reg_op(arg);
82        if (doit)
83            usleep(value*1000);
6484        return 1;
6585    }
6686    if (!strcmp(arg, "frame")) {
...... 
138158}
139159
140160
161/* ----- Pass/Fail/Quit input ---------------------------------------------- */
162
163
164static struct termios old_term;
165
166
167static void restore_term(void)
168{
169    if (tcsetattr(0, TCSAFLUSH, &old_term) < 0)
170        perror("tcsetattr");
171}
172
173
174static void raw(void)
175{
176    struct termios term;
177
178    if (tcgetattr(0, &old_term) < 0) {
179        perror("tcgetattr");
180        exit(1);
181    }
182    term = old_term;
183    cfmakeraw(&term);
184    if (tcsetattr(0, TCSAFLUSH, &term) < 0) {
185        perror("tcsetattr");
186        exit(1);
187    }
188    atexit(restore_term);
189    if (fcntl(0, F_SETFL, O_NONBLOCK) < 0) {
190        perror("fcntl");
191        exit(1);
192    }
193}
194
195
196static void pass_fail(void)
197{
198    ssize_t got;
199    char ch;
200
201    got = read(0, &ch, 1);
202    if (got < 0) {
203        if (errno == EAGAIN)
204            return;
205        perror("read");
206        exit(1);
207    }
208    switch (ch) {
209    case 'P':
210    case 'p':
211        exit(0);
212    case 'F':
213    case 'f':
214    case 'Q':
215    case 'q':
216    case 3: /* Ctrl-C */
217        exit(1);
218    default:
219        break;
220    }
221}
222
223
224/* ----- Command line processing and main loop ----------------------------- */
225
226
141227static void usage(const char *name)
142228{
143229    fprintf(stderr,
144"usage: %s [-d driver[:arg]] command|pattern ...\n"
230"usage: %s [-c] [-d driver[:arg]] command|pattern ...\n"
231" -c cycle, waiting for Pass/Fail/Quit input\n"
145232" -d driver[:arg] use the specified driver (default: %s)\n\n"
146233" command is one of:\n"
147234" reg=value set transceiver register\n"
...... 
149236" read transceiver register and (optionally) verify value\n"
150237" addr!value write one byte to SRAM\n"
151238" addr/value read and verify one byte from SRAM\n"
152" delay wait 10 ms\n"
239" delay[=ms] wait the specified number of milliseconds (default: %d ms)\n"
153240" frame write a one-byte frame to the frame buffer\n"
154241" reset reset the transceiver\n"
155242" slp_tr pulse SLP_TR\n"
...... 
160247" l/o = no pull-up, expect to read 0 h = no pull-up, expect to read 1\n"
161248" Z = pull up, don't read z = no pull-up, don't read\n"
162249" x = don't care . = separator\n"
163    , name, atrf_default_driver_name());
250    , name, atrf_default_driver_name(), DEFAULT_DELAY_MS);
164251    exit(1);
165252}
166253
...... 
183270{
184271    const char *driver = NULL;
185272    struct atrf_dsc *dsc;
273    int cycle = 0;
186274    int trx_off = 1;
187275    int c, i;
188276    const char *s;
189277
190    while ((c = getopt(argc, argv, "d:p")) != EOF)
278    while ((c = getopt(argc, argv, "cd:p")) != EOF)
191279        switch (c) {
280        case 'c':
281            cycle = 1;
282            break;
192283        case 'd':
193284            driver = optarg;
194285            break;
...... 
224315            != TRX_STATUS_TRX_OFF);
225316    }
226317
227    for (i = optind; i != argc; i++) {
228        if (*argv[i] == '#')
229            continue;
230        if (reg_op(dsc, argv[i], 1))
231            continue;
232        if (atrf_usb_handle(dsc))
233            atusb(dsc, argv[i], argv[i+1]);
318    if (cycle)
319        raw();
320
321    while (1) {
322        for (i = optind; i != argc; i++) {
323            if (*argv[i] == '#')
324                continue;
325            if (reg_op(dsc, argv[i], 1))
326                continue;
327            if (atrf_usb_handle(dsc))
328                atusb(dsc, argv[i], argv[i+1]);
329            else
330                atben(dsc, argv[i], argv[i+1]);
331        }
332        if (cycle)
333            pass_fail();
234334        else
235            atben(dsc, argv[i], argv[i+1]);
335            break;
236336    }
237337
238338// atrf_close(dsc);

Archive Download the corresponding diff file



interactive