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
)
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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;
+};
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+};
--- /dev/null
+/*
+ * 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 << ")";
+}
--- /dev/null
+/*
+ * 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);
+};
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+};
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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;
+};
--- /dev/null
+/*
+ * 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)
+{
+}
--- /dev/null
+/*
+ * 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;
+};
#include "sigsession.h"
+#include "logicdata.h"
+#include "logicdatasnapshot.h"
+
#include <QDebug>
#include <assert.h>
+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;
SigSession::~SigSession()
{
- g_array_free(sigData, TRUE);
-
// TODO: This should not be necessary
session = NULL;
}
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<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:
+ _cur_logic_snapshot.reset();
dataUpdated();
break;
}
#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 <string>
+class LogicData;
+class LogicDataSnapshot;
+class Signal;
class SigSession : public QObject
{
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();