diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 4c76ac7e..c53affa1 100755 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -64,12 +64,8 @@ DecoderStack::DecoderStack(pv::SigSession *session, _no_memory = false; _mark_index = -1; _decoder_status = decoder_status; - _stask_stauts = NULL; - - connect(_session, SIGNAL(frame_began()), this, SLOT(on_new_frame())); - - connect(_session, SIGNAL(data_received()), this, SLOT(on_data_received())); - + _stask_stauts = NULL; + _stack.push_back(new decode::Decoder(dec)); build_row(); @@ -668,15 +664,7 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *decoder) if (!(*row_iter).second->push_annotation(a)) d->_no_memory = true; } - -void DecoderStack::on_new_frame() -{ -} - -void DecoderStack::on_data_received() -{ -} - + void DecoderStack::frame_ended() { _options_changed = true; diff --git a/DSView/pv/data/decoderstack.h b/DSView/pv/data/decoderstack.h index c8a2b929..cef31dab 100755 --- a/DSView/pv/data/decoderstack.h +++ b/DSView/pv/data/decoderstack.h @@ -172,11 +172,7 @@ private: static void annotation_callback(srd_proto_data *pdata, void *decoder); -private slots: - void on_new_frame(); - - void on_data_received(); - + signals: void new_decode_data(); void decode_done(); diff --git a/DSView/pv/data/mathstack.cpp b/DSView/pv/data/mathstack.cpp index 87dd08cd..9b2d9686 100755 --- a/DSView/pv/data/mathstack.cpp +++ b/DSView/pv/data/mathstack.cpp @@ -20,10 +20,11 @@ #include "mathstack.h" -#include -#include -#include -#include +#include "dso.h" +#include "dsosnapshot.h" +#include "../sigsession.h" +#include "../view/dsosignal.h" +#include #define PI 3.1415 diff --git a/DSView/pv/data/spectrumstack.cpp b/DSView/pv/data/spectrumstack.cpp index c5c48301..72759c7e 100755 --- a/DSView/pv/data/spectrumstack.cpp +++ b/DSView/pv/data/spectrumstack.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #define PI 3.1415 diff --git a/DSView/pv/device/inputfile.cpp b/DSView/pv/device/inputfile.cpp index 33b346bf..83ed6995 100755 --- a/DSView/pv/device/inputfile.cpp +++ b/DSView/pv/device/inputfile.cpp @@ -51,15 +51,7 @@ void InputFile::use(SigSession *owner) // only *.dsl file is valid // don't allow other types of file input throw tr("Not a valid DSView data file."); - return; - -// _input = load_input_file_format(_path, NULL); -// File::use(owner); - -// sr_session_new(); - -// if (sr_session_dev_add(_input->sdi) != SR_OK) -// throw tr("Failed to add session device."); + return; } void InputFile::release() diff --git a/DSView/pv/dialogs/fftoptions.cpp b/DSView/pv/dialogs/fftoptions.cpp index 425854c0..5b8f44d7 100755 --- a/DSView/pv/dialogs/fftoptions.cpp +++ b/DSView/pv/dialogs/fftoptions.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "../sigsession.h" #include "../data/spectrumstack.h" @@ -31,6 +32,7 @@ #include "../view/dsosignal.h" #include "../view/spectrumtrace.h" + using namespace boost; using namespace std; diff --git a/DSView/pv/dialogs/lissajousoptions.cpp b/DSView/pv/dialogs/lissajousoptions.cpp index 4ab1d3c2..8f8456be 100755 --- a/DSView/pv/dialogs/lissajousoptions.cpp +++ b/DSView/pv/dialogs/lissajousoptions.cpp @@ -30,6 +30,7 @@ #include #include #include +#include using namespace boost; diff --git a/DSView/pv/dialogs/protocollist.cpp b/DSView/pv/dialogs/protocollist.cpp index 9f474fa8..4b094d90 100755 --- a/DSView/pv/dialogs/protocollist.cpp +++ b/DSView/pv/dialogs/protocollist.cpp @@ -49,11 +49,13 @@ ProtocolList::ProtocolList(QWidget *parent, SigSession *session) : _map_zoom_combobox->addItem(tr("Fit to Window")); _map_zoom_combobox->addItem(tr("Fixed")); int cur_map_zoom = _session->get_map_zoom(); + if (cur_map_zoom >= _map_zoom_combobox->count()) _map_zoom_combobox->setCurrentIndex(0); else _map_zoom_combobox->setCurrentIndex(cur_map_zoom); - connect(_map_zoom_combobox, SIGNAL(currentIndexChanged(int)), _session, SLOT(set_map_zoom(int))); + + connect(_map_zoom_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_set_map_zoom(int))); _protocol_combobox = new QComboBox(this); auto &decode_sigs = _session->get_decode_signals(); @@ -193,5 +195,11 @@ void ProtocolList::on_row_check(bool show) _session->get_decoder_model()->setDecoderStack(decoder_stack); } + + void ProtocolList::on_set_map_zoom(int index) + { + _session->set_map_zoom(index); + } + } // namespace dialogs } // namespace pv diff --git a/DSView/pv/dialogs/protocollist.h b/DSView/pv/dialogs/protocollist.h index 0d4024d9..f53dfcfa 100755 --- a/DSView/pv/dialogs/protocollist.h +++ b/DSView/pv/dialogs/protocollist.h @@ -56,6 +56,7 @@ protected: private slots: void set_protocol(int index); void on_row_check(bool show); + void on_set_map_zoom(int index); private: SigSession *_session; diff --git a/DSView/pv/dock/dsotriggerdock.cpp b/DSView/pv/dock/dsotriggerdock.cpp index 03e1a8ee..6d401770 100755 --- a/DSView/pv/dock/dsotriggerdock.cpp +++ b/DSView/pv/dock/dsotriggerdock.cpp @@ -35,6 +35,7 @@ #include #include #include +#include using namespace boost; using namespace std; diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index 5b6c77dd..f3b3f62a 100755 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -308,6 +308,7 @@ void MeasureDock::reCalc() update_dist(); update_edge(); } + void MeasureDock::goto_cursor() { diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index 04888b4a..26afcc8b 100755 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -176,33 +176,23 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *sessio _split_widget->setOrientation(Qt::Vertical); _split_widget->setCollapsible(0, false); _split_widget->setCollapsible(1, false); - //_split_widget->setStretchFactor(1, 1); - //_split_widget this->setWidgetResizable(true); this->setWidget(_split_widget); - //_split_widget->setGeometry(0, 0, sizeHint().width(), 500); + _split_widget->setObjectName("protocolWidget"); connect(_dn_nav_button, SIGNAL(clicked()),this, SLOT(nav_table_view())); - connect(_dn_save_button, SIGNAL(clicked()),this, SLOT(export_table_view())); - connect(_dn_set_button, SIGNAL(clicked()),this, SLOT(set_model())); - connect(_pre_button, SIGNAL(clicked()),this, SLOT(search_pre())); - connect(_nxt_button, SIGNAL(clicked()),this, SLOT(search_nxt())); - connect(_add_button, SIGNAL(clicked()),this, SLOT(on_add_protocol())); + connect(_del_all_button, SIGNAL(clicked()),this, SLOT(on_del_all_protocol())); - connect(_del_all_button, SIGNAL(clicked()),this, SLOT(on_del_all_protocol())); - - connect(_session, SIGNAL(decode_done()), this, SLOT(update_model())); connect(this, SIGNAL(protocol_updated()), this, SLOT(update_model())); connect(_table_view, SIGNAL(clicked(QModelIndex)), this, SLOT(item_clicked(QModelIndex))); connect(_table_view->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(column_resize(int, int, int))); - //connect(_table_view->verticalScrollBar(), SIGNAL(sliderMoved()), this, SLOT(sliderMoved())); connect(_search_edit, SIGNAL(editingFinished()), this, SLOT(search_changed())); retranslateUi(); diff --git a/DSView/pv/dock/protocoldock.h b/DSView/pv/dock/protocoldock.h index b300846a..a83df95b 100755 --- a/DSView/pv/dock/protocoldock.h +++ b/DSView/pv/dock/protocoldock.h @@ -72,6 +72,7 @@ public: void del_all_protocol(); bool sel_protocol(QString name); void add_protocol(bool silent); + private: void changeEvent(QEvent *event); void retranslateUi(); @@ -90,12 +91,14 @@ private: signals: void protocol_updated(); +public slots: + void update_model(); + private slots: void on_add_protocol(); void on_del_all_protocol(); void decoded_progress(int progress); - void set_model(); - void update_model(); + void set_model(); void export_table_view(); void nav_table_view(); void item_clicked(const QModelIndex &index); diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index d69b7828..87fa9e94 100755 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "libsigrok4DSL/libsigrok.h" diff --git a/DSView/pv/dstimer.cpp b/DSView/pv/dstimer.cpp new file mode 100644 index 00000000..e3bbaad2 --- /dev/null +++ b/DSView/pv/dstimer.cpp @@ -0,0 +1,49 @@ + +#include "dstimer.h" +#include + +DsTimer::DsTimer(){ + _binded = false; +} + + void DsTimer::on_timeout() + { + _call(); //call back + } + +void DsTimer::TimeOut(int millsec, CALLBACL_FUNC f) +{ + _call = f; + QTimer::singleShot(millsec, this, SLOT(on_timeout())); +} + +void DsTimer::SetCallback(CALLBACL_FUNC f) + { + assert(!_binded); + _binded = true; + + _call = f; + connect(&_timer, SIGNAL(timeout()), this, SLOT(on_timeout())); + } + + void DsTimer::Start(int millsec, CALLBACL_FUNC f) + { + assert(!_binded); + _binded = true; + + _call = f; + connect(&_timer, SIGNAL(timeout()), this, SLOT(on_timeout())); + _timer.start(millsec); + } + + void DsTimer::Start(int millsec) + { + //check if connectb + assert(_binded); + _timer.start(millsec); + } + + void DsTimer::Stop() + { + _timer.stop(); + } diff --git a/DSView/pv/dstimer.h b/DSView/pv/dstimer.h new file mode 100644 index 00000000..87c35f41 --- /dev/null +++ b/DSView/pv/dstimer.h @@ -0,0 +1,37 @@ + +#ifndef _DS_TIMER_H +#define _DS_TIMER_H + +#include +#include +#include + +typedef std::function CALLBACL_FUNC; + +class DsTimer : public QObject +{ + Q_OBJECT + +public: + DsTimer(); + + void TimeOut(int millsec, CALLBACL_FUNC f); + + void SetCallback(CALLBACL_FUNC f); + + void Start(int millsec, CALLBACL_FUNC f); + + void Start(int millsec); + + void Stop(); + +private slots: + void on_timeout(); + +private: + CALLBACL_FUNC _call; + QTimer _timer; + bool _binded; +}; + +#endif diff --git a/DSView/pv/eventobject.cpp b/DSView/pv/eventobject.cpp new file mode 100644 index 00000000..d8671fa3 --- /dev/null +++ b/DSView/pv/eventobject.cpp @@ -0,0 +1,6 @@ + +#include "eventobject.h" + +EventObject::EventObject(){ + +} \ No newline at end of file diff --git a/DSView/pv/eventobject.h b/DSView/pv/eventobject.h new file mode 100644 index 00000000..770b884d --- /dev/null +++ b/DSView/pv/eventobject.h @@ -0,0 +1,55 @@ + +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * 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 _EVENT_OBJECT_H +#define _EVENT_OBJECT_H + +#include + +class EventObject : public QObject +{ + Q_OBJECT + +public: + EventObject(); + + +signals: + void show_error(QString error); + void capture_state_changed(int state); + void data_updated(); + void device_attach(); + void device_detach(); + + void session_error(); + void signals_changed(); + void receive_trigger(quint64 trigger_pos); + void frame_ended(); + void frame_began(); + + void decode_done(); + void receive_data_len(quint64 len); + void cur_snap_samplerate_changed(); +}; + +#endif \ No newline at end of file diff --git a/DSView/pv/interface/icallbacks.h b/DSView/pv/interface/icallbacks.h new file mode 100644 index 00000000..1d1627c3 --- /dev/null +++ b/DSView/pv/interface/icallbacks.h @@ -0,0 +1,37 @@ + +#ifndef _I_CALLBACKS_ +#define _I_CALLBACKS_ + +class ISessionCallback +{ +public: + virtual void show_error(QString error)=0; + virtual void session_error()=0; + virtual void capture_state_changed(int state)=0; + virtual void device_attach()=0; + virtual void device_detach()=0; + + virtual void session_save()=0; + virtual void data_updated()=0; + virtual void repeat_resume()=0; + virtual void update_capture()=0; + virtual void cur_snap_samplerate_changed()=0; + + virtual void device_setted()=0; + virtual void signals_changed()=0; + virtual void receive_trigger(quint64 trigger_pos)=0; + virtual void frame_ended()=0; + virtual void frame_began()=0; + + virtual void show_region(uint64_t start, uint64_t end, bool keep)=0; + virtual void show_wait_trigger()=0; + virtual void repeat_hold(int percent)=0; + virtual void decode_done()=0; + virtual void receive_data_len(quint64 len)=0; + + virtual void receive_header()=0; + virtual void data_received()=0; + +}; + +#endif diff --git a/DSView/pv/interface/uicallback.h b/DSView/pv/interface/uicallback.h index 8af7964b..b7ae0054 100644 --- a/DSView/pv/interface/uicallback.h +++ b/DSView/pv/interface/uicallback.h @@ -1,4 +1,25 @@ +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2014 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 + */ + #pragma once class IDlgCallback diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 0ca0bc70..2c711e74 100755 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -24,10 +24,7 @@ #include #include "dock/protocoldock.h" - - -#include - + #include #include #include @@ -91,7 +88,7 @@ #include "../ui/msgbox.h" #include "config/appconfig.h" #include "appcontrol.h" - + namespace pv { @@ -101,6 +98,7 @@ MainWindow::MainWindow(QWidget *parent) : _msg(NULL) { _control = AppControl::Instance(); + _control->GetSession()->set_callback(this); setup_ui(); @@ -233,8 +231,7 @@ void MainWindow::setup_ui() _search_dock->installEventFilter(this); // Populate the device list and select the initially selected device - _session->set_default_device(boost::bind(&MainWindow::session_error, this, - QString(tr("Set Default Device failed")), _1)); + _session->set_default_device(); // defaut language AppConfig &app = AppConfig::Instance(); @@ -247,22 +244,25 @@ void MainWindow::setup_ui() // update device update_device_list(); - _session->start_hotplug_work(boost::bind(&MainWindow::session_error, this, - QString(tr("Hotplug failed")), _1)); + _session->start_hotplug_work(); retranslateUi(); + //event + connect(&_event, SIGNAL(capture_state_changed(int)), this, SLOT(on_capture_state_changed(int))); + connect(&_event, SIGNAL(device_attach()), this, SLOT(on_device_attach())); + connect(&_event, SIGNAL(device_detach()), this, SLOT(on_device_detach())); + connect(&_event, SIGNAL(session_error()), this, SLOT(on_session_error())); + connect(&_event, SIGNAL(show_error(QString)), this, SLOT(on_show_error(QString))); + connect(&_event, SIGNAL(signals_changed()), this, SLOT(on_signals_changed())); + connect(&_event, SIGNAL(receive_trigger(quint64)), this, SLOT(on_receive_trigger(quint64))); + connect(&_event, SIGNAL(frame_ended()), this, SLOT(on_frame_ended())); + connect(&_event, SIGNAL(frame_began()), this, SLOT(on_frame_began())); + connect(&_event, SIGNAL(decode_done()), this, SLOT(on_decode_done())); + connect(&_event, SIGNAL(data_updated()), this, SLOT(on_data_updated())); + connect(&_event, SIGNAL(cur_snap_samplerate_changed()), this, SLOT(on_cur_snap_samplerate_changed())); + connect(&_event, SIGNAL(receive_data_len(quint64)), this, SLOT(on_receive_data_len(quint64))); - // Setup _session events - connect(_session, SIGNAL(capture_state_changed(int)), this, SLOT(capture_state_changed(int))); - connect(_session, SIGNAL(device_attach()), this, SLOT(device_attach()), Qt::QueuedConnection); - connect(_session, SIGNAL(device_detach()), this, SLOT(device_detach()), Qt::QueuedConnection); - connect(_session, SIGNAL(session_error()), this, SLOT(on_show_error()), Qt::QueuedConnection); - connect(_session, SIGNAL(session_save()), this, SLOT(session_save())); - connect(_session, SIGNAL(data_updated()), _measure_widget, SLOT(reCalc())); - connect(_session, SIGNAL(repeat_resume()), this, SLOT(repeat_resume())); - connect(_session, SIGNAL(update_capture()), _view, SLOT(update_hori_res()), Qt::DirectConnection); - connect(_session, SIGNAL(cur_snap_samplerate_changed()), _measure_widget, SLOT(cursor_update())); //view connect(_view, SIGNAL(cursor_update()), _measure_widget, SLOT(cursor_update())); @@ -293,7 +293,7 @@ void MainWindow::setup_ui() connect(_logo_bar, SIGNAL(sig_open_doc()), this, SLOT(on_open_doc())); - connect(_protocol_widget, SIGNAL(protocol_updated()), _view, SLOT(signals_changed())); + connect(_protocol_widget, SIGNAL(protocol_updated()), this, SLOT(on_signals_changed())); //SamplingBar connect(_sampling_bar, SIGNAL(sig_device_selected()), this, SLOT(on_device_selected())); @@ -304,8 +304,7 @@ void MainWindow::setup_ui() connect(_sampling_bar, SIGNAL(sig_duration_changed()), _view, SLOT(timebase_changed())); connect(_sampling_bar, SIGNAL(sig_show_calibration()), _view, SLOT(show_calibration())); - connect(_dso_trigger_widget, SIGNAL(set_trig_pos(int)), _view, SLOT(set_trig_pos(int))); - + connect(_dso_trigger_widget, SIGNAL(set_trig_pos(int)), _view, SLOT(set_trig_pos(int))); } @@ -318,14 +317,7 @@ void MainWindow::retranslateUi() _search_dock->setWindowTitle(tr("Search...")); } -void MainWindow::session_error( - const QString text, const QString info_text) -{ - QMetaObject::invokeMethod(this, "show_session_error", - Qt::QueuedConnection, Q_ARG(QString, text), - Q_ARG(QString, info_text)); -} - + void MainWindow::on_device_selected() { update_device_list(); @@ -367,8 +359,7 @@ void MainWindow::update_device_list() int16_t version = g_variant_get_int16(gvar); g_variant_unref(gvar); if (version == 1) { - show_session_error(tr("Attension"), - tr("Current loading file has an old format. " + show_error(tr("Current loading file has an old format. " "This will lead to a slow loading speed. " "Please resave it after loaded.")); } @@ -386,8 +377,7 @@ void MainWindow::update_device_list() // load data const QString errorMessage( QString(tr("Failed to capture file data!"))); - _session->start_capture(true, boost::bind(&MainWindow::session_error, this, - errorMessage, _1)); + _session->start_capture(true); } if (!selected_device->name().contains("virtual")) { @@ -448,9 +438,8 @@ void MainWindow::update_device_list() g_variant_unref(gvar); if (usb30_support && usb_speed == LIBUSB_SPEED_HIGH) - show_session_error(tr("Speed limited"), tr("This is a super-speed usb device(USB 3.0). " - "Plug it into a USB 2.0 port will seriously affect its performance." - "Please replug it into a USB 3.0 port.")); + show_error("Plug it into a USB 2.0 port will seriously affect its performance." + "Please replug it into a USB 3.0 port."); } } } @@ -473,9 +462,8 @@ void MainWindow::on_load_file(QString file_name) session_save(); _session->set_file(file_name); } catch(QString e) { - show_session_error(tr("Failed to load ") + file_name, e); - _session->set_default_device(boost::bind(&MainWindow::session_error, this, - QString(tr("Set Default Device failed")), _1)); + show_error(tr("Failed to load ") + file_name); + _session->set_default_device(); update_device_list(); return; } @@ -483,26 +471,27 @@ void MainWindow::on_load_file(QString file_name) update_device_list(); } -void MainWindow::show_session_error( - const QString text, const QString info_text) +void MainWindow::show_error(QString error) { - dialogs::DSMessageBox msg(this); - _msg = &msg; - msg.mBox()->setText(text); - msg.mBox()->setInformativeText(info_text); - msg.mBox()->setStandardButtons(QMessageBox::Ok); - msg.mBox()->setIcon(QMessageBox::Warning); - msg.exec(); - _msg = NULL; + _event.show_error(error); //safe call +} + +void MainWindow::on_show_error(QString error) +{ + MsgBox::Show(NULL, error.toStdString().c_str(), this); } void MainWindow::device_attach() +{ + _event.device_attach(); //safe call +} + +void MainWindow::on_device_attach() { SigSession *_session = _control->GetSession(); _session->get_device()->device_updated(); - //_session->stop_hot_plug_proc(); - + _session->set_repeating(false); _session->stop_capture(); _sampling_bar->set_sampling(false); @@ -521,14 +510,15 @@ void MainWindow::device_attach() } } - - _session->set_default_device(boost::bind(&MainWindow::session_error, this, - QString(tr("Set Default Device failed")), _1)); + _session->set_default_device(); update_device_list(); - } -void MainWindow::device_detach() +void MainWindow::device_detach(){ + _event.device_detach(); //safe call +} + +void MainWindow::on_device_detach() { SigSession *_session = _control->GetSession(); @@ -586,8 +576,7 @@ void MainWindow::device_detach_post() } } - _session->set_default_device(boost::bind(&MainWindow::session_error, this, - QString(tr("Set Default Device failed")), _1)); + _session->set_default_device(); update_device_list(); } @@ -597,24 +586,21 @@ void MainWindow::device_changed(bool close) if (close) { _sampling_bar->set_sampling(false); - _session->set_default_device(boost::bind(&MainWindow::session_error, this, - QString(tr("Set Default Device failed")), _1)); + _session->set_default_device(); } update_device_list(); } void MainWindow::on_run_stop() -{ +{ SigSession *_session = _control->GetSession(); switch(_session->get_capture_state()) { case SigSession::Init: case SigSession::Stopped: commit_trigger(false); - _session->start_capture(false, - boost::bind(&MainWindow::session_error, this, - QString(tr("Capture failed")), _1)); + _session->start_capture(false); _view->capture_init(); break; @@ -632,9 +618,7 @@ void MainWindow::on_instant_stop() case SigSession::Init: case SigSession::Stopped: commit_trigger(true); - _session->start_capture(true, - boost::bind(&MainWindow::session_error, this, - QString(tr("Capture failed")), _1)); + _session->start_capture(true); _view->capture_init(); break; @@ -651,7 +635,12 @@ void MainWindow::repeat_resume() on_run_stop(); } -void MainWindow::on_show_error() +void MainWindow::session_error() +{ + _event.session_error(); +} + +void MainWindow::on_session_error() { QString title; QString details; @@ -725,6 +714,11 @@ void MainWindow::on_show_error() } void MainWindow::capture_state_changed(int state) +{ + _event.capture_state_changed(state);//safe call +} + +void MainWindow::on_capture_state_changed(int state) { SigSession *_session = _control->GetSession(); @@ -1441,8 +1435,17 @@ void MainWindow::switchTheme(QString style) qApp->setStyleSheet(qss.readAll()); qss.close(); - SigSession *_session = _control->GetSession(); - _session->data_updated(); + data_updated(); +} + +void MainWindow::data_updated() +{ + _event.data_updated(); //safe call +} + +void MainWindow::on_data_updated(){ + _measure_widget->reCalc(); + _view->data_updated(); } void MainWindow::on_open_doc(){ @@ -1463,4 +1466,98 @@ void MainWindow::openDoc() QUrl("file:///"+dir.absolutePath() + "/ug"+QString::number(lan)+".pdf")); } +void MainWindow::update_capture(){ + _view->update_hori_res(); +} + +void MainWindow::cur_snap_samplerate_changed(){ + _event.cur_snap_samplerate_changed(); //safe call +} + +void MainWindow::on_cur_snap_samplerate_changed() +{ + _measure_widget->cursor_update(); +} + +void MainWindow::device_setted(){ + _view->set_device(); +} + + void MainWindow::signals_changed() + { + _event.signals_changed(); //safe call + } + + void MainWindow::on_signals_changed() + { + _view->signals_changed(); + } + + void MainWindow::receive_trigger(quint64 trigger_pos) + { + _event.receive_trigger(trigger_pos); //save call + } + + void MainWindow::on_receive_trigger(quint64 trigger_pos) + { + _view->receive_trigger(trigger_pos); + } + + void MainWindow::frame_ended() + { + _event.frame_ended(); //save call + } + + void MainWindow::on_frame_ended() + { + _view->receive_end(); + } + + void MainWindow::frame_began() + { + _event.frame_began(); //save call + } + + void MainWindow::on_frame_began() + { + _view->frame_began(); + } + + void MainWindow::show_region(uint64_t start, uint64_t end, bool keep){ + _view->show_region(start, end, keep); + } + + void MainWindow::show_wait_trigger(){ + _view->show_wait_trigger(); + } + + void MainWindow::repeat_hold(int percent){ + (void)percent; + _view->repeat_show(); + } + + void MainWindow::decode_done(){ + _event.decode_done(); //safe call + } + + void MainWindow::on_decode_done(){ + _protocol_widget->update_model(); + } + + void MainWindow::receive_data_len(quint64 len){ + _event.receive_data_len(len);//safe call + } + +void MainWindow::on_receive_data_len(quint64 len){ + _view->set_receive_len(len); +} + +void MainWindow::receive_header(){ + +} + +void MainWindow::data_received(){ + +} + } // namespace pv diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index 68f2dd6d..446844b7 100755 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -25,11 +25,11 @@ #define DSVIEW_PV_MAINWINDOW_H #include - #include -#include - +#include #include "dialogs/dsmessagebox.h" +#include "interface/icallbacks.h" +#include "eventobject.h" class QAction; class QMenuBar; @@ -72,153 +72,148 @@ using namespace pv::device; //The mainwindow,referenced by MainFrame //TODO: create graph view,toolbar,and show device list -class MainWindow : public QMainWindow +class MainWindow : public QMainWindow, public ISessionCallback { Q_OBJECT private: static constexpr int Session_Version = 2; - + public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = 0); -protected: - void closeEvent(QCloseEvent *event); - -public: void openDoc(); - void switchLanguage(int language); private: + void closeEvent(QCloseEvent *event); + void setup_ui(); - void retranslateUi(); - void session_error(const QString text, const QString info_text); + void retranslateUi(); bool eventFilter(QObject *object, QEvent *event); - bool load_session_json(QJsonDocument json, bool file_dev,bool bDecoder=true); - void update_device_list(); -public slots: - void session_save(); - +public slots: void switchTheme(QString style); - void restore_dock(); private slots: void on_load_file(QString file_name); - - void on_open_doc(); - - /** - * Updates the device list in the sampling bar, and updates the - * selection. - * @param selected_device The device to select, or NULL if the - * first device in the device list should be selected. - */ - - + void on_open_doc(); void on_device_updated_reload(); - - void show_session_error(const QString text, const QString info_text); - + void on_run_stop(); - - void on_instant_stop(); - - void capture_state_changed(int state); - + void on_instant_stop(); void on_protocol(bool visible); - void on_trigger(bool visible); - void commit_trigger(bool instant); void on_measure(bool visible); - void on_search(bool visible); - void on_screenShot(); - void on_save(); void on_export(); - - bool on_load_session(QString name); - - bool on_store_session(QString name); - - /* - * repeat - */ - void repeat_resume(); - - /* - * hotplug slot function - */ - void device_attach(); - void device_detach(); + bool on_load_session(QString name); + bool on_store_session(QString name); void device_detach_post(); void device_changed(bool close); - void on_device_selected(); - - /* - * errors - */ - void on_show_error(); - + void on_device_selected(); void on_setLanguage(int language); + + void on_capture_state_changed(int state); + void on_data_updated(); + void on_device_attach(); + void on_device_detach(); + void on_show_error(QString str); + void on_session_error(); + void on_signals_changed(); + void on_receive_trigger(quint64 trigger_pos); + void on_frame_ended(); + void on_frame_began(); + void on_decode_done(); + void on_receive_data_len(quint64 len); + void on_cur_snap_samplerate_changed(); signals: void prgRate(int progress); +//ISessionCallback +public: + void session_save(); + +//ISessionCallback private: - AppControl *_control; - bool _hot_detach; + void show_error(QString error); + void session_error(); + void capture_state_changed(int state); + void device_attach(); + void device_detach(); - pv::view::View *_view; - dialogs::DSMessageBox *_msg; + void data_updated(); + void repeat_resume(); + void update_capture(); + void cur_snap_samplerate_changed(); + void device_setted(); - QMenuBar *_menu_bar; - QMenu *_menu_file; - QAction *_action_open; - QAction *_action_connect; - QAction *_action_quit; + void signals_changed(); + void receive_trigger(quint64 trigger_pos); + void frame_ended(); + void frame_began(); + void show_region(uint64_t start, uint64_t end, bool keep); - QMenu *_menu_view; - QAction *_action_view_zoom_in; - QAction *_action_view_zoom_out; - QAction *_action_view_show_cursors; + void show_wait_trigger(); + void repeat_hold(int percent); + void decode_done(); + void receive_data_len(quint64 len); + void receive_header(); + void data_received(); - QMenu *_menu_help; - QAction *_action_about; +private: + AppControl *_control; + bool _hot_detach; - QWidget *_central_widget; - QVBoxLayout *_vertical_layout; + pv::view::View *_view; + dialogs::DSMessageBox *_msg; - toolbars::SamplingBar *_sampling_bar; - toolbars::TrigBar *_trig_bar; - toolbars::FileBar *_file_bar; - toolbars::LogoBar *_logo_bar; //help button, on top right + QMenuBar *_menu_bar; + QMenu *_menu_file; + QAction *_action_open; + QAction *_action_connect; + QAction *_action_quit; + + QMenu *_menu_view; + QAction *_action_view_zoom_in; + QAction *_action_view_zoom_out; + QAction *_action_view_show_cursors; + + QMenu *_menu_help; + QAction *_action_about; + + QWidget *_central_widget; + QVBoxLayout *_vertical_layout; + + toolbars::SamplingBar *_sampling_bar; + toolbars::TrigBar *_trig_bar; + toolbars::FileBar *_file_bar; + toolbars::LogoBar *_logo_bar; //help button, on top right - QDockWidget *_protocol_dock; - dock::ProtocolDock *_protocol_widget; + QDockWidget *_protocol_dock; + dock::ProtocolDock *_protocol_widget; + QDockWidget *_trigger_dock; + QDockWidget *_dso_trigger_dock; + dock::TriggerDock *_trigger_widget; + dock::DsoTriggerDock *_dso_trigger_widget; + QDockWidget *_measure_dock; + dock::MeasureDock *_measure_widget; + QDockWidget *_search_dock; + dock::SearchDock *_search_widget; - - QDockWidget *_trigger_dock; - QDockWidget *_dso_trigger_dock; - dock::TriggerDock *_trigger_widget; - dock::DsoTriggerDock *_dso_trigger_widget; - QDockWidget *_measure_dock; - dock::MeasureDock *_measure_widget; - QDockWidget *_search_dock; - dock::SearchDock * _search_widget; - - QTranslator _qtTrans; - QTranslator _myTrans; + QTranslator _qtTrans; + QTranslator _myTrans; + EventObject _event; }; } // namespace pv diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index a42432db..99a41300 100755 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -23,7 +23,6 @@ #include - #include "sigsession.h" #include "mainwindow.h" #include "devicemanager.h" @@ -55,23 +54,13 @@ #include #include -#include - +#include #include -#include -#include -#include -#include -#include -#include -#include - +#include #include "data/decode/decoderstatus.h" #include "dsvdef.h" - -using namespace boost; namespace pv { @@ -103,7 +92,7 @@ SigSession::SigSession(DeviceManager *device_manager) _data_lock = false; _data_updated = false; - _decoder_model = new pv::data::DecoderModel(this); + _decoder_model = new pv::data::DecoderModel(NULL); _lissajous_trace = NULL; _math_trace = NULL; @@ -112,6 +101,7 @@ SigSession::SigSession(DeviceManager *device_manager) _stop_scale = 1; _bDecodeRunning = false; _bClose = false; + _callback = NULL; // Create snapshots & data containers _logic_data = new data::Logic(new data::LogicSnapshot()); @@ -120,12 +110,11 @@ SigSession::SigSession(DeviceManager *device_manager) _group_data = new data::Group(); _group_cnt = 0; - _feed_timer.stop(); - - connect(&_feed_timer, SIGNAL(timeout()), this, SLOT(feed_timeout())); + _feed_timer.Stop(); + _feed_timer.SetCallback(std::bind(&SigSession::feed_timeout, this)); } -//SigSession::SigSession(SigSession &o){(void)o;} +SigSession::SigSession(SigSession &o){(void)o;} SigSession::~SigSession() { @@ -181,7 +170,7 @@ void SigSession::set_device(DevInst *dev_inst) return; } sr_session_datafeed_callback_add(data_feed_in_proc, NULL); - device_setted(); + _callback->device_setted(); } } @@ -217,7 +206,7 @@ void SigSession::close_file(DevInst *dev_inst) } } -void SigSession::set_default_device(boost::function error_handler) +void SigSession::set_default_device() { assert(_device_manager); @@ -240,7 +229,7 @@ void SigSession::set_default_device(boost::function error_ try { set_device(default_device); } catch(const QString e) { - error_handler(e); + _callback->show_error(e); return; } } @@ -252,14 +241,14 @@ void SigSession::release_device(DevInst *dev_inst) return; assert(dev_inst); - assert(_dev_inst == dev_inst); + // assert(_dev_inst == dev_inst); assert(get_capture_state() != Running); _dev_inst = NULL; } SigSession::capture_state SigSession::get_capture_state() -{ +{ std::lock_guard lock(_sampling_mutex); return _capture_state; } @@ -327,7 +316,7 @@ void SigSession::set_cur_snap_samplerate(uint64_t samplerate) for(auto & m : _spectrum_traces) m->get_spectrum_stack()->set_samplerate(_cur_snap_samplerate); - cur_snap_samplerate_changed(); + _callback->cur_snap_samplerate_changed(); } void SigSession::set_cur_samplelimits(uint64_t samplelimits) @@ -343,7 +332,7 @@ void SigSession::capture_init() set_repeating(get_run_mode() == Repetitive); // update instant setting _dev_inst->set_config(NULL, NULL, SR_CONF_INSTANT, g_variant_new_boolean(_instant)); - update_capture(); + _callback->update_capture(); set_cur_snap_samplerate(_dev_inst->get_sample_rate()); set_cur_samplelimits(_dev_inst->get_sample_limit()); @@ -354,9 +343,9 @@ void SigSession::capture_init() _hw_replied = false; if (_dev_inst->dev_inst()->mode != LOGIC) - _feed_timer.start(FeedInterval); + _feed_timer.Start(FeedInterval); else - _feed_timer.stop(); + _feed_timer.Stop(); _noData_cnt = 0; data_unlock(); @@ -419,8 +408,7 @@ void SigSession::container_init() } -void SigSession::start_capture(bool instant, - boost::function error_handler) +void SigSession::start_capture(bool instant) { // Check that a device instance has been selected. if (!_dev_inst) { @@ -432,7 +420,7 @@ void SigSession::start_capture(bool instant, if (!_dev_inst->is_usable()) { _error = Hw_err; - session_error(); + _callback->session_error(); capture_state_changed(SigSession::Stopped); return; } @@ -468,7 +456,7 @@ void SigSession::start_capture(bool instant, break; } if (!l) { - error_handler(tr("No probes enabled.")); + _callback->show_error("No probes enabled."); data_updated(); set_repeating(false); capture_state_changed(SigSession::Stopped); @@ -478,29 +466,25 @@ void SigSession::start_capture(bool instant, if (_sampling_thread.joinable()){ _sampling_thread.join(); } - _sampling_thread = std::thread(&SigSession::sample_thread_proc, this, _dev_inst, error_handler); + _sampling_thread = std::thread(&SigSession::sample_thread_proc, this, _dev_inst); } -void SigSession::sample_thread_proc(DevInst *dev_inst, - boost::function error_handler) +void SigSession::sample_thread_proc(DevInst *dev_inst) { assert(dev_inst); assert(dev_inst->dev_inst()); - assert(error_handler); try { dev_inst->start(); } catch(const QString e) { - error_handler(e); + _callback->show_error(e); return; } receive_data(0); set_capture_state(Running); - dev_inst->run(); - set_capture_state(Stopped); // Confirm that SR_DF_END was received @@ -564,8 +548,7 @@ std::vector& SigSession::get_group_signals() } std::set SigSession::get_data() -{ - //lock_guard lock(_signals_mutex); +{ std::set data; for(auto &sig : _signals) { @@ -582,7 +565,7 @@ bool SigSession::get_instant() } void SigSession::set_capture_state(capture_state state) -{ +{ std::lock_guard lock(_sampling_mutex); _capture_state = state; data_updated(); @@ -766,7 +749,6 @@ void SigSession::init_signals() spectrum_rebuild(); lissajous_disable(); math_disable(); - //data_updated(); } void SigSession::reload() @@ -776,66 +758,72 @@ void SigSession::reload() if (_capture_state == Running) stop_capture(); - //refresh(0); std::vector sigs; view::Signal *signal = NULL; // Make the logic probe list + for (GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { - for (GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { - sr_channel *probe = - (sr_channel *)l->data; - assert(probe); - signal = NULL; + sr_channel *probe = + (sr_channel *)l->data; + assert(probe); + signal = NULL; - switch(probe->type) { - case SR_CHANNEL_LOGIC: - if (probe->enabled) { - auto i = _signals.begin(); - while (i != _signals.end()) { - if ((*i)->get_index() == probe->index) { - view::LogicSignal *logicSig = NULL; - if ((logicSig = dynamic_cast(*i))) - signal = new view::LogicSignal(logicSig, _logic_data, probe); - break; - } - i++; + switch (probe->type) + { + case SR_CHANNEL_LOGIC: + if (probe->enabled) + { + auto i = _signals.begin(); + while (i != _signals.end()) + { + if ((*i)->get_index() == probe->index) + { + view::LogicSignal *logicSig = NULL; + if ((logicSig = dynamic_cast(*i))) + signal = new view::LogicSignal(logicSig, _logic_data, probe); + break; } - if (signal == NULL){ - signal = new view::LogicSignal(_dev_inst, _logic_data, probe); - } + i++; } - break; - - - case SR_CHANNEL_ANALOG: - if (probe->enabled) { - auto i = _signals.begin(); - while (i != _signals.end()) { - if ((*i)->get_index() == probe->index) { - view::AnalogSignal *analogSig = NULL; - if ((analogSig = dynamic_cast(*i))) - signal = new view::AnalogSignal(analogSig, _analog_data, probe); - break; - } - i++; - } - if (signal == NULL){ - signal = new view::AnalogSignal(_dev_inst, _analog_data, probe); - } - + if (signal == NULL) + { + signal = new view::LogicSignal(_dev_inst, _logic_data, probe); } - break; } - if (signal != NULL) - sigs.push_back(signal); - } + break; - if (!sigs.empty()) { - RELEASE_ARRAY(_signals); - std::vector().swap(_signals); - _signals = sigs; + case SR_CHANNEL_ANALOG: + if (probe->enabled) + { + auto i = _signals.begin(); + while (i != _signals.end()) + { + if ((*i)->get_index() == probe->index) + { + view::AnalogSignal *analogSig = NULL; + if ((analogSig = dynamic_cast(*i))) + signal = new view::AnalogSignal(analogSig, _analog_data, probe); + break; + } + i++; + } + if (signal == NULL) + { + signal = new view::AnalogSignal(_dev_inst, _analog_data, probe); + } + } + break; } + if (signal != NULL) + sigs.push_back(signal); + } + + if (!sigs.empty()) + { + RELEASE_ARRAY(_signals); + std::vector().swap(_signals); + _signals = sigs; } spectrum_rebuild(); @@ -872,9 +860,8 @@ void SigSession::refresh(int holdtime) if (_analog_data) { _analog_data->init(); } - - QTimer::singleShot(holdtime, this, SLOT(feed_timeout())); - //data_updated(); + + _out_timer.TimeOut(holdtime, std::bind(&SigSession::feed_timeout, this)); _data_updated = true; } @@ -912,7 +899,7 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) { (void)sdi; _trigger_pos = 0; - receive_header(); + _callback->receive_header(); } void SigSession::feed_in_meta(const sr_dev_inst *sdi, @@ -941,7 +928,7 @@ void SigSession::feed_in_trigger(const ds_trigger_pos &trigger_pos) _trigger_flag = (trigger_pos.status & 0x01); if (_trigger_flag) { _trigger_pos = trigger_pos.real_pos; - receive_trigger(_trigger_pos); + _callback->receive_trigger(_trigger_pos); } } else { int probe_count = 0; @@ -956,7 +943,7 @@ void SigSession::feed_in_trigger(const ds_trigger_pos &trigger_pos) } } _trigger_pos = trigger_pos.real_pos * probe_count / probe_en_count; - receive_trigger(_trigger_pos); + _callback->receive_trigger(_trigger_pos); } } @@ -970,7 +957,7 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) if (logic.data_error == 1) { _error = Test_data_err; _error_pattern = logic.error_pattern; - session_error(); + _callback->session_error(); } if (_logic_data->snapshot()->last_ended()) { @@ -979,7 +966,7 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) // for logic will be notified. Currently the only user of // frame_began is DecoderStack, but in future we need to signal // this after both analog and logic sweeps have begun. - frame_began(); + _callback->frame_began(); } else { // Append to the existing data snapshot _logic_data->snapshot()->append_payload(logic); @@ -987,13 +974,14 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) if (_logic_data->snapshot()->memory_failed()) { _error = Malloc_err; - session_error(); + _callback->session_error(); return; } - emit receive_data(logic.length * 8 / get_ch_num(SR_CHANNEL_LOGIC)); - data_received(); - //data_updated(); + receive_data(logic.length * 8 / get_ch_num(SR_CHANNEL_LOGIC)); + + _callback->data_received(); + _data_updated = true; } @@ -1040,7 +1028,7 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso) if (_dso_data->snapshot()->memory_failed()) { _error = Malloc_err; - session_error(); + _callback->session_error(); return; } @@ -1098,12 +1086,11 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) if (_analog_data->snapshot()->memory_failed()) { _error = Malloc_err; - session_error(); + _callback->session_error(); return; } receive_data(analog.num_samples); - //data_updated(); _data_updated = true; } @@ -1121,7 +1108,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, if (packet->type != SR_DF_END && packet->status != SR_PKT_OK) { _error = Pkt_data_err; - session_error(); + _callback->session_error(); return; } @@ -1160,7 +1147,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, { if (_error == No_err) { _error = Data_overflow; - session_error(); + _callback->session_error(); } break; } @@ -1190,10 +1177,10 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, if (packet->status != SR_PKT_OK) { _error = Pkt_data_err; - session_error(); + _callback->session_error(); } - frame_ended(); + _callback->frame_ended(); if (get_device()->dev_inst()->mode != LOGIC){ set_session_time(QDateTime::currentDateTime()); @@ -1235,11 +1222,9 @@ int SigSession::hotplug_callback(struct libusb_context *ctx, struct libusb_devic return 0; } -void SigSession::hotplug_proc(boost::function error_handler) +void SigSession::hotplug_proc() { - struct timeval tv; - - (void)error_handler; + struct timeval tv; if (!_dev_inst) return; @@ -1250,12 +1235,12 @@ void SigSession::hotplug_proc(boost::function error_handle libusb_handle_events_timeout(NULL, &tv); if (_hot_attach) { qDebug("DreamSourceLab hardware attached!"); - device_attach(); + _callback->device_attach(); _hot_attach = false; } if (_hot_detach) { qDebug("DreamSourceLab hardware detached!"); - device_detach(); + _callback->device_detach(); _hot_detach = false; } std::this_thread::sleep_for(std::chrono::milliseconds(100)); @@ -1285,7 +1270,7 @@ void SigSession::deregister_hotplug_callback() libusb_hotplug_deregister_callback(NULL, _hotplug_handle); } -void SigSession::start_hotplug_work(boost::function error_handler) +void SigSession::start_hotplug_work() { // Begin the session @@ -1296,7 +1281,7 @@ void SigSession::start_hotplug_work(boost::function error_ if (_hotplug_thread.joinable()){ return; } - _hotplug_thread = std::thread(&SigSession::hotplug_proc, this, error_handler); + _hotplug_thread = std::thread(&SigSession::hotplug_proc, this); } void SigSession::stop_hotplug_work() @@ -1563,7 +1548,7 @@ void SigSession::nodata_timeout() if (gvar == NULL) return; if (g_variant_get_byte(gvar) != DSO_TRIGGER_AUTO) { - show_wait_trigger(); + _callback->show_wait_trigger(); } } @@ -1651,8 +1636,8 @@ bool SigSession::repeat_check() if (_dev_inst->dev_inst()->mode == LOGIC) { _repeat_hold_prg = 100; - repeat_hold(_repeat_hold_prg); - QTimer::singleShot(_repeat_intvl*1000/RepeatHoldDiv, this, SLOT(repeat_update())); + _callback->repeat_hold(_repeat_hold_prg); + _out_timer.TimeOut(_repeat_intvl*1000/RepeatHoldDiv, std::bind(&SigSession::repeat_update, this)); return true; } else { return false; @@ -1663,9 +1648,10 @@ void SigSession::repeat_update() { if (isRepeating()) { _repeat_hold_prg -= 100/RepeatHoldDiv; - if (_repeat_hold_prg != 0) - QTimer::singleShot(_repeat_intvl*1000/RepeatHoldDiv, this, SLOT(repeat_update())); - repeat_hold(_repeat_hold_prg); + if (_repeat_hold_prg != 0){ + _out_timer.TimeOut(_repeat_intvl*1000/RepeatHoldDiv, std::bind(&SigSession::repeat_update, this)); + } + _callback->repeat_hold(_repeat_hold_prg); if (_repeat_hold_prg == 0) repeat_resume(); } diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index c5f97439..16864adb 100755 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -24,30 +24,20 @@ #define DSVIEW_PV_SIGSESSION_H #include -#include - -#include -#include -#include + #include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#include +#include #include +#include +#include #include "view/mathtrace.h" #include "data/mathstack.h" +#include "interface/icallbacks.h" +#include "dstimer.h" struct srd_decoder; struct srd_channel; @@ -96,10 +86,8 @@ class DecoderFactory; using namespace pv::device; //created by MainWindow -class SigSession : public QObject +class SigSession { - Q_OBJECT - private: static constexpr float Oversampling = 2.0f; static const int RefreshTime = 500; @@ -132,7 +120,7 @@ public: }; private: - // SigSession(SigSession &o); + SigSession(SigSession &o); public: explicit SigSession(DeviceManager *device_manager); @@ -145,95 +133,60 @@ public: * Sets device instance that will be used in the next capture session. */ void set_device(DevInst *dev_inst); - void deselect_device(); - void set_file(QString name); - void close_file(DevInst *dev_inst); - - void set_default_device(boost::function error_handler); + void set_default_device(); void release_device(DevInst *dev_inst); - capture_state get_capture_state(); - uint64_t cur_samplerate(); - uint64_t cur_snap_samplerate(); - uint64_t cur_samplelimits(); double cur_sampletime(); - double cur_snap_sampletime(); - double cur_view_time(); void set_cur_snap_samplerate(uint64_t samplerate); - void set_cur_samplelimits(uint64_t samplelimits); - void set_session_time(QDateTime time); QDateTime get_session_time(); - uint64_t get_trigger_pos(); - - void start_capture(bool instant, boost::function error_handler); - + bool get_capture_status(bool &triggered, int &progress); - void container_init(); - + void container_init(); std::set get_data(); - std::vector& get_signals(); - std::vector& get_group_signals(); bool add_decoder(srd_decoder *const dec, bool silent, DecoderStatus *dstatus); - - void remove_decoder(int index); - + void remove_decoder(int index); std::vector& get_decode_signals(); - void rst_decoder(int index); - + void rst_decoder(int index); pv::data::DecoderModel* get_decoder_model(); - std::vector& get_spectrum_traces(); - view::LissajousTrace* get_lissajous_trace(); - view::MathTrace* get_math_trace(); void init_signals(); - void add_group(); - void del_group(); - - void start_hotplug_work(boost::function error_handler); - - void stop_hotplug_work(); - + void start_hotplug_work(); + void stop_hotplug_work(); uint16_t get_ch_num(int type); bool get_instant(); - bool get_data_lock(); - void data_auto_lock(int lock); - void data_auto_unlock(); - bool get_data_auto_lock(); void spectrum_rebuild(); - void lissajous_rebuild(bool enable, int xindex, int yindex, double percent); - void lissajous_disable(); void math_rebuild(bool enable,pv::view::DsoSignal *dsoSig1, @@ -241,91 +194,104 @@ public: data::MathStack::MathType type); void math_disable(); - bool trigd(); - uint8_t trigd_ch(); - data::Snapshot* get_snapshot(int type); - error_state get_error(); - void set_error(error_state state); - void clear_error(); uint64_t get_error_pattern(); - run_mode get_run_mode(); - void set_run_mode(run_mode mode); - int get_repeat_intvl(); - void set_repeat_intvl(int interval); bool isRepeating(); - bool repeat_check(); - int get_repeat_hold(); - int get_map_zoom(); - void set_save_start(uint64_t start); void set_save_end(uint64_t end); - uint64_t get_save_start(); - uint64_t get_save_end(); - bool get_saving(); void set_saving(bool saving); - void set_stop_scale(float scale); - float stop_scale(); void exit_capture(); - sr_dev_inst* get_dev_inst_c(); - void Open(); - void Close(); - void clear_all_decoder(); inline bool is_closed(){ return _bClose; } + + inline void set_callback(ISessionCallback *callback){ + _callback = callback; + } + +public: + inline void capture_state_changed(int state){ + _callback->capture_state_changed(state); + } + + inline void session_save(){ + _callback->session_save(); + } + + inline void repeat_resume(){ + _callback->repeat_resume(); + } + + inline void show_region(uint64_t start, uint64_t end, bool keep){ + _callback->show_region(start, end, keep); + } + + inline void decode_done(){ + _callback->decode_done(); + } + +private: + inline void data_updated(){ + _callback->data_updated(); + } + + inline void signals_changed(){ + _callback->signals_changed(); + } + + inline void receive_data(quint64 len){ + _callback->receive_data_len(len); + } private: void set_capture_state(capture_state state); - void register_hotplug_callback(); - void deregister_hotplug_callback(); bool do_add_decoder(srd_decoder *const dec, bool silent, DecoderStatus *dstatus); void add_decode_task(view::DecodeTrace *trace); - void remove_decode_task(view::DecodeTrace *trace); + void clear_all_decode_task(int &runningDex); - void clear_all_decode_task(int &runningDex); - view::DecodeTrace* get_decoder_trace(int index); - void decode_task_proc(); + view::DecodeTrace* get_top_decode_task(); - view::DecodeTrace* get_top_decode_task(); - void capture_init(); - void do_stop_capture(); + void data_lock(); + void data_unlock(); + void nodata_timeout(); + void feed_timeout(); + void repeat_update(); private: /** @@ -337,14 +303,8 @@ private: */ static sr_input_format* determine_input_file_format( const std::string &filename); - - static sr_input* load_input_file_format( - const std::string &filename, - boost::function error_handler, - sr_input_format *format = NULL); - - void sample_thread_proc(DevInst *dev_inst, - boost::function error_handler); + + void sample_thread_proc(DevInst *dev_inst); // data feed void feed_in_header(const sr_dev_inst *sdi); @@ -367,87 +327,20 @@ private: const struct sr_datafeed_packet *packet, void *cb_data); // thread for hotplug - void hotplug_proc(boost::function error_handler); + void hotplug_proc(); static int hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev, libusb_hotplug_event event, void *user_data); - - -signals: - void capture_state_changed(int state); - - void signals_changed(); - - void data_updated(); - - void receive_data(quint64 length); - - void device_attach(); - - void device_detach(); - - void receive_trigger(quint64 trigger_pos); - - void receive_header(); - - void dso_ch_changed(uint16_t num); - - void frame_began(); - - void data_received(); - - void frame_ended(); - - void device_setted(); - - void zero_adj(); - - void progressSaveFileValueChanged(int percent); - - void decode_done(); - - void show_region(uint64_t start, uint64_t end, bool keep); - - void show_wait_trigger(); - - void session_save(); - - void session_error(); - - void repeat_hold(int percent); - - void repeat_resume(); - - void cur_snap_samplerate_changed(); - - void update_capture(); - -public slots: +public: void reload(); - void refresh(int holdtime); - + void start_capture(bool instant); void stop_capture(); - void check_update(); - // repeat void set_repeating(bool repeat); - void set_map_zoom(int index); - // OSC auto - void auto_end(); - -private slots: - void data_lock(); - - void data_unlock(); - - void nodata_timeout(); - - void feed_timeout(); - - void repeat_update(); + void auto_end(); private: DeviceManager *_device_manager; @@ -494,7 +387,8 @@ private: bool _hot_attach; bool _hot_detach; - QTimer _feed_timer; + DsTimer _feed_timer; + DsTimer _out_timer; int _noData_cnt; bool _data_lock; bool _data_updated; @@ -524,6 +418,8 @@ private: float _stop_scale; bool _bClose; + ISessionCallback *_callback; + private: // TODO: This should not be necessary. Multiple concurrent // sessions should should be supported and it should be diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 1540affb..eee40b78 100755 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -43,6 +43,14 @@ #include #include +#include +#include +#include +#include +#include +#include +#include + #include "config/appconfig.h" diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index 0262e0ac..fb708f96 100755 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -19,18 +19,17 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - +#include #include #include +#include +#include #include "filebar.h" #include "../device/devinst.h" #include "../ui/msgbox.h" #include "../config/appconfig.h" -#include - namespace pv { namespace toolbars { diff --git a/DSView/pv/toolbars/logobar.cpp b/DSView/pv/toolbars/logobar.cpp index 4c65cf41..01da8850 100755 --- a/DSView/pv/toolbars/logobar.cpp +++ b/DSView/pv/toolbars/logobar.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "logobar.h" #include "../dialogs/about.h" diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 59fbcb42..ff193b4c 100755 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "../devicemanager.h" #include "../device/devinst.h" @@ -814,6 +815,7 @@ void SamplingBar::commit_settings() } } +//start or stop capture void SamplingBar::on_run_stop() { if (get_sampling() || _session->isRepeating()) { @@ -886,14 +888,16 @@ void SamplingBar::on_instant_stop() if (dev_inst->dev_inst()->mode == DSO) { GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO); + if (gvar != NULL) { bool zero = g_variant_get_boolean(gvar); g_variant_unref(gvar); + if (zero) { dialogs::DSMessageBox msg(this); msg.mBox()->setText(tr("Auto Calibration")); msg.mBox()->setInformativeText(tr("Auto Calibration program will be started. Don't connect any probes. It can take a while!")); - //msg.mBox()->setStandardButtons(QMessageBox::Ok); + msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole); msg.mBox()->setIcon(QMessageBox::Warning); diff --git a/DSView/pv/toolbars/trigbar.cpp b/DSView/pv/toolbars/trigbar.cpp index 2d6cdf29..4666c88b 100755 --- a/DSView/pv/toolbars/trigbar.cpp +++ b/DSView/pv/toolbars/trigbar.cpp @@ -20,15 +20,17 @@ */ #include "trigbar.h" + +#include +#include +#include + #include "../sigsession.h" #include "../device/devinst.h" #include "../dialogs/fftoptions.h" #include "../dialogs/lissajousoptions.h" #include "../dialogs/mathoptions.h" #include "../view/trace.h" - -#include -#include #include "../dialogs/applicationpardlg.h" #include "../config/appconfig.h" diff --git a/DSView/pv/view/analogsignal.cpp b/DSView/pv/view/analogsignal.cpp index 745834ad..1419046a 100755 --- a/DSView/pv/view/analogsignal.cpp +++ b/DSView/pv/view/analogsignal.cpp @@ -21,7 +21,7 @@ */ #include - +#include #include #include "../view/analogsignal.h" @@ -30,6 +30,7 @@ #include "../view/view.h" #include "../device/devinst.h" + using namespace std; #define byte(x) uint##x##_t diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index f4d748ba..24b69243 100755 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -31,6 +31,8 @@ #include "../device/devinst.h" #include #include +#include +#include using namespace std; @@ -1457,8 +1459,8 @@ void DsoSignal::auto_start() _view->session().data_auto_lock(AutoLock); _autoV = true; _autoH = true; - _view->auto_trig(get_index()); - QTimer::singleShot(AutoTime, &_view->session(), SLOT(auto_end())); + _view->auto_trig(get_index()); + _end_timer.TimeOut(AutoTime, std::bind(&DsoSignal::call_auto_end, this)); //start a timeout } } @@ -1572,5 +1574,9 @@ QString DsoSignal::get_time(double t) return str; } +void DsoSignal::call_auto_end(){ + _view->session().auto_end(); +} + } // namespace view } // namespace pv diff --git a/DSView/pv/view/dsosignal.h b/DSView/pv/view/dsosignal.h index 2cdd8bde..606cd5ba 100755 --- a/DSView/pv/view/dsosignal.h +++ b/DSView/pv/view/dsosignal.h @@ -24,6 +24,7 @@ #define DSVIEW_PV_DSOSIGNAL_H #include "signal.h" +#include "../dstimer.h" namespace pv { namespace data { @@ -107,8 +108,7 @@ public: bool get_vDialActive(); void set_vDialActive(bool active); bool go_vDialPre(bool manul); - bool go_vDialNext(bool manul); - bool update_capture(bool instant); + bool go_vDialNext(bool manul); dslDial *get_vDial(); uint64_t get_vDialValue(); uint16_t get_vDialSel(); @@ -227,6 +227,8 @@ private: void paint_hover_measure(QPainter &p, QColor fore, QColor back); void auto_set(); + void call_auto_end(); + private: pv::data::Dso *_data; float _scale; @@ -268,6 +270,7 @@ private: uint64_t _hover_index; QPointF _hover_point; float _hover_value; + DsTimer _end_timer; }; } // namespace view diff --git a/DSView/pv/view/spectrumtrace.cpp b/DSView/pv/view/spectrumtrace.cpp index 3115bf33..8e6bb11e 100755 --- a/DSView/pv/view/spectrumtrace.cpp +++ b/DSView/pv/view/spectrumtrace.cpp @@ -21,8 +21,7 @@ #include #include #include - - +#include #include #include "spectrumtrace.h" diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 91b53b5b..1728e03e 100755 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -117,7 +117,6 @@ View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget _devmode = new DevMode(this, session); setViewportMargins(headerWidth(), RulerHeight, 0, 0); - //setViewport(_viewport); // windows splitter _time_viewport = new Viewport(*this, TIME_VIEW); @@ -184,21 +183,22 @@ View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget connect(_fft_viewport, SIGNAL(measure_updated()), this, SLOT(on_measure_updated())); connect(_vsplitter, SIGNAL(splitterMoved(int,int)), this, SLOT(splitterMoved(int, int))); - connect(_session, SIGNAL(device_setted()), _devmode, SLOT(set_device())); - connect(_session, SIGNAL(signals_changed()), this, SLOT(signals_changed()), Qt::DirectConnection); - connect(_session, SIGNAL(data_updated()), this, SLOT(data_updated())); - connect(_session, SIGNAL(receive_trigger(quint64)), this, SLOT(receive_trigger(quint64))); - connect(_session, SIGNAL(frame_ended()), this, SLOT(receive_end())); - connect(_session, SIGNAL(frame_began()), this, SLOT(frame_began())); - connect(_session, SIGNAL(show_region(uint64_t, uint64_t, bool)), this, SLOT(show_region(uint64_t, uint64_t, bool))); - - connect(_session, SIGNAL(show_wait_trigger()), _time_viewport, SLOT(show_wait_trigger())); - connect(_session, SIGNAL(repeat_hold(int)), this, SLOT(repeat_show())); + connect(_devmode, SIGNAL(dev_changed(bool)),this, SLOT(dev_changed(bool)), Qt::DirectConnection); connect(_header, SIGNAL(traces_moved()),this, SLOT(on_traces_moved())); connect(_header, SIGNAL(header_updated()),this, SLOT(header_updated())); } +void View::show_wait_trigger() +{ + _time_viewport->show_wait_trigger(); +} + +void View::set_device() +{ + _devmode->set_device(); +} + SigSession& View::session() { return *_session; @@ -1313,5 +1313,14 @@ uint64_t View::pixel2index(double pixel) return index; } +void View::set_receive_len(uint64_t len) +{ + if (_time_viewport) + _time_viewport->set_receive_len(len); + + if (_fft_viewport) + _fft_viewport->set_receive_len(len); +} + } // namespace view } // namespace pv diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index f5e8ea10..a807dd85 100755 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -306,6 +306,12 @@ public slots: // void header_updated(); + void receive_trigger(quint64 trig_pos); + + void receive_end(); + + void frame_began(); + private slots: void h_scroll_value_changed(int value); @@ -315,13 +321,9 @@ private slots: void on_traces_moved(); - void receive_trigger(quint64 trig_pos); + void set_trig_pos(int percent); - - void receive_end(); - - void frame_began(); - + // calibration for oscilloscope void show_calibration(); // lissajous figure @@ -332,59 +334,65 @@ private slots: void dev_changed(bool close); +public: + void show_wait_trigger(); + void set_device(); + void set_receive_len(uint64_t len); + private: - SigSession *_session; - pv::toolbars::SamplingBar *_sampling_bar; + SigSession *_session; + pv::toolbars::SamplingBar *_sampling_bar; - QWidget *_viewcenter; - ViewStatus *_viewbottom; - QSplitter *_vsplitter; - Viewport * _time_viewport; - Viewport * _fft_viewport; - LissajousFigure *_lissajous; - Viewport *_active_viewport; - std::list _viewport_list; - std::map _trace_view_map; - Ruler *_ruler; - Header *_header; - DevMode *_devmode; + QWidget *_viewcenter; + ViewStatus *_viewbottom; + QSplitter *_vsplitter; + Viewport *_time_viewport; + Viewport *_fft_viewport; + Viewport *_active_viewport; + LissajousFigure *_lissajous; + std::list _viewport_list; + std::map _trace_view_map; + Ruler *_ruler; + Header *_header; + DevMode *_devmode; + /// The view time scale in seconds per pixel. - double _scale; - double _preScale; - double _maxscale; - double _minscale; + double _scale; + double _preScale; + double _maxscale; + double _minscale; /// The pixels offset of the left edge of the view - int64_t _offset; - int64_t _preOffset; - int _spanY; - int _signalHeight; - bool _updating_scroll; + int64_t _offset; + int64_t _preOffset; + int _spanY; + int _signalHeight; + bool _updating_scroll; // trigger position fix - double _trig_hoff; + double _trig_hoff; - bool _show_cursors; + bool _show_cursors; std::list _cursorList; - Cursor *_trig_cursor; - bool _show_trig_cursor; - Cursor *_search_cursor; - bool _show_search_cursor; - uint64_t _search_pos; - bool _search_hit; + Cursor *_trig_cursor; + bool _show_trig_cursor; + Cursor *_search_cursor; + bool _show_search_cursor; + uint64_t _search_pos; + bool _search_hit; - bool _show_xcursors; + bool _show_xcursors; std::list _xcursorList; - QPoint _hover_point; + QPoint _hover_point; dialogs::Calibration *_cali; - bool _dso_auto; - bool _show_lissajous; - bool _back_ready; - bool _trig_time_setted; + bool _dso_auto; + bool _show_lissajous; + bool _back_ready; + bool _trig_time_setted; }; } // namespace view diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index fcd8baad..3ca32160 100755 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -98,8 +98,7 @@ Viewport::Viewport(View &parent, View_type type) : setContextMenuPolicy(Qt::CustomContextMenu); connect(&trigger_timer, SIGNAL(timeout()),this, SLOT(on_trigger_timer())); - connect(&_drag_timer, SIGNAL(timeout()),this, SLOT(on_drag_timer())); - connect(&_view.session(), &SigSession::receive_data, this, &Viewport::set_receive_len); + connect(&_drag_timer, SIGNAL(timeout()),this, SLOT(on_drag_timer())); connect(yAction, SIGNAL(triggered(bool)), this, SLOT(add_cursor_y())); connect(xAction, SIGNAL(triggered(bool)), this, SLOT(add_cursor_x())); diff --git a/DSView/pv/view/viewport.h b/DSView/pv/view/viewport.h index 18b4dc4d..0ba08201 100755 --- a/DSView/pv/view/viewport.h +++ b/DSView/pv/view/viewport.h @@ -131,8 +131,7 @@ private: private slots: void on_trigger_timer(); void on_drag_timer(); - void set_receive_len(quint64 length); - + void show_contextmenu(const QPoint& pos); void add_cursor_x(); void add_cursor_y(); @@ -140,6 +139,7 @@ private slots: public slots: void show_wait_trigger(); void unshow_wait_trigger(); + void set_receive_len(quint64 length); signals: void measure_updated(); diff --git a/DSView/pv/view/viewstatus.cpp b/DSView/pv/view/viewstatus.cpp index 6ca30b86..635c02d4 100755 --- a/DSView/pv/view/viewstatus.cpp +++ b/DSView/pv/view/viewstatus.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "../view/trace.h" #include "../sigsession.h"