diff --git a/DSView/pv/deviceagent.cpp b/DSView/pv/deviceagent.cpp index f4f153d0..444ab528 100644 --- a/DSView/pv/deviceagent.cpp +++ b/DSView/pv/deviceagent.cpp @@ -23,15 +23,20 @@ #include #include "log.h" + DeviceAgent::DeviceAgent() { _dev_handle = NULL; + _di = NULL; + _dev_type = 0; } void DeviceAgent::update() { _dev_handle = NULL; _dev_name = ""; + _di = NULL; + _dev_type = 0; ds_device_info info; @@ -39,18 +44,26 @@ void DeviceAgent::update() { _dev_handle = info.handle; _dev_type = info.dev_type; + _di = info.di; _dev_name = QString::fromLocal8Bit(info.name); + _driver_name = QString::fromLocal8Bit(info.driver_name); } } + sr_dev_inst* DeviceAgent::inst() + { + assert(_dev_handle); + return _di; + } + GVariant* DeviceAgent::get_config(const sr_channel *ch, const sr_channel_group *group, int key) { assert(_dev_handle); GVariant *data = NULL; - if (ds_set_actived_device_config(ch, group, key, data) != SR_OK) + if (ds_get_actived_device_config(ch, group, key, &data) != SR_OK) { - dsv_err("%s", "Get device config error!"); + dsv_warn("%s%d", "WARNING: Failed to get value of config id:", key); } return data; } @@ -61,7 +74,7 @@ bool DeviceAgent::set_config(sr_channel *ch, sr_channel_group *group, int key, G if (ds_set_actived_device_config(ch, group, key, data) != SR_OK) { - dsv_err("%s", "Set device config error!"); + dsv_warn("%s%d", "WARNING: Failed to set value of config id:", key); return false; } @@ -69,26 +82,54 @@ bool DeviceAgent::set_config(sr_channel *ch, sr_channel_group *group, int key, G return true; } -GVariant* DeviceAgent::list_config(const sr_channel_group *group, int key) +GVariant* DeviceAgent::get_config_list(const sr_channel_group *group, int key) { assert(_dev_handle); GVariant *data = NULL; if (ds_get_actived_device_config_list(group, key, &data) != SR_OK){ - dsv_err("%s", "Get device config list error!"); + dsv_warn("%s%d", "WARNING: Failed to get config list, key:", key); + if (data != NULL){ + dsv_warn("%s%d", "WARNING: Failed to get config list, but data is not null. key:", key); + } + data = NULL; } return data; } -void DeviceAgent::enable_probe(const sr_channel *probe, bool enable = true) +bool DeviceAgent::enable_probe(const sr_channel *probe, bool enable) { assert(_dev_handle); if (ds_enable_device_channel(probe, enable) == SR_OK){ config_changed(); + return true; } + return false; +} + +bool DeviceAgent::enable_probe(int probe_index, bool enable) +{ + assert(_dev_handle); + + if (ds_enable_device_channel_index(probe_index, enable) == SR_OK){ + config_changed(); + return true; + } + return false; +} + +bool DeviceAgent::set_channel_name(int ch_index, const char *name) +{ + assert(_dev_handle); + + if (ds_set_device_channel_name(ch_index, name) == SR_OK){ + config_changed(); + return true; + } + return false; } uint64_t DeviceAgent::get_sample_limit() @@ -221,58 +262,16 @@ bool DeviceAgent::get_status(struct sr_status &status, gboolean prg) //---------------device config-----------/ int DeviceAgent::get_work_mode() - { - return ds_get_actived_device_mode(); - } - - bool DeviceAgent::get_device_info(struct ds_device_info &info) - { - if (ds_get_actived_device_info(&info) == SR_OK){ - return info.handle != NULL; - } - return false; - } - - bool DeviceAgent::get_device_config(const struct sr_channel *ch, - const struct sr_channel_group *cg, - int key, GVariant **data) - { - - if (ds_get_actived_device_config(ch, cg, key, data) == SR_OK){ - return true; - } - - return false; - } - - bool DeviceAgent::set_device_config(const struct sr_channel *ch, - const struct sr_channel_group *cg, - int key, GVariant *data) { - - if (ds_set_actived_device_config(ch, cg, key, data) == SR_OK){ - return true; - } - - return false; + return ds_get_actived_device_mode(); } - bool DeviceAgent::get_device_config_list(const struct sr_channel_group *cg, - int key, GVariant **data) - { - - if (ds_get_actived_device_config_list(cg, key, data) == SR_OK){ - return true; - } - return false; - } - - const struct sr_config_info* DeviceAgent::get_device_config_info(int 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_device_config_info_by_name(const char *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); } @@ -307,3 +306,4 @@ bool DeviceAgent::get_status(struct sr_status &status, gboolean prg) } //---------------device config end -----------/ + diff --git a/DSView/pv/deviceagent.h b/DSView/pv/deviceagent.h index e4ce1f2b..73eff5f0 100644 --- a/DSView/pv/deviceagent.h +++ b/DSView/pv/deviceagent.h @@ -28,6 +28,7 @@ #include #include + class DeviceAgent: public QObject { Q_OBJECT @@ -49,25 +50,39 @@ public: return _dev_name; } - inline bool isFile(){ + inline QString driver_name(){ + return _driver_name; + } + + inline ds_device_handle handle(){ + return _dev_handle; + } + + struct sr_dev_inst* inst(); + + inline bool is_file(){ return _dev_type == DEV_TYPE_FILELOG; } - inline bool isDemo(){ + inline bool is_demo(){ return _dev_type == DEV_TYPE_DEMO; } - inline bool isHardware(){ + inline bool is_hardware(){ return _dev_type == DEV_TYPE_USB; - } + } GVariant* get_config(const sr_channel *ch, const sr_channel_group *group, int key); bool set_config(sr_channel *ch, sr_channel_group *group, int key, GVariant *data); - GVariant* list_config(const sr_channel_group *group, int key); + GVariant* get_config_list(const sr_channel_group *group, int key); - void enable_probe(const sr_channel *probe, bool enable = true); + bool enable_probe(const sr_channel *probe, bool enable); + + bool enable_probe(int probe_index, bool enable); + + bool set_channel_name(int ch_index, const char *name); /** * @brief Gets the sample limit from the driver. @@ -134,24 +149,11 @@ public: //---------------device config-----------/ public: - int get_work_mode(); + int get_work_mode(); - bool get_device_info(struct ds_device_info &info); + const struct sr_config_info* get_config_info(int key); - bool get_device_config(const struct sr_channel *ch, - const struct sr_channel_group *cg, - int key, GVariant **data); - - bool set_device_config(const struct sr_channel *ch, - const struct sr_channel_group *cg, - int key, GVariant *data); - - bool get_device_config_list(const struct sr_channel_group *cg, - int key, GVariant **data); - - const struct sr_config_info* get_device_config_info(int key); - - const struct sr_config_info* get_device_config_info_by_name(const char *optname); + const struct sr_config_info* get_config_info_by_name(const char *optname); bool get_device_status(struct sr_status &status, gboolean prg); @@ -164,8 +166,9 @@ private: ds_device_handle _dev_handle; int _dev_type; QString _dev_name; - - + QString _driver_name; + struct sr_dev_inst *_di; }; + #endif \ No newline at end of file diff --git a/DSView/pv/dialogs/calibration.cpp b/DSView/pv/dialogs/calibration.cpp index 09804c39..be5282f3 100644 --- a/DSView/pv/dialogs/calibration.cpp +++ b/DSView/pv/dialogs/calibration.cpp @@ -31,6 +31,8 @@ #include "../view/trace.h" #include "../dialogs/dsmessagebox.h" #include "../dsvdef.h" +#include "../appcontrol.h" +#include "../sigsession.h" using namespace std; @@ -59,7 +61,8 @@ Calibration::Calibration(QWidget *parent) : this->setWindowOpacity(0.7); this->setModal(false); - _dev_inst = NULL; + _device_agent = AppControl::Instance()->GetSession()->get_device(); + _save_btn = new QPushButton(this); _abort_btn = new QPushButton(this); _reset_btn = new QPushButton(this); @@ -120,10 +123,11 @@ void Calibration::retranslateUi() setTitle(tr("Manual Calibration")); } -void Calibration::set_device(DevInst *dev_inst) -{ - assert(dev_inst); - _dev_inst = dev_inst; +void Calibration::update_device_info() +{ + if (_device_agent->have_instance()){ + assert(false); + } for(std::list::const_iterator i = _slider_list.begin(); i != _slider_list.end(); i++) { @@ -131,6 +135,7 @@ void Calibration::set_device(DevInst *dev_inst) _flayout->removeWidget((*i)); delete (*i); } + _slider_list.clear(); for(std::list::const_iterator i = _label_list.begin(); i != _label_list.end(); i++) { @@ -140,23 +145,23 @@ void Calibration::set_device(DevInst *dev_inst) } _label_list.clear(); - for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); uint64_t vgain = 0, vgain_default = 0; uint16_t vgain_range = 0; - GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN); + GVariant* gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_VGAIN); if (gvar != NULL) { vgain = g_variant_get_uint64(gvar); g_variant_unref(gvar); } - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT); if (gvar != NULL) { vgain_default = g_variant_get_uint64(gvar); g_variant_unref(gvar); } - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_RANGE); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_RANGE); if (gvar != NULL) { vgain_range = g_variant_get_uint16(gvar); g_variant_unref(gvar); @@ -174,12 +179,12 @@ void Calibration::set_device(DevInst *dev_inst) uint64_t voff = 0; uint16_t voff_range = 0; - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_PREOFF); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_PREOFF); if (gvar != NULL) { voff = g_variant_get_uint16(gvar); g_variant_unref(gvar); } - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_PREOFF_MARGIN); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_PREOFF_MARGIN); if (gvar != NULL) { voff_range = g_variant_get_uint16(gvar); g_variant_unref(gvar); @@ -195,14 +200,14 @@ void Calibration::set_device(DevInst *dev_inst) _label_list.push_back(off_label); bool comb_comp_en = false; - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_PROBE_COMB_COMP_EN); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_PROBE_COMB_COMP_EN); if (gvar != NULL) { comb_comp_en = g_variant_get_boolean(gvar); g_variant_unref(gvar); } if (comb_comp_en) { int16_t comb_comp = 0; - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_COMB_COMP); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_COMB_COMP); if (gvar != NULL) { comb_comp = g_variant_get_int16(gvar); g_variant_unref(gvar); @@ -229,14 +234,14 @@ void Calibration::set_device(DevInst *dev_inst) void Calibration::accept() { using namespace Qt; - _dev_inst->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(false)); + _device_agent->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(false)); QDialog::accept(); } void Calibration::reject() { using namespace Qt; - _dev_inst->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(false)); + _device_agent->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(false)); QDialog::reject(); } @@ -244,25 +249,25 @@ void Calibration::set_value(int value) { QSlider* sc = dynamic_cast(sender()); - for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); if (sc->objectName() == VGAIN+probe->index) { uint64_t vgain_default; - GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT); + GVariant* gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT); if (gvar != NULL) { vgain_default = g_variant_get_uint64(gvar); g_variant_unref(gvar); - _dev_inst->set_config(probe, NULL, SR_CONF_PROBE_VGAIN, + _device_agent->set_config(probe, NULL, SR_CONF_PROBE_VGAIN, g_variant_new_uint64(value+vgain_default)); } break; } else if (sc->objectName() == VOFF+probe->index) { - _dev_inst->set_config(probe, NULL, SR_CONF_PROBE_PREOFF, + _device_agent->set_config(probe, NULL, SR_CONF_PROBE_PREOFF, g_variant_new_uint16(value)); break; } else if (sc->objectName() == VCOMB+probe->index) { - _dev_inst->set_config(probe, NULL, SR_CONF_PROBE_COMB_COMP, + _device_agent->set_config(probe, NULL, SR_CONF_PROBE_COMB_COMP, g_variant_new_int16(value)); break; } @@ -275,7 +280,7 @@ void Calibration::on_save() QFuture future; future = QtConcurrent::run([&]{ //QTime dieTime = QTime::currentTime().addSecs(1); - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_SET, + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO_SET, g_variant_new_boolean(true)); //while( QTime::currentTime() < dieTime ); }); @@ -301,7 +306,7 @@ void Calibration::on_abort() QFuture future; future = QtConcurrent::run([&]{ //QTime dieTime = QTime::currentTime().addSecs(1); - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_LOAD, + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO_LOAD, g_variant_new_boolean(true)); reload_value(); //while( QTime::currentTime() < dieTime ); @@ -324,23 +329,23 @@ void Calibration::on_abort() void Calibration::reload_value() { - for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); uint64_t vgain = 0, vgain_default = 0; uint16_t vgain_range = 0; - GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN); + GVariant* gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_VGAIN); if (gvar != NULL) { vgain = g_variant_get_uint64(gvar); g_variant_unref(gvar); } - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_DEFAULT); if (gvar != NULL) { vgain_default = g_variant_get_uint64(gvar); g_variant_unref(gvar); } - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_RANGE); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_VGAIN_RANGE); if (gvar != NULL) { vgain_range = g_variant_get_uint16(gvar); g_variant_unref(gvar); @@ -348,12 +353,12 @@ void Calibration::reload_value() uint64_t voff = 0; uint16_t voff_range = 0; - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_PREOFF); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_PREOFF); if (gvar != NULL) { voff = g_variant_get_uint16(gvar); g_variant_unref(gvar); } - gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_PREOFF_MARGIN); + gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_PREOFF_MARGIN); if (gvar != NULL) { voff_range = g_variant_get_uint16(gvar); g_variant_unref(gvar); @@ -382,7 +387,7 @@ void Calibration::on_reset() msg.mBox()->addButton(tr("Cancel"), QMessageBox::RejectRole); msg.mBox()->setIcon(QMessageBox::Warning); if (msg.exec()) { - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_DEFAULT, + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO_DEFAULT, g_variant_new_boolean(true)); reload_value(); } diff --git a/DSView/pv/dialogs/calibration.h b/DSView/pv/dialogs/calibration.h index 6253de04..5c4792e2 100644 --- a/DSView/pv/dialogs/calibration.h +++ b/DSView/pv/dialogs/calibration.h @@ -37,7 +37,10 @@ using namespace pv::device; +class DeviceAgent; + namespace pv { + namespace dialogs { class Calibration : public DSDialog @@ -53,7 +56,8 @@ public: Calibration(QWidget *parent); ~Calibration(); - void set_device(DevInst *dev_inst); + void update_device_info(); + protected: void accept(); void reject(); @@ -69,9 +73,7 @@ private slots: void on_reset(); void reload_value(); -private: - DevInst *_dev_inst; - +private: QPushButton *_save_btn; QPushButton *_abort_btn; QPushButton *_reset_btn; @@ -79,6 +81,8 @@ private: QFormLayout *_flayout; std::list _slider_list; std::list _label_list; + + DeviceAgent *_device_agent; }; } // namespace dialogs diff --git a/DSView/pv/dialogs/deviceoptions.cpp b/DSView/pv/dialogs/deviceoptions.cpp index d8bb0cc4..6d4131cc 100644 --- a/DSView/pv/dialogs/deviceoptions.cpp +++ b/DSView/pv/dialogs/deviceoptions.cpp @@ -35,6 +35,8 @@ #include "../prop/property.h" #include "../dsvdef.h" #include "../config/appconfig.h" +#include "../appcontrol.h" +#include "../sigsession.h" using namespace boost; using namespace std; @@ -43,7 +45,7 @@ ChannelLabel::ChannelLabel(IChannelCheck *check, QWidget *parent, int chanIndex) : QWidget(parent) { _checked = check; - _index = chanIndex; + _index = chanIndex; this->setFixedSize(30, 40); @@ -77,8 +79,7 @@ namespace pv { namespace dialogs { DeviceOptions::DeviceOptions(QWidget *parent) : - DSDialog(parent), - _device_options_binding(_dev_inst->dev_inst()) + DSDialog(parent) { _scroll_panel = NULL; _container_panel = NULL; @@ -90,6 +91,9 @@ DeviceOptions::DeviceOptions(QWidget *parent) : _container_lay = NULL; _isBuilding = false; + SigSession *session = AppControl::Instance()->GetSession(); + _device_agent = session->get_device(); + this->setTitle(tr("Device Options")); this->SetTitleSpace(0); this->layout()->setSpacing(0); @@ -134,7 +138,7 @@ DeviceOptions::DeviceOptions(QWidget *parent) : auto button_box = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, this); this->layout()->addWidget(button_box); - GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_OPERATION_MODE); + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_OPERATION_MODE); if (gvar != NULL) { _mode = QString::fromUtf8(g_variant_get_string(gvar, NULL)); g_variant_unref(gvar); @@ -144,7 +148,7 @@ DeviceOptions::DeviceOptions(QWidget *parent) : connect(&_mode_check, SIGNAL(timeout()), this, SLOT(mode_check())); connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); - connect(_dev_inst, SIGNAL(device_updated()), this, SLOT(reject())); + connect(_device_agent, SIGNAL(device_updated()), this, SLOT(reject())); _mode_check.setInterval(100); _mode_check.start(); @@ -166,10 +170,10 @@ void DeviceOptions::accept() } // Commit the probes - if (_dev_inst->dev_inst()->mode == LOGIC || - _dev_inst->dev_inst()->mode == ANALOG) { + int mode = _device_agent->get_work_mode(); + if (mode == LOGIC || mode == ANALOG) { int index = 0; - for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); probe->enabled = _probes_checkBox_list.at(index)->isChecked(); @@ -254,13 +258,16 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout) _probes_checkBox_list.clear(); //channel count checked - if (_dev_inst->dev_inst()->mode == LOGIC) { + if (_device_agent->get_work_mode()== LOGIC) { GVariant *gvar_opts; gsize num_opts; - if (sr_config_list(_dev_inst->dev_inst()->driver, _dev_inst->dev_inst(), NULL, SR_CONF_CHANNEL_MODE, - &gvar_opts) == SR_OK) { + + gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_CHANNEL_MODE); + + if (gvar_opts != NULL) + { const char **const options = g_variant_get_strv(gvar_opts, &num_opts); - GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_CHANNEL_MODE); + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_CHANNEL_MODE); if (gvar != NULL) { QString ch_mode = QString::fromUtf8(g_variant_get_string(gvar, NULL)); g_variant_unref(gvar); @@ -283,7 +290,7 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout) } } - GVariant *gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_VLD_CH_NUM); + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_VLD_CH_NUM); if (gvar != NULL) { vld_ch_num = g_variant_get_int16(gvar); g_variant_unref(gvar); @@ -292,7 +299,7 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout) // channels QHBoxLayout *line_lay = NULL; - for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); @@ -372,7 +379,7 @@ void DeviceOptions::enable_max_probes() { cur_ch_num++; } - GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_VLD_CH_NUM); + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_VLD_CH_NUM); if (gvar == NULL) return; @@ -390,7 +397,7 @@ void DeviceOptions::enable_max_probes() { void DeviceOptions::enable_all_probes() { - GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_STREAM); + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_STREAM); if (gvar != NULL) { bool stream_mode = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -422,9 +429,9 @@ void DeviceOptions::zero_adj() msg.mBox()->setIcon(QMessageBox::Information); if (msg.exec()) { - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(true)); + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(true)); } else { - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); } } @@ -432,7 +439,7 @@ void DeviceOptions::on_calibration() { using namespace Qt; QDialog::accept(); - _dev_inst->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(true)); + _device_agent->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(true)); } void DeviceOptions::mode_check() @@ -442,7 +449,7 @@ void DeviceOptions::mode_check() bool test; QString mode; - GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_OPERATION_MODE); + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_OPERATION_MODE); if (gvar != NULL) { mode = QString::fromUtf8(g_variant_get_string(gvar, NULL)); g_variant_unref(gvar); @@ -454,7 +461,7 @@ void DeviceOptions::mode_check() } } - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_TEST); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); if (gvar != NULL) { test = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -475,7 +482,7 @@ void DeviceOptions::channel_check() text.remove('&'); if(sc != NULL){ - _dev_inst->set_config(NULL, NULL, SR_CONF_CHANNEL_MODE, g_variant_new_string(text.toUtf8().data())); + _device_agent->set_config(NULL, NULL, SR_CONF_CHANNEL_MODE, g_variant_new_string(text.toUtf8().data())); } build_dynamic_panel(); @@ -486,11 +493,11 @@ void DeviceOptions::analog_channel_check() { QCheckBox* sc=dynamic_cast(sender()); if(sc != NULL) { - for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); if (sc->property("index").toInt() == probe->index) - _dev_inst->set_config(probe, NULL, SR_CONF_PROBE_MAP_DEFAULT, + _device_agent->set_config(probe, NULL, SR_CONF_PROBE_MAP_DEFAULT, g_variant_new_boolean(sc->isChecked())); } } @@ -501,12 +508,12 @@ void DeviceOptions::analog_channel_check() void DeviceOptions::channel_enable() { - if (_dev_inst->dev_inst()->mode == LOGIC) { + if (_device_agent->get_work_mode() == LOGIC) { QCheckBox* sc=dynamic_cast(sender()); if (sc == NULL || !sc->isChecked()) return; - GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_STREAM); + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_STREAM); if (gvar == NULL) return; @@ -522,7 +529,7 @@ void DeviceOptions::channel_enable() cur_ch_num++; } - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_VLD_CH_NUM); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_VLD_CH_NUM); if (gvar == NULL) return; @@ -539,7 +546,7 @@ void DeviceOptions::channel_enable() sc->setChecked(false); } } - else if (_dev_inst->dev_inst()->mode == ANALOG) { + else if (_device_agent->get_work_mode() == ANALOG) { QCheckBox* sc=dynamic_cast(sender()); if (sc != NULL) { QGridLayout *const layout = (QGridLayout *)sc->property("Layout").value(); @@ -567,7 +574,7 @@ void DeviceOptions::analog_probes(QGridLayout &layout) tabWidget->setUsesScrollButtons(false); //layout.setContentsMargins(0,20, 0, 10); - for (const GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); @@ -588,7 +595,7 @@ void DeviceOptions::analog_probes(QGridLayout &layout) probe_layout->addWidget(probe_checkBox, 0, 1, 1, 3); pv::prop::binding::ProbeOptions *probe_options_binding = - new pv::prop::binding::ProbeOptions(_dev_inst->dev_inst(), probe); + new pv::prop::binding::ProbeOptions(probe); const auto &properties = probe_options_binding->properties(); int i = 1; @@ -606,7 +613,7 @@ void DeviceOptions::analog_probes(QGridLayout &layout) } else { if (probe_checkBox->isChecked() && p->name().contains("Map")) { bool map_default = true; - GVariant* gvar = _dev_inst->get_config(probe, NULL, SR_CONF_PROBE_MAP_DEFAULT); + GVariant* gvar = _device_agent->get_config(probe, NULL, SR_CONF_PROBE_MAP_DEFAULT); if (gvar != NULL) { map_default =g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -636,16 +643,18 @@ void DeviceOptions::ChannelChecked(int index) channel_enable(); } -QString DeviceOptions::dynamic_widget(QLayout *lay) { +QString DeviceOptions::dynamic_widget(QLayout *lay) + { + int mode = _device_agent->get_work_mode(); - if (_dev_inst->dev_inst()->mode == LOGIC) { + if (mode == LOGIC) { QVBoxLayout *grid = dynamic_cast(lay); assert(grid); logic_probes(*grid); return tr("Channels"); } - else if (_dev_inst->dev_inst()->mode == DSO) { - GVariant* gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_HAVE_ZERO); + else if (mode == DSO) { + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_HAVE_ZERO); if (gvar != NULL) { bool have_zero = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -669,7 +678,7 @@ QString DeviceOptions::dynamic_widget(QLayout *lay) { } } } - else if (_dev_inst->dev_inst()->mode == ANALOG) { + else if (mode == ANALOG) { QGridLayout *grid = dynamic_cast(lay); assert(grid); analog_probes(*grid); @@ -692,7 +701,7 @@ void DeviceOptions::build_dynamic_panel() _dynamic_panel = new QGroupBox("group", _dynamic_panel); _container_lay->addWidget(_dynamic_panel); - if (_dev_inst->dev_inst()->mode == LOGIC) + if (_device_agent->get_work_mode() == LOGIC) _dynamic_panel->setLayout(new QVBoxLayout()); else _dynamic_panel->setLayout(new QGridLayout()); diff --git a/DSView/pv/dialogs/deviceoptions.h b/DSView/pv/dialogs/deviceoptions.h index 47db8746..cef04982 100644 --- a/DSView/pv/dialogs/deviceoptions.h +++ b/DSView/pv/dialogs/deviceoptions.h @@ -73,7 +73,10 @@ private: using namespace pv::device; +class DeviceAgent; + namespace pv { + namespace dialogs { class DeviceOptions : public DSDialog, public IChannelCheck @@ -131,6 +134,7 @@ private: int _groupHeight1; int _groupHeight2; volatile bool _isBuilding; + DeviceAgent *_device_agent; pv::prop::binding::DeviceOptions _device_options_binding; QVector _probe_options_binding_list; diff --git a/DSView/pv/dialogs/waitingdialog.cpp b/DSView/pv/dialogs/waitingdialog.cpp index 1817c34b..1be4bbe4 100644 --- a/DSView/pv/dialogs/waitingdialog.cpp +++ b/DSView/pv/dialogs/waitingdialog.cpp @@ -49,7 +49,8 @@ WaitingDialog::WaitingDialog(QWidget *parent, SigSession *session, int key) : _button_box(QDialogButtonBox::Abort, Qt::Horizontal, this) { - _dev_inst = _session->get_device(); + _device_agent = _session->get_device(); + this->setFixedSize((GIF_WIDTH+2*TIP_WIDTH)*1.2, (GIF_HEIGHT+2*TIP_HEIGHT)*4); this->setWindowOpacity(0.7); @@ -78,7 +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(_dev_inst, SIGNAL(device_updated()), this, SLOT(stop())); + connect(_device_agent, SIGNAL(device_updated()), this, SLOT(stop())); QVBoxLayout *mlayout = new QVBoxLayout(); @@ -100,7 +101,7 @@ void WaitingDialog::accept() QFuture future; future = QtConcurrent::run([&]{ - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_SET, + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO_SET, g_variant_new_boolean(true)); }); Qt::WindowFlags flags = Qt::CustomizeWindowHint; @@ -128,8 +129,8 @@ void WaitingDialog::reject() QFuture future; future = QtConcurrent::run([&]{ - _dev_inst->set_config(NULL, NULL, _key, g_variant_new_boolean(false)); - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_LOAD, + _device_agent->set_config(NULL, NULL, _key, g_variant_new_boolean(false)); + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO_LOAD, g_variant_new_boolean(true)); }); Qt::WindowFlags flags = Qt::CustomizeWindowHint; @@ -174,12 +175,12 @@ void WaitingDialog::changeText() bool comb_comp_en = false; bool zero_fgain = false; - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_PROBE_COMB_COMP_EN); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_PROBE_COMB_COMP_EN); if (gvar != NULL) { comb_comp_en = g_variant_get_boolean(gvar); g_variant_unref(gvar); if (comb_comp_en) { - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_ZERO_COMB_FGAIN); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO_COMB_FGAIN); if (gvar != NULL) { zero_fgain = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -192,13 +193,13 @@ void WaitingDialog::changeText() dsoSig->set_enable(dsoSig->get_index() == 0); } std::this_thread::sleep_for(std::chrono::milliseconds(100)); - _dev_inst->set_config(NULL, NULL, SR_CONF_ZERO_COMB, g_variant_new_boolean(true)); + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO_COMB, g_variant_new_boolean(true)); } } } } - gvar = _dev_inst->get_config(NULL, NULL, _key); + gvar = _device_agent->get_config(NULL, NULL, _key); if (gvar != NULL) { bool zero = g_variant_get_boolean(gvar); g_variant_unref(gvar); diff --git a/DSView/pv/dialogs/waitingdialog.h b/DSView/pv/dialogs/waitingdialog.h index dd1071d0..bec11f1c 100644 --- a/DSView/pv/dialogs/waitingdialog.h +++ b/DSView/pv/dialogs/waitingdialog.h @@ -35,7 +35,10 @@ using namespace pv::device; +class DeviceAgent; + namespace pv { + namespace dialogs { class WaitingDialog : public DSDialog @@ -67,7 +70,6 @@ private slots: private: int _key; SigSession *_session; - DevInst* _dev_inst; toolbars::TitleBar *_titlebar; QDialogButtonBox _button_box; @@ -76,6 +78,7 @@ private: QMovie *movie; QTimer *timer; QLabel *tips; + DeviceAgent *_device_agent; }; } // namespace dialogs diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index 7ce32f22..209a4bab 100644 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -30,8 +30,7 @@ #include "../view/ruler.h" #include "../view/logicsignal.h" #include "../data/signaldata.h" -#include "../data/snapshot.h" -#include "../devicemanager.h" +#include "../data/snapshot.h" #include "../device/device.h" #include "../device/file.h" #include "../dialogs/dsdialog.h" @@ -211,7 +210,7 @@ void MeasureDock::refresh() void MeasureDock::reload() { - if (_session->get_device()->dev_inst()->mode == LOGIC) + if (_session->get_device()->get_work_mode() == LOGIC) _edge_groupBox->setVisible(true); else _edge_groupBox->setVisible(false); diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index 37510258..fd7ae88c 100644 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -360,13 +360,8 @@ void ProtocolDock::on_add_protocol() } bool ProtocolDock::add_protocol_by_id(QString id, bool silent, std::list &sub_decoders) -{ - if (_session->is_device_re_attach() == true){ - dsv_info("%s", "Keep current decoders, cancel add new."); - return true; - } - - if (_session->get_device()->dev_inst()->mode != LOGIC) { +{ + if (_session->get_device()->get_work_mode() != LOGIC) { dsv_info("%s", "Protocol Analyzer\nProtocol Analyzer is only valid in Digital Mode!"); return false; } @@ -431,7 +426,7 @@ bool ProtocolDock::add_protocol_by_id(QString id, bool silent, std::list 0 && _session->is_device_re_attach() == false) + if (_protocol_lay_items.size() > 0) { _session->clear_all_decoder(); diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index bca33960..bcbe3798 100644 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -46,7 +46,7 @@ TriggerDock::TriggerDock(QWidget *parent, SigSession *session) : _session(session) { _cur_ch_num = 16; - if (_session->get_device()) { + if (_session->get_device()->have_instance()) { GVariant *gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TOTAL_CH_NUM); if (gvar != NULL) { _cur_ch_num = g_variant_get_int16(gvar); @@ -251,11 +251,13 @@ void TriggerDock::device_updated() uint8_t maxRange; uint64_t sample_limits; GVariant *gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_HW_DEPTH); + int mode = _session->get_device()->get_work_mode(); + if (gvar != NULL) { hw_depth = g_variant_get_uint64(gvar); g_variant_unref(gvar); - if (_session->get_device()->dev_inst()->mode == LOGIC) { + if (mode == LOGIC) { gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_STREAM); if (gvar != NULL) { diff --git a/DSView/pv/interface/icallbacks.h b/DSView/pv/interface/icallbacks.h index 92d296ff..7b103461 100644 --- a/DSView/pv/interface/icallbacks.h +++ b/DSView/pv/interface/icallbacks.h @@ -54,7 +54,7 @@ public: virtual void receive_header()=0; virtual void data_received()=0; - virtual void device_list_changed(); + virtual void device_list_changed() = 0; }; diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 43672d3b..0556e5fb 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -42,6 +42,8 @@ #include #include #include +#include +#include #ifdef _WIN32 #include @@ -49,10 +51,6 @@ #include "mainwindow.h" -#include "devicemanager.h" -#include "device/device.h" -#include "device/file.h" - #include "data/logicsnapshot.h" #include "data/dsosnapshot.h" #include "data/analogsnapshot.h" @@ -96,9 +94,11 @@ #include "utility/encoding.h" #include "utility/path.h" #include "log.h" +#include "sigsession.h" +#include "deviceagent.h" #define BASE_SESSION_VERSION 2 - + namespace pv { @@ -106,9 +106,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), _hot_detach(false), _msg(NULL) -{ - _control = AppControl::Instance(); - _control->GetSession()->set_callback(this); +{ + _session = AppControl::Instance()->GetSession(); + _session->set_callback(this); + _device_agent = _session->get_device(); + _bFirstLoad = true; setup_ui(); @@ -118,8 +120,6 @@ MainWindow::MainWindow(QWidget *parent) : void MainWindow::setup_ui() { - SigSession *_session = _control->GetSession(); - setObjectName(QString::fromUtf8("MainWindow")); setContentsMargins(0,0,0,0); layout()->setSpacing(0); @@ -234,8 +234,6 @@ void MainWindow::setup_ui() // UI initial _measure_widget->add_dist_measure(); - - _session->start_hotplug_work(); retranslateUi(); @@ -253,9 +251,6 @@ void MainWindow::setup_ui() connect(&_event, SIGNAL(data_updated()), this, SLOT(on_data_updated())); connect(&_event, SIGNAL(cur_snap_samplerate_changed()), this, SLOT(on_cur_snap_samplerate_changed())); connect(&_event, SIGNAL(receive_data_len(quint64)), this, SLOT(on_receive_data_len(quint64))); - connect(&_event, SIGNAL(update_device_list()), this, SLOT(on_device_list_changed())); - - //view connect(_view, SIGNAL(cursor_update()), _measure_widget, SLOT(cursor_update())); connect(_view, SIGNAL(cursor_moving()), _measure_widget, SLOT(cursor_moving())); @@ -324,12 +319,13 @@ void MainWindow::update_device_list() { assert(_sampling_bar); + /* + if (_msg) _msg->close(); AppConfig &app = AppConfig::Instance(); - - SigSession *_session = _control->GetSession(); + switchLanguage(app._frameOptions.language); _session->stop_capture(); @@ -339,10 +335,8 @@ void MainWindow::update_device_list() _protocol_widget->del_all_protocol(); _trig_bar->reload(); - - DeviceManager &_device_manager = _control->GetDeviceManager(); - - DevInst *selected_device = _session->get_device(); + + DevInst *selected_device = _device_agent; _device_manager.add_device(selected_device); _session->init_signals(); _sampling_bar->set_device_list(_device_manager.devices(), selected_device); @@ -455,12 +449,12 @@ void MainWindow::update_device_list() } } } + */ } void MainWindow::on_device_updated_reload() -{ - SigSession *_session = _control->GetSession(); +{ _trigger_widget->device_updated(); _session->reload(); _measure_widget->reload(); @@ -468,10 +462,9 @@ void MainWindow::on_device_updated_reload() void MainWindow::on_load_file(QString file_name) { - SigSession *_session = _control->GetSession(); try { - if (strncmp(_session->get_device()->name().toUtf8(), "virtual", 7)) + if (strncmp(_device_agent->name().toUtf8(), "virtual", 7)) session_save(); _session->set_file(file_name); } catch(QString e) { @@ -499,9 +492,9 @@ void MainWindow::device_attach() void MainWindow::on_device_attach() { - SigSession *_session = _control->GetSession(); + /* - _session->get_device()->device_updated(); + _device_agent->device_updated(); _session->set_repeating(false); _session->stop_capture(); @@ -510,9 +503,7 @@ void MainWindow::on_device_attach() struct sr_dev_driver **const drivers = sr_driver_list(); struct sr_dev_driver **driver; - - DeviceManager &_device_manager = _control->GetDeviceManager(); - + for (driver = drivers; *driver; driver++) { if (*driver){ @@ -523,6 +514,7 @@ void MainWindow::on_device_attach() _session->set_default_device(); update_device_list(); + */ } void MainWindow::device_detach(){ @@ -531,9 +523,9 @@ void MainWindow::device_detach(){ void MainWindow::on_device_detach() { - SigSession *_session = _control->GetSession(); + /* - _session->get_device()->device_updated(); + _device_agent->device_updated(); //_session->stop_hot_plug_proc(); _session->set_repeating(false); @@ -544,8 +536,8 @@ void MainWindow::on_device_detach() session_save(); _view->hide_calibration(); - if (_session->get_device()->dev_inst()->mode != DSO && - strncmp(_session->get_device()->name().toUtf8(), "virtual", 7)) { + 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); @@ -566,18 +558,18 @@ void MainWindow::on_device_detach() } _hot_detach = true; + if (!_session->get_saving()) device_detach_post(); + */ } void MainWindow::device_detach_post() -{ - SigSession *_session = _control->GetSession(); - +{ if (!_hot_detach) return; - DeviceManager &_device_manager = _control->GetDeviceManager(); + /* _hot_detach = false; struct sr_dev_driver **const drivers = sr_driver_list(); struct sr_dev_driver **driver; @@ -590,12 +582,11 @@ void MainWindow::device_detach_post() _session->set_default_device(); update_device_list(); + */ } void MainWindow::device_changed(bool close) -{ - SigSession *_session = _control->GetSession(); - +{ if (close) { _sampling_bar->set_sampling(false); _session->set_default_device(); @@ -606,8 +597,6 @@ void MainWindow::device_changed(bool close) void MainWindow::on_run_stop() { - SigSession *_session = _control->GetSession(); - switch(_session->get_capture_state()) { case SigSession::Init: case SigSession::Stopped: @@ -623,9 +612,7 @@ void MainWindow::on_run_stop() } void MainWindow::on_instant_stop() -{ - SigSession *_session = _control->GetSession(); - +{ switch(_session->get_capture_state()) { case SigSession::Init: case SigSession::Stopped: @@ -659,8 +646,6 @@ void MainWindow::on_session_error() QString ch_status = ""; uint64_t error_pattern; - SigSession *_session = _control->GetSession(); - switch(_session->get_error()) { case SigSession::Hw_err: _session->set_repeating(false); @@ -710,7 +695,7 @@ void MainWindow::on_session_error() } dialogs::DSMessageBox msg(this); - connect(_session->get_device(), SIGNAL(device_updated()), &msg, SLOT(accept())); + connect(_device_agent, SIGNAL(device_updated()), &msg, SLOT(accept())); QFont font("Monaco"); font.setStyleHint(QFont::Monospace); font.setFixedPitch(true); @@ -731,15 +716,13 @@ void MainWindow::capture_state_changed(int state) } void MainWindow::on_capture_state_changed(int state) -{ - SigSession *_session = _control->GetSession(); - +{ 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 (_session->get_device()->dev_inst()->mode != DSO || + if (_device_agent->get_work_mode() != DSO || _session->get_instant()) { _sampling_bar->enable_toggle(state != SigSession::Running); _trig_bar->enable_toggle(state != SigSession::Running); @@ -763,13 +746,17 @@ void MainWindow::session_save() QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation); #endif - AppConfig &app = AppConfig::Instance(); - SigSession *_session = _control->GetSession(); + if (_device_agent->have_instance() == false){ + dsv_info("%s", "There is no need to save the configuration"); + return; + } + + AppConfig &app = AppConfig::Instance(); if(dir.mkpath(path)) { dir.cd(path); - QString driver_name = _session->get_device()->name(); - QString mode_name = QString::number(_session->get_device()->dev_inst()->mode); + QString driver_name = _device_agent->name(); + QString mode_name = QString::number(_device_agent->get_work_mode()); QString lang_name = ".ses" + QString::number(app._frameOptions.language); QString file_name = dir.absolutePath() + "/" + driver_name + mode_name + @@ -799,10 +786,8 @@ void MainWindow::on_protocol(bool visible) } void MainWindow::on_trigger(bool visible) -{ - SigSession *_session = _control->GetSession(); - - if (_session->get_device()->dev_inst()->mode != DSO) { +{ + if (_device_agent->get_work_mode() != DSO) { _trigger_widget->init(); _trigger_dock->setVisible(visible); _dso_trigger_dock->setVisible(false); @@ -818,12 +803,9 @@ void MainWindow::commit_trigger(bool instant) { int i = 0; - AppConfig &app = AppConfig::Instance(); - SigSession *_session = _control->GetSession(); + AppConfig &app = AppConfig::Instance(); - ds_trigger_init(); - - if (_session->get_device()->dev_inst()->mode != LOGIC || + if (_device_agent->get_work_mode() != LOGIC || instant) return; @@ -935,7 +917,11 @@ void MainWindow::on_save() { using pv::dialogs::StoreProgress; - SigSession *_session = _control->GetSession(); + if (_device_agent->have_instance() == false){ + dsv_info("%s", "Have no device, can't to save data."); + return; + } + _session->set_saving(true); StoreProgress *dlg = new StoreProgress(_session, this); @@ -945,8 +931,7 @@ void MainWindow::on_save() void MainWindow::on_export() { - using pv::dialogs::StoreProgress; - SigSession *_session = _control->GetSession(); + using pv::dialogs::StoreProgress; StoreProgress *dlg = new StoreProgress(_session, this); dlg->export_run(); @@ -970,6 +955,8 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev, bool bDeco { QJsonObject sessionObj = json.object(); + /* + // check session file version if (!sessionObj.contains("Version")){ dsv_dbg("%s", "session file version is not exists!"); @@ -985,11 +972,10 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev, bool bDeco if (sessionObj["Version"].toInt() == BASE_SESSION_VERSION){ switchLanguage(sessionObj["Language"].toInt()); } - - SigSession *_session = _control->GetSession(); + // check device and mode - const sr_dev_inst *const sdi = _session->get_device()->dev_inst(); + const sr_dev_inst *const sdi = _device_agent->dev_inst(); if ((!file_dev && strcmp(sdi->driver->name, sessionObj["Device"].toString().toUtf8()) != 0) || sdi->mode != sessionObj["DeviceMode"].toDouble()) { MsgBox::Show(NULL, tr("Session File is not compatible with current device or mode!"), this); @@ -1014,21 +1000,21 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev, bool bDeco if (!sessionObj.contains(info->name)) continue; if (info->datatype == SR_T_BOOL) - _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_boolean(sessionObj[info->name].toDouble())); + _device_agent->set_config(NULL, NULL, info->key, g_variant_new_boolean(sessionObj[info->name].toDouble())); else if (info->datatype == SR_T_UINT64) - _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_uint64(sessionObj[info->name].toString().toULongLong())); + _device_agent->set_config(NULL, NULL, info->key, g_variant_new_uint64(sessionObj[info->name].toString().toULongLong())); else if (info->datatype == SR_T_UINT8) - _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_byte(sessionObj[info->name].toString().toUInt())); + _device_agent->set_config(NULL, NULL, info->key, g_variant_new_byte(sessionObj[info->name].toString().toUInt())); else if (info->datatype == SR_T_FLOAT) - _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_double(sessionObj[info->name].toDouble())); + _device_agent->set_config(NULL, NULL, info->key, g_variant_new_double(sessionObj[info->name].toDouble())); else if (info->datatype == SR_T_CHAR) - _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_string(sessionObj[info->name].toString().toUtf8())); + _device_agent->set_config(NULL, NULL, info->key, g_variant_new_string(sessionObj[info->name].toString().toUtf8())); } } // load channel settings if (file_dev && (sdi->mode == DSO)) { - for (const GSList *l = _session->get_device()->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->dev_inst()->channels; l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); @@ -1048,7 +1034,7 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev, bool bDeco } } } else { - for (const GSList *l = _session->get_device()->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _device_agent->dev_inst()->channels; l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); bool isEnabled = false; @@ -1155,34 +1141,38 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev, bool bDeco if (sessionObj.contains("measure")) { _view->get_viewstatus()->load_session(sessionObj["measure"].toArray()); } + */ return true; } -bool MainWindow::gen_session_json(QJsonObject &sessionVar){ - SigSession *_session = _control->GetSession(); +bool MainWindow::gen_session_json(QJsonObject &sessionVar) +{ AppConfig &app = AppConfig::Instance(); GVariant *gvar_opts; GVariant *gvar; - gsize num_opts; - const sr_dev_inst *const sdi = _session->get_device()->dev_inst(); + gsize num_opts; QJsonArray channelVar; sessionVar["Version"]= QJsonValue::fromVariant(BASE_SESSION_VERSION); - sessionVar["Device"] = QJsonValue::fromVariant(sdi->driver->name); - sessionVar["DeviceMode"] = QJsonValue::fromVariant(sdi->mode); + sessionVar["Device"] = QJsonValue::fromVariant(_device_agent->driver_name()); + sessionVar["DeviceMode"] = QJsonValue::fromVariant(_device_agent->get_work_mode()); sessionVar["Language"] = QJsonValue::fromVariant(app._frameOptions.language); - if ((sr_config_list(sdi->driver, sdi, NULL, SR_CONF_DEVICE_SESSIONS, &gvar_opts) != SR_OK)) - return false; /* Driver supports no device instance sessions. */ + gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_DEVICE_SESSIONS); + if (gvar_opts == NULL){ + dsv_warn("%s", "Device config list is empty. id:SR_CONF_DEVICE_SESSIONS"); + /* Driver supports no device instance sessions. */ + return false; + } const int *const options = (const int32_t *)g_variant_get_fixed_array( gvar_opts, &num_opts, sizeof(int32_t)); + for (unsigned int i = 0; i < num_opts; i++) { - const struct sr_config_info *const info = - sr_config_info_get(options[i]); - gvar = _session->get_device()->get_config(NULL, NULL, info->key); + const struct sr_config_info *const info = _device_agent->get_config_info(options[i]); + gvar = _device_agent->get_config(NULL, NULL, info->key); if (gvar != NULL) { if (info->datatype == SR_T_BOOL) sessionVar[info->name] = QJsonValue::fromVariant(g_variant_get_boolean(gvar)); @@ -1237,7 +1227,7 @@ bool MainWindow::gen_session_json(QJsonObject &sessionVar){ } sessionVar["channel"] = channelVar; - if (_session->get_device()->dev_inst()->mode == LOGIC) { + if (_device_agent->get_work_mode() == LOGIC) { sessionVar["trigger"] = _trigger_widget->get_session(); } @@ -1246,7 +1236,7 @@ bool MainWindow::gen_session_json(QJsonObject &sessionVar){ ss.json_decoders(decodeJson); sessionVar["decoder"] = decodeJson; - if (_session->get_device()->dev_inst()->mode == DSO) { + if (_device_agent->get_work_mode() == DSO) { sessionVar["measure"] = _view->get_viewstatus()->get_session(); } @@ -1298,18 +1288,16 @@ void MainWindow::restore_dock() { MsgBox::Show(NULL, tr("restore window status error!")); } - } + } - SigSession *_session = _control->GetSession(); - - if (_session->get_device()->dev_inst()->mode != DSO) { + if (_device_agent->get_work_mode() != DSO) { _dso_trigger_dock->setVisible(false); _trig_bar->update_trig_btn(_trigger_dock->isVisible()); } else { _trigger_dock->setVisible(false); _trig_bar->update_trig_btn(_dso_trigger_dock->isVisible()); } - if (_session->get_device()->dev_inst()->mode != LOGIC) { + if (_device_agent->get_work_mode() != LOGIC) { on_protocol(false); @@ -1323,8 +1311,8 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) { (void) object; - if ( event->type() == QEvent::KeyPress ) { - SigSession *_session = _control->GetSession(); + if ( event->type() == QEvent::KeyPress ) + { const auto &sigs = _session->get_signals(); QKeyEvent *ke = (QKeyEvent *) event; switch(ke->key()) { @@ -1335,7 +1323,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) on_instant_stop(); break; case Qt::Key_T: - if (_session->get_device()->dev_inst()->mode == DSO) + if (_device_agent->get_work_mode() == DSO) on_trigger(!_dso_trigger_dock->isVisible()); else on_trigger(!_trigger_dock->isVisible()); @@ -1433,9 +1421,8 @@ void MainWindow::switchLanguage(int language) if (language == 0) return; - SigSession *_session = _control->GetSession(); - DevInst *dev = _session->get_device(); - dev->set_config(NULL, NULL, SR_CONF_LANGUAGE, g_variant_new_int16(language)); + if (_device_agent->have_instance()) + _device_agent->set_config(NULL, NULL, SR_CONF_LANGUAGE, g_variant_new_int16(language)); AppConfig &app = AppConfig::Instance(); if (app._frameOptions.language != language && language > 0) @@ -1604,7 +1591,7 @@ void MainWindow::data_received(){ void MainWindow::device_list_changed() { - + _sampling_bar->update_device_list(); } } // namespace pv diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index 36a5006c..463ad304 100644 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -31,6 +31,7 @@ #include "interface/icallbacks.h" #include "eventobject.h" #include "interface/uicallback.h" +#include class QAction; class QMenuBar; @@ -43,8 +44,11 @@ class QDockWidget; class AppControl; +class DeviceAgent; + namespace pv { +class SigSession; namespace toolbars { class SamplingBar; @@ -178,8 +182,7 @@ private: //------private bool gen_session_json(QJsonObject &sessionVar); -private: - AppControl *_control; +private: bool _hot_detach; pv::view::View *_view; @@ -223,6 +226,8 @@ private: QTranslator _myTrans; EventObject _event; bool _bFirstLoad; + SigSession *_session; + DeviceAgent *_device_agent; }; } // namespace pv diff --git a/DSView/pv/prop/binding/deviceoptions.cpp b/DSView/pv/prop/binding/deviceoptions.cpp index ebebb5eb..c647cba9 100644 --- a/DSView/pv/prop/binding/deviceoptions.cpp +++ b/DSView/pv/prop/binding/deviceoptions.cpp @@ -32,6 +32,8 @@ #include "../../config/appconfig.h" #include "../../log.h" #include "../../appcontrol.h" +#include "../../sigsession.h" +#include "../../deviceagent.h" using namespace std; @@ -45,35 +47,37 @@ DeviceOptions::DeviceOptions() gsize num_opts; SigSession *session = AppControl::Instance()->GetSession(); + _device_agent = session->get_device(); + + gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_DEVICE_OPTIONS); - if (session->get_device_config_list(NULL, SR_CONF_DEVICE_OPTIONS, &gvar_opts) == false) + if (gvar_opts == NULL) /* Driver supports no device instance options. */ return; const int *const options = (const int32_t *)g_variant_get_fixed_array( gvar_opts, &num_opts, sizeof(int32_t)); + for (unsigned int i = 0; i < num_opts; i++) { const struct sr_config_info *const info = - sr_config_info_get(options[i]); + _device_agent->get_config_info(options[i]); if (!info) continue; const int key = info->key; - if(sr_config_list(_sdi->driver, _sdi, NULL, key, &gvar_list) != SR_OK) - gvar_list = NULL; + gvar_list = _device_agent->get_config_list(NULL, key); const QString name(info->name); char *label_char = info->label; - GVariant *gvar_tmp = NULL; - if (sr_config_get(_sdi->driver, _sdi, NULL, NULL, SR_CONF_LANGUAGE, &gvar_tmp) == SR_OK) { - if (gvar_tmp != NULL) { - int language = g_variant_get_int16(gvar_tmp); + GVariant *gvar_tmp = _device_agent->get_config(NULL, NULL, SR_CONF_LANGUAGE); + + if (gvar_tmp != NULL) { + int language = g_variant_get_int16(gvar_tmp); if (language == LAN_CN) label_char = info->label_cn; - g_variant_unref(gvar_tmp); - } + g_variant_unref(gvar_tmp); } const QString label(label_char); @@ -145,27 +149,24 @@ DeviceOptions::DeviceOptions() } GVariant* DeviceOptions::config_getter(int key) -{ - GVariant *data = NULL; - if (sr_config_get(sdi->driver, sdi, NULL, NULL, key, &data) != SR_OK) { - dsv_warn("%s%d", "WARNING: Failed to get value of config id:", key); - return NULL; - } - return data; +{ + SigSession *session = AppControl::Instance()->GetSession(); + DeviceAgent *_device_agent = session->get_device(); + return _device_agent->get_config(NULL, NULL, key); } void DeviceOptions::config_setter(int key, GVariant* value) { - if (sr_config_set(sdi, NULL, NULL, key, value) != SR_OK){ - dsv_warn("%s%d", "WARNING: Failed to set value of config id:", key); - } + SigSession *session = AppControl::Instance()->GetSession(); + DeviceAgent *_device_agent = session->get_device(); + _device_agent->set_config(NULL, NULL, key, value); } void DeviceOptions::bind_bool(const QString &name, const QString label, int key) { _properties.push_back( - new Bool(name, label, bind(config_getter, _sdi, key), - bind(config_setter, _sdi, key, _1))); + new Bool(name, label, bind(config_getter, key), + bind(config_setter, key, _1))); } void DeviceOptions::bind_enum(const QString &name, const QString label, int key, @@ -183,8 +184,8 @@ void DeviceOptions::bind_enum(const QString &name, const QString label, int key, _properties.push_back( new Enum(name, label, values, - bind(config_getter, _sdi, key), - bind(config_setter, _sdi, key, _1))); + bind(config_getter, key), + bind(config_setter, key, _1))); } void DeviceOptions::bind_int(const QString &name, const QString label, int key, QString suffix, @@ -192,8 +193,8 @@ void DeviceOptions::bind_int(const QString &name, const QString label, int key, { _properties.push_back( new Int(name, label, suffix, range, - bind(config_getter, _sdi, key), - bind(config_setter, _sdi, key, _1))); + bind(config_getter, key), + bind(config_setter, key, _1))); } void DeviceOptions::bind_double(const QString &name, const QString label, int key, QString suffix, @@ -202,16 +203,17 @@ void DeviceOptions::bind_double(const QString &name, const QString label, int ke { _properties.push_back( new Double(name, label, decimals, suffix, range, step, - bind(config_getter, _sdi, key), - bind(config_setter, _sdi, key, _1))); + bind(config_getter, key), + bind(config_setter, key, _1))); } QString DeviceOptions::print_gvariant(GVariant *const gvar) { QString s; - if (g_variant_is_of_type(gvar, G_VARIANT_TYPE("s"))) + if (g_variant_is_of_type(gvar, G_VARIANT_TYPE("s"))){ s = QString::fromUtf8(g_variant_get_string(gvar, NULL)); + } else { gchar *const text = g_variant_print(gvar, FALSE); @@ -243,8 +245,8 @@ void DeviceOptions::bind_samplerate(const QString &name, const QString label, new Double(name, label, 0, QObject::tr("Hz"), make_pair((double)elements[0], (double)elements[1]), (double)elements[2], - bind(samplerate_double_getter, _sdi), - bind(samplerate_double_setter, _sdi, _1))); + bind(samplerate_double_getter), + bind(samplerate_double_setter, _1))); g_variant_unref(gvar_list_samplerates); } @@ -268,7 +270,7 @@ QString DeviceOptions::print_samplerate(GVariant *const gvar) GVariant* DeviceOptions::samplerate_double_getter() { - GVariant *const gvar = config_getter(sdi, SR_CONF_SAMPLERATE); + GVariant *const gvar = config_getter(SR_CONF_SAMPLERATE); if(!gvar) return NULL; @@ -285,7 +287,7 @@ void DeviceOptions::samplerate_double_setter(GVariant *value) { GVariant *const gvar = g_variant_new_uint64( g_variant_get_double(value)); - config_setter(sdi, SR_CONF_SAMPLERATE, gvar); + config_setter(SR_CONF_SAMPLERATE, gvar); } QString DeviceOptions::print_timebase(GVariant *const gvar) @@ -312,12 +314,11 @@ void DeviceOptions::bind_bandwidths(const QString &name, const QString label, in assert(gvar_list); - GVariant *gvar_tmp = NULL; - if (sr_config_get(_sdi->driver, _sdi, NULL, NULL, SR_CONF_BANDWIDTH, &gvar_tmp) == SR_OK) { - if (gvar_tmp != NULL) { - bw_limit = g_variant_get_boolean(gvar_tmp); - g_variant_unref(gvar_tmp); - } + GVariant *gvar_tmp = _device_agent->get_config(NULL, NULL, SR_CONF_BANDWIDTH); + + if (gvar_tmp != NULL) { + bw_limit = g_variant_get_boolean(gvar_tmp); + g_variant_unref(gvar_tmp); } if (!bw_limit) @@ -329,8 +330,8 @@ void DeviceOptions::bind_bandwidths(const QString &name, const QString label, in _properties.push_back( new Enum(name, label, values, - bind(config_getter, _sdi, key), - bind(config_setter, _sdi, key, _1))); + bind(config_getter, key), + bind(config_setter, key, _1))); } } // binding diff --git a/DSView/pv/prop/binding/deviceoptions.h b/DSView/pv/prop/binding/deviceoptions.h index 1678ae70..cb5757f5 100644 --- a/DSView/pv/prop/binding/deviceoptions.h +++ b/DSView/pv/prop/binding/deviceoptions.h @@ -29,9 +29,12 @@ #include #include -#include "binding.h" +#include "binding.h" + +class DeviceAgent; namespace pv { + namespace prop { namespace binding { @@ -74,6 +77,9 @@ private: void bind_bandwidths(const QString &name, const QString label, int key,GVariant *const gvar_list, boost::function printer = print_gvariant); + +private: + DeviceAgent *_device_agent; }; diff --git a/DSView/pv/prop/binding/probeoptions.cpp b/DSView/pv/prop/binding/probeoptions.cpp index 9acf3959..da1a47e7 100644 --- a/DSView/pv/prop/binding/probeoptions.cpp +++ b/DSView/pv/prop/binding/probeoptions.cpp @@ -29,6 +29,8 @@ #include "../int.h" #include "../../config/appconfig.h" #include "../../log.h" +#include "../../appcontrol.h" +#include "../../sigsession.h" using namespace std; @@ -36,43 +38,45 @@ namespace pv { namespace prop { namespace binding { -ProbeOptions::ProbeOptions(ds_device_handle dev_handel, struct sr_channel *probe) : +ProbeOptions::ProbeOptions(struct sr_channel *probe) : Binding(), _probe(probe) -{ - _dev_handel = dev_handel; +{ GVariant *gvar_opts, *gvar_list; gsize num_opts; - if ((sr_config_list(sdi->driver, sdi, NULL, SR_CONF_PROBE_CONFIGS, - &gvar_opts) != SR_OK)) + SigSession *session = AppControl::Instance()->GetSession(); + _device_agent = session->get_device(); + + gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_PROBE_CONFIGS); + if (gvar_opts != NULL){ /* Driver supports no device instance options. */ return; + } const int *const options = (const int32_t *)g_variant_get_fixed_array( gvar_opts, &num_opts, sizeof(int32_t)); + for (unsigned int i = 0; i < num_opts; i++) { const struct sr_config_info *const info = - sr_config_info_get(options[i]); + _device_agent->get_config_info(options[i]); if (!info) continue; const int key = info->key; - if(sr_config_list(_sdi->driver, _sdi, NULL, key, &gvar_list) != SR_OK) - gvar_list = NULL; + gvar_list = _device_agent->get_config_list(NULL, key); const QString name(info->name); char *label_char = info->label; - GVariant *gvar_tmp = NULL; - if (sr_config_get(_sdi->driver, _sdi, NULL, NULL, SR_CONF_LANGUAGE, &gvar_tmp) == SR_OK) { - if (gvar_tmp != NULL) { + GVariant *gvar_tmp = _device_agent->get_config(NULL, NULL, SR_CONF_LANGUAGE); + + if (gvar_tmp != NULL) { int language = g_variant_get_int16(gvar_tmp); if (language == LAN_CN) label_char = info->label_cn; g_variant_unref(gvar_tmp); - } } const QString label(label_char); @@ -111,32 +115,25 @@ ProbeOptions::ProbeOptions(ds_device_handle dev_handel, struct sr_channel *probe g_variant_unref(gvar_opts); } -GVariant* ProbeOptions::config_getter( - const struct sr_dev_inst *sdi, - const struct sr_channel *probe, int key) -{ - GVariant *data = NULL; - if (sr_config_get(sdi->driver, sdi, probe, NULL, key, &data) != SR_OK) { - dsv_warn("%s%d", "WARNING: Failed to get value of config id:", key); - return NULL; - } - return data; +GVariant* ProbeOptions::config_getter(const struct sr_channel *probe, int key) +{ + SigSession *session = AppControl::Instance()->GetSession(); + DeviceAgent *_device_agent = session->get_device(); + return _device_agent->get_config(probe, NULL, key); } -void ProbeOptions::config_setter( - struct sr_dev_inst *sdi, - struct sr_channel *probe, int key, GVariant* value) +void ProbeOptions::config_setter(struct sr_channel *probe, int key, GVariant* value) { - if (sr_config_set(sdi, probe, NULL, key, value) != SR_OK){ - dsv_warn("%s", "WARNING: Failed to set value of sample rate"); - } + SigSession *session = AppControl::Instance()->GetSession(); + DeviceAgent *_device_agent = session->get_device(); + _device_agent->set_config(probe, NULL, key, value); } void ProbeOptions::bind_bool(const QString &name, const QString label, int key) { _properties.push_back( - new Bool(name, label, bind(config_getter, _sdi, _probe, key), - bind(config_setter, _sdi, _probe, key, _1))); + new Bool(name, label, bind(config_getter, _probe, key), + bind(config_setter, _probe, key, _1))); } void ProbeOptions::bind_enum(const QString &name, const QString label, int key, @@ -154,8 +151,8 @@ void ProbeOptions::bind_enum(const QString &name, const QString label, int key, _properties.push_back( new Enum(name, label, values, - bind(config_getter, _sdi, _probe, key), - bind(config_setter, _sdi, _probe, key, _1))); + bind(config_getter, _probe, key), + bind(config_setter, _probe, key, _1))); } void ProbeOptions::bind_int(const QString &name, const QString label, int key, QString suffix, @@ -163,8 +160,8 @@ void ProbeOptions::bind_int(const QString &name, const QString label, int key, Q { _properties.push_back( new Int(name, label, suffix, range, - bind(config_getter, _sdi, _probe, key), - bind(config_setter, _sdi, _probe, key, _1))); + bind(config_getter, _probe, key), + bind(config_setter, _probe, key, _1))); } void ProbeOptions::bind_double(const QString &name, const QString label, int key, QString suffix, @@ -173,8 +170,8 @@ void ProbeOptions::bind_double(const QString &name, const QString label, int key { _properties.push_back( new Double(name, label, decimals, suffix, range, step, - bind(config_getter, _sdi, _probe, key), - bind(config_setter, _sdi, _probe, key, _1))); + bind(config_getter, _probe, key), + bind(config_setter, _probe, key, _1))); } void ProbeOptions::bind_vdiv(const QString &name, const QString label, diff --git a/DSView/pv/prop/binding/probeoptions.h b/DSView/pv/prop/binding/probeoptions.h index 26696740..4ba29c2a 100644 --- a/DSView/pv/prop/binding/probeoptions.h +++ b/DSView/pv/prop/binding/probeoptions.h @@ -30,6 +30,8 @@ #include #include "binding.h" +class DeviceAgent; + namespace pv { namespace prop { namespace binding { @@ -37,16 +39,14 @@ namespace binding { class ProbeOptions : public Binding { public: - ProbeOptions(ds_device_handle dev_handel, - struct sr_channel *probe); + ProbeOptions(struct sr_channel *probe); private: static GVariant* config_getter( - const struct sr_dev_inst *sdi, const struct sr_channel *probe, int key); + static void config_setter( - struct sr_dev_inst *sdi, struct sr_channel *probe, int key, GVariant* value); void bind_bool(const QString &name, const QString label, int key); @@ -71,8 +71,8 @@ private: static QString print_coupling(GVariant *const gvar); protected: - ds_device_handle _dev_handel; struct sr_channel *const _probe; + DeviceAgent *_device_agent; }; } // binding diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index b30ee92f..cd4442fe 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -26,8 +26,6 @@ #include "sigsession.h" #include "mainwindow.h" -#include "device/device.h" -#include "device/file.h" #include "data/analog.h" #include "data/analogsnapshot.h" @@ -71,9 +69,7 @@ SigSession* SigSession::_session = NULL; SigSession::SigSession() { // TODO: This should not be necessary - _session = this; - _hot_attach = false; - _hot_detach = false; + _session = this; _group_cnt = 0; _bHotplugStop = false; @@ -90,21 +86,18 @@ SigSession::SigSession() _data_lock = false; _data_updated = false; _active_last_device_flag = false; + _bSaving = false; _decoder_model = new pv::data::DecoderModel(NULL); _lissajous_trace = NULL; _math_trace = NULL; - _saving = false; + _dso_feed = false; _stop_scale = 1; _bDecodeRunning = false; _bClose = false; - _callback = NULL; - _dev_inst = NULL; - _is_wait_reattch = false; - _wait_reattch_times = 0; - _is_device_reattach = false; + _callback = NULL; // Create snapshots & data containers _logic_data = new data::Logic(new data::LogicSnapshot()); @@ -164,7 +157,7 @@ double SigSession::cur_snap_sampletime() double SigSession::cur_view_time() { - return _dev_inst->get_time_base() * DS_CONF_DSO_HDIVS * 1.0 / SR_SEC(1); + return _device_agent.get_time_base() * DS_CONF_DSO_HDIVS * 1.0 / SR_SEC(1); } void SigSession::set_cur_snap_samplerate(uint64_t samplerate) @@ -192,7 +185,7 @@ void SigSession::set_cur_snap_samplerate(uint64_t samplerate) // Math if (_math_trace && _math_trace->enabled()) - _math_trace->get_math_stack()->set_samplerate(_dev_inst->get_sample_rate()); + _math_trace->get_math_stack()->set_samplerate(_device_agent.get_sample_rate()); // SpectrumStack for(auto & m : _spectrum_traces) m->get_spectrum_stack()->set_samplerate(_cur_snap_samplerate); @@ -212,11 +205,11 @@ void SigSession::capture_init() set_repeating(get_run_mode() == Repetitive); // update instant setting - _dev_inst->set_config(NULL, NULL, SR_CONF_INSTANT, g_variant_new_boolean(_instant)); + _device_agent.set_config(NULL, NULL, SR_CONF_INSTANT, g_variant_new_boolean(_instant)); _callback->update_capture(); - set_cur_snap_samplerate(_dev_inst->get_sample_rate()); - set_cur_samplelimits(_dev_inst->get_sample_limit()); + set_cur_snap_samplerate(_device_agent.get_sample_rate()); + set_cur_samplelimits(_device_agent.get_sample_limit()); set_stop_scale(1); _data_updated = false; _trigger_flag = false; @@ -314,7 +307,7 @@ void SigSession::start_capture(bool instant) } // update setting - if (_device_agent.isFile() == false) + if (_device_agent.is_file() == false) _instant = instant; else _instant = true; @@ -493,8 +486,11 @@ void SigSession::del_group() } void SigSession::init_signals() -{ - assert(_dev_inst); +{ + if (_device_agent.have_instance() == false){ + assert(false); + } + stop_capture(); std::vector sigs; @@ -541,7 +537,7 @@ void SigSession::init_signals() std::vector().swap(_group_traces); - for (GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) + for (GSList *l = _device_agent.get_channels(); l; l = l->next) { sr_channel *probe = (sr_channel *)l->data; @@ -552,16 +548,16 @@ void SigSession::init_signals() { case SR_CHANNEL_LOGIC: if (probe->enabled) - signal = new view::LogicSignal(_dev_inst, _logic_data, probe); + signal = new view::LogicSignal(_logic_data, probe); break; case SR_CHANNEL_DSO: - signal = new view::DsoSignal(_dev_inst, _dso_data, probe); + signal = new view::DsoSignal(_dso_data, probe); break; case SR_CHANNEL_ANALOG: if (probe->enabled) - signal = new view::AnalogSignal(_dev_inst, _analog_data, probe); + signal = new view::AnalogSignal(_analog_data, probe); break; } if (signal != NULL) @@ -579,7 +575,9 @@ void SigSession::init_signals() void SigSession::reload() { - assert(_dev_inst); + if (_device_agent.have_instance() == false){ + assert(false); + } if (_capture_state == Running) stop_capture(); @@ -588,7 +586,7 @@ void SigSession::reload() view::Signal *signal = NULL; // Make the logic probe list - for (GSList *l = _dev_inst->dev_inst()->channels; l; l = l->next) + for (GSList *l = _device_agent.get_channels(); l; l = l->next) { sr_channel *probe = (sr_channel *)l->data; @@ -614,7 +612,7 @@ void SigSession::reload() } if (signal == NULL) { - signal = new view::LogicSignal(_dev_inst, _logic_data, probe); + signal = new view::LogicSignal(_logic_data, probe); } } break; @@ -636,7 +634,7 @@ void SigSession::reload() } if (signal == NULL) { - signal = new view::AnalogSignal(_dev_inst, _analog_data, probe); + signal = new view::AnalogSignal(_analog_data, probe); } } break; @@ -750,7 +748,7 @@ void SigSession::feed_in_meta(const sr_dev_inst *sdi, void SigSession::feed_in_trigger(const ds_trigger_pos &trigger_pos) { _hw_replied = true; - if (_dev_inst->dev_inst()->mode != DSO) { + if (_device_agent.get_work_mode() != DSO) { _trigger_flag = (trigger_pos.status & 0x01); if (_trigger_flag) { _trigger_pos = trigger_pos.real_pos; @@ -759,8 +757,7 @@ void SigSession::feed_in_trigger(const ds_trigger_pos &trigger_pos) } else { int probe_count = 0; int probe_en_count = 0; - for (const GSList *l = _dev_inst->dev_inst()->channels; - l; l = l->next) { + for (const GSList *l = _device_agent.get_channels(); l; l = l->next) { const sr_channel *const probe = (const sr_channel *)l->data; if (probe->type == SR_CHANNEL_DSO) { probe_count++; @@ -787,7 +784,7 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) } if (_logic_data->snapshot()->last_ended()) { - _logic_data->snapshot()->first_payload(logic, _dev_inst->get_sample_limit(), _dev_inst->dev_inst()->channels); + _logic_data->snapshot()->first_payload(logic, _device_agent.get_sample_limit(), _device_agent.get_channels()); // @todo Putting this here means that only listeners querying // for logic will be notified. Currently the only user of // frame_began is DecoderStack, but in future we need to signal @@ -834,7 +831,7 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso) } // first payload - _dso_data->snapshot()->first_payload(dso, _dev_inst->get_sample_limit(), sig_enable, _instant); + _dso_data->snapshot()->first_payload(dso, _device_agent.get_sample_limit(), sig_enable, _instant); } else { // Append to the existing data snapshot _dso_data->snapshot()->append_payload(dso); @@ -848,7 +845,7 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso) if (dso.num_samples != 0) { // update current sample rate - set_cur_snap_samplerate(_dev_inst->get_sample_rate()); + set_cur_snap_samplerate(_device_agent.get_sample_rate()); } @@ -868,7 +865,7 @@ void SigSession::feed_in_dso(const sr_datafeed_dso &dso) // calculate related math results if (_math_trace && _math_trace->enabled()) { - _math_trace->get_math_stack()->realloc(_dev_inst->get_sample_limit()); + _math_trace->get_math_stack()->realloc(_device_agent.get_sample_limit()); _math_trace->get_math_stack()->calc_math(); } @@ -904,7 +901,7 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) } // first payload - _analog_data->snapshot()->first_payload(analog, _dev_inst->get_sample_limit(), _dev_inst->dev_inst()->channels); + _analog_data->snapshot()->first_payload(analog, _device_agent.get_sample_limit(), _device_agent.get_channels()); } else { // Append to the existing data snapshot _analog_data->snapshot()->append_payload(analog); @@ -1006,7 +1003,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, _callback->frame_ended(); - if (get_device()->dev_inst()->mode != LOGIC){ + if (_device_agent.get_work_mode() != LOGIC){ set_session_time(QDateTime::currentDateTime()); } @@ -1029,7 +1026,7 @@ uint16_t SigSession::get_ch_num(int type) uint16_t dso_ch_num = 0; uint16_t analog_ch_num = 0; - if (_dev_inst->dev_inst()) { + if (_device_agent.have_instance()) { for(auto &s : _signals) { assert(s); @@ -1273,7 +1270,7 @@ void SigSession::math_rebuild(bool enable,view::DsoSignal *dsoSig1, if (_math_trace && _math_trace->enabled()) { _math_trace->get_math_stack()->set_samplerate(_dso_data->samplerate()); - _math_trace->get_math_stack()->realloc(_dev_inst->get_sample_limit()); + _math_trace->get_math_stack()->realloc(_device_agent.get_sample_limit()); _math_trace->get_math_stack()->calc_math(); } signals_changed(); @@ -1317,7 +1314,7 @@ uint8_t SigSession::trigd_ch() void SigSession::nodata_timeout() { - GVariant *gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_TRIGGER_SOURCE); + GVariant *gvar = _device_agent.get_config(NULL, NULL, SR_CONF_TRIGGER_SOURCE); if (gvar == NULL) return; if (g_variant_get_byte(gvar) != DSO_TRIGGER_AUTO) { @@ -1407,7 +1404,7 @@ bool SigSession::repeat_check() return false; } - if (_dev_inst->dev_inst()->mode == LOGIC) { + if (_device_agent.get_work_mode() == LOGIC) { _repeat_hold_prg = 100; _callback->repeat_hold(_repeat_hold_prg); _out_timer.TimeOut(_repeat_intvl * 1000 / RepeatHoldDiv, std::bind(&SigSession::repeat_update, this)); @@ -1478,22 +1475,12 @@ uint64_t SigSession::get_save_end() return _save_end; } -bool SigSession::get_saving() -{ - return _saving; -} - -void SigSession::set_saving(bool saving) -{ - _saving = saving; -} - void SigSession::exit_capture() { set_repeating(false); bool wait_upload = false; if (get_run_mode() != SigSession::Repetitive) { - GVariant *gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD); + GVariant *gvar = _device_agent.get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD); if (gvar != NULL) { wait_upload = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -1531,11 +1518,6 @@ void SigSession::set_stop_scale(float scale) clear_all_decoder(); //clear all decode task, and stop decode thread - if (_dev_inst) - { - _dev_inst->release(); - } - // TODO: This should not be necessary _session = NULL; } @@ -1681,7 +1663,7 @@ void SigSession::set_stop_scale(float scale) Snapshot* SigSession::get_signal_snapshot() { - int mode = ds_get_actived_device_mode(); + int mode = _device_agent.get_work_mode(); if (mode == ANALOG) return _analog_data->snapshot(); else if (mode == DSO) @@ -1731,7 +1713,8 @@ void SigSession::on_device_lib_event(int event) { // Try to save current device data, and auto select the lastest device later. _active_last_device_flag = true; - store_session_data(); + if (!_bSaving) + store_session_data(); return; } } @@ -1743,7 +1726,10 @@ void SigSession::on_device_lib_event(int event) if (event == DS_EV_NEW_DEVICE_ATTACH || event == DS_EV_CURRENT_DEVICE_DETACH) { - set_default_device(); + if (_bSaving) + _active_last_device_flag = true; //Auto switch device after save data. + else + set_default_device(); } else if (_callback != NULL) { @@ -1763,7 +1749,7 @@ bool SigSession::set_default_device() } if (count < 1 || array == NULL) { - dsv_err("%s", "Device list is empty!"); + dsv_err("%s", "SigSession::set_default_device, Device list is empty!"); return false; } @@ -1783,7 +1769,9 @@ bool SigSession::set_default_device() } bool SigSession::set_device(ds_device_handle dev_handle) -{ +{ + assert(!_bSaving); + if (ds_active_device(dev_handle) != SR_OK){ dsv_err("%s", "Switch device error!"); return false; @@ -1793,7 +1781,7 @@ bool SigSession::set_device(ds_device_handle dev_handle) RELEASE_ARRAY(_group_traces); clear_all_decoder(); - if (_device_agent.isFile()) + if (_device_agent.is_file()) dsv_info("%s\"%s\"", "Switch to file: ", _device_agent.name().toUtf8().data()); else dsv_info("%s\"%s\"", "Switch to device: ", _device_agent.name().toUtf8().data()); @@ -1809,7 +1797,6 @@ bool SigSession::set_device(ds_device_handle dev_handle) _callback->device_setted(); } - bool SigSession::set_file(QString name) { dsv_info("Load file:\"%s\"", name.toUtf8().data()); @@ -1880,7 +1867,7 @@ bool SigSession::init() bool SigSession::have_hardware_data() { - if (_device_agent.have_instance() && _device_agent.isHardware()){ + if (_device_agent.have_instance() && _device_agent.is_hardware()){ Snapshot *data = get_signal_snapshot(); return data->have_data(); } @@ -1892,16 +1879,18 @@ bool SigSession::init() } - bool SigSession::get_device_list(struct ds_device_info **out_list, int &out_count, int &actived_index) + struct ds_device_info* SigSession::get_device_list(int &out_count, int &actived_index) { out_count = 0; actived_index = -1; + struct ds_device_info *array = NULL; - if (ds_get_device_list(out_list, &out_count) == SR_OK){ + if (ds_get_device_list(&array, &out_count) == SR_OK) + { actived_index = ds_get_actived_device_index(); - return true; + return array; } - return false; + return NULL; } diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index 54c25869..6cfea1c3 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -37,7 +37,7 @@ #include "interface/icallbacks.h" #include "dstimer.h" #include -#include +#include "deviceagent.h" struct srd_decoder; @@ -48,8 +48,6 @@ typedef std::lock_guard ds_lock_guard; namespace pv { -class DeviceManager; - namespace data { class SignalData; class Snapshot; @@ -135,10 +133,6 @@ public: bool set_device(ds_device_handle dev_handle); bool set_file(QString name); void close_file(ds_device_handle dev_handle); - - /** - * Set the last one device. - */ bool set_default_device(); capture_state get_capture_state(); @@ -221,9 +215,7 @@ public: void set_save_end(uint64_t end); uint64_t get_save_start(); uint64_t get_save_end(); - bool get_saving(); - - void set_saving(bool saving); + void set_stop_scale(float scale); float stop_scale(); @@ -258,10 +250,18 @@ public: _callback->show_region(start, end, keep); } - inline void decode_done(){ + inline void decode_done(){ _callback->decode_done(); } + inline bool is_saving(){ + return _bSaving; + } + + inline void set_saving(bool flag){ + _bSaving = flag; + } + bool init(); void uninit(); @@ -274,13 +274,10 @@ public: void set_repeating(bool repeat); void set_map_zoom(int index); void auto_end(); - - inline bool is_device_re_attach(){ - return _is_device_reattach; - } void store_session_data(); bool have_hardware_data(); + struct ds_device_info* get_device_list(int &out_count, int &actived_index); private: inline void data_updated(){ @@ -295,7 +292,6 @@ private: _callback->receive_data_len(len); } - void set_capture_state(capture_state state); void add_decode_task(view::DecodeTrace *trace); @@ -346,15 +342,12 @@ private: void update_collect_status_view(); void init_device_view(); void update_graph_view(); - - bool get_device_list(struct ds_device_info **out_list, int &out_count, int &actived_index); private: /** * The device instance that will be used in the next capture session. - */ - DevInst *_dev_inst; + */ mutable std::mutex _sampling_mutex; mutable std::mutex _data_mutex; mutable std::mutex _decode_task_mutex; @@ -385,10 +378,7 @@ private: data::Analog *_analog_data; data::Group *_group_data; int _group_cnt; - - bool _hot_attach; - bool _hot_detach; - + DsTimer _feed_timer; DsTimer _out_timer; int _noData_cnt; @@ -406,29 +396,23 @@ private: uint64_t _error_pattern; run_mode _run_mode; - double _repeat_intvl; + double _repeat_intvl; bool _repeating; int _repeat_hold_prg; - int _map_zoom; - - uint64_t _save_start; - uint64_t _save_end; - bool _saving; - + bool _dso_feed; float _stop_scale; - bool _bClose; - struct sr_context *_sr_ctx; - volatile bool _is_wait_reattch; - volatile int _wait_reattch_times; - bool _is_device_reattach; - QString _last_device_name; - bool _active_last_device_flag; + bool _bClose; + bool _active_last_device_flag; + + bool _bSaving; + uint64_t _save_start; + uint64_t _save_end; ISessionCallback *_callback; - DeviceAgent _device_agent; + DeviceAgent _device_agent; private: // TODO: This should not be necessary. Multiple concurrent diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 59e3e830..e4a152e5 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -113,7 +113,7 @@ QList StoreSession::getSuportedExportFormats(){ while(*supportedModules){ if(*supportedModules == NULL) break; - if (_session->get_device()->dev_inst()->mode != LOGIC && + if (_session->get_device()->get_work_mode() != LOGIC && strcmp((*supportedModules)->id, "csv")) break; QString format((*supportedModules)->desc); @@ -353,7 +353,8 @@ bool StoreSession::meta_gen(data::Snapshot *snapshot, std::string &str) struct sr_status status; const sr_dev_inst *sdi = NULL; char meta[300] = {0}; - + + /* sdi = _session->get_device()->dev_inst(); sprintf(meta, "%s", "[version]\n"); str += meta; @@ -364,8 +365,7 @@ bool StoreSession::meta_gen(data::Snapshot *snapshot, std::string &str) sprintf(meta, "driver = %s\n", sdi->driver->name); str += meta; sprintf(meta, "device mode = %d\n", sdi->mode); str += meta; } - - /* metadata */ + sprintf(meta, "capturefile = data\n"); str += meta; sprintf(meta, "total samples = %" PRIu64 "\n", snapshot->get_sample_count()); str += meta; @@ -572,6 +572,7 @@ bool StoreSession::meta_gen(data::Snapshot *snapshot, std::string &str) } probecnt++; } + */ return true; } @@ -669,7 +670,7 @@ void StoreSession::export_proc(data::Snapshot *snapshot) struct sr_output output; output.module = (sr_output_module*) _outModule; - output.sdi = _session->get_device()->dev_inst(); + output.sdi = _session->get_device()->inst(); output.param = NULL; if(_outModule->init) _outModule->init(&output, params); @@ -686,12 +687,14 @@ void StoreSession::export_proc(data::Snapshot *snapshot) struct sr_datafeed_meta meta; struct sr_config *src; - src = sr_config_new(SR_CONF_SAMPLERATE, - g_variant_new_uint64(_session->cur_snap_samplerate())); + src = _session->get_device()->new_config(SR_CONF_SAMPLERATE, + g_variant_new_uint64(_session->cur_snap_samplerate())); + meta.config = g_slist_append(NULL, src); - src = sr_config_new(SR_CONF_LIMIT_SAMPLES, - g_variant_new_uint64(snapshot->get_sample_count())); + src = _session->get_device()->new_config(SR_CONF_LIMIT_SAMPLES, + g_variant_new_uint64(snapshot->get_sample_count())); + meta.config = g_slist_append(meta.config, src); GVariant *gvar; @@ -702,19 +705,24 @@ void StoreSession::export_proc(data::Snapshot *snapshot) g_variant_unref(gvar); } gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); + if (gvar != NULL) { - src = sr_config_new(SR_CONF_REF_MIN, gvar); + src = _session->get_device()->new_config(SR_CONF_REF_MIN, gvar); g_variant_unref(gvar); - } else { - src = sr_config_new(SR_CONF_REF_MIN, g_variant_new_uint32(1)); + } + else { + src = _session->get_device()->new_config(SR_CONF_REF_MIN, g_variant_new_uint32(1)); } + meta.config = g_slist_append(meta.config, src); gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); + if (gvar != NULL) { - src = sr_config_new(SR_CONF_REF_MAX, gvar); + src = _session->get_device()->new_config(SR_CONF_REF_MAX, gvar); g_variant_unref(gvar); - } else { - src = sr_config_new(SR_CONF_REF_MAX, g_variant_new_uint32((1 << bits) - 1)); + } + else { + src = _session->get_device()->new_config(SR_CONF_REF_MAX, g_variant_new_uint32((1 << bits) - 1)); } meta.config = g_slist_append(meta.config, src); @@ -729,7 +737,7 @@ void StoreSession::export_proc(data::Snapshot *snapshot) } for (GSList *l = meta.config; l; l = l->next) { src = (struct sr_config *)l->data; - sr_config_free(src); + _session->get_device()->free_config(src); } g_slist_free(meta.config); @@ -965,7 +973,7 @@ bool StoreSession::json_decoders(QJsonArray &array) bool StoreSession::load_decoders(dock::ProtocolDock *widget, QJsonArray dec_array) { - if (_session->get_device()->dev_inst()->mode != LOGIC) + if (_session->get_device()->get_work_mode() != LOGIC) { dsv_info("%s", "StoreSession::load_decoders(), is not LOGIC mode."); return false; @@ -1203,10 +1211,10 @@ QString StoreSession::MakeSaveFile(bool bDlg) default_name = _root + "/" + _session->get_device()->name() + "-"; } - for (const GSList *l = _session->get_device()->get_dev_mode_list(); - l; l = l->next) { + for (const GSList *l = _session->get_device()->get_device_mode_list(); l; l = l->next) + { const sr_dev_mode *mode = (const sr_dev_mode *)l->data; - if (_session->get_device()->dev_inst()->mode == mode->mode) { + if (_session->get_device()->get_work_mode() == mode->mode) { default_name += mode->acronym; break; } @@ -1261,10 +1269,9 @@ QString StoreSession::MakeExportFile(bool bDlg) default_name = _root + "/" + _session->get_device()->name() + "-"; } - for (const GSList *l = _session->get_device()->get_dev_mode_list(); - l; l = l->next) { + for (const GSList *l = _session->get_device()->get_device_mode_list(); l; l = l->next) { const sr_dev_mode *mode = (const sr_dev_mode *)l->data; - if (_session->get_device()->dev_inst()->mode == mode->mode) { + if (_session->get_device()->get_work_mode() == mode->mode) { default_name += mode->acronym; break; } diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index 0803a251..112b2716 100644 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -200,7 +200,7 @@ void FileBar::on_actionDefault_triggered() } QString driver_name = _session->get_device()->name(); - QString mode_name = QString::number(_session->get_device()->dev_inst()->mode); + QString mode_name = QString::number(_session->get_device()->get_work_mode()); int language = LAN_EN; GVariant *gvar_tmp = _session->get_device()->get_config(NULL, NULL, SR_CONF_LANGUAGE); if (gvar_tmp != NULL) { diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 88e417dc..0d008702 100644 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -26,7 +26,6 @@ #include #include #include -#include "../devicemanager.h" #include "../device/devinst.h" #include "../dialogs/deviceoptions.h" #include "../dialogs/waitingdialog.h" @@ -35,7 +34,8 @@ #include "../dialogs/interval.h" #include "../config/appconfig.h" #include "../dsvdef.h" -#include "../log.h" +#include "../log.h" +#include "../deviceagent.h" using std::map; using std::max; @@ -52,22 +52,24 @@ const QString SamplingBar::DIVString = tr(" / div"); SamplingBar::SamplingBar(SigSession *session, QWidget *parent) : QToolBar("Sampling Bar", parent), - _session(session), - _enable(true), - _sampling(false), _device_type(this), _device_selector(this), _configure_button(this), _sample_count(this), - _sample_rate(this), - _updating_sample_rate(false), - _updating_sample_count(false), + _sample_rate(this), _run_stop_button(this), _instant_button(this), - _mode_button(this), - _instant(false) + _mode_button(this) { - _is_seting_list = false; + _updating_device_list = false; + _updating_sample_rate = false; + _updating_sample_count = false; + _sampling = false; + _enable = true; + _instant = false; + + _session = session; + _device_agent = _session->get_device(); setMovable(false); setContentsMargins(0,0,0,0); @@ -135,19 +137,17 @@ void SamplingBar::changeEvent(QEvent *event) } void SamplingBar::retranslateUi() -{ - struct ds_device_info inf; - bool haveDev = _session->get_device_info(inf); +{ + bool bDev = _device_agent->have_instance(); - if (haveDev) { - if (inf.dev_type == DEV_TYPE_DEMO) + if (bDev) { + if (_device_agent->is_demo()) _device_type.setText(tr("Demo")); - else if (inf.dev_type == DEV_TYPE_FILELOG) + else if (_device_agent->is_file()) _device_type.setText(tr("File")); else { int usb_speed = LIBUSB_SPEED_HIGH; - GVariant *gvar = NULL; - _session->get_device_config(NULL, NULL, SR_CONF_USB_SPEED, &gvar); + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_USB_SPEED); if (gvar != NULL) { usb_speed = g_variant_get_int32(gvar); @@ -164,17 +164,17 @@ void SamplingBar::retranslateUi() _configure_button.setText(tr("Options")); _mode_button.setText(tr("Mode")); - int mode = _session->get_device_work_mode(); + int mode = _device_agent->get_work_mode(); if (_instant) { - if (haveDev && mode == DSO) + if (bDev && mode == DSO) _instant_button.setText(_sampling ? tr("Stop") : tr("Single")); else _instant_button.setText(_sampling ? tr("Stop") : tr("Instant")); _run_stop_button.setText(tr("Start")); } else { _run_stop_button.setText(_sampling ? tr("Stop") : tr("Start")); - if (haveDev && mode == DSO) + if (bDev && mode == DSO) _instant_button.setText(tr("Single")); else _instant_button.setText(tr("Instant")); @@ -186,18 +186,16 @@ void SamplingBar::retranslateUi() void SamplingBar::reStyle() { - struct ds_device_info inf; - bool haveDev = _session->get_device_info(inf); + bool bDev = _device_agent->have_instance(); - if (haveDev){ - if (inf.dev_type == DEV_TYPE_DEMO) + if (bDev){ + if (_device_agent->is_demo()) _device_type.setIcon(QIcon(":/icons/demo.svg")); - else if (inf.dev_type == DEV_TYPE_FILELOG) + else if (_device_agent->is_file()) _device_type.setIcon(QIcon(":/icons/data.svg")); else { int usb_speed = LIBUSB_SPEED_HIGH; - GVariant *gvar = NULL; - _session->get_device_config(NULL, NULL, SR_CONF_USB_SPEED, &gvar); + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_USB_SPEED); if (gvar != NULL) { usb_speed = g_variant_get_int32(gvar); @@ -226,22 +224,27 @@ void SamplingBar::reStyle() void SamplingBar::on_configure() { + if (_device_agent->have_instance() == false){ + dsv_info("%s", "Have no device, can't to set device config."); + return; + } sig_hide_calibration(); - int ret; - struct ds_device_info inf; - bool haveDev = _session->get_device_info(inf); + int ret; - pv::dialogs::DeviceOptions dlg(this, dev_inst); + pv::dialogs::DeviceOptions dlg(this); ret = dlg.exec(); - if (ret == QDialog::Accepted) { + if (ret == QDialog::Accepted) + { sig_device_updated(); update_sample_rate_selector(); + int mode = _device_agent->get_work_mode(); GVariant* gvar; - if (dev_inst->dev_inst()->mode == DSO) { - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO); + + if (mode == DSO) { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); if (gvar != NULL) { bool zero = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -251,7 +254,7 @@ void SamplingBar::on_configure() } } - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_CALI); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_CALI); if (gvar != NULL) { bool cali = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -261,7 +264,7 @@ void SamplingBar::on_configure() } } } - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); if (gvar != NULL) { bool test = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -271,7 +274,7 @@ void SamplingBar::on_configure() _sample_rate.setDisabled(true); } else { _sample_count.setDisabled(false); - if (dev_inst->dev_inst()->mode != DSO) + if (mode != DSO) _sample_rate.setDisabled(false); } } @@ -382,14 +385,15 @@ void SamplingBar::update_sample_rate_selector() disconnect(&_sample_rate, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplerate_sel(int))); - DevInst *dev_inst = get_selected_device(); - if (!dev_inst) - return; - assert(!_updating_sample_rate); + if (_device_agent->have_instance() == false){ + return; + } + _updating_sample_rate = true; - if (!(gvar_dict = dev_inst->list_config(NULL, SR_CONF_SAMPLERATE))) + gvar_dict = _device_agent->get_config_list(NULL, SR_CONF_SAMPLERATE); + if (gvar_dict != NULL) { _sample_rate.clear(); _sample_rate.show(); @@ -434,13 +438,14 @@ void SamplingBar::update_sample_rate_selector_value() if (_updating_sample_rate) return; - const uint64_t samplerate = get_selected_device()->get_sample_rate(); + const uint64_t samplerate = _device_agent->get_sample_rate(); assert(!_updating_sample_rate); _updating_sample_rate = true; - if (samplerate != _sample_rate.itemData( - _sample_rate.currentIndex()).value()) { + uint64_t cur_value = _sample_rate.itemData(_sample_rate.currentIndex()).value(); + + if (samplerate != cur_value) { for (int i = _sample_rate.count() - 1; i >= 0; i--) { if (samplerate >= _sample_rate.itemData( i).value()) { @@ -455,9 +460,8 @@ void SamplingBar::update_sample_rate_selector_value() void SamplingBar::on_samplerate_sel(int index) { - (void)index; - DevInst *dev_inst = get_selected_device(); - if (dev_inst->dev_inst()->mode != DSO) + (void)index; + if (_device_agent->get_work_mode() != DSO) update_sample_count_selector(); } @@ -481,20 +485,22 @@ void SamplingBar::update_sample_count_selector() assert(!_updating_sample_count); _updating_sample_count = true; - - DevInst *dev_inst = get_selected_device(); - GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_STREAM); + + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_STREAM); if (gvar != NULL) { stream_mode = g_variant_get_boolean(gvar); g_variant_unref(gvar); } - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_HW_DEPTH); + + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_HW_DEPTH); if (gvar != NULL) { hw_depth = g_variant_get_uint64(gvar); g_variant_unref(gvar); } - if (dev_inst->dev_inst()->mode == LOGIC) { + int mode = _device_agent->get_work_mode(); + + if (mode == LOGIC) { #if defined(__x86_64__) || defined(_M_X64) sw_depth = LogicMaxSWDepth64; #elif defined(__i386) || defined(_M_IX86) @@ -504,25 +510,27 @@ void SamplingBar::update_sample_count_selector() else sw_depth = LogicMaxSWDepth32 / ch_num; #endif - } else { + } + else { sw_depth = AnalogMaxSWDepth; } - if (dev_inst->dev_inst()->mode == LOGIC) { - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_RLE_SUPPORT); + if (mode == LOGIC) { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_RLE_SUPPORT); if (gvar != NULL) { rle_support = g_variant_get_boolean(gvar); g_variant_unref(gvar); } if (rle_support) rle_depth = min(hw_depth*SR_KB(1), sw_depth); - } else if (dev_inst->dev_inst()->mode == DSO) { - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_MAX_TIMEBASE); + } + else if (mode == DSO) { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MAX_TIMEBASE); if (gvar != NULL) { max_timebase = g_variant_get_uint64(gvar); g_variant_unref(gvar); } - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_MIN_TIMEBASE); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MIN_TIMEBASE); if (gvar != NULL) { min_timebase = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -536,7 +544,8 @@ void SamplingBar::update_sample_count_selector() const uint64_t samplerate = _sample_rate.itemData( _sample_rate.currentIndex()).value(); const double hw_duration = hw_depth / (samplerate * (1.0 / SR_SEC(1))); - if (dev_inst->dev_inst()->mode == DSO) + + if (mode == DSO) duration = max_timebase; else if (stream_mode) duration = sw_depth / (samplerate * (1.0 / SR_SEC(1))); @@ -547,12 +556,12 @@ void SamplingBar::update_sample_count_selector() assert(duration > 0); bool not_last = true; + do { - QString suffix = (dev_inst->dev_inst()->mode == DSO) ? DIVString : + QString suffix = (mode == DSO) ? DIVString : (!stream_mode && duration > hw_duration) ? RLEString : ""; char *const s = sr_time_string(duration); - _sample_count.addItem(QString(s) + suffix, - QVariant::fromValue(duration)); + _sample_count.addItem(QString(s) + suffix, QVariant::fromValue(duration)); g_free(s); double unit; @@ -564,8 +573,9 @@ void SamplingBar::update_sample_count_selector() unit = SR_MIN(1); else unit = 1; - const double log10_duration = pow(10, - floor(log10(duration / unit))); + + const double log10_duration = pow(10, floor(log10(duration / unit))); + if (duration > 5 * log10_duration * unit) duration = 5 * log10_duration * unit; else if (duration > 2 * log10_duration * unit) @@ -578,34 +588,38 @@ void SamplingBar::update_sample_count_selector() unit == SR_HOUR(1) ? SR_MIN(50) : unit == SR_MIN(1) ? SR_SEC(50) : duration * 0.5); - if (dev_inst->dev_inst()->mode == DSO) + if (mode == DSO) not_last = duration >= min_timebase; - else if (dev_inst->dev_inst()->mode == ANALOG) + else if (mode == ANALOG) not_last = (duration >= SR_MS(100)) && (duration / SR_SEC(1) * samplerate >= SR_KB(1)); else not_last = (duration / SR_SEC(1) * samplerate >= SR_KB(1)); + } while(not_last); _updating_sample_count = true; - if (pre_duration > _sample_count.itemData(0).value()) + + if (pre_duration > _sample_count.itemData(0).value()){ _sample_count.setCurrentIndex(0); - else if (pre_duration < _sample_count.itemData(_sample_count.count()-1).value()) + } + else if (pre_duration < _sample_count.itemData(_sample_count.count()-1).value()){ _sample_count.setCurrentIndex(_sample_count.count()-1); + } else { - for (int i = 0; i < _sample_count.count(); i++) - if (pre_duration >= _sample_count.itemData( - i).value()) { + for (int i = 0; i < _sample_count.count(); i++){ + if (pre_duration >= _sample_count.itemData(i).value()) { _sample_count.setCurrentIndex(i); break; } + } } _updating_sample_count = false; update_sample_count_selector_value(); on_samplecount_sel(_sample_count.currentIndex()); - connect(&_sample_count, SIGNAL(currentIndexChanged(int)), - this, SLOT(on_samplecount_sel(int))); + + connect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); } void SamplingBar::update_sample_count_selector_value() @@ -615,9 +629,9 @@ void SamplingBar::update_sample_count_selector_value() GVariant* gvar; double duration; - DevInst *dev_inst = get_selected_device(); - if (dev_inst->dev_inst()->mode == DSO) { - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TIMEBASE); + + if (_device_agent->get_work_mode() == DSO) { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TIMEBASE); if (gvar != NULL) { duration = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -626,8 +640,9 @@ void SamplingBar::update_sample_count_selector_value() dsv_err("%s", "ERROR: config_get SR_CONF_TIMEBASE failed."); return; } - } else { - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES); + } + else { + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES); if (gvar != NULL) { duration = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -636,14 +651,14 @@ void SamplingBar::update_sample_count_selector_value() dsv_err("%s", "ERROR: config_get SR_CONF_TIMEBASE failed."); return; } - const uint64_t samplerate = dev_inst->get_sample_rate(); + const uint64_t samplerate = _device_agent->get_sample_rate(); duration = duration / samplerate * SR_SEC(1); } assert(!_updating_sample_count); _updating_sample_count = true; - if (duration != _sample_count.itemData( - _sample_count.currentIndex()).value()) { + if (duration != _sample_count.itemData(_sample_count.currentIndex()).value()) + { for (int i = 0; i < _sample_count.count(); i++) { if (duration >= _sample_count.itemData( i).value()) { @@ -659,9 +674,8 @@ void SamplingBar::update_sample_count_selector_value() void SamplingBar::on_samplecount_sel(int index) { (void)index; - - DevInst *dev_inst = get_selected_device(); - if (dev_inst->dev_inst()->mode == DSO) + + if (_device_agent->get_work_mode() == DSO) commit_hori_res(); sig_duration_changed(); } @@ -675,15 +689,16 @@ double SamplingBar::hori_knob(int dir) { double hori_res = -1; - disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)), - this, SLOT(on_samplecount_sel(int))); + disconnect(&_sample_count, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplecount_sel(int))); if (0 == dir) { hori_res = commit_hori_res(); - } else if ((dir > 0) && (_sample_count.currentIndex() > 0)) { + } + else if ((dir > 0) && (_sample_count.currentIndex() > 0)) { _sample_count.setCurrentIndex(_sample_count.currentIndex() - 1); hori_res = commit_hori_res(); - } else if ((dir < 0) && (_sample_count.currentIndex() < _sample_count.count() - 1)) { + } + else if ((dir < 0) && (_sample_count.currentIndex() < _sample_count.count() - 1)) { _sample_count.setCurrentIndex(_sample_count.currentIndex() + 1); hori_res = commit_hori_res(); } @@ -698,12 +713,11 @@ double SamplingBar::commit_hori_res() { const double hori_res = _sample_count.itemData( _sample_count.currentIndex()).value(); - - DevInst *dev_inst = get_selected_device(); - const uint64_t sample_limit = dev_inst->get_sample_limit(); + + const uint64_t sample_limit = _device_agent->get_sample_limit(); GVariant* gvar; uint64_t max_sample_rate; - gvar = dev_inst->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLERATE); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLERATE); if (gvar != NULL) { max_sample_rate = g_variant_get_uint64(gvar); @@ -720,7 +734,7 @@ double SamplingBar::commit_hori_res() (_session->get_ch_num(SR_CHANNEL_DSO) ? _session->get_ch_num(SR_CHANNEL_DSO) : 1))); set_sample_rate(sample_rate); - dev_inst->set_config(NULL, NULL, SR_CONF_TIMEBASE, + _device_agent->set_config(NULL, NULL, SR_CONF_TIMEBASE, g_variant_new_uint64(hori_res)); return hori_res; @@ -728,10 +742,10 @@ double SamplingBar::commit_hori_res() void SamplingBar::commit_settings() { - bool test = false; - DevInst *dev_inst = get_selected_device(); - if (dev_inst && dev_inst->owner()) { - GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST); + bool test = false; + + if (_device_agent->have_instance()) { + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); if (gvar != NULL) { test = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -741,28 +755,31 @@ void SamplingBar::commit_settings() if (test) { update_sample_rate_selector_value(); update_sample_count_selector_value(); - } else { + } + else { const double sample_duration = _sample_count.itemData( _sample_count.currentIndex()).value(); const uint64_t sample_rate = _sample_rate.itemData( _sample_rate.currentIndex()).value(); - DevInst *dev_inst = get_selected_device(); - if (dev_inst) { - if (sample_rate != dev_inst->get_sample_rate()) - dev_inst->set_config(NULL, NULL, + + if (_device_agent->have_instance()) + { + if (sample_rate != _device_agent->get_sample_rate()) + _device_agent->set_config(NULL, NULL, SR_CONF_SAMPLERATE, g_variant_new_uint64(sample_rate)); - if (dev_inst->dev_inst()->mode != DSO) { + + if (_device_agent->get_work_mode() != DSO) { const uint64_t sample_count = ((uint64_t)ceil(sample_duration / SR_SEC(1) * sample_rate) + SAMPLES_ALIGN) & ~SAMPLES_ALIGN; - if (sample_count != dev_inst->get_sample_limit()) - dev_inst->set_config(NULL, NULL, + if (sample_count != _device_agent->get_sample_limit()) + _device_agent->set_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES, g_variant_new_uint64(sample_count)); bool rle_mode = _sample_count.currentText().contains(RLEString); - dev_inst->set_config(NULL, NULL, + _device_agent->set_config(NULL, NULL, SR_CONF_RLE, g_variant_new_boolean(rle_mode)); } @@ -775,43 +792,51 @@ void SamplingBar::on_run_stop() { if (get_sampling() || _session->isRepeating()) { _session->exit_capture(); - } else { - enable_run_stop(false); - enable_instant(false); - commit_settings(); - _instant = false; + return; + } - DevInst *dev_inst = get_selected_device(); - if (!dev_inst) - return; + if (_device_agent->have_instance() == false) + { + dsv_info("%s", "Have no device, can't to collect data."); + return; + } + + enable_run_stop(false); + enable_instant(false); + commit_settings(); + _instant = false; - if (dev_inst->dev_inst()->mode == DSO) { - GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO); - if (gvar != NULL) { - bool zero = g_variant_get_boolean(gvar); - g_variant_unref(gvar); - if (zero) { - dialogs::DSMessageBox msg(this); - msg.mBox()->setText(tr("Auto Calibration")); - msg.mBox()->setInformativeText(tr("Please adjust zero skew and save the result!")); - //msg.setStandardButtons(QMessageBox::Ok); - msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); - msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole); - msg.mBox()->setIcon(QMessageBox::Warning); - if (msg.exec()) { - zero_adj(); - } else { - dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); - enable_run_stop(true); - enable_instant(true); - } - return; + + if (_device_agent->get_work_mode() == DSO) { + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); + if (gvar != NULL) + { + bool zero = g_variant_get_boolean(gvar); + g_variant_unref(gvar); + + if (zero) { + dialogs::DSMessageBox msg(this); + msg.mBox()->setText(tr("Auto Calibration")); + msg.mBox()->setInformativeText(tr("Please adjust zero skew and save the result!")); + //msg.setStandardButtons(QMessageBox::Ok); + msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); + msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole); + msg.mBox()->setIcon(QMessageBox::Warning); + + if (msg.exec()) { + zero_adj(); } + else { + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); + enable_run_stop(true); + enable_instant(true); + } + return; } } - - sig_run_stop(); } + + sig_run_stop(); } void SamplingBar::on_instant_stop() @@ -819,8 +844,9 @@ void SamplingBar::on_instant_stop() if (get_sampling()) { _session->set_repeating(false); bool wait_upload = false; + if (_session->get_run_mode() != SigSession::Repetitive) { - GVariant *gvar = get_selected_device()->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD); + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD); if (gvar != NULL) { wait_upload = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -830,19 +856,25 @@ void SamplingBar::on_instant_stop() _session->stop_capture(); _session->capture_state_changed(SigSession::Stopped); } - } else { + } + else { + + if (_device_agent->have_instance() == false){ + dsv_info("%s", "Have no device, can't to collect data."); + return; + } + enable_run_stop(false); enable_instant(false); commit_settings(); _instant = true; - DevInst *dev_inst = get_selected_device(); - - if (!dev_inst) + if (_device_agent->have_instance() == false){ return; + } - if (dev_inst->dev_inst()->mode == DSO) { - GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO); + if (_device_agent->get_work_mode() == DSO) { + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ZERO); if (gvar != NULL) { bool zero = g_variant_get_boolean(gvar); @@ -856,10 +888,12 @@ void SamplingBar::on_instant_stop() msg.mBox()->addButton(tr("Ok"), QMessageBox::AcceptRole); msg.mBox()->addButton(tr("Skip"), QMessageBox::RejectRole); msg.mBox()->setIcon(QMessageBox::Warning); + if (msg.exec()) { zero_adj(); - } else { - dev_inst->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); + } + else { + _device_agent->set_config(NULL, NULL, SR_CONF_ZERO, g_variant_new_boolean(false)); enable_run_stop(true); enable_instant(true); } @@ -873,29 +907,30 @@ void SamplingBar::on_instant_stop() } void SamplingBar::on_device_selected() -{ - +{ + if (_updating_device_list){ + return; + } + if (_device_selector.currentIndex() == -1){ + dsv_err("%s", "Have no selected device."); + return; + } _session->stop_capture(); _session->session_save(); - DevInst* dev_inst = get_selected_device(); - if (!dev_inst) - return; + ds_device_handle devHandle = (ds_device_handle)_device_selector.currentData().toULongLong(); - try { - _session->set_device(dev_inst); - } catch(QString e) { - show_session_error(tr("Failed to select ") + dev_inst->dev_inst()->model, e); + if (_session->set_device(devHandle)){ + sig_device_selected(); } - sig_device_selected(); } void SamplingBar::enable_toggle(bool enable) { bool test = false; - DevInst *dev_inst = get_selected_device(); - if (dev_inst && dev_inst->owner()) { - GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST); + + if (_device_agent->have_instance()) { + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_TEST); if (gvar != NULL) { test = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -903,16 +938,18 @@ void SamplingBar::enable_toggle(bool enable) } if (!test) { _sample_count.setDisabled(!enable); - if (dev_inst->dev_inst()->mode == DSO) + + if (_device_agent->get_work_mode() == DSO) _sample_rate.setDisabled(true); else _sample_rate.setDisabled(!enable); - } else { + } + else { _sample_count.setDisabled(true); _sample_rate.setDisabled(true); } - if (_session->get_device()->name() == "virtual-session") { + if (_device_agent->name() == "virtual-session") { _sample_count.setDisabled(true); _sample_rate.setDisabled(true); } @@ -942,10 +979,12 @@ void SamplingBar::show_session_error( void SamplingBar::reload() { QString iconPath = GetIconPath(); - if (_session->get_device()->dev_inst()->mode == LOGIC) { - if (_session->get_device()->name() == "virtual-session") { + + if (_device_agent->get_work_mode() == LOGIC) { + if (_device_agent->name() == "virtual-session") { _mode_action->setVisible(false); - } else { + } + else { _mode_button.setIcon(_session->get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : QIcon(iconPath+"/moder.svg")); _mode_action->setVisible(true); @@ -953,12 +992,14 @@ void SamplingBar::reload() _run_stop_action->setVisible(true); _instant_action->setVisible(true); enable_toggle(true); - } else if (_session->get_device()->dev_inst()->mode == ANALOG) { + } + else if (_device_agent->get_work_mode() == ANALOG) { _mode_action->setVisible(false); _run_stop_action->setVisible(true); _instant_action->setVisible(false); enable_toggle(true); - } else if (_session->get_device()->dev_inst()->mode == DSO) { + } + else if (_device_agent->get_work_mode() == DSO) { _mode_action->setVisible(false); _run_stop_action->setVisible(true); _instant_action->setVisible(true); @@ -974,10 +1015,12 @@ void SamplingBar::on_mode() { QString iconPath = GetIconPath(); QAction *act = qobject_cast(sender()); + if (act == _action_single) { _mode_button.setIcon(QIcon(iconPath+"/modes.svg")); _session->set_run_mode(pv::SigSession::Single); - } else if (act == _action_repeat) { + } + else if (act == _action_repeat) { _mode_button.setIcon(QIcon(iconPath+"/moder.svg")); pv::dialogs::Interval interval_dlg(_session, this); interval_dlg.exec(); @@ -985,20 +1028,30 @@ void SamplingBar::on_mode() } } - void SamplingBar::update_device_list(struct ds_device_info *array, int count, int select_index) - { - assert(array); - assert(count > 0); + void SamplingBar::update_device_list() + { - _is_seting_list = true; + struct ds_device_info *array = NULL; + int dev_count = 0; + int select_index = 0; + + array = _session->get_device_list(dev_count, select_index); + + if (array == NULL){ + dsv_err("%s", "Get deivce list error!"); + return; + } + + _updating_device_list = true; struct ds_device_info *p = NULL; _device_selector.clear(); - for (int i=0; iname), QVariant::fromValue(p->handle)); + _device_selector.addItem(QString(p->name), QVariant::fromValue((unsigned long long)p->handle)); } + free(array); _device_selector.setCurrentIndex(select_index); @@ -1008,7 +1061,7 @@ void SamplingBar::on_mode() _device_selector.setFixedWidth(min(width+15, _device_selector.maximumWidth())); _device_selector.view()->setMinimumWidth(width+30); - _is_seting_list = false; + _updating_device_list = false; } } // namespace toolbars diff --git a/DSView/pv/toolbars/samplingbar.h b/DSView/pv/toolbars/samplingbar.h index 8c6492e6..bb9416ce 100644 --- a/DSView/pv/toolbars/samplingbar.h +++ b/DSView/pv/toolbars/samplingbar.h @@ -38,8 +38,10 @@ struct st_dev_inst; class QAction; struct ds_device_info; +class DeviceAgent; + namespace pv -{ +{ class SigSession; namespace device @@ -88,7 +90,7 @@ namespace pv double commit_hori_res(); double get_hori_res(); - void update_device_list(struct ds_device_info *array, int count, int select_index); + void update_device_list(); public slots: void set_sample_rate(uint64_t sample_rate); @@ -154,7 +156,8 @@ namespace pv QAction *_action_repeat; QAction *_action_single; bool _instant; - bool _is_seting_list; + bool _updating_device_list; + DeviceAgent *_device_agent; }; } // namespace toolbars diff --git a/DSView/pv/toolbars/trigbar.cpp b/DSView/pv/toolbars/trigbar.cpp index 8bf7495e..00a50a56 100644 --- a/DSView/pv/toolbars/trigbar.cpp +++ b/DSView/pv/toolbars/trigbar.cpp @@ -280,7 +280,9 @@ void TrigBar::reload() { close_all(); - if (_session->get_device()->dev_inst()->mode == LOGIC) { + int mode = _session->get_device()->get_work_mode(); + + if (mode == LOGIC) { _trig_action->setVisible(true); _protocol_action->setVisible(true); _measure_action->setVisible(true); @@ -289,7 +291,7 @@ void TrigBar::reload() _action_lissajous->setVisible(false); _action_dispalyOptions->setVisible(true); - } else if (_session->get_device()->dev_inst()->mode == ANALOG) { + } else if (mode == ANALOG) { _trig_action->setVisible(false); _protocol_action->setVisible(false); _measure_action->setVisible(true); @@ -298,7 +300,7 @@ void TrigBar::reload() _action_lissajous->setVisible(false); _action_dispalyOptions->setVisible(false); - } else if (_session->get_device()->dev_inst()->mode == DSO) { + } else if (mode == DSO) { _trig_action->setVisible(true); _protocol_action->setVisible(false); _measure_action->setVisible(true); @@ -355,7 +357,6 @@ void TrigBar::on_actionLissajous_triggered() void TrigBar::restore_status() { DockOptions *opt = getDockOptions(); - int mode = _session->get_device()->dev_inst()->mode; if (opt->decodeDoc){ _protocol_button.setChecked(true); @@ -381,7 +382,7 @@ void TrigBar::restore_status() DockOptions* TrigBar::getDockOptions() { AppConfig &app = AppConfig::Instance(); - int mode = _session->get_device()->dev_inst()->mode; + int mode = _session->get_device()->get_work_mode(); if (mode == LOGIC) return &app._frameOptions._logicDock; diff --git a/DSView/pv/view/analogsignal.cpp b/DSView/pv/view/analogsignal.cpp index 524536ae..3059496f 100644 --- a/DSView/pv/view/analogsignal.cpp +++ b/DSView/pv/view/analogsignal.cpp @@ -45,9 +45,8 @@ const QColor AnalogSignal::SignalColours[4] = { const float AnalogSignal::EnvelopeThreshold = 16.0f; -AnalogSignal::AnalogSignal(DevInst *dev_inst,data::Analog *data, - sr_channel *probe) : - Signal(dev_inst, probe), +AnalogSignal::AnalogSignal(data::Analog *data, sr_channel *probe) : + Signal(probe), _data(data), _rects(NULL), _hover_en(false), @@ -60,7 +59,7 @@ AnalogSignal::AnalogSignal(DevInst *dev_inst,data::Analog *data, GVariant *gvar; // channel bits - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_UNIT_BITS); + gvar = session->get_device()->get_config(NULL, NULL, SR_CONF_UNIT_BITS); if (gvar != NULL) { _bits = g_variant_get_byte(gvar); g_variant_unref(gvar); @@ -70,14 +69,14 @@ AnalogSignal::AnalogSignal(DevInst *dev_inst,data::Analog *data, dsv_warn("%s%d", "Warning: config_get SR_CONF_UNIT_BITS failed, set to %d(default).", DefaultBits); } - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_REF_MIN); + gvar = session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); if (gvar != NULL) { _ref_min = g_variant_get_uint32(gvar); g_variant_unref(gvar); } else { _ref_min = 1; } - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_REF_MAX); + gvar = session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); if (gvar != NULL) { _ref_max = g_variant_get_uint32(gvar); g_variant_unref(gvar); @@ -86,7 +85,7 @@ AnalogSignal::AnalogSignal(DevInst *dev_inst,data::Analog *data, } // -- vpos - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_OFFSET); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_OFFSET); if (gvar != NULL) { _zero_offset = g_variant_get_uint16(gvar); g_variant_unref(gvar); @@ -155,7 +154,7 @@ double AnalogSignal::get_ref_max() int AnalogSignal::get_hw_offset() { int hw_offset = 0; - GVariant *gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_HW_OFFSET); + GVariant *gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_HW_OFFSET); if (gvar != NULL) { hw_offset = g_variant_get_uint16(gvar); g_variant_unref(gvar); @@ -168,23 +167,23 @@ int AnalogSignal::commit_settings() int ret; // -- enable - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_EN, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_EN, g_variant_new_boolean(enabled())); // -- vdiv - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, g_variant_new_uint64(_probe->vdiv)); // -- coupling - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_COUPLING, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_COUPLING, g_variant_new_byte(_probe->coupling)); // -- offset - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, g_variant_new_uint16(_probe->offset)); // -- trig_value - _dev_inst->set_config(_probe, NULL, SR_CONF_TRIGGER_VALUE, + session->get_device()->set_config(_probe, NULL, SR_CONF_TRIGGER_VALUE, g_variant_new_byte(_probe->trig_value)); return ret; @@ -285,7 +284,7 @@ QPointF AnalogSignal::get_point(uint64_t index, float &value) uint64_t AnalogSignal::get_vdiv() { uint64_t vdiv = 0; - GVariant* gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_VDIV); + GVariant* gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_VDIV); if (gvar != NULL) { vdiv = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -296,7 +295,7 @@ uint64_t AnalogSignal::get_vdiv() uint8_t AnalogSignal::get_acCoupling() { uint64_t coupling = 0; - GVariant* gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_COUPLING); + GVariant* gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_COUPLING); if (gvar != NULL) { coupling = g_variant_get_byte(gvar); g_variant_unref(gvar); @@ -307,7 +306,7 @@ uint8_t AnalogSignal::get_acCoupling() bool AnalogSignal::get_mapDefault() { bool isDefault = true; - GVariant* gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_MAP_DEFAULT); + GVariant* gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_MAP_DEFAULT); if (gvar != NULL) { isDefault = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -318,7 +317,7 @@ bool AnalogSignal::get_mapDefault() QString AnalogSignal::get_mapUnit() { QString unit; - GVariant* gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_MAP_UNIT); + GVariant* gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_MAP_UNIT); if (gvar != NULL) { unit = g_variant_get_string(gvar, NULL); g_variant_unref(gvar); @@ -329,7 +328,7 @@ QString AnalogSignal::get_mapUnit() double AnalogSignal::get_mapMin() { double min = -1; - GVariant* gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_MAP_MIN); + GVariant* gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_MAP_MIN); if (gvar != NULL) { min = g_variant_get_double(gvar); g_variant_unref(gvar); @@ -340,7 +339,7 @@ double AnalogSignal::get_mapMin() double AnalogSignal::get_mapMax() { double max = 1; - GVariant* gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_MAP_MAX); + GVariant* gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_MAP_MAX); if (gvar != NULL) { max = g_variant_get_double(gvar); g_variant_unref(gvar); @@ -352,7 +351,7 @@ uint64_t AnalogSignal::get_factor() { GVariant* gvar; uint64_t factor; - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); if (gvar != NULL) { factor = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -409,7 +408,7 @@ void AnalogSignal::set_zero_ratio(double ratio) return; _zero_offset = ratio2value(ratio); - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, g_variant_new_uint16(_zero_offset)); } diff --git a/DSView/pv/view/analogsignal.h b/DSView/pv/view/analogsignal.h index 48f3d7f6..b2fd6524 100644 --- a/DSView/pv/view/analogsignal.h +++ b/DSView/pv/view/analogsignal.h @@ -52,7 +52,7 @@ private: static const uint8_t DefaultBits = 8; public: - AnalogSignal(DevInst* dev_inst, pv::data::Analog *data, + AnalogSignal(pv::data::Analog *data, sr_channel *probe); AnalogSignal(view::AnalogSignal* s, pv::data::Analog *data, sr_channel *probe); diff --git a/DSView/pv/view/devmode.cpp b/DSView/pv/view/devmode.cpp index 3351268f..78f85392 100644 --- a/DSView/pv/view/devmode.cpp +++ b/DSView/pv/view/devmode.cpp @@ -35,6 +35,7 @@ #include "../config/appconfig.h" #include "../ui/msgbox.h" +#include "../log.h" static const struct dev_mode_name dev_mode_name_list[] = @@ -48,12 +49,14 @@ namespace pv { namespace view { DevMode::DevMode(QWidget *parent, SigSession *session) : - QWidget(parent), - _session(session) + QWidget(parent) { _bFile = false; - QHBoxLayout *layout = new QHBoxLayout(this); + _session = session; + _device_agent = session->get_device(); + + QHBoxLayout *layout = new QHBoxLayout(this); layout->setSpacing(0); layout->setContentsMargins(2, 0, 0, 0); @@ -101,8 +104,10 @@ void DevMode::changeEvent(QEvent *event) void DevMode::set_device() { - DevInst* dev_inst = _session->get_device(); - assert(dev_inst); + if (_device_agent->have_instance() == false){ + dsv_info("%s", "DevMode::set_device, Have no device."); + return; + } _bFile = false; @@ -123,7 +128,7 @@ void DevMode::set_device() QString iconPath = GetIconPath() + "/"; - auto dev_mode_list = dev_inst->get_dev_mode_list(); + auto dev_mode_list = _device_agent->get_device_mode_list(); for (const GSList *l = dev_mode_list; l; l = l->next) { @@ -141,7 +146,7 @@ void DevMode::set_device() connect(action, SIGNAL(triggered()), this, SLOT(on_mode_change())); _mode_list[action] = mode; - if (dev_inst->dev_inst()->mode == _mode_list[action]->mode) + if (_device_agent->get_work_mode() == _mode_list[action]->mode) { QString icon_fname = iconPath + icon_name; _mode_btn->setIcon(QIcon(icon_fname)); @@ -153,8 +158,7 @@ void DevMode::set_device() _pop_menu->addAction(action); } - if ((dynamic_cast(dev_inst))) - { + if (_device_agent->is_file()){ _close_button->setDisabled(false); _close_button->setIcon(QIcon(iconPath + "/close.svg")); _bFile = true; @@ -175,11 +179,15 @@ void DevMode::paintEvent(QPaintEvent*) void DevMode::on_mode_change() { - DevInst* dev_inst = _session->get_device(); - assert(dev_inst); + if (_device_agent->have_instance() == false){ + assert(false); + } + QAction *action = qobject_cast(sender()); - if (dev_inst->dev_inst()->mode == _mode_list[action]->mode) + + if (_device_agent->get_work_mode() == _mode_list[action]->mode){ return; + } QString iconPath = GetIconPath(); AppConfig &app = AppConfig::Instance(); @@ -188,13 +196,13 @@ void DevMode::on_mode_change() for(auto i = _mode_list.begin();i != _mode_list.end(); i++) { if ((*i).first == action) { - if (dev_inst->dev_inst()->mode != (*i).second->mode) { + 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->session_save(); - dev_inst->set_config(NULL, NULL, + _device_agent->set_config(NULL, NULL, SR_CONF_DEVICE_MODE, g_variant_new_int16((*i).second->mode)); @@ -216,12 +224,12 @@ void DevMode::on_mode_change() void DevMode::on_close() { - DevInst *dev_inst = _session->get_device(); - assert(dev_inst); + if (_device_agent->have_instance() == false){ + assert(false); + } if (_bFile && MsgBox::Confirm(tr("are you sure to close the device?"))){ - _session->close_file(dev_inst); - dev_changed(true); + _session->close_file(_device_agent->handle()); } } diff --git a/DSView/pv/view/devmode.h b/DSView/pv/view/devmode.h index e32bdc85..53cae8c6 100644 --- a/DSView/pv/view/devmode.h +++ b/DSView/pv/view/devmode.h @@ -43,6 +43,8 @@ struct dev_mode_name{ const char *_logo; }; +class DeviceAgent; + namespace pv { namespace device{ @@ -93,6 +95,8 @@ private: QPoint _mouse_point; QToolButton *_close_button; bool _bFile; + + DeviceAgent *_device_agent; }; } // namespace view diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index 5b37e8db..3c9cdfad 100644 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -29,9 +29,9 @@ #include "../dsvdef.h" #include "../data/dso.h" #include "../data/dsosnapshot.h" -#include "../sigsession.h" -#include "../device/devinst.h" +#include "../sigsession.h" #include "../log.h" +#include "../appcontrol.h" using namespace std; @@ -53,10 +53,9 @@ const QColor DsoSignal::SignalColours[4] = { const float DsoSignal::EnvelopeThreshold = 256.0f; -DsoSignal::DsoSignal(DevInst *dev_inst, - data::Dso *data, +DsoSignal::DsoSignal(data::Dso *data, sr_channel *probe): - Signal(dev_inst, probe), + Signal(probe), _data(data), _scale(0), _en_lock(false), @@ -75,12 +74,17 @@ DsoSignal::DsoSignal(DevInst *dev_inst, { QVector vValue; QVector vUnit; - for(uint64_t i = 0; i < vDialUnitCount; i++) + + for(uint64_t i = 0; i < vDialUnitCount; i++){ vUnit.append(vDialUnit[i]); + } GVariant *gvar_list, *gvar_list_vdivs; - if (sr_config_list(dev_inst->dev_inst()->driver, dev_inst->dev_inst(), - NULL, SR_CONF_PROBE_VDIV, &gvar_list) == SR_OK) { + + gvar_list = session->get_device()->get_config_list(NULL, SR_CONF_PROBE_VDIV); + + if (gvar_list != NULL) + { assert(gvar_list); if ((gvar_list_vdivs = g_variant_lookup_value(gvar_list, "vdivs", G_VARIANT_TYPE("at")))) { @@ -117,7 +121,7 @@ pv::data::Dso* DsoSignal::dso_data() void DsoSignal::set_scale(int height) { - _scale = height / (_ref_max - _ref_min) * _view->session().stop_scale(); + _scale = height / (_ref_max - _ref_min) * session->stop_scale(); } float DsoSignal::get_scale() @@ -146,15 +150,15 @@ int DsoSignal::get_name_width() } void DsoSignal::set_enable(bool enable) -{ - if (_dev_inst->name() == "DSLogic" && - get_index() == 0) +{ + if (session->get_device()->name() == "DSLogic" && get_index() == 0){ return; + } _en_lock = true; GVariant* gvar; bool cur_enable; - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_EN); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_EN); if (gvar != NULL) { cur_enable = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -170,20 +174,20 @@ void DsoSignal::set_enable(bool enable) } bool running = false; - if (_view->session().get_capture_state() == SigSession::Running) { + if (session->get_capture_state() == SigSession::Running) { running = true; - _view->session().stop_capture(); + session->stop_capture(); } - while(_view->session().get_capture_state() == SigSession::Running) + while(session->get_capture_state() == SigSession::Running) QCoreApplication::processEvents(); set_vDialActive(false); - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_EN, + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_EN, g_variant_new_boolean(enable)); _view->update_hori_res(); if (running) { - _view->session().repeat_resume(); + session->repeat_resume(); } _view->set_update(_viewport, true); @@ -203,22 +207,22 @@ void DsoSignal::set_vDialActive(bool active) } bool DsoSignal::go_vDialPre(bool manul) -{ +{ if (_autoV && manul) - autoV_end(); + autoV_end(); if (enabled() && !_vDial->isMin()) { - if (_view->session().get_capture_state() == SigSession::Running) - _view->session().refresh(RefreshShort); + if (session->get_capture_state() == SigSession::Running) + session->refresh(RefreshShort); const double pre_vdiv = _vDial->get_value(); _vDial->set_sel(_vDial->get_sel() - 1); - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, g_variant_new_uint64(_vDial->get_value())); - if (_view->session().get_capture_state() == SigSession::Stopped) { - _view->session().set_stop_scale(_view->session().stop_scale() * (pre_vdiv/_vDial->get_value())); + if (session->get_capture_state() == SigSession::Stopped) { + session->set_stop_scale(session->stop_scale() * (pre_vdiv/_vDial->get_value())); set_scale(get_view_rect().height()); } - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, g_variant_new_uint16(_zero_offset)); _view->vDial_updated(); @@ -235,20 +239,20 @@ bool DsoSignal::go_vDialPre(bool manul) bool DsoSignal::go_vDialNext(bool manul) { if (_autoV && manul) - autoV_end(); + autoV_end(); if (enabled() && !_vDial->isMax()) { - if (_view->session().get_capture_state() == SigSession::Running) - _view->session().refresh(RefreshShort); + if (session->get_capture_state() == SigSession::Running) + session->refresh(RefreshShort); const double pre_vdiv = _vDial->get_value(); _vDial->set_sel(_vDial->get_sel() + 1); - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, g_variant_new_uint64(_vDial->get_value())); - if (_view->session().get_capture_state() == SigSession::Stopped) { - _view->session().set_stop_scale(_view->session().stop_scale() * (pre_vdiv/_vDial->get_value())); + if (session->get_capture_state() == SigSession::Stopped) { + session->set_stop_scale(session->stop_scale() * (pre_vdiv/_vDial->get_value())); set_scale(get_view_rect().height()); } - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, g_variant_new_uint16(_zero_offset)); _view->vDial_updated(); @@ -264,10 +268,10 @@ bool DsoSignal::go_vDialNext(bool manul) bool DsoSignal::load_settings() { - GVariant* gvar; + GVariant* gvar; // dso channel bits - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_UNIT_BITS); + gvar = session->get_device()->get_config(NULL, NULL, SR_CONF_UNIT_BITS); if (gvar != NULL) { _bits = g_variant_get_byte(gvar); g_variant_unref(gvar); @@ -276,17 +280,17 @@ bool DsoSignal::load_settings() _bits = DefaultBits; dsv_warn("%s%d", "Warning: config_get SR_CONF_UNIT_BITS failed, set to %d(default).", DefaultBits); - if (strncmp(_dev_inst->name().toUtf8().data(), "virtual", 7)) + if (strncmp(session->get_device()->name().toUtf8().data(), "virtual", 7)) return false; } - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_REF_MIN); + gvar = session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); if (gvar != NULL) { _ref_min = g_variant_get_uint32(gvar); g_variant_unref(gvar); } else { _ref_min = 1; } - gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_REF_MAX); + gvar = session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); if (gvar != NULL) { _ref_max = g_variant_get_uint32(gvar); g_variant_unref(gvar); @@ -297,7 +301,7 @@ bool DsoSignal::load_settings() // -- vdiv uint64_t vdiv; uint64_t vfactor; - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_VDIV); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_VDIV); if (gvar != NULL) { vdiv = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -306,7 +310,7 @@ bool DsoSignal::load_settings() dsv_err("%s", "ERROR: config_get SR_CONF_PROBE_VDIV failed."); return false; } - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); if (gvar != NULL) { vfactor = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -320,7 +324,7 @@ bool DsoSignal::load_settings() _vDial->set_factor(vfactor); // -- coupling - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_COUPLING); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_COUPLING); if (gvar != NULL) { _acCoupling = g_variant_get_byte(gvar); g_variant_unref(gvar); @@ -331,7 +335,7 @@ bool DsoSignal::load_settings() } // -- vpos - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_OFFSET); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_OFFSET); if (gvar != NULL) { _zero_offset = g_variant_get_uint16(gvar); g_variant_unref(gvar); @@ -342,7 +346,7 @@ bool DsoSignal::load_settings() } // -- trig_value - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_TRIGGER_VALUE); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_TRIGGER_VALUE); if (gvar != NULL) { _trig_value = g_variant_get_byte(gvar); _trig_delta = get_trig_vrate() - get_zero_ratio(); @@ -350,7 +354,7 @@ bool DsoSignal::load_settings() } else { dsv_err("%s", "ERROR: config_get SR_CONF_TRIGGER_VALUE failed."); - if (strncmp(_dev_inst->name().toUtf8().data(), "virtual", 7)) + if (strncmp(session->get_device()->name().toUtf8().data(), "virtual", 7)) return false; } @@ -364,26 +368,27 @@ bool DsoSignal::load_settings() int DsoSignal::commit_settings() { int ret; + // -- enable - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_EN, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_EN, g_variant_new_boolean(enabled())); // -- vdiv - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_VDIV, g_variant_new_uint64(_vDial->get_value())); - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_FACTOR, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_FACTOR, g_variant_new_uint64(_vDial->get_factor())); // -- coupling - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_COUPLING, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_COUPLING, g_variant_new_byte(_acCoupling)); // -- offset - ret = _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, + ret = session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, g_variant_new_uint16(_zero_offset)); // -- trig_value - _dev_inst->set_config(_probe, NULL, SR_CONF_TRIGGER_VALUE, + session->get_device()->set_config(_probe, NULL, SR_CONF_TRIGGER_VALUE, g_variant_new_byte(_trig_value)); return ret; @@ -412,8 +417,8 @@ uint8_t DsoSignal::get_acCoupling() void DsoSignal::set_acCoupling(uint8_t coupling) { if (enabled()) { - _acCoupling = coupling; - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_COUPLING, + _acCoupling = coupling; + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_COUPLING, g_variant_new_byte(_acCoupling)); } } @@ -439,8 +444,8 @@ double DsoSignal::pos2ratio(int pos) } double DsoSignal::get_trig_vrate() -{ - if (_dev_inst->name() == "DSLogic") +{ + if (session->get_device()->name() == "DSLogic") return value2ratio(_trig_value - ratio2value(0.5)) + get_zero_ratio(); else return value2ratio(_trig_value); @@ -456,8 +461,9 @@ void DsoSignal::set_trig_vpos(int pos, bool delta_change) void DsoSignal::set_trig_ratio(double ratio, bool delta_change) { - double delta = ratio; - if (_dev_inst->name() == "DSLogic") { + double delta = ratio; + + if (session->get_device()->name() == "DSLogic") { delta = delta - get_zero_ratio(); delta = min(delta, 0.5); delta = max(delta, -0.5); @@ -470,7 +476,7 @@ void DsoSignal::set_trig_ratio(double ratio, bool delta_change) _trig_value = std::min(std::max(_trig_value, margin), (ratio2value(1) - margin)); if (delta_change) _trig_delta = get_trig_vrate() - get_zero_ratio(); - _dev_inst->set_config(_probe, NULL, SR_CONF_TRIGGER_VALUE, + session->get_device()->set_config(_probe, NULL, SR_CONF_TRIGGER_VALUE, g_variant_new_byte(_trig_value)); } @@ -486,8 +492,9 @@ double DsoSignal::get_zero_ratio() int DsoSignal::get_hw_offset() { - int hw_offset = 0; - GVariant *gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_HW_OFFSET); + int hw_offset = 0; + + GVariant *gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_HW_OFFSET); if (gvar != NULL) { hw_offset = g_variant_get_uint16(gvar); g_variant_unref(gvar); @@ -505,8 +512,8 @@ void DsoSignal::set_zero_vpos(int pos) void DsoSignal::set_zero_ratio(double ratio) { - _zero_offset = ratio2value(ratio); - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, + _zero_offset = ratio2value(ratio); + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_OFFSET, g_variant_new_uint16(_zero_offset)); } @@ -514,8 +521,9 @@ void DsoSignal::set_factor(uint64_t factor) { if (enabled()) { GVariant* gvar; - uint64_t prefactor = 0; - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); + uint64_t prefactor = 0; + + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); if (gvar != NULL) { prefactor = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -525,7 +533,7 @@ void DsoSignal::set_factor(uint64_t factor) return; } if (prefactor != factor) { - _dev_inst->set_config(_probe, NULL, SR_CONF_PROBE_FACTOR, + session->get_device()->set_config(_probe, NULL, SR_CONF_PROBE_FACTOR, g_variant_new_uint64(factor)); _vDial->set_factor(factor); _view->set_update(_viewport, true); @@ -537,8 +545,9 @@ void DsoSignal::set_factor(uint64_t factor) uint64_t DsoSignal::get_factor() { GVariant* gvar; - uint64_t factor; - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); + uint64_t factor; + + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); if (gvar != NULL) { factor = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -706,11 +715,12 @@ void DsoSignal::paint_prepare() if (!snapshot->has_data(get_index())) return; - const uint16_t enabled_channels = snapshot->get_channel_num(); - if (_view->session().trigd()) { - if (get_index() == _view->session().trigd_ch()) { + const uint16_t enabled_channels = snapshot->get_channel_num(); + + if (session->trigd()) { + if (get_index() == session->trigd_ch()) { uint8_t slope = DSO_TRIGGER_RISING; - GVariant *gvar = _view->session().get_device()->get_config(NULL, NULL, SR_CONF_TRIGGER_SLOPE); + GVariant *gvar = session->get_device()->get_config(NULL, NULL, SR_CONF_TRIGGER_SLOPE); if (gvar != NULL) { slope = g_variant_get_byte(gvar); g_variant_unref(gvar); @@ -751,7 +761,7 @@ void DsoSignal::paint_back(QPainter &p, int left, int right, QColor fore, QColor int i, j; const int height = get_view_rect().height(); - const int width = right - left; + const int width = right - left; fore.setAlpha(View::BackAlpha); @@ -764,8 +774,9 @@ void DsoSignal::paint_back(QPainter &p, int left, int right, QColor fore, QColor // draw zoom region fore.setAlpha(View::ForeAlpha); p.setPen(fore); - const uint64_t sample_len = _view->session().cur_samplelimits(); - const double samplerate = _view->session().cur_snap_samplerate(); + + const uint64_t sample_len = session->cur_samplelimits(); + const double samplerate = session->cur_snap_samplerate(); const double samples_per_pixel = samplerate * _view->scale(); const double shown_rate = min(samples_per_pixel * width * 1.0 / sample_len, 1.0); const double start = _view->offset() * samples_per_pixel; @@ -851,8 +862,8 @@ void DsoSignal::paint_mid(QPainter &p, int left, int right, QColor fore, QColor const uint16_t enabled_channels = snapshot->get_channel_num(); const double pixels_offset = offset; const double samplerate = _data->samplerate(); - //const double samplerate = _dev_inst->get_sample_rate(); - //const double samplerate = _view->session().cur_snap_samplerate(); + //const double samplerate = session->get_device()->get_sample_rate(); + //const double samplerate = session->cur_snap_samplerate(); const int64_t last_sample = max((int64_t)(snapshot->get_sample_count() - 1), (int64_t)0); const double samples_per_pixel = samplerate * scale; const double start = offset * samples_per_pixel - _view->trig_hoff(); @@ -876,8 +887,9 @@ void DsoSignal::paint_mid(QPainter &p, int left, int right, QColor fore, QColor pixels_offset, samples_per_pixel, enabled_channels); } - sr_status status; - if (sr_status_get(_dev_inst->dev_inst(), &status, false) == SR_OK) { + sr_status status; + + if (session->get_device()->get_device_status(status, false)) { _mValid = true; if (status.measure_valid) { _min = (index == 0) ? status.ch0_min : status.ch1_min; @@ -890,7 +902,7 @@ void DsoSignal::paint_mid(QPainter &p, int left, int right, QColor fore, QColor const uint32_t count = (index == 0) ? status.ch0_cyc_cnt : status.ch1_cyc_cnt; const bool plevel = (index == 0) ? status.ch0_plevel : status.ch1_plevel; const bool startXORend = (index == 0) ? (status.ch0_cyc_llen == 0) : (status.ch1_cyc_llen == 0); - const uint16_t total_channels = g_slist_length(_dev_inst->dev_inst()->channels); + const uint16_t total_channels = g_slist_length(session->get_device()->get_channels()); const double tfactor = (total_channels / enabled_channels) * SR_GHZ(1) * 1.0 / samplerate; double samples = (index == 0) ? status.ch0_cyc_tlen : status.ch1_cyc_tlen; @@ -925,7 +937,7 @@ void DsoSignal::paint_fore(QPainter &p, int left, int right, QColor fore, QColor if (!_show) return; - assert(_view); + assert(_view); fore.setAlpha(View::BackAlpha); QPen pen(fore); @@ -999,7 +1011,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 (_view->session().get_capture_state() == SigSession::Stopped) + if (session->get_capture_state() == SigSession::Stopped) paint_hover_measure(p, fore, back); // autoset @@ -1117,7 +1129,7 @@ void DsoSignal::paint_envelope(QPainter &p, } void DsoSignal::paint_type_options(QPainter &p, int right, const QPoint pt, QColor fore) -{ +{ p.setRenderHint(QPainter::Antialiasing, true); QColor foreBack = fore; @@ -1158,7 +1170,7 @@ void DsoSignal::paint_type_options(QPainter &p, int right, const QPoint pt, QCol p.drawText(acdc_rect, Qt::AlignCenter | Qt::AlignVCenter, (_acCoupling == SR_GND_COUPLING) ? tr(strings[2]): (_acCoupling == SR_DC_COUPLING) ? tr(strings[3]) : tr(strings[4])); - if (!_dev_inst->name().contains("virtual")) { + if (!session->get_device()->name().contains("virtual")) { p.setPen(Qt::transparent); p.setBrush(enabled() ? (auto_rect.contains(pt) ? _colour.darker() : _colour) : foreBack); p.drawRect(auto_rect); @@ -1169,7 +1181,7 @@ void DsoSignal::paint_type_options(QPainter &p, int right, const QPoint pt, QCol // paint the probe factor selector GVariant* gvar; uint64_t factor; - gvar = _dev_inst->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); + gvar = session->get_device()->get_config(_probe, NULL, SR_CONF_PROBE_FACTOR); if (gvar != NULL) { factor = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -1196,7 +1208,7 @@ void DsoSignal::paint_type_options(QPainter &p, int right, const QPoint pt, QCol } bool DsoSignal::mouse_press(int right, const QPoint pt) -{ +{ int y = get_y(); const QRectF vDial_rect = get_rect(DSO_VDIAL, y, right); const QRectF chEn_rect = get_rect(DSO_CHEN, y, right); @@ -1207,7 +1219,7 @@ bool DsoSignal::mouse_press(int right, const QPoint pt) const QRectF x100_rect = get_rect(DSO_X100, y, right); if (chEn_rect.contains(pt)) { - if (_dev_inst->name() != "virtual-session" && + if (session->get_device()->name() != "virtual-session" && !_en_lock) { set_enable(!enabled()); } @@ -1218,14 +1230,14 @@ bool DsoSignal::mouse_press(int right, const QPoint pt) go_vDialNext(true); else go_vDialPre(true); - } else if (_dev_inst->name() != "virtual-session" && + } else if (session->get_device()->name() != "virtual-session" && acdc_rect.contains(pt)) { - if (_dev_inst->name() == "DSLogic") + if (session->get_device()->name() == "DSLogic") set_acCoupling((get_acCoupling()+1)%2); else set_acCoupling((get_acCoupling()+1)%2); } else if (auto_rect.contains(pt)) { - if (!_dev_inst->name().contains("virtual")) + if (!session->get_device()->name().contains("virtual")) auto_start(); } else if (x1_rect.contains(pt)) { set_factor(1); @@ -1357,8 +1369,8 @@ void DsoSignal::paint_hover_measure(QPainter &p, QColor fore, QColor back) } void DsoSignal::auto_set() -{ - if (_view->session().get_capture_state() == SigSession::Stopped) { +{ + if (session->get_capture_state() == SigSession::Stopped) { if (_autoV) autoV_end(); if (_autoH) @@ -1367,10 +1379,10 @@ void DsoSignal::auto_set() if (_autoH && _autoV && get_zero_ratio() != 0.5) { set_zero_ratio(0.5); } - if (_mValid && !_view->session().get_data_auto_lock()) { + if (_mValid && !session->get_data_auto_lock()) { if (_autoH) { bool roll = false; - GVariant *gvar = _dev_inst->get_config(NULL, NULL, SR_CONF_ROLL); + GVariant *gvar = session->get_device()->get_config(NULL, NULL, SR_CONF_ROLL); if (gvar != NULL) { roll = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -1414,7 +1426,7 @@ void DsoSignal::auto_set() } } if (_autoH || _autoV) - _view->session().data_auto_lock(AutoLock); + session->data_auto_lock(AutoLock); } } } @@ -1446,11 +1458,12 @@ void DsoSignal::auto_end() } void DsoSignal::auto_start() -{ +{ if (_autoV || _autoH) return; - if (_view->session().get_capture_state() == SigSession::Running) { - _view->session().data_auto_lock(AutoLock); + + if (session->get_capture_state() == SigSession::Running) { + session->data_auto_lock(AutoLock); _autoV = true; _autoH = true; _view->auto_trig(get_index()); @@ -1459,12 +1472,12 @@ void DsoSignal::auto_start() } bool DsoSignal::measure(const QPointF &p) -{ +{ _hover_en = false; if (!enabled() || !show()) return false; - if (_view->session().get_capture_state() != SigSession::Stopped) + if (session->get_capture_state() != SigSession::Stopped) return false; const QRectF window = get_view_rect(); @@ -1569,7 +1582,7 @@ QString DsoSignal::get_time(double t) } void DsoSignal::call_auto_end(){ - _view->session().auto_end(); + session->auto_end(); } } // namespace view diff --git a/DSView/pv/view/dsosignal.h b/DSView/pv/view/dsosignal.h index 606cd5ba..e6be077e 100644 --- a/DSView/pv/view/dsosignal.h +++ b/DSView/pv/view/dsosignal.h @@ -85,7 +85,7 @@ private: static const uint16_t MS_RectHeight = 25; public: - DsoSignal(DevInst* dev_inst, pv::data::Dso *data, + DsoSignal(pv::data::Dso *data, sr_channel *probe); virtual ~DsoSignal(); diff --git a/DSView/pv/view/header.cpp b/DSView/pv/view/header.cpp index 370ed412..b4e834c2 100644 --- a/DSView/pv/view/header.cpp +++ b/DSView/pv/view/header.cpp @@ -415,19 +415,6 @@ void Header::contextMenuEvent(QContextMenuEvent *event) if (!t || !t->selected() || action != Trace::LABEL) return; - - /* - * disable group function for v0.97 temporarily - */ -// QMenu menu(this); -// if (t->get_type() == SR_CHANNEL_LOGIC) -// menu.addAction(_action_add_group); -// else if (t->get_type() == SR_CHANNEL_GROUP) -// menu.addAction(_action_del_group); - -// _context_trace = t; -// menu.exec(event->globalPos()); -// _context_trace.r-eset(); } void Header::on_action_set_name_triggered() @@ -440,7 +427,9 @@ void Header::on_action_set_name_triggered() context_Trace->set_name(nameEdit->text()); if (context_Trace->get_type() == SR_CHANNEL_LOGIC || context_Trace->get_type() == SR_CHANNEL_ANALOG) - sr_dev_probe_name_set(_view.session().get_device()->dev_inst(), context_Trace->get_index(), nameEdit->text().toUtf8().constData()); + { + _view.session().get_device()->set_channel_name(context_Trace->get_index(), nameEdit->text().toUtf8()); + } } nameEdit->hide(); diff --git a/DSView/pv/view/logicsignal.cpp b/DSView/pv/view/logicsignal.cpp index e7853d01..ef41d4c0 100644 --- a/DSView/pv/view/logicsignal.cpp +++ b/DSView/pv/view/logicsignal.cpp @@ -39,10 +39,9 @@ const float LogicSignal::Oversampling = 1.0f; const int LogicSignal::StateHeight = 12; const int LogicSignal::StateRound = 5; -LogicSignal::LogicSignal(DevInst *dev_inst, - data::Logic *data, +LogicSignal::LogicSignal(data::Logic *data, sr_channel *probe) : - Signal(dev_inst, probe), + Signal(probe), _data(data), _trig(NONTRIG) { diff --git a/DSView/pv/view/logicsignal.h b/DSView/pv/view/logicsignal.h index 931c0df6..e179d6ed 100644 --- a/DSView/pv/view/logicsignal.h +++ b/DSView/pv/view/logicsignal.h @@ -35,7 +35,6 @@ class Logic; class Analog; } -using namespace pv::device; namespace view { @@ -64,7 +63,7 @@ public: }; public: - LogicSignal(DevInst *dev_inst, data::Logic* data, sr_channel *probe); + LogicSignal(data::Logic* data, sr_channel *probe); LogicSignal(view::LogicSignal*s, pv::data::Logic *data, sr_channel *probe); diff --git a/DSView/pv/view/ruler.cpp b/DSView/pv/view/ruler.cpp index 3ba947d3..693c1c6e 100644 --- a/DSView/pv/view/ruler.cpp +++ b/DSView/pv/view/ruler.cpp @@ -38,6 +38,7 @@ #include #include #include +#include "../appcontrol.h" using namespace std; @@ -194,8 +195,10 @@ void Ruler::paintEvent(QPaintEvent*) QPainter p(this); style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this); + SigSession *session = AppControl::Instance()->GetSession(); + // Draw tick mark - if (_view.session().get_device()->dev_inst()->mode == DSO) + if (session->get_device()->get_work_mode() == DSO) draw_osc_tick_mark(p); else draw_logic_tick_mark(p); @@ -348,6 +351,10 @@ void Ruler::draw_logic_tick_mark(QPainter &p) { using namespace Qt; + if (_view.session().get_device()->have_instance() == false){ + return; + } + const double SpacingIncrement = 32.0; const double MinValueSpacing = 16.0; const int ValueMargin = 5; diff --git a/DSView/pv/view/signal.cpp b/DSView/pv/view/signal.cpp index 34e8374b..b7b92a2f 100644 --- a/DSView/pv/view/signal.cpp +++ b/DSView/pv/view/signal.cpp @@ -23,25 +23,26 @@ #include #include "signal.h" -#include "view.h" -#include "../device/devinst.h" +#include "view.h" #include "../dsvdef.h" +#include "../appcontrol.h" +#include "../sigsession.h" namespace pv { namespace view { -Signal::Signal(DevInst *dev_inst,sr_channel *probe) : +Signal::Signal(sr_channel *probe) : Trace(probe->name, probe->index, probe->type), - _dev_inst(dev_inst), _probe(probe) { + session = AppControl::Instance()->GetSession(); } Signal::Signal(const Signal &s, sr_channel *probe) : - Trace((const Trace &)s), - _dev_inst(s._dev_inst), + Trace((const Trace &)s), _probe(probe) { + session = AppControl::Instance()->GetSession(); } bool Signal::enabled() @@ -55,11 +56,5 @@ void Signal::set_name(QString name) g_free(_probe->name); _probe->name = g_strdup(name.toUtf8().data()); } - -DevInst* Signal::get_device() -{ - return _dev_inst; -} - } // namespace view } // namespace pv diff --git a/DSView/pv/view/signal.h b/DSView/pv/view/signal.h index 3eb1ff33..e6363f5b 100644 --- a/DSView/pv/view/signal.h +++ b/DSView/pv/view/signal.h @@ -43,11 +43,7 @@ namespace data { class SignalData; } -namespace device { -class DevInst; -} - -using namespace pv::device; +class SigSession; namespace view { @@ -60,7 +56,7 @@ private: protected: - Signal(DevInst* dev_inst,sr_channel * const probe); + Signal(sr_channel * const probe); /** * Copy constructor @@ -80,21 +76,11 @@ public: */ void set_name(QString name); - /** - * Paints the signal label into a QGLWidget. - * @param p the QPainter to paint into. - * @param right the x-coordinate of the right edge of the header - * area. - * @param hover true if the label is being hovered over by the mouse. - * @param action mouse position for hover - */ - //virtual void paint_label(QPainter &p, int right, bool hover, int action); + - DevInst* get_device(); - -protected: - DevInst* _dev_inst; +protected: sr_channel *const _probe; + SigSession *session; }; } // namespace view diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 82d063f1..d91f357e 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -103,6 +103,8 @@ View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget _trig_cursor = NULL; _search_cursor = NULL; + _device_agent = session->get_device(); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); // trace viewport map @@ -245,13 +247,15 @@ double View::get_maxscale() void View::capture_init() { - if (_session->get_device()->dev_inst()->mode == DSO) + int mode = _device_agent->get_work_mode(); + + if (mode == DSO) show_trig_cursor(true); else if (!_session->isRepeating()) show_trig_cursor(false); _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); - if (_session->get_device()->dev_inst()->mode == ANALOG) + if (mode == ANALOG) set_scale_offset(_maxscale, 0); status_clear(); _trig_time_setted = false; @@ -281,7 +285,7 @@ double View::get_hori_res() void View::update_hori_res() { - if (_session->get_device()->dev_inst()->mode == DSO) { + if (_device_agent->get_work_mode() == DSO) { _sampling_bar->hori_knob(0); } } @@ -292,7 +296,7 @@ bool View::zoom(double steps, int offset) _preScale = _scale; _preOffset = _offset; - if (_session->get_device()->dev_inst()->mode != DSO) { + if (_device_agent->get_work_mode() != DSO) { _scale *= std::pow(3.0/2.0, -steps); _scale = max(min(_scale, _maxscale), _minscale); } else { @@ -329,7 +333,7 @@ bool View::zoom(double steps, int offset) void View::timebase_changed() { - if (_session->get_device()->dev_inst()->mode != DSO) + if (_device_agent->get_work_mode() != DSO) return; double scale = this->scale(); @@ -479,7 +483,7 @@ void View::repeat_unshow() void View::frame_began() { -// if (_session->get_device()->dev_inst()->mode == LOGIC) +// if (_device_agent->get_work_mode() == LOGIC) // _viewbottom->set_trig_time(_session->get_session_time()); _search_hit = false; _search_pos = 0; @@ -488,7 +492,7 @@ void View::frame_began() void View::set_trig_time() { - if (!_trig_time_setted && _session->get_device()->dev_inst()->mode == LOGIC) { + if (!_trig_time_setted && _device_agent->get_work_mode() == LOGIC) { _session->set_session_time(QDateTime::currentDateTime()); _viewbottom->set_trig_time(_session->get_session_time()); } @@ -502,13 +506,13 @@ bool View::trig_time_setted() void View::receive_end() { - if (_session->get_device()->dev_inst()->mode == LOGIC) { - GVariant *gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_RLE); + if (_device_agent->get_work_mode() == LOGIC) { + GVariant *gvar = _device_agent->get_config(NULL, NULL, SR_CONF_RLE); if (gvar != NULL) { bool rle = g_variant_get_boolean(gvar); g_variant_unref(gvar); if (rle) { - gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_ACTUAL_SAMPLES); + gvar = _device_agent->get_config(NULL, NULL, SR_CONF_ACTUAL_SAMPLES); if (gvar != NULL) { uint64_t actual_samples = g_variant_get_uint64(gvar); g_variant_unref(gvar); @@ -527,8 +531,8 @@ void View::receive_trigger(quint64 trig_pos) const double time = trig_pos * 1.0 / _session->cur_snap_samplerate(); _trig_cursor->set_index(trig_pos); if (ds_trigger_get_en() || - _session->get_device()->name() == "virtual-session" || - _session->get_device()->dev_inst()->mode == DSO) { + _device_agent->name() == "virtual-session" || + _device_agent->get_work_mode() == DSO) { _show_trig_cursor = true; set_scale_offset(_scale, (time / _scale) - (get_view_width() / 2)); } @@ -651,7 +655,7 @@ void View::update_scroll() void View::update_scale_offset() { - if (_session->get_device()->dev_inst()->mode != DSO) { + if (_device_agent->get_work_mode() != DSO) { _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); _minscale = (1.0 / _session->cur_snap_samplerate()) / MaxPixelsPerSample; } else { @@ -675,7 +679,7 @@ void View::update_scale_offset() void View::dev_changed(bool close) { if (!close) { - if (_session->get_device()->name().contains("virtual")) + if (_device_agent->name().contains("virtual")) _scale = WellSamplesPerPixel * 1.0 / _session->cur_snap_samplerate(); _scale = max(min(_scale, _maxscale), _minscale); } @@ -740,13 +744,13 @@ void View::signals_changed() const double height = (_time_viewport->height() - 2 * actualMargin * label_size) * 1.0 / total_rows; - auto dev = _session->get_device(); - assert(dev); - auto ins = dev->dev_inst(); - assert(ins); + if (_device_agent->have_instance() == false){ + assert(false); + } + + if (_device_agent->get_work_mode() == LOGIC) { + GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_MAX_HEIGHT_VALUE); - if (ins->mode == LOGIC) { - GVariant* gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_MAX_HEIGHT_VALUE); if (gvar != NULL) { max_height = (g_variant_get_byte(gvar) + 1) * MaxHeightUnit; g_variant_unref(gvar); @@ -755,16 +759,20 @@ void View::signals_changed() actualMargin /= 2; _signalHeight = max(1.0, (_time_viewport->height() - 2 * actualMargin * label_size) * 1.0 / total_rows); - } else { + } + else { _signalHeight = (height >= max_height) ? max_height : height; } - } else if (_session->get_device()->dev_inst()->mode == DSO) { + } + else if (_device_agent->get_work_mode() == DSO) { _signalHeight = (_header->height() - horizontalScrollBar()->height() - 2 * actualMargin * label_size) * 1.0 / total_rows; - } else { + } + else { _signalHeight = (int)((height <= 0) ? 1 : height); } + _spanY = _signalHeight + 2 * actualMargin; int next_v_offset = actualMargin; @@ -807,7 +815,7 @@ bool View::eventFilter(QObject *object, QEvent *event) double cur_periods = (mouse_event->pos().x() + _offset) * _scale / _ruler->get_min_period(); int integer_x = round(cur_periods) * _ruler->get_min_period() / _scale - _offset; double cur_deviate_x = qAbs(mouse_event->pos().x() - integer_x); - if (_session->get_device()->dev_inst()->mode == LOGIC && + if (_device_agent->get_work_mode() == LOGIC && cur_deviate_x < 10) _hover_point = QPoint(integer_x, mouse_event->pos().y()); else @@ -866,10 +874,10 @@ void View::resizeEvent(QResizeEvent*) update_margins(); update_scroll(); signals_changed(); - if (_session->get_device()->dev_inst()->mode == DSO) + if (_device_agent->get_work_mode() == DSO) _scale = _session->cur_view_time() / get_view_width(); - if (_session->get_device()->dev_inst()->mode != DSO) + if (_device_agent->get_work_mode() != DSO) _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); else _maxscale = 1e9; @@ -1097,7 +1105,7 @@ void View::on_state_changed(bool stop) QRect View::get_view_rect() { - if (_session->get_device()->dev_inst()->mode == DSO) { + if (_device_agent->get_work_mode() == DSO) { const auto &sigs = _session->get_signals(); for(auto &s : sigs) { return s->get_view_rect(); @@ -1110,7 +1118,7 @@ QRect View::get_view_rect() int View::get_view_width() { int view_width = 0; - if (_session->get_device()->dev_inst()->mode == DSO) { + if (_device_agent->get_work_mode() == DSO) { const auto &sigs = _session->get_signals(); for(auto &s : sigs) { view_width = max(view_width, s->get_view_rect().width()); @@ -1125,7 +1133,7 @@ int View::get_view_width() int View::get_view_height() { int view_height = 0; - if (_session->get_device()->dev_inst()->mode == DSO) { + if (_device_agent->get_work_mode() == DSO) { const auto &sigs = _session->get_signals(); for(auto &s : sigs) { view_height = max(view_height, s->get_view_rect().height()); @@ -1154,7 +1162,7 @@ int64_t View::get_max_offset() // -- calibration dialog void View::show_calibration() { - _cali->set_device(_session->get_device()); + _cali->update_device_info(); _cali->show(); } @@ -1166,7 +1174,7 @@ void View::hide_calibration() void View::vDial_updated() { if (_cali->isVisible()) { - _cali->set_device(_session->get_device()); + _cali->update_device_info(); } auto math_trace = _session->get_math_trace(); if (math_trace && math_trace->enabled()) { @@ -1228,7 +1236,7 @@ void View::clear() { show_trig_cursor(false); - if (_session->get_device()->dev_inst()->mode != DSO) { + if (_device_agent->get_work_mode() != DSO) { show_xcursors(false); } else { if (!get_xcursorList().empty()) @@ -1238,7 +1246,7 @@ void View::clear() void View::reconstruct() { - if (_session->get_device()->dev_inst()->mode == DSO) + if (_device_agent->get_work_mode() == DSO) _viewbottom->setFixedHeight(DsoStatusHeight); else _viewbottom->setFixedHeight(StatusHeight); diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index 81b20132..6479a42a 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -43,6 +43,8 @@ #include "viewstatus.h" #include "../dsvdef.h" +class DeviceAgent; + namespace pv { namespace toolbars { @@ -399,6 +401,7 @@ private: bool _show_lissajous; bool _back_ready; bool _trig_time_setted; + DeviceAgent *_device_agent; }; } // namespace view diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 5250a3b3..ac57e3a8 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -164,7 +164,7 @@ void Viewport::paintEvent(QPaintEvent *event) //auto st = _view.session().get_capture_state(); - if (_view.session().get_device()->dev_inst()->mode == LOGIC || + if (_view.session().get_device()->get_work_mode() == LOGIC || _view.session().get_instant()) { switch(_view.session().get_capture_state()) { case SigSession::Init: @@ -206,7 +206,7 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back) { const auto &traces = _view.get_traces(_type); - if (_view.session().get_device()->dev_inst()->mode == LOGIC) { + if (_view.session().get_device()->get_work_mode() == LOGIC) { for(auto &t : traces) { @@ -328,7 +328,7 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back) paintMeasure(p, fore, back); //plot trigger information - if (_view.session().get_device()->dev_inst()->mode == DSO && + if (_view.session().get_device()->get_work_mode() == DSO && _view.session().get_capture_state() == SigSession::Running) { uint8_t type; bool roll = false; @@ -509,9 +509,9 @@ void Viewport::mousePressEvent(QMouseEvent *event) if (_action_type == NO_ACTION && event->button() == Qt::RightButton && _view.session().get_capture_state() == SigSession::Stopped) { - if (_view.session().get_device()->dev_inst()->mode == LOGIC) { + if (_view.session().get_device()->get_work_mode() == LOGIC) { _action_type = LOGIC_ZOOM; - } else if (_view.session().get_device()->dev_inst()->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); @@ -521,7 +521,7 @@ void Viewport::mousePressEvent(QMouseEvent *event) } if (_action_type == NO_ACTION && event->button() == Qt::LeftButton && - _view.session().get_device()->dev_inst()->mode == DSO) { + _view.session().get_device()->get_work_mode() == DSO) { const auto &sigs = _view.session().get_signals(); @@ -677,14 +677,14 @@ void Viewport::mouseMoveEvent(QMouseEvent *event) assert(s); view::LogicSignal *logicSig = NULL; view::DsoSignal *dsoSig = NULL; - if ((_view.session().get_device()->dev_inst()->mode == LOGIC) && + if ((_view.session().get_device()->get_work_mode() == LOGIC) && (logicSig = dynamic_cast(s))) { if (logicSig->measure(event->pos(), index0, index1, index2)) { logic = true; break; } } - if ((_view.session().get_device()->dev_inst()->mode == DSO) && + if ((_view.session().get_device()->get_work_mode() == DSO) && (dsoSig = dynamic_cast(s))) { curX = min(dsoSig->get_view_rect().right(), curX); break; @@ -770,7 +770,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) if ((_action_type == NO_ACTION) && (event->button() == Qt::LeftButton)) { - if (_view.session().get_device()->dev_inst()->mode == LOGIC && + if (_view.session().get_device()->get_work_mode() == LOGIC && _view.session().get_capture_state() == SigSession::Stopped) { //priority 1 //try to quick scroll view... @@ -843,7 +843,7 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) } } } - } else if (_view.session().get_device()->dev_inst()->mode == DSO) { + } else if (_view.session().get_device()->get_work_mode() == DSO) { // priority 0 if (_action_type == NO_ACTION && _hover_hit) { _action_type = DSO_YM; @@ -976,7 +976,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) if (!_view.get_view_rect().contains(event->pos())) return; - if (_view.session().get_device()->dev_inst()->mode == LOGIC && + if (_view.session().get_device()->get_work_mode() == LOGIC && _view.session().get_capture_state() == SigSession::Stopped) { if (event->button() == Qt::RightButton) { if (_view.scale() == _view.get_maxscale()) @@ -987,7 +987,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) bool logic = false; uint64_t index; uint64_t index0 = 0, index1 = 0, index2 = 0; - if (_view.session().get_device()->dev_inst()->mode == LOGIC) { + if (_view.session().get_device()->get_work_mode() == LOGIC) { const auto &sigs = _view.session().get_signals(); for(auto &s : sigs) { assert(s); @@ -1015,7 +1015,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) _view.show_cursors(true); } update(); - } else if (_view.session().get_device()->dev_inst()->mode == DSO && + } else if (_view.session().get_device()->get_work_mode() == DSO && _view.session().get_capture_state() != SigSession::Init && event->button() == Qt::LeftButton) { if (_dso_xm_valid) { @@ -1032,7 +1032,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) break; } } - } else if (_view.session().get_device()->dev_inst()->mode == ANALOG) { + } else if (_view.session().get_device()->get_work_mode() == ANALOG) { if (event->button() == Qt::LeftButton) { uint64_t index; const double curX = event->pos().x(); @@ -1736,7 +1736,7 @@ bool Viewport::get_dso_trig_moved() void Viewport::show_contextmenu(const QPoint& pos) { if(_cmenu && - _view.session().get_device()->dev_inst()->mode == DSO) + _view.session().get_device()->get_work_mode() == DSO) { _cur_preX = pos.x(); _cur_preY = pos.y(); diff --git a/DSView/pv/view/viewstatus.cpp b/DSView/pv/view/viewstatus.cpp index ccd3872a..002d1440 100644 --- a/DSView/pv/view/viewstatus.cpp +++ b/DSView/pv/view/viewstatus.cpp @@ -64,7 +64,7 @@ void ViewStatus::paintEvent(QPaintEvent *) style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); QColor fore(QWidget::palette().color(QWidget::foregroundRole())); - if (_session->get_device()->dev_inst()->mode == LOGIC) { + if (_session->get_device()->get_work_mode() == LOGIC) { fore.setAlpha(View::ForeAlpha); p.setPen(fore); p.drawText(this->rect(), Qt::AlignLeft | Qt::AlignVCenter, _rle_depth); @@ -77,7 +77,7 @@ void ViewStatus::paintEvent(QPaintEvent *) p.setPen(View::Blue); p.drawText(this->rect(), Qt::AlignCenter | Qt::AlignVCenter, _capture_status); - } else if (_session->get_device()->dev_inst()->mode == DSO) { + } else if (_session->get_device()->get_work_mode() == DSO) { fore.setAlpha(View::BackAlpha); for(size_t i = 0; i < _mrects.size(); i++) { int sig_index = std::get<1>(_mrects[i]); @@ -141,7 +141,7 @@ void ViewStatus::reload() const int COLUMN = 5; const int ROW = 2; const int MARGIN = 3; - if (_session->get_device()->dev_inst()->mode == DSO) + if (_session->get_device()->get_work_mode() == DSO) { const double width = _view.get_view_width() * 1.0 / COLUMN; const int height = (this->height() - 2*MARGIN) / ROW; @@ -192,7 +192,7 @@ void ViewStatus::mousePressEvent(QMouseEvent *event) { assert(event); - if (_session->get_device()->dev_inst()->mode != DSO) + if (_session->get_device()->get_work_mode() != DSO) return; if (event->button() == Qt::LeftButton) { @@ -240,7 +240,7 @@ QJsonArray ViewStatus::get_session() void ViewStatus::load_session(QJsonArray measure_array) { - if (_session->get_device()->dev_inst()->mode != DSO || + if (_session->get_device()->get_work_mode() != DSO || measure_array.empty()) return; diff --git a/libsigrok4DSL/dsdevice.c b/libsigrok4DSL/dsdevice.c index f0e6b117..79c455c5 100644 --- a/libsigrok4DSL/dsdevice.c +++ b/libsigrok4DSL/dsdevice.c @@ -78,7 +78,7 @@ SR_PRIV struct sr_channel *sr_channel_new(uint16_t index, int type, * * @since 0.1.0 (but the API changed in 0.2.0) */ -SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi, +SR_PRIV int sr_dev_probe_name_set(const struct sr_dev_inst *sdi, int probenum, const char *name) { GSList *l; @@ -115,7 +115,7 @@ SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi, * * @since 0.2.0 */ -SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum, +SR_PRIV int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum, gboolean state) { GSList *l; @@ -152,7 +152,7 @@ SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum, * * @since 0.1.0 (but the API changed in 0.2.0) */ -SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, uint16_t probenum, +SR_PRIV int sr_dev_trigger_set(const struct sr_dev_inst *sdi, uint16_t probenum, const char *trigger) { GSList *l; diff --git a/libsigrok4DSL/lib_main.c b/libsigrok4DSL/lib_main.c index 27025356..1026db4f 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}; @@ -44,7 +44,6 @@ struct sr_lib_context struct sr_context *sr_ctx; GList *device_list; // All device instance, sr_dev_inst* type pthread_mutex_t mutext; - GThread *hotplug_thread; int lib_exit_flag; int attach_event_flag; int detach_event_flag; @@ -52,12 +51,13 @@ struct sr_lib_context int check_reconnect_times; struct libusb_device *attach_device_handle; struct libusb_device *detach_device_handle; - struct ds_device_info actived_device_info; struct sr_dev_inst *actived_device_instance; int collect_stop_flag; + GThread *hotplug_thread; GThread *collect_thread; ds_datafeed_callback_t data_forward_callback; int callback_thread_count; + int is_delay_destory_actived_device; }; static void hotplug_event_listen_callback(struct libusb_context *ctx, struct libusb_device *dev, int event); @@ -81,16 +81,12 @@ static struct sr_lib_context lib_ctx = { .check_reconnect_times = 0, .attach_device_handle = NULL, .detach_device_handle = NULL, - .actived_device_info = { - .handle = 0, - .name[0] = '\0', - .dev_type = DEV_TYPE_UNKOWN, - }, .actived_device_instance = NULL, .collect_stop_flag = 0, .data_forward_callback = NULL, .collect_thread = NULL, .callback_thread_count = 0, + .is_delay_destory_actived_device = 0, }; /** @@ -173,6 +169,16 @@ SR_API int ds_lib_exit() lib_ctx.hotplug_thread = NULL; } + // The device is not in list. + 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); + lib_ctx.actived_device_instance = NULL; + lib_ctx.is_delay_destory_actived_device = 0; + } + // Release all device for (l = lib_ctx.device_list; l; l = l->next) { @@ -272,8 +278,15 @@ SR_API int ds_get_device_list(struct ds_device_info **out_list, int *out_count) { dev = l->data; p->handle = dev->handle; - strncpy(p->name, dev->name, sizeof(dev->name) - 1); p->dev_type = dev->dev_type; + p->driver_name[0] = '\0'; + p->di = dev; + strncpy(p->name, dev->name, sizeof(p->name) - 1); + + if (dev->driver && dev->driver->name){ + strncpy(p->driver_name, dev->driver->name, sizeof(p->driver_name) - 1); + } + p++; } @@ -319,12 +332,16 @@ SR_API int ds_active_device(ds_device_handle handle) if (lib_ctx.actived_device_instance != NULL) { - sr_info("Close the previous device \"%s\"", lib_ctx.actived_device_instance->name); - - close_device_instance(lib_ctx.actived_device_instance); - lib_ctx.actived_device_instance = NULL; - lib_ctx.actived_device_info.handle = NULL_HANDLE; - lib_ctx.actived_device_info.name[0] = '\0'; + 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{ + sr_info("Close the previous device \"%s\"", lib_ctx.actived_device_instance->name); + close_device_instance(lib_ctx.actived_device_instance); + } } // To open the new. @@ -335,18 +352,13 @@ 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) - { - lib_ctx.actived_device_info.handle = dev->handle; - lib_ctx.actived_device_info.dev_type = dev->dev_type; - strncpy(lib_ctx.actived_device_info.name, dev->name, sizeof(lib_ctx.actived_device_info.name) - 1); + if (open_device_instance(dev) == SR_OK){ lib_ctx.actived_device_instance = dev; } else @@ -455,6 +467,14 @@ SR_API int ds_have_actived_device() return 0; } +/** + * Create a device from session file, and will auto load the data. + */ +SR_API int ds_device_from_file(const char *file_path) +{ + return SR_OK; +} + /** * Get the decive supports work mode, mode list: LOGIC、ANALOG、DSO * return type see struct sr_dev_mode. @@ -485,22 +505,29 @@ SR_API int ds_remove_device(ds_device_handle handle) { GList *l; struct sr_dev_inst *dev; - struct sr_dev_inst *di; - int bFind = 0; - - di = lib_ctx.actived_device_instance; + int bFind = 0; if (handle == NULL_HANDLE) - { return SR_ERR_ARG; - } - if (di != NULL && di->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) + { + 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; + } + pthread_mutex_lock(&lib_ctx.mutext); for (l = lib_ctx.device_list; l; l = l->next) @@ -510,15 +537,9 @@ 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; } - if (lib_ctx.actived_device_info.handle == dev->handle) - { - lib_ctx.actived_device_info.handle = NULL_HANDLE; - lib_ctx.actived_device_info.name[0] = '\0'; - } destroy_device_instance(dev); bFind = 1; @@ -528,9 +549,8 @@ SR_API int ds_remove_device(ds_device_handle handle) pthread_mutex_unlock(&lib_ctx.mutext); if (bFind == 0) - { return SR_ERR_CALL_STATUS; - } + return SR_OK; } @@ -540,24 +560,42 @@ SR_API int ds_remove_device(ds_device_handle handle) */ 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; - } - fill_info->handle = NULL_HANDLE; - fill_info->name[0] = '\0'; - fill_info->dev_type = DEV_TYPE_UNKOWN; + ret = SR_ERR_CALL_STATUS; - if (lib_ctx.actived_device_info.handle != NULL_HANDLE) + p = fill_info; + + p->handle = NULL_HANDLE; + p->name[0] = '\0'; + p->driver_name[0] = '\0'; + p->dev_type = DEV_TYPE_UNKOWN; + p->di = NULL; + + pthread_mutex_lock(&lib_ctx.mutext); + + dev = lib_ctx.actived_device_instance; + if (dev != NULL) { - fill_info->handle = lib_ctx.actived_device_info.handle; - strncpy(fill_info->name, lib_ctx.actived_device_info.name, sizeof(fill_info->name)); - fill_info->dev_type = lib_ctx.actived_device_info.dev_type; - return SR_OK; + p->handle = dev->handle; + p->dev_type = dev->dev_type; + p->di = dev; + strncpy(p->name, dev->name, sizeof(p->name) - 1); + + if (dev->driver && dev->driver->name){ + strncpy(p->driver_name, dev->driver->name, sizeof(p->driver_name) - 1); + } + ret = SR_OK; } - return SR_ERR_CALL_STATUS; + pthread_mutex_unlock(&lib_ctx.mutext); + + return ret; } /** @@ -737,7 +775,7 @@ SR_API int ds_get_actived_device_config(const struct sr_channel *ch, 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, @@ -826,6 +864,22 @@ SR_API int ds_enable_device_channel(const struct sr_channel *ch, gboolean enable return sr_enable_device_channel(lib_ctx.actived_device_instance, ch, enable); } +SR_API int ds_enable_device_channel_index(int ch_index, gboolean enable) +{ + 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); +} + +SR_API int ds_set_device_channel_name(int ch_index, const char *name) +{ + 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); +} + /** * check that at least one probe is enabled */ @@ -1129,16 +1183,18 @@ static void process_attach_event() } static void process_detach_event() -{ - libusb_device *ev_dev; - int ev = DS_EV_INACTIVE_DEVICE_DETACH; +{ GList *l; struct sr_dev_inst *dev; struct sr_dev_driver *driver_ins; + libusb_device *ev_dev; + int ev; sr_info("%s", "Process device detach event."); + ev = DS_EV_INACTIVE_DEVICE_DETACH; ev_dev = lib_ctx.detach_device_handle; + if (ev_dev == NULL) { sr_err("%s", "The detached device handle is null."); @@ -1154,25 +1210,27 @@ static void process_detach_event() if (dev->handle == (ds_device_handle)ev_dev) { - if (lib_ctx.actived_device_instance != dev && ds_is_collecting()){ + 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. - lib_ctx.device_list = g_slist_remove(lib_ctx.device_list, l->data); - destroy_device_instance(dev); - if (dev == lib_ctx.actived_device_instance) - { - lib_ctx.actived_device_instance = NULL; + // Found the device, and remove it from list. + lib_ctx.device_list = g_slist_remove(lib_ctx.device_list, l->data); + + 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{ + destroy_device_instance(dev); } + break; } } - pthread_mutex_unlock(&lib_ctx.mutext); - - if (ev_dev == lib_ctx.actived_device_info.handle) - ev = DS_EV_CURRENT_DEVICE_DETACH; + pthread_mutex_unlock(&lib_ctx.mutext); // Tell user a new device detached, and the list is updated. post_event_async(ev); diff --git a/libsigrok4DSL/libsigrok-internal.h b/libsigrok4DSL/libsigrok-internal.h index 8eb502af..15ba99a5 100644 --- a/libsigrok4DSL/libsigrok-internal.h +++ b/libsigrok4DSL/libsigrok-internal.h @@ -227,6 +227,15 @@ SR_PRIV void sr_dev_probes_free(struct sr_dev_inst *sdi); SR_PRIV int sr_enable_device_channel(struct sr_dev_inst *sdi, const struct sr_channel *probe, gboolean enable); +SR_PRIV int sr_dev_probe_name_set(const struct sr_dev_inst *sdi, + int probenum, const char *name); + +SR_PRIV int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum, + gboolean state); + +SR_PRIV int sr_dev_trigger_set(const struct sr_dev_inst *sdi, uint16_t probenum, + const char *trigger); + /* Generic device instances */ SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int mode, int index, int status, const char *vendor, const char *model, const char *version); diff --git a/libsigrok4DSL/libsigrok.h b/libsigrok4DSL/libsigrok.h index a97c1049..b9733c68 100644 --- a/libsigrok4DSL/libsigrok.h +++ b/libsigrok4DSL/libsigrok.h @@ -1173,15 +1173,7 @@ struct ds_trigger_pos { * * Header file containing API function prototypes. */ - -/*--- device.c --------------------------------------------------------------*/ - -SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi, - int probenum, const char *name); -SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum, - gboolean state); -SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, uint16_t probenum, - const char *trigger); + /*--- input/input.c ---------------------------------------------------------*/ @@ -1273,7 +1265,9 @@ struct ds_device_info { ds_device_handle handle; char name[50]; + char driver_name[20]; int dev_type; // enum sr_device_type + struct sr_dev_inst *di; }; struct ds_task_progress @@ -1423,6 +1417,10 @@ 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); +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); + /** * heck that at least one probe is enabled */