]> sigrok.org Git - pulseview.git/commitdiff
Push data into data model
authorJoel Holdsworth <redacted>
Tue, 5 Jun 2012 07:49:17 +0000 (08:49 +0100)
committerJoel Holdsworth <redacted>
Mon, 3 Sep 2012 12:59:04 +0000 (13:59 +0100)
datasnapshot.cpp
datasnapshot.h
logicdata.cpp
logicdata.h
logicdatasnapshot.cpp
logicdatasnapshot.h
sigsession.cpp

index 1a6376882286760b36a9be7acb8827312ef74a3e..80d9ba4318f53f83e8d89604d658870d677e4b69 100644 (file)
 
 #include "datasnapshot.h"
 
-DataSnapshot::DataSnapshot() :
-       _sample_count(0)
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+DataSnapshot::DataSnapshot(int unit_size) :
+       _data(NULL),
+       _data_length(0),
+       _unit_size(unit_size)
+{
+       assert(_unit_size > 0);
+}
+
+DataSnapshot::~DataSnapshot()
 {
+       free(_data);
 }
 
 uint64_t DataSnapshot::get_sample_count()
 {
-       return _sample_count;
+       return _data_length / _unit_size;
+}
+
+void DataSnapshot::append_data(void *data, uint64_t length)
+{
+       _data = realloc(_data, _data_length + length);
+       memcpy((uint8_t*)_data + _data_length, data, length);
+       _data_length += length;
 }
index 315e3561562932e39e2ceedec6d53bfb68525065..f3bb3e2136475f3ba591306fb02b7d9704c24321 100644 (file)
@@ -25,10 +25,17 @@ extern "C" {
 class DataSnapshot
 {
 public:
-       DataSnapshot();
+       DataSnapshot(int unit_size);
+
+       virtual ~DataSnapshot();
 
        uint64_t get_sample_count();
 
 protected:
-       uint64_t _sample_count;
+       void append_data(void *data, uint64_t length);
+
+protected:
+       void *_data;
+       uint64_t _data_length;
+       int _unit_size;
 };
index 04a6caa45d2da38d868dbf23e774c298e8c722b8..8fe32ed92fe6c01d701c50efce7020d0b380771e 100644 (file)
@@ -29,6 +29,11 @@ LogicData::LogicData(const sr_datafeed_meta_logic &meta) :
 {
 }
 
+int LogicData::get_num_probes() const
+{
+       return _num_probes;
+}
+
 void LogicData::push_snapshot(
        boost::shared_ptr<LogicDataSnapshot> &snapshot)
 {
index 6ba8679e34c4610dea9543b4725cdb4f3bc9d86b..f835db5ca9f8f9786b93491b11731090fb256dde 100644 (file)
@@ -31,9 +31,11 @@ class LogicData : public SignalData
 public:
        LogicData(const sr_datafeed_meta_logic &meta);
 
+       int get_num_probes() const;
+
        void push_snapshot(
                boost::shared_ptr<LogicDataSnapshot> &snapshot);
 
 private:
-       int _num_probes;
+       const int _num_probes;
 };
index ac8d4d28adc7094a733bfa2f81802f1e193348af..755c81dfb793dfed36a0d14ce13fc20b211dec85 100644 (file)
 
 #include "logicdatasnapshot.h"
 
+#include <assert.h>
+
 #include <QDebug>
 
+LogicDataSnapshot::LogicDataSnapshot(
+       const sr_datafeed_logic &logic) :
+       DataSnapshot(logic.unitsize)
+{
+       append_payload(logic);
+}
+
 void LogicDataSnapshot::append_payload(
        const sr_datafeed_logic &logic)
 {
+       assert(_unit_size == logic.unitsize);
+
        qDebug() << "SR_DF_LOGIC (length =" << logic.length
                << ", unitsize = " << logic.unitsize << ")";
+
+       append_data(logic.data, logic.length);
 }
index 696b9e815eba28275cb5de4b3e8dc04b3d9cd4b3..f321f6cf6e031904e185c5be4b9f89630d41484b 100644 (file)
@@ -23,6 +23,7 @@
 class LogicDataSnapshot : public DataSnapshot
 {
 public:
+       LogicDataSnapshot(const sr_datafeed_logic &logic);
 
        void append_payload(const sr_datafeed_logic &logic);
 };
index 37c758f776e098d86023bb07c123874ad53b2972..9b9798e0577b65b4b64c0de854a82fb203426539 100644 (file)
@@ -76,21 +76,27 @@ void SigSession::dataFeedIn(const struct sr_dev_inst *sdi,
                        if(!_logic_data)
                                break;
 
-                       // Add an empty data snapshot
-                       shared_ptr<LogicDataSnapshot> snapshot(
-                               new LogicDataSnapshot());
-                       _logic_data->push_snapshot(snapshot);
-                       _cur_logic_snapshot = snapshot;
-
                        break;
                }
 
        case SR_DF_LOGIC:
+
                assert(packet->payload);
-               assert(_cur_logic_snapshot);
-               if(_cur_logic_snapshot)
+               if(!_cur_logic_snapshot)
+               {
+                       // Create a new data snapshot
+                       _cur_logic_snapshot = shared_ptr<LogicDataSnapshot>(
+                               new LogicDataSnapshot(
+                               *(sr_datafeed_logic*)packet->payload));
+                       _logic_data->push_snapshot(_cur_logic_snapshot);
+               }
+               else
+               {
+                       // Append to the existing data snapshot
                        _cur_logic_snapshot->append_payload(
                                *(sr_datafeed_logic*)packet->payload);
+               }
+
                break;
 
        case SR_DF_END: