From: Joel Holdsworth Date: Sun, 2 Sep 2012 12:33:14 +0000 (+0100) Subject: Fleshed out data model X-Git-Tag: pulseview-0.1.0~349 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=28a4c9c5eb20296199fc3496bb40b7733dffac75;hp=fc645aa3338e70a1fe3428421037d6a936576464 Fleshed out data model --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d6c7f8f5..4644dc83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,9 +16,15 @@ set(VERSION 0.1.0) set(sigrok-qt2_SOURCES about.cpp + datasnapshot.cpp + logicdata.cpp + logicdatasnapshot.cpp + logicsignal.cpp main.cpp mainwindow.cpp + signaldata.cpp sigsession.cpp + signal.cpp sigview.cpp ) diff --git a/datasnapshot.cpp b/datasnapshot.cpp new file mode 100644 index 00000000..1a637688 --- /dev/null +++ b/datasnapshot.cpp @@ -0,0 +1,31 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 index 00000000..315e3561 --- /dev/null +++ b/datasnapshot.h @@ -0,0 +1,34 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 +} + +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 index 00000000..04a6caa4 --- /dev/null +++ b/logicdata.cpp @@ -0,0 +1,36 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 &snapshot) +{ + _snapshots.push(snapshot); +} diff --git a/logicdata.h b/logicdata.h new file mode 100644 index 00000000..6ba8679e --- /dev/null +++ b/logicdata.h @@ -0,0 +1,39 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 +} + +class LogicDataSnapshot; + +class LogicData : public SignalData +{ +public: + LogicData(const sr_datafeed_meta_logic &meta); + + void push_snapshot( + boost::shared_ptr &snapshot); + +private: + int _num_probes; +}; diff --git a/logicdatasnapshot.cpp b/logicdatasnapshot.cpp new file mode 100644 index 00000000..ac8d4d28 --- /dev/null +++ b/logicdatasnapshot.cpp @@ -0,0 +1,30 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 + +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 index 00000000..696b9e81 --- /dev/null +++ b/logicdatasnapshot.h @@ -0,0 +1,28 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 index 00000000..48a95701 --- /dev/null +++ b/logicsignal.cpp @@ -0,0 +1,29 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 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 index 00000000..9daf6500 --- /dev/null +++ b/logicsignal.h @@ -0,0 +1,35 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 + +class LogicData; + +class LogicSignal : public Signal +{ +public: + LogicSignal(QString name, boost::shared_ptr data, + int probe_index); + +private: + int _probe_index; +}; diff --git a/signal.cpp b/signal.cpp new file mode 100644 index 00000000..476a5a25 --- /dev/null +++ b/signal.cpp @@ -0,0 +1,34 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 + +Signal::Signal(QString name, boost::shared_ptr data) : + _name(name), + _data(data) +{ +} + +QString Signal::get_name() const +{ + return _name; +} diff --git a/signal.h b/signal.h new file mode 100644 index 00000000..47e1dc91 --- /dev/null +++ b/signal.h @@ -0,0 +1,38 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 +#include +#include + +class SignalData; + +class Signal +{ +protected: + Signal(QString name, boost::shared_ptr data); + +public: + QString get_name() const; + +protected: + QString _name; + boost::shared_ptr _data; +}; diff --git a/signaldata.cpp b/signaldata.cpp new file mode 100644 index 00000000..8588e5da --- /dev/null +++ b/signaldata.cpp @@ -0,0 +1,26 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 index 00000000..74d1facd --- /dev/null +++ b/signaldata.h @@ -0,0 +1,36 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * 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 +#include +#include + +class DataSnapshot; + +class SignalData +{ +public: + SignalData(uint64_t samplerate); + +protected: + const uint64_t _samplerate; + + std::queue< boost::shared_ptr > _snapshots; +}; diff --git a/sigsession.cpp b/sigsession.cpp index e8d129fc..37c758f7 100644 --- a/sigsession.cpp +++ b/sigsession.cpp @@ -20,16 +20,19 @@ #include "sigsession.h" +#include "logicdata.h" +#include "logicdatasnapshot.h" + #include #include +using namespace boost; + // 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; @@ -37,8 +40,6 @@ SigSession::SigSession() : SigSession::~SigSession() { - g_array_free(sigData, TRUE); - // 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) { - 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; - 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 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: + _cur_logic_snapshot.reset(); dataUpdated(); break; } diff --git a/sigsession.h b/sigsession.h index 92c048bd..f91a2b92 100644 --- a/sigsession.h +++ b/sigsession.h @@ -21,13 +21,21 @@ #ifndef SIGSESSION_H #define SIGSESSION_H +#include + +#include +#include +#include + #include extern "C" { #include } -#include +class LogicData; +class LogicDataSnapshot; +class Signal; class SigSession : public QObject { @@ -48,9 +56,9 @@ private: struct sr_datafeed_packet *packet); private: - int unitSize; - int probeList[SR_MAX_NUM_PROBES + 1]; - GArray *sigData; + std::list< boost::shared_ptr > _signals; + boost::shared_ptr _logic_data; + boost::shared_ptr _cur_logic_snapshot; signals: void dataUpdated();