svn commit: r237468 - user/adrian/ath_radar_stuff/src/qt-hpktlog
Adrian Chadd
adrian at FreeBSD.org
Sat Jun 23 04:47:42 UTC 2012
Author: adrian
Date: Sat Jun 23 04:47:41 2012
New Revision: 237468
URL: http://svn.freebsd.org/changeset/base/237468
Log:
* Migrate the pcap code to loop over the pcap if in live mode, rather than
handling one every 2ms.
* Move to using the QwtPlotSpectroCurve, which is an example (but does what
I want, thankfully!) 3d plotting widget, which implements 'color' as the
z dimension.
* For now, just use RSSI as the z dimension. Eventually this should be
the "density" rather than RSSI..
Modified:
user/adrian/ath_radar_stuff/src/qt-hpktlog/MainApp.cpp
user/adrian/ath_radar_stuff/src/qt-hpktlog/MainApp.h
user/adrian/ath_radar_stuff/src/qt-hpktlog/PktSource.cpp
user/adrian/ath_radar_stuff/src/qt-hpktlog/PktSource.h
Modified: user/adrian/ath_radar_stuff/src/qt-hpktlog/MainApp.cpp
==============================================================================
--- user/adrian/ath_radar_stuff/src/qt-hpktlog/MainApp.cpp Sat Jun 23 02:08:15 2012 (r237467)
+++ user/adrian/ath_radar_stuff/src/qt-hpktlog/MainApp.cpp Sat Jun 23 04:47:41 2012 (r237468)
@@ -5,6 +5,7 @@
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
+#include "qwt_plot_spectrocurve.h"
#include "qwt_plot_histogram.h"
#include "qwt_symbol.h"
@@ -35,9 +36,10 @@ MainApp::MainApp(QMainWindow *parent)
q_symbol->setSize(2, 2);
// And now, the default curve
- q_curve = new QwtPlotCurve("curve");
- q_curve->setStyle(QwtPlotCurve::Dots);
- q_curve->setSymbol(q_symbol);
+ q_curve = new QwtPlotSpectroCurve("curve");
+ //q_curve->setStyle(QwtPlotCurve::Dots);
+ //q_curve->setSymbol(q_symbol);
+ q_curve->setPenWidth(4);
q_curve->attach(q_plot);
q_plot->show();
@@ -46,7 +48,13 @@ MainApp::MainApp(QMainWindow *parent)
MainApp::~MainApp()
{
- /* XXX TIDYUP */
+ /* XXX correct order? */
+ if (q_symbol)
+ delete q_symbol;
+ if (q_curve)
+ delete q_curve;
+ if (q_plot)
+ delete q_plot;
}
//
@@ -65,13 +73,19 @@ MainApp::getRadarEntry(struct radar_entr
q_dur.insert(q_dur.begin(), (float) re.re_dur);
q_rssi.insert(q_rssi.begin(), (float) re.re_rssi);
+ q_points.insert(q_points.begin(),
+ QwtPoint3D(
+ (float) re.re_dur,
+ (float) re.re_rssi,
+ (float) re.re_rssi * 25.0));
+
// If we're too big, delete the first entry
- if (q_dur.size() > num_entries) {
+ if (q_points.size() > num_entries) {
q_dur.pop_back();
q_rssi.pop_back();
+ q_points.pop_back();
}
-
// Trim the head entries if the array is too big
// (maybe we should use a queue, not a vector?)
@@ -83,7 +97,7 @@ void
MainApp::RePlot()
{
// Plot them
- q_curve->setSamples(&q_dur[0], &q_rssi[0], q_dur.size());
+ q_curve->setSamples(q_points);
/* Plot */
q_plot->replot();
Modified: user/adrian/ath_radar_stuff/src/qt-hpktlog/MainApp.h
==============================================================================
--- user/adrian/ath_radar_stuff/src/qt-hpktlog/MainApp.h Sat Jun 23 02:08:15 2012 (r237467)
+++ user/adrian/ath_radar_stuff/src/qt-hpktlog/MainApp.h Sat Jun 23 04:47:41 2012 (r237468)
@@ -7,11 +7,14 @@
#include <QtCore/QObject>
#include <QtGui/QMainWindow>
+#include <QtCore/QVector>
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
+#include "qwt_plot_spectrocurve.h"
#include "qwt_plot_histogram.h"
#include "qwt_symbol.h"
+#include "qwt_point_3d.h"
#include "libradarpkt/pkt.h"
@@ -23,7 +26,7 @@ class MainApp : public QMainWindow
// Why can't we just use references, rather than
// pointers?
QwtPlot *q_plot;
- QwtPlotCurve *q_curve;
+ QwtPlotSpectroCurve *q_curve;
QwtSymbol *q_symbol;
// How many entries to keep in the histogram
@@ -32,6 +35,7 @@ class MainApp : public QMainWindow
// Our histogram data
std::vector<double> q_dur;
std::vector<double> q_rssi;
+ QVector<QwtPoint3D> q_points;
// TODO When rendering the screen, we only want to do it
// every say, 3ms.
Modified: user/adrian/ath_radar_stuff/src/qt-hpktlog/PktSource.cpp
==============================================================================
--- user/adrian/ath_radar_stuff/src/qt-hpktlog/PktSource.cpp Sat Jun 23 02:08:15 2012 (r237467)
+++ user/adrian/ath_radar_stuff/src/qt-hpktlog/PktSource.cpp Sat Jun 23 04:47:41 2012 (r237468)
@@ -41,6 +41,8 @@ PktSource::Load(const char *filename)
//Kick-start the first timer!
timerId = startTimer(1);
+ isLive = false;
+
return (true);
}
@@ -96,6 +98,7 @@ PktSource::OpenLive(const char *ifname)
//Kick-start the first timer!
timerId = startTimer(2);
+ isLive = true;
return (true);
@@ -127,64 +130,62 @@ PktSource::timerEvent(QTimerEvent *event
// printf("%s: timer event!\n", __func__);
- r = pcap_next_ex(PcapHdl, &hdr, &pkt);
+ while (1) {
+ r = pcap_next_ex(PcapHdl, &hdr, &pkt);
- // Error? Delete the timer.
- if (r < 0) {
- killTimer(timerId);
- timerId = -1;
- printf("%s: final event (r=%d), finish timer!\n",
- __func__,
- r);
- this->Close();
- return;
+ // Error? Delete the timer.
+ if (r < 0) {
+ killTimer(timerId);
+ timerId = -1;
+ printf("%s: final event (r=%d), finish timer!\n",
+ __func__,
+ r);
+ this->Close();
+ return;
+ }
+
+ // Nothing available? Just skip until the next
+ // check.
+ if (r == 0)
+ break;
+
+ rt = (struct ieee80211_radiotap_header *) pkt;
+ if (rt->it_version != 0) {
+ printf("%s: unknown version (%d)\n",
+ __func__,
+ rt->it_version);
+ break;
+ }
+
+ // TODO: just assume AR5416 for now..
+ switch (chipid) {
+ case CHIP_AR5416:
+ r = ar5416_radar_decode(rt,
+ (pkt + le16toh(rt->it_len)),
+ hdr->caplen - le16toh(rt->it_len), &re);
+ break;
+ case CHIP_AR9280:
+ r = ar9280_radar_decode(rt,
+ (pkt + le16toh(rt->it_len)),
+ hdr->caplen - le16toh(rt->it_len), &re);
+ break;
+ default:
+ printf("%s: unknown chip id? (%d)\n",
+ __func__,
+ chipid);
+ }
+
+ // Error? Skip to the next one.
+ if (r <= 0) {
+ printf("%s: parse failed\n", __func__);
+ } else {
+ // The actual event may be delayed; so i either have
+ // to pass a reference (not pointer), _or_ a copy.
+ emit emitRadarEntry(re);
+ }
+
+ // Break out of the loop if we're not live
+ if (! isLive)
+ break;
}
-
- // Nothing available? Just skip
- if (r == 0) {
- return;
- }
-
- rt = (struct ieee80211_radiotap_header *) pkt;
- if (rt->it_version != 0) {
- printf("%s: unknown version (%d)\n",
- __func__,
- rt->it_version);
- return;
- }
-
- // TODO: just assume AR5416 for now..
- switch (chipid) {
- case CHIP_AR5416:
- r = ar5416_radar_decode(rt,
- (pkt + le16toh(rt->it_len)),
- hdr->caplen - le16toh(rt->it_len), &re);
- break;
- case CHIP_AR9280:
- r = ar9280_radar_decode(rt,
- (pkt + le16toh(rt->it_len)),
- hdr->caplen - le16toh(rt->it_len), &re);
- break;
- default:
- printf("%s: unknown chip id? (%d)\n",
- __func__,
- chipid);
- }
- // Error? Just wait for the next one?
- if (r == 0) {
- printf("%s: parse failed\n", __func__);
- return;
- }
-
-#if 0
- printf("%s: parsed: tsf=%llu, rssi=%d, dur=%d\n",
- __func__,
- (unsigned long long) re.re_timestamp,
- re.re_rssi,
- re.re_dur);
-#endif
-
- // The actual event may be delayed; so i either have
- // to pass a reference (not pointer), _or_ a copy.
- emit emitRadarEntry(re);
}
Modified: user/adrian/ath_radar_stuff/src/qt-hpktlog/PktSource.h
==============================================================================
--- user/adrian/ath_radar_stuff/src/qt-hpktlog/PktSource.h Sat Jun 23 02:08:15 2012 (r237467)
+++ user/adrian/ath_radar_stuff/src/qt-hpktlog/PktSource.h Sat Jun 23 04:47:41 2012 (r237468)
@@ -27,9 +27,12 @@ class PktSource : public QObject {
pcap_t *PcapHdl;
int timerId;
int chipid;
+ bool isLive;
public:
- PktSource() : PcapHdl(NULL), timerId(-1), chipid(0) { };
+ PktSource() : PcapHdl(NULL), timerId(-1), chipid(0),
+ isLive(false) { };
+
~PktSource();
void SetChipId(int chip_id) { chipid = chip_id; };
int GetChipId() { return (chipid); };
More information about the svn-src-user
mailing list