Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Jan 2013 21:40:21 +0000 (UTC)
From:      Adrian Chadd <adrian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r245181 - user/adrian/ath_radar_stuff/src/spectral_fft
Message-ID:  <201301082140.r08LeLMj014059@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adrian
Date: Tue Jan  8 21:40:21 2013
New Revision: 245181
URL: http://svnweb.freebsd.org/changeset/base/245181

Log:
  Add a very simple initial histogram data type, to populate and fetch
  histogram entries.

Added:
  user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c
  user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h

Added: user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.c	Tue Jan  8 21:40:21 2013	(r245181)
@@ -0,0 +1,99 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
+#include <string.h>
+#include <netinet/in.h>	/* for ntohl etc */
+
+#include <pcap.h>
+
+#include "net80211/ieee80211.h"
+#include "net80211/ieee80211_radiotap.h"
+
+#include "libradarpkt/pkt.h"
+#include "libradarpkt/ar5212_radar.h"
+#include "libradarpkt/ar5416_radar.h"
+#include "libradarpkt/ar9280_radar.h"
+
+#include "fft_eval.h"
+#include "fft_freebsd.h"
+
+#include "fft_histogram.h"
+
+struct fft_histogram_data fdata;
+
+/* XXX ew */
+#define SPECTRAL_HT20_NUM_BINS          56
+
+void
+fft_histogram_init(void)
+{
+	bzero(&fdata, sizeof(fdata));
+}
+
+int
+freq2fidx(int freqKhz)
+{
+	int freqMhz = freqKhz / 1000;
+	int fidx;
+
+	if (freqMhz < FFT_HISTOGRAM_START_FREQ ||
+	    freqMhz >= FFT_HISTOGRAM_END_FREQ) {
+		return (-1);
+	}
+
+	/* Calculate index */
+	fidx = (freqKhz - FFT_HISTOGRAM_START_FREQ * 1000)
+	    / (1000 / FFT_HISTOGRAM_RESOLUTION);
+
+	if (fidx < 0 || fidx >= FFT_HISTOGRAM_SIZE) {
+		return (-1);
+	}
+
+	return (fidx);
+}
+
+void
+fft_add_sample(struct radar_entry *re, struct radar_fft_entry *fe)
+{
+	float ffreq;
+	int i;
+	int fidx;
+
+	for (i = 0; i < SPECTRAL_HT20_NUM_BINS; i++) {
+		/* Calculate frequency of the given event */
+		ffreq = (float) re->re_freq - 10.0 +
+		    ((20.0 * i) / SPECTRAL_HT20_NUM_BINS);
+
+		/* If it doesn't fit in the array, toss */
+		fidx = freq2fidx((int) (ffreq * 1000.0));
+		if (fidx < 0)
+			continue;
+
+		/* XXX until i figure out what's going on */
+		if (fe->pri.bins[i].dBm == 0 || fe->pri.bins[i].dBm < -185)
+			continue;
+
+		/* Store the current dBm value */
+		fdata.pts[fidx] = fe->pri.bins[i].dBm;
+	}
+}
+
+int
+fft_fetch_freq(int freqKhz)
+{
+	int fidx;
+
+	fidx = freq2fidx(freqKhz);
+	if (fidx < 0)
+		return -150; /* XXX */
+
+#if 0
+	printf("%s: khz=%d, fidx=%d, val=%d\n",
+	    __func__,
+	    freqKhz,
+	    fidx,
+	    fdata.pts[fidx]);
+#endif
+
+	return fdata.pts[fidx];
+}

Added: user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_histogram.h	Tue Jan  8 21:40:21 2013	(r245181)
@@ -0,0 +1,21 @@
+#ifndef	__FFT_HISTOGRAM_H__
+#define	__FFT_HISTOGRAM_H__
+
+#define	FFT_HISTOGRAM_START_FREQ	2300
+#define	FFT_HISTOGRAM_END_FREQ		6000
+
+#define	FFT_HISTOGRAM_RESOLUTION	4	/* 250Khz increments */
+
+#define	FFT_HISTOGRAM_SIZE	\
+	    ((6000-2300)*FFT_HISTOGRAM_RESOLUTION)
+
+struct fft_histogram_data {
+	int	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(int freqKhz);
+
+#endif



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301082140.r08LeLMj014059>