From owner-svn-src-user@FreeBSD.ORG Tue Jan 8 21:40:22 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 059E8380; Tue, 8 Jan 2013 21:40:22 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id EC2E5D78; Tue, 8 Jan 2013 21:40:21 +0000 (UTC) Received: from svn.freebsd.org (svn.FreeBSD.org [8.8.178.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r08LeLwY014061; Tue, 8 Jan 2013 21:40:21 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r08LeLMj014059; Tue, 8 Jan 2013 21:40:21 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201301082140.r08LeLMj014059@svn.freebsd.org> From: Adrian Chadd Date: Tue, 8 Jan 2013 21:40:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r245181 - user/adrian/ath_radar_stuff/src/spectral_fft X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Jan 2013 21:40:22 -0000 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 +#include +#include +#include +#include /* for ntohl etc */ + +#include + +#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