svn commit: r245193 - user/adrian/ath_radar_stuff/src/spectral_fft
Adrian Chadd
adrian at FreeBSD.org
Tue Jan 8 23:25:03 UTC 2013
Author: adrian
Date: Tue Jan 8 23:25:02 2013
New Revision: 245193
URL: http://svnweb.freebsd.org/changeset/base/245193
Log:
* Add home/end to skip between 2 and 5ghz
* Add a history buffer to the current readings, so i can get a better idea
of what's going on graphically (and yes it's pretty)
* change the default alpha for the max to not be 255 ,so there's some
.. prettiness too.
Modified:
user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c
user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c
user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h
Modified: user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c
==============================================================================
--- user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c Tue Jan 8 22:55:39 2013 (r245192)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c Tue Jan 8 23:25:02 2013 (r245193)
@@ -130,17 +130,26 @@ int pixel(Uint32 *pixels, int x, int y,
return 0;
}
-
#define SIZE 2
+
+/* Is this pixel in the viewport? */
+static int
+is_in_viewport(int x, int y)
+{
+ if (x - SIZE < 0 || x + SIZE >= WIDTH)
+ return 0;
+ if (y - SIZE < 0 || y + SIZE >= HEIGHT)
+ return 0;
+ return (1);
+}
+
/* this function blends a 2*SIZE x 2*SIZE blob at the given position with
* the defined opacity. */
int bigpixel(Uint32 *pixels, int x, int y, Uint32 color, uint8_t opacity)
{
int x1, y1;
- if (x - SIZE < 0 || x + SIZE >= WIDTH)
- return -1;
- if (y - SIZE < 0 || y + SIZE >= HEIGHT)
+ if (! is_in_viewport(x, y))
return -1;
for (x1 = x - SIZE; x1 < x + SIZE; x1++)
@@ -188,7 +197,7 @@ int render_text(SDL_Surface *surface, ch
int draw_picture(int highlight, int startfreq)
{
Uint32 *pixels, color, opacity;
- int x, y, i, rnum;
+ int x, y, i, rnum, j;
int highlight_freq = startfreq + 20;
char text[1024];
struct scanresult *result;
@@ -227,24 +236,38 @@ int draw_picture(int highlight, int star
/* Render 2300 -> 6000 in 1MHz increments, but using KHz math */
/* .. as right now the canvas is .. quite large. */
+ /* XXX should just do it based on the current viewport! */
for (i = 2300*1000; i < 6000*1000; i+= 250) {
float signal;
int freqKhz = i;
+ int16_t *s;
x = X_SCALE * (freqKhz - (startfreq * 1000)) / 1000;
+ if (x < 0 || x > WIDTH)
+ continue;
+
/* Fetch dBm value at the given frequency in KHz */
- signal = (float) fft_fetch_freq_avg(freqKhz);
- color = BMASK | AMASK;
- opacity = 64;
- y = 400 - (400.0 + Y_SCALE * signal);
- if (bigpixel(pixels, x, y, color, opacity) < 0)
+ s = fft_fetch_freq_avg(freqKhz);
+ if (s == NULL)
continue;
+ for (j = 0; j < FFT_HISTOGRAM_HISTORY_DEPTH; j++) {
+ if (s[j] == 0)
+ continue;
+ signal = (float) s[j];
+ color = BMASK | AMASK;
+ opacity = 64;
+ y = 400 - (400.0 + Y_SCALE * signal);
+ if (bigpixel(pixels, x, y, color, opacity) < 0)
+ continue;
+ }
+
+
/* .. and the max */
signal = (float) fft_fetch_freq_max(freqKhz);
color = RMASK | AMASK;
- opacity = 255;
+ opacity = 128;
y = 400 - (400.0 + Y_SCALE * signal);
if (bigpixel(pixels, x, y, color, opacity) < 0)
continue;
@@ -337,6 +360,15 @@ void graphics_main(void)
case SDLK_PAGEDOWN:
accel+= 2;
scroll = 1;
+ break;
+ case SDLK_HOME:
+ startfreq = 2300;
+ accel = 0;
+ break;
+ case SDLK_END:
+ startfreq = 5100;
+ accel = 0;
+ break;
default:
break;
}
Modified: user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c
==============================================================================
--- user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c Tue Jan 8 22:55:39 2013 (r245192)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c Tue Jan 8 23:25:02 2013 (r245193)
@@ -58,6 +58,7 @@ fft_add_sample(struct radar_entry *re, s
float ffreq;
int i;
int fidx;
+ int cur;
for (i = 0; i < SPECTRAL_HT20_NUM_BINS; i++) {
/* Calculate frequency of the given event */
@@ -74,7 +75,13 @@ fft_add_sample(struct radar_entry *re, s
continue;
/* Rolling/decaying average */
- fdata.avg_pts[fidx] = (((fdata.avg_pts[fidx] * 100) / 90) + fe->pri.bins[i].dBm) / 2;
+ cur = fdata.avg_pts_cur[fidx];
+ if (fdata.avg_pts[fidx][cur] == 0) {
+ fdata.avg_pts[fidx][cur] = fe->pri.bins[i].dBm;
+ } else {
+ fdata.avg_pts[fidx][cur] = (((fdata.avg_pts[fidx][cur] * 100) / 90) + fe->pri.bins[i].dBm) / 2;
+ }
+ fdata.avg_pts_cur[fidx] = (fdata.avg_pts_cur[fidx] + 1) % FFT_HISTOGRAM_HISTORY_DEPTH;
/* Max */
if (fdata.max_pts[fidx] == 0 || fe->pri.bins[i].dBm > fdata.max_pts[fidx]) {
@@ -85,18 +92,19 @@ fft_add_sample(struct radar_entry *re, s
}
}
-int
+int16_t *
fft_fetch_freq_avg(int freqKhz)
{
int fidx;
fidx = freq2fidx(freqKhz);
if (fidx < 0)
- return -180; /* XXX */
+ return NULL;
return fdata.avg_pts[fidx];
}
-int
+
+int16_t
fft_fetch_freq_max(int freqKhz)
{
int fidx;
Modified: user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h
==============================================================================
--- user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h Tue Jan 8 22:55:39 2013 (r245192)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h Tue Jan 8 23:25:02 2013 (r245193)
@@ -8,16 +8,20 @@
#define FFT_HISTOGRAM_SIZE \
((6000-2300)*FFT_HISTOGRAM_RESOLUTION)
+#define FFT_HISTOGRAM_HISTORY_DEPTH 10
struct fft_histogram_data {
- int avg_pts[FFT_HISTOGRAM_SIZE];
- int max_pts[FFT_HISTOGRAM_SIZE];
+ /* XXX should struct-ize these! */
+ int16_t avg_pts[FFT_HISTOGRAM_SIZE][FFT_HISTOGRAM_HISTORY_DEPTH];
+ int16_t avg_pts_cur[FFT_HISTOGRAM_SIZE];
+
+ int16_t max_pts[FFT_HISTOGRAM_SIZE];
};
extern void fft_histogram_init(void);
extern void fft_add_sample(struct radar_entry *re,
struct radar_fft_entry *fe);
-extern int fft_fetch_freq_avg(int freqKhz);
-extern int fft_fetch_freq_max(int freqKhz);
+extern int16_t * fft_fetch_freq_avg(int freqKhz);
+extern int16_t fft_fetch_freq_max(int freqKhz);
#endif
More information about the svn-src-user
mailing list