diff --git a/DSView/pv/deviceagent.cpp b/DSView/pv/deviceagent.cpp index 1d0defe5..b01f65ba 100644 --- a/DSView/pv/deviceagent.cpp +++ b/DSView/pv/deviceagent.cpp @@ -29,6 +29,7 @@ DeviceAgent::DeviceAgent() _dev_handle = NULL; _di = NULL; _dev_type = 0; + _callback = NULL; } void DeviceAgent::update() @@ -258,52 +259,60 @@ bool DeviceAgent::get_status(struct sr_status &status, gboolean prg) } return false; } + +void DeviceAgent::config_changed() +{ + if (_callback != NULL){ + _callback->DeviceConfigChanged(); + } +} //---------------device config-----------/ - int DeviceAgent::get_work_mode() - { - return ds_get_actived_device_mode(); - } +int DeviceAgent::get_work_mode() +{ + return ds_get_actived_device_mode(); +} - const struct sr_config_info* DeviceAgent::get_config_info(int key) - { - return ds_get_actived_device_config_info(key); - } +const struct sr_config_info *DeviceAgent::get_config_info(int key) +{ + return ds_get_actived_device_config_info(key); +} - const struct sr_config_info* DeviceAgent::get_config_info_by_name(const char *optname) - { - return ds_get_actived_device_config_info_by_name(optname); - } +const struct sr_config_info *DeviceAgent::get_config_info_by_name(const char *optname) +{ + return ds_get_actived_device_config_info_by_name(optname); +} - bool DeviceAgent::get_device_status(struct sr_status &status, gboolean prg) +bool DeviceAgent::get_device_status(struct sr_status &status, gboolean prg) +{ + if (ds_get_actived_device_status(&status, prg) == SR_OK) { - if (ds_get_actived_device_status(&status, prg) == SR_OK){ - return true; - } - return false; + return true; } + return false; +} - struct sr_config* DeviceAgent::new_config(int key, GVariant *data) - { - return ds_new_config(key, data); - } +struct sr_config *DeviceAgent::new_config(int key, GVariant *data) +{ + return ds_new_config(key, data); +} - void DeviceAgent::free_config(struct sr_config *src) - { - ds_free_config(src); - } +void DeviceAgent::free_config(struct sr_config *src) +{ + ds_free_config(src); +} - bool DeviceAgent::is_running() - { - return ds_is_collecting() > 0; - } +bool DeviceAgent::is_collecting() +{ + return ds_is_collecting() > 0; +} - GSList* DeviceAgent::get_channels() - { - assert(_dev_handle); - return ds_get_actived_device_channels(); - } +GSList *DeviceAgent::get_channels() +{ + assert(_dev_handle); + return ds_get_actived_device_channels(); +} //---------------device config end -----------/ diff --git a/DSView/pv/deviceagent.h b/DSView/pv/deviceagent.h index cd96b224..818685f2 100644 --- a/DSView/pv/deviceagent.h +++ b/DSView/pv/deviceagent.h @@ -27,6 +27,12 @@ #include #include +class IDeviceAgentCallback +{ + public: + virtual void DeviceConfigChanged()=0; +}; + class DeviceAgent { public: @@ -62,7 +68,11 @@ public: inline bool is_hardware(){ return _dev_type == DEV_TYPE_USB; - } + } + + inline void set_callback(IDeviceAgentCallback *callback){ + _callback = callback; + } GVariant* get_config(const sr_channel *ch, const sr_channel_group *group, int key); @@ -123,13 +133,11 @@ public: bool have_enabled_channel(); - bool get_status(struct sr_status &status, gboolean prg); - - bool is_running(); + bool get_status(struct sr_status &status, gboolean prg); GSList* get_channels(); - /** + /** * Start collect data. */ bool start(); @@ -139,7 +147,10 @@ public: */ bool stop(); -protected: + bool is_collecting(); + +protected: + void config_changed(); //---------------device config-----------/ public: @@ -162,6 +173,7 @@ private: QString _dev_name; QString _driver_name; struct sr_dev_inst *_di; + IDeviceAgentCallback *_callback; }; diff --git a/DSView/pv/dialogs/deviceoptions.cpp b/DSView/pv/dialogs/deviceoptions.cpp index 6d4131cc..b7a65db3 100644 --- a/DSView/pv/dialogs/deviceoptions.cpp +++ b/DSView/pv/dialogs/deviceoptions.cpp @@ -147,8 +147,7 @@ DeviceOptions::DeviceOptions(QWidget *parent) : try_resize_scroll(); connect(&_mode_check, SIGNAL(timeout()), this, SLOT(mode_check())); - connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); - connect(_device_agent, SIGNAL(device_updated()), this, SLOT(reject())); + connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); _mode_check.setInterval(100); _mode_check.start(); diff --git a/DSView/pv/dialogs/dsdialog.h b/DSView/pv/dialogs/dsdialog.h index 1f586fe3..b8ab9903 100644 --- a/DSView/pv/dialogs/dsdialog.h +++ b/DSView/pv/dialogs/dsdialog.h @@ -29,7 +29,7 @@ #include #include "../toolbars/titlebar.h" -#include "../interface/uicallback.h" +#include "../interface/icallbacks.h" class QDialogButtonBox; diff --git a/DSView/pv/dialogs/dsomeasure.cpp b/DSView/pv/dialogs/dsomeasure.cpp index d9fb4a88..8d62bb76 100644 --- a/DSView/pv/dialogs/dsomeasure.cpp +++ b/DSView/pv/dialogs/dsomeasure.cpp @@ -77,7 +77,7 @@ DsoMeasure::DsoMeasure(SigSession *session, View &parent, connect(_button_box.button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); connect(_button_box.button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(reset())); - connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->device_event_object(), SIGNAL(device_updated()), this, SLOT(reject())); } DsoMeasure::~DsoMeasure(){ diff --git a/DSView/pv/dialogs/fftoptions.cpp b/DSView/pv/dialogs/fftoptions.cpp index 35a2f9d9..d1db5c47 100644 --- a/DSView/pv/dialogs/fftoptions.cpp +++ b/DSView/pv/dialogs/fftoptions.cpp @@ -220,7 +220,7 @@ FftOptions::FftOptions(QWidget *parent, SigSession *session) : connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); connect(_window_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(window_changed(int))); connect(_len_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(len_changed(int))); - connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->device_event_object(), SIGNAL(device_updated()), this, SLOT(reject())); } FftOptions::~FftOptions(){ @@ -243,12 +243,13 @@ void FftOptions::accept() spectrumTraces->get_spectrum_stack()->set_sample_interval(_interval_combobox->currentData().toInt()); spectrumTraces->get_spectrum_stack()->set_windows_index(_window_combobox->currentData().toInt()); spectrumTraces->set_view_mode(_view_combobox->currentData().toUInt()); - //spectrumTraces->init_zoom(); + spectrumTraces->set_dbv_range(_dbv_combobox->currentData().toInt()); spectrumTraces->set_enable(_en_checkbox->isChecked()); - if (_session->get_capture_state() == SigSession::Stopped && - spectrumTraces->enabled()) + + if (_session->is_stopped_status() && spectrumTraces->enabled()){ spectrumTraces->get_spectrum_stack()->calc_fft(); + } } } } diff --git a/DSView/pv/dialogs/interval.cpp b/DSView/pv/dialogs/interval.cpp index ee53ec3e..cb45e5da 100644 --- a/DSView/pv/dialogs/interval.cpp +++ b/DSView/pv/dialogs/interval.cpp @@ -26,9 +26,8 @@ namespace pv { namespace dialogs { -Interval::Interval(SigSession *session, QWidget *parent) : +Interval::Interval(QWidget *parent) : DSDialog(parent), - _session(session), _button_box(QDialogButtonBox::Ok, Qt::Horizontal, this) { @@ -36,6 +35,7 @@ Interval::Interval(SigSession *session, QWidget *parent) : _interval_spinBox = NULL; _interval_slider = NULL; _bSetting = false; + _bDone = false; setMinimumWidth(300); _interval_label = new QLabel(tr("Interval(s): "), this); @@ -46,9 +46,6 @@ Interval::Interval(SigSession *session, QWidget *parent) : _interval_slider = new QSlider(Qt::Horizontal, this); _interval_slider->setRange(0, 10); - _interval_slider->setValue((int)_session->get_repeat_intvl()); - _interval_spinBox->setValue(_session->get_repeat_intvl()); - QGridLayout *glayout = new QGridLayout(this); glayout->addWidget(_interval_label, 0, 0); glayout->addWidget(_interval_spinBox, 0, 1); @@ -66,7 +63,7 @@ Interval::Interval(SigSession *session, QWidget *parent) : void Interval::accept() { using namespace Qt; - _session->set_repeat_intvl(_interval_spinBox->value()); + _bDone = true; QDialog::accept(); } @@ -77,14 +74,24 @@ void Interval::reject() QDialog::reject(); } +void Interval::set_interval(double value) +{ + _interval_slider->setValue((int)value); + _interval_spinBox->setValue(value); +} + +double Interval::get_interval() +{ + return _interval_spinBox->value(); +} + void Interval::on_slider_changed(int value) { if (!_bSetting){ _bSetting = true; _interval_spinBox->setValue((double)value); _bSetting = false; - } - + } } void Interval::on_inputbox_changed(double value) @@ -93,8 +100,7 @@ void Interval::on_inputbox_changed(double value) _bSetting = true; _interval_slider->setValue((int)value); _bSetting = false; - } - + } } } // namespace dialogs diff --git a/DSView/pv/dialogs/interval.h b/DSView/pv/dialogs/interval.h index 421b9d2a..825c0330 100644 --- a/DSView/pv/dialogs/interval.h +++ b/DSView/pv/dialogs/interval.h @@ -40,25 +40,31 @@ class Interval : public DSDialog Q_OBJECT public: - Interval(SigSession *session, QWidget *parent); + Interval(QWidget *parent); + + void set_interval(double value); + double get_interval(); + + inline bool is_done(){ + return _bDone; + } protected: void accept(); - void reject(); - + void reject(); + private Q_SLOTS: void on_slider_changed(int value); void on_inputbox_changed(double value); private: - SigSession *_session; - QLabel *_interval_label; QDoubleSpinBox *_interval_spinBox; QSlider *_interval_slider; QDialogButtonBox _button_box; bool _bSetting; + bool _bDone; }; } // namespace dialogs diff --git a/DSView/pv/dialogs/protocolexp.cpp b/DSView/pv/dialogs/protocolexp.cpp index 7835ec84..30c712b4 100644 --- a/DSView/pv/dialogs/protocolexp.cpp +++ b/DSView/pv/dialogs/protocolexp.cpp @@ -97,7 +97,7 @@ ProtocolExp::ProtocolExp(QWidget *parent, SigSession *session) : connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); - connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->device_event_object(), SIGNAL(device_updated()), this, SLOT(reject())); } diff --git a/DSView/pv/dialogs/protocollist.cpp b/DSView/pv/dialogs/protocollist.cpp index 4144cc58..63803b51 100644 --- a/DSView/pv/dialogs/protocollist.cpp +++ b/DSView/pv/dialogs/protocollist.cpp @@ -90,7 +90,7 @@ ProtocolList::ProtocolList(QWidget *parent, SigSession *session) : connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(_protocol_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(set_protocol(int))); set_protocol(_protocol_combobox->currentIndex()); - connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->device_event_object(), SIGNAL(device_updated()), this, SLOT(reject())); } diff --git a/DSView/pv/dialogs/regionoptions.cpp b/DSView/pv/dialogs/regionoptions.cpp index 8c455d26..303d67b8 100644 --- a/DSView/pv/dialogs/regionoptions.cpp +++ b/DSView/pv/dialogs/regionoptions.cpp @@ -73,7 +73,7 @@ RegionOptions::RegionOptions(view::View *view, SigSession *session, QWidget *par setTitle(tr("Region")); connect(&_button_box, SIGNAL(accepted()), this, SLOT(set_region())); - connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->device_event_object(), SIGNAL(device_updated()), this, SLOT(reject())); } diff --git a/DSView/pv/dialogs/search.cpp b/DSView/pv/dialogs/search.cpp index ff630146..6a2ee47a 100644 --- a/DSView/pv/dialogs/search.cpp +++ b/DSView/pv/dialogs/search.cpp @@ -85,7 +85,6 @@ Search::Search(QWidget *parent, SigSession *session, std::map connect(&search_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(&search_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); } Search::~Search() diff --git a/DSView/pv/dialogs/waitingdialog.cpp b/DSView/pv/dialogs/waitingdialog.cpp index 1be4bbe4..9cfda143 100644 --- a/DSView/pv/dialogs/waitingdialog.cpp +++ b/DSView/pv/dialogs/waitingdialog.cpp @@ -79,8 +79,7 @@ WaitingDialog::WaitingDialog(QWidget *parent, SigSession *session, int key) : connect(timer, SIGNAL(timeout()), this, SLOT(changeText())); connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); - connect(_device_agent, SIGNAL(device_updated()), this, SLOT(stop())); - + connect(_session->device_event_object(), SIGNAL(device_updated()), this, SLOT(stop())); QVBoxLayout *mlayout = new QVBoxLayout(); mlayout->addWidget(warning_tips, Qt::AlignHCenter); diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index c5f8a6b7..d863a773 100644 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -52,9 +52,7 @@ MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) : QScrollArea(parent), _session(session), _view(view) -{ - _session->add_msg_listener(this); - +{ _widget = new QWidget(this); _mouse_groupBox = new QGroupBox(_widget); @@ -691,12 +689,5 @@ void MeasureDock::del_cursor() _view.update(); } -void MeasureDock::OnMessage(int msg) -{ - if (msg == DSV_MSG_DEVICE_OPTIONS_UPDATED){ - this->reload(); - } -} - } // namespace dock } // namespace pv diff --git a/DSView/pv/dock/measuredock.h b/DSView/pv/dock/measuredock.h index 37c316a5..a1a9369e 100644 --- a/DSView/pv/dock/measuredock.h +++ b/DSView/pv/dock/measuredock.h @@ -41,8 +41,7 @@ #include -#include "../ui/dscombobox.h" -#include "../interface/icallbacks.h" +#include "../ui/dscombobox.h" namespace pv { @@ -55,7 +54,7 @@ namespace view { namespace dock { -class MeasureDock : public QScrollArea, public IMessageListener +class MeasureDock : public QScrollArea { Q_OBJECT @@ -78,9 +77,6 @@ private: DsComboBox* create_probe_selector(QWidget *parent); void update_probe_selector(DsComboBox *selector); - //IMessageListener - void OnMessage(int msg); - private slots: void goto_cursor(); diff --git a/DSView/pv/dock/protocoldock.h b/DSView/pv/dock/protocoldock.h index 38ddd13d..57069289 100644 --- a/DSView/pv/dock/protocoldock.h +++ b/DSView/pv/dock/protocoldock.h @@ -70,8 +70,7 @@ namespace dock { class ProtocolDock : public QScrollArea, public IProtocolItemLayerCallback, public IKeywordActive, -public ISearchItemClick, -public IMessageListener +public ISearchItemClick { Q_OBJECT diff --git a/DSView/pv/dock/searchdock.cpp b/DSView/pv/dock/searchdock.cpp index 1bc914eb..7ec4fc27 100644 --- a/DSView/pv/dock/searchdock.cpp +++ b/DSView/pv/dock/searchdock.cpp @@ -51,12 +51,7 @@ SearchDock::SearchDock(QWidget *parent, View &view, SigSession *session) : QWidget(parent), _session(session), _view(view) -{ - connect(&_pre_button, SIGNAL(clicked()), - this, SLOT(on_previous())); - connect(&_nxt_button, SIGNAL(clicked()), - this, SLOT(on_next())); - +{ _search_button = new QPushButton(this); _search_button->setFixedWidth(_search_button->height()); _search_button->setDisabled(true); @@ -85,6 +80,9 @@ SearchDock::SearchDock(QWidget *parent, View &view, SigSession *session) : setLayout(layout); retranslateUi(); + + connect(&_pre_button, SIGNAL(clicked()), this, SLOT(on_previous())); + connect(&_nxt_button, SIGNAL(clicked()),this, SLOT(on_next())); } SearchDock::~SearchDock() @@ -248,6 +246,8 @@ void SearchDock::on_next() void SearchDock::on_set() { dialogs::Search dlg(this, _session, _pattern); + connect(_session->device_event_object(), SIGNAL(device_updated()), &dlg, SLOT(reject())); + if (dlg.exec()) { std::map new_pattern = dlg.get_pattern(); diff --git a/DSView/pv/dock/searchdock.h b/DSView/pv/dock/searchdock.h index d53c261e..a5178d56 100644 --- a/DSView/pv/dock/searchdock.h +++ b/DSView/pv/dock/searchdock.h @@ -67,6 +67,7 @@ public: ~SearchDock(); void paintEvent(QPaintEvent *); + private: void changeEvent(QEvent *event); void retranslateUi(); diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index 8d3858c2..9f3f2db4 100644 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -48,7 +48,6 @@ TriggerDock::TriggerDock(QWidget *parent, SigSession *session) : QScrollArea(parent), _session(session) { - session->add_msg_listener(this); _cur_ch_num = 16; if (_session->get_device()->have_instance()) { @@ -309,8 +308,9 @@ bool TriggerDock::commit_trigger() // trigger mode update if (_simple_radioButton->isChecked()) { ds_trigger_set_mode(SIMPLE_TRIGGER); - return 0; - } else { + return false; + } + else { ds_trigger_set_en(true); if (_adv_tabWidget->currentIndex() == 0) ds_trigger_set_mode(ADV_TRIGGER); @@ -402,7 +402,7 @@ bool TriggerDock::commit_trigger() _serial_bits_comboBox->currentText().toInt() - 1, 0); } - return 1; + return true; } } @@ -898,6 +898,8 @@ void TriggerDock::try_commit_trigger() int mode = _session->get_device()->get_work_mode(); bool bInstant = _session->is_instant(); + ds_trigger_reset(); + if (mode != LOGIC || bInstant){ return; } @@ -949,20 +951,5 @@ void TriggerDock::try_commit_trigger() } } -void TriggerDock::OnMessage(int msg) -{ - switch (msg) - { - case DSV_MSG_DEVICE_OPTIONS_UPDATED: - case DSV_MSG_DEVICE_DURATION_UPDATED: - case DSV_MSG_CURRENT_DEVICE_CHANGED: - device_updated(); - break; - case DSV_MSG_COLLECT_START_PREV: - try_commit_trigger(); - break; - } -} - } // namespace dock } // namespace pv diff --git a/DSView/pv/dock/triggerdock.h b/DSView/pv/dock/triggerdock.h index b599a01a..c02cad3e 100644 --- a/DSView/pv/dock/triggerdock.h +++ b/DSView/pv/dock/triggerdock.h @@ -42,8 +42,7 @@ #include -#include "../ui/dscombobox.h" -#include "../interface/icallbacks.h" +#include "../ui/dscombobox.h" namespace pv { @@ -51,7 +50,7 @@ class SigSession; namespace dock { -class TriggerDock : public QScrollArea, public IMessageListener +class TriggerDock : public QScrollArea { Q_OBJECT @@ -69,6 +68,10 @@ public: QJsonObject get_session(); void set_session(QJsonObject ses); + void device_updated(); + + void try_commit_trigger(); + private: void changeEvent(QEvent *event); void retranslateUi(); @@ -83,20 +86,14 @@ private: * 1: advanced trigger */ bool commit_trigger(); - - void try_commit_trigger(); - - //IMessageListener - void OnMessage(int msg); + public slots: void simple_trigger(); void adv_trigger(); void widget_enable(int index); - void value_changed(); - - void device_updated(); + void value_changed(); private: SigSession *_session; diff --git a/DSView/pv/eventobject.cpp b/DSView/pv/eventobject.cpp index b6f16060..5f5b9076 100644 --- a/DSView/pv/eventobject.cpp +++ b/DSView/pv/eventobject.cpp @@ -23,4 +23,8 @@ EventObject::EventObject(){ +} + +DeviceEventObject::DeviceEventObject() +{ } \ No newline at end of file diff --git a/DSView/pv/eventobject.h b/DSView/pv/eventobject.h index 1b13c2e5..e8d1fe9d 100644 --- a/DSView/pv/eventobject.h +++ b/DSView/pv/eventobject.h @@ -49,4 +49,17 @@ signals: void trigger_message(int msg); }; + +class DeviceEventObject : public QObject +{ + Q_OBJECT + +public: + DeviceEventObject(); + + +signals: + void device_updated(); +}; + #endif \ No newline at end of file diff --git a/DSView/pv/interface/icallbacks.h b/DSView/pv/interface/icallbacks.h index 0b37c84f..e6cebb4b 100644 --- a/DSView/pv/interface/icallbacks.h +++ b/DSView/pv/interface/icallbacks.h @@ -23,23 +23,18 @@ #ifndef _I_CALLBACKS_ #define _I_CALLBACKS_ -struct ds_device_info; 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_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 cur_snap_samplerate_changed()=0; virtual void signals_changed()=0; virtual void receive_trigger(quint64 trigger_pos)=0; virtual void frame_ended()=0; @@ -53,8 +48,7 @@ public: virtual void receive_header()=0; virtual void data_received()=0; - virtual void trigger_message(int msg)=0; - + virtual void trigger_message(int msg)=0; }; class ISessionDataGetter @@ -64,12 +58,26 @@ public: }; -#define DSV_MSG_DEVICE_LIST_UPDATE 4500 -#define DSV_MSG_COLLECT_START_PREV 5001 -#define DSV_MSG_COLLECT_START 5002 -#define DSV_MSG_COLLECT_END_PREV 5003 -#define DSV_MSG_COLLECT_END 5004 +class IDlgCallback +{ +public: + virtual void OnDlgResult(bool bYes)=0; +}; +class IMainForm{ +public: + virtual void switchLanguage(int language)=0; +}; + + +#define DSV_MSG_START_COLLECT_WORK_PREV 5001 +#define DSV_MSG_START_COLLECT_WORK 5002 +#define DSV_MSG_COLLECT_START 5003 +#define DSV_MSG_COLLECT_END 5004 +#define DSV_MSG_END_COLLECT_WORK_PREV 5005 +#define DSV_MSG_END_COLLECT_WORK 5006 + +#define DSV_MSG_DEVICE_LIST_UPDATED 6000 #define DSV_MSG_BEGIN_DEVICE_OPTIONS 6001 //Begin show device options dialog. #define DSV_MSG_END_DEVICE_OPTIONS 6002 #define DSV_MSG_DEVICE_OPTIONS_UPDATED 6003 @@ -78,6 +86,11 @@ public: #define DSV_MSG_CURRENT_DEVICE_CHANGE_PREV 6006 #define DSV_MSG_CURRENT_DEVICE_CHANGED 6007 #define DSV_MSG_NEW_USB_DEVICE 6008 +#define DSV_MSG_CURRENT_DEVICE_DETACHED 6009 +#define DSV_MSG_DEVICE_CONFIG_UPDATED 6010 + +#define DSV_MSG_TRIG_NEXT_COLLECT 7001 +#define DSV_MSG_SAVE_COMPLETE 7002 class IMessageListener { diff --git a/DSView/pv/interface/uicallback.h b/DSView/pv/interface/uicallback.h deleted file mode 100644 index b5dac050..00000000 --- a/DSView/pv/interface/uicallback.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2021 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 - */ - -#pragma once - -class IDlgCallback -{ -public: - virtual void OnDlgResult(bool bYes)=0; -}; - -class IMainForm{ -public: - virtual void switchLanguage(int language)=0; -}; diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index d0d14e05..87fdc12e 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -100,9 +100,11 @@ namespace pv { - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - _msg(NULL) - { + MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + { + _msg = NULL; + _session = AppControl::Instance()->GetSession(); _session->set_callback(this); _device_agent = _session->get_device(); @@ -227,8 +229,7 @@ namespace pv retranslateUi(); - // event - connect(&_event, SIGNAL(capture_state_changed(int)), this, SLOT(on_capture_state_changed(int))); + // event connect(&_event, SIGNAL(session_error()), this, SLOT(on_session_error())); connect(&_event, SIGNAL(signals_changed()), this, SLOT(on_signals_changed())); connect(&_event, SIGNAL(receive_trigger(quint64)), this, SLOT(on_receive_trigger(quint64))); @@ -285,11 +286,10 @@ namespace pv _search_dock->setWindowTitle(tr("Search...")); } +/* void MainWindow::update_device_list() { - assert(_sampling_bar); - - /* + assert(_sampling_bar); if (!selected_device->name().contains("virtual")) { _file_bar->set_settings_en(true); _logo_bar->dsl_connected(true); @@ -345,8 +345,9 @@ namespace pv } } } - */ + } + */ void MainWindow::on_load_file(QString file_name) { @@ -368,54 +369,11 @@ namespace pv MsgBox::Show(NULL, error.toStdString().c_str(), this); } - - // void MainWindow::on_device_detach() - //{ - /* - - _device_agent->device_updated(); - - _session->set_repeating(false); - _session->stop_capture(); - _sampling_bar->set_sampling(false); - _session->capture_state_changed(SigSession::Stopped); - - session_save(); - _view->hide_calibration(); - - if (_device_agent->get_work_mode() != DSO && - strncmp(_device_agent->name().toUtf8(), "virtual", 7)) { - const auto logic_snapshot = _session->get_snapshot(SR_CHANNEL_LOGIC); - assert(logic_snapshot); - const auto analog_snapshot = _session->get_snapshot(SR_CHANNEL_ANALOG); - assert(analog_snapshot); - - if (!logic_snapshot->empty() || !analog_snapshot->empty()) { - dialogs::DSMessageBox msg(this); - _msg = &msg; - msg.mBox()->setText(tr("Hardware Detached")); - msg.mBox()->setInformativeText(tr("Save captured data?")); - msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); - msg.mBox()->addButton(tr("Cancel"), QMessageBox::RejectRole); - msg.mBox()->setIcon(QMessageBox::Warning); - if (msg.exec()) - on_save(); - _msg = NULL; - } - } - - _hot_detach = true; - - if (!_session->get_saving()) - device_detach_post(); - */ - // } - void MainWindow::repeat_resume() { - while (_view->session().get_capture_state() == SigSession::Running) - QCoreApplication::processEvents(); - _session->stop_capture(); + // while (_view->session().is_running_status()) + // QCoreApplication::processEvents(); + // _session->stop_capture(); } void MainWindow::session_error() @@ -478,7 +436,7 @@ namespace pv dialogs::DSMessageBox msg(this); - connect(_device_agent, SIGNAL(device_updated()), &msg, SLOT(accept())); + connect(_session->device_event_object(), SIGNAL(device_updated()), &msg, SLOT(accept())); QFont font("Monaco"); font.setStyleHint(QFont::Monospace); @@ -494,36 +452,6 @@ namespace pv _session->clear_error(); } - void MainWindow::capture_state_changed(int state) - { - _event.capture_state_changed(state); // safe call - } - - void MainWindow::on_capture_state_changed(int state) - { - if (!_session->repeat_check()) - { - _file_bar->enable_toggle(state != SigSession::Running); - _sampling_bar->set_sampling(state == SigSession::Running); - _view->on_state_changed(state != SigSession::Running); - - if (_device_agent->get_work_mode() != DSO || - _session->get_instant()) - { - _sampling_bar->enable_toggle(state != SigSession::Running); - _trig_bar->enable_toggle(state != SigSession::Running); - //_measure_dock->widget()->setEnabled(state != SigSession::Running); - _measure_widget->refresh(); - } - } - - if (state == SigSession::Stopped) - { - prgRate(0); - _view->repeat_unshow(); - } - } - void MainWindow::session_save() { QDir dir; @@ -1072,10 +1000,16 @@ namespace pv switch (ke->key()) { case Qt::Key_S: - on_run_stop(); + if (_session->is_working()) + _session->stop_capture(); + else + _session->start_capture(false); break; case Qt::Key_I: - on_instant_stop(); + if (_session->is_working()) + _session->stop_capture(); + else + _session->start_capture(true); break; case Qt::Key_T: if (_device_agent->get_work_mode() == DSO) @@ -1095,7 +1029,7 @@ namespace pv on_search(!_search_dock->isVisible()); break; case Qt::Key_O: - _sampling_bar->on_configure(); + _sampling_bar->config_device(); break; case Qt::Key_PageUp: _view->set_scale_offset(_view->scale(), @@ -1275,11 +1209,7 @@ namespace pv } /*------------------on event end-------*/ - - void MainWindow::device_setted() - { - _view->set_device(); - } + void MainWindow::signals_changed() { @@ -1403,36 +1333,70 @@ namespace pv { switch (msg) { - case DSV_MSG_DEVICE_LIST_UPDATE: + case DSV_MSG_DEVICE_LIST_UPDATED: _sampling_bar->update_device_list(); break; - case DSV_MSG_COLLECT_START: + case DSV_MSG_START_COLLECT_WORK_PREV: + _trigger_widget->try_commit_trigger(); + _view->capture_init(); + break; + + case DSV_MSG_START_COLLECT_WORK: _sampling_bar->set_sampling(false); break; - case DSV_MSG_COLLECT_END: - _sampling_bar->set_sampling(true); + case DSV_MSG_END_COLLECT_WORK: + _session->device_event_object()->device_updated(); + _sampling_bar->set_sampling(true); break; + case DSV_MSG_NEW_USB_DEVICE: check_usb_device_speed(); break; case DSV_MSG_CURRENT_DEVICE_CHANGED: - if (_msg != NULL) + if (_msg != NULL){ _msg->close(); + _msg = NULL; + } _sampling_bar->update_device_list(); + _view->reload(); + _view->set_device(); _trig_bar->reload(); _sampling_bar->reload(); _view->status_clear(); _trigger_widget->init(); _dso_trigger_widget->init(); - _measure_widget->reload(); + _measure_widget->reload(); + _trigger_widget->device_updated(); break; case DSV_MSG_CURRENT_DEVICE_CHANGE_PREV: _protocol_widget->del_all_protocol(); + _view->reload(); + break; + + case DSV_MSG_DEVICE_OPTIONS_UPDATED: + _trigger_widget->device_updated(); + _measure_widget->reload(); + _view->check_calibration(); + break; + + case DSV_MSG_DEVICE_DURATION_UPDATED: + _trigger_widget->device_updated(); + _view->timebase_changed(); + break; + + case DSV_MSG_DEVICE_MODE_CHANGED: + _view->mode_changed(); + break; + + case DSV_MSG_CURRENT_DEVICE_DETACHED: + _session->device_event_object()->device_updated(); + session_save(); + _view->hide_calibration(); break; } } diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index bbf7a97c..e7c981ea 100644 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -29,8 +29,7 @@ #include #include "dialogs/dsmessagebox.h" #include "interface/icallbacks.h" -#include "eventobject.h" -#include "interface/uicallback.h" +#include "eventobject.h" #include class QAction; @@ -77,8 +76,12 @@ using namespace pv::device; //The mainwindow,referenced by MainFrame //TODO: create graph view,toolbar,and show device list -class MainWindow : public QMainWindow, public ISessionCallback, - public IMainForm, public ISessionDataGetter, public IMessageListener +class MainWindow : + public QMainWindow, + public ISessionCallback, + public IMainForm, + public ISessionDataGetter, + public IMessageListener { Q_OBJECT @@ -101,9 +104,7 @@ public slots: private slots: void on_load_file(QString file_name); - void on_open_doc(); - - void update_device_list(); + void on_open_doc(); void on_protocol(bool visible); void on_trigger(bool visible); @@ -116,8 +117,6 @@ private slots: void on_export(); bool on_load_session(QString name); bool on_store_session(QString name); - - void on_capture_state_changed(int state); void on_data_updated(); void on_session_error(); @@ -149,14 +148,11 @@ private: //ISessionCallback void show_error(QString error); void session_error(); - void capture_state_changed(int state); - void data_updated(); void repeat_resume(); void update_capture(); void cur_snap_samplerate_changed(); - void device_setted(); - + void signals_changed(); void receive_trigger(quint64 trigger_pos); void frame_ended(); @@ -171,8 +167,8 @@ private: void data_received(); void trigger_message(int msg); - //ISessionDataGetter - bool genSessionData(std::string &str); + //ISessionDataGetter + bool genSessionData(std::string &str); bool gen_session_json(QJsonObject &sessionVar); diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 057208e4..f2a608c1 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -80,11 +80,13 @@ SigSession::SigSession() _is_working = false; _is_repeat_mode = false; _is_saving = false; + _device_status = ST_INIT; _noData_cnt = 0; _data_lock = false; _data_updated = false; - _active_last_device_flag = false; + _is_auto_sel_device = false; + _is_trig_new_device_msg = false; this->add_msg_listener(this); @@ -98,6 +100,8 @@ SigSession::SigSession() _bClose = false; _callback = NULL; + _device_agent.set_callback(this); + // Create snapshots & data containers _logic_data = new data::Logic(new data::LogicSnapshot()); _dso_data = new data::Dso(new data::DsoSnapshot()); @@ -156,6 +160,8 @@ bool SigSession::set_default_device() struct ds_device_info *array = NULL; int count = 0; + dsv_info("%s", "Set default device."); + if (ds_get_device_list(&array, &count) != SR_OK) { dsv_err("%s", "Get device list error!"); @@ -192,6 +198,7 @@ bool SigSession::set_device(ds_device_handle dev_handle) return false; } _device_agent.update(); + _device_status = ST_INIT; init_signals(); @@ -237,15 +244,21 @@ bool SigSession::set_file(QString name) } void SigSession::close_file(ds_device_handle dev_handle) -{ - assert(!_is_saving); - assert(!_is_working); +{ + assert(dev_handle); + + if (dev_handle == _device_agent.handle() && _is_working){ + dsv_err("%s", "The virtual device is running, can't remove it."); + return; + } + bool isCurrent = dev_handle == _device_agent.handle(); if (ds_remove_device(dev_handle) != SR_OK){ dsv_err("%s", "Remove virtual deivice error!"); } - stop_capture(); - set_default_device(); + + if (isCurrent) + set_default_device(); } @@ -416,15 +429,25 @@ void SigSession::container_init() } } - void SigSession::start_capture(bool instant) - { - assert(!_is_working); + bool SigSession::start_capture(bool instant) + { assert(_callback); + dsv_info("%s", "Start collect."); + + if (_is_working){ + dsv_err("%s", "Error! Is working now."); + return false; + } + // Check that a device instance has been selected. if (_device_agent.have_instance() == false) { - dsv_err("%s", "No device selected"); - return; + dsv_err("%s", "Error!No device selected"); + assert(false); + } + if (_device_agent.is_collecting()){ + dsv_err("%s", "Error!Device is running."); + return false; } // update setting @@ -432,17 +455,19 @@ void SigSession::container_init() _is_instant = true; else _is_instant = instant; + + _callback->trigger_message(DSV_MSG_START_COLLECT_WORK_PREV); + + return exec_capture(); } -void SigSession::exec_capture() +bool SigSession::exec_capture() { - if (_device_agent.is_running()){ - dsv_err("%s", "Device is running."); - assert(false); + if (_device_agent.is_collecting()){ + dsv_err("%s", "Error!Device is running."); + return false; } - - _callback->trigger_message(DSV_MSG_COLLECT_START_PREV); - + // stop all decode tasks int run_dex = 0; clear_all_decode_task(run_dex); @@ -453,30 +478,33 @@ void SigSession::exec_capture() view::DsoSignal *dsoSig = NULL; if ((dsoSig = dynamic_cast(s))) dsoSig->set_mValid(false); - } - - capture_init(); + } if (_device_agent.have_enabled_channel() == false){ _callback->show_error("No probes enabled."); - data_updated(); - _is_working = false; - return; + return false; } + + capture_init(); if (_device_agent.start() == false) { dsv_err("%s", "Start collect error!"); + return false; } - + _is_working = true; + _callback->trigger_message(DSV_MSG_START_COLLECT_WORK); + return true; } void SigSession::stop_capture() { - assert(_is_working); - - data_unlock(); + dsv_info("%s", "Stop collect."); + + if (!_is_working){ + return; + } bool wait_upload = false; if (!_is_repeat_mode) { @@ -488,7 +516,7 @@ void SigSession::stop_capture() } if (!wait_upload) { _is_working = false; - _callback->trigger_message(DSV_MSG_COLLECT_END_PREV); + _callback->trigger_message(DSV_MSG_END_COLLECT_WORK_PREV); exit_capture(); } else{ @@ -500,7 +528,7 @@ void SigSession::exit_capture() { _is_instant = false; - if (_device_agent.is_running()){ + if (_device_agent.is_collecting()){ _device_agent.stop(); } } @@ -550,20 +578,12 @@ std::set SigSession::get_data() return data; } - -void SigSession::set_capture_state(capture_state state) -{ - std::lock_guard lock(_sampling_mutex); - _capture_state = state; - data_updated(); - capture_state_changed(state); -} void SigSession::check_update() { ds_lock_guard lock(_data_mutex); - if (_device_agent.is_running() == false) + if (_device_agent.is_collecting() == false) return; if (_data_updated) { @@ -742,8 +762,8 @@ void SigSession::reload() assert(false); } - if (_capture_state == Running) - stop_capture(); + if (_is_working) + return; std::vector sigs; view::Signal *signal = NULL; @@ -901,9 +921,6 @@ void SigSession::feed_in_meta(const sr_dev_inst *sdi, /// @todo handle samplerate changes /// samplerate = (uint64_t *)src->value; break; - default: - // Unknown metadata is not an error. - break; } } } @@ -1065,7 +1082,8 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) // first payload _analog_data->snapshot()->first_payload(analog, _device_agent.get_sample_limit(), _device_agent.get_channels()); - } else { + } + else { // Append to the existing data snapshot _analog_data->snapshot()->append_payload(analog); } @@ -1358,18 +1376,17 @@ void SigSession::rst_decoder(int index) } } - void SigSession::rst_decoder_by_key_handel(void *handel) - { - int dex = get_trace_index_by_key_handel(handel); - rst_decoder(dex); - } - +void SigSession::rst_decoder_by_key_handel(void *handel) +{ + int dex = get_trace_index_by_key_handel(handel); + rst_decoder(dex); +} + pv::data::DecoderModel* SigSession::get_decoder_model() { return _decoder_model; } - void SigSession::spectrum_rebuild() { bool has_dso_signal = false; @@ -1539,9 +1556,7 @@ void SigSession::set_repeat_intvl(double interval) bool SigSession::repeat_check() { - if (_device_agent.is_running() || - get_run_mode() != Repetitive || - !isRepeating()) { + if (!_is_working) { return false; } @@ -1557,7 +1572,7 @@ bool SigSession::repeat_check() void SigSession::repeat_update() { - if (isRepeating()) { + if (!_is_instant && _is_working && _is_repeat_mode) { _repeat_hold_prg -= 100/RepeatHoldDiv; if (_repeat_hold_prg != 0){ _out_timer.TimeOut(_repeat_intvl * 1000 / RepeatHoldDiv, std::bind(&SigSession::repeat_update, this)); @@ -1570,7 +1585,7 @@ void SigSession::repeat_update() int SigSession::get_repeat_hold() { - if (isRepeating()) + if (!_is_instant && _is_working && _is_repeat_mode) return _repeat_hold_prg; else return 0; @@ -1626,21 +1641,21 @@ void SigSession::set_stop_scale(float scale) _stop_scale = scale; } - void SigSession::Open() - { - } +void SigSession::Open() +{ +} - void SigSession::Close() - { - if (_bClose) +void SigSession::Close() +{ + if (_bClose) return; - _bClose = true; - stop_capture(); + _bClose = true; + exit_capture(); - // TODO: This should not be necessary - _session = NULL; - } + // TODO: This should not be necessary + _session = NULL; +} //append a decode task, and try create a thread void SigSession::add_decode_task(view::DecodeTrace *trace) @@ -1781,85 +1796,109 @@ void SigSession::set_stop_scale(float scale) _is_decoding = false; } - Snapshot* SigSession::get_signal_snapshot() + Snapshot *SigSession::get_signal_snapshot() { - int mode = _device_agent.get_work_mode(); - if (mode == ANALOG) - return _analog_data->snapshot(); - else if (mode == DSO) - return _dso_data->snapshot(); - else - return _logic_data->snapshot(); + int mode = _device_agent.get_work_mode(); + if (mode == ANALOG) + return _analog_data->snapshot(); + else if (mode == DSO) + return _dso_data->snapshot(); + else + return _logic_data->snapshot(); } void SigSession::device_lib_event_callback(int event) { - if (_session == NULL){ - dsv_err("%s", "Error!Global variable \"_session\" is null."); - return; - } - _session->on_device_lib_event(event); + if (_session == NULL) + { + dsv_err("%s", "Error!Global variable \"_session\" is null."); + return; + } + _session->on_device_lib_event(event); } void SigSession::on_device_lib_event(int event) { - if (event == DS_EV_COLLECT_TASK_START){ + switch (event) + { + case DS_EV_DEVICE_RUNNING: + _device_status = ST_RUNNING; + break; + + case DS_EV_DEVICE_STOPPED: + _device_status = ST_STOPPED; + break; + + case DS_EV_COLLECT_TASK_START: _callback->trigger_message(DSV_MSG_COLLECT_START); - return; - } - - if (event == DS_EV_COLLECT_TASK_END){ - _callback->trigger_message(DSV_MSG_COLLECT_END); + break; - if (_logic_data->snapshot()->last_ended() == false) - dsv_err("%s", "The collected data is error!"); - if (_dso_data->snapshot()->last_ended() == false) - dsv_err("%s", "The collected data is error!"); - if (_analog_data->snapshot()->last_ended() == false) - dsv_err("%s", "The collected data is error!"); - - bool bInstant = _is_instant; - _is_instant = false; - - if (!bInstant && _is_repeat_mode){ - if (_repeat_intvl > 0) - _repeate_timer.Start(_repeat_intvl * 1000); - else - this->exec_capture(); - } - - return; - } - - if (event == DS_EV_NEW_DEVICE_ATTACH || event == DS_EV_CURRENT_DEVICE_DETACH) - { - if (_is_working) - this->stop_capture(); - - - if (have_hardware_data()) + case DS_EV_COLLECT_TASK_END: + case DS_EV_COLLECT_TASK_END_BY_ERROR: + case DS_EV_COLLECT_TASK_END_BY_DETACHED: { - // Try to save current device data, and auto select the lastest device later. - _active_last_device_flag = true; - if (!_is_saving) - store_session_data(); - return; + _callback->trigger_message(DSV_MSG_COLLECT_END); + + if (_logic_data->snapshot()->last_ended() == false) + dsv_err("%s", "The collected data is error!"); + if (_dso_data->snapshot()->last_ended() == false) + dsv_err("%s", "The collected data is error!"); + if (_analog_data->snapshot()->last_ended() == false) + dsv_err("%s", "The collected data is error!"); + + // trigger next collect + if (!_is_instant + && _is_repeat_mode + && _is_working + && event == DS_EV_COLLECT_TASK_END) + { + _callback->trigger_message(DSV_MSG_TRIG_NEXT_COLLECT); + } + else{ + _is_working = false; + _is_instant = false; + _callback->trigger_message(DSV_MSG_END_COLLECT_WORK); + } } - } + break; - if (_is_working) - this->stop_capture(); + case DS_EV_NEW_DEVICE_ATTACH: + case DS_EV_CURRENT_DEVICE_DETACH: + { + if (_is_working) + stop_capture(); - if (event == DS_EV_NEW_DEVICE_ATTACH || event == DS_EV_CURRENT_DEVICE_DETACH) - { - if (_is_saving) - _active_last_device_flag = true; //Auto switch device after save data. - else - set_default_device(); - } - else - { - _callback->trigger_message(DSV_MSG_DEVICE_LIST_UPDATE); // Update list only. + if (DS_EV_CURRENT_DEVICE_DETACH == event){ + _callback->trigger_message(DSV_MSG_CURRENT_DEVICE_DETACHED); + } + + int work_mode = _device_agent.get_work_mode(); + + if (have_hardware_data() && (work_mode == LOGIC || work_mode == ANALOG)) + { + // Try to save current device data, and auto select the lastest device later. + _is_auto_sel_device = true; + if (!_is_saving) + store_session_data(); + + _is_trig_new_device_msg = DS_EV_NEW_DEVICE_ATTACH == event; + } + else{ + set_default_device(); + + if (DS_EV_NEW_DEVICE_ATTACH == event) + _callback->trigger_message(DSV_MSG_NEW_USB_DEVICE); + } + } + break; + + case DS_EV_INACTIVE_DEVICE_DETACH: + _callback->trigger_message(DSV_MSG_DEVICE_LIST_UPDATED); // Update list only. + break; + + default: + dsv_err("%s", "Error!Unknown device event."); + break; } } @@ -1879,22 +1918,54 @@ void SigSession::on_device_lib_event(int event) void SigSession::set_repeat_mode(bool repeat) { assert(!_is_working); - assert(_is_repeat_mode != repeat); - _is_repeat_mode = repeat; - _repeat_hold_prg = 0; + + if(_is_repeat_mode != repeat) + { + _is_repeat_mode = repeat; + _repeat_hold_prg = 0; + } } void SigSession::repeat_capture_wait_timout() { - + exec_capture(); } void SigSession::OnMessage(int msg) { - if (msg == DSV_MSG_DEVICE_OPTIONS_UPDATED){ - this->reload(); + switch (msg) + { + case DSV_MSG_DEVICE_OPTIONS_UPDATED: + reload(); + break; + + case DSV_MSG_TRIG_NEXT_COLLECT: + if (_repeat_intvl > 0) + _repeate_timer.Start(_repeat_intvl * 1000); + else + exec_capture(); + break; + + case DSV_MSG_SAVE_COMPLETE: + bool ret = false; + if (_is_auto_sel_device) + ret = set_default_device(); + if (ret && _is_trig_new_device_msg){ + _callback->trigger_message(DSV_MSG_NEW_USB_DEVICE); + } + break; } } + void SigSession::DeviceConfigChanged() + { + + } + + void SigSession::store_session_data() + { + + } + } // namespace pv diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index 3c0ad75e..6a90a69a 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -38,6 +38,7 @@ #include "dstimer.h" #include #include "deviceagent.h" +#include "eventobject.h" struct srd_decoder; @@ -85,7 +86,9 @@ using namespace pv::device; using namespace pv::data; //created by MainWindow -class SigSession: public IMessageListener +class SigSession: + public IMessageListener, + public IDeviceAgentCallback { private: static constexpr float Oversampling = 2.0f; @@ -107,6 +110,12 @@ public: Data_overflow }; + enum device_status_type{ + ST_INIT = 0, + ST_RUNNING = 1, + ST_STOPPED = 2, + }; + private: SigSession(SigSession &o); @@ -128,7 +137,7 @@ public: bool set_device(ds_device_handle dev_handle); bool set_file(QString name); void close_file(ds_device_handle dev_handle); - void start_capture(bool instant); + bool start_capture(bool instant); void stop_capture(); uint64_t cur_samplerate(); @@ -226,14 +235,27 @@ public: return _is_working; } + inline bool is_init_status(){ + return _device_status == ST_INIT; + } + + // The collect thread is running. + inline bool is_running_status(){ + return _device_status == ST_RUNNING; + } + + inline bool is_stopped_status(){ + return _device_status == ST_STOPPED; + } + void set_repeat_mode(bool repeat); inline bool is_repeat_mode(){ return _is_repeat_mode; - } - - inline void capture_state_changed(int state){ - _callback->capture_state_changed(state); + } + + inline bool is_repeating(){ + return _is_repeat_mode && !_is_instant; } inline void session_save(){ @@ -259,6 +281,10 @@ public: inline void set_saving(bool flag){ _is_saving = flag; } + + inline DeviceEventObject* device_event_object(){ + return &_device_event; + } void reload(); void refresh(int holdtime); @@ -272,7 +298,7 @@ public: void broadcast_msg(int msg); private: - void exec_capture(); + bool exec_capture(); void exit_capture(); inline void data_updated(){ @@ -307,6 +333,9 @@ private: //IMessageListener void OnMessage(int msg); + //IDeviceAgentCallback + void DeviceConfigChanged(); + private: /** * Attempts to autodetect the format. Failing that @@ -315,8 +344,7 @@ private: * used, or NULL if no input format was selected or * auto-detected. */ - static sr_input_format* determine_input_file_format(const std::string &filename); - + static sr_input_format* determine_input_file_format(const std::string &filename); // data feed void feed_in_header(const sr_dev_inst *sdi); @@ -383,7 +411,7 @@ private: bool _dso_feed; float _stop_scale; bool _bClose; - bool _active_last_device_flag; + bool _is_auto_sel_device; uint64_t _save_start; uint64_t _save_end; @@ -393,10 +421,13 @@ private: int _repeat_hold_prg; // The time sleep progress bool _is_saving; bool _is_instant; + bool _is_trig_new_device_msg; + int _device_status; ISessionCallback *_callback; DeviceAgent _device_agent; std::vector _msg_listeners; + DeviceEventObject _device_event; private: // TODO: This should not be necessary. Multiple concurrent diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index 798f6966..cc12c0cc 100644 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -242,10 +242,5 @@ void FileBar::set_settings_en(bool enable) _menu_session->setDisabled(!enable); } -void FileBar::OnMessage(int msg) -{ - -} - } // namespace toolbars } // namespace pv diff --git a/DSView/pv/toolbars/filebar.h b/DSView/pv/toolbars/filebar.h index 243e4501..5b3c435f 100644 --- a/DSView/pv/toolbars/filebar.h +++ b/DSView/pv/toolbars/filebar.h @@ -28,15 +28,14 @@ #include #include -#include "../sigsession.h" -#include "../interface/icallbacks.h" +#include "../sigsession.h" namespace pv { namespace toolbars { //toolbar button,referenced by MainWindow //TODO: load session file, sorte session, load log data file, sorte data, export data -class FileBar : public QToolBar, public IMessageListener +class FileBar : public QToolBar { Q_OBJECT @@ -67,9 +66,6 @@ private slots: void on_actionOpen_triggered(); void on_actionCapture_triggered(); - //IMessageListener - void OnMessage(int msg); - private: bool _enable; SigSession* _session; diff --git a/DSView/pv/toolbars/logobar.h b/DSView/pv/toolbars/logobar.h index 4637cdac..e4c49ccc 100644 --- a/DSView/pv/toolbars/logobar.h +++ b/DSView/pv/toolbars/logobar.h @@ -30,7 +30,7 @@ #include #include "../sigsession.h" -#include "../interface/uicallback.h" +#include "../interface/icallbacks.h" namespace pv { diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 5f24d31d..3269d5af 100644 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -64,8 +64,7 @@ SamplingBar::SamplingBar(SigSession *session, QWidget *parent) : _updating_device_list = false; _updating_sample_rate = false; _updating_sample_count = false; - _sampling = false; - _enable = true; + _last_device_handle = NULL_HANDLE; _session = session; @@ -168,15 +167,17 @@ void SamplingBar::retranslateUi() int mode = _device_agent->get_work_mode(); + bool is_working = _session->is_working(); + if (_session->is_instant()) { if (bDev && mode == DSO) - _instant_button.setText(_sampling ? tr("Stop") : tr("Single")); + _instant_button.setText(is_working ? tr("Stop") : tr("Single")); else - _instant_button.setText(_sampling ? tr("Stop") : tr("Instant")); + _instant_button.setText(is_working ? tr("Stop") : tr("Instant")); _run_stop_button.setText(tr("Start")); } else { - _run_stop_button.setText(_sampling ? tr("Stop") : tr("Start")); + _run_stop_button.setText(is_working ? tr("Stop") : tr("Start")); if (bDev && mode == DSO) _instant_button.setText(tr("Single")); else @@ -215,10 +216,10 @@ void SamplingBar::reStyle() if (true) { QString iconPath = GetIconPath(); _configure_button.setIcon(QIcon(iconPath+"/params.svg")); - _mode_button.setIcon(_session->get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : - QIcon(iconPath+"/moder.svg")); - _run_stop_button.setIcon(_sampling ? QIcon(iconPath+"/stop.svg") : - QIcon(iconPath+"/start.svg")); + QString icon1 = _session->is_repeat_mode() ? "moder.svg" : "modes.svg"; + _mode_button.setIcon(QIcon(iconPath+ "/" + icon1)); + QString icon2 = _session->is_working() ? "stop.svg" : "start.svg"; + _run_stop_button.setIcon(QIcon(iconPath + "/" + icon2)); _instant_button.setIcon(QIcon(iconPath+"/single.svg")); _action_single->setIcon(QIcon(iconPath+"/oneloop.svg")); _action_repeat->setIcon(QIcon(iconPath+"/repeat.svg")); @@ -237,6 +238,8 @@ void SamplingBar::on_configure() _session->broadcast_msg(DSV_MSG_BEGIN_DEVICE_OPTIONS); pv::dialogs::DeviceOptions dlg(this); + connect(_session->device_event_object(), SIGNAL(device_updated()), &dlg, SLOT(reject())); + ret = dlg.exec(); if (ret == QDialog::Accepted) @@ -298,7 +301,7 @@ void SamplingBar::zero_adj() _sample_count.setCurrentIndex(i); commit_hori_res(); - if (_session->is_running() == false) + if (_session->is_working() == false) _session->start_capture(true); pv::dialogs::WaitingDialog wait(this, _session, SR_CONF_ZERO); @@ -310,7 +313,7 @@ void SamplingBar::zero_adj() } } - if (_session->is_running()) + if (_session->is_working()) _session->stop_capture(); _sample_count.setCurrentIndex(index_back); @@ -318,9 +321,7 @@ void SamplingBar::zero_adj() } void SamplingBar::set_sampling(bool sampling) -{ - _sampling = sampling; - +{ if (!sampling) { enable_run_stop(true); enable_instant(true); @@ -344,7 +345,7 @@ void SamplingBar::set_sampling(bool sampling) else _run_stop_button.setIcon(sampling ? QIcon(iconPath+"/stop.svg") : QIcon(iconPath+"/start.svg")); - _mode_button.setIcon(_session->get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : + _mode_button.setIcon(_session->is_repeat_mode() == false ? QIcon(iconPath+"/modes.svg") : QIcon(iconPath+"/moder.svg")); } @@ -370,8 +371,12 @@ void SamplingBar::update_sample_rate_selector() const uint64_t *elements = NULL; gsize num_elements; - if (_updating_sample_rate) + dsv_info("%s", "Update rate list."); + + if (_updating_sample_rate){ + dsv_err("%s", "Error! The rate list is updating."); return; + } disconnect(&_sample_rate, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplerate_sel(int))); @@ -384,7 +389,7 @@ void SamplingBar::update_sample_rate_selector() _updating_sample_rate = true; gvar_dict = _device_agent->get_config_list(NULL, SR_CONF_SAMPLERATE); - if (gvar_dict != NULL) + if (gvar_dict == NULL) { _sample_rate.clear(); _sample_rate.show(); @@ -429,12 +434,9 @@ void SamplingBar::update_sample_rate_selector_value() { if (_updating_sample_rate) return; - - const uint64_t samplerate = _device_agent->get_sample_rate(); - - assert(!_updating_sample_rate); _updating_sample_rate = true; + const uint64_t samplerate = _device_agent->get_sample_rate(); uint64_t cur_value = _sample_rate.itemData(_sample_rate.currentIndex()).value(); if (samplerate != cur_value) { @@ -469,8 +471,12 @@ void SamplingBar::update_sample_count_selector() double duration; bool rle_support = false; - if (_updating_sample_count) + dsv_info("%s", "Update sample count list."); + + if (_updating_sample_count){ + dsv_err("%s", "Error! The sample count is updating."); return; + } disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); @@ -782,8 +788,8 @@ void SamplingBar::commit_settings() //start or stop capture void SamplingBar::on_run_stop() { - if (get_sampling() || _session->isRepeating()) { - _session->exit_capture(); + if (_session->is_working()) { + _session->stop_capture(); return; } @@ -792,9 +798,7 @@ void SamplingBar::on_run_stop() dsv_info("%s", "Have no device, can't to collect data."); return; } - - enable_run_stop(false); - enable_instant(false); + commit_settings(); if (_device_agent->get_work_mode() == DSO) { @@ -825,16 +829,20 @@ void SamplingBar::on_run_stop() } } } - + + if (_session->start_capture(false)){ + enable_run_stop(false); + enable_instant(false); + } } void SamplingBar::on_instant_stop() { - if (get_sampling()) { - _session->set_repeating(false); + if (_session->is_working()) { + _session->set_repeat_mode(false); bool wait_upload = false; - if (_session->get_run_mode() != SigSession::Repetitive) { + if (_session->is_repeat_mode() == false) { GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD); if (gvar != NULL) { wait_upload = g_variant_get_boolean(gvar); @@ -843,24 +851,17 @@ void SamplingBar::on_instant_stop() } if (!wait_upload) { _session->stop_capture(); - _session->capture_state_changed(SigSession::Stopped); } } else { if (_device_agent->have_instance() == false){ - dsv_info("%s", "Have no device, can't to collect data."); + dsv_info("%s", "Error! Have no device, can't to collect data."); return; } - - enable_run_stop(false); - enable_instant(false); + commit_settings(); - if (_device_agent->have_instance() == false){ - return; - } - if (_device_agent->get_work_mode() == DSO) { GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); @@ -888,7 +889,13 @@ void SamplingBar::on_instant_stop() return; } } - } + } + + if (_session->start_capture(true)) + { + enable_run_stop(false); + enable_instant(false); + } } } @@ -991,13 +998,19 @@ void SamplingBar::on_mode() if (act == _action_single) { _mode_button.setIcon(QIcon(iconPath+"/modes.svg")); - _session->set_run_mode(pv::SigSession::Single); + _session->set_repeat_mode(false); } else if (act == _action_repeat) { _mode_button.setIcon(QIcon(iconPath+"/moder.svg")); - pv::dialogs::Interval interval_dlg(_session, this); + pv::dialogs::Interval interval_dlg(this); + + interval_dlg.set_interval(_session->get_repeat_intvl()); interval_dlg.exec(); - _session->set_run_mode(pv::SigSession::Repetitive); + + if (interval_dlg.is_done()){ + _session->set_repeat_intvl(interval_dlg.get_interval()); + _session->set_repeat_mode(true); + } } } @@ -1007,6 +1020,8 @@ void SamplingBar::on_mode() int dev_count = 0; int select_index = 0; + dsv_info("%s", "Update device list."); + array = _session->get_device_list(dev_count, select_index); if (array == NULL){ @@ -1026,7 +1041,6 @@ void SamplingBar::on_mode() free(array); _device_selector.setCurrentIndex(select_index); - update_sample_rate_selector(); int width = _device_selector.sizeHint().width(); @@ -1036,19 +1050,9 @@ void SamplingBar::on_mode() _updating_device_list = false; } - void SamplingBar::OnMessage(int msg) - { - switch (msg) - { - case DSV_MSG_DEVICE_LIST_UPDATE: - case DSV_MSG_CURRENT_DEVICE_CHANGED: - update_device_list(); - break; - case DSV_MSG_COLLECT_START: - set_sampling(false); - case DSV_MSG_COLLECT_END: - set_sampling(true); - } + void SamplingBar::config_device() + { + on_configure(); } } // namespace toolbars diff --git a/DSView/pv/toolbars/samplingbar.h b/DSView/pv/toolbars/samplingbar.h index 6a492ffd..36182864 100644 --- a/DSView/pv/toolbars/samplingbar.h +++ b/DSView/pv/toolbars/samplingbar.h @@ -33,6 +33,7 @@ #include #include #include "../ui/dscombobox.h" +#include struct st_dev_inst; class QAction; @@ -75,9 +76,8 @@ namespace pv public: - SamplingBar(SigSession *session, QWidget *parent); - - void update_sample_rate_selector(); + SamplingBar(SigSession *session, QWidget *parent); + void enable_toggle(bool enable); void enable_instant(bool enable); @@ -85,9 +85,11 @@ namespace pv double commit_hori_res(); double get_hori_res(); void set_sample_rate(uint64_t sample_rate); - void update_device_list(); - void set_sampling(bool sampling); + void update_device_list(); void reload(); + void set_sampling(bool sampling); + + void config_device(); private: void enable_run_stop(bool enable); @@ -95,15 +97,13 @@ namespace pv void retranslateUi(); void reStyle(); + void update_sample_rate_selector(); void update_sample_rate_selector_value(); void update_sample_count_selector(); void update_sample_count_selector_value(); void commit_settings(); void setting_adj(); - //IMessageListener - void OnMessage(int msg); - private slots: void on_mode(); void on_run_stop(); @@ -116,18 +116,18 @@ namespace pv private: - SigSession *_session; - bool _enable; - bool _sampling; + SigSession *_session; - QToolButton _device_type; + QToolButton _device_type; DsComboBox _device_selector; - QToolButton _configure_button; + QToolButton _configure_button; DsComboBox _sample_count; DsComboBox _sample_rate; + bool _updating_sample_rate; bool _updating_sample_count; + bool _updating_device_list; QToolButton _run_stop_button; QToolButton _instant_button; @@ -139,7 +139,7 @@ namespace pv QMenu *_mode_menu; QAction *_action_repeat; QAction *_action_single; - bool _updating_device_list; + DeviceAgent *_device_agent; ds_device_handle _last_device_handle; }; diff --git a/DSView/pv/view/analogsignal.cpp b/DSView/pv/view/analogsignal.cpp index 3059496f..5787d8ec 100644 --- a/DSView/pv/view/analogsignal.cpp +++ b/DSView/pv/view/analogsignal.cpp @@ -195,7 +195,7 @@ bool AnalogSignal::measure(const QPointF &p) if (!enabled()) return false; - if (_view->session().get_capture_state() != SigSession::Stopped) + if (_view->session().is_stopped_status() == false) return false; const QRectF window = get_view_rect(); @@ -404,7 +404,7 @@ int AnalogSignal::get_zero_vpos() void AnalogSignal::set_zero_ratio(double ratio) { - if (_view->session().get_capture_state() == SigSession::Running) + if (_view->session().is_running_status()) return; _zero_offset = ratio2value(ratio); @@ -557,7 +557,7 @@ void AnalogSignal::paint_fore(QPainter &p, int left, int right, QColor fore, QCo fore.setAlpha(View::ForeAlpha); if(enabled()) { // Paint measure - if (_view->session().get_capture_state() == SigSession::Stopped) + if (_view->session().is_stopped_status()) paint_hover_measure(p, fore, back); } } diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index 40ec86b4..0873b5fc 100644 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -567,7 +567,7 @@ void DecodeTrace::on_new_decode_data() } decoded_progress(_progress); - if (_view && _view->session().get_capture_state() == SigSession::Stopped) + if (_view && _view->session().is_stopped_status()) _view->data_updated(); if (_totalHeight/_view->get_signalHeight() != rows_size()) _view->signals_changed(); diff --git a/DSView/pv/view/devmode.cpp b/DSView/pv/view/devmode.cpp index cd28ddb0..c5127bed 100644 --- a/DSView/pv/view/devmode.cpp +++ b/DSView/pv/view/devmode.cpp @@ -105,7 +105,7 @@ void DevMode::changeEvent(QEvent *event) void DevMode::set_device() { if (_device_agent->have_instance() == false){ - dsv_info("%s", "DevMode::set_device, Have no device."); + dsv_detail("%s", "DevMode::set_device, Have no device."); return; } @@ -197,10 +197,8 @@ void DevMode::on_mode_change() { if ((*i).first == action) { if (_device_agent->get_work_mode() != (*i).second->mode) { - _session->set_run_mode(SigSession::Single); - _session->set_repeating(false); _session->stop_capture(); - _session->capture_state_changed(SigSession::Stopped); + _session->set_repeat_mode(false); _session->session_save(); _device_agent->set_config(NULL, NULL, SR_CONF_DEVICE_MODE, diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index 3c9cdfad..e61da76e 100644 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -174,11 +174,13 @@ void DsoSignal::set_enable(bool enable) } bool running = false; - if (session->get_capture_state() == SigSession::Running) { + + if (session->is_running_status()) { running = true; session->stop_capture(); } - while(session->get_capture_state() == SigSession::Running) + + while(session->is_running_status()) QCoreApplication::processEvents(); set_vDialActive(false); @@ -211,14 +213,18 @@ bool DsoSignal::go_vDialPre(bool manul) if (_autoV && manul) autoV_end(); - if (enabled() && !_vDial->isMin()) { - if (session->get_capture_state() == SigSession::Running) + if (enabled() && !_vDial->isMin()) + { + if (session->is_running_status()) session->refresh(RefreshShort); + const double pre_vdiv = _vDial->get_value(); _vDial->set_sel(_vDial->get_sel() - 1); + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, g_variant_new_uint64(_vDial->get_value())); - if (session->get_capture_state() == SigSession::Stopped) { + + if (session->is_stopped_status()) { session->set_stop_scale(session->stop_scale() * (pre_vdiv/_vDial->get_value())); set_scale(get_view_rect().height()); } @@ -229,7 +235,8 @@ bool DsoSignal::go_vDialPre(bool manul) _view->set_update(_viewport, true); _view->update(); return true; - } else { + } + else { if (_autoV && !_autoV_over) autoV_end(); return false; @@ -241,14 +248,18 @@ bool DsoSignal::go_vDialNext(bool manul) if (_autoV && manul) autoV_end(); - if (enabled() && !_vDial->isMax()) { - if (session->get_capture_state() == SigSession::Running) + if (enabled() && !_vDial->isMax()) + { + if (session->is_running_status()) session->refresh(RefreshShort); + const double pre_vdiv = _vDial->get_value(); _vDial->set_sel(_vDial->get_sel() + 1); + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, g_variant_new_uint64(_vDial->get_value())); - if (session->get_capture_state() == SigSession::Stopped) { + + if (session->is_stopped_status()) { session->set_stop_scale(session->stop_scale() * (pre_vdiv/_vDial->get_value())); set_scale(get_view_rect().height()); } @@ -259,7 +270,8 @@ bool DsoSignal::go_vDialNext(bool manul) _view->set_update(_viewport, true); _view->update(); return true; - } else { + } + else { if (_autoV && !_autoV_over) autoV_end(); return false; @@ -1011,7 +1023,7 @@ void DsoSignal::paint_fore(QPainter &p, int left, int right, QColor fore, QColor p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, "T"); // Paint measure - if (session->get_capture_state() == SigSession::Stopped) + if (session->is_stopped_status()) paint_hover_measure(p, fore, back); // autoset @@ -1370,12 +1382,13 @@ void DsoSignal::paint_hover_measure(QPainter &p, QColor fore, QColor back) void DsoSignal::auto_set() { - if (session->get_capture_state() == SigSession::Stopped) { + if (session->is_stopped_status()) { if (_autoV) autoV_end(); if (_autoH) autoH_end(); - } else { + } + else { if (_autoH && _autoV && get_zero_ratio() != 0.5) { set_zero_ratio(0.5); } @@ -1462,7 +1475,7 @@ void DsoSignal::auto_start() if (_autoV || _autoH) return; - if (session->get_capture_state() == SigSession::Running) { + if (session->is_running_status()) { session->data_auto_lock(AutoLock); _autoV = true; _autoH = true; @@ -1474,10 +1487,11 @@ void DsoSignal::auto_start() bool DsoSignal::measure(const QPointF &p) { _hover_en = false; + if (!enabled() || !show()) return false; - if (session->get_capture_state() != SigSession::Stopped) + if (session->is_stopped_status() == false) return false; const QRectF window = get_view_rect(); diff --git a/DSView/pv/view/header.cpp b/DSView/pv/view/header.cpp index b4e834c2..185fb0e4 100644 --- a/DSView/pv/view/header.cpp +++ b/DSView/pv/view/header.cpp @@ -168,8 +168,9 @@ void Header::mousePressEvent(QMouseEvent *event) const auto &traces = _view.get_traces(ALL_VIEW); int action; - const bool instant = _view.session().get_instant(); - if (instant && _view.session().get_capture_state() == SigSession::Running) { + + const bool instant = _view.session().is_instant(); + if (instant && _view.session().is_running_status()) { return; } diff --git a/DSView/pv/view/mathtrace.cpp b/DSView/pv/view/mathtrace.cpp index 8b2075c1..b36c6177 100644 --- a/DSView/pv/view/mathtrace.cpp +++ b/DSView/pv/view/mathtrace.cpp @@ -104,12 +104,12 @@ void MathTrace::update_vDial() void MathTrace::go_vDialPre() { if (enabled() && !_vDial->isMin()) { - if (_view->session().get_capture_state() == SigSession::Running) + if (_view->session().is_running_status()) _view->session().refresh(DsoSignal::RefreshShort); const double pre_vdiv = _vDial->get_value(); _vDial->set_sel(_vDial->get_sel() - 1); - if (_view->session().get_capture_state() == SigSession::Stopped) + if (_view->session().is_stopped_status()) _scale *= pre_vdiv/_vDial->get_value(); _view->set_update(_viewport, true); @@ -120,12 +120,12 @@ void MathTrace::go_vDialPre() void MathTrace::go_vDialNext() { if (enabled() && !_vDial->isMax()) { - if (_view->session().get_capture_state() == SigSession::Running) + if (_view->session().is_running_status()) _view->session().refresh(DsoSignal::RefreshShort); const double pre_vdiv = _vDial->get_value(); _vDial->set_sel(_vDial->get_sel() + 1); - if (_view->session().get_capture_state() == SigSession::Stopped) + if (_view->session().is_stopped_status()) _scale *= pre_vdiv/_vDial->get_value(); _view->set_update(_viewport, true); @@ -255,7 +255,7 @@ void MathTrace::paint_fore(QPainter &p, int left, int right, QColor fore, QColor // Paint measure fore.setAlpha(View::ForeAlpha); - if (_view->session().get_capture_state() == SigSession::Stopped) + if (_view->session().is_stopped_status()) paint_hover_measure(p, fore, back); } diff --git a/DSView/pv/view/ruler.cpp b/DSView/pv/view/ruler.cpp index 693c1c6e..541bdf37 100644 --- a/DSView/pv/view/ruler.cpp +++ b/DSView/pv/view/ruler.cpp @@ -460,7 +460,7 @@ void Ruler::draw_logic_tick_mark(QPainter &p) auto i = _view.get_cursorList().begin(); int index = 1; while (i != _view.get_cursorList().end()) { - (*i)->paint_label(p, rect(), prefix, index, _view.session().get_capture_state() == SigSession::Stopped); + (*i)->paint_label(p, rect(), prefix, index, _view.session().is_stopped_status()); index++; i++; } @@ -578,7 +578,7 @@ void Ruler::draw_osc_tick_mark(QPainter &p) auto i = _view.get_cursorList().begin(); int index = 1; while (i != _view.get_cursorList().end()) { - (*i)->paint_label(p, rect(), prefix, index, _view.session().get_capture_state() == SigSession::Stopped); + (*i)->paint_label(p, rect(), prefix, index, _view.session().is_stopped_status()); index++; i++; } diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 74cd3263..ef865568 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -102,7 +102,6 @@ View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget _session = session; _device_agent = session->get_device(); - session->add_msg_listener(this); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); @@ -249,7 +248,7 @@ void View::capture_init() if (mode == DSO) show_trig_cursor(true); - else if (!_session->isRepeating()) + else if (!_session->is_repeating()) show_trig_cursor(false); _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); @@ -297,10 +296,11 @@ bool View::zoom(double steps, int offset) if (_device_agent->get_work_mode() != DSO) { _scale *= std::pow(3.0/2.0, -steps); _scale = max(min(_scale, _maxscale), _minscale); - } else { - if (_session->get_capture_state() == SigSession::Running && - _session->get_instant()) + } + else { + if (_session->is_running_status() && _session->is_instant()){ return ret; + } double hori_res = -1; if(steps > 0.5) @@ -343,20 +343,18 @@ void View::timebase_changed() void View::set_scale_offset(double scale, int64_t offset) { - //if (_session->get_capture_state() == SigSession::Stopped) { - _preScale = _scale; - _preOffset = _offset; + _preScale = _scale; + _preOffset = _offset; - _scale = max(min(scale, _maxscale), _minscale); - _offset = floor(max(min(offset, get_max_offset()), get_min_offset())); + _scale = max(min(scale, _maxscale), _minscale); + _offset = floor(max(min(offset, get_max_offset()), get_min_offset())); - if (_scale != _preScale || _offset != _preOffset) { - update_scroll(); - _header->update(); - _ruler->update(); - viewport_update(); - } - //} + if (_scale != _preScale || _offset != _preOffset) { + update_scroll(); + _header->update(); + _ruler->update(); + viewport_update(); + } } void View::set_preScale_preOffset() @@ -1371,27 +1369,5 @@ void View::check_calibration() } } -void View::OnMessage(int msg) -{ - switch (msg) - { - case DSV_MSG_DEVICE_OPTIONS_UPDATED: - check_calibration(); - break; - case DSV_MSG_COLLECT_START_PREV: - capture_init(); - break; - case DSV_MSG_DEVICE_DURATION_UPDATED: - timebase_changed(); - break; - case DSV_MSG_DEVICE_MODE_CHANGED: - mode_changed(); - break; - case DSV_MSG_CURRENT_DEVICE_CHANGED: - reload(); - break; - } -} - } // namespace view } // namespace pv diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index a82cb117..ead5d8ca 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -41,8 +41,7 @@ #include "xcursor.h" #include "signal.h" #include "viewstatus.h" -#include "../dsvdef.h" -#include "../interface/icallbacks.h" +#include "../dsvdef.h" class DeviceAgent; @@ -69,7 +68,7 @@ class Viewport; class LissajousFigure; //created by MainWindow -class View : public QScrollArea, public IMessageListener { +class View : public QScrollArea { Q_OBJECT private: @@ -247,22 +246,18 @@ public: int get_cursor_index_by_key(uint64_t key); + void check_calibration(); + signals: void hover_point_changed(); - void cursor_update(); void xcursor_update(); - void cursor_moving(); void cursor_moved(); - void measure_updated(); - void prgRate(int progress); - void resize(); - - void auto_trig(int index); + void auto_trig(int index); private: void get_scroll_layout(int64_t &length, int64_t &offset); @@ -276,20 +271,11 @@ private: const pv::view::Trace *b); void clear(); - void reconstruct(); - - //IMessageListener - void OnMessage(int msg); - -private: + void reconstruct(); bool eventFilter(QObject *object, QEvent *event); - bool viewportEvent(QEvent *e); - void resizeEvent(QResizeEvent *e); - - void check_calibration(); - + public slots: void reload(); void set_measure_en(int enable); @@ -324,6 +310,8 @@ public slots: void frame_began(); + void mode_changed(); + private slots: void h_scroll_value_changed(int value); @@ -344,8 +332,6 @@ private slots: void splitterMoved(int pos, int index); - void mode_changed(); - public: void show_wait_trigger(); void set_device(); diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index ac57e3a8..a753c5ed 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -160,32 +160,26 @@ void Viewport::paintEvent(QPaintEvent *event) t->paint_back(p, 0, _view.get_view_width(), fore, back); if (_view.back_ready()) break; - } - - //auto st = _view.session().get_capture_state(); + } if (_view.session().get_device()->get_work_mode() == LOGIC || - _view.session().get_instant()) { - switch(_view.session().get_capture_state()) { - case SigSession::Init: - break; - - case SigSession::Stopped: + _view.session().is_instant()) + { + if (_view.session().is_stopped_status()){ paintSignals(p, fore, back); - break; - - case SigSession::Running: - if (_view.session().isRepeating() && - !transfer_started) { + } + else if (_view.session().is_running_status()){ + if (_view.session().is_repeat_mode() && !transfer_started) { _view.set_capture_status(); paintSignals(p, fore, back); - } else if (_type == TIME_VIEW) { + } + else if (_type == TIME_VIEW) { _view.repeat_unshow(); paintProgress(p, fore, back); } - break; - } - } else { + } + } + else { paintSignals(p, fore, back); } @@ -259,9 +253,9 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back) const int64_t cursorX = _view.index2pixel((*i)->index()); if (xrect.contains(_view.hover_point().x(), _view.hover_point().y()) && qAbs(cursorX - _view.hover_point().x()) <= HitCursorMargin) - (*i)->paint(p, xrect, 1, index, _view.session().get_capture_state() == SigSession::Stopped); + (*i)->paint(p, xrect, 1, index, _view.session().is_stopped_status()); else - (*i)->paint(p, xrect, 0, index, _view.session().get_capture_state() == SigSession::Stopped); + (*i)->paint(p, xrect, 0, index, _view.session().is_stopped_status()); i++; index++; } @@ -328,8 +322,9 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back) paintMeasure(p, fore, back); //plot trigger information - if (_view.session().get_device()->get_work_mode() == DSO && - _view.session().get_capture_state() == SigSession::Running) { + if (_view.session().get_device()->get_work_mode() == DSO + && _view.session().is_running_status()) + { uint8_t type; bool roll = false; QString type_str=""; @@ -506,12 +501,14 @@ void Viewport::mousePressEvent(QMouseEvent *event) _drag_strength = 0; _elapsed_time.restart(); - if (_action_type == NO_ACTION && - event->button() == Qt::RightButton && - _view.session().get_capture_state() == SigSession::Stopped) { + if (_action_type == NO_ACTION + && event->button() == Qt::RightButton + && _view.session().is_stopped_status()) + { if (_view.session().get_device()->get_work_mode() == LOGIC) { _action_type = LOGIC_ZOOM; - } else if (_view.session().get_device()->get_work_mode() == DSO) { + } + else if (_view.session().get_device()->get_work_mode() == DSO) { if (_hover_hit) { const int64_t index = _view.pixel2index(event->pos().x()); _view.add_cursor(view::Ruler::CursorColor[_view.get_cursorList().size() % 8], index); @@ -768,10 +765,10 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) return; } - if ((_action_type == NO_ACTION) && - (event->button() == Qt::LeftButton)) { - if (_view.session().get_device()->get_work_mode() == LOGIC && - _view.session().get_capture_state() == SigSession::Stopped) { + if ((_action_type == NO_ACTION) && (event->button() == Qt::LeftButton)) + { + if (_view.session().get_device()->get_work_mode() == LOGIC + && _view.session().is_stopped_status()) { //priority 1 //try to quick scroll view... int curX = event->globalPos().x(); @@ -976,14 +973,16 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) if (!_view.get_view_rect().contains(event->pos())) return; - if (_view.session().get_device()->get_work_mode() == LOGIC && - _view.session().get_capture_state() == SigSession::Stopped) { + if (_view.session().get_device()->get_work_mode() == LOGIC + && _view.session().is_stopped_status()) + { if (event->button() == Qt::RightButton) { if (_view.scale() == _view.get_maxscale()) _view.set_preScale_preOffset(); else _view.set_scale_offset(_view.get_maxscale(), _view.get_min_offset()); - } else if (event->button() == Qt::LeftButton) { + } + else if (event->button() == Qt::LeftButton) { bool logic = false; uint64_t index; uint64_t index0 = 0, index1 = 0, index2 = 0; @@ -1015,13 +1014,15 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) _view.show_cursors(true); } update(); - } else if (_view.session().get_device()->get_work_mode() == DSO && - _view.session().get_capture_state() != SigSession::Init && - event->button() == Qt::LeftButton) { + } + else if (_view.session().get_device()->get_work_mode() == DSO + && _view.session().is_init_status() == false + && event->button() == Qt::LeftButton) { if (_dso_xm_valid) { clear_dso_xm(); measure_updated(); - } else if (_action_type == NO_ACTION) { + } + else if (_action_type == NO_ACTION) { for(auto &s : _view.session().get_signals()) { assert(s); if (s->get_view_rect().contains(event->pos())) { @@ -1691,20 +1692,24 @@ void Viewport::on_drag_timer() { const int64_t offset = _view.offset(); const double scale = _view.scale(); - if (_view.session().get_capture_state() == SigSession::Stopped && - _drag_strength != 0 && - offset < _view.get_max_offset() && - offset > _view.get_min_offset()) { + + if (_view.session().is_stopped_status() + && _drag_strength != 0 + && offset < _view.get_max_offset() + && offset > _view.get_min_offset()) + { _view.set_scale_offset(scale, offset + _drag_strength); _drag_strength /= DragDamping; if (_drag_strength != 0) _drag_timer.start(DragTimerInterval); - } else if (offset == _view.get_max_offset() || - offset == _view.get_min_offset()) { + } + else if (offset == _view.get_max_offset() || + offset == _view.get_min_offset()) { _drag_strength = 0; _drag_timer.stop(); _action_type = NO_ACTION; - }else if (_action_type == NO_ACTION){ + } + else if (_action_type == NO_ACTION){ _drag_strength = 0; _drag_timer.stop(); } diff --git a/libsigrok4DSL/lib_main.c b/libsigrok4DSL/lib_main.c index 1acbc82f..f2f68a69 100644 --- a/libsigrok4DSL/lib_main.c +++ b/libsigrok4DSL/lib_main.c @@ -34,7 +34,7 @@ #endif #undef LOG_PREFIX -#define LOG_PREFIX "lib_main: " +#define LOG_PREFIX "lib_main: " char DS_RES_PATH[500] = {0}; @@ -58,6 +58,7 @@ struct sr_lib_context ds_datafeed_callback_t data_forward_callback; int callback_thread_count; int is_delay_destory_actived_device; + int is_stop_by_detached; }; static void hotplug_event_listen_callback(struct libusb_context *ctx, struct libusb_device *dev, int event); @@ -88,6 +89,7 @@ static struct sr_lib_context lib_ctx = { .collect_thread = NULL, .callback_thread_count = 0, .is_delay_destory_actived_device = 0, + .is_stop_by_detached = 0, }; /** @@ -158,7 +160,9 @@ SR_API int ds_lib_exit() sr_info("Uninit %s.", SR_LIB_NAME); if (ds_is_collecting()) + { ds_stop_collect(); // stop collect. + } sr_close_hotplug(lib_ctx.sr_ctx); @@ -171,8 +175,7 @@ SR_API int ds_lib_exit() } // The device is not in list. - if (lib_ctx.is_delay_destory_actived_device - && lib_ctx.actived_device_instance != NULL) + if (lib_ctx.is_delay_destory_actived_device && lib_ctx.actived_device_instance != NULL) { sr_info("The current device is delayed for destruction, handle:%p", lib_ctx.actived_device_instance->handle); destroy_device_instance(lib_ctx.actived_device_instance); @@ -284,10 +287,11 @@ SR_API int ds_get_device_list(struct ds_device_info **out_list, int *out_count) p->di = dev; strncpy(p->name, dev->name, sizeof(p->name) - 1); - if (dev->driver && dev->driver->name){ + if (dev->driver && dev->driver->name) + { strncpy(p->driver_name, dev->driver->name, sizeof(p->driver_name) - 1); } - + p++; } @@ -333,16 +337,18 @@ SR_API int ds_active_device(ds_device_handle handle) if (lib_ctx.actived_device_instance != NULL) { - if (lib_ctx.is_delay_destory_actived_device){ + if (lib_ctx.is_delay_destory_actived_device) + { sr_info("The current device is delayed for destruction, handle:%p", lib_ctx.actived_device_instance->handle); destroy_device_instance(lib_ctx.actived_device_instance); lib_ctx.actived_device_instance = NULL; lib_ctx.is_delay_destory_actived_device = 0; } - else{ + else + { sr_info("Close the previous device \"%s\"", lib_ctx.actived_device_instance->name); - close_device_instance(lib_ctx.actived_device_instance); - } + close_device_instance(lib_ctx.actived_device_instance); + } } // To open the new. @@ -353,13 +359,15 @@ SR_API int ds_active_device(ds_device_handle handle) { bFind = 1; - if (dev->dev_type == DEV_TYPE_USB && DS_RES_PATH[0] == '\0'){ + if (dev->dev_type == DEV_TYPE_USB && DS_RES_PATH[0] == '\0') + { sr_err("%s", "Please call ds_set_firmware_resource_dir() to set the firmware resource path."); } sr_info("Switch \"%s\" to current device.", dev->name); - if (open_device_instance(dev) == SR_OK){ + if (open_device_instance(dev) == SR_OK) + { lib_ctx.actived_device_instance = dev; } else @@ -462,7 +470,8 @@ SR_API int ds_get_actived_device_index() */ SR_API int ds_have_actived_device() { - if (lib_ctx.actived_device_instance != NULL){ + if (lib_ctx.actived_device_instance != NULL) + { return 1; } return 0; @@ -483,19 +492,21 @@ SR_API int ds_device_from_file(const char *file_path) SR_API const GSList *ds_get_actived_device_mode_list() { GSList *l; - struct sr_dev_inst *dev; + struct sr_dev_inst *dev; - dev = lib_ctx.actived_device_instance ; + dev = lib_ctx.actived_device_instance; - if (dev == NULL){ + if (dev == NULL) + { sr_err("%s", "Have no actived device."); } - if (dev->driver == NULL || dev->driver->dev_mode_list == NULL){ + if (dev->driver == NULL || dev->driver->dev_mode_list == NULL) + { sr_err("%s", "Module not implemented."); return NULL; } - return dev->driver->dev_mode_list(dev); + return dev->driver->dev_mode_list(dev); } /** @@ -506,22 +517,18 @@ SR_API int ds_remove_device(ds_device_handle handle) { GSList *l; struct sr_dev_inst *dev; - int bFind = 0; + int bFind = 0; if (handle == NULL_HANDLE) return SR_ERR_ARG; - if (lib_ctx.actived_device_instance != NULL - && lib_ctx.actived_device_instance->handle == handle - && ds_is_collecting()) + if (lib_ctx.actived_device_instance != NULL && lib_ctx.actived_device_instance->handle == handle && ds_is_collecting()) { sr_err("%s", "Device is collecting, can't remove it."); return SR_ERR_CALL_STATUS; } - if (lib_ctx.actived_device_instance != NULL - && lib_ctx.is_delay_destory_actived_device - && lib_ctx.actived_device_instance->handle == handle) + if (lib_ctx.actived_device_instance != NULL && lib_ctx.is_delay_destory_actived_device && lib_ctx.actived_device_instance->handle == handle) { sr_info("The current device is delayed for destruction, handle:%p", lib_ctx.actived_device_instance->handle); destroy_device_instance(lib_ctx.actived_device_instance); @@ -538,7 +545,8 @@ SR_API int ds_remove_device(ds_device_handle handle) { lib_ctx.device_list = g_slist_remove(lib_ctx.device_list, l->data); - if (dev == lib_ctx.actived_device_instance){ + if (dev == lib_ctx.actived_device_instance) + { lib_ctx.actived_device_instance = NULL; } @@ -564,7 +572,7 @@ SR_API int ds_get_actived_device_info(struct ds_device_info *fill_info) struct sr_dev_inst *dev; struct ds_device_info *p; int ret; - + if (fill_info == NULL) return SR_ERR_ARG; @@ -588,9 +596,10 @@ SR_API int ds_get_actived_device_info(struct ds_device_info *fill_info) p->di = dev; strncpy(p->name, dev->name, sizeof(p->name) - 1); - if (dev->driver && dev->driver->name){ + if (dev->driver && dev->driver->name) + { strncpy(p->driver_name, dev->driver->name, sizeof(p->driver_name) - 1); - } + } ret = SR_OK; } @@ -674,6 +683,9 @@ static void collect_run_proc() { int ret; struct sr_dev_inst *di; + int bError; + + bError = 0; di = lib_ctx.actived_device_instance; send_event(DS_EV_COLLECT_TASK_START); @@ -683,6 +695,7 @@ static void collect_run_proc() if (di == NULL || di->driver == NULL || di->driver->dev_acquisition_start == NULL) { sr_err("%s", "The device cannot be used."); + bError = 1; goto END; } @@ -692,20 +705,35 @@ static void collect_run_proc() sr_err("Failed to start acquisition of device in " "running session: %d", ret); + bError = 1; goto END; } + send_event(DS_EV_DEVICE_RUNNING); + ret = sr_session_run(); - if (ret != SR_OK){ + + send_event(DS_EV_DEVICE_STOPPED); + + if (ret != SR_OK) + { sr_err("%s", "Run session error!"); + bError = 1; goto END; - } + } END: sr_info("%s", "Collect thread end."); lib_ctx.collect_thread = NULL; - send_event(DS_EV_COLLECT_TASK_END); + if (bError) + send_event(DS_EV_COLLECT_TASK_END_BY_ERROR); + else if (lib_ctx.is_stop_by_detached) + send_event(DS_EV_COLLECT_TASK_END_BY_DETACHED); + else + send_event(DS_EV_COLLECT_TASK_END); // Normal end. + + lib_ctx.is_stop_by_detached = 0; } /** @@ -756,7 +784,8 @@ int ds_trigger_is_enabled() for (l = lib_ctx.actived_device_instance->channels; l; l = l->next) { p = (struct sr_channel *)l->data; - if (p->trigger && p->trigger[0] != '\0'){ + if (p->trigger && p->trigger[0] != '\0') + { ret = 1; break; } @@ -767,61 +796,70 @@ int ds_trigger_is_enabled() return ret; } +SR_API int ds_trigger_reset() +{ + return ds_trigger_init(); +} + /**-------------------public end ---------------*/ /**-------------------config -------------------*/ SR_API int ds_get_actived_device_config(const struct sr_channel *ch, - const struct sr_channel_group *cg, - int key, GVariant **data) + const struct sr_channel_group *cg, + int key, GVariant **data) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { sr_err("%s", "Have no actived device."); return SR_ERR_CALL_STATUS; } - - return sr_config_get(lib_ctx.actived_device_instance->driver, - lib_ctx.actived_device_instance, - ch, - cg, - key, - data); + + return sr_config_get(lib_ctx.actived_device_instance->driver, + lib_ctx.actived_device_instance, + ch, + cg, + key, + data); } SR_API int ds_set_actived_device_config(const struct sr_channel *ch, - const struct sr_channel_group *cg, - int key, GVariant *data) + const struct sr_channel_group *cg, + int key, GVariant *data) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { sr_err("%s", "Have no actived device."); return SR_ERR_CALL_STATUS; } - + return sr_config_set( - lib_ctx.actived_device_instance, - ch, - cg, - key, - data); + lib_ctx.actived_device_instance, + ch, + cg, + key, + data); } SR_API int ds_get_actived_device_config_list(const struct sr_channel_group *cg, - int key, GVariant **data) + int key, GVariant **data) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { sr_err("%s", "Have no actived device."); return SR_ERR_CALL_STATUS; } return sr_config_list(lib_ctx.actived_device_instance->driver, - lib_ctx.actived_device_instance, - cg, - key, - data); + lib_ctx.actived_device_instance, + cg, + key, + data); } -SR_API const struct sr_config_info* ds_get_actived_device_config_info(int key) +SR_API const struct sr_config_info *ds_get_actived_device_config_info(int key) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { sr_err("%s", "Have no actived device."); return SR_ERR_CALL_STATUS; } @@ -829,9 +867,10 @@ SR_API const struct sr_config_info* ds_get_actived_device_config_info(int key) return sr_config_info_get(key); } -SR_API const struct sr_config_info* ds_get_actived_device_config_info_by_name(const char *optname) +SR_API const struct sr_config_info *ds_get_actived_device_config_info_by_name(const char *optname) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { sr_err("%s", "Have no actived device."); return SR_ERR_CALL_STATUS; } @@ -840,7 +879,8 @@ SR_API const struct sr_config_info* ds_get_actived_device_config_info_by_name(co SR_API int ds_get_actived_device_status(struct sr_status *status, gboolean prg) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { sr_err("%s", "Have no actived device."); return SR_ERR_CALL_STATUS; } @@ -861,7 +901,8 @@ SR_API void ds_free_config(struct sr_config *src) /**-----------channel -------------*/ SR_API int ds_enable_device_channel(const struct sr_channel *ch, gboolean enable) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { return SR_ERR_CALL_STATUS; } return sr_enable_device_channel(lib_ctx.actived_device_instance, ch, enable); @@ -869,7 +910,8 @@ SR_API int ds_enable_device_channel(const struct sr_channel *ch, gboolean enable SR_API int ds_enable_device_channel_index(int ch_index, gboolean enable) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { return SR_ERR_CALL_STATUS; } return sr_dev_probe_enable(lib_ctx.actived_device_instance, ch_index, enable); @@ -877,10 +919,11 @@ SR_API int ds_enable_device_channel_index(int ch_index, gboolean enable) SR_API int ds_set_device_channel_name(int ch_index, const char *name) { - if (lib_ctx.actived_device_instance == NULL){ + if (lib_ctx.actived_device_instance == NULL) + { return SR_ERR_CALL_STATUS; } - return sr_dev_probe_name_set(lib_ctx.actived_device_instance, ch_index, name); + return sr_dev_probe_name_set(lib_ctx.actived_device_instance, ch_index, name); } /** @@ -900,7 +943,8 @@ int ds_channel_is_enabled() for (l = lib_ctx.actived_device_instance->channels; l; l = l->next) { p = (struct sr_channel *)l->data; - if (p->enabled){ + if (p->enabled) + { ret = 1; break; } @@ -910,9 +954,10 @@ int ds_channel_is_enabled() return ret; } -GSList* ds_get_actived_device_channels() +GSList *ds_get_actived_device_channels() { - if (lib_ctx.actived_device_instance != NULL){ + if (lib_ctx.actived_device_instance != NULL) + { return lib_ctx.actived_device_instance->channels; } return NULL; @@ -1114,6 +1159,13 @@ static void hotplug_event_listen_callback(struct libusb_context *ctx, struct lib lib_ctx.detach_device_handle); } + if (lib_ctx.actived_device_instance != NULL && lib_ctx.actived_device_instance->handle == (ds_device_handle)dev && ds_is_collecting()) + { + sr_info("%s", "The actived device is detached, will stop collect thread."); + lib_ctx.is_stop_by_detached = 1; + ds_stop_collect(); + } + /** * Begin to wait the device reconnect, if timeout, will process the detach event. */ @@ -1131,7 +1183,7 @@ static void process_attach_event() { struct sr_dev_driver **drivers; GList *dev_list; - GSList *l; + GSList *l; struct sr_dev_driver *dr; int num = 0; @@ -1158,7 +1210,8 @@ static void process_attach_event() pthread_mutex_lock(&lib_ctx.mutext); - for (l = dev_list; l; l = l->next){ + for (l = dev_list; l; l = l->next) + { lib_ctx.device_list = g_slist_append(lib_ctx.device_list, l->data); num++; } @@ -1181,7 +1234,7 @@ static void process_attach_event() } static void process_detach_event() -{ +{ GSList *l; struct sr_dev_inst *dev; struct sr_dev_driver *driver_ins; @@ -1208,27 +1261,24 @@ static void process_detach_event() if (dev->handle == (ds_device_handle)ev_dev) { - if (dev == lib_ctx.actived_device_instance && ds_is_collecting()){ - sr_info("%s", "The actived device is detached, will stop collect thread."); - ds_stop_collect(); - } - // Found the device, and remove it from list. - lib_ctx.device_list = g_slist_remove(lib_ctx.device_list, l->data); + lib_ctx.device_list = g_slist_remove(lib_ctx.device_list, l->data); - if (dev == lib_ctx.actived_device_instance){ + if (dev == lib_ctx.actived_device_instance) + { sr_info("The current device will be delayed for destruction, handle:%p", dev->handle); lib_ctx.is_delay_destory_actived_device = 1; - ev = DS_EV_CURRENT_DEVICE_DETACH; - } - else{ + ev = DS_EV_CURRENT_DEVICE_DETACH; + } + else + { destroy_device_instance(dev); } - + break; } } - pthread_mutex_unlock(&lib_ctx.mutext); + pthread_mutex_unlock(&lib_ctx.mutext); // Tell user a new device detached, and the list is updated. post_event_async(ev); @@ -1299,11 +1349,13 @@ static void make_demo_device_to_list() { dev_list = dr->scan(NULL); - if (dev_list != NULL){ + if (dev_list != NULL) + { - for (l = dev_list; l; l = l->next){ + for (l = dev_list; l; l = l->next) + { lib_ctx.device_list = g_slist_append(lib_ctx.device_list, l->data); - } + } g_slist_free(dev_list); } } @@ -1383,7 +1435,8 @@ static void post_event_async(int event) static void send_event(int event) { - if (lib_ctx.event_callback != NULL){ + if (lib_ctx.event_callback != NULL) + { lib_ctx.event_callback(event); } } diff --git a/libsigrok4DSL/libsigrok.h b/libsigrok4DSL/libsigrok.h index b9733c68..bbde11e4 100644 --- a/libsigrok4DSL/libsigrok.h +++ b/libsigrok4DSL/libsigrok.h @@ -1209,6 +1209,7 @@ SR_API const char *sr_error_str(int error_code); SR_API const char *sr_error_name(int error_code); /*--- trigger.c ------------------------------------------------------------*/ +SR_API int ds_trigger_reset(); SR_API int ds_trigger_stage_set_value(uint16_t stage, uint16_t probes, char *trigger0, char *trigger1); SR_API int ds_trigger_stage_set_logic(uint16_t stage, uint16_t probes, unsigned char trigger_logic); SR_API int ds_trigger_stage_set_inv(uint16_t stage, uint16_t probes, unsigned char trigger0_inv, unsigned char trigger1_inv); @@ -1237,21 +1238,38 @@ SR_API void ds_log_level(int level); // A new device attached, user need to call ds_get_device_list to get the list, // the last one is new. // User can call ds_active_device() to switch to the current device. -#define DS_EV_NEW_DEVICE_ATTACH 0 +//#define DS_EV_NEW_DEVICE_ATTACH 1 // The current device detached, user need to call ds_get_device_list to get the list, // and call ds_active_device() to switch to the current device. -#define DS_EV_CURRENT_DEVICE_DETACH 1 +//#define DS_EV_CURRENT_DEVICE_DETACH 2 // A inactive device detached. // User can call ds_get_device_list() to get the new list, and update the list view. -#define DS_EV_INACTIVE_DEVICE_DETACH 2 +//#define DS_EV_INACTIVE_DEVICE_DETACH 3 // The collect task is ends. -#define DS_EV_COLLECT_TASK_START 100 +#define DS_EV_COLLECT_TASK_START 101 // The collect task is ends. -#define DS_EV_COLLECT_TASK_END 101 +#define DS_EV_COLLECT_TASK_END 102 + +// The device is running +#define DS_EV_DEVICE_RUNNING 103 + +// The device is stopped +#define DS_EV_DEVICE_STOPPED 104 + +#define DS_EV_COLLECT_TASK_END_BY_DETACHED 105 + +#define DS_EV_COLLECT_TASK_END_BY_ERROR 106 + +enum bbbb +{ + DS_EV_NEW_DEVICE_ATTACH = 1, + DS_EV_CURRENT_DEVICE_DETACH = 2, + DS_EV_INACTIVE_DEVICE_DETACH = 3, +}; typedef unsigned long long ds_device_handle;