Date:2011-06-25 02:50:28 (8 years 2 months ago)
Author:Werner Almesberger
Commit:9af0f937de54ead5790894e1d9e35f160d9dfdff
Message:tools/atrf-rssi/: added WLAN channel display (US, EU, and JP)

- gui.c (wlan_area): the currently displayed regulation domain
- gui.c (wlan_channels): return the number of WLAN channels
- gui.c (show_wlan_channel): determine whether the specified channel
should be used in the currently displayed regulation domain
- gui.c (label_wlan_channels): show WLAN channel numbers and their
width
- gui.c (gui): switch regulation domain with E (Europe), J (Japan),
and U (US)
- gui.c (gui): quit now only if Q is pressed instead of any key
- gui.c (gui): call label_wlan_channels to display the WLAN channels
Files: tools/atrf-rssi/gui.c (7 diffs)

Change Details

tools/atrf-rssi/gui.c
11/*
22 * atrf-rssi/gui.c - Graphical output for atrf-rssi
33 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
4 * Written 2010-2011 by Werner Almesberger
5 * Copyright 2010-2011 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
4040#define BG_RGBA 0x00408080 /* grid background color */
4141#define CHAN_RGBA 0xff4040ff /* channel number color */
4242#define FREQ_RGBA 0x20ff00ff /* frequency color */
43#define WCHAN_RGBA 0xffff00e0 /* WLAN channel number color */
44#define WLAN_RGBA 0x8080ffff /* WLAN channel occupancy color */
4345
4446#define X_STEP 17 /* grid x step */
4547#define Y_STEP 2 /* grid y step */
...... 
4850#define X_OFFSET 7 /* x coordinate of lower left grid corner */
4951#define Y_OFFSET 40 /* y coordinate of lower left grid corner */
5052
53#define X_WLAN_OFFSET 31
54#define Y_WLAN_OFFSET 15
55
56#define WLAN_XR (X_STEP*9.5/5)
57#define WLAN_YH 6
58
59
60static enum {
61    area_us,
62    area_eu,
63    area_jp,
64} wlan_area = area_us;
65
5166
5267static struct timeval t0;
5368
...... 
95110    x-5+(pos)*6, x-1+(pos)*6, y+8, y+4, y, CHAN_RGBA
96111#define CSMALL(pos) \
97112    x-7+(pos)*4, x-5+(pos)*4, y+15, y+13, y+11, FREQ_RGBA
113#define CWLAN(pos) \
114    x-4+(pos)*5, x-1+(pos)*5, y+6, y+3, y, WCHAN_RGBA
98115
99116
100117static void label_channels(SDL_Surface *s, int sx, int x0, int y0)
...... 
121138}
122139
123140
141static int wlan_channels(void)
142{
143    switch (wlan_area) {
144    case area_us:
145        return 11;
146    case area_eu:
147        return 13;
148    case area_jp:
149        return 14;
150    default:
151        abort();
152    }
153}
154
155
156static int show_wlan_channel(int c)
157{
158    switch (wlan_area) {
159    case area_jp:
160        if (c == 14)
161            return 1;
162        /* fall through */
163    case area_us:
164        return !((c-1) % 5);
165    case area_eu:
166        return !((c-1) % 4);
167    default:
168        abort();
169    }
170}
171
172
173static void label_wlan_channels(SDL_Surface *s, int sx, int x0, int y0)
174{
175    int x, xb, y, i, c;
176
177    xb = x0;
178    y = s->h-y0+4;
179    for (i = 0; i != wlan_channels(); i++) {
180        c = i+1;
181        /* Japan special channel: 22 MHz from channel 13 */
182        if (c == 14)
183            xb += X_STEP*12/5-X_STEP;
184        if (c > 9) {
185            x = xb;
186            digit(s, c/10, CWLAN(0));
187        } else {
188            x = xb-3;
189        }
190        digit(s, c % 10, CWLAN(1));
191        if (show_wlan_channel(c)) {
192            hlineColor(s, xb-WLAN_XR, xb+WLAN_XR, y-WLAN_YH,
193                WLAN_RGBA);
194            vlineColor(s, xb, y-2, y-WLAN_YH+1, WLAN_RGBA);
195        }
196        xb += sx;
197    }
198}
199
200
124201void gui(struct atrf_dsc *dsc)
125202{
126203    SDL_Surface *surf;
...... 
143220    }
144221
145222    while (1) {
146        while (SDL_PollEvent(&event))
147            if (event.type == SDL_KEYDOWN ||
148                event.type == SDL_QUIT)
223        while (SDL_PollEvent(&event)) {
224            switch (event.type) {
225            case SDL_KEYDOWN:
226                switch (event.key.keysym.sym) {
227                case SDLK_j:
228                    wlan_area = area_jp;
229                    break;
230                case SDLK_e:
231                    wlan_area = area_eu;
232                    break;
233                case SDLK_u:
234                    wlan_area = area_us;
235                    break;
236                case SDLK_q:
237                    return;
238                default:
239                    break;
240                }
241                break;
242            case SDL_QUIT:
149243                return;
244            default:
245                break;
246            }
247        }
150248
151249        shift_grid(z, N_CHAN, N_TIME);
152250        sweep(dsc, z);
...... 
159257            X_OFFSET, Y_OFFSET,
160258            FG_RGBA, BG_RGBA);
161259        label_channels(surf, X_STEP, X_OFFSET, Y_OFFSET);
260        label_wlan_channels(surf, X_STEP, X_WLAN_OFFSET, Y_WLAN_OFFSET);
162261
163262        SDL_UnlockSurface(surf);
164263        SDL_UpdateRect(surf, 0, 0, 0, 0);

Archive Download the corresponding diff file



interactive