Date:2011-04-14 01:24:50 (8 years 4 months ago)
Author:Werner Almesberger
Commit:c86ce307e22c9ba6e71972622483096ea9c34def
Message:atrf-path: added pass/fail indication (in the GUI, accept the result with P/F)

- atrf-path.c (do_sweeps): return a pass/fail/undecided value
- gui.h (gui), gui.c (gui): return a pass/fail/undecided value
- gui.c (gui): return pass/fail when P or F is pressed; exit
unconditionally if Q is pressed
- atrf-path.c (main): according to the decision of "gui" or "do_sweeps",
print "#PASS", "#FAIL", or nothing
Files: tools/atrf-path/atrf-path.c (3 diffs)
tools/atrf-path/gui.c (3 diffs)
tools/atrf-path/gui.h (1 diff)

Change Details

tools/atrf-path/atrf-path.c
169169}
170170
171171
172static void do_sweeps(const struct sweep *sweep, int sweeps)
172static int do_sweeps(const struct sweep *sweep, int sweeps)
173173{
174174    struct sample res[N_CHAN*2]; /* 2 offsets per channel */
175    int decision = 0, fail, pass;
175176    int i;
176177
178    /*
179     * The pass/fail logic here goes as follows:
180     *
181     * Pass if and only if all sweeps pass.
182     * Fail if and only if all sweeps are below the minimum.
183     * Make no decision if any sweeps were above the maximum or if there
184     * was a mixture of pass and fail.
185     */
186
177187    for (i = 0; i != sweeps; i++) {
178188        if (i)
179189            putchar('\n');
180        do_sweep(sweep, res);
190        fail = do_sweep(sweep, res);
181191        print_sweep(sweep, res);
192        pass = fail < 0 ? -1 : fail > 0 ? 0 : 1;
193        if (!i)
194            decision = pass;
195        else {
196            if (pass != decision)
197                decision = 0;
198        }
182199    }
200    return decision;
183201}
184202
185203
...... 
307325    int sweeps = 1;
308326    unsigned long tmp;
309327    char *end;
310    int c;
328    int c, decision;
311329
312330    while ((c = getopt(argc, argv, "gp:P:t:T:")) != EOF)
313331        switch (c) {
...... 
384402    init_rx(sweep.rx, sweep.trim_rx);
385403    init_tx(sweep.tx, sweep.trim_tx, sweep.power);
386404    if (graphical)
387        gui(&sweep, sweeps);
405        decision = gui(&sweep, sweeps);
388406    else
389        do_sweeps(&sweep, sweeps);
407        decision = do_sweeps(&sweep, sweeps);
408
409    switch (decision) {
410    case -1:
411        printf("#FAIL\n");
412        break;
413    case 0:
414        break;
415    case 1:
416        printf("#PASS\n");
417        break;
418    default:
419        abort();
420    }
390421
391422    atrf_reg_write(sweep.tx, REG_TRX_STATE, TRX_CMD_TRX_OFF);
392423    atrf_reg_write(sweep.rx, REG_TRX_STATE, TRX_CMD_TRX_OFF);
tools/atrf-path/gui.c
169169}
170170
171171
172void gui(const struct sweep *sweep, int sweeps)
172int gui(const struct sweep *sweep, int sweeps)
173173{
174174    SDL_Surface *surf;
175175    SDL_Event event;
176176    int cycle;
177    int fail;
177    int fail = 0;
178178
179179    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
180180        fprintf(stderr, "SDL_init: %s\n", SDL_GetError());
...... 
191191    for (cycle = 0; cycle != sweeps || !sweeps; cycle++) {
192192        struct sample res[N_CHAN*2];
193193
194        /*
195         * Pass/fail logic:
196         *
197         * Quit exit at any time, without making a pass/fail decision
198         * Pass exit if the current result is "pass"
199         * ignored if the current result is "over"/"under"
200         * Fail exit if the current result is "under"
201         * ignored if the current result is "pass"
202         * ignored if the current result is "over", because this
203         * indicates an invalid measurement, not a defective
204         * device
205         */
206
194207        while (SDL_PollEvent(&event))
195            if (event.type == SDL_KEYDOWN ||
196                event.type == SDL_QUIT)
197                return;
208            switch (event.type) {
209            case SDL_KEYDOWN:
210                switch (event.key.keysym.sym) {
211                case SDLK_f:
212                    if (cycle && fail < 0)
213                        return -1;
214                    break;
215                case SDLK_p:
216                    if (cycle && !fail)
217                        return 1;
218                    break;
219                case SDLK_q:
220                    return 0;
221                default:
222                    break;
223                }
224                break;
225            case SDL_QUIT:
226                return 0;
227            default:
228                break;
229            }
230
198231        tstart();
199232        fail = do_sweep(sweep, res);
200233        tstop();
...... 
211244        SDL_UnlockSurface(surf);
212245        SDL_UpdateRect(surf, 0, 0, 0, 0);
213246    }
247
248    return 0;
214249}
tools/atrf-path/gui.h
1818#include "sweep.h"
1919
2020
21/*
22 * gui returns one of the following values:
23 *
24 * -1 fail
25 * 0 no decision taken
26 * 1 pass
27 */
28
2129#ifdef HAVE_GFX
22void gui(const struct sweep *sweep, int sweeps);
30int gui(const struct sweep *sweep, int sweeps);
2331#else
24#define gui(sweep, sweeps) abort()
32#define gui(sweep, sweeps) ({ abort(); 0; })
2533#endif
2634
2735#endif /* !GUI_H */

Archive Download the corresponding diff file



interactive