From 365dc84b7eda7d25638649c5a43c5ff0cd02d7a5 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Mon, 26 Sep 2022 17:43:57 +0800 Subject: [PATCH] Code refactoring 22 --- DSView/pv/device/device.cpp | 99 ---------- DSView/pv/device/device.h | 54 ----- DSView/pv/device/devinst.cpp | 226 --------------------- DSView/pv/device/devinst.h | 148 -------------- DSView/pv/device/file.cpp | 129 ------------ DSView/pv/device/file.h | 58 ------ DSView/pv/device/inputfile.cpp | 139 ------------- DSView/pv/device/inputfile.h | 69 ------- DSView/pv/device/sessionfile.cpp | 85 -------- DSView/pv/device/sessionfile.h | 48 ----- DSView/pv/deviceagent.cpp | 7 +- DSView/pv/deviceagent.h | 5 + DSView/pv/dialogs/calibration.h | 4 - DSView/pv/dialogs/deviceoptions.h | 3 - DSView/pv/dialogs/dsomeasure.cpp | 1 - DSView/pv/dialogs/fftoptions.h | 2 - DSView/pv/dialogs/lissajousoptions.cpp | 1 - DSView/pv/dialogs/mathoptions.cpp | 1 - DSView/pv/dialogs/protocolexp.h | 1 - DSView/pv/dialogs/protocollist.h | 1 - DSView/pv/dialogs/regionoptions.cpp | 1 - DSView/pv/dialogs/search.h | 1 - DSView/pv/dialogs/waitingdialog.h | 3 - DSView/pv/dock/dsotriggerdock.cpp | 1 - DSView/pv/dock/measuredock.cpp | 2 - DSView/pv/dock/protocoldock.cpp | 1 - DSView/pv/dock/searchdock.cpp | 1 - DSView/pv/dock/triggerdock.cpp | 1 - DSView/pv/mainwindow.cpp | 261 ++++++++++++++++--------- DSView/pv/mainwindow.h | 7 +- DSView/pv/sigsession.cpp | 12 +- DSView/pv/sigsession.h | 3 +- DSView/pv/storesession.cpp | 1 - DSView/pv/toolbars/filebar.cpp | 1 - DSView/pv/toolbars/samplingbar.cpp | 17 +- DSView/pv/toolbars/samplingbar.h | 12 +- DSView/pv/toolbars/trigbar.cpp | 1 - DSView/pv/view/analogsignal.cpp | 1 - DSView/pv/view/cursor.cpp | 1 - DSView/pv/view/decodetrace.cpp | 1 - DSView/pv/view/devmode.cpp | 4 +- DSView/pv/view/header.cpp | 1 - DSView/pv/view/lissajoustrace.cpp | 1 - DSView/pv/view/mathtrace.cpp | 1 - DSView/pv/view/ruler.cpp | 1 - DSView/pv/view/spectrumtrace.cpp | 1 - DSView/pv/view/timemarker.cpp | 1 - DSView/pv/view/trace.cpp | 1 - DSView/pv/view/view.cpp | 1 - DSView/pv/view/viewport.cpp | 1 - DSView/pv/view/viewstatus.cpp | 1 - DSView/pv/view/xcursor.cpp | 1 - libsigrok4DSL/lib_main.c | 22 +-- libsigrok4DSL/libsigrok.h | 13 +- libsigrok4DSL/session.c | 2 +- 55 files changed, 228 insertions(+), 1234 deletions(-) delete mode 100644 DSView/pv/device/device.cpp delete mode 100644 DSView/pv/device/device.h delete mode 100644 DSView/pv/device/devinst.cpp delete mode 100644 DSView/pv/device/devinst.h delete mode 100644 DSView/pv/device/file.cpp delete mode 100644 DSView/pv/device/file.h delete mode 100644 DSView/pv/device/inputfile.cpp delete mode 100644 DSView/pv/device/inputfile.h delete mode 100644 DSView/pv/device/sessionfile.cpp delete mode 100644 DSView/pv/device/sessionfile.h diff --git a/DSView/pv/device/device.cpp b/DSView/pv/device/device.cpp deleted file mode 100644 index ca6a4ad9..00000000 --- a/DSView/pv/device/device.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include - -#include "device.h" - -using std::ostringstream; -using std::string; - -namespace pv { -namespace device { - -Device::Device(sr_dev_inst *sdi) : - _sdi(sdi) -{ - assert(_sdi); -} - -Device::~Device() -{ - -} - -sr_dev_inst* Device::dev_inst() -{ - return _sdi; -} - -void Device::use(SigSession *owner) -{ - DevInst::use(owner); - - sr_session_new(); - sr_dev_open(_sdi); - - _usable = (_sdi->status == SR_ST_ACTIVE); - if (sr_session_dev_add(_sdi) != SR_OK) - throw QString(tr("Failed to use device.")); -} - -void Device::release() -{ - if (_owner) { - DevInst::release(); - sr_session_destroy(); - } - - sr_dev_close(_sdi); -} - -QString Device::format_device_title() -{ - ostringstream s; - - if (_sdi->model && _sdi->model[0]) { - s << _sdi->model; - if (_sdi->version && _sdi->version[0]) - s << ' '; - } - - if (_sdi->version && _sdi->version[0]) - s << _sdi->version; - - return QString::fromStdString(s.str()); -} - -bool Device::is_trigger_enabled() -{ - for (const GSList *l = _sdi->channels; l; l = l->next) { - const sr_channel *const p = (const sr_channel *)l->data; - assert(p); - if (p->trigger && p->trigger[0] != '\0') - return true; - } - return false; -} - -} // device -} // pv diff --git a/DSView/pv/device/device.h b/DSView/pv/device/device.h deleted file mode 100644 index 0290f5a2..00000000 --- a/DSView/pv/device/device.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef DSVIEW_PV_DEVICE_DEVICE_H -#define DSVIEW_PV_DEVICE_DEVICE_H - -#include "devinst.h" - -namespace pv { -namespace device { - -class Device : public DevInst -{ -public: - Device(sr_dev_inst *dev_inst); - - ~Device(); - - sr_dev_inst* dev_inst(); - - void use(SigSession *owner); - - void release(); - - QString format_device_title(); - - bool is_trigger_enabled(); - -private: - sr_dev_inst *const _sdi; -}; - -} // device -} // pv - -#endif // DSVIEW_PV_DEVICE_DEVICE_H diff --git a/DSView/pv/device/devinst.cpp b/DSView/pv/device/devinst.cpp deleted file mode 100644 index 1545cc32..00000000 --- a/DSView/pv/device/devinst.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include "devinst.h" -#include "../sigsession.h" -#include "../log.h" - -namespace pv { -namespace device { - -DevInst::DevInst() : - _owner(NULL), - _usable(true) -{ - _id = malloc(1); - _is_file = false; -} - -DevInst::~DevInst() -{ - assert(_id); - free(_id); -} - -void* DevInst::get_id() -{ - assert(_id); - - return _id; -} - -void DevInst::use(SigSession *owner) -{ - assert(owner); - _owner = owner; -} - -void DevInst::release() -{ - if (_owner) { - _owner->release_device(this); - } -} - -SigSession* DevInst::owner() -{ - return _owner; -} - -GVariant* DevInst::get_config(const sr_channel *ch, const sr_channel_group *group, int key) -{ - GVariant *data = NULL; - assert(_owner); - sr_dev_inst *const sdi = dev_inst(); - assert(sdi); - if (sr_config_get(sdi->driver, sdi, ch, group, key, &data) != SR_OK) - return NULL; - return data; -} - -bool DevInst::set_config(sr_channel *ch, sr_channel_group *group, int key, GVariant *data) -{ - assert(_owner); - sr_dev_inst *const sdi = dev_inst(); - assert(sdi); - if(sr_config_set(sdi, ch, group, key, data) == SR_OK) { - config_changed(); - return true; - } - return false; -} - -GVariant* DevInst::list_config(const sr_channel_group *group, int key) -{ - GVariant *data = NULL; - assert(_owner); - sr_dev_inst *const sdi = dev_inst(); - assert(sdi); - if (sr_config_list(sdi->driver, sdi, group, key, &data) != SR_OK) - return NULL; - return data; -} - -void DevInst::enable_probe(const sr_channel *probe, bool enable) -{ - assert(_owner); - sr_dev_inst *const sdi = dev_inst(); - assert(sdi); - for (const GSList *p = sdi->channels; p; p = p->next) - if (probe == p->data) { - const_cast(probe)->enabled = enable; - config_changed(); - return; - } - - // Probe was not found in the device - assert(0); -} - -uint64_t DevInst::get_sample_limit() -{ - uint64_t sample_limit; - GVariant* gvar = get_config(NULL, NULL, SR_CONF_LIMIT_SAMPLES); - if (gvar != NULL) { - sample_limit = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } else { - sample_limit = 0U; - } - return sample_limit; -} - -uint64_t DevInst::get_sample_rate() -{ - uint64_t sample_rate; - GVariant* gvar = get_config(NULL, NULL, SR_CONF_SAMPLERATE); - if (gvar != NULL) { - sample_rate = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } else { - sample_rate = 0U; - } - return sample_rate; -} - -uint64_t DevInst::get_time_base() -{ - uint64_t time_base; - GVariant* gvar = get_config(NULL, NULL, SR_CONF_TIMEBASE); - if (gvar != NULL) { - time_base = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } else { - time_base = 0U; - } - return time_base; -} - - -double DevInst::get_sample_time() -{ - uint64_t sample_rate = get_sample_rate(); - uint64_t sample_limit = get_sample_limit(); - double sample_time; - - if (sample_rate == 0) - sample_time = 0; - else - sample_time = sample_limit * 1.0 / sample_rate; - - return sample_time; -} - -const GSList* DevInst::get_dev_mode_list() -{ - assert(_owner); - sr_dev_inst *const sdi = dev_inst(); - assert(sdi); - return sr_dev_mode_list(sdi); -} - -QString DevInst::name() -{ - sr_dev_inst *const sdi = dev_inst(); - assert(sdi); - return QString::fromLocal8Bit(sdi->driver->name); -} - -bool DevInst::is_trigger_enabled() -{ - return false; -} - -void DevInst::start() -{ - if (sr_session_start() != SR_OK) - throw tr("Failed to start session."); - //assert(false); -} - -void DevInst::run() -{ - dsv_info("%s", "session run loop start"); - int ret = sr_session_run(); - if (ret != SR_OK){ - dsv_err("%s", "start session error!"); - } - dsv_info("%s", "session run loop end"); -} - -void DevInst::stop() -{ - sr_session_stop(); -} - -bool DevInst::is_usable() -{ - return _usable; -} - -void DevInst::destroy(){ - release(); - //delete this; //do not to destroy -} - -} // device -} // pv diff --git a/DSView/pv/device/devinst.h b/DSView/pv/device/devinst.h deleted file mode 100644 index 9597eea4..00000000 --- a/DSView/pv/device/devinst.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef DSVIEW_PV_DEVICE_DEVINST_H -#define DSVIEW_PV_DEVICE_DEVINST_H - -#include -#include -#include -#include -#include - -struct sr_dev_inst; -struct sr_channel; -struct sr_channel_group; - -namespace pv { - -class SigSession; - -namespace device { - -class DevInst : public QObject -{ - Q_OBJECT - -protected: - DevInst(); - - virtual ~DevInst(); - -public: - SigSession* owner(); - - 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); - - void enable_probe(const sr_channel *probe, bool enable = true); - - /** - * @brief Gets the sample limit from the driver. - * - * @return The returned sample limit from the driver, or 0 if the - * sample limit could not be read. - */ - uint64_t get_sample_limit(); - - /** - * @brief Gets the sample rate from the driver. - * - * @return The returned sample rate from the driver, or 0 if the - * sample rate could not be read. - */ - uint64_t get_sample_rate(); - - /** - * @brief Gets the sample time from the driver. - * - * @return The returned sample time from the driver, or 0 if the - * sample time could not be read. - */ - double get_sample_time(); - - /** - * @brief Gets the time base from the driver. - * - * @return The returned time base from the driver, or 0 if the - * time base could not be read. - */ - uint64_t get_time_base(); - - /** - * @brief Gets the device mode list from the driver. - * - * @return The returned device mode list from the driver, or NULL if the - * mode list could not be read. - */ - const GSList *get_dev_mode_list(); - - /** - * @brief Get the device name from the driver - * - * @return device name - */ - QString name(); - - bool is_usable(); - void destroy(); - - inline bool is_file(){ - return _is_file; - } - -public: - virtual void start(); - - virtual void run(); - - virtual void stop(); - - virtual void* get_id(); - - virtual sr_dev_inst* dev_inst() = 0; - - virtual void use(SigSession *owner); - - virtual void release(); - - virtual bool is_trigger_enabled(); - - virtual QString format_device_title() = 0; - -signals: - void device_updated(); - void config_changed(); - -protected: - SigSession *_owner; - void *_id; - bool _usable; - bool _is_file; -}; - -} // device -} // pv - -#endif // DSVIEW_PV_DEVICE_DEVINST_H diff --git a/DSView/pv/device/file.cpp b/DSView/pv/device/file.cpp deleted file mode 100644 index f2dd17ce..00000000 --- a/DSView/pv/device/file.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "file.h" -#include "inputfile.h" -#include "sessionfile.h" - -#include -#include -#include "../utility/path.h" -#include -#include "../ZipMaker.h" -#include "../log.h" - -namespace pv { -namespace device { - -File::File(QString path) -:_path(path) -{ -} - -File::~File(){ - -} - -QString File::format_device_title() -{ - QFileInfo fi(_path); - return fi.fileName(); -} - -File* File::create(QString name) -{ - auto f_name = path::ConvertPath(name); - - if (sr_session_load(f_name.c_str()) == SR_OK) { - GSList *devlist = NULL; - sr_session_dev_list(&devlist); - sr_session_destroy(); - - if (devlist) { - sr_dev_inst *const sdi = (sr_dev_inst*)devlist->data; - g_slist_free(devlist); - if (sdi) { - sr_dev_close(sdi); - sr_dev_clear(sdi->driver); - return new SessionFile(name); - } - } - } - - return new InputFile(name); -} - -QJsonArray File::get_decoders() -{ - QJsonArray dec_array; - QJsonParseError error; - - /* read "decoders" */ - auto f_name = path::ConvertPath(_path); - ZipReader rd(f_name.c_str()); - auto *data = rd.GetInnterFileData("decoders"); - - if (data != NULL){ - QByteArray raw_bytes = QByteArray::fromRawData(data->data(), data->size()); - QString jsonStr(raw_bytes.data()); - QByteArray qbs = jsonStr.toUtf8(); - QJsonDocument sessionDoc = QJsonDocument::fromJson(qbs, &error); - - if (error.error != QJsonParseError::NoError){ - QString estr = error.errorString(); - dsv_err("File::get_decoders(), parse json error:\"%s\"!", estr.toUtf8().data()); - } - - dec_array = sessionDoc.array(); - rd.ReleaseInnerFileData(data); - } - - return dec_array; -} - -QJsonDocument File::get_session() -{ - QJsonDocument sessionDoc; - QJsonParseError error; - - auto f_name = path::ConvertPath(_path); - ZipReader rd(f_name.c_str()); - auto *data = rd.GetInnterFileData("session"); - - if (data != NULL){ - QByteArray raw_bytes = QByteArray::fromRawData(data->data(), data->size()); - QString jsonStr(raw_bytes.data()); - QByteArray qbs = jsonStr.toUtf8(); - sessionDoc = QJsonDocument::fromJson(qbs, &error); - - if (error.error != QJsonParseError::NoError){ - QString estr = error.errorString(); - dsv_err("File::get_session(), parse json error:\"%s\"!", estr.toUtf8().data()); - } - - rd.ReleaseInnerFileData(data); - } - - return sessionDoc; -} - -} // device -} // pv diff --git a/DSView/pv/device/file.h b/DSView/pv/device/file.h deleted file mode 100644 index 15ea77c0..00000000 --- a/DSView/pv/device/file.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef DSVIEW_PV_DEVICE_FILE_H -#define DSVIEW_PV_DEVICE_FILE_H - -#include -#include -#include -#include - -#include "devinst.h" - -namespace pv { -namespace device { - -class File : public DevInst -{ - -protected: - File(QString path); - -public: - ~File(); - - static File* create(QString name); - QJsonArray get_decoders(); - QJsonDocument get_session(); - -public: - QString format_device_title(); - -protected: - const QString _path; -}; - -} // device -} // pv - -#endif // DSVIEW_PV_DEVICE_FILE_H diff --git a/DSView/pv/device/inputfile.cpp b/DSView/pv/device/inputfile.cpp deleted file mode 100644 index 3cb91f87..00000000 --- a/DSView/pv/device/inputfile.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include - -#include "inputfile.h" - -using std::string; - -namespace pv { -namespace device { - -InputFile::InputFile(QString path) : - File(path), - _input(NULL) -{ - _is_file = true; -} - -sr_dev_inst* InputFile::dev_inst() -{ - assert(_input); - return _input->sdi; -} - -void InputFile::use(SigSession *owner) -{ - (void)owner; - assert(!_input); - - // only *.dsl file is valid - // don't allow other types of file input - throw tr("Not a valid DSView data file."); - return; -} - -void InputFile::release() -{ - if (!_owner) - return; - - assert(_input); - File::release(); - sr_dev_close(_input->sdi); - sr_session_destroy(); - _input = NULL; -} - -sr_input_format* InputFile::determine_input_file_format(const QString filename) -{ - int i; - - /* If there are no input formats, return NULL right away. */ - sr_input_format *const *const inputs = sr_input_list(); - if (!inputs) { - g_critical("No supported input formats available."); - return NULL; - } - - /* Otherwise, try to find an input module that can handle this file. */ - for (i = 0; inputs[i]; i++) { - if (inputs[i]->format_match(filename.toUtf8().data())) - break; - } - - /* Return NULL if no input module wanted to touch this. */ - if (!inputs[i]) { - g_critical("Error: no matching input module found."); - return NULL; - } - - return inputs[i]; -} - -sr_input* InputFile::load_input_file_format(const QString filename, - sr_input_format *format) -{ - struct stat st; - sr_input *in; - - if (!format && !(format = - determine_input_file_format(filename))) { - /* The exact cause was already logged. */ - throw tr("Failed to load file"); - } - - if (stat(filename.toUtf8().data(), &st) == -1) - throw tr("Failed to load file"); - - /* Initialize the input module. */ - if (!(in = new sr_input)) { - throw tr("Failed to allocate input module."); - } - - in->format = format; - in->param = NULL; - if (in->format->init && - in->format->init(in, filename.toUtf8().data()) != SR_OK) { - throw tr("Failed to load file"); - } - - return in; -} - -void InputFile::start() -{ -} - -void InputFile::run() -{ - assert(_input); - assert(_input->format); - assert(_input->format->loadfile); - _input->format->loadfile(_input, _path.toUtf8().data()); -} - -} // device -} // pv diff --git a/DSView/pv/device/inputfile.h b/DSView/pv/device/inputfile.h deleted file mode 100644 index c7e6a50d..00000000 --- a/DSView/pv/device/inputfile.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef DSVIEW_PV_DEVICE_INPUTFILE_H -#define DSVIEW_PV_DEVICE_INPUTFILE_H - -#include "file.h" - -#include - -struct sr_input; -struct sr_input_format; - -namespace pv { -namespace device { - -class InputFile : public File -{ -public: - InputFile(QString path); - - sr_dev_inst* dev_inst(); - - virtual void use(SigSession *owner); - - virtual void release(); - - virtual void start(); - - virtual void run(); - -private: - /** - * Attempts to autodetect the format. Failing that - * @param filename The filename of the input file. - * @return A pointer to the 'struct sr_input_format' that should be used, - * or NULL if no input format was selected or auto-detected. - */ - static sr_input_format* determine_input_file_format( - const QString filename); - - static sr_input* load_input_file_format(const QString filename, - sr_input_format *format); -private: - sr_input *_input; -}; - -} // device -} // pv - -#endif // DSVIEW_PV_DEVICE_INPUTFILE_H diff --git a/DSView/pv/device/sessionfile.cpp b/DSView/pv/device/sessionfile.cpp deleted file mode 100644 index b2602bd1..00000000 --- a/DSView/pv/device/sessionfile.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "sessionfile.h" -#include -#include "../utility/path.h" - -namespace pv { -namespace device { - -SessionFile::SessionFile(QString path) : - File(path) -{ - _sdi = NULL; - _is_file = true; -} - -sr_dev_inst* SessionFile::dev_inst() -{ - return _sdi; -} - -void SessionFile::use(SigSession *owner) -{ - if (_sdi){ - release_source(); - } - - auto f_name = path::ConvertPath(_path); - - if (sr_session_load(f_name.c_str()) != SR_OK) - throw tr("Failed to open file.\n"); - - GSList *devlist = NULL; - sr_session_dev_list(&devlist); - - if (!devlist || !devlist->data) { - if (devlist) - g_slist_free(devlist); - throw tr("Failed to start session."); - } - - _sdi = (sr_dev_inst*)devlist->data; - g_slist_free(devlist); - - File::use(owner); -} - -void SessionFile::release() -{ - release_source(); - File::release(); -} - -void SessionFile::release_source() -{ - if (_sdi != NULL) - { - sr_dev_close(_sdi); - sr_dev_clear(_sdi->driver); - sr_session_destroy(); - _sdi = NULL; - } -} - -} // device -} // pv diff --git a/DSView/pv/device/sessionfile.h b/DSView/pv/device/sessionfile.h deleted file mode 100644 index e64c727c..00000000 --- a/DSView/pv/device/sessionfile.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the DSView project. - * DSView is based on PulseView. - * - * Copyright (C) 2014 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef DSVIEW_PV_DEVICE_SESSIONFILE_H -#define DSVIEW_PV_DEVICE_SESSIONFILE_H - -#include "file.h" - -namespace pv { -namespace device { - -class SessionFile : public File -{ -public: - SessionFile(QString path); - sr_dev_inst* dev_inst(); - virtual void use(SigSession *owner); - virtual void release(); - -private: - void release_source(); - -private: - sr_dev_inst *_sdi; -}; - -} // device -} // pv - -#endif // DSVIEW_PV_DEVICE_SESSIONFILE_H diff --git a/DSView/pv/deviceagent.cpp b/DSView/pv/deviceagent.cpp index 06c21a2a..f4f9a331 100644 --- a/DSView/pv/deviceagent.cpp +++ b/DSView/pv/deviceagent.cpp @@ -37,10 +37,11 @@ void DeviceAgent::update() { _dev_handle = NULL; _dev_name = ""; + _path = ""; _di = NULL; _dev_type = 0; - ds_device_info info; + struct ds_device_full_info info; if (ds_get_actived_device_info(&info) == SR_OK) { @@ -50,6 +51,10 @@ void DeviceAgent::update() _dev_name = QString::fromLocal8Bit(info.name); _driver_name = QString::fromLocal8Bit(info.driver_name); + if (info.path[0] != '\0'){ + _path = QString::fromLocal8Bit(info.path); + } + if (is_in_history(_dev_handle) == false){ _is_new_device = true; } diff --git a/DSView/pv/deviceagent.h b/DSView/pv/deviceagent.h index 73ec5fe3..38544375 100644 --- a/DSView/pv/deviceagent.h +++ b/DSView/pv/deviceagent.h @@ -49,6 +49,10 @@ public: return _dev_name; } + inline QString path(){ + return _path; + } + inline QString driver_name(){ return _driver_name; } @@ -183,6 +187,7 @@ private: int _dev_type; QString _dev_name; QString _driver_name; + QString _path; bool _is_new_device; struct sr_dev_inst *_di; std::vector _history_handles; diff --git a/DSView/pv/dialogs/calibration.h b/DSView/pv/dialogs/calibration.h index 5c4792e2..4bbdbf46 100644 --- a/DSView/pv/dialogs/calibration.h +++ b/DSView/pv/dialogs/calibration.h @@ -30,13 +30,9 @@ #include #include - -#include "../device/devinst.h" #include "../toolbars/titlebar.h" #include "dsdialog.h" -using namespace pv::device; - class DeviceAgent; namespace pv { diff --git a/DSView/pv/dialogs/deviceoptions.h b/DSView/pv/dialogs/deviceoptions.h index cef04982..f745a605 100644 --- a/DSView/pv/dialogs/deviceoptions.h +++ b/DSView/pv/dialogs/deviceoptions.h @@ -38,7 +38,6 @@ #include #include #include -#include "../device/devinst.h" #include "../prop/binding/deviceoptions.h" #include "../prop/binding/probeoptions.h" #include "../toolbars/titlebar.h" @@ -71,8 +70,6 @@ private: int _index; }; -using namespace pv::device; - class DeviceAgent; namespace pv { diff --git a/DSView/pv/dialogs/dsomeasure.cpp b/DSView/pv/dialogs/dsomeasure.cpp index 8d62bb76..bf9f2a0a 100644 --- a/DSView/pv/dialogs/dsomeasure.cpp +++ b/DSView/pv/dialogs/dsomeasure.cpp @@ -20,7 +20,6 @@ */ #include "dsomeasure.h" -#include "../device/devinst.h" #include "../sigsession.h" #include "../view/view.h" diff --git a/DSView/pv/dialogs/fftoptions.h b/DSView/pv/dialogs/fftoptions.h index 631713bf..9fe526b6 100644 --- a/DSView/pv/dialogs/fftoptions.h +++ b/DSView/pv/dialogs/fftoptions.h @@ -29,8 +29,6 @@ #include #include - -#include "../device/devinst.h" #include "../toolbars/titlebar.h" #include "dsdialog.h" #include "../ui/dscombobox.h" diff --git a/DSView/pv/dialogs/lissajousoptions.cpp b/DSView/pv/dialogs/lissajousoptions.cpp index 2ae27886..aebe2a01 100644 --- a/DSView/pv/dialogs/lissajousoptions.cpp +++ b/DSView/pv/dialogs/lissajousoptions.cpp @@ -20,7 +20,6 @@ */ #include "lissajousoptions.h" -#include "../device/devinst.h" #include "../sigsession.h" #include "../view/view.h" #include "../view/lissajoustrace.h" diff --git a/DSView/pv/dialogs/mathoptions.cpp b/DSView/pv/dialogs/mathoptions.cpp index afc2e9f9..e2d93602 100644 --- a/DSView/pv/dialogs/mathoptions.cpp +++ b/DSView/pv/dialogs/mathoptions.cpp @@ -20,7 +20,6 @@ */ #include "mathoptions.h" -#include "../device/devinst.h" #include "../sigsession.h" #include "../view/view.h" #include "../view/mathtrace.h" diff --git a/DSView/pv/dialogs/protocolexp.h b/DSView/pv/dialogs/protocolexp.h index 7789d6c0..781c2add 100644 --- a/DSView/pv/dialogs/protocolexp.h +++ b/DSView/pv/dialogs/protocolexp.h @@ -30,7 +30,6 @@ #include #include -#include "../device/devinst.h" #include "../prop/binding/deviceoptions.h" #include "../toolbars/titlebar.h" #include "dsdialog.h" diff --git a/DSView/pv/dialogs/protocollist.h b/DSView/pv/dialogs/protocollist.h index 879787c0..1357d38f 100644 --- a/DSView/pv/dialogs/protocollist.h +++ b/DSView/pv/dialogs/protocollist.h @@ -29,7 +29,6 @@ #include #include -#include "../device/devinst.h" #include "../prop/binding/deviceoptions.h" #include "../toolbars/titlebar.h" #include "dsdialog.h" diff --git a/DSView/pv/dialogs/regionoptions.cpp b/DSView/pv/dialogs/regionoptions.cpp index 303d67b8..3b4dd983 100644 --- a/DSView/pv/dialogs/regionoptions.cpp +++ b/DSView/pv/dialogs/regionoptions.cpp @@ -24,7 +24,6 @@ #include "../sigsession.h" #include "../view/cursor.h" #include "../view/view.h" -#include "../device/devinst.h" using namespace boost; using namespace std; diff --git a/DSView/pv/dialogs/search.h b/DSView/pv/dialogs/search.h index d848dfc0..ff79bfba 100644 --- a/DSView/pv/dialogs/search.h +++ b/DSView/pv/dialogs/search.h @@ -32,7 +32,6 @@ #include "../sigsession.h" #include "../toolbars/titlebar.h" #include "dsdialog.h" -#include "../device/devinst.h" namespace pv { namespace dialogs { diff --git a/DSView/pv/dialogs/waitingdialog.h b/DSView/pv/dialogs/waitingdialog.h index bec11f1c..8609c0ec 100644 --- a/DSView/pv/dialogs/waitingdialog.h +++ b/DSView/pv/dialogs/waitingdialog.h @@ -29,12 +29,9 @@ #include #include "../sigsession.h" -#include "../device/devinst.h" #include "../toolbars/titlebar.h" #include "dsdialog.h" -using namespace pv::device; - class DeviceAgent; namespace pv { diff --git a/DSView/pv/dock/dsotriggerdock.cpp b/DSView/pv/dock/dsotriggerdock.cpp index 7fce3f47..828c8d9f 100644 --- a/DSView/pv/dock/dsotriggerdock.cpp +++ b/DSView/pv/dock/dsotriggerdock.cpp @@ -21,7 +21,6 @@ #include "dsotriggerdock.h" #include "../sigsession.h" -#include "../device/devinst.h" #include "../dialogs/dsmessagebox.h" #include "../view/dsosignal.h" diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index d863a773..b71ea020 100644 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -31,8 +31,6 @@ #include "../view/logicsignal.h" #include "../data/signaldata.h" #include "../data/snapshot.h" -#include "../device/device.h" -#include "../device/file.h" #include "../dialogs/dsdialog.h" #include "../dialogs/dsmessagebox.h" diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index ed850e65..aba1588a 100644 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -22,7 +22,6 @@ #include "protocoldock.h" #include "../sigsession.h" #include "../view/decodetrace.h" -#include "../device/devinst.h" #include "../data/decodermodel.h" #include "../data/decoderstack.h" #include "../dialogs/protocollist.h" diff --git a/DSView/pv/dock/searchdock.cpp b/DSView/pv/dock/searchdock.cpp index 7ec4fc27..738c9f03 100644 --- a/DSView/pv/dock/searchdock.cpp +++ b/DSView/pv/dock/searchdock.cpp @@ -28,7 +28,6 @@ #include "../dialogs/search.h" #include "../data/snapshot.h" #include "../data/logicsnapshot.h" -#include "../device/devinst.h" #include "../dialogs/dsmessagebox.h" #include diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index 980c716a..b6b9a345 100644 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -21,7 +21,6 @@ #include "triggerdock.h" #include "../sigsession.h" -#include "../device/devinst.h" #include "../dialogs/dsmessagebox.h" #include "../view/view.h" diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 44040791..ae165342 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -94,6 +94,8 @@ #include "log.h" #include "sigsession.h" #include "deviceagent.h" +#include +#include "ZipMaker.h" #define BASE_SESSION_VERSION 2 @@ -303,65 +305,6 @@ namespace pv _search_dock->setWindowTitle(tr("Search...")); } -/* - void MainWindow::update_device_list() - { - assert(_sampling_bar); - if (!selected_device->name().contains("virtual")) { - - - #if QT_VERSION >= 0x050400 - QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); - #else - QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); - #endif - if (dir.exists()) { - QString str = dir.absolutePath() + "/"; - QString lang_name = ".ses" + QString::number(app._frameOptions.language); - QString ses_name = str + - selected_device->name() + - QString::number(selected_device->dev_inst()->mode) + - lang_name + ".dsc"; - on_load_session(ses_name); - } - } else { - - - - QDir dir(GetResourceDir()); - if (dir.exists()) { - QString str = dir.absolutePath() + "/"; - QString ses_name = str + - selected_device->name() + - QString::number(selected_device->dev_inst()->mode) + - ".dsc"; - if (QFileInfo(ses_name).exists()) - on_load_session(ses_name); - } - } - - _trig_bar->restore_status(); - - //load specified file name from application startup param - if (_bFirstLoad){ - - QString ldFileName(AppControl::Instance()->_open_file_name.c_str()); - - if (ldFileName != ""){ - if (QFile::exists(ldFileName)){ - dsv_info("auto load file:%s", ldFileName.toUtf8().data()); - on_load_file(ldFileName); - } - else{ - dsv_err("file is not exists:%s", ldFileName.toUtf8().data()); - MsgBox::Show(tr("Open file error!"), ldFileName, NULL); - } - } - } - - } - */ - void MainWindow::on_load_file(QString file_name) { try @@ -511,7 +454,6 @@ namespace pv void MainWindow::on_protocol(bool visible) { - _protocol_dock->setVisible(visible); } @@ -570,7 +512,6 @@ namespace pv if (!fileName.isEmpty()) { - QStringList list = format.split('.').last().split(')'); QString suffix = list.first(); @@ -636,7 +577,7 @@ namespace pv { QJsonObject sessionObj = json.object(); - /* + int mode = _device_agent->get_work_mode(); // check session file version if (!sessionObj.contains("Version")){ @@ -654,48 +595,55 @@ namespace pv switchLanguage(sessionObj["Language"].toInt()); } - - // check device and mode - 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()) { + // check device and mode + if ((!file_dev && strcmp(_device_agent->driver_name().toLocal8Bit().data(), sessionObj["Device"].toString().toUtf8()) != 0) || + mode != sessionObj["DeviceMode"].toDouble()) { MsgBox::Show(NULL, tr("Session File is not compatible with current device or mode!"), this); return false; } // clear decoders - if (sdi->mode == LOGIC && !file_dev) + if (mode == LOGIC && !file_dev) { _protocol_widget->del_all_protocol(); } // load device settings - GVariant *gvar_opts; + GVariant *gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_DEVICE_SESSIONS); gsize num_opts; - if ((sr_config_list(sdi->driver, sdi, NULL, SR_CONF_DEVICE_SESSIONS, &gvar_opts) == SR_OK)) { + + if (gvar_opts != NULL) { 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]); + + for (unsigned int i = 0; i < num_opts; i++) + { + const struct sr_config_info *const info = _device_agent->get_config_info(options[i]); + if (!sessionObj.contains(info->name)) continue; + if (info->datatype == SR_T_BOOL) - _device_agent->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) - _device_agent->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) - _device_agent->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) - _device_agent->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) - _device_agent->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 = _device_agent->dev_inst()->channels; l; l = l->next) { + if (file_dev && mode == DSO) { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); @@ -714,8 +662,9 @@ namespace pv } } } - } else { - for (const GSList *l = _device_agent->dev_inst()->channels; l; l = l->next) { + } + else { + for (const GSList *l = _device_agent->get_channels(); l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); bool isEnabled = false; @@ -746,7 +695,7 @@ namespace pv _session->reload(); // load signal setting - if (file_dev && (sdi->mode == DSO)) { + if (file_dev && mode == DSO) { for(auto &s : _session->get_signals()) { for (const QJsonValue &value : sessionObj["channel"].toArray()) { @@ -766,7 +715,8 @@ namespace pv } } } - } else { + } + else { for(auto &s : _session->get_signals()) { for (const QJsonValue &value : sessionObj["channel"].toArray()) { QJsonObject obj = value.toObject(); @@ -822,7 +772,6 @@ namespace pv if (sessionObj.contains("measure")) { _view->get_viewstatus()->load_session(sessionObj["measure"].toArray()); } - */ return true; } @@ -1364,6 +1313,124 @@ namespace pv return false; } + void MainWindow::check_session_file_version() + { + auto device_agent = _session->get_device(); + if (device_agent->is_file() && device_agent->is_new_device()){ + if (device_agent->get_work_mode() == LOGIC){ + GVariant* gvar = device_agent->get_config(NULL, NULL, SR_CONF_FILE_VERSION); + if (gvar != NULL) { + int16_t version = g_variant_get_int16(gvar); + g_variant_unref(gvar); + if (version == 1) { + show_error(tr("Current loading file has an old format. " + "This will lead to a slow loading speed. " + "Please resave it after loaded.")); + } + } + } + } + } + + void MainWindow::load_device_config() + { + int lang = AppConfig::Instance()._frameOptions.language; + QString name = _device_agent->name(); + int mode = _device_agent->get_work_mode(); + + if (_device_agent->is_hardware()) + { + +#if QT_VERSION >= 0x050400 + QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); +#else + QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); +#endif + if (dir.exists()) + { + QString str = dir.absolutePath() + "/"; + QString lang_name = ".ses" + QString::number(lang); + QString ses_name = str + + name + + QString::number(mode) + + lang_name + ".dsc"; + on_load_session(ses_name); + } + } + else + { + QDir dir(GetResourceDir()); + if (dir.exists()) + { + QString str = dir.absolutePath() + "/"; + QString ses_name = str + + name + + QString::number(mode) + + ".dsc"; + if (QFileInfo(ses_name).exists()) + on_load_session(ses_name); + } + } + } + + QJsonDocument MainWindow::get_session_json_from_file(QString file) + { + QJsonDocument sessionDoc; + QJsonParseError error; + + auto f_name = path::ConvertPath(file); + ZipReader rd(f_name.c_str()); + auto *data = rd.GetInnterFileData("session"); + + if (data != NULL) + { + QByteArray raw_bytes = QByteArray::fromRawData(data->data(), data->size()); + QString jsonStr(raw_bytes.data()); + QByteArray qbs = jsonStr.toUtf8(); + sessionDoc = QJsonDocument::fromJson(qbs, &error); + + if (error.error != QJsonParseError::NoError) + { + QString estr = error.errorString(); + dsv_err("File::get_session(), parse json error:\"%s\"!", estr.toUtf8().data()); + } + + rd.ReleaseInnerFileData(data); + } + + return sessionDoc; + } + + QJsonArray MainWindow::get_decoder_json_from_file(QString file) + { + QJsonArray dec_array; + QJsonParseError error; + + /* read "decoders" */ + auto f_name = path::ConvertPath(file); + ZipReader rd(f_name.c_str()); + auto *data = rd.GetInnterFileData("decoders"); + + if (data != NULL) + { + QByteArray raw_bytes = QByteArray::fromRawData(data->data(), data->size()); + QString jsonStr(raw_bytes.data()); + QByteArray qbs = jsonStr.toUtf8(); + QJsonDocument sessionDoc = QJsonDocument::fromJson(qbs, &error); + + if (error.error != QJsonParseError::NoError) + { + QString estr = error.errorString(); + dsv_err("File::get_decoders(), parse json error:\"%s\"!", estr.toUtf8().data()); + } + + dec_array = sessionDoc.array(); + rd.ReleaseInnerFileData(data); + } + + return dec_array; + } + void MainWindow::OnMessage(int msg) { switch (msg) @@ -1401,12 +1468,24 @@ namespace pv _msg->close(); _msg = NULL; } - + + load_device_config(); _sampling_bar->update_device_list(); - reset_all_view(); - bool is_hardware = _session->get_device()->is_hardware(); - _logo_bar->dsl_connected(is_hardware); + reset_all_view(); + _logo_bar->dsl_connected(_session->get_device()->is_hardware()); _file_bar->update_view_status(); + + if (_device_agent->is_file()){ + check_session_file_version(); + StoreSession ss(_session); + // load decoder + bool bFlag = ss.load_decoders(_protocol_widget + ,get_decoder_json_from_file(_device_agent->path())); + + // load session + load_session_json(get_session_json_from_file(_device_agent->path()), true, !bFlag); + _session->start_capture(true); + } } break; @@ -1421,7 +1500,9 @@ namespace pv _view->timebase_changed(); break; - case DSV_MSG_DEVICE_MODE_CHANGED: + case DSV_MSG_DEVICE_MODE_CHANGED: + _sampling_bar->update_sample_rate_selector(); + _sampling_bar->update_view_status(); _view->mode_changed(); reset_all_view(); break; diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index 8f54c038..032930bb 100644 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -71,8 +71,6 @@ class View; namespace device{ class DevInst; } - -using namespace pv::device; //The mainwindow,referenced by MainFrame //TODO: create graph view,toolbar,and show device list @@ -171,8 +169,11 @@ private: //ISessionDataGetter bool genSessionData(std::string &str); - bool gen_session_json(QJsonObject &sessionVar); + void check_session_file_version(); + void load_device_config(); + QJsonDocument get_session_json_from_file(QString file); + QJsonArray get_decoder_json_from_file(QString file); //IMessageListener void OnMessage(int msg); diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 44afccfe..27e83b24 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -155,7 +155,7 @@ namespace pv assert(!_is_saving); assert(!_is_working); - struct ds_device_info *array = NULL; + struct ds_device_base_info *array = NULL; int count = 0; dsv_info("%s", "Set default device."); @@ -171,7 +171,7 @@ namespace pv return false; } - struct ds_device_info *dev = (array + count - 1); + struct ds_device_base_info *dev = (array + count - 1); ds_device_handle dev_handle = dev->handle; free(array); @@ -188,7 +188,7 @@ namespace pv assert(!_is_saving); assert(!_is_working); - // Release old device. + // Release the old device. _device_agent.release(); if (_callback != NULL) @@ -277,11 +277,11 @@ namespace pv return false; } - struct ds_device_info *SigSession::get_device_list(int &out_count, int &actived_index) + struct ds_device_base_info *SigSession::get_device_list(int &out_count, int &actived_index) { out_count = 0; actived_index = -1; - struct ds_device_info *array = NULL; + struct ds_device_base_info *array = NULL; if (ds_get_device_list(&array, &out_count) == SR_OK) { @@ -612,7 +612,7 @@ namespace pv return; if (_data_updated) - { + { data_updated(); _data_updated = false; _noData_cnt = 0; diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index d7652268..a0e3b573 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -82,7 +82,6 @@ class LissajousTrace; class MathTrace; } -using namespace pv::device; using namespace pv::data; //created by MainWindow @@ -292,7 +291,7 @@ public: void set_map_zoom(int index); void auto_end(); bool have_hardware_data(); - struct ds_device_info* get_device_list(int &out_count, int &actived_index); + struct ds_device_base_info* get_device_list(int &out_count, int &actived_index); void add_msg_listener(IMessageListener *ln); void broadcast_msg(int msg); bool switch_work_mode(int mode); diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index a0a7a15f..56aedc6e 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -38,7 +38,6 @@ #include "view/logicsignal.h" #include "view/dsosignal.h" #include "view/decodetrace.h" -#include "device/devinst.h" #include "dock/protocoldock.h" #include diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index 933209e5..9d43ccb7 100644 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -26,7 +26,6 @@ #include #include "filebar.h" -#include "../device/devinst.h" #include "../ui/msgbox.h" #include "../config/appconfig.h" #include "../utility/path.h" diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 11eaace6..e4478ad7 100644 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -26,7 +26,6 @@ #include #include #include -#include "../device/devinst.h" #include "../dialogs/deviceoptions.h" #include "../dialogs/waitingdialog.h" #include "../dialogs/dsmessagebox.h" @@ -43,8 +42,6 @@ using std::max; using std::min; using std::string; -using namespace pv::device; - namespace pv { namespace toolbars @@ -361,7 +358,7 @@ namespace pv } void SamplingBar::update_sample_rate_selector() - { + { GVariant *gvar_dict, *gvar_list; const uint64_t *elements = NULL; gsize num_elements; @@ -1078,7 +1075,7 @@ namespace pv void SamplingBar::update_device_list() { - struct ds_device_info *array = NULL; + struct ds_device_base_info *array = NULL; int dev_count = 0; int select_index = 0; @@ -1093,7 +1090,7 @@ namespace pv } _updating_device_list = true; - struct ds_device_info *p = NULL; + struct ds_device_base_info *p = NULL; ds_device_handle cur_dev_handle = NULL_HANDLE; _device_selector.clear(); @@ -1140,9 +1137,15 @@ namespace pv _mode_button.setEnabled(bEnable); _configure_button.setEnabled(bEnable); _device_selector.setEnabled(bEnable); - _sample_rate.setEnabled(bEnable); _sample_count.setEnabled(bEnable); + if (_session->get_device()->get_work_mode() == DSO){ + _sample_rate.setEnabled(false); + } + else{ + _sample_rate.setEnabled(bEnable); + } + if (_session->is_working()){ _run_stop_button.setEnabled(_is_run_as_instant ? false : true); diff --git a/DSView/pv/toolbars/samplingbar.h b/DSView/pv/toolbars/samplingbar.h index 0be8872b..f17d5105 100644 --- a/DSView/pv/toolbars/samplingbar.h +++ b/DSView/pv/toolbars/samplingbar.h @@ -78,15 +78,14 @@ namespace pv public: SamplingBar(SigSession *session, QWidget *parent); - double hori_knob(int dir); - double commit_hori_res(); - double get_hori_res(); - void set_sample_rate(uint64_t sample_rate); + double hori_knob(int dir); + double get_hori_res(); void update_device_list(); void reload(); void update_view_status(); void config_device(); ds_device_handle get_next_device_handle(); + void update_sample_rate_selector(); signals: void sig_store_session_data(); @@ -95,8 +94,9 @@ namespace pv void changeEvent(QEvent *event); void retranslateUi(); void reStyle(); - - void update_sample_rate_selector(); + void set_sample_rate(uint64_t sample_rate); + double commit_hori_res(); + void update_sample_rate_selector_value(); void update_sample_count_selector(); void update_sample_count_selector_value(); diff --git a/DSView/pv/toolbars/trigbar.cpp b/DSView/pv/toolbars/trigbar.cpp index 03edf1ae..df5de4d5 100644 --- a/DSView/pv/toolbars/trigbar.cpp +++ b/DSView/pv/toolbars/trigbar.cpp @@ -26,7 +26,6 @@ #include #include "../sigsession.h" -#include "../device/devinst.h" #include "../dialogs/fftoptions.h" #include "../dialogs/lissajousoptions.h" #include "../dialogs/mathoptions.h" diff --git a/DSView/pv/view/analogsignal.cpp b/DSView/pv/view/analogsignal.cpp index 5787d8ec..8e07a600 100644 --- a/DSView/pv/view/analogsignal.cpp +++ b/DSView/pv/view/analogsignal.cpp @@ -25,7 +25,6 @@ #include "../data/analog.h" #include "../data/analogsnapshot.h" #include "../view/view.h" -#include "../device/devinst.h" #include "../dsvdef.h" #include "../log.h" diff --git a/DSView/pv/view/cursor.cpp b/DSView/pv/view/cursor.cpp index 19b0a235..e9a11af5 100644 --- a/DSView/pv/view/cursor.cpp +++ b/DSView/pv/view/cursor.cpp @@ -24,7 +24,6 @@ #include "ruler.h" #include "view.h" -#include "../device/device.h" #include #include diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index 0873b5fc..e0f44e4f 100644 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -45,7 +45,6 @@ #include "../view/view.h" #include "../widgets/decodergroupbox.h" #include "../widgets/decodermenu.h" -#include "../device/devinst.h" #include "../view/cursor.h" #include "../toolbars/titlebar.h" #include "../dsvdef.h" diff --git a/DSView/pv/view/devmode.cpp b/DSView/pv/view/devmode.cpp index e6515b27..b007573e 100644 --- a/DSView/pv/view/devmode.cpp +++ b/DSView/pv/view/devmode.cpp @@ -22,9 +22,7 @@ #include "devmode.h" #include "view.h" #include "trace.h" -#include "../sigsession.h" -#include "../device/devinst.h" -#include "../device/file.h" +#include "../sigsession.h" #include #include diff --git a/DSView/pv/view/header.cpp b/DSView/pv/view/header.cpp index 6eaa78ea..e1107d52 100644 --- a/DSView/pv/view/header.cpp +++ b/DSView/pv/view/header.cpp @@ -40,7 +40,6 @@ #include "groupsignal.h" #include "decodetrace.h" #include "../sigsession.h" -#include "../device/devinst.h" #include "../dsvdef.h" diff --git a/DSView/pv/view/lissajoustrace.cpp b/DSView/pv/view/lissajoustrace.cpp index e5286388..8197f2a5 100644 --- a/DSView/pv/view/lissajoustrace.cpp +++ b/DSView/pv/view/lissajoustrace.cpp @@ -29,7 +29,6 @@ #include "../data/dso.h" #include "../data/dsosnapshot.h" #include "../sigsession.h" -#include "../device/devinst.h" using namespace std; diff --git a/DSView/pv/view/mathtrace.cpp b/DSView/pv/view/mathtrace.cpp index b36c6177..31c70efa 100644 --- a/DSView/pv/view/mathtrace.cpp +++ b/DSView/pv/view/mathtrace.cpp @@ -28,7 +28,6 @@ #include "../data/mathstack.h" #include "view.h" #include "../sigsession.h" -#include "../device/devinst.h" #include "../view/dsosignal.h" #include "../dsvdef.h" diff --git a/DSView/pv/view/ruler.cpp b/DSView/pv/view/ruler.cpp index 541bdf37..3a83ed92 100644 --- a/DSView/pv/view/ruler.cpp +++ b/DSView/pv/view/ruler.cpp @@ -26,7 +26,6 @@ #include "view.h" #include "viewport.h" #include "../sigsession.h" -#include "../device/devinst.h" #include "dsosignal.h" #include "../dsvdef.h" diff --git a/DSView/pv/view/spectrumtrace.cpp b/DSView/pv/view/spectrumtrace.cpp index 7e2c3f48..ea7703e2 100644 --- a/DSView/pv/view/spectrumtrace.cpp +++ b/DSView/pv/view/spectrumtrace.cpp @@ -32,7 +32,6 @@ #include "../data/dsosnapshot.h" #include "../view/dsosignal.h" #include "../view/viewport.h" -#include "../device/devinst.h" #include "../data/spectrumstack.h" #include "../dsvdef.h" diff --git a/DSView/pv/view/timemarker.cpp b/DSView/pv/view/timemarker.cpp index 79a43707..ad8aa705 100644 --- a/DSView/pv/view/timemarker.cpp +++ b/DSView/pv/view/timemarker.cpp @@ -24,7 +24,6 @@ #include "view.h" #include "ruler.h" -#include "../device/device.h" #include diff --git a/DSView/pv/view/trace.cpp b/DSView/pv/view/trace.cpp index 2f6b109b..f5bed0a2 100644 --- a/DSView/pv/view/trace.cpp +++ b/DSView/pv/view/trace.cpp @@ -29,7 +29,6 @@ #include "trace.h" #include "view.h" -#include "../device/devinst.h" #include "../sigsession.h" #include "../dsvdef.h" diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index ef679820..21901197 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -41,7 +41,6 @@ #include "lissajoustrace.h" #include "analogsignal.h" -#include "../device/devinst.h" #include "../sigsession.h" #include "../data/logic.h" #include "../data/logicsnapshot.h" diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 1b9b56e6..db2f5400 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -28,7 +28,6 @@ #include "logicsignal.h" #include "analogsignal.h" #include "spectrumtrace.h" -#include "../device/devinst.h" #include "../data/logic.h" #include "../data/logicsnapshot.h" #include "../sigsession.h" diff --git a/DSView/pv/view/viewstatus.cpp b/DSView/pv/view/viewstatus.cpp index 002d1440..5ff07548 100644 --- a/DSView/pv/view/viewstatus.cpp +++ b/DSView/pv/view/viewstatus.cpp @@ -31,7 +31,6 @@ #include "../view/trace.h" #include "../sigsession.h" -#include "../device/devinst.h" #include "../view/view.h" #include "../view/trace.h" #include "../dialogs/dsomeasure.h" diff --git a/DSView/pv/view/xcursor.cpp b/DSView/pv/view/xcursor.cpp index 1148dfb5..29180de6 100644 --- a/DSView/pv/view/xcursor.cpp +++ b/DSView/pv/view/xcursor.cpp @@ -24,7 +24,6 @@ #include "view.h" #include "ruler.h" -#include "../device/device.h" #include "dsosignal.h" #include diff --git a/libsigrok4DSL/lib_main.c b/libsigrok4DSL/lib_main.c index 4107152b..45c2457e 100644 --- a/libsigrok4DSL/lib_main.c +++ b/libsigrok4DSL/lib_main.c @@ -240,11 +240,11 @@ SR_API void ds_set_datafeed_callback(ds_datafeed_callback_t cb) * Get the device list, if the field _handle is 0, the list visited to end. * User need call free() to release the buffer. If the list is empty, the out_list is null. */ -SR_API int ds_get_device_list(struct ds_device_info **out_list, int *out_count) +SR_API int ds_get_device_list(struct ds_device_base_info **out_list, int *out_count) { int num; - struct ds_device_info *array = NULL; - struct ds_device_info *p = NULL; + struct ds_device_base_info *array = NULL; + struct ds_device_base_info *p = NULL; GSList *l; struct sr_dev_inst *dev; @@ -263,7 +263,7 @@ SR_API int ds_get_device_list(struct ds_device_info **out_list, int *out_count) return SR_OK; } - array = (struct ds_device_info *)malloc(sizeof(struct ds_device_info) * (num + 1)); + array = (struct ds_device_info *)malloc(sizeof(struct ds_device_base_info) * (num + 1)); if (array == NULL) { pthread_mutex_unlock(&lib_ctx.mutext); @@ -276,16 +276,7 @@ SR_API int ds_get_device_list(struct ds_device_info **out_list, int *out_count) { dev = l->data; p->handle = dev->handle; - 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++; } @@ -561,10 +552,10 @@ SR_API int ds_remove_device(ds_device_handle handle) * Get the actived device info. * If the actived device is not exists, the handle filed will be set null. */ -SR_API int ds_get_actived_device_info(struct ds_device_info *fill_info) +SR_API int ds_get_actived_device_info(struct ds_device_full_info *fill_info) { struct sr_dev_inst *dev; - struct ds_device_info *p; + struct ds_device_full_info *p; int ret; if (fill_info == NULL) @@ -576,6 +567,7 @@ SR_API int ds_get_actived_device_info(struct ds_device_info *fill_info) p->handle = NULL_HANDLE; p->name[0] = '\0'; + p->path[0] = '\0'; p->driver_name[0] = '\0'; p->dev_type = DEV_TYPE_UNKOWN; p->di = NULL; diff --git a/libsigrok4DSL/libsigrok.h b/libsigrok4DSL/libsigrok.h index cb02f701..01b37d50 100644 --- a/libsigrok4DSL/libsigrok.h +++ b/libsigrok4DSL/libsigrok.h @@ -1279,10 +1279,17 @@ typedef unsigned long long ds_device_handle; /** * Device base info */ -struct ds_device_info +struct ds_device_base_info { ds_device_handle handle; char name[50]; +}; + +struct ds_device_full_info +{ + ds_device_handle handle; + char name[50]; + char path[256]; //file path char driver_name[20]; int dev_type; // enum sr_device_type struct sr_dev_inst *di; @@ -1344,7 +1351,7 @@ SR_API void ds_set_firmware_resource_dir(const char *dir); * Get the device list, if the field _handle is 0, the list visited to end. * User need call free() to release the buffer. If the list is empty, the out_list is null. */ -SR_API int ds_get_device_list(struct ds_device_info** out_list, int *out_count); +SR_API int ds_get_device_list(struct ds_device_base_info** out_list, int *out_count); /** * Active a device. @@ -1388,7 +1395,7 @@ SR_API const GSList *ds_get_actived_device_mode_list(); * Get the actived device info. * If the actived device is not exists, the handle filed will be set null. */ -SR_API int ds_get_actived_device_info(struct ds_device_info *fill_info); +SR_API int ds_get_actived_device_info(struct ds_device_full_info *fill_info); /** * Get actived device work model. mode list:LOGIC、ANALOG、DSO diff --git a/libsigrok4DSL/session.c b/libsigrok4DSL/session.c index 7b06a1af..9b2bacc4 100644 --- a/libsigrok4DSL/session.c +++ b/libsigrok4DSL/session.c @@ -71,7 +71,7 @@ struct source { SR_PRIV struct sr_session *sr_session_new(void) { if (session != NULL){ - sr_info("%s", "Destroy the old session."); + sr_detail("%s", "Destroy the old session."); sr_session_destroy(); // Destory the old. }