svn commit: r244896 - user/adrian/ath_radar_stuff/src/spectral_fft
Adrian Chadd
adrian at FreeBSD.org
Mon Dec 31 07:03:21 UTC 2012
Author: adrian
Date: Mon Dec 31 07:03:20 2012
New Revision: 244896
URL: http://svnweb.freebsd.org/changeset/base/244896
Log:
Break out the parsing code into fft_linux.c.
This (hopefully) will let me implement a FreeBSD-format version of this.
Added:
user/adrian/ath_radar_stuff/src/spectral_fft/fft_linux.c
user/adrian/ath_radar_stuff/src/spectral_fft/fft_linux.h
Modified:
user/adrian/ath_radar_stuff/src/spectral_fft/Makefile
user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c
Modified: user/adrian/ath_radar_stuff/src/spectral_fft/Makefile
==============================================================================
--- user/adrian/ath_radar_stuff/src/spectral_fft/Makefile Mon Dec 31 06:53:03 2012 (r244895)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/Makefile Mon Dec 31 07:03:20 2012 (r244896)
@@ -1,6 +1,6 @@
PROG= fft_eval
-SRCS= fft_eval.c
+SRCS= fft_eval.c fft_linux.c
CFLAGS+= -I/usr/local/include -L/usr/local/lib
Modified: user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c
==============================================================================
--- user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c Mon Dec 31 06:53:03 2012 (r244895)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_eval.c Mon Dec 31 07:03:20 2012 (r244896)
@@ -31,6 +31,7 @@
#include <SDL/SDL_ttf.h>
#include "fft_eval.h"
+#include "fft_linux.h"
#define WIDTH 1600
#define HEIGHT 650
@@ -276,97 +277,6 @@ int draw_picture(int highlight, int star
return highlight_freq;
}
-/* read_file - reads an file into a big buffer and returns it
- *
- * @fname: file name
- *
- * returns the buffer with the files content
- */
-char *read_file(char *fname, size_t *size)
-{
- FILE *fp;
- char *buf = NULL;
- size_t ret;
-
- fp = fopen(fname, "r");
-
- if (!fp)
- return NULL;
-
- *size = 0;
- while (!feof(fp)) {
-
- buf = realloc(buf, *size + 4097);
- if (!buf)
- return NULL;
-
- ret = fread(buf + *size, 1, 4096, fp);
- *size += ret;
- }
- fclose(fp);
-
- buf[*size] = 0;
-
- return buf;
-}
-
-/*
- * read_scandata - reads the fft scandata and compiles a linked list of datasets
- *
- * @fname: file name
- *
- * returns 0 on success, -1 on error.
- */
-int read_scandata(char *fname)
-{
- char *pos, *scandata;
- size_t len, sample_len;
- struct scanresult *result;
- struct fft_sample_tlv *tlv;
- struct scanresult *tail = result_list;
-
- scandata = read_file(fname, &len);
- if (!scandata)
- return -1;
-
- pos = scandata;
-
- while (pos - scandata < len) {
- tlv = (struct fft_sample_tlv *) pos;
- sample_len = sizeof(*tlv) + tlv->length;
- pos += sample_len;
- if (tlv->type != ATH_FFT_SAMPLE_HT20) {
- fprintf(stderr, "unknown sample type (%d)\n", tlv->type);
- continue;
- }
-
- if (sample_len != sizeof(result->sample)) {
- fprintf(stderr, "wrong sample length (have %d, expected %d)\n", sample_len, sizeof(result->sample));
- continue;
- }
-
- result = malloc(sizeof(*result));
- if (!result)
- continue;
-
- memset(result, 0, sizeof(*result));
- memcpy(&result->sample, tlv, sizeof(result->sample));
- fprintf(stderr, "copy %d bytes\n", sizeof(result->sample));
-
- if (tail)
- tail->next = result;
- else
- result_list = result;
-
- tail = result;
-
- scanresults_n++;
- }
-
- fprintf(stderr, "read %d scan results\n", scanresults_n);
- return 0;
-}
-
/*
* graphics_main - sets up the data and holds the mainloop.
*
@@ -485,7 +395,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "WARNING: Experimental Software! Don't trust anything you see. :)\n");
fprintf(stderr, "\n");
- if (read_scandata(argv[1]) < 0) {
+ scanresults_n = read_scandata_linux(argv[1], &result_list);
+ if (scanresults_n < 0) {
fprintf(stderr, "Couldn't read scanfile ...\n");
usage(argc, argv);
return -1;
Added: user/adrian/ath_radar_stuff/src/spectral_fft/fft_linux.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_linux.c Mon Dec 31 07:03:20 2012 (r244896)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2012 Simon Wunderlich <siwu at hrz.tu-chemnitz.de>
+ * Copyright (C) 2012 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ */
+
+/*
+ * This program has been created to aid open source spectrum
+ * analyzer development for Qualcomm/Atheros AR92xx and AR93xx
+ * based chipsets.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <math.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_ttf.h>
+
+#include "fft_eval.h"
+
+#include "fft_linux.h"
+
+/* read_file - reads an file into a big buffer and returns it
+ *
+ * @fname: file name
+ *
+ * returns the buffer with the files content
+ */
+static char *
+read_file(char *fname, size_t *size)
+{
+ FILE *fp;
+ char *buf = NULL;
+ size_t ret;
+
+ fp = fopen(fname, "r");
+
+ if (!fp)
+ return NULL;
+
+ *size = 0;
+ while (!feof(fp)) {
+
+ buf = realloc(buf, *size + 4097);
+ if (!buf)
+ return NULL;
+
+ ret = fread(buf + *size, 1, 4096, fp);
+ *size += ret;
+ }
+ fclose(fp);
+
+ buf[*size] = 0;
+
+ return buf;
+}
+
+/*
+ * read_scandata - reads the fft scandata and compiles a linked list of datasets
+ *
+ * @fname: file name
+ *
+ * returns 0 on success, -1 on error.
+ */
+int
+read_scandata_linux(char *fname, struct scanresult **result_list)
+{
+ int scanresults_n = 0;
+ char *pos, *scandata;
+ size_t len, sample_len;
+ struct scanresult *result;
+ struct fft_sample_tlv *tlv;
+ struct scanresult *tail = *result_list;
+
+ scandata = read_file(fname, &len);
+ if (!scandata)
+ return -1;
+
+ pos = scandata;
+
+ while (pos - scandata < len) {
+ tlv = (struct fft_sample_tlv *) pos;
+ sample_len = sizeof(*tlv) + tlv->length;
+ pos += sample_len;
+ if (tlv->type != ATH_FFT_SAMPLE_HT20) {
+ fprintf(stderr, "unknown sample type (%d)\n", tlv->type);
+ continue;
+ }
+
+ if (sample_len != sizeof(result->sample)) {
+ fprintf(stderr, "wrong sample length (have %d, expected %d)\n", sample_len, sizeof(result->sample));
+ continue;
+ }
+
+ result = malloc(sizeof(*result));
+ if (!result)
+ continue;
+
+ memset(result, 0, sizeof(*result));
+ memcpy(&result->sample, tlv, sizeof(result->sample));
+ fprintf(stderr, "copy %d bytes\n", sizeof(result->sample));
+
+ if (tail)
+ tail->next = result;
+ else
+ (*result_list) = result;
+
+ tail = result;
+
+ scanresults_n++;
+ }
+
+ fprintf(stderr, "read %d scan results\n", scanresults_n);
+ return (scanresults_n);
+}
+
Added: user/adrian/ath_radar_stuff/src/spectral_fft/fft_linux.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ user/adrian/ath_radar_stuff/src/spectral_fft/fft_linux.h Mon Dec 31 07:03:20 2012 (r244896)
@@ -0,0 +1,6 @@
+#ifndef __FFT_LINUX_H__
+#define __FFT_LINUX_H__
+
+extern int read_scandata_linux(char *fname, struct scanresult **result_list);
+
+#endif
More information about the svn-src-user
mailing list