set(pulseview_SOURCES
main.cpp
pv/about.cpp
+ pv/analogdata.cpp
+ pv/analogdatasnapshot.cpp
pv/datasnapshot.cpp
pv/logicdata.cpp
pv/logicdatasnapshot.cpp
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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
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)
{
}
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;
#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>
{
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()
}
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);
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) {
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;
}
}
+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);
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)
*(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;
namespace pv {
+class AnalogData;
+class AnalogDataSnapshot;
class LogicData;
class LogicDataSnapshot;
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);
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;
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;
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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