]> sigrok.org Git - pulseview.git/commitdiff
Added skeleton analog support
authorJoel Holdsworth <redacted>
Mon, 17 Dec 2012 21:21:14 +0000 (21:21 +0000)
committerJoel Holdsworth <redacted>
Thu, 20 Dec 2012 08:02:44 +0000 (08:02 +0000)
CMakeLists.txt
pv/analogdata.cpp [new file with mode: 0644]
pv/analogdata.h [new file with mode: 0644]
pv/analogdatasnapshot.cpp [new file with mode: 0644]
pv/analogdatasnapshot.h [new file with mode: 0644]
pv/logicdata.cpp
pv/logicdata.h
pv/sigsession.cpp
pv/sigsession.h
pv/view/analogsignal.cpp [new file with mode: 0644]
pv/view/analogsignal.h [new file with mode: 0644]

index a510bd6a2b3c8a39b93d516523e36b60e992ccf4..52c5b56688f27f5b5e3d036fb741d52f545b2d37 100644 (file)
@@ -81,6 +81,8 @@ configure_file (
 set(pulseview_SOURCES
        main.cpp
        pv/about.cpp
+       pv/analogdata.cpp
+       pv/analogdatasnapshot.cpp
        pv/datasnapshot.cpp
        pv/logicdata.cpp
        pv/logicdatasnapshot.cpp
@@ -88,6 +90,7 @@ set(pulseview_SOURCES
        pv/samplingbar.cpp
        pv/signaldata.cpp
        pv/sigsession.cpp
+       pv/view/analogsignal.cpp
        pv/view/cursor.cpp
        pv/view/header.cpp
        pv/view/logicsignal.cpp
diff --git a/pv/analogdata.cpp b/pv/analogdata.cpp
new file mode 100644 (file)
index 0000000..8cfa7a6
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * This file is part of the PulseView 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 "analogdata.h"
+#include "analogdatasnapshot.h"
+
+using namespace boost;
+using namespace std;
+
+namespace pv {
+
+AnalogData::AnalogData(const sr_datafeed_meta_analog &meta,
+       uint64_t samplerate) :
+       SignalData(samplerate)
+{
+}
+
+void AnalogData::push_snapshot(
+       boost::shared_ptr<AnalogDataSnapshot> &snapshot)
+{
+       _snapshots.push_front(snapshot);
+}
+
+deque< shared_ptr<AnalogDataSnapshot> >& AnalogData::get_snapshots()
+{
+       return _snapshots;
+}
+
+} // namespace pv
diff --git a/pv/analogdata.h b/pv/analogdata.h
new file mode 100644 (file)
index 0000000..e1c4ee6
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the PulseView 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
+ */
+
+#ifndef PULSEVIEW_PV_ANALOGDATA_H
+#define PULSEVIEW_PV_ANALOGDATA_H
+
+#include "signaldata.h"
+
+#include <boost/shared_ptr.hpp>
+#include <deque>
+
+extern "C" {
+#include <libsigrok/libsigrok.h>
+}
+
+namespace pv {
+
+class AnalogDataSnapshot;
+
+class AnalogData : public SignalData
+{
+public:
+       AnalogData(const sr_datafeed_meta_analog &meta,
+               uint64_t samplerate);
+
+       void push_snapshot(
+               boost::shared_ptr<AnalogDataSnapshot> &snapshot);
+
+       std::deque< boost::shared_ptr<AnalogDataSnapshot> >&
+               get_snapshots();
+
+private:
+       std::deque< boost::shared_ptr<AnalogDataSnapshot> >
+               _snapshots;
+};
+
+} // namespace pv
+
+#endif // PULSEVIEW_PV_ANALOGDATA_H
diff --git a/pv/analogdatasnapshot.cpp b/pv/analogdatasnapshot.cpp
new file mode 100644 (file)
index 0000000..2203bb5
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the PulseView 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 <extdef.h>
+
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <boost/foreach.hpp>
+
+#include "analogdatasnapshot.h"
+
+using namespace boost;
+using namespace std;
+
+namespace pv {
+
+AnalogDataSnapshot::AnalogDataSnapshot(
+       const sr_datafeed_analog &analog) :
+       DataSnapshot(sizeof(float))
+{
+       lock_guard<recursive_mutex> lock(_mutex);
+       append_payload(analog);
+}
+
+void AnalogDataSnapshot::append_payload(
+       const sr_datafeed_analog &analog)
+{
+       lock_guard<recursive_mutex> lock(_mutex);
+
+       append_data(analog.data, analog.num_samples);
+}
+
+} // namespace pv
diff --git a/pv/analogdatasnapshot.h b/pv/analogdatasnapshot.h
new file mode 100644 (file)
index 0000000..03184c0
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * This file is part of the PulseView 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
+ */
+
+#ifndef PULSEVIEW_PV_ANALOGDATASNAPSHOT_H
+#define PULSEVIEW_PV_ANALOGDATASNAPSHOT_H
+
+#include "datasnapshot.h"
+
+#include <utility>
+#include <vector>
+
+namespace pv {
+
+class AnalogDataSnapshot : public DataSnapshot
+{
+public:
+       AnalogDataSnapshot(const sr_datafeed_analog &analog);
+
+       void append_payload(const sr_datafeed_analog &analog);
+};
+
+} // namespace pv
+
+#endif // PULSEVIEW_PV_ANALOGDATASNAPSHOT_H
index c8b3b84de9974c1a7947a37152d58c4aa9a5f236..492961fb57fe2027f2c832ee7f09df08cfa008cd 100644 (file)
@@ -26,8 +26,9 @@ using namespace std;
 
 namespace pv {
 
-LogicData::LogicData(const sr_datafeed_meta_logic &meta) :
-       SignalData(meta.samplerate > 0 ? meta.samplerate : 1),
+LogicData::LogicData(const sr_datafeed_meta_logic &meta,
+       uint64_t samplerate) :
+       SignalData(samplerate),
        _num_probes(meta.num_probes)
 {
 }
index 11e5f9a30bd75aad3194bd34cf7ecb3bade1554c..af1d32eed7bd9aed9919e3ea6756437974a3a45a 100644 (file)
@@ -37,7 +37,7 @@ class LogicDataSnapshot;
 class LogicData : public SignalData
 {
 public:
-       LogicData(const sr_datafeed_meta_logic &meta);
+       LogicData(const sr_datafeed_meta_logic &meta, uint64_t samplerate);
 
        int get_num_probes() const;
 
index adad2c5ee0cc51304f928e92445471d7ef88c2d8..b7e910e3a4839268792b9bf970033ac2d6c1c69c 100644 (file)
 
 #include "sigsession.h"
 
+#include "analogdata.h"
+#include "analogdatasnapshot.h"
 #include "logicdata.h"
 #include "logicdatasnapshot.h"
+#include "view/analogsignal.h"
 #include "view/logicsignal.h"
 
 #include <QDebug>
@@ -73,10 +76,12 @@ void SigSession::start_capture(struct sr_dev_inst *sdi,
 {
        stop_capture();
 
+       lock_guard<mutex> lock(_sampling_mutex);
+       _sample_rate = sample_rate;
 
        _sampling_thread.reset(new boost::thread(
                &SigSession::sample_thread_proc, this, sdi,
-               record_length, sample_rate));
+               record_length));
 }
 
 void SigSession::stop_capture()
@@ -133,7 +138,7 @@ void SigSession::load_thread_proc(const string name)
 }
 
 void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
-       uint64_t record_length, uint64_t sample_rate)
+       uint64_t record_length)
 {
        sr_session_new();
        sr_session_datafeed_callback_add(data_feed_in_proc);
@@ -151,11 +156,14 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
                return;
        }
 
-       if (sr_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
-               &sample_rate) != SR_OK) {
-               qDebug() << "Failed to configure samplerate.";
-               sr_session_destroy();
-               return;
+       {
+               lock_guard<mutex> lock(_sampling_mutex);
+               if (sr_dev_config_set(sdi, SR_HWCAP_SAMPLERATE,
+                       &_sample_rate) != SR_OK) {
+                       qDebug() << "Failed to configure samplerate.";
+                       sr_session_destroy();
+                       return;
+               }
        }
 
        if (sr_session_start() != SR_OK) {
@@ -177,10 +185,11 @@ void SigSession::feed_in_meta_logic(const struct sr_dev_inst *sdi,
        using view::LogicSignal;
 
        {
-               lock_guard<mutex> lock(_data_mutex);
+               lock_guard<mutex> data_lock(_data_mutex);
+               lock_guard<mutex> sampling_lock(_sampling_mutex);
 
                // Create an empty LogicData for coming data snapshots
-               _logic_data.reset(new LogicData(meta_logic));
+               _logic_data.reset(new LogicData(meta_logic, _sample_rate));
                assert(_logic_data);
                if (!_logic_data)
                        return;
@@ -206,6 +215,35 @@ void SigSession::feed_in_meta_logic(const struct sr_dev_inst *sdi,
        }
 }
 
+void SigSession::feed_in_meta_analog(const struct sr_dev_inst *sdi,
+       const sr_datafeed_meta_analog &meta_analog)
+{
+       using view::AnalogSignal;
+
+       {
+               lock_guard<mutex> data_lock(_data_mutex);
+               lock_guard<mutex> sampling_lock(_sampling_mutex);
+
+               // Create an empty AnalogData for coming data snapshots
+               _analog_data.reset(new AnalogData(
+                       meta_analog, _sample_rate));
+               assert(_analog_data);
+               if (!_analog_data)
+                       return;
+       }
+
+       {
+               lock_guard<mutex> lock(_signals_mutex);
+
+               // Add the signals
+               shared_ptr<AnalogSignal> signal(
+                       new AnalogSignal(QString("???"), _analog_data));
+               _signals.push_back(signal);
+
+               signals_changed();
+       }
+}
+
 void SigSession::feed_in_logic(const sr_datafeed_logic &logic)
 {
        lock_guard<mutex> lock(_data_mutex);
@@ -225,6 +263,24 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic)
        data_updated();
 }
 
+void SigSession::feed_in_analog(const sr_datafeed_analog &analog)
+{
+       lock_guard<mutex> lock(_data_mutex);
+       if (!_cur_analog_snapshot)
+       {
+               // Create a new data snapshot
+               _cur_analog_snapshot = shared_ptr<AnalogDataSnapshot>(
+                       new AnalogDataSnapshot(analog));
+               _analog_data->push_snapshot(_cur_analog_snapshot);
+       }
+       else
+       {
+               // Append to the existing data snapshot
+               _cur_analog_snapshot->append_payload(analog);
+       }
+
+       data_updated();
+}
 
 void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
        const struct sr_datafeed_packet *packet)
@@ -246,16 +302,28 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi,
                        *(const sr_datafeed_meta_logic*)packet->payload);
                break;
 
+       case SR_DF_META_ANALOG:
+               assert(packet->payload);
+               feed_in_meta_analog(sdi,
+                       *(const sr_datafeed_meta_analog*)packet->payload);
+               break;
+
        case SR_DF_LOGIC:
                assert(packet->payload);
                feed_in_logic(*(const sr_datafeed_logic*)packet->payload);
                break;
 
+       case SR_DF_ANALOG:
+               assert(packet->payload);
+               feed_in_analog(*(const sr_datafeed_analog*)packet->payload);
+               break;
+
        case SR_DF_END:
        {
                {
                        lock_guard<mutex> lock(_data_mutex);
                        _cur_logic_snapshot.reset();
+                       _cur_analog_snapshot.reset();
                }
                data_updated();
                break;
index deb95ed8b2cb8b18bf36235fbd453e9195ade31d..308b082730d13548f884b931e7bdc92cf46baf0f 100644 (file)
@@ -36,6 +36,8 @@ extern "C" {
 
 namespace pv {
 
+class AnalogData;
+class AnalogDataSnapshot;
 class LogicData;
 class LogicDataSnapshot;
 
@@ -79,13 +81,18 @@ private:
        void load_thread_proc(const std::string name);
 
        void sample_thread_proc(struct sr_dev_inst *sdi,
-               uint64_t record_length, uint64_t sample_rate);
+               uint64_t record_length);
 
        void feed_in_meta_logic(const struct sr_dev_inst *sdi,
                const sr_datafeed_meta_logic &meta_logic);
 
+       void feed_in_meta_analog(const struct sr_dev_inst *sdi,
+               const sr_datafeed_meta_analog &meta_analog);
+
        void feed_in_logic(const sr_datafeed_logic &logic);
 
+       void feed_in_analog(const sr_datafeed_analog &analog);
+
        void data_feed_in(const struct sr_dev_inst *sdi,
                const struct sr_datafeed_packet *packet);
 
@@ -95,6 +102,7 @@ private:
 private:
        mutable boost::mutex _sampling_mutex;
        capture_state _capture_state;
+       uint64_t _sample_rate;
 
        mutable boost::mutex _signals_mutex;
        std::vector< boost::shared_ptr<view::Signal> > _signals;
@@ -102,6 +110,8 @@ private:
        mutable boost::mutex _data_mutex;
        boost::shared_ptr<LogicData> _logic_data;
        boost::shared_ptr<LogicDataSnapshot> _cur_logic_snapshot;
+       boost::shared_ptr<AnalogData> _analog_data;
+       boost::shared_ptr<AnalogDataSnapshot> _cur_analog_snapshot;
 
        std::auto_ptr<boost::thread> _sampling_thread;
 
diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp
new file mode 100644 (file)
index 0000000..73ab168
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * This file is part of the PulseView 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 <extdef.h>
+
+#include <math.h>
+
+#include "analogsignal.h"
+#include "../analogdata.h"
+#include "../analogdatasnapshot.h"
+
+using namespace boost;
+using namespace std;
+
+namespace pv {
+namespace view {
+
+AnalogSignal::AnalogSignal(QString name, shared_ptr<AnalogData> data) :
+       Signal(name),
+       _data(data)
+{
+       _colour = Qt::blue;
+}
+
+void AnalogSignal::paint(QPainter &p, const QRect &rect, double scale,
+       double offset)
+{
+}
+
+int AnalogSignal::get_nominal_offset(const QRect &rect) const
+{
+       return rect.bottom();
+}
+
+} // namespace view
+} // namespace pv
diff --git a/pv/view/analogsignal.h b/pv/view/analogsignal.h
new file mode 100644 (file)
index 0000000..b3cafd2
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the PulseView 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
+ */
+
+#ifndef PULSEVIEW_PV_ANALOGSIGNAL_H
+#define PULSEVIEW_PV_ANALOGSIGNAL_H
+
+#include "signal.h"
+
+#include <boost/shared_ptr.hpp>
+
+namespace pv {
+
+class AnalogData;
+
+namespace view {
+
+class AnalogSignal : public Signal
+{
+public:
+       AnalogSignal(QString name,
+               boost::shared_ptr<pv::AnalogData> data);
+
+       /**
+        * Paints the signal with a QPainter
+        * @param p the QPainter to paint into.
+        * @param rect the rectangular area to draw the trace into.
+        * @param scale the scale in seconds per pixel.
+        * @param offset the time to show at the left hand edge of
+        *   the view in seconds.
+        **/
+       void paint(QPainter &p, const QRect &rect,
+               double scale, double offset);
+
+private:
+
+       /**
+        * When painting into the rectangle, calculate the y
+        * offset of the zero point.
+        **/
+       int get_nominal_offset(const QRect &rect) const;
+
+private:
+       boost::shared_ptr<pv::AnalogData> _data;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PULSEVIEW_PV_ANALOGSIGNAL_H