diff -Nru spectools-201004R1/debian/changelog spectools-201108r1/debian/changelog --- spectools-201004R1/debian/changelog 2010-12-22 04:19:54.000000000 +0000 +++ spectools-201108r1/debian/changelog 2011-08-09 19:41:12.000000000 +0000 @@ -1,3 +1,13 @@ +spectools (201108r1-1) unstable; urgency=low + + * New upstream release + + * Remove obsolete "Break" (udev << 136) in debian/control + * Add empty build-arch and build-indep targets in debian/rules + * Bump Standards-Version up to 3.9.2 + + -- Francois Marier Tue, 09 Aug 2011 15:40:32 -0400 + spectools (201004R1-2) unstable; urgency=low * Bump Standards-Version up to 3.9.1 diff -Nru spectools-201004R1/debian/control spectools-201108r1/debian/control --- spectools-201004R1/debian/control 2010-12-22 04:19:54.000000000 +0000 +++ spectools-201108r1/debian/control 2011-08-09 19:41:12.000000000 +0000 @@ -3,7 +3,7 @@ Priority: extra Maintainer: Francois Marier Build-Depends: debhelper (>= 8), autotools-dev, libusb-dev, libgtk2.0-dev, libncurses5-dev -Standards-Version: 3.9.1 +Standards-Version: 3.9.2 Homepage: http://www.kismetwireless.net/spectools/ Vcs-Git: git://git.debian.org/git/collab-maint/spectools.git Vcs-Browser: http://git.debian.org/?p=collab-maint/spectools.git;a=summary @@ -11,7 +11,6 @@ Package: spectools Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} -Breaks: udev (<< 136-1) Description: Utilities for using the Wi-Spy USB spectrum analyzer hardware Spectrum-Tools is a set of utilities for using the Wi-Spy USB spectrum analyzer tools from Metageek LLC. They include userspace drivers for diff -Nru spectools-201004R1/debian/patches/debian-changes-201004R1-2 spectools-201108r1/debian/patches/debian-changes-201004R1-2 --- spectools-201004R1/debian/patches/debian-changes-201004R1-2 2010-12-22 04:20:05.000000000 +0000 +++ spectools-201108r1/debian/patches/debian-changes-201004R1-2 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ -Description: Upstream changes introduced in version 201004R1-2 - This patch has been created by dpkg-source during the package build. - Here's the last changelog entry, hopefully it gives details on why - those changes were made: - . - spectools (201004R1-2) unstable; urgency=low - . - * Bump Standards-Version up to 3.9.1 - * Bump debhelper compatibility to 8 - . - The person named in the Author field signed this changelog entry. -Author: Francois Marier - ---- -The information above should follow the Patch Tagging Guidelines, please -checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here -are templates for supplementary fields that you might want to add: - -Origin: , -Bug: -Bug-Debian: http://bugs.debian.org/ -Bug-Ubuntu: https://launchpad.net/bugs/ -Forwarded: -Reviewed-By: -Last-Update: - ---- spectools-201004R1.orig/wispy_hw_dbx.c -+++ spectools-201004R1/wispy_hw_dbx.c -@@ -114,7 +114,7 @@ - uint16_t __x = (x); \ - ((uint16_t)( \ - (uint16_t)(((uint16_t)(__x) & (uint16_t)0x000000ff) << 24) | \ -- (uint16_t)(((uint16_t)(__x) & (uint16_t)0x0000ff00) << 8) | \ -+ (uint16_t)(((uint16_t)(__x) & (uint16_t)0x0000ff00) << 8) )); \ - }) - - /* Aux tracking struct for wispy1 characteristics */ diff -Nru spectools-201004R1/debian/patches/series spectools-201108r1/debian/patches/series --- spectools-201004R1/debian/patches/series 2010-12-22 04:20:05.000000000 +0000 +++ spectools-201108r1/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -debian-changes-201004R1-2 diff -Nru spectools-201004R1/debian/rules spectools-201108r1/debian/rules --- spectools-201004R1/debian/rules 2010-12-22 04:19:54.000000000 +0000 +++ spectools-201108r1/debian/rules 2011-08-09 19:41:12.000000000 +0000 @@ -28,6 +28,8 @@ ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs" +build-arch: +build-indep: build: build-stamp build-stamp: config.status diff -Nru spectools-201004R1/Makefile.in spectools-201108r1/Makefile.in --- spectools-201004R1/Makefile.in 2008-09-17 13:41:31.000000000 +0000 +++ spectools-201108r1/Makefile.in 2011-06-11 04:59:10.000000000 +0000 @@ -20,19 +20,21 @@ GTK_CONFIG=@GTK_CONFIG@ -RAWOBJS = spectool_container.o wispy_hw_gen1.o wispy_hw_24x.o wispy_hw_dbx.o \ +DRIVERS = wispy_hw_gen1.o wispy_hw_24x.o wispy_hw_dbx.o ubertooth_hw_u1.o + +RAWOBJS = spectool_container.o ${DRIVERS} \ spectool_net_client.o spectool_raw.o RAWBIN = spectool_raw -CURSOBJS = spectool_container.o wispy_hw_gen1.o wispy_hw_24x.o wispy_hw_dbx.o \ +CURSOBJS = spectool_container.o ${DRIVERS} \ spectool_net_client.o spectool_curses.o CURSBIN = spectool_curses -NETOBJS = spectool_container.o wispy_hw_gen1.o wispy_hw_24x.o wispy_hw_dbx.o \ +NETOBJS = spectool_container.o ${DRIVERS} \ spectool_net_server.o NETBIN = spectool_net -GTKOBJS = spectool_container.o wispy_hw_gen1.o wispy_hw_24x.o wispy_hw_dbx.o \ +GTKOBJS = spectool_container.o ${DRIVERS} \ spectool_net_client.o \ spectool_gtk_hw_registry.o spectool_gtk_widget.o spectool_gtk_channel.o \ spectool_gtk_planar.o spectool_gtk_spectral.o spectool_gtk_topo.o \ diff -Nru spectools-201004R1/spectool_container.c spectools-201108r1/spectool_container.c --- spectools-201004R1/spectool_container.c 2009-03-01 03:51:17.000000000 +0000 +++ spectools-201108r1/spectool_container.c 2011-06-15 04:04:23.000000000 +0000 @@ -18,58 +18,59 @@ #include "wispy_hw_gen1.h" #include "wispy_hw_24x.h" #include "wispy_hw_dbx.h" +#include "ubertooth_hw_u1.h" -int wispy_get_state(wispy_phy *phydev) { +int spectool_get_state(spectool_phy *phydev) { return phydev->state; } -char *wispy_get_error(wispy_phy *phydev) { +char *spectool_get_error(spectool_phy *phydev) { return phydev->errstr; } -char *wispy_phy_getname(wispy_phy *phydev) { +char *spectool_phy_getname(spectool_phy *phydev) { if (phydev->device_spec == NULL) return NULL; return phydev->device_spec->device_name; } -int wispy_phy_getdevid(wispy_phy *phydev) { +int spectool_phy_getdevid(spectool_phy *phydev) { if (phydev->device_spec == NULL) return 0; return phydev->device_spec->device_id; } -void wispy_phy_setname(wispy_phy *phydev, char *name) { +void spectool_phy_setname(spectool_phy *phydev, char *name) { if (phydev->device_spec == NULL) return; - snprintf(phydev->device_spec->device_name, WISPY_PHY_NAME_MAX, "%s", name); + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, "%s", name); } -int wispy_phy_open(wispy_phy *phydev) { +int spectool_phy_open(spectool_phy *phydev) { if (phydev->open_func == NULL) return 0; return (*(phydev->open_func))(phydev); } -int wispy_phy_close(wispy_phy *phydev) { +int spectool_phy_close(spectool_phy *phydev) { if (phydev->close_func == NULL) return 0; return (*(phydev->close_func))(phydev); } -int wispy_phy_poll(wispy_phy *phydev) { +int spectool_phy_poll(spectool_phy *phydev) { if (phydev->poll_func == NULL) - return WISPY_POLL_ERROR; + return SPECTOOL_POLL_ERROR; return (*(phydev->poll_func))(phydev); } -int wispy_phy_getpollfd(wispy_phy *phydev) { +int spectool_phy_getpollfd(spectool_phy *phydev) { if (phydev == NULL) return -1; @@ -79,40 +80,41 @@ return (*(phydev->pollfd_func))(phydev); } -void wispy_phy_setcalibration(wispy_phy *phydev, int enable) { +void spectool_phy_setcalibration(spectool_phy *phydev, int enable) { if (phydev->setcalib_func != NULL) return (*(phydev->setcalib_func))(phydev, enable); } -int wispy_phy_getflags(wispy_phy *phydev) { +int spectool_phy_getflags(spectool_phy *phydev) { return phydev->device_spec->device_flags; } -int wispy_phy_setposition(wispy_phy *phydev, int in_profile, +int spectool_phy_setposition(spectool_phy *phydev, int in_profile, int start_khz, int res_hz) { if (phydev->setposition_func != NULL) return (*(phydev->setposition_func))(phydev, in_profile, start_khz, res_hz); - snprintf(phydev->errstr, WISPY_ERROR_MAX, "Device does not support setting " + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "Device does not support setting " "scan position or resolution"); return -1; } -wispy_sample_sweep *wispy_phy_getsweep(wispy_phy *phydev) { +spectool_sample_sweep *spectool_phy_getsweep(spectool_phy *phydev) { if (phydev->getsweep_func == NULL) return NULL; return (*(phydev->getsweep_func))(phydev); } -wispy_sweep_cache *wispy_cache_alloc(int nsweeps, int calc_peak, int calc_avg) { +spectool_sweep_cache *spectool_cache_alloc(int nsweeps, int calc_peak, int calc_avg) { int x; - wispy_sweep_cache *c = (wispy_sweep_cache *) malloc(sizeof(wispy_sweep_cache)); + spectool_sweep_cache *c = (spectool_sweep_cache *) malloc(sizeof(spectool_sweep_cache)); c->sweeplist = - (wispy_sample_sweep **) malloc(sizeof(wispy_sample_sweep *) * nsweeps); + (spectool_sample_sweep **) malloc(sizeof(spectool_sample_sweep *) * nsweeps); c->avg = NULL; c->peak = NULL; + c->roll_peak = NULL; c->latest = NULL; for (x = 0; x < nsweeps; x++) { @@ -122,6 +124,7 @@ c->num_alloc = nsweeps; c->pos = -1; c->looped = 0; + c->num_used = 0; c->calc_peak = calc_peak; c->calc_avg = calc_avg; @@ -129,7 +132,7 @@ return c; } -void wispy_cache_free(wispy_sweep_cache *c) { +void spectool_cache_free(spectool_sweep_cache *c) { if (c->avg != NULL) free(c->avg); if (c->peak != NULL) @@ -137,7 +140,7 @@ free(c->sweeplist); } -void wispy_cache_clear(wispy_sweep_cache *c) { +void spectool_cache_clear(spectool_sweep_cache *c) { if (c->avg != NULL) free(c->avg); c->avg = NULL; @@ -146,14 +149,20 @@ free(c->peak); c->peak = NULL; + if (c->roll_peak != NULL) + free(c->roll_peak); + c->roll_peak = NULL; + c->pos = 0; c->looped = 0; + c->num_used = 0; } -void wispy_cache_append(wispy_sweep_cache *c, wispy_sample_sweep *s) { +void spectool_cache_append(spectool_sweep_cache *c, spectool_sample_sweep *s) { int x, y, sum = 0; int *avgdata, *avgsum; int navg; + int nsampled; /* Make sure we don't overflow and crash, should be sufficient * to make sure that the new sweep is reasonable */ @@ -165,22 +174,30 @@ c->pos = 0; } else { c->pos++; + + if (c->num_used < c->num_alloc) + c->num_used++; } if (c->sweeplist[c->pos] != NULL) { free(c->sweeplist[c->pos]); } + if (c->looped) + nsampled = c->num_alloc; + else + nsampled = c->pos; + c->sweeplist[c->pos] = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(s->num_samples)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(s->num_samples)); - memcpy(c->sweeplist[c->pos], s, WISPY_SWEEP_SIZE(s->num_samples)); + memcpy(c->sweeplist[c->pos], s, SPECTOOL_SWEEP_SIZE(s->num_samples)); c->latest = c->sweeplist[c->pos]; if (c->avg == NULL && c->calc_avg) { - c->avg = (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(s->num_samples)); - memcpy(c->avg, s, WISPY_SWEEP_SIZE(s->num_samples)); + c->avg = (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(s->num_samples)); + memcpy(c->avg, s, SPECTOOL_SWEEP_SIZE(s->num_samples)); } else if (c->calc_avg) { /* Reset average times */ c->avg->tm_start.tv_sec = 0; @@ -197,7 +214,8 @@ } /* Sum them up */ - for (x = 0; x < c->num_alloc; x++) { + + for (x = 0; x < nsampled; x++) { if (c->sweeplist[x] == NULL) continue; @@ -239,25 +257,69 @@ /* Allocate or update the peak. We don't track peak timelines */ if (c->peak == NULL && c->calc_peak) { - c->peak = (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(s->num_samples)); - memcpy(c->peak, s, WISPY_SWEEP_SIZE(s->num_samples)); + c->peak = (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(s->num_samples)); + memcpy(c->peak, s, SPECTOOL_SWEEP_SIZE(s->num_samples)); + + /* This will never be allocated if peak is not */ + c->roll_peak = (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(s->num_samples)); + memcpy(c->roll_peak, s, SPECTOOL_SWEEP_SIZE(s->num_samples)); } else if (c->calc_peak) { + for (x = 0; x < c->peak->num_samples; x++) { if (c->peak->sample_data[x] < s->sample_data[x]) { c->peak->sample_data[x] = s->sample_data[x]; } } + + memcpy(c->roll_peak, s, SPECTOOL_SWEEP_SIZE(s->num_samples)); + for (x = 0; x < nsampled; x++) { + for (y = 0; y < c->roll_peak->num_samples; y++) { + // printf("debug - compare sampled %d pos %d loop %d set %d sample %d\n", nsampled, c->pos, c->looped, x, y); + if (c->roll_peak->sample_data[y] < c->sweeplist[x]->sample_data[y]) { + c->roll_peak->sample_data[y] = c->sweeplist[x]->sample_data[y]; + } + } + } + + } +} + +void spectool_cache_itr_init(spectool_sweep_cache *c, spectool_sweep_cache_itr *i) { + i->pos_start = c->pos; + i->pos_cur = c->pos + 1; + i->looped_start = 0; +} + +spectool_sample_sweep *spectool_cache_itr_next(spectool_sweep_cache *c, spectool_sweep_cache_itr *i) { + // if we've covered it all, punt + if (i->pos_cur == i->pos_start) { + if (i->looped_start == 0) + i->looped_start = 1; + else + return NULL; } + + // 'next' is actually backwards + i->pos_cur--; + + // if we've hit the bottom but we're looped, go to the max filled slot + if (i->pos_cur < 0 && c->looped) i->pos_cur = c->num_used - 1; + // Or we're done + if (i->pos_cur < 0) return NULL; + // safety + if (i->pos_cur >= c->num_used) return NULL; + + return c->sweeplist[i->pos_cur]; } -void wispy_device_scan_init(wispy_device_list *list) { - list->list = (wispy_device_rec *) malloc(sizeof(wispy_device_rec) * MAX_SCAN_RESULT); +void spectool_device_scan_init(spectool_device_list *list) { + list->list = (spectool_device_rec *) malloc(sizeof(spectool_device_rec) * MAX_SCAN_RESULT); list->num_devs = 0; list->max_devs = MAX_SCAN_RESULT; } -int wispy_device_scan(wispy_device_list *list) { - wispy_device_scan_init(list); +int spectool_device_scan(spectool_device_list *list) { + spectool_device_scan_init(list); if (wispy1_usb_device_scan(list) < 0) { return -1; @@ -271,10 +333,14 @@ return -1; } + if (ubertooth_u1_device_scan(list) < 0) { + return -1; + } + return list->num_devs; } -void wispy_device_scan_free(wispy_device_list *list) { +void spectool_device_scan_free(spectool_device_list *list) { int x; for (x = 0; x < list->num_devs && x < list->max_devs; x++) { @@ -289,11 +355,11 @@ free(list->list); } -int wispy_device_init(wispy_phy *phydev, wispy_device_rec *rec) { +int spectool_device_init(spectool_phy *phydev, spectool_device_rec *rec) { return (*(rec->init_func))(phydev, rec); } -wispy_sample_sweep *wispy_phy_getcurprofile(wispy_phy *phydev) { +spectool_sample_sweep *spectool_phy_getcurprofile(spectool_phy *phydev) { if (phydev == NULL) return NULL; diff -Nru spectools-201004R1/spectool_container.h spectools-201108r1/spectool_container.h --- spectools-201004R1/spectool_container.h 2009-06-30 22:47:17.000000000 +0000 +++ spectools-201108r1/spectool_container.h 2011-06-15 04:04:23.000000000 +0000 @@ -14,8 +14,8 @@ * */ -#ifndef __WISPY_DEVCONTAINER_H__ -#define __WISPY_DEVCONTAINER_H__ +#ifndef __SPECTOOL_DEVCONTAINER_H__ +#define __SPECTOOL_DEVCONTAINER_H__ #include #include @@ -32,7 +32,7 @@ * re-use this same record as the definition of what sweep ranges a device * can handle. */ -typedef struct _wispy_sample_sweep { +typedef struct _spectool_sample_sweep { /* Name of sweep (if used as a range marker */ char *name; @@ -46,7 +46,7 @@ /* RSSI conversion information in mdbm * db = (rssi * (amp_res_mdbm / 1000)) - (amp_offset_mdbm / 1000) */ int amp_offset_mdbm; - unsigned int amp_res_mdbm; + int amp_res_mdbm; unsigned int rssi_max; /* Lowest RSSI seen by the device */ @@ -70,39 +70,50 @@ /* Actual sample data. This is num_samples of uint8_t RSSI */ uint8_t sample_data[0]; -} wispy_sample_sweep; +} spectool_sample_sweep; -#define WISPY_RSSI_CONVERT(O,R,D) (int) ((D) * ((double) (R) / 1000.0f) + \ +#define SPECTOOL_RSSI_CONVERT(O,R,D) (int) ((D) * ((double) (R) / 1000.0f) + \ ((double) (O) / 1000.0f)) -#define WISPY_SWEEP_SIZE(y) (sizeof(wispy_sample_sweep) + (y)) +#define SPECTOOL_SWEEP_SIZE(y) (sizeof(spectool_sample_sweep) + (y)) /* Sweep record for aggregating multiple sweep points */ -typedef struct _wispy_sweep_cache { - wispy_sample_sweep **sweeplist; - wispy_sample_sweep *avg; - wispy_sample_sweep *peak; - wispy_sample_sweep *latest; +typedef struct _spectool_sweep_cache { + spectool_sample_sweep **sweeplist; + spectool_sample_sweep *avg; + spectool_sample_sweep *peak; + spectool_sample_sweep *roll_peak; + spectool_sample_sweep *latest; int num_alloc, pos, looped; int calc_peak, calc_avg; + int num_used; uint32_t device_id; -} wispy_sweep_cache; +} spectool_sweep_cache; + +typedef struct _spectool_sweep_cache_itr { + int pos_start; + int pos_cur; + int looped_start; +} spectool_sweep_cache_itr; /* Allocate and manipulate sweep caches */ -wispy_sweep_cache *wispy_cache_alloc(int nsweeps, int calc_peak, int calc_avg); -void wispy_cache_append(wispy_sweep_cache *c, wispy_sample_sweep *s); -void wispy_cache_clear(wispy_sweep_cache *c); -void wispy_cache_free(wispy_sweep_cache *c); - -#define WISPY_ERROR_MAX 512 -#define WISPY_PHY_NAME_MAX 256 -typedef struct _wispy_dev_spec { +spectool_sweep_cache *spectool_cache_alloc(int nsweeps, int calc_peak, int calc_avg); +void spectool_cache_append(spectool_sweep_cache *c, spectool_sample_sweep *s); +void spectool_cache_clear(spectool_sweep_cache *c); +void spectool_cache_free(spectool_sweep_cache *c); + +void spectool_cache_itr_init(spectool_sweep_cache *c, spectool_sweep_cache_itr *i); +spectool_sample_sweep *spectool_cache_itr_next(spectool_sweep_cache *c, spectool_sweep_cache_itr *i); + +#define SPECTOOL_ERROR_MAX 512 +#define SPECTOOL_PHY_NAME_MAX 256 +typedef struct _spectool_dev_spec { /* A unique ID fetched from the firmware (in the future) or extracted from the * USB bus (currently) */ uint32_t device_id; /* User-specified name */ - char device_name[WISPY_PHY_NAME_MAX]; + char device_name[SPECTOOL_PHY_NAME_MAX]; /* Version of the physical source device. * 0x01 WiSPY generation 1 USB device @@ -114,7 +125,7 @@ /* Device flags */ uint8_t device_flags; - wispy_sample_sweep *default_range; + spectool_sample_sweep *default_range; /* Number of sweep ranges this device supports. * Gen1 supports 1 range. @@ -122,22 +133,22 @@ unsigned int num_sweep_ranges; /* Supported sweep ranges */ - wispy_sample_sweep *supported_ranges; + spectool_sample_sweep *supported_ranges; int cur_profile; -} wispy_dev_spec; +} spectool_dev_spec; /* Device flags */ -#define WISPY_DEV_FL_NONE 0 +#define SPECTOOL_DEV_FL_NONE 0 /* Variable sweep supported */ -#define WISPY_DEV_FL_VAR_SWEEP 1 +#define SPECTOOL_DEV_FL_VAR_SWEEP 1 -#define WISPY_DEV_SIZE(y) (sizeof(wispy_dev_spec)) +#define SPECTOOL_DEV_SIZE(y) (sizeof(spectool_dev_spec)) -/* Central tracking structure for wispy device data and API callbacks */ -typedef struct _wispy_phy { +/* Central tracking structure for spectool device data and API callbacks */ +typedef struct _spectool_phy { /* Phy capabilities */ - wispy_dev_spec *device_spec; + spectool_dev_spec *device_spec; /* Running state */ int state; @@ -149,92 +160,92 @@ void *auxptr; /* Function pointers to be filled in by the device init system */ - int (*open_func)(struct _wispy_phy *); - int (*close_func)(struct _wispy_phy *); - int (*poll_func)(struct _wispy_phy *); - int (*pollfd_func)(struct _wispy_phy *); - void (*setcalib_func)(struct _wispy_phy *, int); - int (*setposition_func)(struct _wispy_phy *, int, int, int); - wispy_sample_sweep *(*getsweep_func)(struct _wispy_phy *); + int (*open_func)(struct _spectool_phy *); + int (*close_func)(struct _spectool_phy *); + int (*poll_func)(struct _spectool_phy *); + int (*pollfd_func)(struct _spectool_phy *); + void (*setcalib_func)(struct _spectool_phy *, int); + int (*setposition_func)(struct _spectool_phy *, int, int, int); + spectool_sample_sweep *(*getsweep_func)(struct _spectool_phy *); - char errstr[WISPY_ERROR_MAX]; + char errstr[SPECTOOL_ERROR_MAX]; /* Linked list elements incase we need them in our implementation */ - struct _wispy_phy *next; + struct _spectool_phy *next; /* Suggested delay for drawing */ int draw_agg_suggestion; -} wispy_phy; +} spectool_phy; -#define WISPY_PHY_SIZE (sizeof(wispy_phy)) +#define SPECTOOL_PHY_SIZE (sizeof(spectool_phy)) -int wispy_get_state(wispy_phy *phydev); -char *wispy_get_error(wispy_phy *phydev); -int wispy_phy_open(wispy_phy *phydev); -int wispy_phy_close(wispy_phy *phydev); -int wispy_phy_poll(wispy_phy *phydev); -int wispy_phy_getpollfd(wispy_phy *phydev); -wispy_sample_sweep *wispy_phy_getsweep(wispy_phy *phydev); -void wispy_phy_setcalibration(wispy_phy *phydev, int enable); -int wispy_phy_setposition(wispy_phy *phydev, int in_profile, +int spectool_get_state(spectool_phy *phydev); +char *spectool_get_error(spectool_phy *phydev); +int spectool_phy_open(spectool_phy *phydev); +int spectool_phy_close(spectool_phy *phydev); +int spectool_phy_poll(spectool_phy *phydev); +int spectool_phy_getpollfd(spectool_phy *phydev); +spectool_sample_sweep *spectool_phy_getsweep(spectool_phy *phydev); +void spectool_phy_setcalibration(spectool_phy *phydev, int enable); +int spectool_phy_setposition(spectool_phy *phydev, int in_profile, int start_khz, int res_hz); -char *wispy_phy_getname(wispy_phy *phydev); -void wispy_phy_setname(wispy_phy *phydev, char *name); -int wispy_phy_getdevid(wispy_phy *phydev); -int wispy_phy_get_flags(wispy_phy *phydev); -wispy_sample_sweep *wispy_phy_getcurprofile(wispy_phy *phydev); +char *spectool_phy_getname(spectool_phy *phydev); +void spectool_phy_setname(spectool_phy *phydev, char *name); +int spectool_phy_getdevid(spectool_phy *phydev); +int spectool_phy_get_flags(spectool_phy *phydev); +spectool_sample_sweep *spectool_phy_getcurprofile(spectool_phy *phydev); /* Running states */ -#define WISPY_STATE_CLOSED 0 -#define WISPY_STATE_CONFIGURING 1 -#define WISPY_STATE_CALIBRATING 2 -#define WISPY_STATE_RUNNING 3 -#define WISPY_STATE_ERROR 255 +#define SPECTOOL_STATE_CLOSED 0 +#define SPECTOOL_STATE_CONFIGURING 1 +#define SPECTOOL_STATE_CALIBRATING 2 +#define SPECTOOL_STATE_RUNNING 3 +#define SPECTOOL_STATE_ERROR 255 /* Poll return states */ /* Failure */ -#define WISPY_POLL_ERROR 256 +#define SPECTOOL_POLL_ERROR 256 /* No state - partial poll, etc */ -#define WISPY_POLL_NONE 1 +#define SPECTOOL_POLL_NONE 1 /* Sweep is complete, caller should pull data */ -#define WISPY_POLL_SWEEPCOMPLETE 2 +#define SPECTOOL_POLL_SWEEPCOMPLETE 2 /* Device has finished configuring */ -#define WISPY_POLL_CONFIGURED 4 +#define SPECTOOL_POLL_CONFIGURED 4 /* Device has additional pending data and poll should be called again */ -#define WISPY_POLL_ADDITIONAL 8 +#define SPECTOOL_POLL_ADDITIONAL 8 /* Device scan handling */ -typedef struct _wispy_device_rec { +typedef struct _spectool_device_rec { /* Name of device */ - char name[WISPY_PHY_NAME_MAX]; + char name[SPECTOOL_PHY_NAME_MAX]; /* ID of device */ uint32_t device_id; /* Init function */ - int (*init_func)(struct _wispy_phy *, struct _wispy_device_rec *); + int (*init_func)(struct _spectool_phy *, struct _spectool_device_rec *); /* Hardware record pointing to the aux handling */ void *hw_rec; /* Supported sweep ranges identified from hw type */ unsigned int num_sweep_ranges; - wispy_sample_sweep *supported_ranges; -} wispy_device_rec; + spectool_sample_sweep *supported_ranges; +} spectool_device_rec; -typedef struct _wispy_device_list { +typedef struct _spectool_device_list { int num_devs; int max_devs; - wispy_device_rec *list; -} wispy_device_list; + spectool_device_rec *list; +} spectool_device_list; /* Hopefully this doesn't come back and bite us, but, really, 32 SAs on one system? */ #define MAX_SCAN_RESULT 32 /* Scan for all attached devices we can handle */ -void wispy_device_scan_init(wispy_device_list *list); -int wispy_device_scan(wispy_device_list *list); -void wispy_device_scan_free(wispy_device_list *list); -int wispy_device_init(wispy_phy *phydev, wispy_device_rec *rec); +void spectool_device_scan_init(spectool_device_list *list); +int spectool_device_scan(spectool_device_list *list); +void spectool_device_scan_free(spectool_device_list *list); +int spectool_device_init(spectool_phy *phydev, spectool_device_rec *rec); -struct wispy_channels { +struct spectool_channels { /* Name of the channel set */ char *name; /* Start and end khz for matching */ @@ -281,9 +292,11 @@ }; /* Allocate all our channels in a big nasty array */ -static struct wispy_channels channel_list[] = { +static struct spectool_channels channel_list[] = { { "802.11b/g", 2400000, 2483000, 14, chan_freqs_24, 22000, chan_text_24 }, - { "802.11a", 5160000, 5832000, 24, chan_freqs_5, 20000, chan_text_5 }, + { "802.11b/g", 2402000, 2480000, 14, chan_freqs_24, 22000, chan_text_24 }, + { "802.11a", 5100000, 5832000, 24, chan_freqs_5, 20000, chan_text_5 }, + { "802.11a UN-II", 5100000, 5483000, 14, chan_freqs_5, 20000, chan_text_5 }, { "900 ISM", 902000, 927000, 5, chan_freqs_900, 5000, chan_text_900 }, { NULL, 0, 0, 0, NULL, 0, NULL } }; diff -Nru spectools-201004R1/spectool_curses.c spectools-201108r1/spectool_curses.c --- spectools-201004R1/spectool_curses.c 2009-03-17 17:55:37.000000000 +0000 +++ spectools-201108r1/spectool_curses.c 2011-06-15 19:53:10.000000000 +0000 @@ -16,16 +16,12 @@ #include "spectool_container.h" #include "spectool_net_client.h" -wispy_phy *dev = NULL; +spectool_phy *dev = NULL; -void sighandle(int sig) { - int x; - - endwin(); - - printf("Dying %d from signal %d\n", getpid(), sig); +void fatal_error(int, const char *, ...); - exit(1); +void sighandle(int sig) { + fatal_error(1, "Dying %d from signal %d\n", getpid(), sig); } void Usage(void) { @@ -37,13 +33,24 @@ return; } +void fatal_error(int code, const char *format, ...) { + va_list args; + + endwin(); + + va_start(args, format); + vprintf(format, args); + + exit(code); +} + int main(int argc, char *argv[]) { - wispy_device_list list; + spectool_device_list list; int x = 0, r = 0, y = 0, ndev = 0; - wispy_sample_sweep *sb = NULL; - wispy_sweep_cache *sweepcache = NULL; + spectool_sample_sweep *sb = NULL; + spectool_sweep_cache *sweepcache = NULL; spectool_server sr; - char errstr[WISPY_ERROR_MAX]; + char errstr[SPECTOOL_ERROR_MAX]; int ret; WINDOW *window; @@ -72,7 +79,7 @@ char *neturl = NULL; - ndev = wispy_device_scan(&list); + ndev = spectool_device_scan(&list); while (1) { int o = getopt_long(argc, argv, "n:ld:r:h", @@ -115,7 +122,7 @@ if (list_only) { if (ndev <= 0) { - printf("No wispy devices found, bailing\n"); + printf("No spectool devices found, bailing\n"); exit(1); } @@ -126,7 +133,7 @@ x, list.list[x].name, list.list[x].device_id); for (r = 0; r < list.list[x].num_sweep_ranges; r++) { - wispy_sample_sweep *ran = + spectool_sample_sweep *ran = &(list.list[x].supported_ranges[r]); printf(" Range %d: \"%s\" %d%s-%d%s @ %0.2f%s, %d samples\n", r, @@ -164,11 +171,11 @@ printf("Connected to server, waiting for device list...\n"); } else if (neturl == NULL) { if (ndev <= 0) { - printf("No wispy devices found, bailing\n"); + printf("No spectool devices found, bailing\n"); exit(1); } - printf("Found %d wispy devices...\n", ndev); + printf("Found %d spectool devices...\n", ndev); if (ndev > 1 && device == -1) { printf("spectool-curses can only display one device, specify one with " @@ -184,32 +191,32 @@ exit(1); } - dev = (wispy_phy *) malloc(WISPY_PHY_SIZE); + dev = (spectool_phy *) malloc(SPECTOOL_PHY_SIZE); dev->next = NULL; - if (wispy_device_init(dev, &(list.list[device])) < 0) { + if (spectool_device_init(dev, &(list.list[device])) < 0) { printf("Error initializing WiSPY device %s id %u\n", list.list[device].name, list.list[device].device_id); - printf("%s\n", wispy_get_error(dev)); + printf("%s\n", spectool_get_error(dev)); exit(1); } - if (wispy_phy_open(dev) < 0) { + if (spectool_phy_open(dev) < 0) { printf("Error opening WiSPY device %s id %u\n", list.list[device].name, list.list[device].device_id); - printf("%s\n", wispy_get_error(dev)); + printf("%s\n", spectool_get_error(dev)); exit(1); } - wispy_phy_setcalibration(dev, 1); + spectool_phy_setcalibration(dev, 1); /* Configure the range */ - wispy_phy_setposition(dev, range, 0, 0); + spectool_phy_setposition(dev, range, 0, 0); - wispy_device_scan_free(&list); + spectool_device_scan_free(&list); } - sweepcache = wispy_cache_alloc(50, 1, 1); + sweepcache = spectool_cache_alloc(50, 1, 1); /* Fire up curses */ initscr(); @@ -223,6 +230,9 @@ init_pair(4, COLOR_YELLOW, COLOR_BLACK); init_pair(5, COLOR_YELLOW, COLOR_BLUE); init_pair(6, COLOR_YELLOW, COLOR_GREEN); + init_pair(7, COLOR_BLACK, COLOR_RED); + + nodelay(stdscr, TRUE); window = subwin(stdscr, LINES - 2, COLS - 5, 0, 5); sigwin = subwin(stdscr, LINES - 2, 5, 0, 0); @@ -235,20 +245,42 @@ refresh(); /* Naive poll that doesn't use select() to find pending data */ - while (1) { + int do_main_loop = TRUE; + int is_paused = FALSE; + while (do_main_loop == TRUE) { fd_set rfds; fd_set wfds; int maxfd = 0; struct timeval tm; + switch (getch()) { + case 0x71: // 'q' + do_main_loop = FALSE; + continue; + case 0x70: // 'p' + if (is_paused == TRUE) + is_paused = FALSE; + else { + is_paused = TRUE; + wcolor_set(window, 7, NULL); + mvwaddstr(window, 1, 1, "Paused !"); + wrefresh(window); + } + break; + case ERR: // no key pressed + break; + default: + break; + } + FD_ZERO(&rfds); FD_ZERO(&wfds); - if (wispy_phy_getpollfd(dev) >= 0) { - FD_SET(wispy_phy_getpollfd(dev), &rfds); + if (spectool_phy_getpollfd(dev) >= 0) { + FD_SET(spectool_phy_getpollfd(dev), &rfds); - if (wispy_phy_getpollfd(dev) > maxfd) - maxfd = wispy_phy_getpollfd(dev); + if (spectool_phy_getpollfd(dev) > maxfd) + maxfd = spectool_phy_getpollfd(dev); } if (neturl != NULL) { @@ -270,17 +302,13 @@ tm.tv_sec = 0; tm.tv_usec = 10000; - if (select(maxfd + 1, &rfds, &wfds, NULL, &tm) < 0) { - printf("wispy_raw select() error: %s\n", strerror(errno)); - exit(1); - } + if (select(maxfd + 1, &rfds, &wfds, NULL, &tm) < 0) + fatal_error(1, "spectool_raw select() error: %s\n", strerror(errno)); if (spectool_netcli_getwritefd(&sr) >= 0 && FD_ISSET(spectool_netcli_getwritefd(&sr), &wfds)) { - if (spectool_netcli_writepoll(&sr, errstr) < 0) { - printf("Error write-polling network server %s\n", errstr); - exit(1); - } + if (spectool_netcli_writepoll(&sr, errstr) < 0) + fatal_error(1, "Error write-polling network server %s\n", errstr); } ret = SPECTOOL_NETCLI_POLL_ADDITIONAL; @@ -288,10 +316,8 @@ FD_ISSET(spectool_netcli_getpollfd(&sr), &rfds) && (ret & SPECTOOL_NETCLI_POLL_ADDITIONAL)) { - if ((ret = spectool_netcli_poll(&sr, errstr)) < 0) { - printf("Error polling network server %s\n", errstr); - exit(1); - } + if ((ret = spectool_netcli_poll(&sr, errstr)) < 0) + fatal_error(1, "Error polling network server %s\n", errstr); if ((ret & SPECTOOL_NETCLI_POLL_NEWDEVS)) { /* Only enable the first device */ @@ -301,53 +327,55 @@ } } - if (wispy_phy_getpollfd(dev) < 0) { - if (wispy_get_state(dev) == WISPY_STATE_ERROR) { - printf("Error polling wispy device %s\n", - wispy_phy_getname(dev)); - printf("%s\n", wispy_get_error(dev)); - exit(1); - } + if (spectool_phy_getpollfd(dev) < 0) { + if (spectool_get_state(dev) == SPECTOOL_STATE_ERROR) + fatal_error(1, "Error polling spectool device %s\n%s\n", + spectool_phy_getname(dev), + spectool_get_error(dev)); } - if (FD_ISSET(wispy_phy_getpollfd(dev), &rfds) == 0) { + if (FD_ISSET(spectool_phy_getpollfd(dev), &rfds) == 0) { continue; } do { - r = wispy_phy_poll(dev); + r = spectool_phy_poll(dev); - if ((r & WISPY_POLL_CONFIGURED)) { - wispy_sample_sweep *ran = &(dev->device_spec->supported_ranges[0]); + if ((r & SPECTOOL_POLL_CONFIGURED)) { + spectool_sample_sweep *ran = &(dev->device_spec->supported_ranges[0]); amp_offset_mdbm = ran->amp_offset_mdbm; amp_res_mdbm = ran->amp_res_mdbm; base_db_offset = - WISPY_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, + SPECTOOL_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, ran->rssi_max); min_db_draw = - WISPY_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, 0); + SPECTOOL_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, 0); continue; - } else if ((r & WISPY_POLL_ERROR)) { - printf("Error polling wispy device %s\n", - wispy_phy_getname(dev)); - printf("%s\n", wispy_get_error(dev)); - exit(1); - } else if ((r & WISPY_POLL_SWEEPCOMPLETE)) { - sb = wispy_phy_getsweep(dev); + } else if ((r & SPECTOOL_POLL_ERROR)) { + fatal_error(1, "Error polling spectool device %s\n%s\n", + spectool_phy_getname(dev), + spectool_get_error(dev)); + } else if ((r & SPECTOOL_POLL_SWEEPCOMPLETE)) { + sb = spectool_phy_getsweep(dev); if (sb == NULL) continue; - wispy_cache_append(sweepcache, sb); + spectool_cache_append(sweepcache, sb); min_db_draw = - WISPY_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, + SPECTOOL_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, sb->min_rssi_seen > 2 ? sb->min_rssi_seen - 1 : sb->min_rssi_seen); } - } while ((r & WISPY_POLL_ADDITIONAL)); + } while ((r & SPECTOOL_POLL_ADDITIONAL)); + + // TODO: allow pausing without polling. + // currently this would cause a timeout + if (is_paused == TRUE) + continue; /* Redraw the windows */ werase(sigwin); @@ -371,7 +399,7 @@ (float) ((float) (abs(x) + base_db_offset) / (float) (abs(min_db_draw) + base_db_offset)); - snprintf(errstr, WISPY_ERROR_MAX, "%d", x); + snprintf(errstr, SPECTOOL_ERROR_MAX, "%d", x); mvwaddstr(sigwin, py + 1, 0, errstr); } @@ -411,8 +439,8 @@ if (nuse == 0) continue; - avg = WISPY_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, (avg / nuse)); - avgc = WISPY_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, (avgc / nuse)); + avg = SPECTOOL_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, (avg / nuse)); + avgc = SPECTOOL_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, (avgc / nuse)); py = (float) (LINES - 4) * (float) ((float) (abs(avg) + base_db_offset) / @@ -464,8 +492,8 @@ if (nuse == 0) continue; - avg = WISPY_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, (avg / nuse)); - avgc = WISPY_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, (avgc / nuse)); + avg = SPECTOOL_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, (avg / nuse)); + avgc = SPECTOOL_RSSI_CONVERT(amp_offset_mdbm, amp_res_mdbm, (avgc / nuse)); py = (float) (LINES - 4) * (float) ((float) (abs(avg) + base_db_offset) / diff -Nru spectools-201004R1/spectool_gtk.c spectools-201108r1/spectool_gtk.c --- spectools-201004R1/spectool_gtk.c 2009-01-25 07:01:09.000000000 +0000 +++ spectools-201108r1/spectool_gtk.c 2011-06-15 19:53:10.000000000 +0000 @@ -36,7 +36,7 @@ #define GETTEXT_PACKAGE "spectool_gtk" #define LOCALEDIR "/usr/share/locale/spectool_gtk" -void Wispy_Alert_Dialog(char *text) { +void Spectool_Alert_Dialog(char *text) { GtkWidget *dialog, *okbutton, *label; label = gtk_label_new(text); @@ -54,7 +54,7 @@ gtk_widget_show_all(dialog); } -void Wispy_Help_Dialog(char *title, char *text) { +void Spectool_Help_Dialog(char *title, char *text) { GtkWidget *dialog, *scroll, *okbutton, *label; label = gtk_label_new(NULL); @@ -74,7 +74,7 @@ } typedef struct _wg_aux { - wispy_device_registry *wdr; + spectool_device_registry *wdr; GtkWidget *main_vbox; GtkWidget *main_window; GtkWidget *notebook; @@ -87,13 +87,13 @@ wg_aux *auxptr; GtkWidget *planar, *spectral, *topo, *channel; - WispyWidgetController *p_con, *s_con, *t_con; + SpectoolWidgetController *p_con, *s_con, *t_con; gint pagenum; - WispyChannelOpts *chanopts; + SpectoolChannelOpts *chanopts; - wispy_phy *phydev; + spectool_phy *phydev; int wdr_slot; GList *wdr_menu; } nb_aux; @@ -106,14 +106,14 @@ g_return_if_fail(aux != NULL); - wispy_widget_bind_dev(nbaux->planar, nbaux->auxptr->wdr, slot); - wispy_widget_bind_dev(nbaux->topo, nbaux->auxptr->wdr, slot); - wispy_widget_bind_dev(nbaux->spectral, nbaux->auxptr->wdr, slot); - wispy_widget_bind_dev(nbaux->channel, nbaux->auxptr->wdr, slot); + spectool_widget_bind_dev(nbaux->planar, nbaux->auxptr->wdr, slot); + spectool_widget_bind_dev(nbaux->topo, nbaux->auxptr->wdr, slot); + spectool_widget_bind_dev(nbaux->spectral, nbaux->auxptr->wdr, slot); + spectool_widget_bind_dev(nbaux->channel, nbaux->auxptr->wdr, slot); nbaux->phydev = wdr_get_phy(nbaux->auxptr->wdr, slot); - gtk_label_set_text(GTK_LABEL(nbaux->nblabel), wispy_phy_getname(nbaux->phydev)); + gtk_label_set_text(GTK_LABEL(nbaux->nblabel), spectool_phy_getname(nbaux->phydev)); gtk_widget_hide(nbaux->nodev_vbox); @@ -321,34 +321,34 @@ gtk_widget_show(nbaux->nblabel); /* Make the inactive devices */ - nbaux->chanopts = (WispyChannelOpts *) malloc(sizeof(WispyChannelOpts)); - wispychannelopts_init(nbaux->chanopts); + nbaux->chanopts = (SpectoolChannelOpts *) malloc(sizeof(SpectoolChannelOpts)); + spectoolchannelopts_init(nbaux->chanopts); - nbaux->channel = wispy_channel_new(); - wispy_widget_link_channel(nbaux->channel, nbaux->chanopts); + nbaux->channel = spectool_channel_new(); + spectool_widget_link_channel(nbaux->channel, nbaux->chanopts); gtk_box_pack_end(GTK_BOX(nbaux->nbvbox), nbaux->channel, FALSE, FALSE, 0); - nbaux->planar = wispy_planar_new(); - wispy_widget_link_channel(nbaux->planar, nbaux->chanopts); - nbaux->p_con = wispy_widget_buildcontroller(GTK_WIDGET(nbaux->planar)); + nbaux->planar = spectool_planar_new(); + spectool_widget_link_channel(nbaux->planar, nbaux->chanopts); + nbaux->p_con = spectool_widget_buildcontroller(GTK_WIDGET(nbaux->planar)); gtk_box_pack_end(GTK_BOX(nbaux->nbvbox), nbaux->planar, TRUE, TRUE, 0); gtk_box_pack_end(GTK_BOX(nbaux->nbvbox), nbaux->p_con->evbox, FALSE, FALSE, 2); - nbaux->topo = wispy_topo_new(); - wispy_widget_link_channel(nbaux->topo, nbaux->chanopts); - nbaux->t_con = wispy_widget_buildcontroller(GTK_WIDGET(nbaux->topo)); + nbaux->topo = spectool_topo_new(); + spectool_widget_link_channel(nbaux->topo, nbaux->chanopts); + nbaux->t_con = spectool_widget_buildcontroller(GTK_WIDGET(nbaux->topo)); gtk_box_pack_end(GTK_BOX(nbaux->nbvbox), nbaux->topo, TRUE, TRUE, 0); gtk_box_pack_end(GTK_BOX(nbaux->nbvbox), nbaux->t_con->evbox, FALSE, FALSE, 2); - nbaux->spectral = wispy_spectral_new(); - wispy_widget_link_channel(nbaux->spectral, nbaux->chanopts); - nbaux->s_con = wispy_widget_buildcontroller(GTK_WIDGET(nbaux->spectral)); + nbaux->spectral = spectool_spectral_new(); + spectool_widget_link_channel(nbaux->spectral, nbaux->chanopts); + nbaux->s_con = spectool_widget_buildcontroller(GTK_WIDGET(nbaux->spectral)); gtk_box_pack_end(GTK_BOX(nbaux->nbvbox), nbaux->spectral, TRUE, TRUE, 0); gtk_box_pack_end(GTK_BOX(nbaux->nbvbox), nbaux->s_con->evbox, FALSE, FALSE, 2); - wispy_channel_append_update(nbaux->channel, nbaux->planar); - wispy_channel_append_update(nbaux->channel, nbaux->topo); - wispy_channel_append_update(nbaux->channel, nbaux->spectral); + spectool_channel_append_update(nbaux->channel, nbaux->planar); + spectool_channel_append_update(nbaux->channel, nbaux->topo); + spectool_channel_append_update(nbaux->channel, nbaux->spectral); gtk_widget_show(nbaux->nbvbox); @@ -379,7 +379,7 @@ nb_aux *nbfirst; #if 0 - GtkWidget *menubar, *menu, *mn_wispy, *menuitem; + GtkWidget *menubar, *menu, *mn_spectool, *menuitem; #endif GtkWidget *menubar; @@ -387,11 +387,11 @@ GtkItemFactory *item_factory; GtkAccelGroup *accel_group; - wispy_device_registry wdr; + spectool_device_registry wdr; int x; - char errstr[WISPY_ERROR_MAX]; + char errstr[SPECTOOL_ERROR_MAX]; setlocale(LC_ALL, ""); bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); @@ -404,7 +404,7 @@ /* Turn on broadcast autodetection */ if (wdr_enable_bcast(&wdr, errstr) < 0) { - Wispy_Alert_Dialog(errstr); + Spectool_Alert_Dialog(errstr); } window = gtk_window_new(GTK_WINDOW_TOPLEVEL); @@ -415,6 +415,8 @@ g_signal_connect(G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL); + g_signal_connect(G_OBJECT (window), "destroy", + G_CALLBACK (gtk_main_quit), NULL); accel_group = gtk_accel_group_new(); diff -Nru spectools-201004R1/spectool_gtk_channel.c spectools-201108r1/spectool_gtk_channel.c --- spectools-201004R1/spectool_gtk_channel.c 2007-10-03 19:56:37.000000000 +0000 +++ spectools-201108r1/spectool_gtk_channel.c 2011-06-10 15:53:29.000000000 +0000 @@ -21,31 +21,31 @@ #include "spectool_gtk_channel.h" -static void wispy_channel_class_init(WispyChannelClass *class); -static void wispy_channel_init(WispyChannel *graph); -static void wispy_channel_destroy(GtkObject *object); +static void spectool_channel_class_init(SpectoolChannelClass *class); +static void spectool_channel_init(SpectoolChannel *graph); +static void spectool_channel_destroy(GtkObject *object); -static gint wispy_channel_configure(GtkWidget *widget, +static gint spectool_channel_configure(GtkWidget *widget, GdkEventConfigure *event); -static gboolean wispy_channel_expose(GtkWidget *widget, +static gboolean spectool_channel_expose(GtkWidget *widget, GdkEventExpose *event, gpointer *aux); -static gboolean wispy_channel_button_press(GtkWidget *widget, +static gboolean spectool_channel_button_press(GtkWidget *widget, GdkEventButton *event, gpointer *aux); -static gboolean wispy_channel_mouse_move(GtkWidget *widget, +static gboolean spectool_channel_mouse_move(GtkWidget *widget, GdkEventMotion *event, gpointer *aux); -G_DEFINE_TYPE(WispyChannel, wispy_channel, WISPY_TYPE_WIDGET); +G_DEFINE_TYPE(SpectoolChannel, spectool_channel, SPECTOOL_TYPE_WIDGET); -inline int wispy_channel_find_chan_pt(WispyChannel *cwidget, int x, int y) { +inline int spectool_channel_find_chan_pt(SpectoolChannel *cwidget, int x, int y) { int dbm, maxy, nchannels; - WispyWidget *wwidget; + SpectoolWidget *wwidget; g_return_if_fail(cwidget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(cwidget)); - wwidget = WISPY_WIDGET(cwidget); + g_return_if_fail(IS_SPECTOOL_WIDGET(cwidget)); + wwidget = SPECTOOL_WIDGET(cwidget); /* Only compute if we know a chanset and if we're inside the bounding * box */ @@ -79,15 +79,15 @@ return -1; } -void wispy_channel_draw(GtkWidget *widget, cairo_t *cr, WispyWidget *wwidget) { - WispyChannel *channel; +void spectool_channel_draw(GtkWidget *widget, cairo_t *cr, SpectoolWidget *wwidget) { + SpectoolChannel *channel; cairo_text_extents_t extents; int x, chpix; char mtext[128]; g_return_if_fail(widget != NULL); - channel = WISPY_CHANNEL(wwidget); + channel = SPECTOOL_CHANNEL(wwidget); cairo_save(cr); @@ -216,20 +216,20 @@ } } -static gint wispy_channel_button_press(GtkWidget *widget, +static gint spectool_channel_button_press(GtkWidget *widget, GdkEventButton *event, gpointer *aux) { - WispyChannel *channel; - WispyWidget *wwidget; + SpectoolChannel *channel; + SpectoolWidget *wwidget; int ch; GList *upd_iter; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_CHANNEL(aux)); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_CHANNEL(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - channel = WISPY_CHANNEL(aux); - wwidget = WISPY_WIDGET(aux); + channel = SPECTOOL_CHANNEL(aux); + wwidget = SPECTOOL_WIDGET(aux); g_return_if_fail(wwidget->chanopts != NULL); g_return_if_fail(wwidget->chanopts->chanset != NULL); @@ -239,7 +239,7 @@ if (event->button != 1) return TRUE; - if ((ch = wispy_channel_find_chan_pt(channel, event->x, event->y)) > -1) { + if ((ch = spectool_channel_find_chan_pt(channel, event->x, event->y)) > -1) { /* Should never get here if we don't have a chanset, do some * checking anyhow though */ if (ch < 0 || ch > wwidget->chanopts->chanset->chan_num) @@ -255,11 +255,11 @@ } - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_update(GTK_WIDGET(wwidget)); upd_iter = channel->update_list; while (upd_iter != NULL) { - wispy_widget_update(GTK_WIDGET(upd_iter->data)); + spectool_widget_update(GTK_WIDGET(upd_iter->data)); upd_iter = g_list_next(upd_iter); continue; @@ -268,22 +268,22 @@ return TRUE; } -static gboolean wispy_channel_mouse_move(GtkWidget *widget, +static gboolean spectool_channel_mouse_move(GtkWidget *widget, GdkEventMotion *event, gpointer *aux) { int x, y; int ch; GdkModifierType state; - WispyChannel *channel; - WispyWidget *wwidget; + SpectoolChannel *channel; + SpectoolWidget *wwidget; GList *upd_iter; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_CHANNEL(aux)); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_CHANNEL(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - channel = WISPY_CHANNEL(aux); - wwidget = WISPY_WIDGET(aux); + channel = SPECTOOL_CHANNEL(aux); + wwidget = SPECTOOL_WIDGET(aux); g_return_if_fail(wwidget->sweepcache != NULL); g_return_if_fail(wwidget->sweepcache->latest != NULL); @@ -301,14 +301,14 @@ g_return_if_fail(wwidget->chanopts != NULL); g_return_if_fail(wwidget->chanopts->chanset != NULL); - if ((ch = wispy_channel_find_chan_pt(channel, x, y)) >= -1) { + if ((ch = spectool_channel_find_chan_pt(channel, x, y)) >= -1) { if (ch != wwidget->chanopts->hi_chan) { wwidget->chanopts->hi_chan = ch; - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_update(GTK_WIDGET(wwidget)); upd_iter = channel->update_list; while (upd_iter != NULL) { - wispy_widget_update(GTK_WIDGET(upd_iter->data)); + spectool_widget_update(GTK_WIDGET(upd_iter->data)); upd_iter = g_list_next(upd_iter); continue; @@ -316,11 +316,11 @@ } } else if (wwidget->chanopts->hi_chan > -1) { wwidget->chanopts->hi_chan = -1; - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_update(GTK_WIDGET(wwidget)); upd_iter = channel->update_list; while (upd_iter != NULL) { - wispy_widget_update(GTK_WIDGET(upd_iter->data)); + spectool_widget_update(GTK_WIDGET(upd_iter->data)); upd_iter = g_list_next(upd_iter); continue; @@ -330,16 +330,16 @@ return TRUE; } -void wispy_channel_update(GtkWidget *widget) { - WispyWidget *wwidget; - WispyChannel *channel; +void spectool_channel_update(GtkWidget *widget) { + SpectoolWidget *wwidget; + SpectoolChannel *channel; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); - g_return_if_fail(IS_WISPY_CHANNEL(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_CHANNEL(widget)); - wwidget = WISPY_WIDGET(widget); - channel = WISPY_CHANNEL(widget); + wwidget = SPECTOOL_WIDGET(widget); + channel = SPECTOOL_CHANNEL(widget); g_return_if_fail(wwidget->draw != NULL); @@ -350,8 +350,8 @@ return; } -static void wispy_channel_size_request (GtkWidget *widget, GtkRequisition *requisition) { - WispyWidget *wwidget = WISPY_WIDGET(widget); +static void spectool_channel_size_request (GtkWidget *widget, GtkRequisition *requisition) { + SpectoolWidget *wwidget = SPECTOOL_WIDGET(widget); requisition->width = 0; requisition->height = 25; @@ -366,7 +366,7 @@ } } -static void wispy_channel_class_init(WispyChannelClass *class) { +static void spectool_channel_class_init(SpectoolChannelClass *class) { GObjectClass *gobject_class; GtkObjectClass *object_class; GtkWidgetClass *widget_class; @@ -375,44 +375,44 @@ object_class = GTK_OBJECT_CLASS(class); widget_class = GTK_WIDGET_CLASS(class); - object_class->destroy = wispy_channel_destroy; + object_class->destroy = spectool_channel_destroy; - widget_class->size_request = wispy_channel_size_request; + widget_class->size_request = spectool_channel_size_request; } -static void wispy_channel_destroy(GtkObject *object) { - WispyChannel *channel = WISPY_CHANNEL(object); - WispyWidget *wwidget; +static void spectool_channel_destroy(GtkObject *object) { + SpectoolChannel *channel = SPECTOOL_CHANNEL(object); + SpectoolWidget *wwidget; - wwidget = WISPY_WIDGET(channel); + wwidget = SPECTOOL_WIDGET(channel); - GTK_OBJECT_CLASS(wispy_channel_parent_class)->destroy(object); + GTK_OBJECT_CLASS(spectool_channel_parent_class)->destroy(object); } -GtkWidget *wispy_channel_new() { - WispyChannel *channel; - WispyWidget *wwidget; +GtkWidget *spectool_channel_new() { + SpectoolChannel *channel; + SpectoolWidget *wwidget; - channel = gtk_type_new(wispy_channel_get_type()); + channel = gtk_type_new(spectool_channel_get_type()); printf("debug - channel new %p widget %p\n", channel, GTK_WIDGET(channel)); - wwidget = WISPY_WIDGET(channel); + wwidget = SPECTOOL_WIDGET(channel); return GTK_WIDGET(channel); } -static void wispy_channel_wdr_sweep(int slot, int mode, - wispy_sample_sweep *sweep, void *aux) { - WispyChannel *cwidget; - WispyWidget *wwidget; +static void spectool_channel_wdr_sweep(int slot, int mode, + spectool_sample_sweep *sweep, void *aux) { + SpectoolChannel *cwidget; + SpectoolWidget *wwidget; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_CHANNEL(aux)); + g_return_if_fail(IS_SPECTOOL_CHANNEL(aux)); - cwidget = WISPY_CHANNEL(aux); - wwidget = WISPY_WIDGET(aux); + cwidget = SPECTOOL_CHANNEL(aux); + wwidget = SPECTOOL_WIDGET(aux); - if ((mode & WISPY_POLL_CONFIGURED)) { + if ((mode & SPECTOOL_POLL_CONFIGURED)) { if (wwidget->chanopts == NULL) return; @@ -426,11 +426,11 @@ } } -static void wispy_channel_init(WispyChannel *channel) { - WispyWidget *wwidget; +static void spectool_channel_init(SpectoolChannel *channel) { + SpectoolWidget *wwidget; GtkWidget *temp; - wwidget = WISPY_WIDGET(channel); + wwidget = SPECTOOL_WIDGET(channel); channel->chan_points = NULL; channel->chan_h = -1; @@ -445,29 +445,29 @@ wwidget->graph_control_bg = "#ABBBBB"; wwidget->show_channels = 1; - wwidget->wdr_sweep_func = wispy_channel_wdr_sweep; + wwidget->wdr_sweep_func = spectool_channel_wdr_sweep; wwidget->wdr_devbind_func = NULL; - wwidget->draw_mouse_move_func = wispy_channel_mouse_move; - wwidget->draw_mouse_click_func = wispy_channel_button_press; + wwidget->draw_mouse_move_func = spectool_channel_mouse_move; + wwidget->draw_mouse_click_func = spectool_channel_button_press; wwidget->draw_timeout = 1000; - wwidget->draw_func = wispy_channel_draw; - wwidget->update_func = wispy_channel_update; + wwidget->draw_func = spectool_channel_draw; + wwidget->update_func = spectool_channel_update; wwidget->timeout_ref = g_timeout_add(wwidget->draw_timeout, - (GSourceFunc) wispy_widget_timeout, wwidget); + (GSourceFunc) spectool_widget_timeout, wwidget); - wispy_widget_buildgui(wwidget); + spectool_widget_buildgui(wwidget); } -void wispy_channel_append_update(GtkWidget *widget, GtkWidget *update) { - WispyChannel *channel; +void spectool_channel_append_update(GtkWidget *widget, GtkWidget *update) { + SpectoolChannel *channel; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_CHANNEL(widget)); + g_return_if_fail(IS_SPECTOOL_CHANNEL(widget)); - channel = WISPY_CHANNEL(widget); + channel = SPECTOOL_CHANNEL(widget); channel->update_list = g_list_append(channel->update_list, update); } diff -Nru spectools-201004R1/spectool_gtk_channel.h spectools-201108r1/spectool_gtk_channel.h --- spectools-201004R1/spectool_gtk_channel.h 2007-10-03 18:31:56.000000000 +0000 +++ spectools-201108r1/spectool_gtk_channel.h 2011-06-10 15:53:29.000000000 +0000 @@ -1,4 +1,4 @@ -/* Wispy signal graph +/* Spectool signal graph * * GTK widget implementation * @@ -20,8 +20,8 @@ #include "config.h" -#ifndef __WISPY_CHANNEL_WIDGET_H__ -#define __WISPY_CHANNEL_WIDGET_H__ +#ifndef __SPECTOOL_CHANNEL_WIDGET_H__ +#define __SPECTOOL_CHANNEL_WIDGET_H__ #ifdef HAVE_GTK @@ -34,28 +34,28 @@ G_BEGIN_DECLS -#define WISPY_TYPE_CHANNEL \ - (wispy_channel_get_type()) -#define WISPY_CHANNEL(obj) \ +#define SPECTOOL_TYPE_CHANNEL \ + (spectool_channel_get_type()) +#define SPECTOOL_CHANNEL(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - WISPY_TYPE_CHANNEL, WispyChannel)) -#define WISPY_CHANNEL_CLASS(klass) \ + SPECTOOL_TYPE_CHANNEL, SpectoolChannel)) +#define SPECTOOL_CHANNEL_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass), \ - WISPY_TYPE_CHANNEL, WispyChannelClass)) -#define IS_WISPY_CHANNEL(obj) \ + SPECTOOL_TYPE_CHANNEL, SpectoolChannelClass)) +#define IS_SPECTOOL_CHANNEL(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - WISPY_TYPE_CHANNEL)) -#define IS_WISPY_CHANNEL_CLASS(klass) \ + SPECTOOL_TYPE_CHANNEL)) +#define IS_SPECTOOL_CHANNEL_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((class), \ - WISPY_TYPE_CHANNEL)) + SPECTOOL_TYPE_CHANNEL)) -typedef struct _WispyChannel WispyChannel; -typedef struct _WispyChannelClass WispyChannelClass; +typedef struct _SpectoolChannel SpectoolChannel; +typedef struct _SpectoolChannelClass SpectoolChannelClass; -#define WISPY_CHANNEL_NUM_SAMPLES 0 +#define SPECTOOL_CHANNEL_NUM_SAMPLES 0 -struct _WispyChannel { - WispyWidget parent; +struct _SpectoolChannel { + SpectoolWidget parent; /* is the mouse down during an event? */ int mouse_down; @@ -68,13 +68,13 @@ GList *update_list; }; -struct _WispyChannelClass { - WispyWidgetClass parent_class; +struct _SpectoolChannelClass { + SpectoolWidgetClass parent_class; }; -GType wispy_channel_get_type(void); -GtkWidget *wispy_channel_new(); -void wispy_channel_append_update(GtkWidget *widget, GtkWidget *update); +GType spectool_channel_get_type(void); +GtkWidget *spectool_channel_new(); +void spectool_channel_append_update(GtkWidget *widget, GtkWidget *update); G_END_DECLS diff -Nru spectools-201004R1/spectool_gtk.h spectools-201108r1/spectool_gtk.h --- spectools-201004R1/spectool_gtk.h 2007-08-22 23:41:09.000000000 +0000 +++ spectools-201108r1/spectool_gtk.h 2011-06-10 15:53:29.000000000 +0000 @@ -16,8 +16,8 @@ #include "config.h" -#ifndef __WISPY_GTK_H__ -#define __WISPY_GTK_H__ +#ifndef __SPECTOOL_GTK_H__ +#define __SPECTOOL_GTK_H__ #ifdef HAVE_GTK @@ -26,9 +26,9 @@ #include #include -void Wispy_Alert_Dialog(char *text); +void Spectool_Alert_Dialog(char *text); -void Wispy_Help_Dialog(char *title, char *text); +void Spectool_Help_Dialog(char *title, char *text); #endif #endif diff -Nru spectools-201004R1/spectool_gtk_hw_registry.c spectools-201108r1/spectool_gtk_hw_registry.c --- spectools-201004R1/spectool_gtk_hw_registry.c 2009-02-28 04:34:47.000000000 +0000 +++ spectools-201108r1/spectool_gtk_hw_registry.c 2011-06-10 15:53:29.000000000 +0000 @@ -21,7 +21,7 @@ #include "spectool_net.h" #include "spectool_net_client.h" -void wdr_init(wispy_device_registry *wdr) { +void wdr_init(spectool_device_registry *wdr) { int x = 0; wdr->max_dev = WDR_MAX_DEV - 1; @@ -41,7 +41,7 @@ wdr->bcastsock = -1; } -void wdr_free(wispy_device_registry *wdr) { +void wdr_free(spectool_device_registry *wdr) { int x = 0; for (x = 0; x < WDR_MAX_DEV; x++) { @@ -49,7 +49,7 @@ continue; /* Close it */ - wispy_phy_close(wdr->devices[x]->phydev); + spectool_phy_close(wdr->devices[x]->phydev); g_list_free(wdr->devices[x]->sweep_cb_l); @@ -61,10 +61,10 @@ } } -int wdr_open_add(wispy_device_registry *wdr, wispy_device_rec *devrec, int pos, +int wdr_open_add(spectool_device_registry *wdr, spectool_device_rec *devrec, int pos, char *errstr) { int x; - wispy_phy *phydev; + spectool_phy *phydev; wdr_reg_dev *regdev; for (x = 0; x < wdr->max_dev; x++) { @@ -78,32 +78,32 @@ } if (wdr->cur_dev >= wdr->max_dev) { - snprintf(errstr, WISPY_ERROR_MAX, "WDR registry full"); + snprintf(errstr, SPECTOOL_ERROR_MAX, "WDR registry full"); return -1; } - phydev = (wispy_phy *) malloc(WISPY_PHY_SIZE); + phydev = (spectool_phy *) malloc(SPECTOOL_PHY_SIZE); - if (wispy_device_init(phydev, devrec) < 0) { + if (spectool_device_init(phydev, devrec) < 0) { printf("deug - wdr devinit failed\n"); - snprintf(errstr, WISPY_ERROR_MAX, "Error initializing WiSPY device %s: %s", - devrec->name, wispy_get_error(phydev)); + snprintf(errstr, SPECTOOL_ERROR_MAX, "Error initializing WiSPY device %s: %s", + devrec->name, spectool_get_error(phydev)); free(phydev); return -1; } - if (wispy_phy_open(phydev) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "Error opening WiSPY device %s: %s", - devrec->name, wispy_get_error(phydev)); + if (spectool_phy_open(phydev) < 0) { + snprintf(errstr, SPECTOOL_ERROR_MAX, "Error opening WiSPY device %s: %s", + devrec->name, spectool_get_error(phydev)); free(phydev); return -1; } /* We always want to calibrate it, imho */ - wispy_phy_setcalibration(phydev, 1); + spectool_phy_setcalibration(phydev, 1); /* Set the position to 0 for now */ - wispy_phy_setposition(phydev, pos, 0, 0); + spectool_phy_setposition(phydev, pos, 0, 0); regdev = (wdr_reg_dev *) malloc(sizeof(wdr_reg_dev)); regdev->phydev = phydev; @@ -116,7 +116,7 @@ regdev->poll_rec = (wdr_poll_rec *) malloc(sizeof(wdr_poll_rec)); ((wdr_poll_rec *) regdev->poll_rec)->wdr = wdr; - regdev->poll_tag = gdk_input_add(wispy_phy_getpollfd(phydev), + regdev->poll_tag = gdk_input_add(spectool_phy_getpollfd(phydev), GDK_INPUT_READ, wdr_poll, regdev->poll_rec); @@ -136,7 +136,7 @@ return x; } -int wdr_open_phy(wispy_device_registry *wdr, wispy_phy *phydev, char *errstr) { +int wdr_open_phy(spectool_device_registry *wdr, spectool_phy *phydev, char *errstr) { int x; wdr_reg_dev *regdev; @@ -145,13 +145,13 @@ continue; if (wdr->devices[x]->phydev->device_spec->device_id == - wispy_phy_getdevid(phydev)) { + spectool_phy_getdevid(phydev)) { return x; } } if (wdr->cur_dev >= wdr->max_dev) { - snprintf(errstr, WISPY_ERROR_MAX, "WDR registry full"); + snprintf(errstr, SPECTOOL_ERROR_MAX, "WDR registry full"); return -1; } @@ -166,7 +166,7 @@ regdev->poll_rec = (wdr_poll_rec *) malloc(sizeof(wdr_poll_rec)); ((wdr_poll_rec *) regdev->poll_rec)->wdr = wdr; - regdev->poll_tag = gdk_input_add(wispy_phy_getpollfd(phydev), + regdev->poll_tag = gdk_input_add(spectool_phy_getpollfd(phydev), GDK_INPUT_READ, wdr_poll, regdev->poll_rec); @@ -186,7 +186,7 @@ return x; } -int wdr_open_net(wispy_device_registry *wdr, char *url, char *errstr) { +int wdr_open_net(spectool_device_registry *wdr, char *url, char *errstr) { int x; spectool_server *netptr; @@ -202,7 +202,7 @@ return x; } -int wdr_open_netptr(wispy_device_registry *wdr, spectool_server *netptr, +int wdr_open_netptr(spectool_device_registry *wdr, spectool_server *netptr, char *errstr) { int x; wdr_reg_srv *wrs; @@ -220,7 +220,7 @@ } if (wdr->cur_srv >= wdr->max_srv) { - snprintf(errstr, WISPY_ERROR_MAX, "WDR registry full"); + snprintf(errstr, SPECTOOL_ERROR_MAX, "WDR registry full"); return -1; } @@ -262,7 +262,7 @@ return x; } -void wdr_close_net(wispy_device_registry *wdr, int slot) { +void wdr_close_net(spectool_device_registry *wdr, int slot) { if (slot < 0 || slot > wdr->max_srv) return; @@ -281,8 +281,8 @@ wdr->cur_srv--; } -int wdr_enable_bcast(wispy_device_registry *wdr, char *errstr) { - if ((wdr->bcastsock = spectool_netcli_initbroadcast(WISPY_NET_DEFAULT_PORT, +int wdr_enable_bcast(spectool_device_registry *wdr, char *errstr) { + if ((wdr->bcastsock = spectool_netcli_initbroadcast(SPECTOOL_NET_DEFAULT_PORT, errstr)) < 0) return -1; @@ -293,7 +293,7 @@ return 1; } -void wdr_disable_bcast(wispy_device_registry *wdr) { +void wdr_disable_bcast(spectool_device_registry *wdr) { if (wdr->bcastsock >= 0) { close(wdr->bcastsock); @@ -304,17 +304,17 @@ } gboolean wdr_bcpoll(GIOChannel *ioch, GIOCondition cond, gpointer data) { - wispy_device_registry *wdr = (wispy_device_registry *) data; + spectool_device_registry *wdr = (spectool_device_registry *) data; char bcasturl[SPECTOOL_NETCLI_URL_MAX]; - char errstr[WISPY_ERROR_MAX]; - char reperr[WISPY_ERROR_MAX]; + char errstr[SPECTOOL_ERROR_MAX]; + char reperr[SPECTOOL_ERROR_MAX]; int ret; if ((ret = spectool_netcli_pollbroadcast(wdr->bcastsock, bcasturl, errstr)) < 0) { - snprintf(reperr, WISPY_ERROR_MAX, "Error processing broadcast packet, disabling " + snprintf(reperr, SPECTOOL_ERROR_MAX, "Error processing broadcast packet, disabling " "broadcast detection: %s", errstr); - Wispy_Alert_Dialog(reperr); + Spectool_Alert_Dialog(reperr); wdr_disable_bcast(wdr); return FALSE; } else if (ret > 0) { @@ -324,7 +324,7 @@ return TRUE; } -wispy_phy *wdr_get_phy(wispy_device_registry *wdr, int slot) { +spectool_phy *wdr_get_phy(spectool_device_registry *wdr, int slot) { if (slot < 0 || slot > wdr->max_dev) return; @@ -334,7 +334,7 @@ return wdr->devices[slot]->phydev; } -void wdr_add_ref(wispy_device_registry *wdr, int slot) { +void wdr_add_ref(spectool_device_registry *wdr, int slot) { if (slot < 0 || slot > wdr->max_dev) return; @@ -344,7 +344,7 @@ wdr->devices[slot]->refcount++; } -void wdr_del_ref(wispy_device_registry *wdr, int slot) { +void wdr_del_ref(spectool_device_registry *wdr, int slot) { if (slot < 0 || slot > wdr->max_dev) return; @@ -356,7 +356,7 @@ if (wdr->devices[slot]->refcount > 0) return; - wispy_phy_close(wdr->devices[slot]->phydev); + spectool_phy_close(wdr->devices[slot]->phydev); g_list_free(wdr->devices[slot]->sweep_cb_l); @@ -370,8 +370,8 @@ wdr->cur_dev--; } -void wdr_add_sweepcb(wispy_device_registry *wdr, int slot, - void (*cb)(int, int, wispy_sample_sweep *, void *), +void wdr_add_sweepcb(spectool_device_registry *wdr, int slot, + void (*cb)(int, int, spectool_sample_sweep *, void *), int nagg, void *aux) { wdr_reg_sweep_cb *wdrcb; @@ -389,7 +389,7 @@ if (nagg == 0) { wdrcb->agg_sweep = NULL; } else { - wdrcb->agg_sweep = wispy_cache_alloc(nagg, 1, 0); + wdrcb->agg_sweep = spectool_cache_alloc(nagg, 1, 0); } wdrcb->num_agg = nagg; wdrcb->pos_agg = 0; @@ -398,8 +398,8 @@ g_list_append(wdr->devices[slot]->sweep_cb_l, wdrcb); } -void wdr_del_sweepcb(wispy_device_registry *wdr, int slot, - void (*cb)(int, int, wispy_sample_sweep *, void *), +void wdr_del_sweepcb(spectool_device_registry *wdr, int slot, + void (*cb)(int, int, spectool_sample_sweep *, void *), void *aux) { GList *iter; @@ -425,8 +425,8 @@ } } -void wdr_sweep_update(wispy_device_registry *wdr, int slot, - int mode, wispy_sample_sweep *sweep) { +void wdr_sweep_update(spectool_device_registry *wdr, int slot, + int mode, spectool_sample_sweep *sweep) { GList *iter; wdr_reg_sweep_cb *scb; @@ -447,12 +447,12 @@ if (scb->agg_sweep == NULL || sweep == NULL) { (*(scb->cb))(slot, mode, sweep, scb->aux); } else { - wispy_cache_append(scb->agg_sweep, sweep); + spectool_cache_append(scb->agg_sweep, sweep); scb->pos_agg++; if (scb->pos_agg == scb->num_agg) { (*(scb->cb))(slot, mode, scb->agg_sweep->peak, scb->aux); - wispy_cache_clear(scb->agg_sweep); + spectool_cache_clear(scb->agg_sweep); scb->pos_agg = 0; } } @@ -464,10 +464,10 @@ void wdr_poll(gpointer data, gint source, GdkInputCondition condition) { wdr_poll_rec *wdrpr = (wdr_poll_rec *) data; - wispy_phy *phydev; + spectool_phy *phydev; int r; - char err[WISPY_ERROR_MAX]; - wispy_sample_sweep *sweep; + char err[SPECTOOL_ERROR_MAX]; + spectool_sample_sweep *sweep; if (wdrpr->slot < 0 || wdrpr->slot > wdrpr->wdr->max_dev) return; @@ -478,30 +478,30 @@ phydev = wdrpr->wdr->devices[wdrpr->slot]->phydev; do { - r = wispy_phy_poll(phydev); + r = spectool_phy_poll(phydev); - if ((r & WISPY_POLL_ERROR)) { - snprintf(err, WISPY_ERROR_MAX, "Error polling WiSPY device %s: %s", - wispy_phy_getname(phydev), wispy_get_error(phydev)); - /* wispy_phy_close(phydev); */ + if ((r & SPECTOOL_POLL_ERROR)) { + snprintf(err, SPECTOOL_ERROR_MAX, "Error polling WiSPY device %s: %s", + spectool_phy_getname(phydev), spectool_get_error(phydev)); + /* spectool_phy_close(phydev); */ /* Push the error, this should result in all the graphs removing * their references to us */ wdr_sweep_update(wdrpr->wdr, wdrpr->slot, r, NULL); /* Pop up the error */ - Wispy_Alert_Dialog(err); + Spectool_Alert_Dialog(err); /* remove us from being pollable, free our tracker ref. No-one should * reference us anymore since we told them there was an error, so we * can drop out entirely */ gdk_input_remove(wdrpr->poll_tag); return; - } else if ((r & WISPY_POLL_CONFIGURED)) { + } else if ((r & SPECTOOL_POLL_CONFIGURED)) { wdr_sweep_update(wdrpr->wdr, wdrpr->slot, r, NULL); return; - } else if ((r & WISPY_POLL_SWEEPCOMPLETE)) { - sweep = wispy_phy_getsweep(phydev); + } else if ((r & SPECTOOL_POLL_SWEEPCOMPLETE)) { + sweep = spectool_phy_getsweep(phydev); if (sweep == NULL) continue; @@ -511,7 +511,7 @@ continue; } - } while ((r & WISPY_POLL_ADDITIONAL)); + } while ((r & SPECTOOL_POLL_ADDITIONAL)); /* We do nothing otherwise, no events for partial polls */ } @@ -520,7 +520,7 @@ wdr_poll_rec *wdrpr = (wdr_poll_rec *) data; spectool_server *sr; int r; - char err[WISPY_ERROR_MAX]; + char err[SPECTOOL_ERROR_MAX]; if (wdrpr->slot < 0 || wdrpr->slot > wdrpr->wdr->max_dev) return; @@ -534,7 +534,7 @@ r = spectool_netcli_poll(sr, err); if (r < 0) { - Wispy_Alert_Dialog(err); + Spectool_Alert_Dialog(err); wdr_close_net(wdrpr->wdr, wdrpr->slot); return; @@ -543,7 +543,7 @@ } while ((r & SPECTOOL_NETCLI_POLL_ADDITIONAL)); } -GList *wdr_populate_menu(wispy_device_registry *wdr, GtkWidget *menu, +GList *wdr_populate_menu(spectool_device_registry *wdr, GtkWidget *menu, int sep, int fillnodev, GCallback cb, void *aux) { wdr_menu_rec *r; @@ -580,7 +580,7 @@ * no race for devices if a graph is being closed */ wdr_add_ref(wdr, x); - mi = gtk_menu_item_new_with_label(wispy_phy_getname(wdr->devices[x]->phydev)); + mi = gtk_menu_item_new_with_label(spectool_phy_getname(wdr->devices[x]->phydev)); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); g_signal_connect_swapped(G_OBJECT(mi), "activate", G_CALLBACK(cb), r); @@ -606,7 +606,7 @@ free(r); } -void wdr_free_menu(wispy_device_registry *wdr, GList *gl) { +void wdr_free_menu(spectool_device_registry *wdr, GList *gl) { g_list_foreach(gl, (GFunc) wdr_free_menu_fe, NULL); g_list_free(gl); } @@ -616,7 +616,7 @@ GtkTreeModel *model; GtkTreeIter iter; wdr_gtk_devpicker_aux *dpaux = (wdr_gtk_devpicker_aux *) aux; - char err[WISPY_ERROR_MAX]; + char err[SPECTOOL_ERROR_MAX]; model = gtk_tree_view_get_model(treeview); @@ -631,7 +631,7 @@ /* Error alert */ if (r < 0) { - Wispy_Alert_Dialog(err); + Spectool_Alert_Dialog(err); } else { /* Call their callback saying we've picked a device */ if (dpaux->pickcb != NULL) @@ -645,7 +645,7 @@ void wdr_devpicker_destroy(GtkWidget *widget, gpointer *aux) { wdr_gtk_devpicker_aux *dpaux = (wdr_gtk_devpicker_aux *) aux; - wispy_device_scan_free(&(dpaux->devlist)); + spectool_device_scan_free(&(dpaux->devlist)); free(aux); } @@ -670,10 +670,10 @@ dpaux->treemodellist = model; - wispy_device_scan_free(&(dpaux->devlist)); + spectool_device_scan_free(&(dpaux->devlist)); - /* Scan for Wispy V1 devices */ - ndevs = wispy_device_scan(&(dpaux->devlist)); + /* Scan for Spectool V1 devices */ + ndevs = spectool_device_scan(&(dpaux->devlist)); if (ndevs <= 0) { gtk_list_store_append(GTK_LIST_STORE(dpaux->treemodellist), &iter); @@ -741,7 +741,7 @@ GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; - char err[WISPY_ERROR_MAX]; + char err[SPECTOOL_ERROR_MAX]; selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dpaux->treeview)); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { @@ -754,7 +754,7 @@ r = wdr_open_add(dpaux->wdr, phyptr, p, err); if (r < 0) { - Wispy_Alert_Dialog(err); + Spectool_Alert_Dialog(err); } else { /* Call their callback saying we've picked a device */ if (dpaux->pickcb != NULL) @@ -772,7 +772,7 @@ } } -void wdr_devpicker_spawn(wispy_device_registry *wdr, +void wdr_devpicker_spawn(spectool_device_registry *wdr, void (*cb)(int, void *), void *aux) { GtkWidget *top_window, *scrolled_window; @@ -791,7 +791,7 @@ dpaux->pickcb = cb; dpaux->cbaux = aux; - wispy_device_scan_init(&(dpaux->devlist)); + spectool_device_scan_init(&(dpaux->devlist)); scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), @@ -1135,11 +1135,11 @@ GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; - char err[WISPY_ERROR_MAX]; + char err[SPECTOOL_ERROR_MAX]; selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(nmaux->treeview)); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { - wispy_phy *phyptr; + spectool_phy *phyptr; int srvid; unsigned int devid; int r; @@ -1155,12 +1155,12 @@ devid, err); if (phyptr == NULL) { - Wispy_Alert_Dialog(err); + Spectool_Alert_Dialog(err); } else { r = wdr_open_phy(nmaux->wdr, phyptr, err); if (r < 0) { - Wispy_Alert_Dialog(err); + Spectool_Alert_Dialog(err); } else { /* Call their callback saying we've picked a device */ if (nmaux->pickcb != NULL) @@ -1181,7 +1181,7 @@ wdr_netmanager_button(nmaux->openbutton, aux); } -void wdr_netmanager_spawn(wispy_device_registry *wdr, +void wdr_netmanager_spawn(spectool_device_registry *wdr, void (*cb)(int, void *), void *aux) { GtkWidget *top_window, *scrolled_window; @@ -1197,7 +1197,7 @@ int x, ndevs; char url[1024]; - char err[WISPY_ERROR_MAX]; + char err[SPECTOOL_ERROR_MAX]; wdr_gtk_netmanager_aux *nmaux = (wdr_gtk_netmanager_aux *) malloc(sizeof(wdr_gtk_netmanager_aux)); @@ -1298,7 +1298,7 @@ (GSourceFunc) wdr_netmanager_populate, nmaux); - snprintf(url, 1024, "tcp://localhost:%d", WISPY_NET_DEFAULT_PORT); + snprintf(url, 1024, "tcp://localhost:%d", SPECTOOL_NET_DEFAULT_PORT); if (wdr_open_net(wdr, url, err) >= 0) { wdr_netmanager_populate(wdr->netmanager); @@ -1320,7 +1320,7 @@ } if (widget == npaux->okbutton) { - char err[WISPY_ERROR_MAX]; + char err[SPECTOOL_ERROR_MAX]; char url[1024]; int r; @@ -1329,7 +1329,7 @@ gtk_entry_get_text(GTK_ENTRY(npaux->portentry))); if (wdr_open_net(npaux->wdr, url, err) < 0) { - Wispy_Alert_Dialog(err); + Spectool_Alert_Dialog(err); } wdr_netmanager_populate(npaux->wdr->netmanager); @@ -1339,7 +1339,7 @@ } } -void wdr_netentry_spawn(wispy_device_registry *wdr) { +void wdr_netentry_spawn(spectool_device_registry *wdr) { GtkWidget *top_window; GtkWidget *vbox, *hbox; @@ -1382,7 +1382,7 @@ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 2); npaux->portentry = gtk_entry_new(); - snprintf(port, 16, "%hd", WISPY_NET_DEFAULT_PORT); + snprintf(port, 16, "%hd", SPECTOOL_NET_DEFAULT_PORT); gtk_entry_set_text(GTK_ENTRY(npaux->portentry), port); gtk_entry_set_editable(GTK_ENTRY(npaux->portentry), 1); gtk_widget_show(npaux->portentry); diff -Nru spectools-201004R1/spectool_gtk_hw_registry.h spectools-201108r1/spectool_gtk_hw_registry.h --- spectools-201004R1/spectool_gtk_hw_registry.h 2009-01-27 05:40:54.000000000 +0000 +++ spectools-201108r1/spectool_gtk_hw_registry.h 2011-06-10 15:53:29.000000000 +0000 @@ -16,8 +16,8 @@ #include "config.h" -#ifndef __WISPY_GTK_HW_REGISTRY__ -#define __WISPY_GTK_HW_REGISTRY__ +#ifndef __SPECTOOL_GTK_HW_REGISTRY__ +#define __SPECTOOL_GTK_HW_REGISTRY__ #ifdef HAVE_GTK @@ -32,16 +32,16 @@ /* Sweep callback functions take a sweep and do (something) with it, * and so need: * int slot - slot # of device which triggered - * wispy_sample_sweep sweep - the sweep data + * spectool_sample_sweep sweep - the sweep data * void *aux - auxptr they provided (probably their main struct ref * * if sweep is NULL an error occurred and the device should be released. */ typedef struct _wdr_reg_sweep_cb { void *aux; - void (*cb)(int, int, wispy_sample_sweep *, void *); + void (*cb)(int, int, spectool_sample_sweep *, void *); /* Local queue buf and number to aggregate together */ - wispy_sweep_cache *agg_sweep; + spectool_sweep_cache *agg_sweep; int num_agg; int pos_agg; } wdr_reg_sweep_cb; @@ -49,7 +49,7 @@ /* Item in the device registry */ typedef struct _wdr_reg_dev { /* Physical device */ - wispy_phy *phydev; + spectool_phy *phydev; /* List of sweep caches we write into */ GList *sweep_cb_l; /* Reference count for this hw dev */ @@ -74,7 +74,7 @@ * assume a user will never have more than 32 devices on a system, * and if I'm wrong, we can mod it easily enough. Saves a whole lot * of glist mess */ -typedef struct _wispy_device_registry { +typedef struct _spectool_device_registry { wdr_reg_dev *devices[WDR_MAX_DEV]; int max_dev; int cur_dev; @@ -89,43 +89,43 @@ GIOChannel *bcioc; int bcioc_rtag; -} wispy_device_registry; +} spectool_device_registry; /* Passed to gdk_input_add as aux pointer struct */ typedef struct _wdr_poll_rec { - wispy_device_registry *wdr; + spectool_device_registry *wdr; int slot; int poll_tag; int poll_wtag; GIOChannel *ioch; } wdr_poll_rec; -void wdr_init(wispy_device_registry *wdr); -void wdr_free(wispy_device_registry *wdr); +void wdr_init(spectool_device_registry *wdr); +void wdr_free(spectool_device_registry *wdr); -int wdr_open_add(wispy_device_registry *wdr, wispy_device_rec *devrec, int pos, +int wdr_open_add(spectool_device_registry *wdr, spectool_device_rec *devrec, int pos, char *errstr); -int wdr_open_phy(wispy_device_registry *wdr, wispy_phy *phydev, char *errstr); +int wdr_open_phy(spectool_device_registry *wdr, spectool_phy *phydev, char *errstr); -int wdr_open_net(wispy_device_registry *wdr, char *url, char *errstr); -int wdr_open_netptr(wispy_device_registry *wdr, spectool_server *netptr, char *errstr); -void wdr_close_net(wispy_device_registry *wdr, int slot); +int wdr_open_net(spectool_device_registry *wdr, char *url, char *errstr); +int wdr_open_netptr(spectool_device_registry *wdr, spectool_server *netptr, char *errstr); +void wdr_close_net(spectool_device_registry *wdr, int slot); -int wdr_enable_bcast(wispy_device_registry *wdr, char *errstr); -void wdr_disable_bcast(wispy_device_registry *wdr); +int wdr_enable_bcast(spectool_device_registry *wdr, char *errstr); +void wdr_disable_bcast(spectool_device_registry *wdr); gboolean wdr_bcpoll(GIOChannel *ioch, GIOCondition cond, gpointer data); -wispy_phy *wdr_get_phy(wispy_device_registry *wdr, int slot); +spectool_phy *wdr_get_phy(spectool_device_registry *wdr, int slot); -void wdr_add_ref(wispy_device_registry *wdr, int slot); -void wdr_del_ref(wispy_device_registry *wdr, int slot); +void wdr_add_ref(spectool_device_registry *wdr, int slot); +void wdr_del_ref(spectool_device_registry *wdr, int slot); -void wdr_add_sweepcb(wispy_device_registry *wdr, int slot, - void (*cb)(int, int, wispy_sample_sweep *, void *), +void wdr_add_sweepcb(spectool_device_registry *wdr, int slot, + void (*cb)(int, int, spectool_sample_sweep *, void *), int nagg, void *aux); -void wdr_del_sweepcb(wispy_device_registry *wdr, int slot, - void (*cb)(int, int, wispy_sample_sweep *, void *), +void wdr_del_sweepcb(spectool_device_registry *wdr, int slot, + void (*cb)(int, int, spectool_sample_sweep *, void *), void *aux); /* Polling function suitable for calling from gdk_input */ @@ -139,20 +139,20 @@ typedef struct _wdr_menu_rec { int slot; void *aux; - wispy_device_registry *wdr; + spectool_device_registry *wdr; } wdr_menu_rec; /* Populate a menu and return a reference we have to make sure to * clean up */ -GList *wdr_populate_menu(wispy_device_registry *wdr, GtkWidget *menu, +GList *wdr_populate_menu(spectool_device_registry *wdr, GtkWidget *menu, int sep, int fillnodev, GCallback cb, void *aux); -void wdr_free_menu(wispy_device_registry *wdr, GList *gl); +void wdr_free_menu(spectool_device_registry *wdr, GList *gl); /* Device picker aux data */ typedef struct _wdr_gtk_devpicker_aux { - wispy_device_registry *wdr; + spectool_device_registry *wdr; - wispy_device_list devlist; + spectool_device_list devlist; GtkWidget *picker_win; @@ -168,12 +168,12 @@ } wdr_gtk_devpicker_aux; /* Spawn a device picker window and call our CB when the user has picked one */ -void wdr_devpicker_spawn(wispy_device_registry *wdr, +void wdr_devpicker_spawn(spectool_device_registry *wdr, void (*cb)(int, void *), void *aux); typedef struct _wdr_gtk_netmanager_aux { - wispy_device_registry *wdr; + spectool_device_registry *wdr; GtkWidget *picker_win; @@ -193,14 +193,14 @@ void *cbaux; } wdr_gtk_netmanager_aux; -void wdr_netmanager_spawn(wispy_device_registry *wdr, +void wdr_netmanager_spawn(spectool_device_registry *wdr, void (*cb)(int, void *), void *aux); typedef struct _wdr_gtk_netentry_aux { - wispy_device_registry *wdr; + spectool_device_registry *wdr; - wispy_device_list devlist; + spectool_device_list devlist; GtkWidget *picker_win; GtkWidget *hostentry, *portentry; @@ -208,7 +208,7 @@ } wdr_gtk_netentry_aux; -void wdr_netentry_spawn(wispy_device_registry *wdr); +void wdr_netentry_spawn(spectool_device_registry *wdr); #endif diff -Nru spectools-201004R1/spectool_gtk_planar.c spectools-201108r1/spectool_gtk_planar.c --- spectools-201004R1/spectool_gtk_planar.c 2009-12-04 15:38:14.000000000 +0000 +++ spectools-201108r1/spectool_gtk_planar.c 2011-06-15 19:53:10.000000000 +0000 @@ -29,26 +29,26 @@ "Channels may be highlighted by selecting the channel number from the listen " "channels at the bottom of the graph."; -static void wispy_planar_class_init(WispyPlanarClass *class); -static void wispy_planar_init(WispyPlanar *graph); -static void wispy_planar_destroy(GtkObject *object); +static void spectool_planar_class_init(SpectoolPlanarClass *class); +static void spectool_planar_init(SpectoolPlanar *graph); +static void spectool_planar_destroy(GtkObject *object); -static gint wispy_planar_configure(GtkWidget *widget, +static gint spectool_planar_configure(GtkWidget *widget, GdkEventConfigure *event); -static gboolean wispy_planar_expose(GtkWidget *widget, +static gboolean spectool_planar_expose(GtkWidget *widget, GdkEventExpose *event, gpointer *aux); -static gboolean wispy_planar_button_press(GtkWidget *widget, +static gboolean spectool_planar_button_press(GtkWidget *widget, GdkEventButton *event, gpointer *aux); -static gboolean wispy_planar_mouse_move(GtkWidget *widget, +static gboolean spectool_planar_mouse_move(GtkWidget *widget, GdkEventMotion *event, gpointer *aux); -G_DEFINE_TYPE(WispyPlanar, wispy_planar, WISPY_TYPE_WIDGET); +G_DEFINE_TYPE(SpectoolPlanar, spectool_planar, SPECTOOL_TYPE_WIDGET); -void wispy_planar_draw(GtkWidget *widget, cairo_t *cr, WispyWidget *wwidget) { - WispyPlanar *planar; +void spectool_planar_draw(GtkWidget *widget, cairo_t *cr, SpectoolWidget *wwidget) { + SpectoolPlanar *planar; cairo_text_extents_t extents; int x, chpix, maxcw; const double dash_onoff[] = {2, 4}; @@ -59,11 +59,11 @@ int chanmod; GList *mkr_iter; - wispy_planar_marker *mkr; + spectool_planar_marker *mkr; g_return_if_fail(widget != NULL); - planar = WISPY_PLANAR(wwidget); + planar = SPECTOOL_PLANAR(wwidget); cairo_save(cr); @@ -74,7 +74,7 @@ cairo_move_to(cr, wwidget->g_start_x + 0.5, wwidget->g_end_y - 0.5); for (x = 0; x < wwidget->sweepcache->avg->num_samples; x++) { int px, py; - int sdb = WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + int sdb = SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, wwidget->sweepcache->peak->sample_data[x]); chpix = x * wwidget->wbar; @@ -117,7 +117,7 @@ cairo_move_to(cr, wwidget->g_start_x + 0.5, wwidget->g_end_y - 0.5); for (x = 0; x < wwidget->sweepcache->avg->num_samples; x++) { int px, py; - int sdb = WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + int sdb = SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, wwidget->sweepcache->avg->sample_data[x]); chpix = x * wwidget->wbar; @@ -151,14 +151,22 @@ cairo_restore(cr); } +#if 0 /* Render the latest points */ if (planar->draw_cur) { + spectool_sweep_cache_itr sci; + spectool_sample_sweep *sweep; + + spectool_cache_itr_init(planar->agecache, &sci); + + while ((sweep = spectool_cache_itr_next(planar->agecache, &sci)) != NULL) { + cairo_save(cr); cairo_new_path(cr); cairo_move_to(cr, wwidget->g_start_x + 0.5, wwidget->g_end_y - 0.5); for (x = 0; x < wwidget->sweepcache->avg->num_samples; x++) { int px, py; - int sdb = WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + int sdb = SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, wwidget->sweepcache->latest->sample_data[x]); chpix = x * wwidget->wbar; @@ -188,12 +196,70 @@ cairo_stroke(cr); cairo_restore(cr); } +#endif + + /* Render the latest points */ + if (planar->draw_cur) { + spectool_sweep_cache_itr sci; + spectool_sample_sweep *sweep; + float n = 0; + float alpha; + + spectool_cache_itr_init(planar->agecache, &sci); + + while ((sweep = spectool_cache_itr_next(planar->agecache, &sci)) != NULL) { + + cairo_save(cr); + cairo_new_path(cr); + cairo_move_to(cr, wwidget->g_start_x + 0.5, wwidget->g_end_y - 0.5); + for (x = 0; x < sweep->num_samples; x++) { + int px, py; + int sdb = SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + sweep->sample_data[x]); + chpix = x * wwidget->wbar; + + px = wwidget->g_start_x + chpix; + py = (float) wwidget->g_len_y * + (float) ((float) (abs(sdb) + wwidget->base_db_offset) / + (float) (abs(wwidget->min_db_draw) + + wwidget->base_db_offset)); + + if (px < wwidget->g_start_x) + px = wwidget->g_start_x; + if (px > wwidget->g_end_x) + px = wwidget->g_end_x; + + if (py < wwidget->g_start_y) + py = wwidget->g_start_y; + if (py > wwidget->g_end_y) + py = wwidget->g_end_y; + + cairo_line_to(cr, px + 0.5, py + 0.5); + } + cairo_line_to(cr, wwidget->g_end_x - 0.5, wwidget->g_end_y - 0.5); + cairo_close_path(cr); + /* Plot it */ + + if (n == 0) + cairo_set_line_width(cr, 2); + else + cairo_set_line_width(cr, 1); + + alpha = 1.0f - (1.0f * (n / planar->agecache->num_used)); + + cairo_set_source_rgba(cr, HC2CC(0xFF * alpha), HC2CC(0xFF), HC2CC(0x00), alpha); + cairo_stroke(cr); + cairo_restore(cr); + + n = n + 1; + } + } mkr_iter = planar->mkr_list; while (mkr_iter != NULL && planar->draw_markers) { int px, py; int sdb; - mkr = (wispy_planar_marker *) mkr_iter->data; + mkr = (spectool_planar_marker *) mkr_iter->data; if (mkr->samp_num < 0 || mkr->samp_num > wwidget->sweepcache->latest->num_samples) { @@ -203,7 +269,7 @@ chpix = mkr->samp_num * wwidget->wbar; - sdb = WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + sdb = SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, wwidget->sweepcache->latest->sample_data[mkr->samp_num]); px = wwidget->g_start_x + chpix; @@ -229,42 +295,44 @@ cairo_restore(cr); } -static void wispy_planar_wdr_devbind(GtkWidget *widget, wispy_device_registry *wdr, int slot) { - WispyPlanar *planar; - WispyWidget *wwidget; +static void spectool_planar_wdr_devbind(GtkWidget *widget, spectool_device_registry *wdr, int slot) { + SpectoolPlanar *planar; + SpectoolWidget *wwidget; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_PLANAR(widget)); - g_return_if_fail(IS_WISPY_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_PLANAR(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); - planar = WISPY_PLANAR(widget); - wwidget = WISPY_WIDGET(widget); + planar = SPECTOOL_PLANAR(widget); + wwidget = SPECTOOL_WIDGET(widget); } -static void wispy_planar_wdr_sweep(int slot, int mode, - wispy_sample_sweep *sweep, void *aux) { - WispyPlanar *planar; - WispyWidget *wwidget; - wispy_phy *pd; +static void spectool_planar_wdr_sweep(int slot, int mode, + spectool_sample_sweep *sweep, void *aux) { + SpectoolPlanar *planar; + SpectoolWidget *wwidget; + spectool_phy *pd; int tout = 0; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_PLANAR(aux)); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_PLANAR(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - planar = WISPY_PLANAR(aux); - wwidget = WISPY_WIDGET(aux); + planar = SPECTOOL_PLANAR(aux); + wwidget = SPECTOOL_WIDGET(aux); tout = wwidget->draw_timeout; /* Update the timer */ if (sweep != NULL && sweep->phydev != NULL) { - pd = (wispy_phy *) sweep->phydev; + pd = (spectool_phy *) sweep->phydev; #ifdef HAVE_HILDON tout = 300 * pd->draw_agg_suggestion; #else tout = 100 * pd->draw_agg_suggestion; #endif + + spectool_cache_append(planar->agecache, sweep); } if (tout != wwidget->draw_timeout) { @@ -272,23 +340,23 @@ g_source_remove(wwidget->timeout_ref); wwidget->timeout_ref = g_timeout_add(wwidget->draw_timeout, - (GSourceFunc) wispy_widget_timeout, wwidget); + (GSourceFunc) spectool_widget_timeout, wwidget); } } -static gint wispy_planar_button_press(GtkWidget *widget, +static gint spectool_planar_button_press(GtkWidget *widget, GdkEventButton *event, gpointer *aux) { - WispyPlanar *planar; - WispyWidget *wwidget; + SpectoolPlanar *planar; + SpectoolWidget *wwidget; int ch; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_PLANAR(aux)); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_PLANAR(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - planar = WISPY_PLANAR(aux); - wwidget = WISPY_WIDGET(aux); + planar = SPECTOOL_PLANAR(aux); + wwidget = SPECTOOL_WIDGET(aux); g_return_if_fail(wwidget->sweepcache != NULL); g_return_if_fail(wwidget->sweepcache->avg != NULL); @@ -296,27 +364,27 @@ if (event->button != 1) return TRUE; - wispy_widget_graphics_update(wwidget); - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_graphics_update(wwidget); + spectool_widget_update(GTK_WIDGET(wwidget)); return TRUE; } -static gboolean wispy_planar_mouse_move(GtkWidget *widget, +static gboolean spectool_planar_mouse_move(GtkWidget *widget, GdkEventMotion *event, gpointer *aux) { int x, y; int ch; GdkModifierType state; - WispyPlanar *planar; - WispyWidget *wwidget; + SpectoolPlanar *planar; + SpectoolWidget *wwidget; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_PLANAR(aux)); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_PLANAR(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - planar = WISPY_PLANAR(aux); - wwidget = WISPY_WIDGET(aux); + planar = SPECTOOL_PLANAR(aux); + wwidget = SPECTOOL_WIDGET(aux); g_return_if_fail(wwidget->sweepcache != NULL); g_return_if_fail(wwidget->sweepcache->avg != NULL); @@ -342,8 +410,8 @@ planar->cur_mkr->samp_num = -1; } - wispy_widget_graphics_update(wwidget); - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_graphics_update(wwidget); + spectool_widget_update(GTK_WIDGET(wwidget)); } else if ((state & GDK_BUTTON1_MASK)) { GtkTreeIter iter; GtkTreeSelection *selection; @@ -367,21 +435,21 @@ return TRUE; } -void wispy_planar_update(GtkWidget *widget) { - WispyWidget *wwidget; - WispyPlanar *planar; +void spectool_planar_update(GtkWidget *widget) { + SpectoolWidget *wwidget; + SpectoolPlanar *planar; GtkTreeIter iter; GtkTreeModel *model; gboolean valid; char freqt[6], curt[6], avgt[6], maxt[6]; - wispy_planar_marker *mkr; + spectool_planar_marker *mkr; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); - g_return_if_fail(IS_WISPY_PLANAR(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_PLANAR(widget)); - wwidget = WISPY_WIDGET(widget); - planar = WISPY_PLANAR(widget); + wwidget = SPECTOOL_WIDGET(widget); + planar = SPECTOOL_PLANAR(widget); g_return_if_fail(wwidget->draw != NULL); @@ -418,13 +486,13 @@ snprintf(freqt, 6, "%4d", freq); snprintf(avgt, 6, "%d", - WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, wwidget->sweepcache->avg->sample_data[mkr->samp_num])); snprintf(maxt, 6, "%d", - WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, wwidget->sweepcache->peak->sample_data[mkr->samp_num])); snprintf(curt, 6, "%d", - WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, wwidget->sweepcache->latest->sample_data[mkr->samp_num])); gtk_list_store_set(GTK_LIST_STORE(model), &iter, @@ -442,20 +510,20 @@ } } -void wispy_planar_context_help(gpointer *aux) { - Wispy_Help_Dialog("Planar View", planar_help_txt); +void spectool_planar_context_help(gpointer *aux) { + Spectool_Help_Dialog("Planar View", planar_help_txt); } -void wispy_planar_context_markers(gpointer *aux) { - WispyWidget *wwidget; - WispyPlanar *planar; +void spectool_planar_context_markers(gpointer *aux) { + SpectoolWidget *wwidget; + SpectoolPlanar *planar; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); - g_return_if_fail(IS_WISPY_PLANAR(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_PLANAR(aux)); - wwidget = WISPY_WIDGET(aux); - planar = WISPY_PLANAR(aux); + wwidget = SPECTOOL_WIDGET(aux); + planar = SPECTOOL_PLANAR(aux); if (planar->draw_markers) { planar->draw_markers = 0; @@ -464,20 +532,20 @@ } gtk_widget_set_sensitive(planar->mkr_treeview, planar->draw_markers); - wispy_widget_graphics_update(wwidget); - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_graphics_update(wwidget); + spectool_widget_update(GTK_WIDGET(wwidget)); } -void wispy_planar_context_peak(gpointer *aux) { - WispyWidget *wwidget; - WispyPlanar *planar; +void spectool_planar_context_peak(gpointer *aux) { + SpectoolWidget *wwidget; + SpectoolPlanar *planar; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); - g_return_if_fail(IS_WISPY_PLANAR(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_PLANAR(aux)); - wwidget = WISPY_WIDGET(aux); - planar = WISPY_PLANAR(aux); + wwidget = SPECTOOL_WIDGET(aux); + planar = SPECTOOL_PLANAR(aux); if (planar->draw_peak) { planar->draw_peak = 0; @@ -485,20 +553,20 @@ planar->draw_peak = 1; } - wispy_widget_graphics_update(wwidget); - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_graphics_update(wwidget); + spectool_widget_update(GTK_WIDGET(wwidget)); } -void wispy_planar_context_avg(gpointer *aux) { - WispyWidget *wwidget; - WispyPlanar *planar; +void spectool_planar_context_avg(gpointer *aux) { + SpectoolWidget *wwidget; + SpectoolPlanar *planar; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); - g_return_if_fail(IS_WISPY_PLANAR(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_PLANAR(aux)); - wwidget = WISPY_WIDGET(aux); - planar = WISPY_PLANAR(aux); + wwidget = SPECTOOL_WIDGET(aux); + planar = SPECTOOL_PLANAR(aux); if (planar->draw_avg) { planar->draw_avg = 0; @@ -506,20 +574,20 @@ planar->draw_avg = 1; } - wispy_widget_graphics_update(wwidget); - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_graphics_update(wwidget); + spectool_widget_update(GTK_WIDGET(wwidget)); } -void wispy_planar_context_cur(gpointer *aux) { - WispyWidget *wwidget; - WispyPlanar *planar; +void spectool_planar_context_cur(gpointer *aux) { + SpectoolWidget *wwidget; + SpectoolPlanar *planar; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); - g_return_if_fail(IS_WISPY_PLANAR(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_PLANAR(aux)); - wwidget = WISPY_WIDGET(aux); - planar = WISPY_PLANAR(aux); + wwidget = SPECTOOL_WIDGET(aux); + planar = SPECTOOL_PLANAR(aux); if (planar->draw_cur) { planar->draw_cur = 0; @@ -527,28 +595,28 @@ planar->draw_cur = 1; } - wispy_widget_graphics_update(wwidget); - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_graphics_update(wwidget); + spectool_widget_update(GTK_WIDGET(wwidget)); } -void wispy_planar_context_menu(GtkWidget *widget, GtkWidget *menu) { - WispyWidget *wwidget; - WispyPlanar *planar; +void spectool_planar_context_menu(GtkWidget *widget, GtkWidget *menu) { + SpectoolWidget *wwidget; + SpectoolPlanar *planar; GtkWidget *mi; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); - g_return_if_fail(IS_WISPY_PLANAR(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_PLANAR(widget)); - wwidget = WISPY_WIDGET(widget); - planar = WISPY_PLANAR(widget); + wwidget = SPECTOOL_WIDGET(widget); + planar = SPECTOOL_PLANAR(widget); mi = gtk_check_menu_item_new_with_label("Show dBm scale"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); gtk_widget_set_sensitive(mi, (wwidget->wdr_slot >= 0)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), wwidget->show_dbm); g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(wispy_widget_context_dbm), + G_CALLBACK(spectool_widget_context_dbm), widget); gtk_widget_show(mi); @@ -557,7 +625,7 @@ gtk_widget_set_sensitive(mi, (wwidget->wdr_slot >= 0)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), wwidget->show_dbm_lines); g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(wispy_widget_context_dbmlines), + G_CALLBACK(spectool_widget_context_dbmlines), widget); gtk_widget_show(mi); @@ -571,7 +639,7 @@ gtk_widget_set_sensitive(mi, (wwidget->wdr_slot >= 0)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), planar->draw_markers); g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(wispy_planar_context_markers), + G_CALLBACK(spectool_planar_context_markers), widget); gtk_widget_show(mi); @@ -580,7 +648,7 @@ gtk_widget_set_sensitive(mi, (wwidget->wdr_slot >= 0)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), planar->draw_peak); g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(wispy_planar_context_peak), + G_CALLBACK(spectool_planar_context_peak), widget); gtk_widget_show(mi); @@ -589,7 +657,7 @@ gtk_widget_set_sensitive(mi, (wwidget->wdr_slot >= 0)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), planar->draw_avg); g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(wispy_planar_context_avg), + G_CALLBACK(spectool_planar_context_avg), widget); gtk_widget_show(mi); @@ -598,12 +666,12 @@ gtk_widget_set_sensitive(mi, (wwidget->wdr_slot >= 0)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), planar->draw_cur); g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(wispy_planar_context_cur), + G_CALLBACK(spectool_planar_context_cur), widget); gtk_widget_show(mi); } -static void wispy_planar_class_init(WispyPlanarClass *class) { +static void spectool_planar_class_init(SpectoolPlanarClass *class) { GObjectClass *gobject_class; GtkObjectClass *object_class; GtkWidgetClass *widget_class; @@ -612,33 +680,33 @@ object_class = GTK_OBJECT_CLASS(class); widget_class = GTK_WIDGET_CLASS(class); - object_class->destroy = wispy_planar_destroy; + object_class->destroy = spectool_planar_destroy; } -static void wispy_planar_destroy(GtkObject *object) { - WispyPlanar *planar = WISPY_PLANAR(object); - WispyWidget *wwidget; +static void spectool_planar_destroy(GtkObject *object) { + SpectoolPlanar *planar = SPECTOOL_PLANAR(object); + SpectoolWidget *wwidget; - wwidget = WISPY_WIDGET(planar); + wwidget = SPECTOOL_WIDGET(planar); - GTK_OBJECT_CLASS(wispy_planar_parent_class)->destroy(object); + GTK_OBJECT_CLASS(spectool_planar_parent_class)->destroy(object); } -GtkWidget *wispy_planar_new() { - WispyPlanar *planar; - WispyWidget *wwidget; +GtkWidget *spectool_planar_new() { + SpectoolPlanar *planar; + SpectoolWidget *wwidget; - planar = gtk_type_new(wispy_planar_get_type()); + planar = gtk_type_new(spectool_planar_get_type()); - wwidget = WISPY_WIDGET(planar); + wwidget = SPECTOOL_WIDGET(planar); return GTK_WIDGET(planar); } -wispy_planar_marker *wispy_planar_marker_new(GtkWidget *widget, +spectool_planar_marker *spectool_planar_marker_new(GtkWidget *widget, double r, double g, double b, int samp) { - wispy_planar_marker *mkr = malloc(sizeof(wispy_planar_marker)); + spectool_planar_marker *mkr = malloc(sizeof(spectool_planar_marker)); cairo_t *cr; GdkPixmap *pixmap; GdkColormap *cmap; @@ -670,8 +738,8 @@ return mkr; } -static void wispy_planar_init(WispyPlanar *planar) { - WispyWidget *wwidget; +static void spectool_planar_init(SpectoolPlanar *planar) { + SpectoolWidget *wwidget; GtkWidget *scrollwindow; GtkCellRenderer *cell; @@ -688,11 +756,11 @@ GdkColor c; GtkStyle *style; - wispy_planar_marker *mkr; + spectool_planar_marker *mkr; - wwidget = WISPY_WIDGET(planar); + wwidget = SPECTOOL_WIDGET(planar); - wwidget->sweep_num_samples = WISPY_PLANAR_NUM_SAMPLES; + wwidget->sweep_num_samples = SPECTOOL_PLANAR_NUM_SAMPLES; wwidget->sweep_keep_avg = 1; wwidget->sweep_keep_peak = 1; @@ -709,27 +777,29 @@ wwidget->show_dbm = 1; wwidget->show_dbm_lines = 1; - wwidget->wdr_sweep_func = wispy_planar_wdr_sweep; - wwidget->wdr_devbind_func = wispy_planar_wdr_devbind; - wwidget->draw_mouse_move_func = wispy_planar_mouse_move; - wwidget->draw_mouse_click_func = wispy_planar_button_press; + wwidget->wdr_sweep_func = spectool_planar_wdr_sweep; + wwidget->wdr_devbind_func = spectool_planar_wdr_devbind; + wwidget->draw_mouse_move_func = spectool_planar_mouse_move; + wwidget->draw_mouse_click_func = spectool_planar_button_press; #ifdef HAVE_HILDON wwidget->draw_timeout = 1500; #else wwidget->draw_timeout = 500; #endif - wwidget->draw_func = wispy_planar_draw; - wwidget->update_func = wispy_planar_update; + wwidget->draw_func = spectool_planar_draw; + wwidget->update_func = spectool_planar_update; - wwidget->menu_func = wispy_planar_context_menu; - wwidget->help_func = wispy_planar_context_help; + wwidget->menu_func = spectool_planar_context_menu; + wwidget->help_func = spectool_planar_context_help; wwidget->timeout_ref = g_timeout_add(wwidget->draw_timeout, - (GSourceFunc) wispy_widget_timeout, wwidget); + (GSourceFunc) spectool_widget_timeout, wwidget); + + spectool_widget_buildgui(wwidget); - wispy_widget_buildgui(wwidget); + planar->agecache = spectool_cache_alloc(10, 0, 0); planar->mkr_list = NULL; planar->cur_mkr = NULL; @@ -853,7 +923,7 @@ g_object_unref(planar->mkr_treelist); pango_attr_list_unref(attr_lst); - mkr = wispy_planar_marker_new(GTK_WIDGET(planar), 1, 0, 0, -1); + mkr = spectool_planar_marker_new(GTK_WIDGET(planar), 1, 0, 0, -1); planar->mkr_list = g_list_append(planar->mkr_list, mkr); gtk_list_store_append(GTK_LIST_STORE(planar->mkr_treelist), &iter); gtk_list_store_set(GTK_LIST_STORE(planar->mkr_treelist), &iter, @@ -865,7 +935,7 @@ 5, mkr, -1); - mkr = wispy_planar_marker_new(GTK_WIDGET(planar), 0, 1, 0, -1); + mkr = spectool_planar_marker_new(GTK_WIDGET(planar), 0, 1, 0, -1); planar->mkr_list = g_list_append(planar->mkr_list, mkr); gtk_list_store_append(GTK_LIST_STORE(planar->mkr_treelist), &iter); gtk_list_store_set(GTK_LIST_STORE(planar->mkr_treelist), &iter, @@ -877,7 +947,7 @@ 5, mkr, -1); - mkr = wispy_planar_marker_new(GTK_WIDGET(planar), 0, 0, 1, -1); + mkr = spectool_planar_marker_new(GTK_WIDGET(planar), 0, 0, 1, -1); planar->mkr_list = g_list_append(planar->mkr_list, mkr); gtk_list_store_append(GTK_LIST_STORE(planar->mkr_treelist), &iter); gtk_list_store_set(GTK_LIST_STORE(planar->mkr_treelist), &iter, @@ -889,7 +959,7 @@ 5, mkr, -1); - mkr = wispy_planar_marker_new(GTK_WIDGET(planar), 1, 1, 0, -1); + mkr = spectool_planar_marker_new(GTK_WIDGET(planar), 1, 1, 0, -1); planar->mkr_list = g_list_append(planar->mkr_list, mkr); gtk_list_store_append(GTK_LIST_STORE(planar->mkr_treelist), &iter); gtk_list_store_set(GTK_LIST_STORE(planar->mkr_treelist), &iter, diff -Nru spectools-201004R1/spectool_gtk_planar.h spectools-201108r1/spectool_gtk_planar.h --- spectools-201004R1/spectool_gtk_planar.h 2007-10-03 18:31:56.000000000 +0000 +++ spectools-201108r1/spectool_gtk_planar.h 2011-06-15 04:04:23.000000000 +0000 @@ -1,4 +1,4 @@ -/* Wispy signal graph +/* Spectool signal graph * * GTK widget implementation * @@ -20,8 +20,8 @@ #include "config.h" -#ifndef __WISPY_PLANAR_WIDGET_H__ -#define __WISPY_PLANAR_WIDGET_H__ +#ifndef __SPECTOOL_PLANAR_WIDGET_H__ +#define __SPECTOOL_PLANAR_WIDGET_H__ #ifdef HAVE_GTK @@ -34,41 +34,42 @@ G_BEGIN_DECLS -#define WISPY_TYPE_PLANAR \ - (wispy_planar_get_type()) -#define WISPY_PLANAR(obj) \ +#define SPECTOOL_TYPE_PLANAR \ + (spectool_planar_get_type()) +#define SPECTOOL_PLANAR(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - WISPY_TYPE_PLANAR, WispyPlanar)) -#define WISPY_PLANAR_CLASS(klass) \ + SPECTOOL_TYPE_PLANAR, SpectoolPlanar)) +#define SPECTOOL_PLANAR_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass), \ - WISPY_TYPE_PLANAR, WispyPlanarClass)) -#define IS_WISPY_PLANAR(obj) \ + SPECTOOL_TYPE_PLANAR, SpectoolPlanarClass)) +#define IS_SPECTOOL_PLANAR(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - WISPY_TYPE_PLANAR)) -#define IS_WISPY_PLANAR_CLASS(klass) \ + SPECTOOL_TYPE_PLANAR)) +#define IS_SPECTOOL_PLANAR_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((class), \ - WISPY_TYPE_PLANAR)) + SPECTOOL_TYPE_PLANAR)) -typedef struct _WispyPlanar WispyPlanar; -typedef struct _WispyPlanarClass WispyPlanarClass; +typedef struct _SpectoolPlanar SpectoolPlanar; +typedef struct _SpectoolPlanarClass SpectoolPlanarClass; -#define WISPY_PLANAR_NUM_SAMPLES 250 +#define SPECTOOL_PLANAR_NUM_SAMPLES 250 -typedef struct _wispy_planar_marker { +typedef struct _spectool_planar_marker { double r, g, b; GdkPixbuf *pixbuf; int samp_num; int cur, avg, peak; -} wispy_planar_marker; +} spectool_planar_marker; -struct _WispyPlanar { - WispyWidget parent; +struct _SpectoolPlanar { + SpectoolWidget parent; /* What components do we draw */ int draw_markers; int draw_peak; int draw_avg; int draw_cur; + int draw_history; /* is the mouse down during an event? */ int mouse_down; @@ -78,17 +79,19 @@ GtkWidget *mkr_treeview; GtkListStore *mkr_treelist; GList *mkr_list; - wispy_planar_marker *cur_mkr; + spectool_planar_marker *cur_mkr; GtkWidget *mkr_newbutton, *mkr_delbutton; + + spectool_sweep_cache *agecache; }; -struct _WispyPlanarClass { - WispyWidgetClass parent_class; +struct _SpectoolPlanarClass { + SpectoolWidgetClass parent_class; }; -GType wispy_planar_get_type(void); -GtkWidget *wispy_planar_new(); -void wispy_planar_clear(void); +GType spectool_planar_get_type(void); +GtkWidget *spectool_planar_new(); +void spectool_planar_clear(void); G_END_DECLS diff -Nru spectools-201004R1/spectool_gtk_spectral.c spectools-201108r1/spectool_gtk_spectral.c --- spectools-201004R1/spectool_gtk_spectral.c 2009-02-28 04:34:47.000000000 +0000 +++ spectools-201108r1/spectool_gtk_spectral.c 2011-06-10 15:53:29.000000000 +0000 @@ -26,7 +26,7 @@ "\"Waterfall\" style view over time showing the peak spectrum usage for each " "time slice."; -/* Default set of colors inherited from the old wispy_gtk code */ +/* Default set of colors inherited from the old spectool_gtk code */ float spect_default_colormap[] = { HC2CC(0x00), HC2CC(0x45), HC2CC(0xFE), HC2CC(0x00), HC2CC(0x5C), HC2CC(0xFE), @@ -117,17 +117,17 @@ }; int spect_21_colormap_len = 50; -static void wispy_spectral_class_init(WispySpectralClass *class); -static void wispy_spectral_init(WispySpectral *graph); -static void wispy_spectral_destroy(GtkObject *object); +static void spectool_spectral_class_init(SpectoolSpectralClass *class); +static void spectool_spectral_init(SpectoolSpectral *graph); +static void spectool_spectral_destroy(GtkObject *object); -static gint wispy_spectral_configure(GtkWidget *widget, +static gint spectool_spectral_configure(GtkWidget *widget, GdkEventConfigure *event); -G_DEFINE_TYPE(WispySpectral, wispy_spectral, WISPY_TYPE_WIDGET); +G_DEFINE_TYPE(SpectoolSpectral, spectool_spectral, SPECTOOL_TYPE_WIDGET); -void wispy_spectral_draw(GtkWidget *widget, cairo_t *cr, WispyWidget *wwidget) { - WispySpectral *spectral; +void spectool_spectral_draw(GtkWidget *widget, cairo_t *cr, SpectoolWidget *wwidget) { + SpectoolSpectral *spectral; int nsamp, pos, sp; int sh, b_s_y; cairo_pattern_t *pattern; @@ -138,7 +138,7 @@ g_return_if_fail(widget != NULL); - spectral = WISPY_SPECTRAL(wwidget); + spectral = SPECTOOL_SPECTRAL(wwidget); cairo_save(cr); @@ -173,7 +173,7 @@ pos = 0; while (nsamp != wwidget->sweepcache->pos && pos <= wwidget->sweepcache->num_alloc) { - wispy_sample_sweep *samp; + spectool_sample_sweep *samp; /* Loop around the ring */ if (nsamp >= wwidget->sweepcache->num_alloc) @@ -216,7 +216,7 @@ for (sp = 0; sp < samp->num_samples - 1; sp++) { int cpos; int sdb = - WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, samp->sample_data[sp]); cpos = @@ -226,7 +226,7 @@ abs(wwidget->base_db_offset))); if (cpos < 0) - cpos == 0; + cpos = 0; else if (cpos >= spectral->colormap_len) cpos = spectral->colormap_len - 1; @@ -236,9 +236,9 @@ * them that way */ cairo_pattern_add_color_stop_rgb(pattern, (float) (sp) / (samp->num_samples - 1), - WISPY_SPECTRAL_COLOR(spectral->colormap, cpos, 0), - WISPY_SPECTRAL_COLOR(spectral->colormap, cpos, 1), - WISPY_SPECTRAL_COLOR(spectral->colormap, cpos, 2)); + SPECTOOL_SPECTRAL_COLOR(spectral->colormap, cpos, 0), + SPECTOOL_SPECTRAL_COLOR(spectral->colormap, cpos, 1), + SPECTOOL_SPECTRAL_COLOR(spectral->colormap, cpos, 2)); } /* Draw a line over our pixmap */ @@ -267,12 +267,12 @@ cairo_restore(cr); } -static void wispy_spectral_size_allocate(GtkWidget *widget, +static void spectool_spectral_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { - WispySpectral *spectral = WISPY_SPECTRAL(widget); + SpectoolSpectral *spectral = SPECTOOL_SPECTRAL(widget); int x; - GTK_WIDGET_CLASS(wispy_spectral_parent_class)->size_allocate(widget, allocation); + GTK_WIDGET_CLASS(spectool_spectral_parent_class)->size_allocate(widget, allocation); /* Wipe the line cache on resize */ if (allocation->width != spectral->oldx || @@ -292,7 +292,7 @@ } } -static void wispy_spectral_class_init(WispySpectralClass *class) { +static void spectool_spectral_class_init(SpectoolSpectralClass *class) { GObjectClass *gobject_class; GtkObjectClass *object_class; GtkWidgetClass *widget_class; @@ -301,52 +301,52 @@ object_class = GTK_OBJECT_CLASS(class); widget_class = GTK_WIDGET_CLASS(class); - object_class->destroy = wispy_spectral_destroy; - widget_class->size_allocate = wispy_spectral_size_allocate; + object_class->destroy = spectool_spectral_destroy; + widget_class->size_allocate = spectool_spectral_size_allocate; } -static void wispy_spectral_destroy(GtkObject *object) { - WispySpectral *spectral = WISPY_SPECTRAL(object); - WispyWidget *wwidget; +static void spectool_spectral_destroy(GtkObject *object) { + SpectoolSpectral *spectral = SPECTOOL_SPECTRAL(object); + SpectoolWidget *wwidget; - wwidget = WISPY_WIDGET(spectral); + wwidget = SPECTOOL_WIDGET(spectral); - GTK_OBJECT_CLASS(wispy_spectral_parent_class)->destroy(object); + GTK_OBJECT_CLASS(spectool_spectral_parent_class)->destroy(object); } -static void wispy_spectral_wdr_devbind(GtkWidget *widget, wispy_device_registry *wdr, +static void spectool_spectral_wdr_devbind(GtkWidget *widget, spectool_device_registry *wdr, int slot) { - WispySpectral *spectral; - WispyWidget *wwidget; + SpectoolSpectral *spectral; + SpectoolWidget *wwidget; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_SPECTRAL(widget)); - g_return_if_fail(IS_WISPY_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_SPECTRAL(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); - spectral = WISPY_SPECTRAL(widget); - wwidget = WISPY_WIDGET(widget); + spectral = SPECTOOL_SPECTRAL(widget); + wwidget = SPECTOOL_WIDGET(widget); } -static void wispy_spectral_wdr_sweep(int slot, int mode, - wispy_sample_sweep *sweep, +static void spectool_spectral_wdr_sweep(int slot, int mode, + spectool_sample_sweep *sweep, void *aux) { - WispySpectral *spectral; - WispyWidget *wwidget; + SpectoolSpectral *spectral; + SpectoolWidget *wwidget; int x, tout; - wispy_phy *pd; + spectool_phy *pd; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_SPECTRAL(aux)); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_SPECTRAL(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - spectral = WISPY_SPECTRAL(aux); - wwidget = WISPY_WIDGET(aux); + spectral = SPECTOOL_SPECTRAL(aux); + wwidget = SPECTOOL_WIDGET(aux); tout = wwidget->draw_timeout; /* Update the timer */ if (sweep != NULL && sweep->phydev != NULL) { - pd = (wispy_phy *) sweep->phydev; + pd = (spectool_phy *) sweep->phydev; #ifdef HAVE_HILDON tout = 500 * pd->draw_agg_suggestion; #else @@ -359,10 +359,10 @@ g_source_remove(wwidget->timeout_ref); wwidget->timeout_ref = g_timeout_add(wwidget->draw_timeout, - (GSourceFunc) wispy_widget_timeout, wwidget); + (GSourceFunc) spectool_widget_timeout, wwidget); } - if ((mode & WISPY_POLL_CONFIGURED)) { + if ((mode & SPECTOOL_POLL_CONFIGURED)) { /* Allocate the cache of lines to draw */ if (spectral->line_cache != NULL) { for (x = 0; x < spectral->line_cache_len; x++) { @@ -382,7 +382,7 @@ for (x = 0; x < spectral->line_cache_len; x++) { spectral->line_cache[x] = NULL; } - } else if ((mode & WISPY_POLL_SWEEPCOMPLETE)) { + } else if ((mode & SPECTOOL_POLL_SWEEPCOMPLETE)) { /* Null out this sweep in the cache so we have to recalculate it */ if (wwidget->sweepcache->pos >= 0 && wwidget->sweepcache->pos < spectral->line_cache_len) { @@ -395,31 +395,31 @@ } } -GtkWidget *wispy_spectral_new(void) { - WispySpectral *spectral; - WispyWidget *wwidget; +GtkWidget *spectool_spectral_new(void) { + SpectoolSpectral *spectral; + SpectoolWidget *wwidget; - spectral = gtk_type_new(wispy_spectral_get_type()); + spectral = gtk_type_new(spectool_spectral_get_type()); - wwidget = WISPY_WIDGET(spectral); + wwidget = SPECTOOL_WIDGET(spectral); return GTK_WIDGET(spectral); } -static gboolean wispy_spectral_legend_expose(GtkWidget *widget, +static gboolean spectool_spectral_legend_expose(GtkWidget *widget, GdkEventExpose *event, gpointer *aux) { cairo_t *cr; int x, y, w, h, dw, dh; - WispySpectral *spectral; + SpectoolSpectral *spectral; cairo_pattern_t *pattern; int cp; g_return_if_fail(widget != NULL); g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_SPECTRAL(aux)); + g_return_if_fail(IS_SPECTOOL_SPECTRAL(aux)); - spectral = WISPY_SPECTRAL(aux); + spectral = SPECTOOL_SPECTRAL(aux); cr = gdk_cairo_create(widget->window); @@ -446,9 +446,9 @@ for (cp = 0; cp < spectral->colormap_len; cp++) { cairo_pattern_add_color_stop_rgb(pattern, (float) (cp) / (spectral->colormap_len), - WISPY_SPECTRAL_COLOR(spectral->colormap, cp, 0), - WISPY_SPECTRAL_COLOR(spectral->colormap, cp, 1), - WISPY_SPECTRAL_COLOR(spectral->colormap, cp, 2)); + SPECTOOL_SPECTRAL_COLOR(spectral->colormap, cp, 0), + SPECTOOL_SPECTRAL_COLOR(spectral->colormap, cp, 1), + SPECTOOL_SPECTRAL_COLOR(spectral->colormap, cp, 2)); } cairo_set_source(cr, pattern); @@ -461,21 +461,21 @@ return FALSE; } -void wispy_spectral_context_help(gpointer *aux) { - Wispy_Help_Dialog("Spectral View", spectral_help_txt); +void spectool_spectral_context_help(gpointer *aux) { + Spectool_Help_Dialog("Spectral View", spectral_help_txt); } -static void wispy_spectral_init(WispySpectral *spectral) { - WispyWidget *wwidget; +static void spectool_spectral_init(SpectoolSpectral *spectral) { + SpectoolWidget *wwidget; GtkWidget *temp; GtkWidget *legendv, *legendh; PangoAttrList *attr_list; PangoAttribute *attr; - wwidget = WISPY_WIDGET(spectral); + wwidget = SPECTOOL_WIDGET(spectral); - wwidget->sweep_num_samples = WISPY_SPECTRAL_NUM_SAMPLES; + wwidget->sweep_num_samples = SPECTOOL_SPECTRAL_NUM_SAMPLES; wwidget->sweep_keep_avg = 0; wwidget->sweep_keep_peak = 0; @@ -492,8 +492,8 @@ wwidget->show_dbm = 0; wwidget->show_dbm_lines = 0; - wwidget->wdr_sweep_func = wispy_spectral_wdr_sweep; - wwidget->wdr_devbind_func = wispy_spectral_wdr_devbind; + wwidget->wdr_sweep_func = spectool_spectral_wdr_sweep; + wwidget->wdr_devbind_func = spectool_spectral_wdr_devbind; wwidget->draw_mouse_move_func = NULL; wwidget->draw_mouse_click_func = NULL; #ifdef HAVE_HILDON @@ -501,19 +501,19 @@ #else wwidget->draw_timeout = 500; #endif - wwidget->draw_func = wispy_spectral_draw; + wwidget->draw_func = spectool_spectral_draw; wwidget->menu_func = NULL; - wwidget->help_func = wispy_spectral_context_help; + wwidget->help_func = spectool_spectral_context_help; spectral->colormap = spect_21_colormap; spectral->colormap_len = spect_21_colormap_len; wwidget->timeout_ref = g_timeout_add(wwidget->draw_timeout, - (GSourceFunc) wispy_widget_timeout, wwidget); + (GSourceFunc) spectool_widget_timeout, wwidget); - wispy_widget_buildgui(wwidget); + spectool_widget_buildgui(wwidget); temp = gtk_frame_new("Legend"); gtk_box_pack_start(GTK_BOX(wwidget->vbox), temp, FALSE, FALSE, 2); @@ -528,7 +528,7 @@ gtk_box_pack_start(GTK_BOX(legendv), spectral->legend_pix, FALSE, FALSE, 2); gtk_drawing_area_size(GTK_DRAWING_AREA(spectral->legend_pix), -1, 10); gtk_signal_connect(GTK_OBJECT(spectral->legend_pix), "expose_event", - (GtkSignalFunc) wispy_spectral_legend_expose, spectral); + (GtkSignalFunc) spectool_spectral_legend_expose, spectral); attr_list = pango_attr_list_new(); attr = pango_attr_size_new(7.0 * PANGO_SCALE); diff -Nru spectools-201004R1/spectool_gtk_spectral.h spectools-201108r1/spectool_gtk_spectral.h --- spectools-201004R1/spectool_gtk_spectral.h 2007-10-04 04:48:10.000000000 +0000 +++ spectools-201108r1/spectool_gtk_spectral.h 2011-06-10 15:53:29.000000000 +0000 @@ -1,4 +1,4 @@ -/* Wispy signal graph +/* Spectool signal graph * * GTK widget implementation * @@ -20,8 +20,8 @@ #include "config.h" -#ifndef __WISPY_SPECTRAL_WIDGET_H__ -#define __WISPY_SPECTRAL_WIDGET_H__ +#ifndef __SPECTOOL_SPECTRAL_WIDGET_H__ +#define __SPECTOOL_SPECTRAL_WIDGET_H__ #ifdef HAVE_GTK @@ -34,31 +34,31 @@ G_BEGIN_DECLS -#define WISPY_TYPE_SPECTRAL \ - (wispy_spectral_get_type()) -#define WISPY_SPECTRAL(obj) \ +#define SPECTOOL_TYPE_SPECTRAL \ + (spectool_spectral_get_type()) +#define SPECTOOL_SPECTRAL(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - WISPY_TYPE_SPECTRAL, WispySpectral)) -#define WISPY_SPECTRAL_CLASS(klass) \ + SPECTOOL_TYPE_SPECTRAL, SpectoolSpectral)) +#define SPECTOOL_SPECTRAL_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass), \ - WISPY_TYPE_SPECTRAL, WispySpectralClass)) -#define IS_WISPY_SPECTRAL(obj) \ + SPECTOOL_TYPE_SPECTRAL, SpectoolSpectralClass)) +#define IS_SPECTOOL_SPECTRAL(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - WISPY_TYPE_SPECTRAL)) -#define IS_WISPY_SPECTRAL_CLASS(klass) \ + SPECTOOL_TYPE_SPECTRAL)) +#define IS_SPECTOOL_SPECTRAL_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((class), \ - WISPY_TYPE_SPECTRAL)) + SPECTOOL_TYPE_SPECTRAL)) -typedef struct _WispySpectral WispySpectral; -typedef struct _WispySpectralClass WispySpectralClass; +typedef struct _SpectoolSpectral SpectoolSpectral; +typedef struct _SpectoolSpectralClass SpectoolSpectralClass; -#define WISPY_SPECTRAL_NUM_SAMPLES 100 +#define SPECTOOL_SPECTRAL_NUM_SAMPLES 100 /* Access the color array */ -#define WISPY_SPECTRAL_COLOR(a, b, c) ((a)[((b) * 3) + c]) +#define SPECTOOL_SPECTRAL_COLOR(a, b, c) ((a)[((b) * 3) + c]) -struct _WispySpectral { - WispyWidget parent; +struct _SpectoolSpectral { + SpectoolWidget parent; GtkWidget *sweepinfo; @@ -74,13 +74,13 @@ int oldx, oldy; }; -struct _WispySpectralClass { - WispyWidgetClass parent_class; +struct _SpectoolSpectralClass { + SpectoolWidgetClass parent_class; }; -GType wispy_spectral_get_type(void); -GtkWidget *wispy_spectral_new(void); -void wispy_spectral_clear(void); +GType spectool_spectral_get_type(void); +GtkWidget *spectool_spectral_new(void); +void spectool_spectral_clear(void); G_END_DECLS diff -Nru spectools-201004R1/spectool_gtk_topo.c spectools-201108r1/spectool_gtk_topo.c --- spectools-201004R1/spectool_gtk_topo.c 2009-12-04 02:58:37.000000000 +0000 +++ spectools-201108r1/spectool_gtk_topo.c 2011-06-12 04:49:39.000000000 +0000 @@ -82,17 +82,17 @@ }; int topo_21_colormap_len = 50; -static void wispy_topo_class_init(WispyTopoClass *class); -static void wispy_topo_init(WispyTopo *graph); -static void wispy_topo_destroy(GtkObject *object); +static void spectool_topo_class_init(SpectoolTopoClass *class); +static void spectool_topo_init(SpectoolTopo *graph); +static void spectool_topo_destroy(GtkObject *object); -static gint wispy_topo_configure(GtkWidget *widget, +static gint spectool_topo_configure(GtkWidget *widget, GdkEventConfigure *event); -G_DEFINE_TYPE(WispyTopo, wispy_topo, WISPY_TYPE_WIDGET); +G_DEFINE_TYPE(SpectoolTopo, spectool_topo, SPECTOOL_TYPE_WIDGET); -void wispy_topo_draw(GtkWidget *widget, cairo_t *cr, WispyWidget *wwidget) { - WispyTopo *topo; +void spectool_topo_draw(GtkWidget *widget, cairo_t *cr, SpectoolWidget *wwidget) { + SpectoolTopo *topo; float sh; double chpix; @@ -100,12 +100,14 @@ int samp, db; - g_return_if_fail(IS_WISPY_TOPO(wwidget)); + g_return_if_fail(IS_SPECTOOL_TOPO(wwidget)); - topo = WISPY_TOPO(wwidget); + topo = SPECTOOL_TOPO(wwidget); - if (topo->sch == 0 || topo->scw == 0) + if (topo->sch == 0 || topo->scw == 0) { + printf("debug - sch or scw 0? %d %d\n", topo->sch, topo->scw); return; + } cairo_save(cr); @@ -137,9 +139,9 @@ cairo_pattern_add_color_stop_rgb(pattern, (float) (samp) / (topo->scw), - WISPY_TOPO_COLOR(topo->colormap, cpos, 0), - WISPY_TOPO_COLOR(topo->colormap, cpos, 1), - WISPY_TOPO_COLOR(topo->colormap, cpos, 2)); + SPECTOOL_TOPO_COLOR(topo->colormap, cpos, 0), + SPECTOOL_TOPO_COLOR(topo->colormap, cpos, 1), + SPECTOOL_TOPO_COLOR(topo->colormap, cpos, 2)); } cairo_set_source(cr, pattern); @@ -163,17 +165,17 @@ cairo_restore(cr); } -void wispy_topo_update(GtkWidget *widget) { - WispyWidget *wwidget; - WispyTopo *topo; +void spectool_topo_update(GtkWidget *widget) { + SpectoolWidget *wwidget; + SpectoolTopo *topo; char perct[6]; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); - g_return_if_fail(IS_WISPY_TOPO(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_TOPO(widget)); - wwidget = WISPY_WIDGET(widget); - topo = WISPY_TOPO(widget); + wwidget = SPECTOOL_WIDGET(widget); + topo = SPECTOOL_TOPO(widget); if (topo->sweep_count_num > 0 && topo->sweep_peak_max > 0) { snprintf(perct, 6, "%2.1f%%", @@ -184,7 +186,7 @@ } -static void wispy_topo_class_init(WispyTopoClass *class) { +static void spectool_topo_class_init(SpectoolTopoClass *class) { GObjectClass *gobject_class; GtkObjectClass *object_class; GtkWidgetClass *widget_class; @@ -193,48 +195,48 @@ object_class = GTK_OBJECT_CLASS(class); widget_class = GTK_WIDGET_CLASS(class); - object_class->destroy = wispy_topo_destroy; + object_class->destroy = spectool_topo_destroy; } -static void wispy_topo_destroy(GtkObject *object) { - WispyTopo *topo = WISPY_TOPO(object); - WispyWidget *wwidget; +static void spectool_topo_destroy(GtkObject *object) { + SpectoolTopo *topo = SPECTOOL_TOPO(object); + SpectoolWidget *wwidget; - wwidget = WISPY_WIDGET(topo); + wwidget = SPECTOOL_WIDGET(topo); if (topo->sample_counts != NULL) { free(topo->sample_counts); topo->sample_counts = NULL; } - GTK_OBJECT_CLASS(wispy_topo_parent_class)->destroy(object); + GTK_OBJECT_CLASS(spectool_topo_parent_class)->destroy(object); } -static void wispy_topo_wdr_devbind(GtkWidget *widget, wispy_device_registry *wdr, +static void spectool_topo_wdr_devbind(GtkWidget *widget, spectool_device_registry *wdr, int slot) { /* Nothing, magic moved to sweep-configured */ } -static void wispy_topo_wdr_sweep(int slot, int mode, - wispy_sample_sweep *sweep, +static void spectool_topo_wdr_sweep(int slot, int mode, + spectool_sample_sweep *sweep, void *aux) { - WispyTopo *topo; - WispyWidget *wwidget; + SpectoolTopo *topo; + SpectoolWidget *wwidget; int s, x, sc, tout; - wispy_phy *pd; + spectool_phy *pd; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_TOPO(aux)); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_TOPO(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - topo = WISPY_TOPO(aux); - wwidget = WISPY_WIDGET(aux); + topo = SPECTOOL_TOPO(aux); + wwidget = SPECTOOL_WIDGET(aux); tout = wwidget->draw_timeout; /* Update the timer */ if (sweep != NULL && sweep->phydev != NULL) { - pd = (wispy_phy *) sweep->phydev; + pd = (spectool_phy *) sweep->phydev; #ifdef HAVE_HILDON tout = 500 * pd->draw_agg_suggestion; #else @@ -247,15 +249,15 @@ g_source_remove(wwidget->timeout_ref); wwidget->timeout_ref = g_timeout_add(wwidget->draw_timeout, - (GSourceFunc) wispy_widget_timeout, wwidget); + (GSourceFunc) spectool_widget_timeout, wwidget); } - if ((mode & WISPY_POLL_ERROR)) { + if ((mode & SPECTOOL_POLL_ERROR)) { if (topo->sample_counts) { free(topo->sample_counts); topo->sample_counts = NULL; } - } else if ((mode & WISPY_POLL_CONFIGURED)) { + } else if ((mode & SPECTOOL_POLL_CONFIGURED)) { if (topo->sample_counts != NULL) { free(topo->sample_counts); } @@ -266,7 +268,7 @@ wwidget->phydev->device_spec->supported_ranges[0].num_samples; */ topo->scw = - wispy_phy_getcurprofile(wwidget->phydev)->num_samples; + spectool_phy_getcurprofile(wwidget->phydev)->num_samples; topo->sample_counts = (unsigned int *) malloc(sizeof(unsigned int) * topo->sch * topo->scw); @@ -278,7 +280,7 @@ /* always 1 for math */ topo->sweep_peak_max = 1; - } else if ((mode & WISPY_POLL_SWEEPCOMPLETE)) { + } else if ((mode & SPECTOOL_POLL_SWEEPCOMPLETE)) { topo->sweep_count_num = 0; topo->sweep_peak_max = 1; @@ -290,11 +292,10 @@ max = wwidget->sweepcache->num_alloc; for (s = 0; s < max; s++) { - /* Copy the aggregate sweep (ie our peak data) over... */ for (x = 0; x < topo->scw && x < wwidget->sweepcache->sweeplist[s]->num_samples; x++) { - int sdb = WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, + int sdb = SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, wwidget->sweepcache->sweeplist[s]->sample_data[x]); @@ -311,8 +312,10 @@ sc = ++(topo->sample_counts[(x * topo->sch) + ndb]); /* Record the max peak count for easy math later */ - if (sc > topo->sweep_peak_max) + if (sc > topo->sweep_peak_max) { + // printf("debug - sweep peak %d\n", sc); topo->sweep_peak_max = sc; + } } @@ -321,28 +324,28 @@ } } -void wispy_topo_context_help(gpointer *aux) { - Wispy_Help_Dialog("Topographic View", topo_help_txt); +void spectool_topo_context_help(gpointer *aux) { + Spectool_Help_Dialog("Topographic View", topo_help_txt); } -void wispy_topo_context_menu(GtkWidget *widget, GtkWidget *menu) { - WispyWidget *wwidget; - WispyTopo *topo; +void spectool_topo_context_menu(GtkWidget *widget, GtkWidget *menu) { + SpectoolWidget *wwidget; + SpectoolTopo *topo; GtkWidget *mi; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); - g_return_if_fail(IS_WISPY_TOPO(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_TOPO(widget)); - wwidget = WISPY_WIDGET(widget); - topo = WISPY_TOPO(widget); + wwidget = SPECTOOL_WIDGET(widget); + topo = SPECTOOL_TOPO(widget); mi = gtk_check_menu_item_new_with_label("Show dBm scale"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi); gtk_widget_set_sensitive(mi, (wwidget->wdr_slot >= 0)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), wwidget->show_dbm); g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(wispy_widget_context_dbm), + G_CALLBACK(spectool_widget_context_dbm), widget); gtk_widget_show(mi); @@ -351,36 +354,36 @@ gtk_widget_set_sensitive(mi, (wwidget->wdr_slot >= 0)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi), wwidget->show_dbm_lines); g_signal_connect_swapped(G_OBJECT(mi), "activate", - G_CALLBACK(wispy_widget_context_dbmlines), + G_CALLBACK(spectool_widget_context_dbmlines), widget); gtk_widget_show(mi); } -GtkWidget *wispy_topo_new(void) { - WispyTopo *topo; - WispyWidget *wwidget; +GtkWidget *spectool_topo_new(void) { + SpectoolTopo *topo; + SpectoolWidget *wwidget; - topo = gtk_type_new(wispy_topo_get_type()); + topo = gtk_type_new(spectool_topo_get_type()); - wwidget = WISPY_WIDGET(topo); + wwidget = SPECTOOL_WIDGET(topo); return GTK_WIDGET(topo); } -static gboolean wispy_topo_legend_expose(GtkWidget *widget, +static gboolean spectool_topo_legend_expose(GtkWidget *widget, GdkEventExpose *event, gpointer *aux) { cairo_t *cr; int x, y, w, h, dw, dh; - WispyTopo *topo; + SpectoolTopo *topo; cairo_pattern_t *pattern; int cp; g_return_if_fail(widget != NULL); g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_TOPO(aux)); + g_return_if_fail(IS_SPECTOOL_TOPO(aux)); - topo = WISPY_TOPO(aux); + topo = SPECTOOL_TOPO(aux); cr = gdk_cairo_create(widget->window); @@ -407,9 +410,9 @@ for (cp = 0; cp < topo->colormap_len; cp++) { cairo_pattern_add_color_stop_rgb(pattern, (float) (cp) / (topo->colormap_len), - WISPY_TOPO_COLOR(topo->colormap, cp, 0), - WISPY_TOPO_COLOR(topo->colormap, cp, 1), - WISPY_TOPO_COLOR(topo->colormap, cp, 2)); + SPECTOOL_TOPO_COLOR(topo->colormap, cp, 0), + SPECTOOL_TOPO_COLOR(topo->colormap, cp, 1), + SPECTOOL_TOPO_COLOR(topo->colormap, cp, 2)); } cairo_set_source(cr, pattern); @@ -422,15 +425,15 @@ return FALSE; } -static void wispy_topo_init(WispyTopo *topo) { - WispyWidget *wwidget; +static void spectool_topo_init(SpectoolTopo *topo) { + SpectoolWidget *wwidget; GtkWidget *temp; GtkWidget *legendv, *legendh; PangoAttrList *attr_list; PangoAttribute *attr; - wwidget = WISPY_WIDGET(topo); + wwidget = SPECTOOL_WIDGET(topo); wwidget->sweep_num_samples = 60; @@ -451,8 +454,8 @@ wwidget->show_dbm = 1; wwidget->show_dbm_lines = 1; - wwidget->wdr_sweep_func = wispy_topo_wdr_sweep; - wwidget->wdr_devbind_func = wispy_topo_wdr_devbind; + wwidget->wdr_sweep_func = spectool_topo_wdr_sweep; + wwidget->wdr_devbind_func = spectool_topo_wdr_devbind; wwidget->draw_mouse_move_func = NULL; wwidget->draw_mouse_click_func = NULL; @@ -461,20 +464,20 @@ #else wwidget->draw_timeout = 4000; #endif - wwidget->draw_func = wispy_topo_draw; + wwidget->draw_func = spectool_topo_draw; - wwidget->menu_func = wispy_topo_context_menu; + wwidget->menu_func = spectool_topo_context_menu; - wwidget->update_func = wispy_topo_update; + wwidget->update_func = spectool_topo_update; topo->colormap = topo_21_colormap; topo->colormap_len = topo_21_colormap_len; wwidget->timeout_ref = g_timeout_add(wwidget->draw_timeout, - (GSourceFunc) wispy_widget_timeout, wwidget); + (GSourceFunc) spectool_widget_timeout, wwidget); - wispy_widget_buildgui(wwidget); + spectool_widget_buildgui(wwidget); temp = gtk_frame_new("Legend"); gtk_box_pack_start(GTK_BOX(wwidget->vbox), temp, FALSE, FALSE, 2); @@ -489,7 +492,7 @@ gtk_box_pack_start(GTK_BOX(legendv), topo->legend_pix, FALSE, FALSE, 2); gtk_drawing_area_size(GTK_DRAWING_AREA(topo->legend_pix), -1, 10); gtk_signal_connect(GTK_OBJECT(topo->legend_pix), "expose_event", - (GtkSignalFunc) wispy_topo_legend_expose, topo); + (GtkSignalFunc) spectool_topo_legend_expose, topo); attr_list = pango_attr_list_new(); attr = pango_attr_size_new(7.0 * PANGO_SCALE); diff -Nru spectools-201004R1/spectool_gtk_topo.h spectools-201108r1/spectool_gtk_topo.h --- spectools-201004R1/spectool_gtk_topo.h 2007-10-03 18:31:56.000000000 +0000 +++ spectools-201108r1/spectool_gtk_topo.h 2011-06-10 15:53:29.000000000 +0000 @@ -1,4 +1,4 @@ -/* Wispy signal graph +/* Spectool signal graph * * GTK widget implementation * @@ -20,8 +20,8 @@ #include "config.h" -#ifndef __WISPY_TOPO_WIDGET_H__ -#define __WISPY_TOPO_WIDGET_H__ +#ifndef __SPECTOOL_TOPO_WIDGET_H__ +#define __SPECTOOL_TOPO_WIDGET_H__ #ifdef HAVE_GTK @@ -34,29 +34,29 @@ G_BEGIN_DECLS -#define WISPY_TYPE_TOPO \ - (wispy_topo_get_type()) -#define WISPY_TOPO(obj) \ +#define SPECTOOL_TYPE_TOPO \ + (spectool_topo_get_type()) +#define SPECTOOL_TOPO(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - WISPY_TYPE_TOPO, WispyTopo)) -#define WISPY_TOPO_CLASS(klass) \ + SPECTOOL_TYPE_TOPO, SpectoolTopo)) +#define SPECTOOL_TOPO_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass), \ - WISPY_TYPE_TOPO, WispyTopoClass)) -#define IS_WISPY_TOPO(obj) \ + SPECTOOL_TYPE_TOPO, SpectoolTopoClass)) +#define IS_SPECTOOL_TOPO(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - WISPY_TYPE_TOPO)) -#define IS_WISPY_TOPO_CLASS(klass) \ + SPECTOOL_TYPE_TOPO)) +#define IS_SPECTOOL_TOPO_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((class), \ - WISPY_TYPE_TOPO)) + SPECTOOL_TYPE_TOPO)) -typedef struct _WispyTopo WispyTopo; -typedef struct _WispyTopoClass WispyTopoClass; +typedef struct _SpectoolTopo SpectoolTopo; +typedef struct _SpectoolTopoClass SpectoolTopoClass; /* Access the color array */ -#define WISPY_TOPO_COLOR(a, b, c) ((a)[((b) * 3) + c]) +#define SPECTOOL_TOPO_COLOR(a, b, c) ((a)[((b) * 3) + c]) -struct _WispyTopo { - WispyWidget parent; +struct _SpectoolTopo { + SpectoolWidget parent; GtkWidget *sweepinfo; @@ -71,13 +71,13 @@ int sweep_count_num, sweep_peak_max; }; -struct _WispyTopoClass { - WispyWidgetClass parent_class; +struct _SpectoolTopoClass { + SpectoolWidgetClass parent_class; }; -GType wispy_topo_get_type(void); -GtkWidget *wispy_topo_new(void); -void wispy_topo_clear(void); +GType spectool_topo_get_type(void); +GtkWidget *spectool_topo_new(void); +void spectool_topo_clear(void); G_END_DECLS diff -Nru spectools-201004R1/spectool_gtk_widget.c spectools-201108r1/spectool_gtk_widget.c --- spectools-201004R1/spectool_gtk_widget.c 2009-01-27 19:26:26.000000000 +0000 +++ spectools-201108r1/spectool_gtk_widget.c 2011-06-15 04:04:23.000000000 +0000 @@ -23,28 +23,28 @@ #include "spectool_gtk_widget.h" /* control/picker pane width and initial height */ -#define WISPY_WIDGET_PADDING 5 +#define SPECTOOL_WIDGET_PADDING 5 -static void wispy_widget_class_init(WispyWidgetClass *class); -static void wispy_widget_init(WispyWidget *graph); -static void wispy_widget_destroy(GtkObject *object); -static void wispy_widget_realize(GtkWidget *widget); +static void spectool_widget_class_init(SpectoolWidgetClass *class); +static void spectool_widget_init(SpectoolWidget *graph); +static void spectool_widget_destroy(GtkObject *object); +static void spectool_widget_realize(GtkWidget *widget); -static gint wispy_widget_configure(GtkWidget *widget, +static gint spectool_widget_configure(GtkWidget *widget, GdkEventConfigure *event); -static gboolean wispy_widget_expose(GtkWidget *widget, +static gboolean spectool_widget_expose(GtkWidget *widget, GdkEventExpose *event, gpointer *aux); -static void wispy_widget_size_allocate(GtkWidget *widget, +static void spectool_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation); -static void wispy_widget_wdr_sweep(int slot, int mode, - wispy_sample_sweep *sweep, void *aux); +static void spectool_widget_wdr_sweep(int slot, int mode, + spectool_sample_sweep *sweep, void *aux); -static GType wispy_widget_child_type (GtkContainer *container); +static GType spectool_widget_child_type (GtkContainer *container); -G_DEFINE_TYPE(WispyWidget, wispy_widget, GTK_TYPE_BIN); +G_DEFINE_TYPE(SpectoolWidget, spectool_widget, GTK_TYPE_BIN); -void wispychannelopts_init(WispyChannelOpts *in) { +void spectoolchannelopts_init(SpectoolChannelOpts *in) { in->chan_h = -1; in->chanhit = NULL; in->chancolors = NULL; @@ -52,11 +52,11 @@ in->hi_chan = -1; } -static void wispy_widget_destroy(GtkObject *object) { - WispyWidget *wwidget = WISPY_WIDGET(object); +static void spectool_widget_destroy(GtkObject *object) { + SpectoolWidget *wwidget = SPECTOOL_WIDGET(object); wdr_del_sweepcb(wwidget->wdr, wwidget->wdr_slot, - wispy_widget_wdr_sweep, wwidget); + spectool_widget_wdr_sweep, wwidget); if (wwidget->wdr_slot >= 0) { wdr_del_ref(wwidget->wdr, wwidget->wdr_slot); @@ -68,65 +68,66 @@ wwidget->timeout_ref = -1; } - GTK_OBJECT_CLASS(wispy_widget_parent_class)->destroy(object); + GTK_OBJECT_CLASS(spectool_widget_parent_class)->destroy(object); } -GtkWidget *wispy_widget_new() { - WispyWidget *wwidget; +GtkWidget *spectool_widget_new() { + SpectoolWidget *wwidget; - wwidget = gtk_type_new(wispy_widget_get_type()); + wwidget = gtk_type_new(spectool_widget_get_type()); return GTK_WIDGET(wwidget); } -static void wispy_widget_wdr_sweep(int slot, int mode, - wispy_sample_sweep *sweep, void *aux) { - WispyWidget *wwidget; +static void spectool_widget_wdr_sweep(int slot, int mode, + spectool_sample_sweep *sweep, void *aux) { + SpectoolWidget *wwidget; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - wwidget = WISPY_WIDGET(aux); + wwidget = SPECTOOL_WIDGET(aux); wwidget->dirty = 1; /* Generic sweep handler to add it to our cache, all things get this */ - if ((mode & WISPY_POLL_ERROR)) { + if ((mode & SPECTOOL_POLL_ERROR)) { wwidget->phydev = NULL; if (wwidget->sweepcache != NULL) { - wispy_cache_free(wwidget->sweepcache); + spectool_cache_free(wwidget->sweepcache); wwidget->sweepcache = NULL; } wdr_del_ref(wwidget->wdr, wwidget->wdr_slot); wwidget->wdr_slot = -1; - } else if ((mode & WISPY_POLL_CONFIGURED)) { + } else if ((mode & SPECTOOL_POLL_CONFIGURED)) { if (wwidget->sweepcache != NULL) { - wispy_cache_free(wwidget->sweepcache); + spectool_cache_free(wwidget->sweepcache); wwidget->sweepcache = NULL; } if (wwidget->sweep_num_samples > 0) { wwidget->sweepcache = - wispy_cache_alloc(wwidget->sweep_num_samples, + spectool_cache_alloc(wwidget->sweep_num_samples, wwidget->sweep_keep_avg, wwidget->sweep_keep_peak); } wwidget->amp_offset_mdbm = - wispy_phy_getcurprofile(wwidget->phydev)->amp_offset_mdbm; + spectool_phy_getcurprofile(wwidget->phydev)->amp_offset_mdbm; wwidget->amp_res_mdbm = - wispy_phy_getcurprofile(wwidget->phydev)->amp_res_mdbm; + spectool_phy_getcurprofile(wwidget->phydev)->amp_res_mdbm; wwidget->base_db_offset = - WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, - wispy_phy_getcurprofile(wwidget->phydev)->rssi_max); + SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + spectool_phy_getcurprofile(wwidget->phydev)->rssi_max); wwidget->min_db_draw = - WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, 0); + SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, 0); + printf("debug - min db draw %d\n", wwidget->min_db_draw); } else if (wwidget->sweepcache != NULL && sweep != NULL) { - wispy_cache_append(wwidget->sweepcache, sweep); + spectool_cache_append(wwidget->sweepcache, sweep); wwidget->min_db_draw = - WISPY_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, + SPECTOOL_RSSI_CONVERT(wwidget->amp_offset_mdbm, wwidget->amp_res_mdbm, sweep->min_rssi_seen > 2 ? sweep->min_rssi_seen - 2: sweep->min_rssi_seen); } @@ -138,16 +139,16 @@ /* Common level function for opening a device, calls the secondary level * function if one exists after device is linked in */ -void wispy_widget_bind_dev(GtkWidget *widget, wispy_device_registry *wdr, +void spectool_widget_bind_dev(GtkWidget *widget, spectool_device_registry *wdr, int slot) { - WispyWidget *wwidget; + SpectoolWidget *wwidget; char ltxt[256]; - wispy_sample_sweep *ran; + spectool_sample_sweep *ran; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); - wwidget = WISPY_WIDGET(widget); + wwidget = SPECTOOL_WIDGET(widget); wwidget->wdr = wdr; @@ -163,7 +164,7 @@ /* register a sweep callback */ wdr_add_sweepcb(wwidget->wdr, wwidget->wdr_slot, - wispy_widget_wdr_sweep, wwidget->sweep_num_aggregate, + spectool_widget_wdr_sweep, wwidget->sweep_num_aggregate, wwidget); /* Call our secondary open function */ @@ -171,16 +172,16 @@ (*(wwidget->wdr_devbind_func))(widget, wdr, slot); /* Force calibration */ - if (wispy_get_state(wwidget->phydev) > WISPY_STATE_CONFIGURING) - wispy_widget_wdr_sweep(-1, WISPY_POLL_CONFIGURED, NULL, widget); + if (spectool_get_state(wwidget->phydev) > SPECTOOL_STATE_CONFIGURING) + spectool_widget_wdr_sweep(-1, SPECTOOL_POLL_CONFIGURED, NULL, widget); /* Toggle off the "no device" panel and give us the graph */ gtk_widget_show(wwidget->draw); } -static gboolean wispy_widget_menu_button_press(gpointer *widget, +static gboolean spectool_widget_menu_button_press(gpointer *widget, GdkEvent *event) { - WispyWidgetController *con = (WispyWidgetController *) widget; + SpectoolWidgetController *con = (SpectoolWidgetController *) widget; char alt_title_text[32]; g_return_if_fail(widget != NULL); @@ -221,19 +222,19 @@ return FALSE; } -WispyWidgetController *wispy_widget_buildcontroller(GtkWidget *widget) { +SpectoolWidgetController *spectool_widget_buildcontroller(GtkWidget *widget) { GtkWidget *hbox; - WispyWidgetController *con = - (WispyWidgetController *) malloc(sizeof(WispyWidgetController)); - WispyWidget *wwidget; + SpectoolWidgetController *con = + (SpectoolWidgetController *) malloc(sizeof(SpectoolWidgetController)); + SpectoolWidget *wwidget; GdkColor c; GtkStyle *style; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); - wwidget = WISPY_WIDGET(widget); + wwidget = SPECTOOL_WIDGET(widget); con->wwidget = wwidget; @@ -263,7 +264,7 @@ gtk_container_add(GTK_CONTAINER(con->menubutton), con->arrow); gtk_box_pack_end(GTK_BOX(hbox), con->menubutton, FALSE, FALSE, 0); g_signal_connect_swapped(G_OBJECT(con->menubutton), "event", - G_CALLBACK(wispy_widget_menu_button_press), + G_CALLBACK(spectool_widget_menu_button_press), G_OBJECT(con)); gtk_widget_show(con->arrow); @@ -277,27 +278,27 @@ return con; } -void wispy_widget_link_channel(GtkWidget *widget, WispyChannelOpts *opts) { - WispyWidget *wwidget; +void spectool_widget_link_channel(GtkWidget *widget, SpectoolChannelOpts *opts) { + SpectoolWidget *wwidget; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); - wwidget = WISPY_WIDGET(widget); + wwidget = SPECTOOL_WIDGET(widget); wwidget->chanopts = opts; } -gint wispy_widget_mouse_click(GtkWidget *widget, GdkEventButton *button, gpointer *aux) { - WispyWidget *wwidget; +gint spectool_widget_mouse_click(GtkWidget *widget, GdkEventButton *button, gpointer *aux) { + SpectoolWidget *wwidget; GtkWidget *menu; GdkEvent *event = (GdkEvent *) button; g_return_if_fail(widget != NULL); g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - wwidget = WISPY_WIDGET(aux); + wwidget = SPECTOOL_WIDGET(aux); /* Catch rightclick */ if (event->type == GDK_BUTTON_PRESS && event->button.button == 3 && @@ -320,7 +321,7 @@ return 0; } -void wispy_widget_buildgui(WispyWidget *widget) { +void spectool_widget_buildgui(SpectoolWidget *widget) { GtkWidget *vbox, *hbox, *hbox2; GtkWidget *temp; /* Sigh, is this really the only way to change the colors here? */ @@ -346,7 +347,7 @@ widget->draw = gtk_drawing_area_new(); gtk_signal_connect(GTK_OBJECT(widget->draw), "expose_event", - (GtkSignalFunc) wispy_widget_expose, widget); + (GtkSignalFunc) spectool_widget_expose, widget); /* Set mask */ gtk_widget_set_events(widget->draw, GDK_EXPOSURE_MASK | @@ -357,7 +358,7 @@ /* Attach mouse */ gtk_signal_connect(GTK_OBJECT(widget->draw), "button_press_event", - (GtkSignalFunc) wispy_widget_mouse_click, + (GtkSignalFunc) spectool_widget_mouse_click, widget); #ifndef HAVE_HILDON /* Hildon doesn't get mouseover events since it doesn't have mouse @@ -383,7 +384,7 @@ /* Sidebar contents */ vbox = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(vbox), WISPY_WIDGET_PADDING); + gtk_container_set_border_width(GTK_CONTAINER(vbox), SPECTOOL_WIDGET_PADDING); gtk_box_pack_end(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); eb = gtk_event_box_new(); @@ -411,7 +412,7 @@ gtk_widget_show(hbox); } -static void wispy_widget_init(WispyWidget *widget) { +static void spectool_widget_init(SpectoolWidget *widget) { widget->chanopts = NULL; widget->g_start_x = widget->g_end_x = widget->g_len_x = 0; widget->g_start_y = widget->g_end_y = widget->g_len_y = 0; @@ -422,7 +423,7 @@ widget->sweepcache = NULL; widget->wdr_slot = -1; - widget->hbox = gtk_hbox_new(FALSE, WISPY_WIDGET_PADDING); + widget->hbox = gtk_hbox_new(FALSE, SPECTOOL_WIDGET_PADDING); gtk_widget_set_parent(widget->hbox, GTK_WIDGET(widget)); GTK_BIN(widget)->child = widget->hbox; @@ -432,9 +433,9 @@ widget->dirty = 0; } -static void wispy_widget_size_allocate(GtkWidget *widget, +static void spectool_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { - WispyWidget *wwidget = WISPY_WIDGET(widget); + SpectoolWidget *wwidget = SPECTOOL_WIDGET(widget); widget->allocation = *allocation; @@ -454,10 +455,13 @@ wwidget->old_width = allocation->width; wwidget->old_height = allocation->height; } + + if (wwidget->sizechange_func != NULL) + (*(wwidget->sizechange_func))(widget, allocation); } -static void wispy_widget_size_request (GtkWidget *widget, GtkRequisition *requisition) { - WispyWidget *wwidget = WISPY_WIDGET(widget); +static void spectool_widget_size_request (GtkWidget *widget, GtkRequisition *requisition) { + SpectoolWidget *wwidget = SPECTOOL_WIDGET(widget); requisition->width = 0; requisition->height = 0; @@ -472,7 +476,7 @@ } } -void wispy_widget_draw(GtkWidget *widget, cairo_t *cr, WispyWidget *wwidget) { +void spectool_widget_draw(GtkWidget *widget, cairo_t *cr, SpectoolWidget *wwidget) { cairo_text_extents_t extents; int x, chpix, maxcw, start_db; const double dash_onoff[] = {2, 4}; @@ -656,7 +660,7 @@ cairo_restore(cr); } -void wispy_widget_graphics_update(WispyWidget *wwidget) { +void spectool_widget_graphics_update(SpectoolWidget *wwidget) { cairo_text_extents_t extents; int x, chpix, maxcw, start_db; const double dash_onoff[] = {2, 4}; @@ -676,7 +680,7 @@ widget = wwidget->draw; - /* Make an offscreen surface for this wispywidget if one doesn't exist (ie, it's a + /* Make an offscreen surface for this spectoolwidget if one doesn't exist (ie, it's a * new widget, or it's been resized) */ if (wwidget->offscreen == NULL) { wwidget->offscreen = @@ -693,10 +697,10 @@ cairo_fill(offcr); cairo_stroke(offcr); - wwidget->g_len_x = widget->allocation.width - (WISPY_WIDGET_PADDING * 2); - wwidget->g_len_y = widget->allocation.height - (WISPY_WIDGET_PADDING * 2); - wwidget->g_start_x = WISPY_WIDGET_PADDING; - wwidget->g_start_y = WISPY_WIDGET_PADDING; + wwidget->g_len_x = widget->allocation.width - (SPECTOOL_WIDGET_PADDING * 2); + wwidget->g_len_y = widget->allocation.height - (SPECTOOL_WIDGET_PADDING * 2); + wwidget->g_start_x = SPECTOOL_WIDGET_PADDING; + wwidget->g_start_y = SPECTOOL_WIDGET_PADDING; wwidget->g_end_x = wwidget->g_start_x + wwidget->g_len_x; wwidget->g_end_y = wwidget->g_start_y + wwidget->g_len_y; @@ -746,13 +750,13 @@ * width of a sample, so we can use that for all sorts of math later */ wwidget->wbar = (double) (widget->allocation.width - wwidget->dbm_w - - (WISPY_WIDGET_PADDING * 2) - 5) / + (SPECTOOL_WIDGET_PADDING * 2) - 5) / (double) (wwidget->sweepcache->latest->num_samples - 1); wwidget->g_len_x = wwidget->wbar * (wwidget->sweepcache->latest->num_samples - 1); - wwidget->g_len_y = widget->allocation.height - (WISPY_WIDGET_PADDING * 2); - wwidget->g_start_x = WISPY_WIDGET_PADDING + wwidget->dbm_w; - wwidget->g_start_y = WISPY_WIDGET_PADDING; + wwidget->g_len_y = widget->allocation.height - (SPECTOOL_WIDGET_PADDING * 2); + wwidget->g_start_x = SPECTOOL_WIDGET_PADDING + wwidget->dbm_w; + wwidget->g_start_y = SPECTOOL_WIDGET_PADDING; wwidget->g_end_x = wwidget->g_start_x + wwidget->g_len_x; wwidget->g_end_y = wwidget->g_start_y + wwidget->g_len_y; @@ -770,15 +774,15 @@ } /* Expose event on the drawable widget */ -static gint wispy_widget_expose(GtkWidget *widget, GdkEventExpose *event, +static gint spectool_widget_expose(GtkWidget *widget, GdkEventExpose *event, gpointer *aux) { int x, y, w, h; - WispyWidget *wwidget; + SpectoolWidget *wwidget; cairo_t *cr; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); - wwidget = WISPY_WIDGET(aux); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); + wwidget = SPECTOOL_WIDGET(aux); cr = gdk_cairo_create(widget->window); @@ -798,21 +802,21 @@ cairo_clip(cr); - wispy_widget_draw(widget, cr, wwidget); + spectool_widget_draw(widget, cr, wwidget); cairo_destroy(cr); return FALSE; } -void wispy_widget_update(GtkWidget *widget) { - WispyWidget *wwidget; +void spectool_widget_update(GtkWidget *widget) { + SpectoolWidget *wwidget; GdkRectangle update_rect; g_return_if_fail(widget != NULL); - g_return_if_fail(IS_WISPY_WIDGET(widget)); + g_return_if_fail(IS_SPECTOOL_WIDGET(widget)); - wwidget = WISPY_WIDGET(widget); + wwidget = SPECTOOL_WIDGET(widget); g_return_if_fail(wwidget->draw != NULL); @@ -827,26 +831,26 @@ (*(wwidget->update_func))(widget); } -gint wispy_widget_timeout(gpointer *data) { +gint spectool_widget_timeout(gpointer *data) { /* Kick the graphics update out here during a timered update */ - if (WISPY_WIDGET(data)->dirty) - wispy_widget_graphics_update(WISPY_WIDGET(data)); + if (SPECTOOL_WIDGET(data)->dirty) + spectool_widget_graphics_update(SPECTOOL_WIDGET(data)); - WISPY_WIDGET(data)->dirty = 0; + SPECTOOL_WIDGET(data)->dirty = 0; /* do a GTK level update */ - wispy_widget_update(GTK_WIDGET(data)); + spectool_widget_update(GTK_WIDGET(data)); return TRUE; } -static GType wispy_widget_child_type(GtkContainer *container) { +static GType spectool_widget_child_type(GtkContainer *container) { if (!GTK_BIN(container)->child) return GTK_TYPE_WIDGET; else return G_TYPE_NONE; } -static void wispy_widget_class_init(WispyWidgetClass *class) { +static void spectool_widget_class_init(SpectoolWidgetClass *class) { GObjectClass *gobject_class; GtkObjectClass *object_class; GtkWidgetClass *widget_class; @@ -857,11 +861,11 @@ widget_class = GTK_WIDGET_CLASS(class); container_class = (GtkContainerClass*) class; - object_class->destroy = wispy_widget_destroy; - widget_class->size_allocate = wispy_widget_size_allocate; - widget_class->size_request = wispy_widget_size_request; + object_class->destroy = spectool_widget_destroy; + widget_class->size_allocate = spectool_widget_size_allocate; + widget_class->size_request = spectool_widget_size_request; - container_class->child_type = wispy_widget_child_type; + container_class->child_type = spectool_widget_child_type; } /* Annoying that nothing else seems to include this, but we need it for @@ -1005,13 +1009,13 @@ *g *= 255; } -void wispy_widget_context_channels(gpointer *aux) { - WispyWidget *wwidget; +void spectool_widget_context_channels(gpointer *aux) { + SpectoolWidget *wwidget; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - wwidget = WISPY_WIDGET(aux); + wwidget = SPECTOOL_WIDGET(aux); if (wwidget->show_channels) { wwidget->show_channels = 0; @@ -1019,16 +1023,16 @@ wwidget->show_channels = 1; } - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_update(GTK_WIDGET(wwidget)); } -void wispy_widget_context_dbm(gpointer *aux) { - WispyWidget *wwidget; +void spectool_widget_context_dbm(gpointer *aux) { + SpectoolWidget *wwidget; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - wwidget = WISPY_WIDGET(aux); + wwidget = SPECTOOL_WIDGET(aux); if (wwidget->show_dbm) { wwidget->show_dbm = 0; @@ -1036,16 +1040,16 @@ wwidget->show_dbm = 1; } - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_update(GTK_WIDGET(wwidget)); } -void wispy_widget_context_dbmlines(gpointer *aux) { - WispyWidget *wwidget; +void spectool_widget_context_dbmlines(gpointer *aux) { + SpectoolWidget *wwidget; g_return_if_fail(aux != NULL); - g_return_if_fail(IS_WISPY_WIDGET(aux)); + g_return_if_fail(IS_SPECTOOL_WIDGET(aux)); - wwidget = WISPY_WIDGET(aux); + wwidget = SPECTOOL_WIDGET(aux); if (wwidget->show_dbm_lines) { wwidget->show_dbm_lines = 0; @@ -1053,6 +1057,6 @@ wwidget->show_dbm_lines = 1; } - wispy_widget_update(GTK_WIDGET(wwidget)); + spectool_widget_update(GTK_WIDGET(wwidget)); } diff -Nru spectools-201004R1/spectool_gtk_widget.h spectools-201108r1/spectool_gtk_widget.h --- spectools-201004R1/spectool_gtk_widget.h 2009-01-27 19:26:26.000000000 +0000 +++ spectools-201108r1/spectool_gtk_widget.h 2011-06-15 04:04:23.000000000 +0000 @@ -18,8 +18,8 @@ #include "config.h" -#ifndef __WISPY_GTK_WIDGET_H__ -#define __WISPY_GTK_WIDGET_H__ +#ifndef __SPECTOOL_GTK_WIDGET_H__ +#define __SPECTOOL_GTK_WIDGET_H__ #ifdef HAVE_GTK @@ -44,37 +44,37 @@ /* Hex color to cairo color */ #define HC2CC(x) ((double) ((double) (x) / (double) 0xFF)) -#define WISPY_TYPE_WIDGET \ - (wispy_widget_get_type()) -#define WISPY_WIDGET(obj) \ +#define SPECTOOL_TYPE_WIDGET \ + (spectool_widget_get_type()) +#define SPECTOOL_WIDGET(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - WISPY_TYPE_WIDGET, WispyWidget)) -#define WISPY_WIDGET_CLASS(klass) \ + SPECTOOL_TYPE_WIDGET, SpectoolWidget)) +#define SPECTOOL_WIDGET_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass), \ - WISPY_TYPE_WIDGET, WispyWidgetClass)) -#define IS_WISPY_WIDGET(obj) \ + SPECTOOL_TYPE_WIDGET, SpectoolWidgetClass)) +#define IS_SPECTOOL_WIDGET(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - WISPY_TYPE_WIDGET)) -#define IS_WISPY_WIDGET_CLASS(klass) \ + SPECTOOL_TYPE_WIDGET)) +#define IS_SPECTOOL_WIDGET_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((class), \ - WISPY_TYPE_WIDGET)) + SPECTOOL_TYPE_WIDGET)) -typedef struct _WispyWidget WispyWidget; -typedef struct _WispyWidgetClass WispyWidgetClass; +typedef struct _SpectoolWidget SpectoolWidget; +typedef struct _SpectoolWidgetClass SpectoolWidgetClass; -typedef struct _WispyChannelOpts { +typedef struct _SpectoolChannelOpts { int chan_h; int *chanhit; double *chancolors; - struct wispy_channels *chanset; + struct spectool_channels *chanset; /* Hilighted channel, if we're showing channels */ int hi_chan; -} WispyChannelOpts; +} SpectoolChannelOpts; -void wispychannelopts_init(WispyChannelOpts *in); +void spectoolchannelopts_init(SpectoolChannelOpts *in); -struct _WispyWidget { +struct _SpectoolWidget { GtkBinClass parent; int hlines; @@ -99,7 +99,7 @@ GtkWidget *sweepinfo; GtkWidget *draw, *menubutton; - wispy_sweep_cache *sweepcache; + spectool_sweep_cache *sweepcache; /* To be set by children to control behavior */ int sweep_num_samples; @@ -109,12 +109,12 @@ int sweep_num_aggregate; /* Callbacks used by open, sweep */ - void (* wdr_sweep_func)(int, int, wispy_sample_sweep *, void *); - void (* wdr_devbind_func)(GtkWidget *, wispy_device_registry *, int); + void (* wdr_sweep_func)(int, int, spectool_sample_sweep *, void *); + void (* wdr_devbind_func)(GtkWidget *, spectool_device_registry *, int); - wispy_device_registry *wdr; + spectool_device_registry *wdr; int wdr_slot; - wispy_phy *phydev; + spectool_phy *phydev; /* Graph title (INCLUDING formatting) */ char *graph_title; @@ -136,7 +136,10 @@ /* Callbacks for drawing */ int draw_timeout; - void (* draw_func)(GtkWidget *, cairo_t *, WispyWidget *); + void (* draw_func)(GtkWidget *, cairo_t *, SpectoolWidget *); + + /* Callbacks on size change */ + void (* sizechange_func)(GtkWidget *, GtkAllocation *); /* Plot channels on the bottom */ int show_channels; @@ -152,52 +155,52 @@ /* Update function */ void (* update_func)(GtkWidget *); - WispyChannelOpts *chanopts; + SpectoolChannelOpts *chanopts; /* Have we gotten a sweep? */ int dirty; }; -struct _WispyWidgetClass { +struct _SpectoolWidgetClass { GtkBinClass parent_class; }; /* Controller item - didn't feel like making this a full widget, so you ask * the widget to make you a controller then embed the box prior to the widget */ -typedef struct _WispyWidgetController { +typedef struct _SpectoolWidgetController { /* Main widget */ GtkWidget *evbox; GtkWidget *label, *arrow, *menubutton; - WispyWidget *wwidget; -} WispyWidgetController; + SpectoolWidget *wwidget; +} SpectoolWidgetController; -GType wispy_widget_get_type(void); -GtkWidget *wispy_widget_new(void); -void wispy_widget_bind_dev(GtkWidget *widget, wispy_device_registry *wdr, +GType spectool_widget_get_type(void); +GtkWidget *spectool_widget_new(void); +void spectool_widget_bind_dev(GtkWidget *widget, spectool_device_registry *wdr, int slot); /* Do the heavy lifting of actually constructing the GUI, so that child * classes can trigger this after setting up titles, etc. I'm sure this * isn't the most elegant method, someone can send me a patch */ -void wispy_widget_buildgui(WispyWidget *widget); +void spectool_widget_buildgui(SpectoolWidget *widget); /* Update the backing graphics */ -void wispy_widget_graphics_update(WispyWidget *wwidget); +void spectool_widget_graphics_update(SpectoolWidget *wwidget); -WispyWidgetController *wispy_widget_buildcontroller(GtkWidget *widget); +SpectoolWidgetController *spectool_widget_buildcontroller(GtkWidget *widget); -void wispy_widget_link_channel(GtkWidget *widget, WispyChannelOpts *opts); +void spectool_widget_link_channel(GtkWidget *widget, SpectoolChannelOpts *opts); /* Timeout function */ -gint wispy_widget_timeout(gpointer *data); +gint spectool_widget_timeout(gpointer *data); /* Calculate the channel clicked in */ -inline int wispy_widget_find_chan_pt(WispyWidget *wwidget, int x, int y); +inline int spectool_widget_find_chan_pt(SpectoolWidget *wwidget, int x, int y); -void wispy_widget_context_channels(gpointer *aux); -void wispy_widget_context_dbm(gpointer *aux); -void wispy_widget_context_dbmlines(gpointer *aux); +void spectool_widget_context_channels(gpointer *aux); +void spectool_widget_context_dbm(gpointer *aux); +void spectool_widget_context_dbmlines(gpointer *aux); /* Color space conversion tools */ inline void rgb_to_hsv(double r, double g, double b, diff -Nru spectools-201004R1/spectool_net_client.c spectools-201108r1/spectool_net_client.c --- spectools-201004R1/spectool_net_client.c 2009-03-01 03:51:17.000000000 +0000 +++ spectools-201108r1/spectool_net_client.c 2011-06-10 15:53:29.000000000 +0000 @@ -42,9 +42,9 @@ if ((ret = sscanf(url, "tcp://%256[^:]:%hd", sr->hostname, &(sr->port))) == 1) { - sr->port = WISPY_NET_DEFAULT_PORT; + sr->port = SPECTOOL_NET_DEFAULT_PORT; } else if (ret != 2) { - snprintf(errstr, WISPY_ERROR_MAX, "Could not parse server URL, expected " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not parse server URL, expected " "tcp://host:port"); sr->state = SPECTOOL_NET_STATE_ERROR; return -1; @@ -53,7 +53,7 @@ sr->host = gethostbyname(sr->hostname); if (sr->host == NULL) { - snprintf(errstr, WISPY_ERROR_MAX, "Could not resolve host '%s'", + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not resolve host '%s'", sr->hostname); sr->state = SPECTOOL_NET_STATE_ERROR; return -1; @@ -80,7 +80,7 @@ servaddr.sin_port = htons(sr->port); if ((sr->sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "Failed to create socket to server: %s", + snprintf(errstr, SPECTOOL_ERROR_MAX, "Failed to create socket to server: %s", strerror(errno)); sr->state = SPECTOOL_NET_STATE_ERROR; return -1; @@ -93,7 +93,7 @@ if (bind(sr->sock, (struct sockaddr *) &localaddr, sizeof(localaddr)) < 0) { close(sr->sock); - snprintf(errstr, WISPY_ERROR_MAX, "Failed to bind socket to server: %s", + snprintf(errstr, SPECTOOL_ERROR_MAX, "Failed to bind socket to server: %s", strerror(errno)); sr->state = SPECTOOL_NET_STATE_ERROR; return -1; @@ -101,7 +101,7 @@ if (connect(sr->sock, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) { close(sr->sock); - snprintf(errstr, WISPY_ERROR_MAX, "Failed to connect socket to server: %s", + snprintf(errstr, SPECTOOL_ERROR_MAX, "Failed to connect socket to server: %s", strerror(errno)); sr->state = SPECTOOL_NET_STATE_ERROR; return -1; @@ -166,19 +166,19 @@ } int spectool_netcli_poll(spectool_server *sr, char *errstr) { - wispy_fr_header *header; + spectool_fr_header *header; int res; int ret = 0; if (sr->sock < 0) return -1; - while (sr->read_fill - sr->read_pos >= wispy_fr_header_size()) { - header = (wispy_fr_header *) &(sr->rbuf[sr->read_pos]); + while (sr->read_fill - sr->read_pos >= spectool_fr_header_size()) { + header = (spectool_fr_header *) &(sr->rbuf[sr->read_pos]); /* Nuke the buffer entirely and start over if we can't find a * sentinel */ - if (ntohl(header->sentinel) != WISPY_NET_SENTINEL) { + if (ntohl(header->sentinel) != SPECTOOL_NET_SENTINEL) { sr->read_fill = 0; sr->read_pos = 0; return 0; @@ -197,7 +197,7 @@ } /* We only care about device and sweeps, the rest get ignored (for now) */ - if (header->block_type == WISPY_NET_FRAME_DEVICE) { + if (header->block_type == SPECTOOL_NET_FRAME_DEVICE) { if ((res = spectool_netcli_block_netdev(sr, header, errstr)) < 0) { return -1; } @@ -206,7 +206,7 @@ ret |= SPECTOOL_NETCLI_POLL_NEWDEVS; } - } else if (header->block_type == WISPY_NET_FRAME_SWEEP) { + } else if (header->block_type == SPECTOOL_NET_FRAME_SWEEP) { if ((res = spectool_netcli_block_sweep(sr, header, errstr)) < 0) { return -1; } @@ -223,7 +223,7 @@ if (errno == EAGAIN) return ret; - snprintf(errstr, WISPY_ERROR_MAX, "Failed to read from socket: %s", + snprintf(errstr, SPECTOOL_ERROR_MAX, "Failed to read from socket: %s", strerror(errno)); sr->state == SPECTOOL_NET_STATE_ERROR; return -1; @@ -243,7 +243,7 @@ if ((res = write(sr->sock, &(sr->wbuf[sr->write_pos]), sr->write_fill - sr->write_pos)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "write() failed on %s", + snprintf(errstr, SPECTOOL_ERROR_MAX, "write() failed on %s", strerror(errno)); return -1; } @@ -258,11 +258,11 @@ return 1; } -int spectool_netcli_block_netdev(spectool_server *sr, wispy_fr_header *header, +int spectool_netcli_block_netdev(spectool_server *sr, spectool_fr_header *header, char *errstr) { - wispy_fr_device *dev; + spectool_fr_device *dev; spectool_net_dev *sni; - int bsize = ntohs(header->frame_len) - wispy_fr_header_size(); + int bsize = ntohs(header->frame_len) - spectool_fr_header_size(); int num_devices; int x; @@ -272,14 +272,14 @@ for (x = 0; x < header->num_blocks; x++) { /* If we can't fit, bail. In the future this will have to be * rewritten to handle variable sized devices, maybe */ - if (bsize < wispy_fr_device_size() * (x + 1)) { + if (bsize < spectool_fr_device_size() * (x + 1)) { return -1; } - dev = (wispy_fr_device *) &(header->data[wispy_fr_device_size() * x]); + dev = (spectool_fr_device *) &(header->data[spectool_fr_device_size() * x]); /* Is this the last device? */ - if (dev->device_version == WISPY_NET_DEVTYPE_LASTDEV) { + if (dev->device_version == SPECTOOL_NET_DEVTYPE_LASTDEV) { sr->state == SPECTOOL_NET_STATE_CONFIGURED; return 1; } @@ -324,27 +324,27 @@ return 0; } -int spectool_netcli_block_sweep(spectool_server *sr, wispy_fr_header *header, +int spectool_netcli_block_sweep(spectool_server *sr, spectool_fr_header *header, char *errstr) { - wispy_fr_sweep *sweep; + spectool_fr_sweep *sweep; int x, y; - int bsize = ntohs(header->frame_len) - wispy_fr_header_size(); + int bsize = ntohs(header->frame_len) - spectool_fr_header_size(); int pos = 0; spectool_net_dev *sni; - wispy_sample_sweep *auxsweep; + spectool_sample_sweep *auxsweep; for (x = 0; x < header->num_blocks; x++) { - sweep = (wispy_fr_sweep *) &(header->data[pos]); + sweep = (spectool_fr_sweep *) &(header->data[pos]); if (bsize - pos < 2) { /* way too short, bail with error */ - snprintf(errstr, WISPY_ERROR_MAX, "Got runt sweep frame, bailing"); + snprintf(errstr, SPECTOOL_ERROR_MAX, "Got runt sweep frame, bailing"); return -1; } - if (ntohs(sweep->frame_len) < wispy_fr_sweep_size(0)) { + if (ntohs(sweep->frame_len) < spectool_fr_sweep_size(0)) { /* Again, too short */ - snprintf(errstr, WISPY_ERROR_MAX, "Got runt sweep frame, bailing"); + snprintf(errstr, SPECTOOL_ERROR_MAX, "Got runt sweep frame, bailing"); return -1; } @@ -357,18 +357,18 @@ } if (sni == NULL) { - snprintf(errstr, WISPY_ERROR_MAX, "Got sweep frame for device which " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Got sweep frame for device which " "was not advertised, discarding"); return -1; } if (ntohs(sweep->frame_len) < - wispy_fr_sweep_size(sni->num_samples)) { - snprintf(errstr, WISPY_ERROR_MAX, "Got sweep frame too small to hold " + spectool_fr_sweep_size(sni->num_samples)) { + snprintf(errstr, SPECTOOL_ERROR_MAX, "Got sweep frame too small to hold " "indicated number of samples, bailing - %u samples %u < %u", sni->num_samples, ntohs(sweep->frame_len), - wispy_fr_sweep_size(sni->num_samples)); + spectool_fr_sweep_size(sni->num_samples)); return -1; } @@ -380,12 +380,12 @@ if (sni->phydev == NULL) continue; - if ((auxsweep = ((wispy_net_dev_aux *) (sni->phydev->auxptr))->sweep) != NULL) { + if ((auxsweep = ((spectool_net_dev_aux *) (sni->phydev->auxptr))->sweep) != NULL) { free(auxsweep); } auxsweep = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(sni->num_samples)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(sni->num_samples)); /* Copy data out of our device record (this will change later when the * spectool internals change) */ @@ -421,9 +421,9 @@ auxsweep->phydev = sni->phydev; /* Flag that we got a new frame */ - ((wispy_net_dev_aux *) (sni->phydev->auxptr))->new_sweep = 1; - ((wispy_net_dev_aux *) (sni->phydev->auxptr))->sweep = auxsweep; - write(((wispy_net_dev_aux *) (sni->phydev->auxptr))->spipe[1], "0", 1); + ((spectool_net_dev_aux *) (sni->phydev->auxptr))->new_sweep = 1; + ((spectool_net_dev_aux *) (sni->phydev->auxptr))->sweep = auxsweep; + write(((spectool_net_dev_aux *) (sni->phydev->auxptr))->spipe[1], "0", 1); } return 1; @@ -432,7 +432,7 @@ int spectool_netcli_append(spectool_server *sr, uint8_t *data, int len, char *errstr) { if (sr->bufferwrite == 0) { if (write(sr->sock, data, len) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "write() failed on %s", + snprintf(errstr, SPECTOOL_ERROR_MAX, "write() failed on %s", strerror(errno)); return -1; } @@ -441,7 +441,7 @@ } if (sr->write_fill + len >= CLI_BUF_SZ) { - snprintf(errstr, WISPY_ERROR_MAX, "Network client write buffer can't " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Network client write buffer can't " "fit %d bytes, %d of %d full", len, sr->write_fill, CLI_BUF_SZ); return -1; } @@ -452,14 +452,14 @@ return 1; } -wispy_phy *spectool_netcli_enabledev(spectool_server *sr, unsigned int dev_id, +spectool_phy *spectool_netcli_enabledev(spectool_server *sr, unsigned int dev_id, char *errstr) { - wispy_phy *phyret; - wispy_net_dev_aux *aux; + spectool_phy *phyret; + spectool_net_dev_aux *aux; spectool_net_dev *sni; - wispy_fr_header *header; - wispy_fr_command *cmd; - wispy_fr_command_enabledev *cmde; + spectool_fr_header *header; + spectool_fr_command *cmd; + spectool_fr_command_enabledev *cmde; int sz; sni = sr->devlist; @@ -471,7 +471,7 @@ } if (sni == NULL) { - snprintf(errstr, WISPY_ERROR_MAX, "Could not find device %u in list " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not find device %u in list " "from server.", dev_id); return NULL; } @@ -479,24 +479,24 @@ if (sni->phydev != NULL) return sni->phydev; - sz = wispy_fr_header_size() + - wispy_fr_command_size(wispy_fr_command_enabledev_size(0)); + sz = spectool_fr_header_size() + + spectool_fr_command_size(spectool_fr_command_enabledev_size(0)); - header = (wispy_fr_header *) malloc(sz); + header = (spectool_fr_header *) malloc(sz); - cmd = (wispy_fr_command *) header->data; - cmde = (wispy_fr_command_enabledev *) cmd->command_data; + cmd = (spectool_fr_command *) header->data; + cmde = (spectool_fr_command_enabledev *) cmd->command_data; - header->sentinel = htonl(WISPY_NET_SENTINEL); + header->sentinel = htonl(SPECTOOL_NET_SENTINEL); header->frame_len = htons(sz); - header->proto_version = WISPY_NET_PROTO_VERSION; - header->block_type = WISPY_NET_FRAME_COMMAND; + header->proto_version = SPECTOOL_NET_PROTO_VERSION; + header->block_type = SPECTOOL_NET_FRAME_COMMAND; header->num_blocks = 1; cmd->frame_len = - htons(wispy_fr_command_size(wispy_fr_command_enabledev_size(0))); - cmd->command_id = WISPY_NET_COMMAND_ENABLEDEV; - cmd->command_len = htons(wispy_fr_command_enabledev_size(0)); + htons(spectool_fr_command_size(spectool_fr_command_enabledev_size(0))); + cmd->command_id = SPECTOOL_NET_COMMAND_ENABLEDEV; + cmd->command_len = htons(spectool_fr_command_enabledev_size(0)); cmde->device_id = htonl(dev_id); @@ -507,8 +507,8 @@ free(header); - phyret = (wispy_phy *) malloc(WISPY_PHY_SIZE); - aux = (wispy_net_dev_aux *) malloc(sizeof(wispy_net_dev_aux)); + phyret = (spectool_phy *) malloc(SPECTOOL_PHY_SIZE); + aux = (spectool_net_dev_aux *) malloc(sizeof(spectool_net_dev_aux)); phyret->auxptr = aux; aux->sweep = NULL; @@ -517,9 +517,9 @@ pipe(aux->spipe); fcntl(aux->spipe[0], F_SETFL, fcntl(aux->spipe[0], F_GETFL, 0) | O_NONBLOCK); - phyret->device_spec = (wispy_dev_spec *) malloc(sizeof(wispy_dev_spec)); + phyret->device_spec = (spectool_dev_spec *) malloc(sizeof(spectool_dev_spec)); - phyret->state = WISPY_STATE_CONFIGURING; + phyret->state = SPECTOOL_STATE_CONFIGURING; phyret->min_rssi_seen = -1; phyret->device_spec->device_id = sni->device_id; @@ -529,7 +529,7 @@ phyret->device_spec->num_sweep_ranges = 1; phyret->device_spec->supported_ranges = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(0)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(0)); phyret->device_spec->supported_ranges[0].num_samples = sni->def_num_samples; phyret->device_spec->supported_ranges[0].amp_offset_mdbm = sni->amp_offset_mdbm; @@ -554,7 +554,7 @@ phyret->getsweep_func = &spectool_net_getsweep; phyret->setposition_func = &spectool_net_setposition; - snprintf(phyret->device_spec->device_name, WISPY_PHY_NAME_MAX, + snprintf(phyret->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, "%s", sni->device_name); sni->phydev = phyret; @@ -562,13 +562,13 @@ return phyret; } -int spectool_netcli_disabledev(spectool_server *sr, wispy_phy *dev) { - wispy_net_dev_aux *aux; +int spectool_netcli_disabledev(spectool_server *sr, spectool_phy *dev) { + spectool_net_dev_aux *aux; spectool_net_dev *sni; - wispy_fr_header *header; - wispy_fr_command *cmd; - wispy_fr_command_disabledev *cmdd; - char errstr[WISPY_ERROR_MAX]; + spectool_fr_header *header; + spectool_fr_command *cmd; + spectool_fr_command_disabledev *cmdd; + char errstr[SPECTOOL_ERROR_MAX]; int sz; sni = sr->devlist; @@ -586,24 +586,24 @@ if (sni->phydev == NULL) return -1; - sz = wispy_fr_header_size() + - wispy_fr_command_size(wispy_fr_command_disabledev_size(0)); + sz = spectool_fr_header_size() + + spectool_fr_command_size(spectool_fr_command_disabledev_size(0)); - header = (wispy_fr_header *) malloc(sz); + header = (spectool_fr_header *) malloc(sz); - cmd = (wispy_fr_command *) header->data; - cmdd = (wispy_fr_command_disabledev *) cmd->command_data; + cmd = (spectool_fr_command *) header->data; + cmdd = (spectool_fr_command_disabledev *) cmd->command_data; - header->sentinel = htonl(WISPY_NET_SENTINEL); + header->sentinel = htonl(SPECTOOL_NET_SENTINEL); header->frame_len = htons(sz); - header->proto_version = WISPY_NET_PROTO_VERSION; - header->block_type = WISPY_NET_FRAME_COMMAND; + header->proto_version = SPECTOOL_NET_PROTO_VERSION; + header->block_type = SPECTOOL_NET_FRAME_COMMAND; header->num_blocks = 1; cmd->frame_len = - htons(wispy_fr_command_size(wispy_fr_command_disabledev_size(0))); - cmd->command_id = WISPY_NET_COMMAND_DISABLEDEV; - cmd->command_len = htons(wispy_fr_command_disabledev_size(0)); + htons(spectool_fr_command_size(spectool_fr_command_disabledev_size(0))); + cmd->command_id = SPECTOOL_NET_COMMAND_DISABLEDEV; + cmd->command_len = htons(spectool_fr_command_disabledev_size(0)); cmdd->device_id = htonl(sni->device_id); @@ -621,51 +621,51 @@ return 1; } -void spectool_net_setcalibration(wispy_phy *phydev, int in_calib) { +void spectool_net_setcalibration(spectool_phy *phydev, int in_calib) { return; } -int spectool_net_poll(wispy_phy *phydev) { - int ret = WISPY_POLL_NONE; +int spectool_net_poll(spectool_phy *phydev) { + int ret = SPECTOOL_POLL_NONE; char junk[8]; - read(((wispy_net_dev_aux *) phydev->auxptr)->spipe[0], junk, 8); + read(((spectool_net_dev_aux *) phydev->auxptr)->spipe[0], junk, 8); - if (phydev->state == WISPY_STATE_CONFIGURING) { - ret |= WISPY_POLL_CONFIGURED; - ret |= WISPY_POLL_ADDITIONAL; - phydev->state = WISPY_STATE_RUNNING; + if (phydev->state == SPECTOOL_STATE_CONFIGURING) { + ret |= SPECTOOL_POLL_CONFIGURED; + ret |= SPECTOOL_POLL_ADDITIONAL; + phydev->state = SPECTOOL_STATE_RUNNING; return ret; } - if (((wispy_net_dev_aux *) phydev->auxptr)->new_sweep) { - ((wispy_net_dev_aux *) phydev->auxptr)->new_sweep = 0; - ret |= WISPY_POLL_SWEEPCOMPLETE; + if (((spectool_net_dev_aux *) phydev->auxptr)->new_sweep) { + ((spectool_net_dev_aux *) phydev->auxptr)->new_sweep = 0; + ret |= SPECTOOL_POLL_SWEEPCOMPLETE; } return ret; } -int spectool_net_getpollfd(wispy_phy *phydev) { - return ((wispy_net_dev_aux *) phydev->auxptr)->spipe[0]; +int spectool_net_getpollfd(spectool_phy *phydev) { + return ((spectool_net_dev_aux *) phydev->auxptr)->spipe[0]; } -int spectool_net_open(wispy_phy *phydev) { +int spectool_net_open(spectool_phy *phydev) { return 1; } -int spectool_net_close(wispy_phy *phydev) { +int spectool_net_close(spectool_phy *phydev) { /* TODO - fill this in w/a close */ - close(((wispy_net_dev_aux *) phydev->auxptr)->spipe[0]); - close(((wispy_net_dev_aux *) phydev->auxptr)->spipe[1]); + close(((spectool_net_dev_aux *) phydev->auxptr)->spipe[0]); + close(((spectool_net_dev_aux *) phydev->auxptr)->spipe[1]); return 1; } -wispy_sample_sweep *spectool_net_getsweep(wispy_phy *phydev) { - return ((wispy_net_dev_aux *) phydev->auxptr)->sweep; +spectool_sample_sweep *spectool_net_getsweep(spectool_phy *phydev) { + return ((spectool_net_dev_aux *) phydev->auxptr)->sweep; } -int spectool_net_setposition(wispy_phy *phydev, int in_profile, +int spectool_net_setposition(spectool_phy *phydev, int in_profile, int start_khz, int res_hz) { /* todo - fill this in */ return 1; @@ -682,7 +682,7 @@ lsin.sin_addr.s_addr = INADDR_ANY; if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "netcli broadcast listen socket failed: %s", strerror(errno)); return -1; } @@ -690,7 +690,7 @@ /* we don't seem to need this in listen mode? x = 1; if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &x, sizeof(x)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "netcli broadcast listen socket bcast sockopt failed: %s", strerror(errno)); close(sock); @@ -701,7 +701,7 @@ fcntl(sock, F_SETFL, fcntl(sock, F_GETFL, 0) | O_NONBLOCK); if (bind(sock, (struct sockaddr *) &lsin, sizeof(lsin)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "netcli broadcast listen socket bind failed: %s", strerror(errno)); close(sock); @@ -714,11 +714,11 @@ int spectool_netcli_pollbroadcast(int sock, char *ret_url, char *errstr) { struct msghdr rcv_msg; struct iovec iov; - wispy_fr_broadcast buf; + spectool_fr_broadcast buf; struct sockaddr_in recv_addr; iov.iov_base = &buf; - iov.iov_len = sizeof(wispy_fr_broadcast); + iov.iov_len = sizeof(spectool_fr_broadcast); rcv_msg.msg_name = &recv_addr; rcv_msg.msg_namelen = sizeof(recv_addr); @@ -728,12 +728,12 @@ rcv_msg.msg_controllen = 0; if (recvmsg(sock, &rcv_msg, 0) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "netcli broadcast recv failed: %s", strerror(errno)); return -1; } - if (ntohl(buf.sentinel) == WISPY_NET_SENTINEL) { + if (ntohl(buf.sentinel) == SPECTOOL_NET_SENTINEL) { snprintf(ret_url, SPECTOOL_NETCLI_URL_MAX, "tcp://%s:%hu", inet_ntoa(recv_addr.sin_addr), ntohs(buf.server_port)); return 1; diff -Nru spectools-201004R1/spectool_net_client.h spectools-201108r1/spectool_net_client.h --- spectools-201004R1/spectool_net_client.h 2009-01-26 23:30:57.000000000 +0000 +++ spectools-201108r1/spectool_net_client.h 2011-06-10 15:53:29.000000000 +0000 @@ -10,8 +10,8 @@ * GNU General Public License for more details. */ -#ifndef __WISPY_NET_CLIENT_H__ -#define __WISPY_NET_CLIENT_H__ +#ifndef __SPECTOOL_NET_CLIENT_H__ +#define __SPECTOOL_NET_CLIENT_H__ #include "config.h" @@ -62,7 +62,7 @@ unsigned int num_samples; /* Local attributes if we're an activated device */ - wispy_phy *phydev; + spectool_phy *phydev; struct _spectool_net_dev *next; } spectool_net_dev; @@ -111,14 +111,14 @@ #define SPECTOOL_NET_STATE_CONFIGURED 2 #define SPECTOOL_NET_STATE_ERROR 255 -/* Auxptr struct attached to a wispy_net phydev */ -typedef struct _wispy_net_dev_aux { +/* Auxptr struct attached to a spectool_net phydev */ +typedef struct _spectool_net_dev_aux { spectool_server *server; spectool_net_dev *netdev; - wispy_sample_sweep *sweep; + spectool_sample_sweep *sweep; int new_sweep; int spipe[2]; -} wispy_net_dev_aux; +} spectool_net_dev_aux; /* Server manipulation commands - one server can have many phydevs linked to it, * and an app can conceivably have many servers. */ @@ -134,9 +134,9 @@ int spectool_netcli_getwritepend(spectool_server *sr); int spectool_netcli_getwritefd(spectool_server *sr); int spectool_netcli_poll(spectool_server *sr, char *errstr); -wispy_phy *spectool_netcli_enabledev(spectool_server *sr, unsigned int dev_id, +spectool_phy *spectool_netcli_enabledev(spectool_server *sr, unsigned int dev_id, char *errstr); -int spectool_netcli_disabledev(spectool_server *sr, wispy_phy *dev); +int spectool_netcli_disabledev(spectool_server *sr, spectool_phy *dev); /* Initialize a broadcast listening socket, retval is the socket */ int spectool_netcli_initbroadcast(short int port, char *errstr); @@ -154,24 +154,24 @@ #define SPECTOOL_NETCLI_POLL_NEWSWEEPS 4 /* Parsers */ -int spectool_netcli_block_netdev(spectool_server *sr, wispy_fr_header *header, +int spectool_netcli_block_netdev(spectool_server *sr, spectool_fr_header *header, char *errstr); -int spectool_netcli_block_sweep(spectool_server *sr, wispy_fr_header *header, +int spectool_netcli_block_sweep(spectool_server *sr, spectool_fr_header *header, char *errstr); /* Block management */ int spectool_netcli_append(spectool_server *sr, uint8_t *data, int len, char *errstr); /* Phydev hooks */ -void spectool_net_setcalibration(wispy_phy *phydev, int in_calib); -int spectool_net_poll(wispy_phy *phydev); -int spectool_net_getpollfd(wispy_phy *phydev); -int spectool_net_open(wispy_phy *phydev); -int spectool_net_close(wispy_phy *phydev); -wispy_sample_sweep *spectool_net_getsweep(wispy_phy *phydev); -int spectool_net_setposition(wispy_phy *phydev, int profilenum, int start_khz, +void spectool_net_setcalibration(spectool_phy *phydev, int in_calib); +int spectool_net_poll(spectool_phy *phydev); +int spectool_net_getpollfd(spectool_phy *phydev); +int spectool_net_open(spectool_phy *phydev); +int spectool_net_close(spectool_phy *phydev); +spectool_sample_sweep *spectool_net_getsweep(spectool_phy *phydev); +int spectool_net_setposition(spectool_phy *phydev, int profilenum, int start_khz, int res_hz); -wispy_sample_sweep *spectool_net_getsweep(wispy_phy *phydev); +spectool_sample_sweep *spectool_net_getsweep(spectool_phy *phydev); #endif diff -Nru spectools-201004R1/spectool_net.h spectools-201108r1/spectool_net.h --- spectools-201004R1/spectool_net.h 2007-12-02 06:30:35.000000000 +0000 +++ spectools-201108r1/spectool_net.h 2011-06-10 15:53:29.000000000 +0000 @@ -17,7 +17,7 @@ */ /* - * Implementation of the wispy network protocol + * Implementation of the spectool network protocol * {published url goes here} * * All multibyte values are expected to be big-endian @@ -29,14 +29,14 @@ * All sub-frame types contain a total frame length for future expandability. * * !!! NOTE !!! - * THIS IS NOT THE FINAL WISPY PROTOCOL, DON'T USE THIS EXPECTING IT TO STAY + * THIS IS NOT THE FINAL SPECTOOL PROTOCOL, DON'T USE THIS EXPECTING IT TO STAY * THE SAME, THIS IS KLUGED TOGETHER AS A PROTOTYPE BEFORE THE FINAL PROTOCOL * IS DEFINED BY METAGEEK. * */ -#ifndef __WISPY_NET_H__ -#define __WISPY_NET_H__ +#ifndef __SPECTOOL_NET_H__ +#define __SPECTOOL_NET_H__ #include "config.h" @@ -57,52 +57,52 @@ * Subframes of different types cannot be mixed in a single header. */ -#define WISPY_NET_FRAME_DEVICE 0x00 -#define WISPY_NET_FRAME_SWEEP 0x01 -#define WISPY_NET_FRAME_COMMAND 0x02 -#define WISPY_NET_FRAME_MESSAGE 0x03 +#define SPECTOOL_NET_FRAME_DEVICE 0x00 +#define SPECTOOL_NET_FRAME_SWEEP 0x01 +#define SPECTOOL_NET_FRAME_COMMAND 0x02 +#define SPECTOOL_NET_FRAME_MESSAGE 0x03 -#define WISPY_NET_SENTINEL 0xDECAFBAD +#define SPECTOOL_NET_SENTINEL 0xDECAFBAD -#define WISPY_NET_PROTO_VERSION 0x01 +#define SPECTOOL_NET_PROTO_VERSION 0x01 -#define WISPY_NET_DEFAULT_PORT 30569 +#define SPECTOOL_NET_DEFAULT_PORT 30569 -typedef struct _wispy_fr_header { +typedef struct _spectool_fr_header { uint32_t sentinel; uint16_t frame_len; uint8_t proto_version; uint8_t block_type; uint8_t num_blocks; uint8_t data[0]; -} __attribute__ ((packed)) wispy_fr_header; +} __attribute__ ((packed)) spectool_fr_header; /* Size of a container header */ -#define wispy_fr_header_size() (sizeof(wispy_fr_header)) +#define spectool_fr_header_size() (sizeof(spectool_fr_header)) -#define WISPY_NET_SWEEPTYPE_CUR 0x01 -#define WISPY_NET_SWEEPTYPE_AVG 0x02 -#define WISPY_NET_SWEEPTYPE_PEAK 0x03 +#define SPECTOOL_NET_SWEEPTYPE_CUR 0x01 +#define SPECTOOL_NET_SWEEPTYPE_AVG 0x02 +#define SPECTOOL_NET_SWEEPTYPE_PEAK 0x03 -typedef struct _wispy_fr_sweep { +typedef struct _spectool_fr_sweep { uint16_t frame_len; uint32_t device_id; uint8_t sweep_type; uint32_t start_sec; uint32_t start_usec; uint8_t sample_data[0]; -} __attribute__ ((packed)) wispy_fr_sweep; +} __attribute__ ((packed)) spectool_fr_sweep; /* Size of a sweep of N samples */ -#define wispy_fr_sweep_size(x) (sizeof(wispy_fr_sweep) + (x)) +#define spectool_fr_sweep_size(x) (sizeof(spectool_fr_sweep) + (x)) -#define WISPY_NET_DEVTYPE_USB1 0x01 -#define WISPY_NET_DEVTYPE_USB2 0x02 -#define WISPY_NET_DEVTYPE_LASTDEV 0xFF +#define SPECTOOL_NET_DEVTYPE_USB1 0x01 +#define SPECTOOL_NET_DEVTYPE_USB2 0x02 +#define SPECTOOL_NET_DEVTYPE_LASTDEV 0xFF -#define WISPY_NET_DEVFLAG_NONE 0x00 -#define WISPY_NET_DEVFLAG_VARSWEEP 0x01 -#define WISPY_NET_DEVFLAG_LOCKED 0x02 +#define SPECTOOL_NET_DEVFLAG_NONE 0x00 +#define SPECTOOL_NET_DEVFLAG_VARSWEEP 0x01 +#define SPECTOOL_NET_DEVFLAG_LOCKED 0x02 -typedef struct _wispy_fr_device { +typedef struct _spectool_fr_device { uint16_t frame_len; uint8_t device_version; uint16_t device_flags; @@ -121,71 +121,71 @@ uint32_t start_khz; uint32_t res_hz; uint16_t num_samples; -} __attribute__ ((packed)) wispy_fr_device; +} __attribute__ ((packed)) spectool_fr_device; /* Size of a device frame of N sample definitions */ -#define wispy_fr_device_size() (sizeof(wispy_fr_device)) +#define spectool_fr_device_size() (sizeof(spectool_fr_device)) -#define WISPY_NET_TXTTYPE_INFO 0x00 -#define WISPY_NET_TXTTYPE_ERROR 0x01 -#define WISPY_NET_TXTTYPE_FATAL 0x02 -typedef struct _wispy_fr_txtmessage { +#define SPECTOOL_NET_TXTTYPE_INFO 0x00 +#define SPECTOOL_NET_TXTTYPE_ERROR 0x01 +#define SPECTOOL_NET_TXTTYPE_FATAL 0x02 +typedef struct _spectool_fr_txtmessage { uint16_t frame_len; uint8_t message_type; uint16_t message_len; uint8_t message[0]; -} __attribute__ ((packed)) wispy_fr_txtmessage; +} __attribute__ ((packed)) spectool_fr_txtmessage; /* Size of a text message of N characters */ -#define wispy_fr_txtmessage_size(x) (sizeof(wispy_fr_txtmessage) + (x)) +#define spectool_fr_txtmessage_size(x) (sizeof(spectool_fr_txtmessage) + (x)) -#define WISPY_NET_COMMAND_NULL 0x00 -#define WISPY_NET_COMMAND_ENABLEDEV 0x01 -#define WISPY_NET_COMMAND_DISABLEDEV 0x02 -#define WISPY_NET_COMMAND_SETSCAN 0x03 -#define WISPY_NET_COMMAND_LOCK 0x04 -#define WISPY_NET_COMMAND_UNLOCK 0x05 -typedef struct _wispy_fr_command { +#define SPECTOOL_NET_COMMAND_NULL 0x00 +#define SPECTOOL_NET_COMMAND_ENABLEDEV 0x01 +#define SPECTOOL_NET_COMMAND_DISABLEDEV 0x02 +#define SPECTOOL_NET_COMMAND_SETSCAN 0x03 +#define SPECTOOL_NET_COMMAND_LOCK 0x04 +#define SPECTOOL_NET_COMMAND_UNLOCK 0x05 +typedef struct _spectool_fr_command { uint16_t frame_len; uint8_t command_id; uint16_t command_len; uint8_t command_data[0]; -} __attribute__ ((packed)) wispy_fr_command; -#define wispy_fr_command_size(x) (sizeof(wispy_fr_command) + (x)) +} __attribute__ ((packed)) spectool_fr_command; +#define spectool_fr_command_size(x) (sizeof(spectool_fr_command) + (x)) -typedef struct _wispy_fr_command_enabledev { +typedef struct _spectool_fr_command_enabledev { uint32_t device_id; -} __attribute__ ((packed)) wispy_fr_command_enabledev; -#define wispy_fr_command_enabledev_size(x) (sizeof(wispy_fr_command_enabledev)) +} __attribute__ ((packed)) spectool_fr_command_enabledev; +#define spectool_fr_command_enabledev_size(x) (sizeof(spectool_fr_command_enabledev)) -typedef struct _wispy_fr_command_disabledev { +typedef struct _spectool_fr_command_disabledev { uint32_t device_id; -} __attribute__ ((packed)) wispy_fr_command_disabledev; -#define wispy_fr_command_disabledev_size(x) (sizeof(wispy_fr_command_disabledev)) +} __attribute__ ((packed)) spectool_fr_command_disabledev; +#define spectool_fr_command_disabledev_size(x) (sizeof(spectool_fr_command_disabledev)) -typedef struct _wispy_fr_command_setscan { +typedef struct _spectool_fr_command_setscan { uint32_t device_id; uint32_t start_khz; uint32_t res_hz; uint32_t filter_bw_hz; uint16_t sweep_points; uint8_t lock_dev; -} __attribute__ ((packed)) wispy_fr_command_setscan; -#define wispy_fr_command_setscan_size(x) (sizeof(wispy_fr_command_setscan)) +} __attribute__ ((packed)) spectool_fr_command_setscan; +#define spectool_fr_command_setscan_size(x) (sizeof(spectool_fr_command_setscan)) -typedef struct _wispy_fr_command_lockdev { +typedef struct _spectool_fr_command_lockdev { uint32_t device_id; -} __attribute__ ((packed)) wispy_fr_command_lockdev; -#define wispy_fr_command_lockdev_size(x) (sizeof(wispy_fr_command_lockdev)) +} __attribute__ ((packed)) spectool_fr_command_lockdev; +#define spectool_fr_command_lockdev_size(x) (sizeof(spectool_fr_command_lockdev)) -typedef struct _wispy_fr_command_unlockdev { +typedef struct _spectool_fr_command_unlockdev { uint32_t device_id; -} __attribute__ ((packed)) wispy_fr_command_unlockdev; -#define wispy_fr_command_unlockdev_size(x) (sizeof(wispy_fr_command_unlockdev)) +} __attribute__ ((packed)) spectool_fr_command_unlockdev; +#define spectool_fr_command_unlockdev_size(x) (sizeof(spectool_fr_command_unlockdev)) -typedef struct _wispy_fr_broadcast { +typedef struct _spectool_fr_broadcast { uint32_t sentinel; uint8_t version; uint16_t server_port; -} __attribute__ ((packed)) wispy_fr_broadcast; +} __attribute__ ((packed)) spectool_fr_broadcast; #endif diff -Nru spectools-201004R1/spectool_net_server.c spectools-201108r1/spectool_net_server.c --- spectools-201004R1/spectool_net_server.c 2009-02-28 04:34:47.000000000 +0000 +++ spectools-201108r1/spectool_net_server.c 2011-06-10 15:53:29.000000000 +0000 @@ -41,12 +41,12 @@ * it would fragment all over, so this should be fine */ #define CLI_BUF_SZ 2048 -typedef struct _wispy_tcpcli_dev { +typedef struct _spectool_tcpcli_dev { uint32_t device_id; - struct _wispy_tcpcli_dev *next; -} wispy_tcpcli_dev; + struct _spectool_tcpcli_dev *next; +} spectool_tcpcli_dev; -typedef struct _wispy_tcpcli { +typedef struct _spectool_tcpcli { int fd; uint8_t wbuf[CLI_BUF_SZ]; uint8_t rbuf[CLI_BUF_SZ]; @@ -59,17 +59,17 @@ int write_fill, read_fill; /* List of devices we send sweep data for */ - wispy_tcpcli_dev *devlist; + spectool_tcpcli_dev *devlist; - struct _wispy_tcpcli *next; -} wispy_tcpcli; + struct _spectool_tcpcli *next; +} spectool_tcpcli; -typedef struct _wispy_tcpserv_dev { - wispy_phy phydev; +typedef struct _spectool_tcpserv_dev { + spectool_phy phydev; int lock_fd; -} wispy_tcpserv_dev; +} spectool_tcpserv_dev; -typedef struct _wispy_tcpserv { +typedef struct _spectool_tcpserv { short int port; unsigned int maxclients; struct sockaddr_in serv_addr; @@ -77,14 +77,14 @@ fd_set master_fds; unsigned int maxfd; - wispy_tcpcli *cli_list; + spectool_tcpcli *cli_list; - wispy_tcpserv_dev *devs; + spectool_tcpserv_dev *devs; int ndev; -} wispy_tcpserv; +} spectool_tcpserv; -int wts_init(wispy_tcpserv *wts) { +int wts_init(spectool_tcpserv *wts) { wts->port = 0; wts->maxclients = 0; wts->bindfd = 0; @@ -97,7 +97,7 @@ return 1; } -int wts_bind(wispy_tcpserv *wts, char *addr, short int port, char *errstr) { +int wts_bind(spectool_tcpserv *wts, char *addr, short int port, char *errstr) { int sz = 2; /* TODO - support binding to an address */ @@ -111,23 +111,23 @@ wts->serv_addr.sin_port = htons(port); if ((wts->bindfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "socket() failed %s", strerror(errno)); + snprintf(errstr, SPECTOOL_ERROR_MAX, "socket() failed %s", strerror(errno)); return -1; } if (setsockopt(wts->bindfd, SOL_SOCKET, SO_REUSEADDR, &sz, sizeof(sz)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "setsockopt() failed %s", strerror(errno)); + snprintf(errstr, SPECTOOL_ERROR_MAX, "setsockopt() failed %s", strerror(errno)); return -1; } if (bind(wts->bindfd, (struct sockaddr *) &(wts->serv_addr), sizeof(wts->serv_addr)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "bind() failed %s", strerror(errno)); + snprintf(errstr, SPECTOOL_ERROR_MAX, "bind() failed %s", strerror(errno)); return -1; } if (listen(wts->bindfd, 10) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "listen() failed %s", strerror(errno)); + snprintf(errstr, SPECTOOL_ERROR_MAX, "listen() failed %s", strerror(errno)); return -1; } @@ -139,9 +139,9 @@ return 1; } -int wts_cli_append(wispy_tcpcli *tci, uint8_t *data, int len, char *errstr) { +int wts_cli_append(spectool_tcpcli *tci, uint8_t *data, int len, char *errstr) { if (tci->write_fill + len >= CLI_BUF_SZ) { - snprintf(errstr, WISPY_ERROR_MAX, "client write buffer %d can't fit %d bytes, " + snprintf(errstr, SPECTOOL_ERROR_MAX, "client write buffer %d can't fit %d bytes, " "%d of %d full", tci->fd, len, tci->write_fill, CLI_BUF_SZ); return -1; } @@ -152,46 +152,46 @@ return 1; } -int wts_send_devblock(wispy_tcpserv *wts, wispy_tcpcli *tci, char *errstr) { - wispy_fr_header *hdr; - wispy_fr_device *dev; - wispy_fr_sweep *sweep; +int wts_send_devblock(spectool_tcpserv *wts, spectool_tcpcli *tci, char *errstr) { + spectool_fr_header *hdr; + spectool_fr_device *dev; + spectool_fr_sweep *sweep; int devblen = 0, x = 0, r = 0; - wispy_sample_sweep *ran; + spectool_sample_sweep *ran; /* Number of devices */ - devblen = wispy_fr_device_size() * wts->ndev; + devblen = spectool_fr_device_size() * wts->ndev; /* Plus one more device for the end block */ - devblen += wispy_fr_device_size(); + devblen += spectool_fr_device_size(); /* Big allocation of the entire block */ - hdr = (wispy_fr_header *) malloc(wispy_fr_header_size() + + hdr = (spectool_fr_header *) malloc(spectool_fr_header_size() + devblen); - hdr->sentinel = htonl(WISPY_NET_SENTINEL); - hdr->frame_len = htons(wispy_fr_header_size() + devblen); - hdr->proto_version = WISPY_NET_PROTO_VERSION; - hdr->block_type = WISPY_NET_FRAME_DEVICE; + hdr->sentinel = htonl(SPECTOOL_NET_SENTINEL); + hdr->frame_len = htons(spectool_fr_header_size() + devblen); + hdr->proto_version = SPECTOOL_NET_PROTO_VERSION; + hdr->block_type = SPECTOOL_NET_FRAME_DEVICE; hdr->num_blocks = wts->ndev + 1; /* ndevs + lastdev */ int lastpos = 0; for (x = 0; x < wts->ndev; x++) { - wispy_tcpserv_dev *d = &(wts->devs[x]); + spectool_tcpserv_dev *d = &(wts->devs[x]); - dev = (wispy_fr_device *) &(hdr->data[lastpos]); + dev = (spectool_fr_device *) &(hdr->data[lastpos]); - lastpos += wispy_fr_device_size(); + lastpos += spectool_fr_device_size(); - dev->frame_len = htons(wispy_fr_device_size()); + dev->frame_len = htons(spectool_fr_device_size()); dev->device_version = d->phydev.device_spec->device_version; dev->device_flags = htons(d->phydev.device_spec->device_flags); dev->device_id = htonl(d->phydev.device_spec->device_id); - dev->device_name_len = strlen(wispy_phy_getname(&(d->phydev))); - snprintf(dev->device_name, 256, "%s", wispy_phy_getname(&(d->phydev))); + dev->device_name_len = strlen(spectool_phy_getname(&(d->phydev))); + snprintf(dev->device_name, 256, "%s", spectool_phy_getname(&(d->phydev))); - ran = wispy_phy_getcurprofile(&(d->phydev)); + ran = spectool_phy_getcurprofile(&(d->phydev)); dev->amp_offset_mdbm = htonl(ran->amp_offset_mdbm * -1); dev->amp_res_mdbm = htonl(ran->amp_res_mdbm); @@ -221,13 +221,13 @@ /* Set the last device sentinel -- nothing needs to be set except the * length of the block and the device type */ - dev = (wispy_fr_device *) &(hdr->data[lastpos]); - memset(dev, 0, wispy_fr_device_size()); - dev->frame_len = htons(wispy_fr_device_size()); - dev->device_version = WISPY_NET_DEVTYPE_LASTDEV; + dev = (spectool_fr_device *) &(hdr->data[lastpos]); + memset(dev, 0, spectool_fr_device_size()); + dev->frame_len = htons(spectool_fr_device_size()); + dev->device_version = SPECTOOL_NET_DEVTYPE_LASTDEV; if (wts_cli_append(tci, (uint8_t *) hdr, - wispy_fr_header_size() + devblen, + spectool_fr_header_size() + devblen, errstr) < 0) return -1; @@ -236,8 +236,8 @@ return 1; } -int wts_send_devblock_all(wispy_tcpserv *wts, char *errstr) { - wispy_tcpcli *tci = wts->cli_list; +int wts_send_devblock_all(spectool_tcpserv *wts, char *errstr) { + spectool_tcpcli *tci = wts->cli_list; while (tci != NULL) { wts_send_devblock(wts, tci, errstr); @@ -248,9 +248,9 @@ return 1; } -wispy_tcpcli *wts_accept(wispy_tcpserv *wts, char *errstr) { +spectool_tcpcli *wts_accept(spectool_tcpserv *wts, char *errstr) { int newfd; - wispy_tcpcli *tc; + spectool_tcpcli *tc; struct sockaddr_in client_addr; socklen_t client_len; char inhost[16]; @@ -261,11 +261,11 @@ if ((newfd = accept(wts->bindfd, (struct sockaddr *) &client_addr, &client_len)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "accept() failed %s", strerror(errno)); + snprintf(errstr, SPECTOOL_ERROR_MAX, "accept() failed %s", strerror(errno)); return NULL; } - tc = (wispy_tcpcli *) malloc(sizeof(wispy_tcpcli)); + tc = (spectool_tcpcli *) malloc(sizeof(spectool_tcpcli)); tc->fd = newfd; @@ -286,9 +286,9 @@ return tc; } -void wts_remove(wispy_tcpserv *wts, wispy_tcpcli *tc, char *errstr) { - wispy_tcpcli *tci = wts->cli_list; - wispy_tcpcli *tcb = NULL; +void wts_remove(spectool_tcpserv *wts, spectool_tcpcli *tc, char *errstr) { + spectool_tcpcli *tci = wts->cli_list; + spectool_tcpcli *tcb = NULL; int x, dchange; /* Unlock any devices they controlled */ @@ -327,8 +327,8 @@ wts_send_devblock_all(wts, errstr); } -int wts_fdset(wispy_tcpserv *wts, fd_set *rfd, fd_set *wfd) { - wispy_tcpcli *tci = wts->cli_list; +int wts_fdset(spectool_tcpserv *wts, fd_set *rfd, fd_set *wfd) { + spectool_tcpcli *tci = wts->cli_list; int x; FD_SET(wts->bindfd, rfd); @@ -347,42 +347,42 @@ tci = tci->next; } - /* wispy devices */ + /* spectool devices */ for (x = 0; x < wts->ndev; x++) { - FD_SET(wispy_phy_getpollfd(&(wts->devs[x].phydev)), rfd); + FD_SET(spectool_phy_getpollfd(&(wts->devs[x].phydev)), rfd); - if (wispy_phy_getpollfd(&(wts->devs[x].phydev)) > wts->maxfd) - wts->maxfd = wispy_phy_getpollfd(&(wts->devs[x].phydev)); + if (spectool_phy_getpollfd(&(wts->devs[x].phydev)) > wts->maxfd) + wts->maxfd = spectool_phy_getpollfd(&(wts->devs[x].phydev)); } return 1; } -int wts_send_sweepblock(wispy_tcpserv *wts, - wispy_phy *phydev, wispy_sample_sweep *sweep, +int wts_send_sweepblock(spectool_tcpserv *wts, + spectool_phy *phydev, spectool_sample_sweep *sweep, char *errstr) { - wispy_fr_header *hdr; - wispy_fr_sweep *fsweep; - wispy_tcpcli *tci = NULL; + spectool_fr_header *hdr; + spectool_fr_sweep *fsweep; + spectool_tcpcli *tci = NULL; int x; /* Big allocation */ - hdr = (wispy_fr_header *) malloc(wispy_fr_header_size() + - wispy_fr_sweep_size(sweep->num_samples)); + hdr = (spectool_fr_header *) malloc(spectool_fr_header_size() + + spectool_fr_sweep_size(sweep->num_samples)); - hdr->sentinel = htonl(WISPY_NET_SENTINEL); - hdr->frame_len = htons(wispy_fr_header_size() + - wispy_fr_sweep_size(sweep->num_samples)); - hdr->proto_version = WISPY_NET_PROTO_VERSION; - hdr->block_type = WISPY_NET_FRAME_SWEEP; + hdr->sentinel = htonl(SPECTOOL_NET_SENTINEL); + hdr->frame_len = htons(spectool_fr_header_size() + + spectool_fr_sweep_size(sweep->num_samples)); + hdr->proto_version = SPECTOOL_NET_PROTO_VERSION; + hdr->block_type = SPECTOOL_NET_FRAME_SWEEP; hdr->num_blocks = 1; - fsweep = (wispy_fr_sweep *) hdr->data; + fsweep = (spectool_fr_sweep *) hdr->data; - fsweep->frame_len = htons(wispy_fr_sweep_size(sweep->num_samples)); + fsweep->frame_len = htons(spectool_fr_sweep_size(sweep->num_samples)); fsweep->device_id = htonl(phydev->device_spec->device_id); - fsweep->sweep_type = WISPY_NET_SWEEPTYPE_CUR; + fsweep->sweep_type = SPECTOOL_NET_SWEEPTYPE_CUR; fsweep->start_sec = htonl(sweep->tm_start.tv_sec); fsweep->start_usec = htonl(sweep->tm_start.tv_usec); @@ -394,7 +394,7 @@ while (tci != NULL) { int send = 0; - wispy_tcpcli_dev *di = tci->devlist; + spectool_tcpcli_dev *di = tci->devlist; while (di != NULL) { if (di->device_id == phydev->device_spec->device_id) { send = 1; @@ -406,8 +406,8 @@ if (send) { if (wts_cli_append(tci, (uint8_t *) hdr, - wispy_fr_header_size() + - wispy_fr_sweep_size(sweep->num_samples), + spectool_fr_header_size() + + spectool_fr_sweep_size(sweep->num_samples), errstr) < 0) printf("Failure to send\n"); } @@ -420,42 +420,42 @@ return 1; } -int wts_handle_command(wispy_tcpserv *wts, wispy_tcpcli *tci, - wispy_fr_header *frh) { +int wts_handle_command(spectool_tcpserv *wts, spectool_tcpcli *tci, + spectool_fr_header *frh) { int blk, offt = 0; - wispy_fr_command *ch; - wispy_tcpcli_dev *di, *pdi; + spectool_fr_command *ch; + spectool_tcpcli_dev *di, *pdi; int did, x; - if (ntohs(frh->frame_len) < wispy_fr_command_size(0)) { + if (ntohs(frh->frame_len) < spectool_fr_command_size(0)) { fprintf(stderr, "Short command frame, something is wrong, " "total len < cmd header\n"); return -1; } for (blk = 0; blk < frh->num_blocks; blk++) { - ch = (wispy_fr_command *) &(frh->data[offt]); + ch = (spectool_fr_command *) &(frh->data[offt]); offt += ntohs(ch->frame_len); - if (ch->command_id == WISPY_NET_COMMAND_NULL) { + if (ch->command_id == SPECTOOL_NET_COMMAND_NULL) { /* No action */ continue; - } else if (ch->command_id == WISPY_NET_COMMAND_ENABLEDEV) { - wispy_fr_command_enabledev *ce; + } else if (ch->command_id == SPECTOOL_NET_COMMAND_ENABLEDEV) { + spectool_fr_command_enabledev *ce; int matched = 0; /* Find the device and activate it */ if (ntohs(ch->frame_len) < - wispy_fr_command_size(wispy_fr_command_enabledev_size())) { + spectool_fr_command_size(spectool_fr_command_enabledev_size())) { fprintf(stderr, "Short enabledev frame, something is wrong, skipping\n"); continue; } - ce = (wispy_fr_command_enabledev *) ch->command_data; + ce = (spectool_fr_command_enabledev *) ch->command_data; for (x = 0; x < wts->ndev; x++) { - if (wispy_phy_getdevid(&(wts->devs[x].phydev)) == + if (spectool_phy_getdevid(&(wts->devs[x].phydev)) == ntohl(ce->device_id)) { matched = 1; break; @@ -484,22 +484,22 @@ continue; /* Make a new record */ - di = (wispy_tcpcli_dev *) malloc(sizeof(wispy_tcpcli_dev)); + di = (spectool_tcpcli_dev *) malloc(sizeof(spectool_tcpcli_dev)); di->next = tci->devlist; di->device_id = ntohl(ce->device_id); tci->devlist = di; - } else if (ch->command_id == WISPY_NET_COMMAND_DISABLEDEV) { - wispy_fr_command_disabledev *cd; + } else if (ch->command_id == SPECTOOL_NET_COMMAND_DISABLEDEV) { + spectool_fr_command_disabledev *cd; int matched = 0; if (ntohs(ch->frame_len) < - wispy_fr_command_size(wispy_fr_command_disabledev_size())) { + spectool_fr_command_size(spectool_fr_command_disabledev_size())) { fprintf(stderr, "Short disabledev frame, something is wrong, skipping\n"); continue; } - cd = (wispy_fr_command_disabledev *) ch->command_data; + cd = (spectool_fr_command_disabledev *) ch->command_data; /* Shortcut removing the only device */ if (tci->devlist != NULL && tci->devlist->device_id == ntohl(cd->device_id)) { @@ -521,9 +521,9 @@ } } - } else if (ch->command_id == WISPY_NET_COMMAND_SETSCAN) { + } else if (ch->command_id == SPECTOOL_NET_COMMAND_SETSCAN) { if (ntohs(ch->frame_len) < - wispy_fr_command_size(wispy_fr_command_setscan_size())) { + spectool_fr_command_size(spectool_fr_command_setscan_size())) { fprintf(stderr, "Short setscan frame, something is wrong, skipping\n"); continue; } @@ -533,8 +533,8 @@ return 1; } -int wts_poll(wispy_tcpserv *wts, fd_set *rfd, fd_set *wfd, char *errstr) { - wispy_tcpcli *tci = NULL, *tcb = NULL; +int wts_poll(spectool_tcpserv *wts, fd_set *rfd, fd_set *wfd, char *errstr) { + spectool_tcpcli *tci = NULL, *tcb = NULL; int x = 0, r = 0; tci = wts->cli_list; @@ -547,7 +547,7 @@ if ((res = write(tcb->fd, &(tcb->wbuf[tcb->write_pos]), tcb->write_fill - tcb->write_pos)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, "write() failed on fd %d %s", + snprintf(errstr, SPECTOOL_ERROR_MAX, "write() failed on fd %d %s", tcb->fd, strerror(errno)); wts_remove(wts, tcb, errstr); return 0; @@ -570,7 +570,7 @@ if (errno == EAGAIN) continue; - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "fd %d read error %s\n", tcb->fd, strerror(errno)); wts_remove(wts, tcb, errstr); @@ -581,10 +581,10 @@ /* Process incoming packets */ while (tcb->read_pos < tcb->read_fill && - tcb->read_fill - tcb->read_pos > wispy_fr_header_size()) { - wispy_fr_header *frh = (wispy_fr_header *) &(tcb->rbuf[tcb->read_pos]); + tcb->read_fill - tcb->read_pos > spectool_fr_header_size()) { + spectool_fr_header *frh = (spectool_fr_header *) &(tcb->rbuf[tcb->read_pos]); - if (ntohl(frh->sentinel) != WISPY_NET_SENTINEL) { + if (ntohl(frh->sentinel) != SPECTOOL_NET_SENTINEL) { tcb->read_fill = 0; tcb->read_pos = 0; /* Yes, I know, 'goto'. Go away. */ @@ -599,7 +599,7 @@ /* advance to the end of the frame */ tcb->read_pos += ntohs(frh->frame_len); - if (frh->block_type == WISPY_NET_FRAME_COMMAND) { + if (frh->block_type == SPECTOOL_NET_FRAME_COMMAND) { wts_handle_command(wts, tcb, frh); } @@ -628,41 +628,41 @@ } for (x = 0; x < wts->ndev; x++) { - if (wispy_get_state(&(wts->devs[x].phydev)) == WISPY_STATE_ERROR) { - snprintf(errstr, WISPY_ERROR_MAX, "Wispy phy %d in error state: %s", - x, wispy_get_error(&(wts->devs[x].phydev))); + if (spectool_get_state(&(wts->devs[x].phydev)) == SPECTOOL_STATE_ERROR) { + snprintf(errstr, SPECTOOL_ERROR_MAX, "Spectool phy %d in error state: %s", + x, spectool_get_error(&(wts->devs[x].phydev))); return -1; } - if (FD_ISSET(wispy_phy_getpollfd(&(wts->devs[x].phydev)), rfd) == 0) + if (FD_ISSET(spectool_phy_getpollfd(&(wts->devs[x].phydev)), rfd) == 0) continue; do { - r = wispy_phy_poll(&(wts->devs[x].phydev)); + r = spectool_phy_poll(&(wts->devs[x].phydev)); - if ((r & WISPY_POLL_ERROR)) { - snprintf(errstr, WISPY_ERROR_MAX, "Wispy phy %d poll failed: %s", - x, wispy_get_error(&(wts->devs[x].phydev))); + if ((r & SPECTOOL_POLL_ERROR)) { + snprintf(errstr, SPECTOOL_ERROR_MAX, "Spectool phy %d poll failed: %s", + x, spectool_get_error(&(wts->devs[x].phydev))); return -1; } - if ((r & WISPY_POLL_SWEEPCOMPLETE)) { + if ((r & SPECTOOL_POLL_SWEEPCOMPLETE)) { if (wts_send_sweepblock(wts, &(wts->devs[x].phydev), - wispy_phy_getsweep(&(wts->devs[x].phydev)), + spectool_phy_getsweep(&(wts->devs[x].phydev)), errstr) < 0) return -1; } - } while ((r & WISPY_POLL_ADDITIONAL)); + } while ((r & SPECTOOL_POLL_ADDITIONAL)); } return 1; } -void wts_shutdown(wispy_tcpserv *wts) { - wispy_tcpcli *tci = wts->cli_list; +void wts_shutdown(spectool_tcpserv *wts) { + spectool_tcpcli *tci = wts->cli_list; while (tci != NULL) { - wispy_tcpcli *tcb = tci; + spectool_tcpcli *tcb = tci; close(tci->fd); tci = tci->next; free(tcb); @@ -687,28 +687,28 @@ lin.sin_addr.s_addr = INADDR_ANY; if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not make bcast socket: %s", strerror(errno)); return -1; } x = 1; if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &x, sizeof(x)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not set socket broadcast option: %s", strerror(errno)); close(sock); return -1; } if (bind(sock, (struct sockaddr *) &lin, sizeof(lin)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not bind bcast socket: %s", strerror(errno)); close(sock); return -1; } if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not connect bcast socket: %s", strerror(errno)); close(sock); return -1; @@ -718,14 +718,14 @@ } int wts_send_bcast(int sock, short int port, char *errstr) { - wispy_fr_broadcast bp; + spectool_fr_broadcast bp; - bp.sentinel = htonl(WISPY_NET_SENTINEL); - bp.version = WISPY_NET_PROTO_VERSION; + bp.sentinel = htonl(SPECTOOL_NET_SENTINEL); + bp.version = SPECTOOL_NET_PROTO_VERSION; bp.server_port = htons(port); - if (send(sock, &bp, sizeof(wispy_fr_broadcast), 0) < 0) { - snprintf(errstr, WISPY_ERROR_MAX, + if (send(sock, &bp, sizeof(spectool_fr_broadcast), 0) < 0) { + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not send broadcast frame: %s", strerror(errno)); return -1; } @@ -748,13 +748,13 @@ } int main(int argc, char *argv[]) { - wispy_tcpserv wts; - char errstr[WISPY_ERROR_MAX]; + spectool_tcpserv wts; + char errstr[SPECTOOL_ERROR_MAX]; fd_set sel_r_fds, sel_w_fds; struct timeval tm; - wispy_device_list list; - wispy_tcpserv_dev *devs = NULL; + spectool_device_list list; + spectool_tcpserv_dev *devs = NULL; int ndev = 0; int x = 0, r = 0; @@ -771,14 +771,14 @@ int option_index; char *bindaddr = NULL; - short int bindport = WISPY_NET_DEFAULT_PORT; + short int bindport = SPECTOOL_NET_DEFAULT_PORT; int broadcast = 0, bcast_sock = -1; time_t last_bcast = 0; int list_only = 0; - ndev = wispy_device_scan(&list); + ndev = spectool_device_scan(&list); int *rangeset = NULL; if (ndev > 0) { @@ -835,7 +835,7 @@ if (list_only) { if (ndev <= 0) { - printf("No wispy devices found, bailing\n"); + printf("No spectool devices found, bailing\n"); exit(1); } @@ -846,7 +846,7 @@ x, list.list[x].name, list.list[x].device_id); for (r = 0; r < list.list[x].num_sweep_ranges; r++) { - wispy_sample_sweep *ran = + spectool_sample_sweep *ran = &(list.list[x].supported_ranges[r]); printf(" Range %d: \"%s\" %d%s-%d%s @ %0.2f%s, %d samples\n", r, @@ -868,16 +868,16 @@ } if (ndev <= 0) { - printf("No wispy devices found, bailing\n"); + printf("No spectool devices found, bailing\n"); exit(1); } signal(SIGPIPE, &sigcatch); - fprintf(stderr, "Found %d wispy devices...\n", ndev); + fprintf(stderr, "Found %d spectool devices...\n", ndev); - /* devs = (wispy_phy *) malloc(WISPY_PHY_SIZE * ndev); */ - devs = (wispy_tcpserv_dev *) malloc(sizeof(wispy_tcpserv_dev) * ndev); + /* devs = (spectool_phy *) malloc(SPECTOOL_PHY_SIZE * ndev); */ + devs = (spectool_tcpserv_dev *) malloc(sizeof(spectool_tcpserv_dev) * ndev); for (x = 0; x < ndev; x++) { fprintf(stderr, "Initializing WiSPY device %s id %u\n", @@ -885,26 +885,26 @@ devs[x].lock_fd = -1; - if (wispy_device_init(&(devs[x].phydev), &(list.list[x])) < 0) { + if (spectool_device_init(&(devs[x].phydev), &(list.list[x])) < 0) { fprintf(stderr, "Error initializing WiSPY device %s id %u\n", list.list[x].name, list.list[x].device_id); - fprintf(stderr, "%s\n", wispy_get_error(&(devs[x].phydev))); + fprintf(stderr, "%s\n", spectool_get_error(&(devs[x].phydev))); exit(1); } - if (wispy_phy_open(&(devs[x].phydev)) < 0) { + if (spectool_phy_open(&(devs[x].phydev)) < 0) { fprintf(stderr, "Error opening WiSPY device %s id %u\n", list.list[x].name, list.list[x].device_id); - fprintf(stderr, "%s\n", wispy_get_error(&(devs[x].phydev))); + fprintf(stderr, "%s\n", spectool_get_error(&(devs[x].phydev))); exit(1); } - wispy_phy_setcalibration(&(devs[x].phydev), 1); + spectool_phy_setcalibration(&(devs[x].phydev), 1); /* configure the default sweep block */ - wispy_phy_setposition(&(devs[x].phydev), rangeset[x], 0, 0); + spectool_phy_setposition(&(devs[x].phydev), rangeset[x], 0, 0); } - wispy_device_scan_free(&list); + spectool_device_scan_free(&list); wts_init(&wts); diff -Nru spectools-201004R1/spectool_raw.c spectools-201108r1/spectool_raw.c --- spectools-201004R1/spectool_raw.c 2009-03-01 03:36:04.000000000 +0000 +++ spectools-201108r1/spectool_raw.c 2011-06-11 04:59:10.000000000 +0000 @@ -36,7 +36,7 @@ #include "spectool_container.h" #include "spectool_net_client.h" -wispy_phy *devs = NULL; +spectool_phy *devs = NULL; int ndev = 0; void sighandle(int sig) { @@ -58,13 +58,13 @@ } int main(int argc, char *argv[]) { - wispy_device_list list; + spectool_device_list list; int x = 0, r = 0; - wispy_sample_sweep *sb; + spectool_sample_sweep *sb; spectool_server sr; - char errstr[WISPY_ERROR_MAX]; + char errstr[SPECTOOL_ERROR_MAX]; int ret; - wispy_phy *pi; + spectool_phy *pi; static struct option long_options[] = { { "net", required_argument, 0, 'n' }, @@ -84,7 +84,7 @@ int list_only = 0; - ndev = wispy_device_scan(&list); + ndev = spectool_device_scan(&list); int *rangeset = NULL; if (ndev > 0) { @@ -106,7 +106,7 @@ bcastlisten = 1; } else if (o == 'n') { neturl = strdup(optarg); - printf("debug - wispy_raw neturl %s\n", neturl); + printf("debug - spectool_raw neturl %s\n", neturl); continue; } else if (o == 'l') { list_only = 1; @@ -134,7 +134,7 @@ if (list_only) { if (ndev <= 0) { - printf("No wispy devices found, bailing\n"); + printf("No spectool devices found, bailing\n"); exit(1); } @@ -145,7 +145,7 @@ x, list.list[x].name, list.list[x].device_id); for (r = 0; r < list.list[x].num_sweep_ranges; r++) { - wispy_sample_sweep *ran = + spectool_sample_sweep *ran = &(list.list[x].supported_ranges[r]); printf(" Range %d: \"%s\" %d%s-%d%s @ %0.2f%s, %d samples\n", r, @@ -169,7 +169,7 @@ if (bcastlisten) { printf("Initializing broadcast listen...\n"); - if ((bcastsock = spectool_netcli_initbroadcast(WISPY_NET_DEFAULT_PORT, + if ((bcastsock = spectool_netcli_initbroadcast(SPECTOOL_NET_DEFAULT_PORT, errstr)) < 0) { printf("Error initializing bcast socket: %s\n", errstr); exit(1); @@ -192,41 +192,41 @@ printf("Connected to server, waiting for device list...\n"); } else if (neturl == NULL) { if (ndev <= 0) { - printf("No wispy devices found, bailing\n"); + printf("No spectool devices found, bailing\n"); exit(1); } - printf("Found %d wispy devices...\n", ndev); + printf("Found %d spectool devices...\n", ndev); for (x = 0; x < ndev; x++) { printf("Initializing WiSPY device %s id %u\n", list.list[x].name, list.list[x].device_id); - pi = (wispy_phy *) malloc(WISPY_PHY_SIZE); + pi = (spectool_phy *) malloc(SPECTOOL_PHY_SIZE); pi->next = devs; devs = pi; - if (wispy_device_init(pi, &(list.list[x])) < 0) { + if (spectool_device_init(pi, &(list.list[x])) < 0) { printf("Error initializing WiSPY device %s id %u\n", list.list[x].name, list.list[x].device_id); - printf("%s\n", wispy_get_error(pi)); + printf("%s\n", spectool_get_error(pi)); exit(1); } - if (wispy_phy_open(pi) < 0) { + if (spectool_phy_open(pi) < 0) { printf("Error opening WiSPY device %s id %u\n", list.list[x].name, list.list[x].device_id); - printf("%s\n", wispy_get_error(pi)); + printf("%s\n", spectool_get_error(pi)); exit(1); } - wispy_phy_setcalibration(pi, 1); + spectool_phy_setcalibration(pi, 1); /* configure the default sweep block */ - wispy_phy_setposition(pi, rangeset[x], 0, 0); + spectool_phy_setposition(pi, rangeset[x], 0, 0); } - wispy_device_scan_free(&list); + spectool_device_scan_free(&list); } /* Naive poll that doesn't use select() to find pending data */ @@ -241,11 +241,11 @@ pi = devs; while (pi != NULL) { - if (wispy_phy_getpollfd(pi) >= 0) { - FD_SET(wispy_phy_getpollfd(pi), &rfds); + if (spectool_phy_getpollfd(pi) >= 0) { + FD_SET(spectool_phy_getpollfd(pi), &rfds); - if (wispy_phy_getpollfd(pi) > maxfd) - maxfd = wispy_phy_getpollfd(pi); + if (spectool_phy_getpollfd(pi) > maxfd) + maxfd = spectool_phy_getpollfd(pi); } pi = pi->next; @@ -276,7 +276,7 @@ tm.tv_usec = 10000; if (select(maxfd + 1, &rfds, &wfds, NULL, &tm) < 0) { - printf("wispy_raw select() error: %s\n", strerror(errno)); + printf("spectool_raw select() error: %s\n", strerror(errno)); exit(1); } @@ -336,35 +336,35 @@ pi = devs; while (pi != NULL) { - wispy_phy *di = pi; + spectool_phy *di = pi; pi = pi->next; - if (wispy_phy_getpollfd(di) < 0) { - if (wispy_get_state(di) == WISPY_STATE_ERROR) { - printf("Error polling wispy device %s\n", - wispy_phy_getname(di)); - printf("%s\n", wispy_get_error(di)); + if (spectool_phy_getpollfd(di) < 0) { + if (spectool_get_state(di) == SPECTOOL_STATE_ERROR) { + printf("Error polling spectool device %s\n", + spectool_phy_getname(di)); + printf("%s\n", spectool_get_error(di)); exit(1); } continue; } - if (FD_ISSET(wispy_phy_getpollfd(di), &rfds) == 0) { + if (FD_ISSET(spectool_phy_getpollfd(di), &rfds) == 0) { continue; } do { - r = wispy_phy_poll(di); + r = spectool_phy_poll(di); - if ((r & WISPY_POLL_CONFIGURED)) { + if ((r & SPECTOOL_POLL_CONFIGURED)) { printf("Configured device %u (%s)\n", - wispy_phy_getdevid(di), - wispy_phy_getname(di), + spectool_phy_getdevid(di), + spectool_phy_getname(di), di->device_spec->num_sweep_ranges); - wispy_sample_sweep *ran = - wispy_phy_getcurprofile(di); + spectool_sample_sweep *ran = + spectool_phy_getcurprofile(di); if (ran == NULL) { printf("Error - no current profile?\n"); @@ -383,24 +383,25 @@ ran->num_samples); continue; - } else if ((r & WISPY_POLL_ERROR)) { - printf("Error polling wispy device %s\n", - wispy_phy_getname(di)); - printf("%s\n", wispy_get_error(di)); + } else if ((r & SPECTOOL_POLL_ERROR)) { + printf("Error polling spectool device %s\n", + spectool_phy_getname(di)); + printf("%s\n", spectool_get_error(di)); exit(1); - } else if ((r & WISPY_POLL_SWEEPCOMPLETE)) { - sb = wispy_phy_getsweep(di); + } else if ((r & SPECTOOL_POLL_SWEEPCOMPLETE)) { + sb = spectool_phy_getsweep(di); if (sb == NULL) continue; - printf("%s: ", wispy_phy_getname(di)); + printf("%s: ", spectool_phy_getname(di)); for (r = 0; r < sb->num_samples; r++) { + // printf("[%d %d %d %d] ", sb->sample_data[r], sb->amp_offset_mdbm, sb->amp_res_mdbm, sb->sample_data[r] * (sb->amp_res_mdbm / 1000) + (sb->amp_offset_mdbm / 1000)); printf("%d ", - WISPY_RSSI_CONVERT(sb->amp_offset_mdbm, sb->amp_res_mdbm, + SPECTOOL_RSSI_CONVERT(sb->amp_offset_mdbm, sb->amp_res_mdbm, sb->sample_data[r])); } printf("\n"); } - } while ((r & WISPY_POLL_ADDITIONAL)); + } while ((r & SPECTOOL_POLL_ADDITIONAL)); } } diff -Nru spectools-201004R1/ubertooth_hw_u1.c spectools-201108r1/ubertooth_hw_u1.c --- spectools-201004R1/ubertooth_hw_u1.c 1970-01-01 00:00:00.000000000 +0000 +++ spectools-201108r1/ubertooth_hw_u1.c 2011-06-12 06:00:07.000000000 +0000 @@ -0,0 +1,897 @@ +/* + * This code is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This code 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. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_VALUES_H +#include +#endif + +#ifdef SYS_LINUX +/* Needed for our own tools */ +#include +#include +#include + +/* Kluge around kernel internal/external header breakage */ +#ifndef __user +#define __user +#endif + +#include +#include +/* + * Miserable hack to fix some distros which bundle a modern kernel but didn't + * update their linux/usbdevice_fs.h files. We define the ioctl locally, in + * theory the worst that could happen is that the kernel rejects it anyhow. + */ +#ifndef USBDEVFS_DISCONNECT +#warning "Kernel headers dont define USB disconnect support, trying to fake it" +#define USBDEVFS_DISCONNECT _IO('U', 22) +#endif +#endif /* linux hack */ + +/* LibUSB stuff */ +#include + +/* USB HID functions from specs which aren't defined for us */ +#define HID_GET_REPORT 0x01 +#define HID_SET_REPORT 0x09 +#define TIMEOUT 9000 + +#define UBERTOOTH_U1_VID 0xffff +#define UBERTOOTH_U1_PID 0x0004 + +/* # of samples to average */ +#define UBERTOOTH_U1_AVG_SAMPLES 3 + +/* Default # of samples */ +#define UBERTOOTH_U1_NUM_SAMPLES 79 + +#define UBERTOOTH_U1_OFFSET_MDBM -109000 +#define UBERTOOTH_U1_RES_MDBM 1000 +#define UBERTOOTH_U1_RSSI_MAX 58 + +#define UBERTOOTH_U1_DEF_H_MINKHZ 2402000 +#define UBERTOOTH_U1_DEF_H_RESHZ 1000000 +#define UBERTOOTH_U1_DEF_H_STEPS 78 + +#include "spectool_container.h" +#include "ubertooth_hw_u1.h" + +#define endian_swap32(x) \ +({ \ + uint32_t __x = (x); \ + ((uint32_t)( \ + (uint32_t)(((uint32_t)(__x) & (uint32_t)0x000000ff) << 24) | \ + (uint32_t)(((uint32_t)(__x) & (uint32_t)0x0000ff00) << 8) | \ + (uint32_t)(((uint32_t)(__x) & (uint32_t)0x00ff0000) >> 8) | \ + (uint32_t)(((uint32_t)(__x) & (uint32_t)0xff000000) >> 24) )); \ +}) + +#define endian_swap16(x) \ +({ \ + uint16_t __x = (x); \ + ((uint16_t)( \ + (uint16_t)(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \ + (uint16_t)(((uint16_t)(__x) & (uint16_t)0xff00) >> 8) )); \ +}) + +typedef struct _ubertooth_u1_sample { + uint16_t be_freq; + int8_t rssi; +} __attribute__((packed)) ubertooth_u1_sample; + +typedef struct _ubertooth_u1_report { + uint8_t type; + uint8_t status; + uint8_t channel; + uint8_t clk_high; + uint32_t clk_100ns; + uint8_t reserved[6]; + ubertooth_u1_sample data[16]; +} __attribute__((packed)) ubertooth_u1_report; + +/* Aux tracking struct for wispy1 characteristics */ +typedef struct _ubertooth_u1_aux { + struct usb_device *dev; + struct usb_dev_handle *devhdl; + + time_t last_read; + + /* have we pushed a configure event from sweeps */ + int configured; + + /* IPC tracking records to the forked process for capturing data */ + pthread_t usb_thread; + int usb_thread_alive; + + /* Has the sweep data buffer been initialized? (ie, did we get a sample at 0) */ + int sweepbuf_initialized; + /* how many sweeps has this device done over the run time? Nice to know, and + * we can use it for calibration counters too */ + int num_sweeps; + + /* Sweep buffer we fill */ + spectool_sample_sweep *sweepbuf; + /* Sweep buffer we return */ + spectool_sample_sweep *full_sweepbuf; + + /* peak samples */ + spectool_sweep_cache *peak_cache; + + int sockpair[2]; + + int sweepbase; + + /* Primed - we don't start at 1 */ + int primed; + + spectool_phy *phydev; +} ubertooth_u1_aux; + +#ifdef SYS_LINUX +/* Libusb doesn't seem to always provide this, so we'll use our own, taken from the +* usb_detatch_kernel_driver_np... +* +* THIS IS A HORRIBLE EVIL HACK THAT SHOULDN'T BE DONE, EVER +* +*/ +struct local_usb_ioctl { + int ifno; + int ioctl_code; + void *data; +}; + +struct ghetto_libusb_devhandle { + int fd; + /* Nooo... so bad. */ +}; + +int ubertooth_u1_detach_hack(struct usb_dev_handle *dev, int interface, char *errstr) { + struct local_usb_ioctl command; + struct ghetto_libusb_devhandle *gdev; + + command.ifno = interface; + command.ioctl_code = USBDEVFS_DISCONNECT; + command.data = NULL; + + gdev = (struct ghetto_libusb_devhandle *) dev; + + if (ioctl(gdev->fd, USBDEVFS_IOCTL, &command) < 0) { + if (errno == EINVAL) { + snprintf(errstr, SPECTOOL_ERROR_MAX, "Your kernel doesn't appear to accept " + "the USB disconnect command. Either your kernel is too old and " + "does not support device removal, or support for removal has " + "been changed by your distribution kernel maintainers."); + } + + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not detatch kernel driver from " + "interface %d: %s", interface, strerror(errno)); + return -1; + } + + return 0; +} +#endif /* sys_linux */ + +/* Prototypes */ +int ubertooth_u1_open(spectool_phy *); +int ubertooth_u1_close(spectool_phy *); +int ubertooth_u1_thread_close(spectool_phy *); +int ubertooth_u1_poll(spectool_phy *); +int ubertooth_u1_getpollfd(spectool_phy *); +void ubertooth_u1_setcalibration(spectool_phy *, int); +int ubertooth_u1_setposition(spectool_phy *, int, int, int); +spectool_sample_sweep *ubertooth_u1_getsweep(spectool_phy *); +spectool_sample_sweep *ubertooth_u1_build_sweepbuf(spectool_phy *); + +uint32_t ubertooth_u1_adler_checksum(const char *buf1, int len) { + int i; + uint32_t s1, s2; + char *buf = (char *)buf1; + int CHAR_OFFSET = 0; + + s1 = s2 = 0; + for (i = 0; i < (len-4); i+=4) { + s2 += 4*(s1 + buf[i]) + 3*buf[i+1] + 2*buf[i+2] + buf[i+3] + + 10*CHAR_OFFSET; + s1 += (buf[i+0] + buf[i+1] + buf[i+2] + buf[i+3] + 4*CHAR_OFFSET); + } + + for (; i < len; i++) { + s1 += (buf[i]+CHAR_OFFSET); s2 += s1; + } + + return (s1 & 0xffff) + (s2 << 16); +} + +/* Scan for devices */ +int ubertooth_u1_device_scan(spectool_device_list *list) { + struct usb_bus *bus; + struct usb_device *dev; + int num_found = 0; + ubertooth_u1_usb_pair *auxpair; + char combopath[128]; + + /* Libusb init */ + usb_init(); + usb_find_busses(); + usb_find_devices(); + + for (bus = usb_busses; bus; bus = bus->next) { + for (dev = bus->devices; dev; dev = dev->next) { + if (((dev->descriptor.idVendor == UBERTOOTH_U1_VID) && + (dev->descriptor.idProduct == UBERTOOTH_U1_PID))) { + + /* If we're full up, break */ + if (list->num_devs == list->max_devs - 1) + break; + + auxpair = + (ubertooth_u1_usb_pair *) malloc(sizeof(ubertooth_u1_usb_pair)); + + snprintf(auxpair->bus, 64, "%s", bus->dirname); + snprintf(auxpair->dev, 64, "%s", dev->filename); + + snprintf(combopath, 128, "%s%s", auxpair->bus, auxpair->dev); + + /* Fill in the list elements */ + list->list[list->num_devs].device_id = + wispy24x_adler_checksum(combopath, 128); + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, + "Ubertooth One USB %u", list->list[list->num_devs].device_id); + + list->list[list->num_devs].init_func = ubertooth_u1_init; + list->list[list->num_devs].hw_rec = auxpair; + + list->list[list->num_devs].num_sweep_ranges = 1; + list->list[list->num_devs].supported_ranges = + (spectool_sample_sweep *) malloc(sizeof(spectool_sample_sweep)); + + list->list[list->num_devs].supported_ranges[0].name = + strdup("2.4GHz ISM"); + + list->list[list->num_devs].supported_ranges[0].num_samples = + UBERTOOTH_U1_NUM_SAMPLES; + + list->list[list->num_devs].supported_ranges[0].amp_offset_mdbm = + UBERTOOTH_U1_OFFSET_MDBM; + list->list[list->num_devs].supported_ranges[0].amp_res_mdbm = + UBERTOOTH_U1_RES_MDBM; + list->list[list->num_devs].supported_ranges[0].rssi_max = + UBERTOOTH_U1_RSSI_MAX; + + list->list[list->num_devs].supported_ranges[0].start_khz = + UBERTOOTH_U1_DEF_H_MINKHZ; + list->list[list->num_devs].supported_ranges[0].end_khz = + UBERTOOTH_U1_DEF_H_MINKHZ + ((UBERTOOTH_U1_DEF_H_STEPS * + UBERTOOTH_U1_DEF_H_RESHZ) / 1000); + list->list[list->num_devs].supported_ranges[0].res_hz = + UBERTOOTH_U1_DEF_H_RESHZ; + + list->num_devs++; + + num_found++; + } + } + } + + return num_found; +} + +int ubertooth_u1_init(spectool_phy *phydev, spectool_device_rec *rec) { + ubertooth_u1_usb_pair *auxpair = (ubertooth_u1_usb_pair *) rec->hw_rec; + + if (auxpair == NULL) + return -1; + + return ubertooth_u1_init_path(phydev, auxpair->bus, auxpair->dev); +} + +/* Initialize a specific USB device based on bus and device IDs passed by the UI */ +int ubertooth_u1_init_path(spectool_phy *phydev, char *buspath, char *devpath) { + struct usb_bus *bus = NULL; + struct usb_device *dev = NULL; + + struct usb_device *usb_dev_chosen = NULL; + + char combopath[128]; + uint32_t cid; + + ubertooth_u1_aux *auxptr = NULL; + + usb_init(); + usb_find_busses(); + usb_find_devices(); + + snprintf(combopath, 128, "%s%s", buspath, devpath); + cid = ubertooth_u1_adler_checksum(combopath, 128); + + /* Don't know if a smarter way offhand, and we don't do this often, so just + * crawl and compare */ + for (bus = usb_busses; bus; bus = bus->next) { + if (strcmp(bus->dirname, buspath)) + continue; + + for (dev = bus->devices; dev; dev = dev->next) { + if (strcmp(dev->filename, devpath)) + continue; + + if (((dev->descriptor.idVendor == UBERTOOTH_U1_VID) && + (dev->descriptor.idProduct == UBERTOOTH_U1_PID))) { + usb_dev_chosen = dev; + break; + } else { + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "UBERTOOTH_U1_INIT failed, specified device %u does not " + "appear to be an Ubertooth One device", cid); + return -1; + } + } + } + + if (usb_dev_chosen == NULL) { + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "UBERTOOTH_U1_INIT failed, specified device %u does not appear " + "to exist.", cid); + return -1; + } + + /* Build the device record with one sweep capability */ + phydev->device_spec = (spectool_dev_spec *) malloc(sizeof(spectool_dev_spec)); + + phydev->device_spec->device_id = cid; + + /* Default the name to the buspath */ + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, + "Ubertooth One %u", cid); + + /* State */ + phydev->state = SPECTOOL_STATE_CLOSED; + + phydev->min_rssi_seen = -1; + + phydev->device_spec->device_version = 0x02; + phydev->device_spec->device_flags = SPECTOOL_DEV_FL_NONE; + + phydev->device_spec->num_sweep_ranges = 1; + phydev->device_spec->supported_ranges = + (spectool_sample_sweep *) malloc(sizeof(spectool_sample_sweep)); + + phydev->device_spec->default_range = phydev->device_spec->supported_ranges; + + phydev->device_spec->default_range->name = strdup("2.4GHz ISM"); + + phydev->device_spec->default_range->num_samples = UBERTOOTH_U1_NUM_SAMPLES; + + phydev->device_spec->default_range->amp_offset_mdbm = UBERTOOTH_U1_OFFSET_MDBM; + phydev->device_spec->default_range->amp_res_mdbm = UBERTOOTH_U1_RES_MDBM; + phydev->device_spec->default_range->rssi_max = UBERTOOTH_U1_RSSI_MAX; + + phydev->device_spec->default_range->start_khz = UBERTOOTH_U1_DEF_H_MINKHZ; + phydev->device_spec->default_range->end_khz = + UBERTOOTH_U1_DEF_H_MINKHZ + ((UBERTOOTH_U1_DEF_H_STEPS * + UBERTOOTH_U1_DEF_H_RESHZ) / 1000); + phydev->device_spec->default_range->res_hz = UBERTOOTH_U1_DEF_H_RESHZ; + + phydev->device_spec->cur_profile = 0; + + /* Set up the aux state */ + auxptr = malloc(sizeof(ubertooth_u1_aux)); + phydev->auxptr = auxptr; + + auxptr->configured = 0; + auxptr->primed = 0; + + auxptr->dev = dev; + auxptr->devhdl = NULL; + auxptr->phydev = phydev; + auxptr->sockpair[0] = -1; + auxptr->sockpair[1] = -1; + + /* Will be filled in by setposition later */ + auxptr->sweepbuf_initialized = 0; + auxptr->sweepbuf = NULL; + auxptr->full_sweepbuf = NULL; + + auxptr->peak_cache = spectool_cache_alloc(UBERTOOTH_U1_AVG_SAMPLES, 1, 0); + + phydev->open_func = &ubertooth_u1_open; + phydev->close_func = &ubertooth_u1_close; + phydev->poll_func = &ubertooth_u1_poll; + phydev->pollfd_func = &ubertooth_u1_getpollfd; + phydev->setcalib_func = &ubertooth_u1_setcalibration; + phydev->getsweep_func = &ubertooth_u1_getsweep; + phydev->setposition_func = &ubertooth_u1_setposition; + + phydev->draw_agg_suggestion = 1; + + return 0; +} + +void *ubertooth_u1_servicethread(void *aux) { + ubertooth_u1_aux *auxptr = (ubertooth_u1_aux *) aux; + + int sock; + struct usb_device *dev; + struct usb_dev_handle *u1; + + char buf[64]; + int x = 0, error = 0; + fd_set wset; + + struct timeval tm; + + sigset_t signal_set; + + error = 0; + + sock = auxptr->sockpair[1]; + + dev = auxptr->dev; + u1 = auxptr->devhdl; + + /* We don't want to see any signals in the child thread */ + sigfillset(&signal_set); + pthread_sigmask(SIG_BLOCK, &signal_set, NULL); + + while (1) { + /* wait until we're able to write out to the IPC socket, go into a blocking + * select */ + FD_ZERO(&wset); + FD_SET(sock, &wset); + + if (select(sock + 1, NULL, &wset, NULL, NULL) < 0) { + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 poller failed on IPC write select(): %s", + strerror(errno)); + auxptr->usb_thread_alive = 0; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; + pthread_exit(NULL); + } + + if (auxptr->usb_thread_alive == 0) { + auxptr->phydev->state = SPECTOOL_STATE_ERROR; + pthread_exit(NULL); + } + + if (FD_ISSET(sock, &wset) == 0) + continue; + + /* Get new data only if we haven't requeued */ + if (error == 0) { + memset(buf, 0, 64); + + if (usb_bulk_read(u1, 0x82, buf, 64, TIMEOUT) <= 0) { + if (errno == EAGAIN) + continue; + + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 poller failed to read USB data: %s", + strerror(errno)); + auxptr->usb_thread_alive = 0; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; + pthread_exit(NULL); + } + + /* Send it to the IPC remote, re-queue on enobufs */ + if (send(sock, buf, 64, 0) < 0) { + if (errno == ENOBUFS) { + error = 1; + continue; + } + + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 poller failed on IPC send: %s", + strerror(errno)); + auxptr->usb_thread_alive = 0; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; + pthread_exit(NULL); + } + + } + + error = 0; + } + + auxptr->usb_thread_alive = 0; + send(sock, buf, 64, 0); + auxptr->phydev->state = SPECTOOL_STATE_ERROR; + pthread_exit(NULL); +} + +int ubertooth_u1_getpollfd(spectool_phy *phydev) { + ubertooth_u1_aux *auxptr = (ubertooth_u1_aux *) phydev->auxptr; + + if (auxptr->usb_thread_alive == 0) { + ubertooth_u1_close(phydev); + return -1; + } + + return auxptr->sockpair[0]; +} + +int ubertooth_u1_open(spectool_phy *phydev) { + int pid_status; + ubertooth_u1_aux *auxptr = (ubertooth_u1_aux *) phydev->auxptr; + + /* Make the client/server socketpair */ + if (socketpair(PF_UNIX, SOCK_DGRAM, 0, auxptr->sockpair) < 0) { + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 open failed to create socket pair for capture " + "process: %s", strerror(errno)); + return -1; + } + + if ((auxptr->devhdl = usb_open(auxptr->dev)) == NULL) { + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 capture process failed to open USB device: %s", + strerror(errno)); + return -1; + } + +#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP + // fprintf(stderr, "debug - detatch kernel driver np\n"); + if (usb_detach_kernel_driver_np(auxptr->devhdl, 0)) { + // fprintf(stderr, "Could not detach kernel driver %s\n", usb_strerror()); + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "Could not detach device from kernel driver: %s", + usb_strerror()); + } +#endif + + // fprintf(stderr, "debug - set_configuration\n"); + usb_set_configuration(auxptr->devhdl, 1); + + // fprintf(stderr, "debug - claiming interface\n"); + if (usb_claim_interface(auxptr->devhdl, 0) < 0) { + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "could not claim interface: %s", usb_strerror()); + } + + auxptr->usb_thread_alive = 1; + + auxptr->last_read = time(0); + + if (pthread_create(&(auxptr->usb_thread), NULL, + ubertooth_u1_servicethread, auxptr) < 0) { + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 capture failed to create thread: %s", + strerror(errno)); + auxptr->usb_thread_alive = 0; + return -1; + } + + /* Update the state */ + phydev->state = SPECTOOL_STATE_CONFIGURING; + + /* + if (ubertooth_u1_setposition(phydev, 0, 0, 0) < 0) + return -1; + */ + + return 1; +} + +int ubertooth_u1_close(spectool_phy *phydev) { + ubertooth_u1_aux *aux; + + if (phydev == NULL) + return 0; + + aux = (ubertooth_u1_aux *) phydev->auxptr; + + if (aux == NULL) + return 0; + + /* If the thread is still alive, don't take away the devices it might + * still be reading, wait for it to error down */ + if (aux->usb_thread_alive) { + aux->usb_thread_alive = 0; + pthread_join(aux->usb_thread, NULL); + } + + if (aux->devhdl) { + usb_close(aux->devhdl); + aux->devhdl = NULL; + } + + if (aux->sockpair[0] >= 0) { + close(aux->sockpair[0]); + aux->sockpair[0] = -1; + } + + if (aux->sockpair[1] >= 0) { + close(aux->sockpair[1]); + aux->sockpair[1] = -1; + } + + return 1; +} + +spectool_sample_sweep *ubertooth_u1_getsweep(spectool_phy *phydev) { + ubertooth_u1_aux *auxptr = (ubertooth_u1_aux *) phydev->auxptr; + + // return auxptr->full_sweepbuf; + return auxptr->peak_cache->roll_peak; +} + +void ubertooth_u1_setcalibration(spectool_phy *phydev, int in_calib) { + phydev->state = SPECTOOL_STATE_RUNNING; +} + +int ubertooth_u1_poll(spectool_phy *phydev) { + ubertooth_u1_aux *auxptr = (ubertooth_u1_aux *) phydev->auxptr; + char lbuf[64]; + int x, freq, ret, full = 0, rssi; + ubertooth_u1_report *report = (ubertooth_u1_report *) lbuf; + + /* Push a configure event before anything else */ + if (auxptr->configured == 0) { + auxptr->configured = 1; + return SPECTOOL_POLL_CONFIGURED; + } + + /* Use the error set by the polling thread */ + if (auxptr->usb_thread_alive == 0) { + phydev->state = SPECTOOL_STATE_ERROR; + ubertooth_u1_close(phydev); + return SPECTOOL_POLL_ERROR; + } + + if ((ret = recv(auxptr->sockpair[0], lbuf, 64, 0)) < 0) { + if (auxptr->usb_thread_alive != 0) + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 IPC receiver failed to read signal data: %s", + strerror(errno)); + phydev->state = SPECTOOL_STATE_ERROR; + return SPECTOOL_POLL_ERROR; + } + + if (time(0) - auxptr->last_read > 3) { + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 didn't see any data for more than 3 seconds, " + "something has gone wrong (was the device removed?)"); + phydev->state = SPECTOOL_STATE_ERROR; + return SPECTOOL_POLL_ERROR; + } + + if (ret > 0) + auxptr->last_read = time(0); + + // If we don't have a sweepbuf we're not configured, barf + if (auxptr->sweepbuf == NULL) { + return SPECTOOL_POLL_NONE; + } + + // If we're full entering a read we need to wipe out + if (auxptr->peak_cache->num_used >= UBERTOOTH_U1_AVG_SAMPLES) { + // spectool_cache_clear(auxptr->peak_cache); + // printf("debug - clearing peak cache\n"); + } + + for (x = 0; x < 16; x++) { + // printf("%u %d\n", endian_swap16(report->data[x].be_freq), report->data[x].rssi); +#ifdef WORDS_BIGENDIAN + freq = report->data[x].be_freq; +#else + freq = endian_swap16(report->data[x].be_freq); +#endif + + freq = freq - (auxptr->sweepbuf->start_khz / 1000); + + rssi = (report->data[x].rssi + 55); + + // printf("%u = %d ", freq, rssi); + + if (freq < 0 || freq >= auxptr->sweepbuf->num_samples) { + printf("debug - sample freq %d not in range\n", freq); + continue; + } + + auxptr->sweepbuf->sample_data[freq] = rssi; + + if (rssi < phydev->min_rssi_seen) + phydev->min_rssi_seen = rssi; + + if (freq == 0) { + if (auxptr->primed == 0) { + // printf("debug - u1 primed\n"); + auxptr->primed = 1; + continue; + } + + auxptr->sweepbuf_initialized = 1; + auxptr->num_sweeps++; + + gettimeofday(&(auxptr->sweepbuf->tm_end), NULL); + auxptr->sweepbuf->min_rssi_seen = phydev->min_rssi_seen; + + /* + if (auxptr->full_sweepbuf != NULL) { + free(auxptr->full_sweepbuf); + } + + auxptr->full_sweepbuf = auxptr->sweepbuf; + */ + + // auxptr->sweepbuf = ubertooth_u1_build_sweepbuf(phydev); + + spectool_cache_append(auxptr->peak_cache, auxptr->sweepbuf); + + if (auxptr->peak_cache->num_used >= UBERTOOTH_U1_AVG_SAMPLES) { + full = 1; + } + + gettimeofday(&(auxptr->sweepbuf->tm_start), NULL); + + // printf("debug - u1 - sweep complete, freq %d\n", freq); + } + } + + if (full == 1) { + // printf("debug - returning sc\n"); + return SPECTOOL_POLL_SWEEPCOMPLETE; + } + + +#if 0 + /* + + /* Initialize the sweep buffer when we get to it + * If we haven't gotten around to a 0 state to initialize the buffer, we throw + * out the sample data until we do. */ + if (base == 0) { + auxptr->sweepbuf_initialized = 1; + auxptr->num_sweeps++; + + /* Init the timestamp for sweep begin */ + gettimeofday(&(auxptr->sweepbuf->tm_start), NULL); + } else if (auxptr->sweepbuf_initialized == 0) { + return SPECTOOL_POLL_NONE; + } + + for (x = 0; x < report->valid_bytes; x++) { + if (base + x >= auxptr->sweepbuf->num_samples) { + break; + } + + /* + auxptr->sweepbuf->sample_data[base + x] = + ubertooth_u1_RSSI(report->data[x]); + */ + auxptr->sweepbuf->sample_data[base + x] = report->data[x]; + + if (report->data[x] < phydev->min_rssi_seen) + phydev->min_rssi_seen = report->data[x]; + } + + auxptr->sweepbase += report->valid_bytes; + + /* Flag that a sweep is complete */ + if (base + report->valid_bytes == auxptr->sweepbuf->num_samples) { + gettimeofday(&(auxptr->sweepbuf->tm_end), NULL); + auxptr->sweepbuf->min_rssi_seen = phydev->min_rssi_seen; + return SPECTOOL_POLL_SWEEPCOMPLETE; + } +#endif + + return SPECTOOL_POLL_NONE; +} + +spectool_sample_sweep *ubertooth_u1_build_sweepbuf(spectool_phy *phydev) { + spectool_sample_sweep *r; + + r = (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(UBERTOOTH_U1_NUM_SAMPLES)); + r->phydev = phydev; + r->start_khz = + phydev->device_spec->supported_ranges[0].start_khz; + r->end_khz = + phydev->device_spec->supported_ranges[0].end_khz; + r->res_hz = + phydev->device_spec->supported_ranges[0].res_hz; + r->num_samples = + phydev->device_spec->supported_ranges[0].num_samples; + + r->amp_offset_mdbm = + phydev->device_spec->supported_ranges[0].amp_offset_mdbm; + r->amp_res_mdbm = + phydev->device_spec->supported_ranges[0].amp_res_mdbm; + r->rssi_max = + phydev->device_spec->supported_ranges[0].rssi_max; + + return r; +} + +int ubertooth_u1_setposition(spectool_phy *phydev, int in_profile, + int start_khz, int res_hz) { + int temp_d, temp_m; + int best_s_m = 0, best_s_e = 0, best_b_m = 0, best_b_e = 0; + int m = 0, e = 0, best_d; + int target_bw; + struct usb_dev_handle *u1; + ubertooth_u1_aux *auxptr = (ubertooth_u1_aux *) phydev->auxptr; + + + u1 = auxptr->devhdl; + + // printf("debug - writing control msg\n"); + + if (usb_control_msg(u1, + 0x40, 27, 2402, 2480, NULL, 0, TIMEOUT)) { + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "ubertooth_u1 setposition failed to set sweep feature set: %s", + strerror(errno)); + phydev->state = SPECTOOL_STATE_ERROR; + return -1; + } + + /* If we successfully configured the hardware, update the sweep capabilities and + * the sweep buffer and reset the device */ + + phydev->device_spec->num_sweep_ranges = 1; + if (phydev->device_spec->supported_ranges) + free(phydev->device_spec->supported_ranges); + phydev->device_spec->supported_ranges = + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(0)); + memset (phydev->device_spec->supported_ranges, 0, SPECTOOL_SWEEP_SIZE(0)); + + /* Set the universal values */ + phydev->device_spec->supported_ranges[0].num_samples = UBERTOOTH_U1_NUM_SAMPLES; + + phydev->device_spec->supported_ranges[0].amp_offset_mdbm = UBERTOOTH_U1_OFFSET_MDBM; + phydev->device_spec->supported_ranges[0].amp_res_mdbm = UBERTOOTH_U1_RES_MDBM; + phydev->device_spec->supported_ranges[0].rssi_max = UBERTOOTH_U1_RSSI_MAX; + + /* Set the sweep records based on default or new data */ + phydev->device_spec->supported_ranges[0].start_khz = UBERTOOTH_U1_DEF_H_MINKHZ; + phydev->device_spec->supported_ranges[0].end_khz = + UBERTOOTH_U1_DEF_H_MINKHZ + ((UBERTOOTH_U1_NUM_SAMPLES * + UBERTOOTH_U1_DEF_H_RESHZ) / 1000); + phydev->device_spec->supported_ranges[0].res_hz = UBERTOOTH_U1_DEF_H_RESHZ; + + /* We're not configured, so we need to push a new configure block out next time + * we sweep */ + auxptr->configured = 0; + + /* Rebuild the sweep buffer */ + if (auxptr->sweepbuf) + free(auxptr->sweepbuf); + + auxptr->sweepbuf = ubertooth_u1_build_sweepbuf(phydev); + + /* + auxptr->sweepbuf->min_sample = + phydev->device_spec->supported_ranges[0].min_sample; + auxptr->sweepbuf->min_sig_report = + phydev->device_spec->supported_ranges[0].min_sig_report; + auxptr->sweepbuf->max_sample = + phydev->device_spec->supported_ranges[0].max_sample; + */ + + auxptr->sweepbuf_initialized = 0; + auxptr->num_sweeps = -1; +} + diff -Nru spectools-201004R1/ubertooth_hw_u1.h spectools-201108r1/ubertooth_hw_u1.h --- spectools-201004R1/ubertooth_hw_u1.h 1970-01-01 00:00:00.000000000 +0000 +++ spectools-201108r1/ubertooth_hw_u1.h 2011-06-11 04:59:10.000000000 +0000 @@ -0,0 +1,32 @@ +/* + * Ubertooth1 interface, for the Ubertooth One hardware + * + * This code is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This code 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. + * + */ + +#ifndef __UBERTOOTH_HW_U1_H__ +#define __UBERTOOTH_HW_U1_H__ + +#include "spectool_container.h" + +/* U1 scan results */ +typedef struct _ubertooth_u1_usb_pair { + char bus[64]; + char dev[64]; +} ubertooth_u1_usb_pair; + +int ubertooth_u1_device_scan(spectool_device_list *list); + +int ubertooth_u1_init_path(spectool_phy *phydev, char *buspath, char *devpath); +int ubertooth_u1_init(spectool_phy *phydev, spectool_device_rec *rec); + +#endif diff -Nru spectools-201004R1/wispy_hw_24x.c spectools-201108r1/wispy_hw_24x.c --- spectools-201004R1/wispy_hw_24x.c 2009-06-17 23:43:33.000000000 +0000 +++ spectools-201108r1/wispy_hw_24x.c 2011-06-10 15:53:29.000000000 +0000 @@ -142,13 +142,13 @@ int num_sweeps; /* Sweep buffer we maintain and return */ - wispy_sample_sweep *sweepbuf; + spectool_sample_sweep *sweepbuf; int sockpair[2]; int sweepbase; - wispy_phy *phydev; + spectool_phy *phydev; } wispy24x_usb_aux; typedef struct _wispy24x_rfsettings { @@ -202,13 +202,13 @@ if (ioctl(gdev->fd, USBDEVFS_IOCTL, &command) < 0) { if (errno == EINVAL) { - snprintf(errstr, WISPY_ERROR_MAX, "Your kernel doesn't appear to accept " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Your kernel doesn't appear to accept " "the USB disconnect command. Either your kernel is too old and " "does not support device removal, or support for removal has " "been changed by your distribution kernel maintainers."); } - snprintf(errstr, WISPY_ERROR_MAX, "Could not detatch kernel driver from " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not detatch kernel driver from " "interface %d: %s", interface, strerror(errno)); return -1; } @@ -218,14 +218,14 @@ #endif /* sys_linux */ /* Prototypes */ -int wispy24x_usb_open(wispy_phy *); -int wispy24x_usb_close(wispy_phy *); -int wispy24x_usb_thread_close(wispy_phy *); -int wispy24x_usb_poll(wispy_phy *); -int wispy24x_usb_getpollfd(wispy_phy *); -void wispy24x_usb_setcalibration(wispy_phy *, int); -int wispy24x_usb_setposition(wispy_phy *, int, int, int); -wispy_sample_sweep *wispy24x_usb_getsweep(wispy_phy *); +int wispy24x_usb_open(spectool_phy *); +int wispy24x_usb_close(spectool_phy *); +int wispy24x_usb_thread_close(spectool_phy *); +int wispy24x_usb_poll(spectool_phy *); +int wispy24x_usb_getpollfd(spectool_phy *); +void wispy24x_usb_setcalibration(spectool_phy *, int); +int wispy24x_usb_setposition(spectool_phy *, int, int, int); +spectool_sample_sweep *wispy24x_usb_getsweep(spectool_phy *); uint32_t wispy24x_adler_checksum(const char *buf1, int len) { int i; @@ -248,7 +248,7 @@ } /* Scan for devices */ -int wispy24x_usb_device_scan(wispy_device_list *list) { +int wispy24x_usb_device_scan(spectool_device_list *list) { struct usb_bus *bus; struct usb_device *dev; int num_found = 0; @@ -279,7 +279,7 @@ /* Fill in the list elements */ list->list[list->num_devs].device_id = wispy24x_adler_checksum(combopath, 128); - snprintf(list->list[list->num_devs].name, WISPY_PHY_NAME_MAX, + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy 24x USB %u", list->list[list->num_devs].device_id); list->list[list->num_devs].init_func = wispy24x_usb_init; @@ -287,7 +287,7 @@ list->list[list->num_devs].num_sweep_ranges = 1; list->list[list->num_devs].supported_ranges = - (wispy_sample_sweep *) malloc(sizeof(wispy_sample_sweep)); + (spectool_sample_sweep *) malloc(sizeof(spectool_sample_sweep)); list->list[list->num_devs].supported_ranges[0].name = strdup("2.4GHz ISM"); @@ -320,7 +320,7 @@ return num_found; } -int wispy24x_usb_init(wispy_phy *phydev, wispy_device_rec *rec) { +int wispy24x_usb_init(spectool_phy *phydev, spectool_device_rec *rec) { wispy24x_usb_pair *auxpair = (wispy24x_usb_pair *) rec->hw_rec; if (auxpair == NULL) @@ -330,7 +330,7 @@ } /* Initialize a specific USB device based on bus and device IDs passed by the UI */ -int wispy24x_usb_init_path(wispy_phy *phydev, char *buspath, char *devpath) { +int wispy24x_usb_init_path(spectool_phy *phydev, char *buspath, char *devpath) { struct usb_bus *bus = NULL; struct usb_device *dev = NULL; @@ -363,7 +363,7 @@ usb_dev_chosen = dev; break; } else { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "WISPY24x_INIT failed, specified device %u does not " "appear to be a Wi-Spy device", cid); return -1; @@ -372,32 +372,32 @@ } if (usb_dev_chosen == NULL) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "WISPY24x_INIT failed, specified device %u does not appear " "to exist.", cid); return -1; } /* Build the device record with one sweep capability */ - phydev->device_spec = (wispy_dev_spec *) malloc(sizeof(wispy_dev_spec)); + phydev->device_spec = (spectool_dev_spec *) malloc(sizeof(spectool_dev_spec)); phydev->device_spec->device_id = cid; /* Default the name to the buspath */ - snprintf(phydev->device_spec->device_name, WISPY_PHY_NAME_MAX, + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy 24x USB %u", cid); /* State */ - phydev->state = WISPY_STATE_CLOSED; + phydev->state = SPECTOOL_STATE_CLOSED; phydev->min_rssi_seen = -1; phydev->device_spec->device_version = 0x02; - phydev->device_spec->device_flags = WISPY_DEV_FL_VAR_SWEEP; + phydev->device_spec->device_flags = SPECTOOL_DEV_FL_VAR_SWEEP; phydev->device_spec->num_sweep_ranges = 1; phydev->device_spec->supported_ranges = - (wispy_sample_sweep *) malloc(sizeof(wispy_sample_sweep)); + (spectool_sample_sweep *) malloc(sizeof(spectool_sample_sweep)); phydev->device_spec->default_range = phydev->device_spec->supported_ranges; @@ -479,16 +479,16 @@ FD_SET(sock, &wset); if (select(sock + 1, NULL, &wset, NULL, NULL) < 0) { - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb poller failed on IPC write select(): %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } if (auxptr->usb_thread_alive == 0) { - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } @@ -503,11 +503,11 @@ if (errno == EAGAIN) continue; - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb poller failed to read USB data: %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } @@ -518,11 +518,11 @@ continue; } - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb poller failed on IPC send: %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } @@ -533,11 +533,11 @@ auxptr->usb_thread_alive = 0; send(sock, buf, 64, 0); - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } -int wispy24x_usb_getpollfd(wispy_phy *phydev) { +int wispy24x_usb_getpollfd(spectool_phy *phydev) { wispy24x_usb_aux *auxptr = (wispy24x_usb_aux *) phydev->auxptr; if (auxptr->usb_thread_alive == 0) { @@ -548,20 +548,20 @@ return auxptr->sockpair[0]; } -int wispy24x_usb_open(wispy_phy *phydev) { +int wispy24x_usb_open(spectool_phy *phydev) { int pid_status; wispy24x_usb_aux *auxptr = (wispy24x_usb_aux *) phydev->auxptr; /* Make the client/server socketpair */ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, auxptr->sockpair) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb open failed to create socket pair for capture " "process: %s", strerror(errno)); return -1; } if ((auxptr->devhdl = usb_open(auxptr->dev)) == NULL) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb capture process failed to open USB device: %s", strerror(errno)); return -1; @@ -571,7 +571,7 @@ // fprintf(stderr, "debug - detatch kernel driver np\n"); if (usb_detach_kernel_driver_np(auxptr->devhdl, 0)) { // fprintf(stderr, "Could not detach kernel driver %s\n", usb_strerror()); - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "Could not detach device from kernel driver: %s", usb_strerror()); } @@ -582,7 +582,7 @@ // fprintf(stderr, "debug - claiming interface\n"); if (usb_claim_interface(auxptr->devhdl, 0) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "could not claim interface: %s", usb_strerror()); } @@ -592,7 +592,7 @@ if (pthread_create(&(auxptr->usb_thread), NULL, wispy24x_usb_servicethread, auxptr) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb capture failed to create thread: %s", strerror(errno)); auxptr->usb_thread_alive = 0; @@ -600,7 +600,7 @@ } /* Update the state */ - phydev->state = WISPY_STATE_CONFIGURING; + phydev->state = SPECTOOL_STATE_CONFIGURING; /* if (wispy24x_usb_setposition(phydev, 0, 0, 0) < 0) @@ -610,7 +610,7 @@ return 1; } -int wispy24x_usb_close(wispy_phy *phydev) { +int wispy24x_usb_close(spectool_phy *phydev) { wispy24x_usb_aux *aux; if (phydev == NULL) @@ -646,17 +646,17 @@ return 1; } -wispy_sample_sweep *wispy24x_usb_getsweep(wispy_phy *phydev) { +spectool_sample_sweep *wispy24x_usb_getsweep(spectool_phy *phydev) { wispy24x_usb_aux *auxptr = (wispy24x_usb_aux *) phydev->auxptr; return auxptr->sweepbuf; } -void wispy24x_usb_setcalibration(wispy_phy *phydev, int in_calib) { - phydev->state = WISPY_STATE_RUNNING; +void wispy24x_usb_setcalibration(spectool_phy *phydev, int in_calib) { + phydev->state = SPECTOOL_STATE_RUNNING; } -int wispy24x_usb_poll(wispy_phy *phydev) { +int wispy24x_usb_poll(spectool_phy *phydev) { wispy24x_usb_aux *auxptr = (wispy24x_usb_aux *) phydev->auxptr; char lbuf[64]; int base, res, ret, x; @@ -665,31 +665,31 @@ /* Push a configure event before anything else */ if (auxptr->configured == 0) { auxptr->configured = 1; - return WISPY_POLL_CONFIGURED; + return SPECTOOL_POLL_CONFIGURED; } /* Use the error set by the polling thread */ if (auxptr->usb_thread_alive == 0) { - phydev->state = WISPY_STATE_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; wispy24x_usb_close(phydev); - return WISPY_POLL_ERROR; + return SPECTOOL_POLL_ERROR; } if ((ret = recv(auxptr->sockpair[0], lbuf, 64, 0)) < 0) { if (auxptr->usb_thread_alive != 0) - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb IPC receiver failed to read signal data: %s", strerror(errno)); - phydev->state = WISPY_STATE_ERROR; - return WISPY_POLL_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; + return SPECTOOL_POLL_ERROR; } if (time(0) - auxptr->last_read > 3) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb didn't see any data for more than 3 seconds, " "something has gone wrong (was the device removed?)"); - phydev->state = WISPY_STATE_ERROR; - return WISPY_POLL_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; + return SPECTOOL_POLL_ERROR; } if (ret > 0) @@ -697,12 +697,12 @@ // If we don't have a sweepbuf we're not configured, barf if (auxptr->sweepbuf == NULL) { - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } if (ret < sizeof(wispy24x_report)) { printf("Short report\n"); - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } report = (wispy24x_report *) lbuf; @@ -729,7 +729,7 @@ if (base < 0 || base > auxptr->sweepbuf->num_samples) { /* Bunk data, throw it out */ - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } /* Initialize the sweep buffer when we get to it @@ -742,7 +742,7 @@ /* Init the timestamp for sweep begin */ gettimeofday(&(auxptr->sweepbuf->tm_start), NULL); } else if (auxptr->sweepbuf_initialized == 0) { - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } for (x = 0; x < report->valid_bytes; x++) { @@ -766,13 +766,13 @@ if (base + report->valid_bytes == auxptr->sweepbuf->num_samples) { gettimeofday(&(auxptr->sweepbuf->tm_end), NULL); auxptr->sweepbuf->min_rssi_seen = phydev->min_rssi_seen; - return WISPY_POLL_SWEEPCOMPLETE; + return SPECTOOL_POLL_SWEEPCOMPLETE; } - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } -int wispy24x_usb_setposition(wispy_phy *phydev, int in_profile, +int wispy24x_usb_setposition(spectool_phy *phydev, int in_profile, int start_khz, int res_hz) { int temp_d, temp_m; int best_s_m = 0, best_s_e = 0, best_b_m = 0, best_b_e = 0; @@ -868,10 +868,10 @@ 0, (uint8_t *) &rfset, (int) sizeof(wispy24x_rfsettings), TIMEOUT) == 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb setposition failed to set sweep feature set: %s", strerror(errno)); - phydev->state = WISPY_STATE_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; return -1; } @@ -882,8 +882,8 @@ if (phydev->device_spec->supported_ranges) free(phydev->device_spec->supported_ranges); phydev->device_spec->supported_ranges = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(0)); - memset (phydev->device_spec->supported_ranges, 0, WISPY_SWEEP_SIZE(0)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(0)); + memset (phydev->device_spec->supported_ranges, 0, SPECTOOL_SWEEP_SIZE(0)); /* Set the universal values */ phydev->device_spec->supported_ranges[0].num_samples = WISPY24x_USB_NUM_SAMPLES; @@ -915,7 +915,7 @@ free(auxptr->sweepbuf); auxptr->sweepbuf = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(WISPY24x_USB_NUM_SAMPLES)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(WISPY24x_USB_NUM_SAMPLES)); auxptr->sweepbuf->phydev = phydev; auxptr->sweepbuf->start_khz = phydev->device_spec->supported_ranges[0].start_khz; diff -Nru spectools-201004R1/wispy_hw_24x.h spectools-201108r1/wispy_hw_24x.h --- spectools-201004R1/wispy_hw_24x.h 2007-08-22 23:26:45.000000000 +0000 +++ spectools-201108r1/wispy_hw_24x.h 2011-06-10 15:53:29.000000000 +0000 @@ -32,11 +32,11 @@ char dev[64]; } wispy24x_usb_pair; -int wispy24x_usb_device_scan(wispy_device_list *list); +int wispy24x_usb_device_scan(spectool_device_list *list); /* Wispy24x init function to build a phydev linked to a bus and device path * scanned */ -int wispy24x_usb_init_path(wispy_phy *phydev, char *buspath, char *devpath); -int wispy24x_usb_init(wispy_phy *phydev, wispy_device_rec *rec); +int wispy24x_usb_init_path(spectool_phy *phydev, char *buspath, char *devpath); +int wispy24x_usb_init(spectool_phy *phydev, spectool_device_rec *rec); #endif diff -Nru spectools-201004R1/wispy_hw_dbx.c spectools-201108r1/wispy_hw_dbx.c --- spectools-201004R1/wispy_hw_dbx.c 2010-04-16 19:04:07.000000000 +0000 +++ spectools-201108r1/wispy_hw_dbx.c 2011-06-10 15:53:29.000000000 +0000 @@ -64,18 +64,34 @@ #define METAGEEK_WISPYDBx_VID 0x1dd5 #define METAGEEK_WISPYDBx_PID 0x5000 +#define METAGEEK_WISPYDBx_V2_VID 0x1dd5 +#define METAGEEK_WISPYDBx_V2_PID 0x5001 + #define METAGEEK_WISPY24I_VID 0x1dd5 #define METAGEEK_WISPY24I_PID 0x2400 +#define METAGEEK_WISPY24x_V2_VID 0x1dd5 +#define METAGEEK_WISPY24x_V2_PID 0x2410 + #define METAGEEK_WISPY900x_VID 0x1dd5 #define METAGEEK_WISPY900x_PID 0x0900 +#define METAGEEK_WISPY950x_VID 0x1dd5 +#define METAGEEK_WISPY950x_PID 0x0950 + /* Default config */ -#define WISPYDBx_USB_STARTKHZ_58 5160000 +#define WISPYDBx_USB_STARTKHZ_58 5100000 #define WISPYDBx_USB_RESHZ_58 748536 -#define WISPYDBx_USB_FILTERHZ_58 428571 -#define WISPYDBx_USB_NUM_SAMPLES_58 903 -#define WISPYDBx_USB_SAMPLESPOINT_58 2 +#define WISPYDBx_USB_FILTERHZ_58 375000 +#define WISPYDBx_USB_NUM_SAMPLES_58 1024 +#define WISPYDBx_USB_SAMPLESPOINT_58 1 + +/* u-nii lower (5400mhz) */ +#define WISPYDBx_USB_STARTKHZ_58_UNL 5100000 +#define WISPYDBx_USB_RESHZ_58_UNL 374268 +#define WISPYDBx_USB_FILTERHZ_58_UNL 375000 +#define WISPYDBx_USB_NUM_SAMPLES_58_UNL 1024 +#define WISPYDBx_USB_SAMPLESPOINT_58_UNL 1 /* Used for DBx and 24i */ #define WISPYDBx_USB_DEF_STARTKHZ_24 2400000 @@ -84,6 +100,13 @@ #define WISPYDBx_USB_DEF_SAMPLESPOINT_24 4 #define WISPYDBx_USB_NUM_SAMPLES_24 419 +/* Used for DBx and 24i */ +#define WISPYDBx_USB_DEF_STARTKHZ_24_FAST 2400000 +#define WISPYDBx_USB_DEF_RESHZ_24_FAST 560000 +#define WISPYDBx_USB_DEF_FILTERHZ_24_FAST 500000 +#define WISPYDBx_USB_DEF_SAMPLESPOINT_24_FAST 1 +#define WISPYDBx_USB_NUM_SAMPLES_24_FAST 150 + /* 900x */ #define WISPY900x_USB_DEF_STARTKHZ 902000 #define WISPY900x_USB_DEF_RESHZ 101807 @@ -113,11 +136,11 @@ ({ \ uint16_t __x = (x); \ ((uint16_t)( \ - (uint16_t)(((uint16_t)(__x) & (uint16_t)0x000000ff) << 24) | \ - (uint16_t)(((uint16_t)(__x) & (uint16_t)0x0000ff00) << 8) | \ + (uint16_t)(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \ + (uint16_t)(((uint16_t)(__x) & (uint16_t)0xff00) >> 8) )); \ }) -/* Aux tracking struct for wispy1 characteristics */ +/* Aux tracking struct for wispydbx characteristics */ typedef struct _wispydbx_usb_aux { struct usb_device *dev; struct usb_dev_handle *devhdl; @@ -138,17 +161,20 @@ int num_sweeps; /* Sweep buffer we maintain and return */ - wispy_sample_sweep *sweepbuf; + spectool_sample_sweep *sweepbuf; int sockpair[2]; int sweepbase; - wispy_phy *phydev; + spectool_phy *phydev; - // Model - 0 = dbx, 1 = 24i, 2 = 900x + // Model - 0 = dbx, 1 = 24i, 2 = 900x, 3 = dbxV2, 4 = 24xv2, 5 = 950 int model; + // Protocol - v1 or v2 + int protocol; + uint8_t cmd_seq : 2; } wispydbx_usb_aux; @@ -156,7 +182,7 @@ ({ \ ((uint8_t)( \ (uint8_t)(((uint8_t)(seq) & (uint8_t) 0x3) << 5) | \ - (uint8_t)(((uint8_t)(len) & (uint8_t) 0xF)) )); \ + (uint8_t)(((uint8_t)(len) & (uint8_t) 0x1F)) )); \ }) typedef struct _wispydbx_rfsettings { @@ -172,6 +198,24 @@ } __attribute__((packed)) wispydbx_rfsettings; #define WISPYDBx_USB_RFSETTINGS_LEN 15 +typedef struct _wispydbx_rfsettings_v2 { + uint8_t report_id; + uint8_t command_id; + uint8_t command_flags; + + uint32_t start_khz; + uint32_t freq_res_hz; + uint32_t filter_bw_hz; + uint16_t points_per_sweep; + + // Samples per point goes away and becomes dwell time + + uint8_t dwell_time; + uint8_t dither_steps; + uint8_t reserved; +} __attribute__((packed)) wispydbx_rfsettings_v2; +#define WISPYDBx_USB_RFSETTINGS_V2_LEN 17 + typedef struct _wispydbx_startsweep { uint8_t report_id; uint8_t command_id; @@ -185,6 +229,14 @@ uint8_t data[61]; } __attribute__((packed)) wispydbx_report; +typedef struct _wispydbx_report_v2 { + uint8_t report_id; + uint16_t packet_index; + uint8_t current_dither; + uint8_t reserved; + uint8_t data[59]; +} __attribute__((packed)) wispydbx_report_v2; + #ifdef SYS_LINUX /* Libusb doesn't seem to always provide this, so we'll use our own, taken from the * usb_detatch_kernel_driver_np... @@ -215,13 +267,13 @@ if (ioctl(gdev->fd, USBDEVFS_IOCTL, &command) < 0) { if (errno == EINVAL) { - snprintf(errstr, WISPY_ERROR_MAX, "Your kernel doesn't appear to accept " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Your kernel doesn't appear to accept " "the USB disconnect command. Either your kernel is too old and " "does not support device removal, or support for removal has " "been changed by your distribution kernel maintainers."); } - snprintf(errstr, WISPY_ERROR_MAX, "Could not detatch kernel driver from " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not detatch kernel driver from " "interface %d: %s", interface, strerror(errno)); return -1; } @@ -231,19 +283,19 @@ #endif /* sys_linux */ /* Prototypes */ -int wispydbx_usb_open(wispy_phy *); -int wispydbx_usb_close(wispy_phy *); -int wispydbx_usb_thread_close(wispy_phy *); -int wispydbx_usb_poll(wispy_phy *); -int wispydbx_usb_getpollfd(wispy_phy *); -void wispydbx_usb_setcalibration(wispy_phy *, int); -int wispydbx_usb_setposition(wispy_phy *, int, int, int); -wispy_sample_sweep *wispydbx_usb_getsweep(wispy_phy *); +int wispydbx_usb_open(spectool_phy *); +int wispydbx_usb_close(spectool_phy *); +int wispydbx_usb_thread_close(spectool_phy *); +int wispydbx_usb_poll(spectool_phy *); +int wispydbx_usb_getpollfd(spectool_phy *); +void wispydbx_usb_setcalibration(spectool_phy *, int); +int wispydbx_usb_setposition(spectool_phy *, int, int, int); +spectool_sample_sweep *wispydbx_usb_getsweep(spectool_phy *); -void wispy24i_add_supportedranges(int *num_ranges, wispy_sample_sweep **ranges) { - *ranges = (wispy_sample_sweep *) malloc(sizeof(wispy_sample_sweep) * 1); +void wispy24i_add_supportedranges(int *num_ranges, spectool_sample_sweep **ranges) { + *ranges = (spectool_sample_sweep *) malloc(sizeof(spectool_sample_sweep) * 2); - *num_ranges = 1; + *num_ranges = 2; (*ranges)[0].name = strdup("2.4GHz ISM"); (*ranges)[0].num_samples = WISPYDBx_USB_NUM_SAMPLES_24; @@ -259,10 +311,26 @@ (*ranges)[0].res_hz = WISPYDBx_USB_DEF_RESHZ_24; (*ranges)[0].samples_per_point = WISPYDBx_USB_DEF_SAMPLESPOINT_24; (*ranges)[0].filter_bw_hz = WISPYDBx_USB_DEF_FILTERHZ_24; + + (*ranges)[1].name = strdup("2.4GHz ISM FAST"); + (*ranges)[1].num_samples = WISPYDBx_USB_NUM_SAMPLES_24_FAST; + + (*ranges)[1].amp_offset_mdbm = WISPYDBx_USB_OFFSET_MDBM; + (*ranges)[1].amp_res_mdbm = WISPYDBx_USB_RES_MDBM; + (*ranges)[1].rssi_max = WISPYDBx_USB_RSSI_MAX; + + (*ranges)[1].start_khz = WISPYDBx_USB_DEF_STARTKHZ_24_FAST; + (*ranges)[1].end_khz = + WISPYDBx_USB_DEF_STARTKHZ_24_FAST + + ((WISPYDBx_USB_NUM_SAMPLES_24_FAST * + WISPYDBx_USB_DEF_RESHZ_24_FAST) / 1000); + (*ranges)[1].res_hz = WISPYDBx_USB_DEF_RESHZ_24_FAST; + (*ranges)[1].samples_per_point = WISPYDBx_USB_DEF_SAMPLESPOINT_24_FAST; + (*ranges)[1].filter_bw_hz = WISPYDBx_USB_DEF_FILTERHZ_24_FAST; } -void wispy900x_add_supportedranges(int *num_ranges, wispy_sample_sweep **ranges) { - *ranges = (wispy_sample_sweep *) malloc(sizeof(wispy_sample_sweep) * 1); +void wispy900x_add_supportedranges(int *num_ranges, spectool_sample_sweep **ranges) { + *ranges = (spectool_sample_sweep *) malloc(sizeof(spectool_sample_sweep) * 1); *num_ranges = 1; @@ -283,10 +351,10 @@ (*ranges)[0].filter_bw_hz = WISPY900x_USB_DEF_FILTERHZ; } -void wispydbx_add_supportedranges(int *num_ranges, wispy_sample_sweep **ranges) { - *ranges = (wispy_sample_sweep *) malloc(sizeof(wispy_sample_sweep) * 2); +void wispydbx_add_supportedranges(int *num_ranges, spectool_sample_sweep **ranges) { + *ranges = (spectool_sample_sweep *) malloc(sizeof(spectool_sample_sweep) * 4); - *num_ranges = 2; + *num_ranges = 4; (*ranges)[0].name = strdup("2.4GHz ISM"); (*ranges)[0].num_samples = WISPYDBx_USB_NUM_SAMPLES_24; @@ -303,20 +371,51 @@ (*ranges)[0].samples_per_point = WISPYDBx_USB_DEF_SAMPLESPOINT_24; (*ranges)[0].filter_bw_hz = WISPYDBx_USB_DEF_FILTERHZ_24; - (*ranges)[1].name = strdup("5GHz"); - (*ranges)[1].num_samples = WISPYDBx_USB_NUM_SAMPLES_58; + (*ranges)[1].name = strdup("2.4GHz ISM FAST"); + (*ranges)[1].num_samples = WISPYDBx_USB_NUM_SAMPLES_24_FAST; (*ranges)[1].amp_offset_mdbm = WISPYDBx_USB_OFFSET_MDBM; (*ranges)[1].amp_res_mdbm = WISPYDBx_USB_RES_MDBM; (*ranges)[1].rssi_max = WISPYDBx_USB_RSSI_MAX; - (*ranges)[1].start_khz = WISPYDBx_USB_STARTKHZ_58; + (*ranges)[1].start_khz = WISPYDBx_USB_DEF_STARTKHZ_24_FAST; (*ranges)[1].end_khz = + WISPYDBx_USB_DEF_STARTKHZ_24_FAST + + ((WISPYDBx_USB_NUM_SAMPLES_24_FAST * + WISPYDBx_USB_DEF_RESHZ_24_FAST) / 1000); + (*ranges)[1].res_hz = WISPYDBx_USB_DEF_RESHZ_24_FAST; + (*ranges)[1].samples_per_point = WISPYDBx_USB_DEF_SAMPLESPOINT_24_FAST; + (*ranges)[1].filter_bw_hz = WISPYDBx_USB_DEF_FILTERHZ_24_FAST; + + (*ranges)[2].name = strdup("5GHz"); + (*ranges)[2].num_samples = WISPYDBx_USB_NUM_SAMPLES_58; + + (*ranges)[2].amp_offset_mdbm = WISPYDBx_USB_OFFSET_MDBM; + (*ranges)[2].amp_res_mdbm = WISPYDBx_USB_RES_MDBM; + (*ranges)[2].rssi_max = WISPYDBx_USB_RSSI_MAX; + + (*ranges)[2].start_khz = WISPYDBx_USB_STARTKHZ_58; + (*ranges)[2].end_khz = WISPYDBx_USB_STARTKHZ_58 + ((WISPYDBx_USB_NUM_SAMPLES_58 * WISPYDBx_USB_RESHZ_58) / 1000); - (*ranges)[1].res_hz = WISPYDBx_USB_RESHZ_58; - (*ranges)[1].samples_per_point = WISPYDBx_USB_SAMPLESPOINT_58; - (*ranges)[1].filter_bw_hz = WISPYDBx_USB_FILTERHZ_58; + (*ranges)[2].res_hz = WISPYDBx_USB_RESHZ_58; + (*ranges)[2].samples_per_point = WISPYDBx_USB_SAMPLESPOINT_58; + (*ranges)[2].filter_bw_hz = WISPYDBx_USB_FILTERHZ_58; + + (*ranges)[3].name = strdup("5GHz UN-II"); + (*ranges)[3].num_samples = WISPYDBx_USB_NUM_SAMPLES_58_UNL; + + (*ranges)[3].amp_offset_mdbm = WISPYDBx_USB_OFFSET_MDBM; + (*ranges)[3].amp_res_mdbm = WISPYDBx_USB_RES_MDBM; + (*ranges)[3].rssi_max = WISPYDBx_USB_RSSI_MAX; + + (*ranges)[3].start_khz = WISPYDBx_USB_STARTKHZ_58_UNL; + (*ranges)[3].end_khz = + WISPYDBx_USB_STARTKHZ_58_UNL + ((WISPYDBx_USB_NUM_SAMPLES_58_UNL * + WISPYDBx_USB_RESHZ_58_UNL) / 1000); + (*ranges)[3].res_hz = WISPYDBx_USB_RESHZ_58_UNL; + (*ranges)[3].samples_per_point = WISPYDBx_USB_SAMPLESPOINT_58_UNL; + (*ranges)[3].filter_bw_hz = WISPYDBx_USB_FILTERHZ_58_UNL; } uint32_t wispydbx_adler_checksum(const char *buf1, int len) { @@ -340,7 +439,7 @@ } /* Scan for devices */ -int wispydbx_usb_device_scan(wispy_device_list *list) { +int wispydbx_usb_device_scan(spectool_device_list *list) { struct usb_bus *bus; struct usb_device *dev; int num_found = 0; @@ -357,10 +456,16 @@ for (dev = bus->devices; dev; dev = dev->next) { if (((dev->descriptor.idVendor == METAGEEK_WISPYDBx_VID) && (dev->descriptor.idProduct == METAGEEK_WISPYDBx_PID)) || + ((dev->descriptor.idVendor == METAGEEK_WISPYDBx_V2_VID) && + (dev->descriptor.idProduct == METAGEEK_WISPYDBx_V2_PID)) || ((dev->descriptor.idVendor == METAGEEK_WISPY24I_VID) && (dev->descriptor.idProduct == METAGEEK_WISPY24I_PID)) || + ((dev->descriptor.idVendor == METAGEEK_WISPY24x_V2_VID) && + (dev->descriptor.idProduct == METAGEEK_WISPY24x_V2_PID)) || ((dev->descriptor.idVendor == METAGEEK_WISPY900x_VID) && - (dev->descriptor.idProduct == METAGEEK_WISPY900x_PID))) { + (dev->descriptor.idProduct == METAGEEK_WISPY900x_PID)) || + ((dev->descriptor.idVendor == METAGEEK_WISPY950x_VID) && + (dev->descriptor.idProduct == METAGEEK_WISPY950x_PID))) { /* If we're full up, break */ if (list->num_devs == list->max_devs - 1) @@ -374,15 +479,27 @@ snprintf(combopath, 128, "%s%s", auxpair->bus, auxpair->dev); if (dev->descriptor.idProduct == METAGEEK_WISPY24I_PID) { - snprintf(list->list[list->num_devs].name, WISPY_PHY_NAME_MAX, + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy %s USB %u", "24i", list->list[list->num_devs].device_id); model = 1; } else if (dev->descriptor.idProduct == METAGEEK_WISPY900x_PID) { - snprintf(list->list[list->num_devs].name, WISPY_PHY_NAME_MAX, + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy %s USB %u", "900x", list->list[list->num_devs].device_id); model = 2; + } else if (dev->descriptor.idProduct == METAGEEK_WISPY950x_PID) { + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, + "Wi-Spy %s USB %u", "950x", list->list[list->num_devs].device_id); + model = 2; + } else if (dev->descriptor.idProduct == METAGEEK_WISPYDBx_V2_PID) { + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, + "Wi-Spy %s USB %u", "DBx2", list->list[list->num_devs].device_id); + model = 3; + } else if (dev->descriptor.idProduct == METAGEEK_WISPY24x_V2_PID) { + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, + "Wi-Spy %s USB %u", "24x2", list->list[list->num_devs].device_id); + model = 4; } else { - snprintf(list->list[list->num_devs].name, WISPY_PHY_NAME_MAX, + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy %s USB %u", "DBx", list->list[list->num_devs].device_id); } @@ -392,15 +509,15 @@ list->list[list->num_devs].init_func = wispydbx_usb_init; list->list[list->num_devs].hw_rec = auxpair; - if (model == 0) + if (model == 0 || model == 3) wispydbx_add_supportedranges( &(list->list[list->num_devs].num_sweep_ranges), &(list->list[list->num_devs].supported_ranges)); - else if (model == 1) + else if (model == 1 || model == 4) wispy24i_add_supportedranges( &(list->list[list->num_devs].num_sweep_ranges), &(list->list[list->num_devs].supported_ranges)); - else if (model == 2) + else if (model == 2 || model == 5) wispy900x_add_supportedranges( &(list->list[list->num_devs].num_sweep_ranges), &(list->list[list->num_devs].supported_ranges)); @@ -415,7 +532,7 @@ return num_found; } -int wispydbx_usb_init(wispy_phy *phydev, wispy_device_rec *rec) { +int wispydbx_usb_init(spectool_phy *phydev, spectool_device_rec *rec) { wispydbx_usb_pair *auxpair = (wispydbx_usb_pair *) rec->hw_rec; if (auxpair == NULL) @@ -425,7 +542,7 @@ } /* Initialize a specific USB device based on bus and device IDs passed by the UI */ -int wispydbx_usb_init_path(wispy_phy *phydev, char *buspath, char *devpath) { +int wispydbx_usb_init_path(spectool_phy *phydev, char *buspath, char *devpath) { struct usb_bus *bus = NULL; struct usb_device *dev = NULL; @@ -458,14 +575,20 @@ if (((dev->descriptor.idVendor == METAGEEK_WISPYDBx_VID) && (dev->descriptor.idProduct == METAGEEK_WISPYDBx_PID)) || + ((dev->descriptor.idVendor == METAGEEK_WISPYDBx_V2_VID) && + (dev->descriptor.idProduct == METAGEEK_WISPYDBx_V2_PID)) || ((dev->descriptor.idVendor == METAGEEK_WISPY24I_VID) && (dev->descriptor.idProduct == METAGEEK_WISPY24I_PID)) || + ((dev->descriptor.idVendor == METAGEEK_WISPY24x_V2_VID) && + (dev->descriptor.idProduct == METAGEEK_WISPY24x_V2_PID)) || ((dev->descriptor.idVendor == METAGEEK_WISPY900x_VID) && - (dev->descriptor.idProduct == METAGEEK_WISPY900x_PID))) { + (dev->descriptor.idProduct == METAGEEK_WISPY900x_PID)) || + ((dev->descriptor.idVendor == METAGEEK_WISPY950x_VID) && + (dev->descriptor.idProduct == METAGEEK_WISPY950x_PID))) { usb_dev_chosen = dev; break; } else { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "WISPYDBx_INIT failed, specified device %u does not " "appear to be a Wi-Spy device", cid); return -1; @@ -474,7 +597,7 @@ } if (usb_dev_chosen == NULL) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "WISPYDBx_INIT failed, specified device %u does not appear " "to exist.", cid); return -1; @@ -484,9 +607,15 @@ model = 1; else if (usb_dev_chosen->descriptor.idProduct == METAGEEK_WISPY900x_PID) model = 2; + else if (usb_dev_chosen->descriptor.idProduct == METAGEEK_WISPYDBx_V2_PID) + model = 3; + else if (usb_dev_chosen->descriptor.idProduct == METAGEEK_WISPY24x_V2_PID) + model = 4; + else if (usb_dev_chosen->descriptor.idProduct == METAGEEK_WISPY950x_PID) + model = 5; /* Build the device record with appropriate sweep capabilities */ - phydev->device_spec = (wispy_dev_spec *) malloc(sizeof(wispy_dev_spec)); + phydev->device_spec = (spectool_dev_spec *) malloc(sizeof(spectool_dev_spec)); phydev->device_spec->device_id = cid; @@ -494,34 +623,49 @@ switch (model) { case 1: - snprintf(phydev->device_spec->device_name, WISPY_PHY_NAME_MAX, + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy %s USB %u", "24i", cid); break; case 2: - snprintf(phydev->device_spec->device_name, WISPY_PHY_NAME_MAX, + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy %s USB %u", "900x", cid); break; + case 3: + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, + "Wi-Spy %s USB %u", "DBx2", cid); + break; + case 4: + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, + "Wi-Spy %s USB %u", "24x2", cid); + break; + case 5: + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, + "Wi-Spy %s USB %u", "950x", cid); + break; default: - snprintf(phydev->device_spec->device_name, WISPY_PHY_NAME_MAX, + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy %s USB %u", "DBx", cid); break; } /* State */ - phydev->state = WISPY_STATE_CLOSED; + phydev->state = SPECTOOL_STATE_CLOSED; phydev->min_rssi_seen = -1; phydev->device_spec->device_version = 0x03; - phydev->device_spec->device_flags = WISPY_DEV_FL_VAR_SWEEP; + phydev->device_spec->device_flags = SPECTOOL_DEV_FL_VAR_SWEEP; - if (model == 0) { + if (model == 0 || model == 3) { + // DBX v1 and V2 wispydbx_add_supportedranges(&phydev->device_spec->num_sweep_ranges, &phydev->device_spec->supported_ranges); - } else if (model == 1) { + } else if (model == 1 || model == 4) { + // 24i and 24xv2 wispy24i_add_supportedranges(&phydev->device_spec->num_sweep_ranges, &phydev->device_spec->supported_ranges); - } else if (model == 2) { + } else if (model == 2 || model == 5) { + // 900 and 950x wispy900x_add_supportedranges(&phydev->device_spec->num_sweep_ranges, &phydev->device_spec->supported_ranges); } @@ -536,6 +680,14 @@ auxptr = malloc(sizeof(wispydbx_usb_aux)); phydev->auxptr = auxptr; + auxptr->model = model; + + // Set the protocol version + if (model == 3 || model == 4) + auxptr->protocol = 2; + else + auxptr->protocol = 1; + auxptr->configured = 0; auxptr->sweepbase = 0; @@ -570,7 +722,10 @@ struct usb_device *dev; struct usb_dev_handle *wispy; - char buf[sizeof(wispydbx_report)]; + // Size by v2 report, which is bigger + char buf[sizeof(wispydbx_report_v2)]; + int bufsz; + int x = 0, error = 0; fd_set wset; @@ -582,6 +737,12 @@ sock = auxptr->sockpair[1]; + // Size report based on v1 or v2 protocol + if (auxptr->protocol == 2) + bufsz = sizeof(wispydbx_report_v2); + else + bufsz = sizeof(wispydbx_report); + dev = auxptr->dev; wispy = auxptr->devhdl; @@ -598,16 +759,16 @@ FD_SET(sock, &wset); if (select(sock + 1, NULL, &wset, NULL, NULL) < 0) { - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb poller failed on IPC write select(): %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } if (auxptr->usb_thread_alive == 0) { - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } @@ -616,14 +777,14 @@ } /* Get new data only if we haven't requeued */ - if (error == 0 && auxptr->phydev->state == WISPY_STATE_RUNNING) { + if (error == 0 && auxptr->phydev->state == SPECTOOL_STATE_RUNNING) { int len = 0; - memset(buf, 0, sizeof(wispydbx_report)); + memset(buf, 0, bufsz); // fprintf(stderr, "debug - running, poll\n"); if ((len = usb_interrupt_read(wispy, 0x82, buf, - sizeof(wispydbx_report), TIMEOUT)) <= 0) { + bufsz, TIMEOUT)) <= 0) { if (errno == EAGAIN) { // fprintf(stderr, "debug - eagain on usb_interrupt_read\n"); continue; @@ -632,28 +793,28 @@ // fprintf(stderr, "debug - failed - %s\n", strerror(errno)); // fprintf(stderr, "debug - %s\n", usb_strerror()); - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb poller failed to read USB data: %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } // printf("debug - usb read return %d\n", len); /* Send it to the IPC remote, re-queue on enobufs */ - if (send(sock, buf, sizeof(wispydbx_report), 0) < 0) { + if (send(sock, buf, bufsz, 0) < 0) { if (errno == ENOBUFS) { error = 1; continue; } - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb poller failed on IPC send: %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } @@ -663,12 +824,12 @@ } auxptr->usb_thread_alive = 0; - send(sock, buf, sizeof(wispydbx_report), 0); - auxptr->phydev->state = WISPY_STATE_ERROR; + send(sock, buf, bufsz, 0); + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } -int wispydbx_usb_getpollfd(wispy_phy *phydev) { +int wispydbx_usb_getpollfd(spectool_phy *phydev) { wispydbx_usb_aux *auxptr = (wispydbx_usb_aux *) phydev->auxptr; if (auxptr->usb_thread_alive == 0) { @@ -681,7 +842,7 @@ return auxptr->sockpair[0]; } -int wispydbx_usb_open(wispy_phy *phydev) { +int wispydbx_usb_open(spectool_phy *phydev) { int pid_status; struct usb_dev_handle *wispy; wispydbx_usb_aux *auxptr = (wispydbx_usb_aux *) phydev->auxptr; @@ -689,14 +850,14 @@ /* Make the client/server socketpair */ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, auxptr->sockpair) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb open failed to create socket pair for capture " "process: %s", strerror(errno)); return -1; } if ((auxptr->devhdl = usb_open(auxptr->dev)) == NULL) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb capture process failed to open USB device: %s", strerror(errno)); return -1; @@ -704,7 +865,7 @@ #if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP) if (usb_detach_kernel_driver_np(auxptr->devhdl, 0) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "Could not detach device from kernel driver: %s", usb_strerror()); } @@ -712,14 +873,14 @@ // fprintf(stderr, "debug - set_configuration\n"); if (usb_set_configuration(auxptr->devhdl, 1) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "could not configure interface: %s", usb_strerror()); // fprintf(stderr, "debug - failed to set config: %s\n", usb_strerror()); } // fprintf(stderr, "debug - claiming interface\n"); if (usb_claim_interface(auxptr->devhdl, 0) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "could not claim interface: %s", usb_strerror()); } // fprintf(stderr, "debug - done claiming\n"); @@ -731,7 +892,7 @@ if (pthread_create(&(auxptr->usb_thread), NULL, wispydbx_usb_servicethread, auxptr) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb capture failed to create thread: %s", strerror(errno)); auxptr->usb_thread_alive = 0; @@ -741,7 +902,7 @@ // printf("debug - done creating thread\n"); /* Update the state */ - phydev->state = WISPY_STATE_CONFIGURING; + phydev->state = SPECTOOL_STATE_CONFIGURING; /* if (wispydbx_usb_setposition(phydev, 0, 0, 0) < 0) { @@ -768,10 +929,10 @@ (uint8_t *) &startcmd, (int) sizeof(wispydbx_startsweep), 0) <= 0) { // fprintf(stderr, "debug - controlmsg start failed %s\n", strerror(errno)); - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb open failed to send start command: %s", strerror(errno)); - phydev->state = WISPY_STATE_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; return -1; } @@ -780,7 +941,7 @@ return 1; } -int wispydbx_usb_close(wispy_phy *phydev) { +int wispydbx_usb_close(spectool_phy *phydev) { wispydbx_usb_aux *aux; if (phydev == NULL) @@ -816,24 +977,42 @@ return 1; } -wispy_sample_sweep *wispydbx_usb_getsweep(wispy_phy *phydev) { +spectool_sample_sweep *wispydbx_usb_getsweep(spectool_phy *phydev) { wispydbx_usb_aux *auxptr = (wispydbx_usb_aux *) phydev->auxptr; return auxptr->sweepbuf; } -void wispydbx_usb_setcalibration(wispy_phy *phydev, int in_calib) { - phydev->state = WISPY_STATE_RUNNING; +void wispydbx_usb_setcalibration(spectool_phy *phydev, int in_calib) { + phydev->state = SPECTOOL_STATE_RUNNING; } -int wispydbx_usb_poll(wispy_phy *phydev) { +int wispydbx_usb_poll(spectool_phy *phydev) { wispydbx_usb_aux *auxptr = (wispydbx_usb_aux *) phydev->auxptr; - char lbuf[sizeof(wispydbx_report)]; + + // Use v2 report size as it is larger + char lbuf[sizeof(wispydbx_report_v2)]; + int bufsz; + int x; int base = 0; int ret = 0; int sweep_full = 0; + wispydbx_report *report; + wispydbx_report_v2 *report2; + + uint16_t packet_index; + uint8_t *data; + unsigned int nsamples; + + if (auxptr->protocol == 2) { + bufsz = sizeof(wispydbx_report_v2); + nsamples = 59; + } else { + bufsz = sizeof(wispydbx_report); + nsamples = 61; + } // printf("debug - usb poll\n"); @@ -841,33 +1020,33 @@ if (auxptr->configured == 0) { auxptr->configured = 1; // printf("debug - usb poll return configured\n"); - return WISPY_POLL_CONFIGURED; + return SPECTOOL_POLL_CONFIGURED; } /* Use the error set by the polling thread */ if (auxptr->usb_thread_alive == 0) { - phydev->state = WISPY_STATE_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; wispydbx_usb_close(phydev); // printf("debug - usb poll return error\n"); - return WISPY_POLL_ERROR; + return SPECTOOL_POLL_ERROR; } - if ((ret = recv(auxptr->sockpair[0], lbuf, sizeof(wispydbx_report), 0)) < 0) { + if ((ret = recv(auxptr->sockpair[0], lbuf, bufsz, 0)) < 0) { // printf("debug - usb poll return recv error\n"); if (auxptr->usb_thread_alive != 0) - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb IPC receiver failed to read signal data: %s", strerror(errno)); - phydev->state = WISPY_STATE_ERROR; - return WISPY_POLL_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; + return SPECTOOL_POLL_ERROR; } if (time(0) - auxptr->last_read > 3) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, - "wispy1_usb didn't see any data for more than 3 seconds, " + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "wispydbx_usb didn't see any data for more than 3 seconds, " "something has gone wrong (was the device removed?)"); - phydev->state = WISPY_STATE_ERROR; - return WISPY_POLL_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; + return SPECTOOL_POLL_ERROR; } if (ret > 0) @@ -875,22 +1054,33 @@ // printf("debug usb poll recv len %d\n", ret); // - if (ret < sizeof(wispydbx_report)) { + if (ret < bufsz) { printf("Short report\n"); - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } // If we don't have a sweepbuf we're not configured, barf if (auxptr->sweepbuf == NULL) - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; + + if (auxptr->protocol == 2) { + report2 = (wispydbx_report_v2 *) lbuf; + + packet_index = report2->packet_index; + data = report2->data; - report = (wispydbx_report *) lbuf; + } else { + report = (wispydbx_report *) lbuf; + + packet_index = report->packet_index; + data = report->data; + } /* Extract the slot index */ #ifdef WORDS_BIGENDIAN - base = endian_swap16(report->packet_index); + base = endian_swap16(packet_index); #else - base = report->packet_index; + base = packet_index; #endif if (base == 0) @@ -900,7 +1090,7 @@ if (base < 0 || base > auxptr->sweepbuf->num_samples) { /* Bunk data, throw it out */ - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } /* Initialize the sweep buffer when we get to it @@ -913,38 +1103,45 @@ /* Init the timestamp for sweep begin */ gettimeofday(&(auxptr->sweepbuf->tm_start), NULL); } else if (auxptr->sweepbuf_initialized == 0) { - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } - for (x = 0; x < 61; x++) { + for (x = 0; x < nsamples; x++) { if (base + x >= auxptr->sweepbuf->num_samples) { sweep_full = 1; break; } - auxptr->sweepbuf->sample_data[base + x] = report->data[x]; + auxptr->sweepbuf->sample_data[base + x] = data[x]; - if (report->data[x] < phydev->min_rssi_seen) - phydev->min_rssi_seen = report->data[x]; + if (data[x] < phydev->min_rssi_seen) + phydev->min_rssi_seen = data[x]; } - auxptr->sweepbase += 61; + auxptr->sweepbase += nsamples; /* Flag that a sweep is complete */ - if (base + 61 == auxptr->sweepbuf->num_samples || sweep_full) { + if (base + nsamples == auxptr->sweepbuf->num_samples || sweep_full) { gettimeofday(&(auxptr->sweepbuf->tm_end), NULL); auxptr->sweepbuf->min_rssi_seen = phydev->min_rssi_seen; - return WISPY_POLL_SWEEPCOMPLETE; + return SPECTOOL_POLL_SWEEPCOMPLETE; } - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } -int wispydbx_usb_setposition(wispy_phy *phydev, int in_profile, +int wispydbx_usb_setposition(spectool_phy *phydev, int in_profile, int start_khz, int res_hz) { struct usb_dev_handle *wispy; + wispydbx_rfsettings rfset; + wispydbx_rfsettings_v2 rfset2; + uint8_t *use_rfset = NULL; + int rfset_len = 0; + + int x; + wispydbx_usb_aux *auxptr = (wispydbx_usb_aux *) phydev->auxptr; int use_default = 0; @@ -970,25 +1167,58 @@ phydev->device_spec->supported_ranges[in_profile].samples_per_point; /* Initialize the hw sweep features */ - rfset.report_id = 0x53; - rfset.command_id = 0x10; - rfset.command_flags = - WISPYDBx_USB_ASSEMBLE_CMDFLAGS(auxptr->cmd_seq++, - WISPYDBx_USB_RFSETTINGS_LEN); + if (auxptr->protocol == 2) { + // model 3 (dbx v2) gets the v2 settings block + rfset2.report_id = 0x53; + rfset2.command_id = 0x10; + + rfset2.command_flags = + WISPYDBx_USB_ASSEMBLE_CMDFLAGS(auxptr->cmd_seq++, + WISPYDBx_USB_RFSETTINGS_V2_LEN); - /* Multibytes have to be handled in USB-endian (little) */ + /* Multibytes have to be handled in USB-endian (little) */ #ifdef WORDS_BIGENDIAN - rfset.start_khz = endian_swap32(start_khz); - rfset.freq_res_hz = endian_swap32(res_hz); - rfset.filter_bw_hz = endian_swap32(filter_bw_hz); - rfset.points_per_sweep = endian_swap16(points_per_sweep); + rfset2.start_khz = endian_swap32(start_khz); + rfset2.freq_res_hz = endian_swap32(res_hz); + rfset2.filter_bw_hz = endian_swap32(filter_bw_hz); + rfset2.points_per_sweep = endian_swap16(points_per_sweep); #else - rfset.start_khz = start_khz; - rfset.freq_res_hz = res_hz; - rfset.filter_bw_hz = filter_bw_hz; - rfset.points_per_sweep = points_per_sweep; + rfset2.start_khz = start_khz; + rfset2.freq_res_hz = res_hz; + rfset2.filter_bw_hz = filter_bw_hz; + rfset2.points_per_sweep = points_per_sweep; #endif - rfset.samples_per_point = samples_per_point; + rfset2.dwell_time = 100; + rfset2.dither_steps = 1; + rfset2.reserved = 0; + + use_rfset = &rfset2; + rfset_len = (int) sizeof(wispydbx_rfsettings_v2); + } else { + rfset.report_id = 0x53; + rfset.command_id = 0x10; + rfset.command_flags = + WISPYDBx_USB_ASSEMBLE_CMDFLAGS(auxptr->cmd_seq++, + WISPYDBx_USB_RFSETTINGS_LEN); + + /* Multibytes have to be handled in USB-endian (little) */ +#ifdef WORDS_BIGENDIAN + rfset.start_khz = endian_swap32(start_khz); + rfset.freq_res_hz = endian_swap32(res_hz); + rfset.filter_bw_hz = endian_swap32(filter_bw_hz); + rfset.points_per_sweep = endian_swap16(points_per_sweep); +#else + rfset.start_khz = start_khz; + rfset.freq_res_hz = res_hz; + rfset.filter_bw_hz = filter_bw_hz; + rfset.points_per_sweep = points_per_sweep; +#endif + rfset.samples_per_point = samples_per_point; + + use_rfset = &rfset; + rfset_len = (int) sizeof(wispydbx_rfsettings); + + } wispy = auxptr->devhdl; @@ -998,17 +1228,55 @@ HID_SET_REPORT, 0x02 + (0x03 << 8), 0, - (uint8_t *) &rfset, (int) sizeof(wispydbx_rfsettings), + (uint8_t *) use_rfset, rfset_len, 0) == 0) { fprintf(stderr, "debug - control_msg_fail: %s\n", usb_strerror()); - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispydbx_usb setposition failed to set sweep feature set: %s", strerror(errno)); - phydev->state = WISPY_STATE_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; return -1; } // printf("debug - finished wrting usb control\n"); +#if 0 + memset(use_rfset, 0, rfset_len); + + if (auxptr->protocol == 2) { + rfset2.report_id = 0x53; + rfset2.command_id = 0x11; + rfset2.command_flags = + WISPYDBx_USB_ASSEMBLE_CMDFLAGS(auxptr->cmd_seq++, + WISPYDBx_USB_RFSETTINGS_V2_LEN); + } else { + rfset.report_id = 0x53; + rfset.command_id = 0x11; + rfset.command_flags = + WISPYDBx_USB_ASSEMBLE_CMDFLAGS(auxptr->cmd_seq++, + WISPYDBx_USB_RFSETTINGS_LEN); + } + + if (usb_control_msg(wispy, + USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE, + HID_GET_REPORT, + 0x02 + (0x03 << 8), + 0, + (uint8_t *) use_rfset, rfset_len, + 0) == 0) { + fprintf(stderr, "debug - control_msg_fail: %s\n", usb_strerror()); + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, + "wispydbx_usb setposition failed to get sweep feature set: %s", + strerror(errno)); + phydev->state = SPECTOOL_STATE_ERROR; + return -1; + } + + for (x = 0; x < rfset_len; x++) { + printf("%02x ", use_rfset[x]); + } + printf("\n"); +#endif + /* We're not configured, so we need to push a new configure block out next time * we sweep */ auxptr->configured = 0; @@ -1018,7 +1286,7 @@ free(auxptr->sweepbuf); auxptr->sweepbuf = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(phydev->device_spec->supported_ranges[in_profile].num_samples)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(phydev->device_spec->supported_ranges[in_profile].num_samples)); auxptr->sweepbuf->phydev = phydev; auxptr->sweepbuf->start_khz = phydev->device_spec->supported_ranges[in_profile].start_khz; diff -Nru spectools-201004R1/wispy_hw_dbx.h spectools-201108r1/wispy_hw_dbx.h --- spectools-201004R1/wispy_hw_dbx.h 2008-09-17 13:41:31.000000000 +0000 +++ spectools-201108r1/wispy_hw_dbx.h 2011-06-10 15:53:29.000000000 +0000 @@ -32,11 +32,11 @@ char dev[64]; } wispydbx_usb_pair; -int wispydbx_usb_device_scan(wispy_device_list *list); +int wispydbx_usb_device_scan(spectool_device_list *list); /* Wispy24x init function to build a phydev linked to a bus and device path * scanned */ -int wispydbx_usb_init_path(wispy_phy *phydev, char *buspath, char *devpath); -int wispydbx_usb_init(wispy_phy *phydev, wispy_device_rec *rec); +int wispydbx_usb_init_path(spectool_phy *phydev, char *buspath, char *devpath); +int wispydbx_usb_init(spectool_phy *phydev, spectool_device_rec *rec); #endif diff -Nru spectools-201004R1/wispy_hw_gen1.c spectools-201108r1/wispy_hw_gen1.c --- spectools-201004R1/wispy_hw_gen1.c 2009-06-17 23:43:33.000000000 +0000 +++ spectools-201108r1/wispy_hw_gen1.c 2011-06-10 15:53:29.000000000 +0000 @@ -110,7 +110,7 @@ int num_sweeps; /* Sweep buffer we maintain and return */ - wispy_sample_sweep *sweepbuf; + spectool_sample_sweep *sweepbuf; /* Calibration modes. We avoid a "want calibration" by setting it to true */ int calibrated; @@ -121,7 +121,7 @@ int sockpair[2]; - wispy_phy *phydev; + spectool_phy *phydev; } wispy1_usb_aux; #ifdef SYS_LINUX @@ -154,13 +154,13 @@ if (ioctl(gdev->fd, USBDEVFS_IOCTL, &command) < 0) { if (errno == EINVAL) { - snprintf(errstr, WISPY_ERROR_MAX, "Your kernel doesn't appear to accept " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Your kernel doesn't appear to accept " "the USB disconnect command. Either your kernel is too old and " "does not support device removal, or support for removal has " "been changed by your distribution kernel maintainers."); } - snprintf(errstr, WISPY_ERROR_MAX, "Could not detatch kernel driver from " + snprintf(errstr, SPECTOOL_ERROR_MAX, "Could not detatch kernel driver from " "interface %d: %s", interface, strerror(errno)); return -1; } @@ -170,12 +170,12 @@ #endif /* sys_linux */ /* Prototypes */ -int wispy1_usb_open(wispy_phy *); -int wispy1_usb_close(wispy_phy *); -int wispy1_usb_poll(wispy_phy *); -int wispy1_usb_getpollfd(wispy_phy *); -void wispy1_usb_setcalibration(wispy_phy *, int); -wispy_sample_sweep *wispy1_usb_getsweep(wispy_phy *); +int wispy1_usb_open(spectool_phy *); +int wispy1_usb_close(spectool_phy *); +int wispy1_usb_poll(spectool_phy *); +int wispy1_usb_getpollfd(spectool_phy *); +void wispy1_usb_setcalibration(spectool_phy *, int); +spectool_sample_sweep *wispy1_usb_getsweep(spectool_phy *); uint32_t wispy1_adler_checksum(const char *buf1, int len) { int i; @@ -198,7 +198,7 @@ } /* Scan for devices */ -int wispy1_usb_device_scan(wispy_device_list *list) { +int wispy1_usb_device_scan(spectool_device_list *list) { struct usb_bus *bus; struct usb_device *dev; int num_found = 0; @@ -231,7 +231,7 @@ /* Fill in the list elements */ list->list[list->num_devs].device_id = wispy1_adler_checksum(combopath, 128); - snprintf(list->list[list->num_devs].name, WISPY_PHY_NAME_MAX, + snprintf(list->list[list->num_devs].name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy v1 USB %u", list->list[list->num_devs].device_id); list->list[list->num_devs].init_func = wispy1_usb_init; list->list[list->num_devs].hw_rec = auxpair; @@ -239,7 +239,7 @@ list->list[list->num_devs].num_sweep_ranges = 1; list->list[list->num_devs].supported_ranges = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(0)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(0)); /* 2400 to 2484 MHz at 1MHz res */ list->list[list->num_devs].supported_ranges[0].name = @@ -267,7 +267,7 @@ return num_found; } -int wispy1_usb_init(wispy_phy *phydev, wispy_device_rec *rec) { +int wispy1_usb_init(spectool_phy *phydev, spectool_device_rec *rec) { wispy1_usb_pair *auxpair = (wispy1_usb_pair *) rec->hw_rec; if (auxpair == NULL) @@ -277,7 +277,7 @@ } /* Initialize a specific USB device based on bus and device IDs passed by the UI */ -int wispy1_usb_init_path(wispy_phy *phydev, char *buspath, char *devpath) { +int wispy1_usb_init_path(spectool_phy *phydev, char *buspath, char *devpath) { struct usb_bus *bus = NULL; struct usb_device *dev = NULL; @@ -312,7 +312,7 @@ usb_dev_chosen = dev; break; } else { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "WISPY1_INIT failed, specified device %u does not " "appear to be a Wi-Spy device", cid); return -1; @@ -321,23 +321,23 @@ } if (usb_dev_chosen == NULL) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "WISPY1_INIT failed, specified device %u does not appear " "to exist.", cid); return -1; } /* Build the device record with one sweep capability */ - phydev->device_spec = (wispy_dev_spec *) malloc(sizeof(wispy_dev_spec)); + phydev->device_spec = (spectool_dev_spec *) malloc(sizeof(spectool_dev_spec)); phydev->device_spec->device_id = cid; /* Default the name to the buspath */ - snprintf(phydev->device_spec->device_name, WISPY_PHY_NAME_MAX, + snprintf(phydev->device_spec->device_name, SPECTOOL_PHY_NAME_MAX, "Wi-Spy v1 USB %u", cid); /* State */ - phydev->state = WISPY_STATE_CLOSED; + phydev->state = SPECTOOL_STATE_CLOSED; phydev->min_rssi_seen = -1; @@ -345,7 +345,7 @@ phydev->device_spec->num_sweep_ranges = 1; phydev->device_spec->supported_ranges = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(0)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(0)); /* 2400 to 2484 MHz at 1MHz res */ phydev->device_spec->supported_ranges[0].start_khz = 2400000; @@ -376,7 +376,7 @@ auxptr->sweepbuf_initialized = 0; auxptr->sweepbuf = - (wispy_sample_sweep *) malloc(WISPY_SWEEP_SIZE(WISPY1_USB_NUM_SAMPLES)); + (spectool_sample_sweep *) malloc(SPECTOOL_SWEEP_SIZE(WISPY1_USB_NUM_SAMPLES)); auxptr->sweepbuf->start_khz = 2400000; auxptr->sweepbuf->end_khz = 2484000; auxptr->sweepbuf->res_hz = 1000 * 1000; @@ -439,16 +439,16 @@ FD_SET(sock, &wset); if (select(sock + 1, NULL, &wset, NULL, NULL) < 0) { - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb poller failed on IPC write select(): %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } if (auxptr->usb_thread_alive == 0) { - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } @@ -464,21 +464,21 @@ USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE, HID_GET_REPORT, (HID_RT_FEATURE << 8), 0, buf, 8, TIMEOUT) == 0) { - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb poller failed on usb_control_msg " "HID cmd: %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } if (buf[0] == (char) 0xFF) { - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb poller failed on usb_control_msg " "HID cmd, no data returned, was the device removed?"); auxptr->usb_thread_alive = 0; send(sock, buf, 8, 0); - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } } @@ -490,11 +490,11 @@ continue; } - snprintf(auxptr->phydev->errstr, WISPY_ERROR_MAX, + snprintf(auxptr->phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb poller failed on IPC send: %s", strerror(errno)); auxptr->usb_thread_alive = 0; - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } @@ -507,11 +507,11 @@ auxptr->usb_thread_alive = 0; send(sock, buf, 8, 0); - auxptr->phydev->state = WISPY_STATE_ERROR; + auxptr->phydev->state = SPECTOOL_STATE_ERROR; pthread_exit(NULL); } -int wispy1_usb_getpollfd(wispy_phy *phydev) { +int wispy1_usb_getpollfd(spectool_phy *phydev) { wispy1_usb_aux *auxptr = (wispy1_usb_aux *) phydev->auxptr; if (auxptr->usb_thread_alive == 0) { @@ -522,20 +522,20 @@ return auxptr->sockpair[0]; } -int wispy1_usb_open(wispy_phy *phydev) { +int wispy1_usb_open(spectool_phy *phydev) { int pid_status; wispy1_usb_aux *auxptr = (wispy1_usb_aux *) phydev->auxptr; /* Make the client/server socketpair */ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, auxptr->sockpair) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb open failed to create socket pair for capture " "process: %s", strerror(errno)); return -1; } if ((auxptr->devhdl = usb_open(auxptr->dev)) == NULL) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb capture process failed to open USB device: %s", strerror(errno)); return -1; @@ -544,12 +544,12 @@ #ifndef SYS_DARWIN /* Claim the device on non-OSX systems */ if (usb_claim_interface(auxptr->devhdl, 0) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "could not claim interface: %s", usb_strerror()); #ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP if (usb_detach_kernel_driver_np(auxptr->devhdl, 0) < 0) { fprintf(stderr, "Could not detach kernel driver %s\n", usb_strerror()); - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "Could not detach device from kernel driver: %s", usb_strerror()); #endif @@ -561,7 +561,7 @@ usb_set_configuration(auxptr->devhdl, auxptr->dev->config->bConfigurationValue); if (usb_claim_interface(auxptr->devhdl, 0) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy24x_usb capture process detached device but still " "can't claim interface: %s", strerror(errno)); return -1; @@ -580,7 +580,7 @@ if (pthread_create(&(auxptr->usb_thread), NULL, wispy1_usb_servicethread, auxptr) < 0) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb capture failed to create thread: %s", strerror(errno)); auxptr->usb_thread_alive = 0; @@ -588,12 +588,12 @@ } /* Update the state */ - phydev->state = WISPY_STATE_CONFIGURING; + phydev->state = SPECTOOL_STATE_CONFIGURING; return 1; } -int wispy1_usb_close(wispy_phy *phydev) { +int wispy1_usb_close(spectool_phy *phydev) { wispy1_usb_aux *aux; if (phydev == NULL) @@ -627,13 +627,13 @@ return 1; } -wispy_sample_sweep *wispy1_usb_getsweep(wispy_phy *phydev) { +spectool_sample_sweep *wispy1_usb_getsweep(spectool_phy *phydev) { wispy1_usb_aux *auxptr = (wispy1_usb_aux *) phydev->auxptr; return auxptr->sweepbuf; } -void wispy1_usb_setcalibration(wispy_phy *phydev, int in_calib) { +void wispy1_usb_setcalibration(spectool_phy *phydev, int in_calib) { wispy1_usb_aux *auxptr = (wispy1_usb_aux *) phydev->auxptr; int x; @@ -641,7 +641,7 @@ free(auxptr->calibrationbuf); auxptr->calibrationbuf = NULL; auxptr->calibrated = 1; - phydev->state = WISPY_STATE_RUNNING; + phydev->state = SPECTOOL_STATE_RUNNING; } if (in_calib != 0 && auxptr->calibrationbuf == NULL) { @@ -650,11 +650,11 @@ auxptr->calibrated = 0; for (x = 0; x < WISPY1_USB_NUM_SAMPLES; x++) auxptr->calibrationbuf[x] = 0; - phydev->state = WISPY_STATE_CALIBRATING; + phydev->state = SPECTOOL_STATE_CALIBRATING; } } -int wispy1_usb_poll(wispy_phy *phydev) { +int wispy1_usb_poll(spectool_phy *phydev) { wispy1_usb_aux *auxptr = (wispy1_usb_aux *) phydev->auxptr; unsigned char lbuf[8]; int x, pos, calfreqs, ret; @@ -664,31 +664,31 @@ /* Push a configure event before anything else */ if (auxptr->configured == 0) { auxptr->configured = 1; - return WISPY_POLL_CONFIGURED; + return SPECTOOL_POLL_CONFIGURED; } /* Use the error set by the polling thread */ if (auxptr->usb_thread_alive == 0) { - phydev->state = WISPY_STATE_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; wispy1_usb_close(phydev); - return WISPY_POLL_ERROR; + return SPECTOOL_POLL_ERROR; } if ((ret = recv(auxptr->sockpair[0], lbuf, 8, 0)) < 0) { if (auxptr->usb_thread_alive != 0) - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb IPC receiver failed to read signal data: %s", strerror(errno)); - phydev->state = WISPY_STATE_ERROR; - return WISPY_POLL_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; + return SPECTOOL_POLL_ERROR; } if (time(0) - auxptr->last_read > 3) { - snprintf(phydev->errstr, WISPY_ERROR_MAX, + snprintf(phydev->errstr, SPECTOOL_ERROR_MAX, "wispy1_usb didn't see any data for more than 3 seconds, " "something has gone wrong (was the device removed?)"); - phydev->state = WISPY_STATE_ERROR; - return WISPY_POLL_ERROR; + phydev->state = SPECTOOL_STATE_ERROR; + return SPECTOOL_POLL_ERROR; } if (ret > 0) @@ -734,11 +734,11 @@ free(auxptr->calibrationbuf); auxptr->calibrationbuf = NULL; - phydev->state = WISPY_STATE_RUNNING; + phydev->state = SPECTOOL_STATE_RUNNING; } } else if (auxptr->sweepbuf_initialized == 0) { - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } for (x = 0; x < 7; x++) { @@ -774,9 +774,9 @@ auxptr->calibrated) { gettimeofday(&(auxptr->sweepbuf->tm_end), NULL); auxptr->sweepbuf->min_rssi_seen = phydev->min_rssi_seen; - return WISPY_POLL_SWEEPCOMPLETE; + return SPECTOOL_POLL_SWEEPCOMPLETE; } - return WISPY_POLL_NONE; + return SPECTOOL_POLL_NONE; } diff -Nru spectools-201004R1/wispy_hw_gen1.h spectools-201108r1/wispy_hw_gen1.h --- spectools-201004R1/wispy_hw_gen1.h 2007-08-22 23:26:45.000000000 +0000 +++ spectools-201108r1/wispy_hw_gen1.h 2011-06-10 15:53:29.000000000 +0000 @@ -23,12 +23,12 @@ char dev[64]; } wispy1_usb_pair; -int wispy1_usb_device_scan(wispy_device_list *list); +int wispy1_usb_device_scan(spectool_device_list *list); /* Wispy1 init function to build a phydev linked to a bus and device path * scanned */ -int wispy1_usb_init_path(wispy_phy *phydev, char *buspath, char *devpath); -int wispy1_usb_init(wispy_phy *phydev, wispy_device_rec *rec); +int wispy1_usb_init_path(spectool_phy *phydev, char *buspath, char *devpath); +int wispy1_usb_init(spectool_phy *phydev, spectool_device_rec *rec); #endif