From 009e1503d46291cbc33cdb900761eaa505fd6269 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 26 May 2012 14:43:58 +0100 Subject: [PATCH] Implemented initial data model --- mainwindow.cpp | 4 ++++ mainwindow.h | 3 +++ mainwindow.ui | 10 ---------- sigsession.cpp | 36 +++++++++++++++++++++++++++++++++++- sigsession.h | 11 ++++++++++- sigview.cpp | 16 ++++++++++++++-- sigview.h | 13 ++++++++----- 7 files changed, 74 insertions(+), 19 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index d85c0a40..10ef3013 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -28,6 +28,7 @@ extern "C" { #include "mainwindow.h" #include "ui_mainwindow.h" +#include "sigview.h" extern "C" { /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ @@ -44,6 +45,9 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + + view = new SigView(session, this); + ui->verticalLayout->addWidget(view); } MainWindow::~MainWindow() diff --git a/mainwindow.h b/mainwindow.h index 34fb1b92..1ba4c8e9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -25,6 +25,8 @@ #include "sigsession.h" +class SigView; + namespace Ui { class MainWindow; } @@ -40,6 +42,7 @@ public: private: Ui::MainWindow *ui; SigSession session; + SigView *view; private slots: diff --git a/mainwindow.ui b/mainwindow.ui index 5cf32c6d..1e17f115 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -46,9 +46,6 @@ 0 - - - @@ -64,13 +61,6 @@ - - - SigView - QGLWidget -
sigview.h
-
-
diff --git a/sigsession.cpp b/sigsession.cpp index 2df6a151..e8d129fc 100644 --- a/sigsession.cpp +++ b/sigsession.cpp @@ -20,12 +20,16 @@ #include "sigsession.h" +#include + #include // TODO: This should not be necessary SigSession* SigSession::session = NULL; -SigSession::SigSession() +SigSession::SigSession() : + unitSize(0), + sigData(NULL) { // TODO: This should not be necessary session = this; @@ -33,6 +37,8 @@ SigSession::SigSession() SigSession::~SigSession() { + g_array_free(sigData, TRUE); + // TODO: This should not be necessary session = NULL; } @@ -68,10 +74,38 @@ void SigSession::dataFeedIn(const struct sr_dev_inst *sdi, probeList[num_enabled_probes++] = probe->index; } } + + /* How many bytes we need to store num_enabled_probes bits */ + unitSize = (num_enabled_probes + 7) / 8; + sigData = g_array_new(FALSE, FALSE, unitSize); + } + break; + + case SR_DF_LOGIC: + { + uint64_t filter_out_len; + uint8_t *filter_out; + + const struct sr_datafeed_logic *const logic = + (sr_datafeed_logic*)packet->payload; + + qDebug() << "SR_DF_LOGIC (length =" << logic->length + << ", unitsize = " << logic->unitsize << ")"; + + if (sr_filter_probes(logic->unitsize, unitSize, + probeList, (uint8_t*)logic->data, logic->length, + &filter_out, &filter_out_len) != SR_OK) + return; + + assert(sigData); + g_array_append_vals(sigData, filter_out, filter_out_len / unitSize); + + g_free(filter_out); } break; case SR_DF_END: + dataUpdated(); break; } } diff --git a/sigsession.h b/sigsession.h index 47f37a10..92c048bd 100644 --- a/sigsession.h +++ b/sigsession.h @@ -21,14 +21,18 @@ #ifndef SIGSESSION_H #define SIGSESSION_H +#include + extern "C" { #include } #include -class SigSession +class SigSession : public QObject { + Q_OBJECT + public: SigSession(); @@ -44,7 +48,12 @@ private: struct sr_datafeed_packet *packet); private: + int unitSize; int probeList[SR_MAX_NUM_PROBES + 1]; + GArray *sigData; + +signals: + void dataUpdated(); private: // TODO: This should not be necessary. Multiple concurrent diff --git a/sigview.cpp b/sigview.cpp index c83ea791..b682cce9 100644 --- a/sigview.cpp +++ b/sigview.cpp @@ -20,9 +20,15 @@ #include "sigview.h" -SigView::SigView(QWidget *parent) : - QGLWidget(parent) +#include "sigsession.h" + +SigView::SigView(SigSession &session, QWidget *parent) : + QGLWidget(parent), + _session(session) { + connect(&_session, SIGNAL(dataUpdated()), + this, SLOT(dataUpdated())); + setMouseTracking(true); } @@ -50,3 +56,9 @@ void SigView::paintGL() { glClear(GL_COLOR_BUFFER_BIT); } + +void SigView::dataUpdated() +{ + printf("Data Updated\n"); +} + diff --git a/sigview.h b/sigview.h index d2bdbe4d..780d765a 100644 --- a/sigview.h +++ b/sigview.h @@ -24,11 +24,13 @@ #include #include +class SigSession; + class SigView : public QGLWidget { Q_OBJECT public: - explicit SigView(QWidget *parent = 0); + explicit SigView(SigSession &session, QWidget *parent = 0); protected: @@ -38,10 +40,11 @@ protected: void paintGL(); -signals: - -public slots: - +private slots: + void dataUpdated(); + +private: + SigSession &_session; }; #endif // SIGVIEW_H -- 2.30.2