From: Joel Holdsworth Date: Tue, 5 Jun 2012 07:49:17 +0000 (+0100) Subject: Push data into data model X-Git-Tag: pulseview-0.1.0~347 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f556bc6a4d1798e59f6d0276cdb0d55b5ffab476;p=pulseview.git Push data into data model --- diff --git a/datasnapshot.cpp b/datasnapshot.cpp index 1a637688..80d9ba43 100644 --- a/datasnapshot.cpp +++ b/datasnapshot.cpp @@ -20,12 +20,31 @@ #include "datasnapshot.h" -DataSnapshot::DataSnapshot() : - _sample_count(0) +#include +#include +#include + +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; } diff --git a/datasnapshot.h b/datasnapshot.h index 315e3561..f3bb3e21 100644 --- a/datasnapshot.h +++ b/datasnapshot.h @@ -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; }; diff --git a/logicdata.cpp b/logicdata.cpp index 04a6caa4..8fe32ed9 100644 --- a/logicdata.cpp +++ b/logicdata.cpp @@ -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 &snapshot) { diff --git a/logicdata.h b/logicdata.h index 6ba8679e..f835db5c 100644 --- a/logicdata.h +++ b/logicdata.h @@ -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 &snapshot); private: - int _num_probes; + const int _num_probes; }; diff --git a/logicdatasnapshot.cpp b/logicdatasnapshot.cpp index ac8d4d28..755c81df 100644 --- a/logicdatasnapshot.cpp +++ b/logicdatasnapshot.cpp @@ -20,11 +20,24 @@ #include "logicdatasnapshot.h" +#include + #include +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); } diff --git a/logicdatasnapshot.h b/logicdatasnapshot.h index 696b9e81..f321f6cf 100644 --- a/logicdatasnapshot.h +++ b/logicdatasnapshot.h @@ -23,6 +23,7 @@ class LogicDataSnapshot : public DataSnapshot { public: + LogicDataSnapshot(const sr_datafeed_logic &logic); void append_payload(const sr_datafeed_logic &logic); }; diff --git a/sigsession.cpp b/sigsession.cpp index 37c758f7..9b9798e0 100644 --- a/sigsession.cpp +++ b/sigsession.cpp @@ -76,21 +76,27 @@ void SigSession::dataFeedIn(const struct sr_dev_inst *sdi, if(!_logic_data) break; - // Add an empty data snapshot - shared_ptr 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( + 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: