From: Joel Holdsworth Date: Mon, 17 Dec 2012 21:21:14 +0000 (+0000) Subject: Added skeleton analog support X-Git-Tag: pulseview-0.1.0~192 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=aba1dd166b90f3408cd9d2b23b906df081845563;p=pulseview.git Added skeleton analog support --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a510bd6a..52c5b566 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 00000000..8cfa7a69 --- /dev/null +++ b/pv/analogdata.cpp @@ -0,0 +1,46 @@ +/* + * This file is part of the PulseView 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 "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 &snapshot) +{ + _snapshots.push_front(snapshot); +} + +deque< shared_ptr >& AnalogData::get_snapshots() +{ + return _snapshots; +} + +} // namespace pv diff --git a/pv/analogdata.h b/pv/analogdata.h new file mode 100644 index 00000000..e1c4ee62 --- /dev/null +++ b/pv/analogdata.h @@ -0,0 +1,56 @@ +/* + * This file is part of the PulseView 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 + */ + +#ifndef PULSEVIEW_PV_ANALOGDATA_H +#define PULSEVIEW_PV_ANALOGDATA_H + +#include "signaldata.h" + +#include +#include + +extern "C" { +#include +} + +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 &snapshot); + + std::deque< boost::shared_ptr >& + get_snapshots(); + +private: + std::deque< boost::shared_ptr > + _snapshots; +}; + +} // namespace pv + +#endif // PULSEVIEW_PV_ANALOGDATA_H diff --git a/pv/analogdatasnapshot.cpp b/pv/analogdatasnapshot.cpp new file mode 100644 index 00000000..2203bb57 --- /dev/null +++ b/pv/analogdatasnapshot.cpp @@ -0,0 +1,53 @@ +/* + * This file is part of the PulseView 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 +#include +#include + +#include + +#include "analogdatasnapshot.h" + +using namespace boost; +using namespace std; + +namespace pv { + +AnalogDataSnapshot::AnalogDataSnapshot( + const sr_datafeed_analog &analog) : + DataSnapshot(sizeof(float)) +{ + lock_guard lock(_mutex); + append_payload(analog); +} + +void AnalogDataSnapshot::append_payload( + const sr_datafeed_analog &analog) +{ + lock_guard 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 index 00000000..03184c0f --- /dev/null +++ b/pv/analogdatasnapshot.h @@ -0,0 +1,41 @@ +/* + * This file is part of the PulseView 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 + */ + +#ifndef PULSEVIEW_PV_ANALOGDATASNAPSHOT_H +#define PULSEVIEW_PV_ANALOGDATASNAPSHOT_H + +#include "datasnapshot.h" + +#include +#include + +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 diff --git a/pv/logicdata.cpp b/pv/logicdata.cpp index c8b3b84d..492961fb 100644 --- a/pv/logicdata.cpp +++ b/pv/logicdata.cpp @@ -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) { } diff --git a/pv/logicdata.h b/pv/logicdata.h index 11e5f9a3..af1d32ee 100644 --- a/pv/logicdata.h +++ b/pv/logicdata.h @@ -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; diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index adad2c5e..b7e910e3 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -20,8 +20,11 @@ #include "sigsession.h" +#include "analogdata.h" +#include "analogdatasnapshot.h" #include "logicdata.h" #include "logicdatasnapshot.h" +#include "view/analogsignal.h" #include "view/logicsignal.h" #include @@ -73,10 +76,12 @@ void SigSession::start_capture(struct sr_dev_inst *sdi, { stop_capture(); + lock_guard 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 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 lock(_data_mutex); + lock_guard data_lock(_data_mutex); + lock_guard 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 data_lock(_data_mutex); + lock_guard 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 lock(_signals_mutex); + + // Add the signals + shared_ptr signal( + new AnalogSignal(QString("???"), _analog_data)); + _signals.push_back(signal); + + signals_changed(); + } +} + void SigSession::feed_in_logic(const sr_datafeed_logic &logic) { lock_guard 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 lock(_data_mutex); + if (!_cur_analog_snapshot) + { + // Create a new data snapshot + _cur_analog_snapshot = shared_ptr( + 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 lock(_data_mutex); _cur_logic_snapshot.reset(); + _cur_analog_snapshot.reset(); } data_updated(); break; diff --git a/pv/sigsession.h b/pv/sigsession.h index deb95ed8..308b0827 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -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 > _signals; @@ -102,6 +110,8 @@ private: mutable boost::mutex _data_mutex; boost::shared_ptr _logic_data; boost::shared_ptr _cur_logic_snapshot; + boost::shared_ptr _analog_data; + boost::shared_ptr _cur_analog_snapshot; std::auto_ptr _sampling_thread; diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp new file mode 100644 index 00000000..73ab1686 --- /dev/null +++ b/pv/view/analogsignal.cpp @@ -0,0 +1,53 @@ +/* + * This file is part of the PulseView 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 "analogsignal.h" +#include "../analogdata.h" +#include "../analogdatasnapshot.h" + +using namespace boost; +using namespace std; + +namespace pv { +namespace view { + +AnalogSignal::AnalogSignal(QString name, shared_ptr 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 index 00000000..b3cafd2f --- /dev/null +++ b/pv/view/analogsignal.h @@ -0,0 +1,66 @@ +/* + * This file is part of the PulseView 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 + */ + +#ifndef PULSEVIEW_PV_ANALOGSIGNAL_H +#define PULSEVIEW_PV_ANALOGSIGNAL_H + +#include "signal.h" + +#include + +namespace pv { + +class AnalogData; + +namespace view { + +class AnalogSignal : public Signal +{ +public: + AnalogSignal(QString name, + boost::shared_ptr 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 _data; +}; + +} // namespace view +} // namespace pv + +#endif // PULSEVIEW_PV_ANALOGSIGNAL_H