]> sigrok.org Git - pulseview.git/commitdiff
Parse logic signals
authorJoel Holdsworth <redacted>
Tue, 5 Jun 2012 08:19:43 +0000 (09:19 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:59:04 +0000 (13:59 +0100)
logicsignal.cpp
logicsignal.h
signal.h
sigsession.cpp
sigsession.h
sigview.cpp
sigview.h

index 48a9570157c083b2c928b6a30b7abfffdf1c4d6e..7a86b7c6bfbd60ea26170823bfe43f7573fb13d3 100644 (file)
@@ -27,3 +27,13 @@ LogicSignal::LogicSignal(QString name, boost::shared_ptr<SignalData> data,
 {
        assert(_probe_index >= 0);
 }
+
+void LogicSignal::paint(QGLWidget &widget, const QRect &rect)
+{
+       glColor3f(1,0,0);
+       glBegin(GL_POLYGON);
+       glVertex2f(rect.left(), rect.top());
+       glVertex2f(rect.right(), rect.top());
+       glVertex2f(rect.right(), rect.bottom());
+       glEnd();
+}
index 9daf65005f3d35d4eaf6c71319a958877a1cf56b..91c70ab21a9d644bb0814d3601a44a2b0c9c6d4b 100644 (file)
@@ -30,6 +30,8 @@ public:
        LogicSignal(QString name, boost::shared_ptr<SignalData> data,
                int probe_index);
 
+       void paint(QGLWidget &widget, const QRect &rect);
+
 private:
        int _probe_index;
 };
index 47e1dc915b4e50b873b58b6540c748d105e87cff..ee051dca62d315ebe307ea1d51ce520c4a5858b5 100644 (file)
--- a/signal.h
+++ b/signal.h
  */
 
 #include <boost/shared_ptr.hpp>
+
+#include <QGLWidget>
+#include <QRect>
 #include <QString>
+
 #include <stdint.h>
 
 class SignalData;
@@ -32,6 +36,8 @@ protected:
 public:
        QString get_name() const;
 
+       virtual void paint(QGLWidget &widget, const QRect &rect) = 0;
+
 protected:
        QString _name;
        boost::shared_ptr<SignalData> _data;
index 9b9798e0577b65b4b64c0de854a82fb203426539..e6288e7c0cf64f4331ce1e8fcd160aec3f87c9ef 100644 (file)
 
 #include "logicdata.h"
 #include "logicdatasnapshot.h"
+#include "logicsignal.h"
 
 #include <QDebug>
 
 #include <assert.h>
 
 using namespace boost;
+using namespace std;
 
 // TODO: This should not be necessary
 SigSession* SigSession::session = NULL;
@@ -55,6 +57,11 @@ void SigSession::loadFile(const std::string &name)
        }
 }
 
+vector< shared_ptr<Signal> >& SigSession::get_signals()
+{
+       return _signals;
+}
+
 void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
        struct sr_datafeed_packet *packet)
 {
@@ -63,19 +70,38 @@ void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
 
        switch (packet->type) {
        case SR_DF_HEADER:
+               _signals.clear();
                break;
 
        case SR_DF_META_LOGIC:
                {
                        assert(packet->payload);
 
-                       _logic_data.reset(new LogicData(
-                               *(sr_datafeed_meta_logic*)packet->payload));
+                       const sr_datafeed_meta_logic &meta_logic =
+                               *(sr_datafeed_meta_logic*)packet->payload;
 
+                       // Create an empty LogiData for coming data snapshots
+                       _logic_data.reset(new LogicData(meta_logic));
                        assert(_logic_data);
                        if(!_logic_data)
                                break;
 
+                       // Add the signals
+                       for (int i = 0; i < meta_logic.num_probes; i++)
+                       {
+                               const sr_probe *const probe =
+                                       (const sr_probe*)g_slist_nth_data(
+                                               sdi->probes, i);
+                               if(probe->enabled)
+                               {
+                                       boost::shared_ptr<LogicSignal> signal(
+                                               new LogicSignal(probe->name,
+                                                       _logic_data,
+                                                       probe->index));
+                                       _signals.push_back(signal);
+                               }
+                       }
+
                        break;
                }
 
index f91a2b927c1d75c611ee03ef46652dc0c4dc6899..a08ba8129914ae0f61c6031d28b858a32cd0b1d0 100644 (file)
@@ -23,9 +23,8 @@
 
 #include <boost/shared_ptr.hpp>
 
-#include <list>
-#include <map>
 #include <string>
+#include <vector>
 
 #include <QObject>
 
@@ -48,6 +47,9 @@ public:
 
        void loadFile(const std::string &name);
 
+       std::vector< boost::shared_ptr<Signal> >&
+               get_signals();
+
 private:
        void dataFeedIn(const struct sr_dev_inst *sdi,
                struct sr_datafeed_packet *packet);
@@ -56,7 +58,7 @@ private:
                struct sr_datafeed_packet *packet);
 
 private:
-       std::list< boost::shared_ptr<Signal> > _signals;
+       std::vector< boost::shared_ptr<Signal> > _signals;
        boost::shared_ptr<LogicData> _logic_data;
        boost::shared_ptr<LogicDataSnapshot> _cur_logic_snapshot;
 
index b682cce950cd22ddff85f4b6df8860e7a025979e..565e67e2eb8a4d968c5fcf8d0be78727168797a3 100644 (file)
 #include "sigview.h"
 
 #include "sigsession.h"
+#include "signal.h"
+
+#include <boost/foreach.hpp>
+
+using namespace boost;
+using namespace std;
+
+const int SigView::SignalHeight = 50;
 
 SigView::SigView(SigSession &session, QWidget *parent) :
        QGLWidget(parent),
@@ -55,10 +63,20 @@ void SigView::resizeGL(int width, int height)
 void SigView::paintGL()
 {
        glClear(GL_COLOR_BUFFER_BIT);
+
+       QRect rect(0, 0, width(), SignalHeight);
+       const vector< shared_ptr<Signal> > &sigs =
+               _session.get_signals();
+       BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+       {
+               assert(s);
+               s->paint(*this, rect);
+               rect.translate(0, SignalHeight);
+       }
 }
 
 void SigView::dataUpdated()
 {
-       printf("Data Updated\n");
+       update();
 }
 
index 780d765ae5ecbfbc04f40b7a2a55adb3b631de49..b43ae9a55e5b0b49987f94b3fb756eed76f97ff8 100644 (file)
--- a/sigview.h
+++ b/sigview.h
@@ -29,6 +29,10 @@ class SigSession;
 class SigView : public QGLWidget
 {
        Q_OBJECT
+
+private:
+       static const int SignalHeight;
+
 public:
        explicit SigView(SigSession &session, QWidget *parent = 0);