]> sigrok.org Git - pulseview.git/commitdiff
Fleshed out data model
authorJoel Holdsworth <redacted>
Sun, 2 Sep 2012 12:33:14 +0000 (13:33 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:49:39 +0000 (13:49 +0100)
15 files changed:
CMakeLists.txt
datasnapshot.cpp [new file with mode: 0644]
datasnapshot.h [new file with mode: 0644]
logicdata.cpp [new file with mode: 0644]
logicdata.h [new file with mode: 0644]
logicdatasnapshot.cpp [new file with mode: 0644]
logicdatasnapshot.h [new file with mode: 0644]
logicsignal.cpp [new file with mode: 0644]
logicsignal.h [new file with mode: 0644]
signal.cpp [new file with mode: 0644]
signal.h [new file with mode: 0644]
signaldata.cpp [new file with mode: 0644]
signaldata.h [new file with mode: 0644]
sigsession.cpp
sigsession.h

index d6c7f8f56d30d40e3314cc45a52a3e224ccf7211..4644dc8355471cef2136d62eb80865884762e7c4 100644 (file)
@@ -16,9 +16,15 @@ set(VERSION 0.1.0)
 
 set(sigrok-qt2_SOURCES
        about.cpp
 
 set(sigrok-qt2_SOURCES
        about.cpp
+       datasnapshot.cpp
+       logicdata.cpp
+       logicdatasnapshot.cpp
+       logicsignal.cpp
        main.cpp
        mainwindow.cpp
        main.cpp
        mainwindow.cpp
+       signaldata.cpp
        sigsession.cpp
        sigsession.cpp
+       signal.cpp
        sigview.cpp
 )
 
        sigview.cpp
 )
 
diff --git a/datasnapshot.cpp b/datasnapshot.cpp
new file mode 100644 (file)
index 0000000..1a63768
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "datasnapshot.h"
+
+DataSnapshot::DataSnapshot() :
+       _sample_count(0)
+{
+}
+
+uint64_t DataSnapshot::get_sample_count()
+{
+       return _sample_count;
+}
diff --git a/datasnapshot.h b/datasnapshot.h
new file mode 100644 (file)
index 0000000..315e356
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+extern "C" {
+#include <libsigrok/libsigrok.h>
+}
+
+class DataSnapshot
+{
+public:
+       DataSnapshot();
+
+       uint64_t get_sample_count();
+
+protected:
+       uint64_t _sample_count;
+};
diff --git a/logicdata.cpp b/logicdata.cpp
new file mode 100644 (file)
index 0000000..04a6caa
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "logicdata.h"
+#include "logicdatasnapshot.h"
+
+using namespace boost;
+
+LogicData::LogicData(const sr_datafeed_meta_logic &meta) :
+       SignalData(meta.samplerate),
+       _num_probes(meta.num_probes)
+{
+}
+
+void LogicData::push_snapshot(
+       boost::shared_ptr<LogicDataSnapshot> &snapshot)
+{
+       _snapshots.push(snapshot);
+}
diff --git a/logicdata.h b/logicdata.h
new file mode 100644 (file)
index 0000000..6ba8679
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "signaldata.h"
+
+extern "C" {
+#include <libsigrok/libsigrok.h>
+}
+
+class LogicDataSnapshot;
+
+class LogicData : public SignalData
+{
+public:
+       LogicData(const sr_datafeed_meta_logic &meta);
+
+       void push_snapshot(
+               boost::shared_ptr<LogicDataSnapshot> &snapshot);
+
+private:
+       int _num_probes;
+};
diff --git a/logicdatasnapshot.cpp b/logicdatasnapshot.cpp
new file mode 100644 (file)
index 0000000..ac8d4d2
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "logicdatasnapshot.h"
+
+#include <QDebug>
+
+void LogicDataSnapshot::append_payload(
+       const sr_datafeed_logic &logic)
+{
+       qDebug() << "SR_DF_LOGIC (length =" << logic.length
+               << ", unitsize = " << logic.unitsize << ")";
+}
diff --git a/logicdatasnapshot.h b/logicdatasnapshot.h
new file mode 100644 (file)
index 0000000..696b9e8
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "datasnapshot.h"
+
+class LogicDataSnapshot : public DataSnapshot
+{
+public:
+
+       void append_payload(const sr_datafeed_logic &logic);
+};
diff --git a/logicsignal.cpp b/logicsignal.cpp
new file mode 100644 (file)
index 0000000..48a9570
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "logicsignal.h"
+
+LogicSignal::LogicSignal(QString name, boost::shared_ptr<SignalData> data,
+       int probe_index) :
+       Signal(name, data),
+       _probe_index(probe_index)
+{
+       assert(_probe_index >= 0);
+}
diff --git a/logicsignal.h b/logicsignal.h
new file mode 100644 (file)
index 0000000..9daf650
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "signal.h"
+
+#include <boost/shared_ptr.hpp>
+
+class LogicData;
+
+class LogicSignal : public Signal
+{
+public:
+       LogicSignal(QString name, boost::shared_ptr<SignalData> data,
+               int probe_index);
+
+private:
+       int _probe_index;
+};
diff --git a/signal.cpp b/signal.cpp
new file mode 100644 (file)
index 0000000..476a5a2
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "signal.h"
+
+#include <memory.h>
+
+Signal::Signal(QString name, boost::shared_ptr<SignalData> data) :
+       _name(name),
+       _data(data)
+{
+}
+
+QString Signal::get_name() const
+{
+       return _name;
+}
diff --git a/signal.h b/signal.h
new file mode 100644 (file)
index 0000000..47e1dc9
--- /dev/null
+++ b/signal.h
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <boost/shared_ptr.hpp>
+#include <QString>
+#include <stdint.h>
+
+class SignalData;
+
+class Signal
+{
+protected:
+       Signal(QString name, boost::shared_ptr<SignalData> data);
+
+public:
+       QString get_name() const;
+
+protected:
+       QString _name;
+       boost::shared_ptr<SignalData> _data;
+};
diff --git a/signaldata.cpp b/signaldata.cpp
new file mode 100644 (file)
index 0000000..8588e5d
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include "signaldata.h"
+
+SignalData::SignalData(uint64_t samplerate) :
+       _samplerate(samplerate)
+{
+}
diff --git a/signaldata.h b/signaldata.h
new file mode 100644 (file)
index 0000000..74d1fac
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <boost/shared_ptr.hpp>
+#include <queue>
+#include <stdint.h>
+
+class DataSnapshot;
+
+class SignalData
+{
+public:
+       SignalData(uint64_t samplerate);
+
+protected:
+       const uint64_t _samplerate;
+
+       std::queue< boost::shared_ptr<DataSnapshot> > _snapshots;
+};
index e8d129fcdcc6f7f2cdd3d85455d3bcd352988b52..37c758f776e098d86023bb07c123874ad53b2972 100644 (file)
 
 #include "sigsession.h"
 
 
 #include "sigsession.h"
 
+#include "logicdata.h"
+#include "logicdatasnapshot.h"
+
 #include <QDebug>
 
 #include <assert.h>
 
 #include <QDebug>
 
 #include <assert.h>
 
+using namespace boost;
+
 // TODO: This should not be necessary
 SigSession* SigSession::session = NULL;
 
 // TODO: This should not be necessary
 SigSession* SigSession::session = NULL;
 
-SigSession::SigSession() :
-       unitSize(0),
-       sigData(NULL)
+SigSession::SigSession()
 {
        // TODO: This should not be necessary
        session = this;
 {
        // TODO: This should not be necessary
        session = this;
@@ -37,8 +40,6 @@ SigSession::SigSession() :
 
 SigSession::~SigSession()
 {
 
 SigSession::~SigSession()
 {
-       g_array_free(sigData, TRUE);
-
        // TODO: This should not be necessary
        session = NULL;
 }
        // TODO: This should not be necessary
        session = NULL;
 }
@@ -61,50 +62,39 @@ void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
        assert(packet);
 
        switch (packet->type) {
        assert(packet);
 
        switch (packet->type) {
-       case SR_DF_META_LOGIC:
-               {
-                       const sr_datafeed_meta_logic *meta_logic =
-                               (sr_datafeed_meta_logic*)packet->payload;
-                       int num_enabled_probes = 0;
-
-                       for (int i = 0; i < meta_logic->num_probes; i++) {
-                               const sr_probe *probe =
-                                       (sr_probe *)g_slist_nth_data(sdi->probes, i);
-                               if (probe->enabled) {
-                                       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);
-               }
+       case SR_DF_HEADER:
                break;
 
                break;
 
-       case SR_DF_LOGIC:
+       case SR_DF_META_LOGIC:
                {
                {
-                       uint64_t filter_out_len;
-                       uint8_t *filter_out;
-
-                       const struct sr_datafeed_logic *const logic =
-                               (sr_datafeed_logic*)packet->payload;
+                       assert(packet->payload);
 
 
-                       qDebug() << "SR_DF_LOGIC (length =" << logic->length
-                               << ", unitsize = " << logic->unitsize << ")";
+                       _logic_data.reset(new LogicData(
+                               *(sr_datafeed_meta_logic*)packet->payload));
 
 
-                       if (sr_filter_probes(logic->unitsize, unitSize,
-                               probeList, (uint8_t*)logic->data, logic->length,
-                               &filter_out, &filter_out_len) != SR_OK)
-                               return;
+                       assert(_logic_data);
+                       if(!_logic_data)
+                               break;
 
 
-                       assert(sigData);
-                       g_array_append_vals(sigData, filter_out, filter_out_len / unitSize);
+                       // Add an empty data snapshot
+                       shared_ptr<LogicDataSnapshot> snapshot(
+                               new LogicDataSnapshot());
+                       _logic_data->push_snapshot(snapshot);
+                       _cur_logic_snapshot = snapshot;
 
 
-                       g_free(filter_out);
+                       break;
                }
                }
+
+       case SR_DF_LOGIC:
+               assert(packet->payload);
+               assert(_cur_logic_snapshot);
+               if(_cur_logic_snapshot)
+                       _cur_logic_snapshot->append_payload(
+                               *(sr_datafeed_logic*)packet->payload);
                break;
 
        case SR_DF_END:
                break;
 
        case SR_DF_END:
+               _cur_logic_snapshot.reset();
                dataUpdated();
                break;
        }
                dataUpdated();
                break;
        }
index 92c048bddc1bcf5e25d357d204f312f4fda17919..f91a2b927c1d75c611ee03ef46652dc0c4dc6899 100644 (file)
 #ifndef SIGSESSION_H
 #define SIGSESSION_H
 
 #ifndef SIGSESSION_H
 #define SIGSESSION_H
 
+#include <boost/shared_ptr.hpp>
+
+#include <list>
+#include <map>
+#include <string>
+
 #include <QObject>
 
 extern "C" {
 #include <libsigrok/libsigrok.h>
 }
 
 #include <QObject>
 
 extern "C" {
 #include <libsigrok/libsigrok.h>
 }
 
-#include <string>
+class LogicData;
+class LogicDataSnapshot;
+class Signal;
 
 class SigSession : public QObject
 {
 
 class SigSession : public QObject
 {
@@ -48,9 +56,9 @@ private:
                struct sr_datafeed_packet *packet);
 
 private:
                struct sr_datafeed_packet *packet);
 
 private:
-       int unitSize;
-       int probeList[SR_MAX_NUM_PROBES + 1];
-       GArray *sigData;
+       std::list< boost::shared_ptr<Signal> > _signals;
+       boost::shared_ptr<LogicData> _logic_data;
+       boost::shared_ptr<LogicDataSnapshot> _cur_logic_snapshot;
 
 signals:
        void dataUpdated();
 
 signals:
        void dataUpdated();