diff --git a/CMakeLists.txt b/CMakeLists.txt index f43bdfb2..63a20b0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ set(DS_DESCRIPTION "A GUI for instruments of DreamSourceLab") set(DS_VERSION_MAJOR 1) set(DS_VERSION_MINOR 3) set(DS_VERSION_MICRO 0) -set(DS_VERSION_STRING ${DS_VERSION_MAJOR}.${DS_VERSION_MINOR}.${DS_VERSION_MICRO}-dev ) +set(DS_VERSION_STRING ${DS_VERSION_MAJOR}.${DS_VERSION_MINOR}.${DS_VERSION_MICRO}-dev2 ) configure_file ( ${PROJECT_SOURCE_DIR}/DSView/config.h.in diff --git a/DSView/config.h b/DSView/config.h index a449a3fa..03048a28 100644 --- a/DSView/config.h +++ b/DSView/config.h @@ -30,6 +30,6 @@ #define DS_VERSION_MAJOR 1 #define DS_VERSION_MINOR 3 #define DS_VERSION_MICRO 0 -#define DS_VERSION_STRING "1.3.0-dev" +#define DS_VERSION_STRING "1.3.0-dev2" #endif diff --git a/DSView/pv/deviceagent.cpp b/DSView/pv/deviceagent.cpp index fb0a76de..05de986a 100644 --- a/DSView/pv/deviceagent.cpp +++ b/DSView/pv/deviceagent.cpp @@ -74,12 +74,12 @@ GVariant* DeviceAgent::get_config(const sr_channel *ch, const sr_channel_group * { assert(_dev_handle); GVariant *data = NULL; - if (ds_get_actived_device_config(ch, group, key, &data) != SR_OK) + + int ret = ds_get_actived_device_config(ch, group, key, &data); + if (ret != SR_OK) { - if (is_hardware()) - dsv_warn("%s%d", "WARNING: Failed to get value of config id:", key); - else - dsv_detail("%s%d", "WARNING: Failed to get value of config id:", key); + if (ret != SR_ERR_NA) + dsv_err("%s%d", "ERROR: Failed to get value of config id:", key); } return data; } @@ -88,12 +88,11 @@ bool DeviceAgent::set_config(sr_channel *ch, sr_channel_group *group, int key, G { assert(_dev_handle); - if (ds_set_actived_device_config(ch, group, key, data) != SR_OK) - { - if (is_hardware()) - dsv_warn("%s%d", "WARNING: Failed to set value of config id:", key); - else - dsv_detail("%s%d", "WARNING: Failed to set value of config id:", key); + int ret = ds_set_actived_device_config(ch, group, key, data); + if (ret != SR_OK) + { + if (ret != SR_ERR_NA) + dsv_err("%s%d", "ERROR: Failed to set value of config id:", key); return false; } @@ -107,8 +106,11 @@ GVariant* DeviceAgent::get_config_list(const sr_channel_group *group, int key) GVariant *data = NULL; - if (ds_get_actived_device_config_list(group, key, &data) != SR_OK){ - dsv_warn("%s%d", "WARNING: Failed to get config list, key:", key); + int ret = ds_get_actived_device_config_list(group, key, &data); + if (ret != SR_OK){ + if (ret != SR_ERR_NA) + dsv_detail("%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); } diff --git a/DSView/pv/dialogs/deviceoptions.cpp b/DSView/pv/dialogs/deviceoptions.cpp index 8e39bef6..fb3cafcb 100644 --- a/DSView/pv/dialogs/deviceoptions.cpp +++ b/DSView/pv/dialogs/deviceoptions.cpp @@ -141,7 +141,7 @@ DeviceOptions::DeviceOptions(QWidget *parent) : GVariant* gvar = _device_agent->get_config(NULL, NULL, SR_CONF_OPERATION_MODE); if (gvar != NULL) { - _mode = QString::fromUtf8(g_variant_get_string(gvar, NULL)); + _opt_mode = g_variant_get_int16(gvar); g_variant_unref(gvar); } @@ -186,19 +186,20 @@ void DeviceOptions::accept() } if (hasEnabled) { - QVector::iterator i = _probe_options_binding_list.begin(); - while(i != _probe_options_binding_list.end()) { - const auto &probe_props = (*i)->properties(); + auto it = _probe_options_binding_list.begin(); + while(it != _probe_options_binding_list.end()) { + const auto &probe_props = (*it)->properties(); for(auto &p :probe_props) { assert(p); p->commit(); } - i++; + it++; } QDialog::accept(); - } else { + } + else { dialogs::DSMessageBox msg(this); msg.mBox()->setText(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_ATTENTION), "Attention")); msg.mBox()->setInformativeText(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_ALL_CHANNEL_DISABLE), "All channel disabled! Please enable at least one channel.")); @@ -222,12 +223,19 @@ QLayout * DeviceOptions::get_property_form(QWidget * parent) const auto &properties =_device_options_binding.properties(); int i = 0; - for(auto &p : properties) - { - assert(p); - const QString label = p->labeled_widget() ? QString() : p->label(); - layout->addWidget(new QLabel(label, parent), i, 0); - if (label == L_S(STR_PAGE_DLG, S_ID(IDS_DLG_OPERATION_MODE), "Operation Mode")) + for(auto p : properties) + { + const QString label = p->labeled_widget() ? QString() : p->label(); + QString lable_text; + + if (label != ""){ + const char *label_str = label.toLocal8Bit().data(); + lable_text = LangResource::Instance()->get_lang_text(STR_PAGE_DSL, label_str, label_str); + } + + layout->addWidget(new QLabel(lable_text, parent), i, 0); + + if (label == QString("Operation Mode")) layout->addWidget(p->get_widget(parent, true), i, 1); else layout->addWidget(p->get_widget(parent), i, 1); @@ -235,7 +243,6 @@ QLayout * DeviceOptions::get_property_form(QWidget * parent) i++; } - //_groupHeight1 = i * 22 + 180; _groupHeight1 = parent->sizeHint().height(); parent->setFixedHeight(_groupHeight1); @@ -259,34 +266,40 @@ void DeviceOptions::logic_probes(QVBoxLayout &layout) //channel count checked if (_device_agent->get_work_mode()== LOGIC) { - GVariant *gvar_opts; - gsize num_opts; + GVariant * gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_CHANNEL_MODE); - gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_CHANNEL_MODE); - - if (gvar_opts != NULL) + if (gvar_opts != NULL) { - const char **const options = g_variant_get_strv(gvar_opts, &num_opts); - 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); + struct sr_list_item *plist = (struct sr_list_item*)g_variant_get_uint64(gvar_opts); + g_variant_unref(gvar_opts); - for (unsigned int i=0; isizeHint().height(); //radio button height - - connect(ch_opts, SIGNAL(pressed()), this, SLOT(channel_check())); + GVariant* mode_var = _device_agent->get_config(NULL, NULL, SR_CONF_CHANNEL_MODE); + assert(mode_var); + _channel_mode_indexs.clear(); - row1++; - if (QString::fromUtf8(options[i]) == ch_mode) - ch_opts->setChecked(true); - } + int ch_mode = g_variant_get_int16(mode_var); + g_variant_unref(mode_var); + + while (plist != NULL && plist->id >= 0) + { + row1++; + QString text = LangResource::Instance()->get_lang_text(STR_PAGE_DSL, plist->name, plist->name); + QRadioButton *mode_button = new QRadioButton(text); + ChannelModePair mode_index; + mode_index.key = mode_button; + mode_index.value = plist->id; + _channel_mode_indexs.push_back(mode_index); + + layout.addWidget(mode_button); + contentHeight += mode_button->sizeHint().height(); //radio button height + + connect(mode_button, SIGNAL(pressed()), this, SLOT(channel_check())); + + if (plist->id == ch_mode) + mode_button->setChecked(true); + + plist++; } - if (gvar_opts) - g_variant_unref(gvar_opts); } } @@ -449,14 +462,14 @@ void DeviceOptions::mode_check_timeout() return; bool test; - QString mode; + int 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)); + mode = g_variant_get_int16(gvar); g_variant_unref(gvar); - if (mode != _mode) { - _mode = mode; + if (mode != _opt_mode) { + _opt_mode = mode; build_dynamic_panel(); try_resize_scroll(); } @@ -478,14 +491,22 @@ void DeviceOptions::mode_check_timeout() void DeviceOptions::channel_check() { - QRadioButton* sc=dynamic_cast(sender()); - QString text = sc->text(); - text.remove('&'); + QRadioButton* bt = dynamic_cast(sender()); + assert(bt); - if(sc != NULL){ - _device_agent->set_config(NULL, NULL, SR_CONF_CHANNEL_MODE, g_variant_new_string(text.toUtf8().data())); + int mode_index = -1; + + for( auto p : _channel_mode_indexs){ + if (p.key == bt){ + mode_index = p.value; + break; + } } - + assert(mode_index >= 0); + + GVariant* gvar = g_variant_new_int16(mode_index); + _device_agent->set_config(NULL, NULL, SR_CONF_CHANNEL_MODE, gvar); + build_dynamic_panel(); try_resize_scroll(); } diff --git a/DSView/pv/dialogs/deviceoptions.h b/DSView/pv/dialogs/deviceoptions.h index d3d15d30..d48952b4 100644 --- a/DSView/pv/dialogs/deviceoptions.h +++ b/DSView/pv/dialogs/deviceoptions.h @@ -46,12 +46,14 @@ class QScrollArea; -class IChannelCheck{ +class IChannelCheck +{ public: virtual void ChannelChecked(int index)=0; }; -class ChannelLabel : public QWidget { +class ChannelLabel : public QWidget +{ Q_OBJECT public: @@ -70,6 +72,12 @@ private: int _index; }; +struct ChannelModePair +{ + void *key; + int value; +}; + class DeviceAgent; namespace pv { @@ -120,7 +128,7 @@ private: std::vector _sub_lays; QTimer _mode_check_timer; - QString _mode; + int _opt_mode; QWidget *_scroll_panel; QScrollArea *_scroll; QWidget *_container_panel; @@ -134,7 +142,8 @@ private: DeviceAgent *_device_agent; pv::prop::binding::DeviceOptions _device_options_binding; - QVector _probe_options_binding_list; + std::vector _probe_options_binding_list; + std::vector _channel_mode_indexs; }; } // namespace dialogs diff --git a/DSView/pv/mainframe.cpp b/DSView/pv/mainframe.cpp index f3420b73..d4fff5ea 100644 --- a/DSView/pv/mainframe.cpp +++ b/DSView/pv/mainframe.cpp @@ -48,7 +48,6 @@ #include "config/appconfig.h" #include "ui/msgbox.h" #include "appcontrol.h" - #include "ui/langresource.h" #include @@ -163,10 +162,15 @@ void MainFrame::resizeEvent(QResizeEvent *event) } void MainFrame::closeEvent(QCloseEvent *event) -{ +{ writeSettings(); - _mainWindow->session_save(); - event->accept(); + + if (_mainWindow->able_to_close()){ + event->accept(); + } + else{ + event->ignore(); + } } void MainFrame::unfreezing() diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 6e92fe9c..383df7c1 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -98,7 +98,7 @@ #include "ZipMaker.h" #include "ui/langresource.h" -#define BASE_SESSION_VERSION 2 +#define BASE_SESSION_VERSION 3 namespace pv { @@ -417,12 +417,6 @@ namespace pv void MainWindow::session_save() { -#if QT_VERSION >= 0x050400 - QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); -#else - QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation); -#endif - if (_device_agent->have_instance() == false) { dsv_info("%s", "There is no need to save the configuration"); @@ -432,7 +426,7 @@ namespace pv AppConfig &app = AppConfig::Instance(); if (_device_agent->is_hardware()){ - QString sessionFile = genSessionFileName(); + QString sessionFile = genSessionFileName(true); on_store_session(sessionFile); } @@ -440,7 +434,7 @@ namespace pv app.SaveFrame(); } - QString MainWindow::genSessionFileName() + QString MainWindow::genSessionFileName(bool isNewFormat) { #if QT_VERSION >= 0x050400 QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); @@ -456,18 +450,27 @@ namespace pv } QString driver_name = _device_agent->driver_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 + lang_name + ".dsc"; + QString mode_name = QString::number(_device_agent->get_work_mode()); + QString lang_name; + QString base_path = dir.absolutePath() + "/" + driver_name + mode_name; - return file_name; + if (!isNewFormat){ + lang_name = QString::number(app._frameOptions.language); + } + + return base_path + ".ses" + lang_name + ".dsc"; } - void MainWindow::closeEvent(QCloseEvent *event) + bool MainWindow::able_to_close() { // not used, refer to closeEvent of mainFrame session_save(); - event->accept(); + + if (confirm_to_store_data()){ + on_save(); + return false; + } + return true; } void MainWindow::on_protocol(bool visible) @@ -606,7 +609,7 @@ namespace pv return load_session_json(sessionDoc, bDone); } - bool MainWindow::gen_session_json(QJsonObject &sessionVar) + bool MainWindow::gen_session_json(QJsonObject &sessionVar) { AppConfig &app = AppConfig::Instance(); @@ -645,13 +648,15 @@ namespace pv else if (info->datatype == SR_T_UINT64) sessionVar[info->name] = QJsonValue::fromVariant(QString::number(g_variant_get_uint64(gvar))); else if (info->datatype == SR_T_UINT8) - sessionVar[info->name] = QJsonValue::fromVariant(QString::number(g_variant_get_byte(gvar))); - else if (info->datatype == SR_T_FLOAT) - sessionVar[info->name] = QJsonValue::fromVariant(g_variant_get_double(gvar)); + sessionVar[info->name] = QJsonValue::fromVariant(g_variant_get_byte(gvar)); + else if (info->datatype == SR_T_INT16) + sessionVar[info->name] = QJsonValue::fromVariant(g_variant_get_int16(gvar)); + else if (info->datatype == SR_T_FLOAT) //save as string format + sessionVar[info->name] = QJsonValue::fromVariant(QString::number(g_variant_get_double(gvar))); else if (info->datatype == SR_T_CHAR) sessionVar[info->name] = QJsonValue::fromVariant(g_variant_get_string(gvar, NULL)); else if (info->datatype == SR_T_LIST) - sessionVar[info->name] = QJsonValue::fromVariant(QString::number(g_variant_get_uint16(gvar))); + sessionVar[info->name] = QJsonValue::fromVariant(g_variant_get_int16(gvar)); else{ dsv_err("Unkown config info type:%d", info->datatype); assert(false); @@ -731,7 +736,6 @@ namespace pv QJsonObject sessionObj = json.object(); int mode = _device_agent->get_work_mode(); - bool isNew = false; // check session file version if (!sessionObj.contains("Version")) @@ -740,23 +744,22 @@ namespace pv return false; } - if (sessionObj["Version"].toInt() < BASE_SESSION_VERSION) + int format_ver = sessionObj["Version"].toInt(); + + if (format_ver < 2) { dsv_err("%s", "session file version is error!"); return false; - } + } - if (sessionObj.contains("Title")) - isNew = true; - - int sessionMode = sessionObj["DeviceMode"].toInt(); + int conf_dev_mode = sessionObj["DeviceMode"].toInt(); if (_device_agent->is_hardware()) { QString driverName = _device_agent->driver_name(); QString sessionDevice = sessionObj["Device"].toString(); // check device and mode - if (driverName != sessionDevice || mode != sessionMode) + if (driverName != sessionDevice || mode != conf_dev_mode) { MsgBox::Show(NULL, L_S(STR_PAGE_MSG, S_ID(IDS_MSG_NOT_COMPATIBLE), "Session File is not compatible with current device or mode!"), this); return false; @@ -774,23 +777,71 @@ namespace pv for (unsigned int i = 0; i < num_opts; i++) { - const struct sr_config_info *const info = _device_agent->get_config_info(options[i]); + const struct sr_config_info *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())); - else if (info->datatype == SR_T_UINT64) - _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())); - else if (info->datatype == SR_T_FLOAT) - _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())); + GVariant *gvar = NULL; + + //dsv_info("read key:'%s'", info->name); + + if (info->datatype == SR_T_BOOL){ + gvar = g_variant_new_boolean(sessionObj[info->name].toInt()); + } + else if (info->datatype == SR_T_UINT64){ + //from string text. + gvar = g_variant_new_uint64(sessionObj[info->name].toString().toULongLong()); + //dsv_info("uint64:'%s',%llu", info->name, g_variant_get_uint64(gvar)); + } + else if (info->datatype == SR_T_UINT8){ + if (sessionObj[info->name].toString() != "") + gvar = g_variant_new_byte(sessionObj[info->name].toString().toUInt()); + else + gvar = g_variant_new_byte(sessionObj[info->name].toInt()); + //dsv_info("uint8:'%s',%d", info->name,g_variant_get_byte(gvar)); + } + else if (info->datatype == SR_T_INT16){ + gvar = g_variant_new_int16(sessionObj[info->name].toInt()); + } + else if (info->datatype == SR_T_FLOAT){ + if (sessionObj[info->name].toString() != "") + gvar = g_variant_new_double(sessionObj[info->name].toString().toDouble()); + else + gvar = g_variant_new_double(sessionObj[info->name].toDouble()); + //dsv_info("float:'%s',%f", info->name,g_variant_get_double(gvar)); + } + else if (info->datatype == SR_T_CHAR){ + gvar = g_variant_new_string(sessionObj[info->name].toString().toLocal8Bit().data()); + } else if (info->datatype == SR_T_LIST) - _device_agent->set_config(NULL, NULL, info->key, g_variant_new_uint16(sessionObj[info->name].toString().toInt())); + { + int id = 0; + if (format_ver > 2){ + // Is new version format. + id = sessionObj[info->name].toInt(); + } + else{ + const char *fd_key = sessionObj[info->name].toString().toLocal8Bit().data(); + id = ds_dsl_option_value_to_code(conf_dev_mode, info->key, fd_key); + if (id == -1){ + dsv_warn("The lang text parse fail! will use default value, the text:%s", fd_key); + id = 0; //set default value. + } + else{ + dsv_info("key:'%s',text:'%s',convert to code:%d",info->name, fd_key, id); + } + } + gvar = g_variant_new_int16(id); + } + + if (gvar == NULL) + { + dsv_warn("Warning: session file, failed to parse key:'%s'", info->name); + continue; + } + + _device_agent->set_config(NULL, NULL, info->key, gvar); } } @@ -966,7 +1017,7 @@ namespace pv assert(false); } - dsv_info("Store session file: \"%s\"", name.toLocal8Bit().data()); + dsv_info("Store session to file: \"%s\"", name.toLocal8Bit().data()); QFile sessionFile(name); if (!sessionFile.open(QIODevice::WriteOnly | QIODevice::Text)) @@ -1397,8 +1448,9 @@ namespace pv bool MainWindow::confirm_to_store_data() { - if (_session->have_hardware_data()) - { + if (_session->have_hardware_data() && _session->is_first_store_confirm()) + { + // Only popup one time. return MsgBox::Confirm(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_SAVE_CAPDATE), "Save captured data?")); } return false; @@ -1428,21 +1480,27 @@ namespace pv void MainWindow::load_device_config() { - int lang = AppConfig::Instance()._frameOptions.language; int mode = _device_agent->get_work_mode(); if (_device_agent->is_hardware()) { - QString ses_name = genSessionFileName(); + QString ses_name = genSessionFileName(true); + + QFile sf(ses_name); + if (!sf.exists()){ + dsv_info("Try to load the low version session file."); + ses_name = genSessionFileName(false); + } + on_load_session(ses_name); } else if (_device_agent->is_demo()) { QDir dir(GetResourceDir()); if (dir.exists()) - { - QString str = dir.absolutePath() + "/"; - QString ses_name = str + _device_agent->driver_name() + QString::number(mode) + ".dsc"; + { + QString ses_name = dir.absolutePath() + "/" + + _device_agent->driver_name() + QString::number(mode) + ".dsc"; on_load_session(ses_name); } } diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index b33f8fc9..1a0d0869 100644 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -125,12 +125,9 @@ signals: public: //IMainForm void switchLanguage(int language); - - //ISessionCallback - void session_save(); + bool able_to_close(); -private: - void closeEvent(QCloseEvent *event); +private: void setup_ui(); void retranslateUi(); bool eventFilter(QObject *object, QEvent *event); @@ -140,7 +137,7 @@ private: bool confirm_to_store_data(); void update_toolbar_view_status(); bool load_session_json(QJsonDocument json, bool &haveDecoder); - QString genSessionFileName(); + QString genSessionFileName(bool isNewFormat); bool gen_session_json(QJsonObject &sessionVar); void check_session_file_version(); void load_device_config(); @@ -168,6 +165,7 @@ private: void receive_header(); void data_received(); void trigger_message(int msg); + void session_save(); //ISessionDataGetter bool genSessionData(std::string &str); diff --git a/DSView/pv/prop/binding/decoderoptions.cpp b/DSView/pv/prop/binding/decoderoptions.cpp index 222e34ef..6b5d2446 100644 --- a/DSView/pv/prop/binding/decoderoptions.cpp +++ b/DSView/pv/prop/binding/decoderoptions.cpp @@ -50,7 +50,7 @@ DecoderOptions::DecoderOptions(pv::data::DecoderStack* decoder_stack, data::deco assert(dec); for (GSList *l = dec->options; l; l = l->next) - { + { const srd_decoder_option *const opt = (srd_decoder_option*)l->data; diff --git a/DSView/pv/prop/binding/deviceoptions.cpp b/DSView/pv/prop/binding/deviceoptions.cpp index 81eb08dd..804bba20 100644 --- a/DSView/pv/prop/binding/deviceoptions.cpp +++ b/DSView/pv/prop/binding/deviceoptions.cpp @@ -86,15 +86,11 @@ DeviceOptions::DeviceOptions() case SR_CONF_PATTERN_MODE: case SR_CONF_BUFFERSIZE: - case SR_CONF_TRIGGER_SOURCE: - case SR_CONF_FILTER: + case SR_CONF_TRIGGER_SOURCE: case SR_CONF_MAX_HEIGHT: case SR_CONF_MAX_HEIGHT_VALUE: case SR_CONF_PROBE_COUPLING: case SR_CONF_PROBE_EN: - case SR_CONF_OPERATION_MODE: - case SR_CONF_BUFFER_OPTIONS: - case SR_CONF_THRESHOLD: case SR_CONF_ZERO: case SR_CONF_STREAM: case SR_CONF_TEST: @@ -103,14 +99,18 @@ DeviceOptions::DeviceOptions() bind_enum(name, label, key, gvar_list); break; + case SR_CONF_OPERATION_MODE: + case SR_CONF_BUFFER_OPTIONS: + case SR_CONF_THRESHOLD: + case SR_CONF_FILTER: + bind_list(name, label, key, gvar_list); + break; + case SR_CONF_VTH: bind_double(name, label, key, "V", pair(0.0, 5.0), 1, 0.1); break; case SR_CONF_RLE: - bind_bool(name, label, key); - break; - case SR_CONF_RLE_SUPPORT: case SR_CONF_CLOCK_TYPE: case SR_CONF_CLOCK_EDGE: @@ -157,8 +157,9 @@ void DeviceOptions::config_setter(int key, GVariant* value) void DeviceOptions::bind_bool(const QString &name, const QString label, int key) { + QString text = LangResource::Instance()->get_lang_text(STR_PAGE_DSL, label.toLocal8Bit().data(), label.toLocal8Bit().data()); _properties.push_back( - new Bool(name, label, bind(config_getter, key), + new Bool(name, text, bind(config_getter, key), bind(config_setter, key, _1))); } @@ -172,8 +173,12 @@ void DeviceOptions::bind_enum(const QString &name, const QString label, int key, assert(gvar_list); g_variant_iter_init (&iter, gvar_list); + while ((gvar = g_variant_iter_next_value (&iter))) - values.push_back(make_pair(gvar, printer(gvar))); + { + QString v = printer(gvar); + values.push_back(make_pair(gvar, v)); + } _properties.push_back( new Enum(name, label, values, @@ -301,31 +306,62 @@ QString DeviceOptions::print_vdiv(GVariant *const gvar) void DeviceOptions::bind_bandwidths(const QString &name, const QString label, int key, GVariant *const gvar_list, boost::function printer) { - GVariant *gvar; - GVariantIter iter; - std::vector< pair > values; - bool bw_limit = FALSE; + bool bw_limit; + GVariant *gvar_tmp; + GVariant *gvar; + std::vector< pair > values; + struct sr_list_item *plist; - assert(gvar_list); + assert(gvar_list); + plist = (struct sr_list_item*)g_variant_get_uint64(gvar_list); + assert(plist); - GVariant *gvar_tmp = _device_agent->get_config(NULL, NULL, SR_CONF_BANDWIDTH); + bw_limit = FALSE; + 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) return; - g_variant_iter_init (&iter, gvar_list); - while ((gvar = g_variant_iter_next_value (&iter))) - values.push_back(make_pair(gvar, printer(gvar))); + while (plist && plist->id >= 0) + { + QString v = LangResource::Instance()->get_lang_text(STR_PAGE_DSL, plist->name, plist->name); + gvar = g_variant_new_int16(plist->id); + values.push_back(make_pair(gvar, v)); + plist++; + } - _properties.push_back( + _properties.push_back( new Enum(name, label, values, - bind(config_getter, key), - bind(config_setter, key, _1))); + bind(config_getter, key), + bind(config_setter, key, _1))); +} + +void DeviceOptions::bind_list(const QString &name, const QString label, int key, GVariant *const gvar_list) +{ + GVariant *gvar; + std::vector< pair > values; + struct sr_list_item *plist; + + assert(gvar_list); + plist = (struct sr_list_item*)g_variant_get_uint64(gvar_list); + assert(plist); + + while (plist && plist->id >= 0) + { + QString v = LangResource::Instance()->get_lang_text(STR_PAGE_DSL, plist->name, plist->name); + gvar = g_variant_new_int16(plist->id); + values.push_back(make_pair(gvar, v)); + plist++; + } + + _properties.push_back( + new Enum(name, label, values, + 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 cb5757f5..f23be5da 100644 --- a/DSView/pv/prop/binding/deviceoptions.h +++ b/DSView/pv/prop/binding/deviceoptions.h @@ -54,6 +54,8 @@ private: void bind_enum(const QString &name, const QString label, int key, GVariant *const gvar_list, boost::function printer = print_gvariant); + void bind_list(const QString &name, const QString label, int key, GVariant *const gvar_list); + void bind_int(const QString &name, const QString label, int key, QString suffix, boost::optional< std::pair > range); diff --git a/DSView/pv/prop/binding/probeoptions.cpp b/DSView/pv/prop/binding/probeoptions.cpp index ae1fa025..3bbf445a 100644 --- a/DSView/pv/prop/binding/probeoptions.cpp +++ b/DSView/pv/prop/binding/probeoptions.cpp @@ -31,6 +31,7 @@ #include "../../log.h" #include "../../appcontrol.h" #include "../../sigsession.h" +#include "../../ui/langresource.h" using namespace std; @@ -70,7 +71,7 @@ ProbeOptions::ProbeOptions(struct sr_channel *probe) : GVariant *gvar_list = _device_agent->get_config_list(NULL, key); const QString name(info->name); - char *label_char = info->name; + const char *label_char = LangResource::Instance()->get_lang_text(STR_PAGE_DSL, info->name, info->name); const QString label(label_char); switch(key) diff --git a/DSView/pv/prop/enum.cpp b/DSView/pv/prop/enum.cpp index e70f1925..78e2a6f7 100644 --- a/DSView/pv/prop/enum.cpp +++ b/DSView/pv/prop/enum.cpp @@ -47,9 +47,15 @@ Enum::Enum(QString name, QString label, Enum::~Enum() { - for (unsigned int i = 0; i < _values.size(); i++) + for (unsigned int i = 0; i < _values.size(); i++){ if (_values[i].first) g_variant_unref(_values[i].first); + } + + if (_selector != NULL){ + delete _selector; + _selector = NULL; + } } QWidget* Enum::get_widget(QWidget *parent, bool auto_commit) @@ -63,9 +69,11 @@ QWidget* Enum::get_widget(QWidget *parent, bool auto_commit) } _selector = new DsComboBox(parent); + for (unsigned int i = 0; i < _values.size(); i++) { const pair &v = _values[i]; _selector->addItem(v.second, QVariant::fromValue((void*)v.first)); + if (value && g_variant_compare(v.first, value) == 0) _selector->setCurrentIndex(i); } diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index e75ca01e..33c9eb04 100644 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -97,6 +97,8 @@ namespace pv _is_decoding = false; _bClose = false; _callback = NULL; + _capture_time_id = 0; + _confirm_store_time_id = 0; _repeat_wait_prog_step = 10; _device_agent.set_callback(this); @@ -471,7 +473,8 @@ namespace pv _callback->trigger_message(DSV_MSG_START_COLLECT_WORK_PREV); if (exec_capture()) - { + { + _capture_time_id++; _is_working = true; _callback->trigger_message(DSV_MSG_START_COLLECT_WORK); return true; @@ -518,12 +521,12 @@ namespace pv } void SigSession::stop_capture() - { - dsv_info("%s", "Stop collect."); - + { if (!_is_working) return; + dsv_info("%s", "Stop collect."); + if (_bClose) { _is_working = false; @@ -2004,4 +2007,13 @@ namespace pv return false; } + bool SigSession::is_first_store_confirm() + { + if (_capture_time_id != _confirm_store_time_id){ + _confirm_store_time_id = _capture_time_id; + return true; + } + return false; + } + } // namespace pv diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index 4751ee2f..51c23fd5 100644 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -165,6 +165,8 @@ public: return _trigger_pos; } + bool is_first_store_confirm(); + bool get_capture_status(bool &triggered, int &progress); std::set get_data(); @@ -489,6 +491,8 @@ private: bool _is_saving; bool _is_instant; int _device_status; + int _capture_time_id; + int _confirm_store_time_id; ISessionCallback *_callback; diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index 2d539062..909f1e74 100644 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -138,7 +138,7 @@ void FileBar::on_actionOpen_triggered() //open data file AppConfig &app = AppConfig::Instance(); - if (_session->have_hardware_data()){ + if (_session->have_hardware_data() && _session->is_first_store_confirm()){ if (MsgBox::Confirm(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_SAVE_CAPDATE), "Save captured data?"))){ sig_save(); return; diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 3b7bf172..d5461552 100644 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -966,7 +966,7 @@ namespace pv _session->session_save(); ds_device_handle devHandle = (ds_device_handle)_device_selector.currentData().toULongLong(); - if (_session->have_hardware_data()){ + if (_session->have_hardware_data() && _session->is_first_store_confirm()){ if (MsgBox::Confirm(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_SAVE_CAPDATE), "Save captured data?"))) { _updating_device_list = true; diff --git a/DSView/pv/ui/langresource.cpp b/DSView/pv/ui/langresource.cpp index 03bff5a0..1c0c1ecf 100644 --- a/DSView/pv/ui/langresource.cpp +++ b/DSView/pv/ui/langresource.cpp @@ -43,6 +43,7 @@ void Lang_resource_page::Clear() LangResource::LangResource() { _current_page = NULL; + _cur_lang = -1; } LangResource *LangResource::Instance() @@ -60,7 +61,7 @@ LangResource *LangResource::Instance() const char *LangResource::get_lang_key(int lang) { int num = sizeof(lang_id_keys) / sizeof(lang_key_item); - char *lan_name = NULL; + const char *lan_name = NULL; for (int i = 0; i < num; i++) { @@ -85,6 +86,8 @@ bool LangResource::Load(int lang) return false; } + _cur_lang = lang; + Release(); num = sizeof(lange_page_keys) / sizeof(lang_page_item); @@ -94,13 +97,11 @@ bool LangResource::Load(int lang) Lang_resource_page *p = new Lang_resource_page(); p->_id = lange_page_keys[i].id; p->_source = lange_page_keys[i].source; + p->_loaded = false; _pages.push_back(p); - - QString file = GetAppDataDir() + "/lang/" + QString(lan_name) + "/" + p->_source; - load_page(*p, file); } - return false; + return true; } void LangResource::Release() @@ -113,11 +114,33 @@ void LangResource::Release() _pages.clear(); } +void LangResource::load_page(Lang_resource_page &p) +{ + if (p._loaded) + return; + p._loaded = true; + + const char *lan_name = get_lang_key(_cur_lang); + if (lan_name == NULL){ + dsv_err("Can't find language key,lang:%d", _cur_lang); + return; + } + + QString fileNmae(p._source); + QStringList files = fileNmae.split(","); + + for (int x=0; x_id != page_id){ _current_page = NULL; @@ -168,17 +197,21 @@ const char* LangResource::get_lang_text(int page_id, const char *str_id, const c } if (_current_page == NULL){ - dsv_warn("Warning:Cant find language source page:%d", page_id); + if (_cur_lang != LAN_EN) + dsv_warn("Warning:Cant find language source page:%d", page_id); return default_str; } + if (_current_page->_loaded == false) + load_page(*_current_page); + auto it = _current_page->_res.find(std::string(str_id)); if (it != _current_page->_res.end()){ return (*it).second.c_str(); } - else{ + else if(_cur_lang != LAN_EN){ dsv_warn("Warning:Cant't get language text:%s", str_id); } return default_str; -} \ No newline at end of file +} diff --git a/DSView/pv/ui/langresource.h b/DSView/pv/ui/langresource.h index 0301c951..0a20aea9 100644 --- a/DSView/pv/ui/langresource.h +++ b/DSView/pv/ui/langresource.h @@ -30,7 +30,7 @@ struct lang_key_item { int id; - char *name; + const char *name; }; class Lang_resource_page @@ -40,14 +40,15 @@ public: public: int _id; - char *_source; + const char *_source; + bool _loaded; std::map _res; }; struct lang_page_item { int id; - char *source; + const char *source; }; static const struct lang_key_item lang_id_keys[] = @@ -58,11 +59,10 @@ static const struct lang_key_item lang_id_keys[] = static const struct lang_page_item lange_page_keys[] = { - {STR_PAGE_MAIN, "main.json"}, {STR_PAGE_TOOLBAR, "toolbar.json"}, {STR_PAGE_MSG, "msg.json"}, {STR_PAGE_DLG, "dlg.json"}, - {STR_PAGE_DSL, "DSL.json"} + {STR_PAGE_DSL, "dsl_list.json, dsl_label.json, dsl_channel.json"} }; class LangResource @@ -79,11 +79,14 @@ public: private: const char *get_lang_key(int lang); - void load_page(Lang_resource_page &p, QString file); + void load_page(Lang_resource_page &p); + void load_page(Lang_resource_page &p, QString file); + private: std::vector _pages; Lang_resource_page *_current_page; + int _cur_lang; }; #define S_ID(id) #id diff --git a/DSView/pv/ui/msgbox.cpp b/DSView/pv/ui/msgbox.cpp index b579455c..c04468c1 100644 --- a/DSView/pv/ui/msgbox.cpp +++ b/DSView/pv/ui/msgbox.cpp @@ -25,6 +25,7 @@ #include #include "../dsvdef.h" #include "../appcontrol.h" +#include "langresource.h" //QMessageBox::information(NULL, "Title", "Content",QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); //QMessageBox::information(NULL, "Title", "Content",QMessageBox::Yes|QMessageBox::No); @@ -63,7 +64,8 @@ bool MsgBox::Confirm(const QString text, QWidget *parent) parent = AppControl::Instance()->GetTopWindow(); } - pv::dialogs::DSMessageBox msg(parent, "Question"); + const char *title = L_S(STR_PAGE_MSG, S_ID(IDS_MSG_BOX_CONFIRM), "Confirm"); + pv::dialogs::DSMessageBox msg(parent, title); msg.mBox()->setText(str); msg.mBox()->setStandardButtons(QMessageBox::Yes | QMessageBox::No); msg.mBox()->setIcon(QMessageBox::Question); diff --git a/DSView/pv/ui/string_ids.h b/DSView/pv/ui/string_ids.h index 6a6660c1..6e86d157 100644 --- a/DSView/pv/ui/string_ids.h +++ b/DSView/pv/ui/string_ids.h @@ -22,10 +22,9 @@ #ifndef STRING_IDS_H #define STRING_IDS_H -#define STR_PAGE_MAIN 1 -#define STR_PAGE_MSG 2 -#define STR_PAGE_TOOLBAR 3 -#define STR_PAGE_DLG 4 +#define STR_PAGE_MSG 1 +#define STR_PAGE_TOOLBAR 2 +#define STR_PAGE_DLG 3 #define STR_PAGE_DSL 100 // xx diff --git a/lang/cn/dsl.txt b/lang/cn/dsl.txt deleted file mode 100644 index 8b137891..00000000 --- a/lang/cn/dsl.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lang/cn/dsl_channel.json b/lang/cn/dsl_channel.json new file mode 100644 index 00000000..e1125112 --- /dev/null +++ b/lang/cn/dsl_channel.json @@ -0,0 +1,118 @@ +[ + { + "id": "Use 16 Channels (Max 20MHz)", + "text": "使用16个通道(最大采样率 20MHz)" + }, + { + "id": "Use 12 Channels (Max 25MHz)", + "text": "使用12个通道(最大采样率 25MHz)" + }, + { + "id": "Use 6 Channels (Max 50MHz)", + "text": "使用6个通道(最大采样率 50MHz)" + }, + { + "id": "Use 3 Channels (Max 100MHz)", + "text": "使用3个通道(最大采样率 100MHz)" + }, + { + "id": "Use 16 Channels (Max 20MHz)", + "text": "使用16个通道(最大采样率 20MHz)" + }, + { + "id": "Use 12 Channels (Max 25MHz)", + "text": "使用12个通道(最大采样率 25MHz)" + }, + { + "id": "Use 6 Channels (Max 50MHz)", + "text": "使用6个通道(最大采样率 50MHz)" + }, + { + "id": "Use 3 Channels (Max 100MHz)", + "text": "使用3个通道(最大采样率 100MHz)" + }, + { + "id": "Use 32 Channels (Max 10MHz)", + "text": "使用32个通道(最大采样率 10MHz)" + }, + { + "id": "Use 16 Channels (Max 20MHz)", + "text": "使用16个通道(最大采样率 20MHz)" + }, + { + "id": "Use 12 Channels (Max 25MHz)", + "text": "使用12个通道(最大采样率 25MHz)" + }, + { + "id": "Use 6 Channels (Max 50MHz)", + "text": "使用6个通道(最大采样率 50MHz)" + }, + { + "id": "Use 3 Channels (Max 100MHz)", + "text": "使用3个通道(最大采样率 100MHz)" + }, + { + "id": "Use 32 Channels (Max 50MHz)", + "text": "使用32个通道(最大采样率 50MHz)" + }, + { + "id": "Use 30 Channels (Max 100MHz)", + "text": "使用30个通道(最大采样率 100MHz)" + }, + { + "id": "Use 12 Channels (Max 250MHz)", + "text": "使用12个通道(最大采样率 250MHz)" + }, + { + "id": "Use 16 Channels (Max 125MHz)", + "text": "使用16个通道(最大采样率 125MHz)" + }, + { + "id": "Use 12 Channels (Max 250MHz)", + "text": "使用12个通道(最大采样率 250MHz)" + }, + { + "id": "Use 6 Channels (Max 500MHz)", + "text": "使用6个通道(最大采样率 500MHz)" + }, + { + "id": "Use 3 Channels (Max 1GHz)", + "text": "使用3个通道(最大采样率 1GHz)" + }, + { + "id": "Use Channels 0~15 (Max 100MHz)", + "text": "使用通道 0~15 (最大采样率 100MHz)" + }, + { + "id": "Use Channels 0~7 (Max 200MHz)", + "text": "使用通道 0~7 (最大采样率 200MHz)" + }, + { + "id": "Use Channels 0~3 (Max 400MHz)", + "text": "使用通道 0~3 (最大采样率 400MHz)" + }, + { + "id": "Use Channels 0~31 (Max 250MHz)", + "text": "使用通道 0~31 (最大采样率 250MHz)" + }, + { + "id": "Use Channels 0~15 (Max 500MHz)", + "text": "使用通道 0~15 (最大采样率 500MHz)" + }, + { + "id": "Use Channels 0~7 (Max 1GHz)", + "text": "使用通道 0~7 (最大采样率 1GHz)" + }, + { + "id": "Use Channels 0~1 (Max 10MHz)", + "text": "使用通道 0~1 (最大采样率 10MHz)" + }, + { + "id": "Use Channels 0~1 (Max 200MHz)", + "text": "使用通道 0~1 (最大采样率 200MHz)" + }, + { + "id": "Use Channels 0~1 (Max 1GHz)", + "text": "使用通道 0~1 (最大采样率 1GHz)" + } +] \ No newline at end of file diff --git a/lang/cn/dsl_label.json b/lang/cn/dsl_label.json new file mode 100644 index 00000000..65172a64 --- /dev/null +++ b/lang/cn/dsl_label.json @@ -0,0 +1,150 @@ +[ + { + "id": "Connection", + "text": "连接" + }, + { + "id": "Serial communication", + "text": "串口通讯" + }, + { + "id": "Sample rate", + "text": "采样率" + }, + { + "id": "Sample depth", + "text": "采样深度" + }, + { + "id": "Sample count", + "text": "实际采样数" + }, + { + "id": "Using External Clock", + "text": "使用外部输入时钟采样" + }, + { + "id": "Using Clock Negedge", + "text": "使用时钟下降沿采样" + }, + { + "id": "Pre-trigger capture ratio", + "text": "触发前采样比例" + }, + { + "id": "Pattern mode", + "text": "信号模式" + }, + { + "id": "Run Length Encoding", + "text": "RLE编码" + }, + { + "id": "Wait Buffer Upload", + "text": "上传已采集数据" + }, + { + "id": "Trigger slope", + "text": "触发沿" + }, + { + "id": "Trigger source", + "text": "触发源" + }, + { + "id": "Trigger channel", + "text": "触发通道" + }, + { + "id": "Horizontal trigger position", + "text": "触发位置" + }, + { + "id": "Trigger hold off", + "text": "触发释抑时间" + }, + { + "id": "Trigger margin", + "text": "触发灵敏度" + }, + { + "id": "Buffer size", + "text": "缓存大小" + }, + { + "id": "Time base", + "text": "时基" + }, + { + "id": "Max Height", + "text": "最大高度" + }, + { + "id": "Max Height value", + "text": "最大高度值" + }, + { + "id": "Filter Targets", + "text": "滤波器设置" + }, + { + "id": "Datalog", + "text": "数据记录" + }, + { + "id": "Operation Mode", + "text": "运行模式" + }, + { + "id": "Stop Options", + "text": "停止选项" + }, + { + "id": "Channel Mode", + "text": "通道模式" + }, + { + "id": "Threshold Levels", + "text": "阈值电压" + }, + { + "id": "Threshold Level", + "text": "阈值电压" + }, + { + "id": "Enable RLE Compress", + "text": "RLE硬件压缩" + }, + { + "id": "Bandwidth Limit", + "text": "带宽限制" + }, + { + "id": "Coupling", + "text": "耦合" + }, + { + "id": "Volts/div", + "text": "电压/格" + }, + { + "id": "Probe Factor", + "text": "探头衰减" + }, + { + "id": "Map Default", + "text": "默认电压" + }, + { + "id": "Map Unit", + "text": "对应单位" + }, + { + "id": "Map Min", + "text": "对应最小值" + }, + { + "id": "Map Max", + "text": "对应最大值" + } +] \ No newline at end of file diff --git a/lang/cn/dsl_list.json b/lang/cn/dsl_list.json new file mode 100644 index 00000000..be453cbb --- /dev/null +++ b/lang/cn/dsl_list.json @@ -0,0 +1,50 @@ +[ + { + "id": "Buffer Mode", + "text": "Buffer模式" + }, + { + "id": "Stream Mode", + "text": "Stream模式" + }, + { + "id": "Internal Test", + "text": "内部测试" + }, + { + "id": "External Test", + "text": "外部测试" + }, + { + "id": "DRAM Loopback Test", + "text": "内存回环测试" + }, + { + "id": "Stop immediately", + "text": "立即停止" + }, + { + "id": "Upload captured data", + "text": "上传已采集的数据" + }, + { + "id": "None", + "text": "无" + }, + { + "id": "1 Sample Clock", + "text": "1个采样周期" + }, + { + "id": "Normal", + "text": "正常" + }, + { + "id": "Full Bandwidth", + "text": "全带宽" + }, + { + "id": "20MHz", + "text": "20MHz" + } +] \ No newline at end of file diff --git a/lang/cn/msg.json b/lang/cn/msg.json index 5762f4e2..3b5ebdba 100644 --- a/lang/cn/msg.json +++ b/lang/cn/msg.json @@ -346,5 +346,9 @@ { "id": "IDS_MSG_MESSAGE", "text": "消息" + }, + { + "id": "IDS_MSG_BOX_CONFIRM", + "text": "确认" } ] \ No newline at end of file diff --git a/lang/en/device.json b/lang/en/device.json deleted file mode 100644 index b8e07c0b..00000000 --- a/lang/en/device.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "id": "vvv", - "text": "xxx" - }, - { - "id": "vvv1", - "text": "xxx1" - } -] \ No newline at end of file diff --git a/lang/en/msg.json b/lang/en/msg.json index ae88d59b..252e601a 100644 --- a/lang/en/msg.json +++ b/lang/en/msg.json @@ -347,5 +347,9 @@ { "id": "IDS_MSG_MESSAGE", "text": "Message" + }, + { + "id": "IDS_MSG_BOX_CONFIRM", + "text": "Confirm" } ] \ No newline at end of file diff --git a/libsigrok4DSL/hardware/DSL/dscope.c b/libsigrok4DSL/hardware/DSL/dscope.c index e2b34b81..ed5d38cc 100644 --- a/libsigrok4DSL/hardware/DSL/dscope.c +++ b/libsigrok4DSL/hardware/DSL/dscope.c @@ -42,17 +42,19 @@ enum { BW_20M = 1, }; -static const char *opmodes[] = { - "Normal", - "Internal Test", +static const struct sr_list_item opmode_list[] = { + {OP_NORMAL,"Normal"}, + {OP_INTEST,"Internal Test"}, + {-1, NULL}, }; -static const char *bandwidths[] = { - "Full Bandwidth", - "20MHz", +static const struct sr_list_item bandwidth_list[] = { + {BW_FULL,"Full Bandwidth"}, + {BW_20M,"20MHz"}, + {-1, NULL}, }; -static struct lang_text_map_item opmodes_map[] = +static struct lang_text_map_item lang_text_map[] = { {SR_CONF_OPERATION_MODE, OP_NORMAL, "Normal", "正常"}, {SR_CONF_OPERATION_MODE, OP_INTEST, "Internal Test", "内部测试"}, @@ -123,8 +125,9 @@ static struct DSL_context *DSCope_dev_new(const struct DSL_profile *prof) return NULL; } - for (i = 0; i < ARRAY_SIZE(channel_modes); i++) + for (i = 0; i < ARRAY_SIZE(channel_modes); i++){ assert(channel_modes[i].id == i); + } devc->channel = NULL; devc->profile = prof; @@ -1031,6 +1034,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, unsigned int i; int ret; struct DSL_context *devc; + uint64_t vgain_default; assert(sdi); assert(sdi->priv); @@ -1041,43 +1045,27 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, if (ret != SR_OK) { switch (id) { case SR_CONF_OPERATION_MODE: - if (!sdi) - return SR_ERR; - *data = g_variant_new_string(opmodes[devc->op_mode]); + *data = g_variant_new_int16(devc->op_mode); break; case SR_CONF_BANDWIDTH_LIMIT: - if (!sdi) - return SR_ERR; - *data = g_variant_new_string(bandwidths[devc->bw_limit]); + *data = g_variant_new_int16(devc->bw_limit); break; case SR_CONF_CALI: - if (!sdi) - return SR_ERR; *data = g_variant_new_boolean(devc->cali); break; case SR_CONF_TEST: - if (!sdi) - return SR_ERR; *data = g_variant_new_boolean(FALSE); break; case SR_CONF_STREAM: - if (!sdi) - return SR_ERR; *data = g_variant_new_boolean(devc->stream); break; case SR_CONF_MAX_DSO_SAMPLERATE: - if (!sdi) - return SR_ERR; *data = g_variant_new_uint64(channel_modes[devc->ch_mode].max_samplerate); break; case SR_CONF_MAX_DSO_SAMPLELIMITS: - if (!sdi) - return SR_ERR; *data = g_variant_new_uint64(devc->profile->dev_caps.dso_depth); break; case SR_CONF_HW_DEPTH: - if (!sdi) - return SR_ERR; *data = g_variant_new_uint64(devc->profile->dev_caps.hw_depth / channel_modes[devc->ch_mode].unit_bits); break; case SR_CONF_PROBE_VGAIN: @@ -1086,8 +1074,6 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_uint64(dso_vga(ch)>>8); break; case SR_CONF_PROBE_COMB_COMP_EN: - if (!sdi) - return SR_ERR; *data = g_variant_new_boolean((devc->profile->dev_caps.feature_caps & CAPS_FEATURE_HMCAD1511) != 0); break; case SR_CONF_PROBE_COMB_COMP: @@ -1107,9 +1093,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, } break; case SR_CONF_PROBE_VGAIN_RANGE: - if (!sdi) - return SR_ERR; - uint64_t vgain_default = 0; + vgain_default = 0; for (i = 0; vga_defaults[i].id; i++) { if (vga_defaults[i].id == devc->profile->dev_caps.vga_id && vga_defaults[i].key == ch->vdiv) { @@ -1141,8 +1125,6 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_uint16(get_default_preoff(sdi, ch)); break; case SR_CONF_PROBE_PREOFF_MARGIN: - if (!sdi) - return SR_ERR; *data = g_variant_new_uint16(devc->profile->dev_caps.default_pwmmargin); break; case SR_CONF_PROBE_MAP_DEFAULT: @@ -1166,8 +1148,6 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_double(ch->map_max); break; case SR_CONF_VLD_CH_NUM: - if (!sdi) - return SR_ERR; *data = g_variant_new_int16(channel_modes[devc->ch_mode].vld_num); break; default: @@ -1190,6 +1170,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, struct ctl_wr_cmd wr_cmd; unsigned int i; GSList *l; + int nv; assert(sdi); assert(sdi->priv); @@ -1367,33 +1348,40 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, dsl_adjust_probes(sdi, num_probes); dsl_adjust_samplerate(devc); sr_dbg("%s: setting mode to %d", __func__, sdi->mode); - } else if (id == SR_CONF_OPERATION_MODE) { - stropt = g_variant_get_string(data, NULL); - if (!strcmp(stropt, opmodes[OP_NORMAL])) { + } + else if (id == SR_CONF_OPERATION_MODE) { + nv = g_variant_get_int16(data); + if (nv == OP_NORMAL) { devc->op_mode = OP_NORMAL; devc->test_mode = SR_TEST_NONE; - } else if (!strcmp(stropt, opmodes[OP_INTEST])) { + } + else if (nv == OP_INTEST) { devc->op_mode = OP_INTEST; devc->test_mode = SR_TEST_INTERNAL; - } else { + } + else { ret = SR_ERR; } sr_dbg("%s: setting pattern to %d", __func__, devc->op_mode); - } else if (id == SR_CONF_BANDWIDTH_LIMIT) { - stropt = g_variant_get_string(data, NULL); - if (!strcmp(stropt, bandwidths[BW_FULL])) { + } + else if (id == SR_CONF_BANDWIDTH_LIMIT) { + nv = g_variant_get_int16(data); + if (nv == BW_FULL) { devc->bw_limit = BW_FULL; dsl_wr_reg(sdi, CTR0_ADDR, bmBW20M_CLR); - } else if (!strcmp(stropt, bandwidths[BW_20M])) { + } + else if (nv == BW_20M) { devc->bw_limit = BW_20M; dsl_wr_reg(sdi, CTR0_ADDR, bmBW20M_SET); - } else { + } + else { ret = SR_ERR; } sr_dbg("%s: setting bandwidth limit to %d", __func__, devc->bw_limit); - } else if (id == SR_CONF_PROBE_EN) { + } + else if (id == SR_CONF_PROBE_EN) { ch->enabled = g_variant_get_boolean(data); if (sdi->mode == DSO) { @@ -1689,6 +1677,9 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, { struct DSL_context *devc; + assert(sdi); + assert(sdi->priv); + (void)cg; devc = sdi->priv; @@ -1697,8 +1688,6 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, switch (key) { case SR_CONF_DEVICE_OPTIONS: -// *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, -// hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); *data = g_variant_new_from_data(G_VARIANT_TYPE("ai"), hwoptions, ARRAY_SIZE(hwoptions)*sizeof(int32_t), TRUE, NULL, NULL); break; @@ -1710,11 +1699,11 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_from_data(G_VARIANT_TYPE("ai"), sessions_daq, ARRAY_SIZE(sessions_daq)*sizeof(int32_t), TRUE, NULL, NULL); break; - case SR_CONF_OPERATION_MODE: - *data = g_variant_new_strv(opmodes, ARRAY_SIZE(opmodes)); + case SR_CONF_OPERATION_MODE: + *data = g_variant_new_uint64((uint64_t)&opmode_list); break; - case SR_CONF_BANDWIDTH_LIMIT: - *data = g_variant_new_strv(bandwidths, ARRAY_SIZE(bandwidths)); + case SR_CONF_BANDWIDTH_LIMIT: + *data = g_variant_new_uint64((uint64_t)&bandwidth_list); break; default: return SR_ERR_NA; @@ -2088,6 +2077,16 @@ static int dev_status_get(const struct sr_dev_inst *sdi, struct sr_status *statu return ret; } +SR_PRIV int sr_dscope_option_value_to_code(const struct sr_dev_inst *sdi, int config_id, const char *value) +{ + int num; + + assert(sdi); + + num = sizeof(lang_text_map) / sizeof(lang_text_map[0]); + return sr_option_value_to_code(config_id, value, &lang_text_map, num); +} + SR_PRIV struct sr_dev_driver DSCope_driver_info = { .name = "DSCope", .longname = "DSCope (generic driver for DScope oscilloscope)", diff --git a/libsigrok4DSL/hardware/DSL/dsl.c b/libsigrok4DSL/hardware/DSL/dsl.c index 7e92f12b..2165a24d 100644 --- a/libsigrok4DSL/hardware/DSL/dsl.c +++ b/libsigrok4DSL/hardware/DSL/dsl.c @@ -2487,3 +2487,30 @@ SR_PRIV int dsl_destroy_device(const struct sr_dev_inst *sdi) sr_dev_inst_free(sdi); } + +SR_PRIV int sr_option_value_to_code(int config_id, const char *value, const struct lang_text_map_item *array, int num) +{ + int i; + struct lang_text_map_item *p; + + assert(array); + assert(value); + + p = array; + + for (i = 0; i < num; i++){ + if (p->config_id == config_id){ + if (strcmp(value, p->en_name) == 0){ + return p->id; + } + if (p->cn_name != NULL && strcmp(value, p->cn_name) == 0){ + return p->id; + } + } + p++; + } + + sr_err("Unkown lang text value:%s,config id:%d", value, config_id); + + return -1; +} diff --git a/libsigrok4DSL/hardware/DSL/dsl.h b/libsigrok4DSL/hardware/DSL/dsl.h index 7226c8ea..b7503fc4 100644 --- a/libsigrok4DSL/hardware/DSL/dsl.h +++ b/libsigrok4DSL/hardware/DSL/dsl.h @@ -364,75 +364,75 @@ struct DSL_channels { static const struct DSL_channels channel_modes[] = { // LA Stream {DSL_STREAM20x16, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 16, 1, SR_KHZ(10), SR_MHZ(20), - SR_KHZ(10), SR_MHZ(100), 1, "Use 16 Channels (Max 20MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use 16 Channels (Max 20MHz)"}, {DSL_STREAM25x12, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 12, 1, SR_KHZ(10), SR_MHZ(25), - SR_KHZ(10), SR_MHZ(100), 1, "Use 12 Channels (Max 25MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use 12 Channels (Max 25MHz)"}, {DSL_STREAM50x6, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 6, 1, SR_KHZ(10), SR_MHZ(50), - SR_KHZ(10), SR_MHZ(100), 1, "Use 6 Channels (Max 50MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use 6 Channels (Max 50MHz)"}, {DSL_STREAM100x3, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 3, 1, SR_KHZ(10), SR_MHZ(100), - SR_KHZ(10), SR_MHZ(100), 1, "Use 3 Channels (Max 100MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use 3 Channels (Max 100MHz)"}, {DSL_STREAM20x16_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 16, 1, SR_KHZ(10), SR_MHZ(20), - SR_KHZ(10), SR_MHZ(500), 5, "Use 16 Channels (Max 20MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 16 Channels (Max 20MHz)"}, {DSL_STREAM25x12_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 12, 1, SR_KHZ(10), SR_MHZ(25), - SR_KHZ(10), SR_MHZ(500), 5, "Use 12 Channels (Max 25MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 12 Channels (Max 25MHz)"}, {DSL_STREAM50x6_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 6, 1, SR_KHZ(10), SR_MHZ(50), - SR_KHZ(10), SR_MHZ(500), 5, "Use 6 Channels (Max 50MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 6 Channels (Max 50MHz)"}, {DSL_STREAM100x3_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 3, 1, SR_KHZ(10), SR_MHZ(100), - SR_KHZ(10), SR_MHZ(500), 5, "Use 3 Channels (Max 100MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 3 Channels (Max 100MHz)"}, {DSL_STREAM10x32_32_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 32, 32, 1, SR_KHZ(10), SR_MHZ(10), - SR_KHZ(10), SR_MHZ(500), 5, "Use 32 Channels (Max 10MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 32 Channels (Max 10MHz)"}, {DSL_STREAM20x16_32_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 32, 16, 1, SR_KHZ(10), SR_MHZ(20), - SR_KHZ(10), SR_MHZ(500), 5, "Use 16 Channels (Max 20MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 16 Channels (Max 20MHz)"}, {DSL_STREAM25x12_32_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 32, 12, 1, SR_KHZ(10), SR_MHZ(25), - SR_KHZ(10), SR_MHZ(500), 5, "Use 12 Channels (Max 25MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 12 Channels (Max 25MHz)"}, {DSL_STREAM50x6_32_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 32, 6, 1, SR_KHZ(10), SR_MHZ(50), - SR_KHZ(10), SR_MHZ(500), 5, "Use 6 Channels (Max 50MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 6 Channels (Max 50MHz)"}, {DSL_STREAM100x3_32_3DN2, LOGIC, SR_CHANNEL_LOGIC, TRUE, 32, 3, 1, SR_KHZ(10), SR_MHZ(100), - SR_KHZ(10), SR_MHZ(500), 5, "Use 3 Channels (Max 100MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 3 Channels (Max 100MHz)"}, {DSL_STREAM50x32, LOGIC, SR_CHANNEL_LOGIC, TRUE, 32, 32, 1, SR_KHZ(10), SR_MHZ(50), - SR_KHZ(10), SR_MHZ(500), 5, "Use 32 Channels (Max 50MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 32 Channels (Max 50MHz)"}, {DSL_STREAM100x30, LOGIC, SR_CHANNEL_LOGIC, TRUE, 32, 30, 1, SR_KHZ(10), SR_MHZ(100), - SR_KHZ(10), SR_MHZ(500), 5, "Use 30 Channels (Max 100MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 30 Channels (Max 100MHz)"}, {DSL_STREAM250x12, LOGIC, SR_CHANNEL_LOGIC, TRUE, 32, 12, 1, SR_KHZ(10), SR_MHZ(250), - SR_KHZ(10), SR_MHZ(500), 5, "Use 12 Channels (Max 250MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 12 Channels (Max 250MHz)"}, {DSL_STREAM125x16_16, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 16, 1, SR_KHZ(10), SR_MHZ(125), - SR_KHZ(10), SR_MHZ(500), 5, "Use 16 Channels (Max 125MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 16 Channels (Max 125MHz)"}, {DSL_STREAM250x12_16, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 12, 1, SR_KHZ(10), SR_MHZ(250), - SR_KHZ(10), SR_MHZ(500), 5, "Use 12 Channels (Max 250MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 12 Channels (Max 250MHz)"}, {DSL_STREAM500x6, LOGIC, SR_CHANNEL_LOGIC, TRUE, 16, 6, 1, SR_KHZ(10), SR_MHZ(500), - SR_KHZ(10), SR_MHZ(500), 5, "Use 6 Channels (Max 500MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 6 Channels (Max 500MHz)"}, {DSL_STREAM1000x3, LOGIC, SR_CHANNEL_LOGIC, TRUE, 8, 3, 1, SR_KHZ(10), SR_GHZ(1), - SR_KHZ(10), SR_MHZ(500), 5, "Use 3 Channels (Max 1GHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use 3 Channels (Max 1GHz)"}, // LA Buffer {DSL_BUFFER100x16, LOGIC, SR_CHANNEL_LOGIC, FALSE, 16, 16, 1, SR_KHZ(10), SR_MHZ(100), - SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~15 (Max 100MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~15 (Max 100MHz)"}, {DSL_BUFFER200x8, LOGIC, SR_CHANNEL_LOGIC, FALSE, 8, 8, 1, SR_KHZ(10), SR_MHZ(200), - SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~7 (Max 200MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~7 (Max 200MHz)"}, {DSL_BUFFER400x4, LOGIC, SR_CHANNEL_LOGIC, FALSE, 4, 4, 1, SR_KHZ(10), SR_MHZ(400), - SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~3 (Max 400MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~3 (Max 400MHz)"}, {DSL_BUFFER250x32, LOGIC, SR_CHANNEL_LOGIC, FALSE, 32, 32, 1, SR_KHZ(10), SR_MHZ(250), - SR_KHZ(10), SR_MHZ(500), 5, "Use Channels 0~31 (Max 250MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use Channels 0~31 (Max 250MHz)"}, {DSL_BUFFER500x16, LOGIC, SR_CHANNEL_LOGIC, FALSE, 16, 16, 1, SR_KHZ(10), SR_MHZ(500), - SR_KHZ(10), SR_MHZ(500), 5, "Use Channels 0~15 (Max 500MHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use Channels 0~15 (Max 500MHz)"}, {DSL_BUFFER1000x8, LOGIC, SR_CHANNEL_LOGIC, FALSE, 8, 8, 1, SR_KHZ(10), SR_GHZ(1), - SR_KHZ(10), SR_MHZ(500), 5, "Use Channels 0~7 (Max 1GHz)"}, + SR_KHZ(10), SR_MHZ(500), 5, "Use Channels 0~7 (Max 1GHz)"}, // DAQ {DSL_ANALOG10x2, ANALOG, SR_CHANNEL_ANALOG, TRUE, 2, 2, 8, SR_HZ(10), SR_MHZ(10), - SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~1 (Max 10MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~1 (Max 10MHz)"}, {DSL_ANALOG10x2_500, ANALOG, SR_CHANNEL_ANALOG, TRUE, 2, 2, 8, SR_HZ(10), SR_MHZ(10), - SR_KHZ(10), SR_MHZ(500), 1, "Use Channels 0~1 (Max 10MHz)"}, + SR_KHZ(10), SR_MHZ(500), 1, "Use Channels 0~1 (Max 10MHz)"}, // OSC {DSL_DSO200x2, DSO, SR_CHANNEL_DSO, FALSE, 2, 2, 8, SR_KHZ(10), SR_MHZ(200), - SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~1 (Max 200MHz)"}, + SR_KHZ(10), SR_MHZ(100), 1, "Use Channels 0~1 (Max 200MHz)"}, {DSL_DSO1000x2, DSO, SR_CHANNEL_DSO, FALSE, 2, 2, 8, SR_KHZ(10), SR_GHZ(1), - SR_KHZ(10), SR_MHZ(500), 1, "Use Channels 0~1 (Max 1GHz)"} + SR_KHZ(10), SR_MHZ(500), 1, "Use Channels 0~1 (Max 1GHz)"} }; /* hardware Capabilities */ diff --git a/libsigrok4DSL/hardware/DSL/dslogic.c b/libsigrok4DSL/hardware/DSL/dslogic.c index 4db45030..f21c10fb 100644 --- a/libsigrok4DSL/hardware/DSL/dslogic.c +++ b/libsigrok4DSL/hardware/DSL/dslogic.c @@ -61,30 +61,37 @@ enum DSLOGIC_BUFFER_OPT_MODE SR_BUF_UPLOAD = 1, }; -static const char *opmodes[] = { - "Buffer Mode", - "Stream Mode", - "Internal Test", - "External Test", - "DRAM Loopback Test", +static const struct sr_list_item opmode_list[] = { + {OP_BUFFER,"Buffer Mode"}, + {OP_STREAM,"Stream Mode"}, + {OP_INTEST,"Internal Test"}, + {OP_EXTEST,"External Test"}, + {OP_LPTEST,"DRAM Loopback Test"}, + {-1, NULL}, }; -static const char *bufoptions[] = { - "Stop immediately", - "Upload captured data", +static const struct sr_list_item bufoption_list[] = { + {SR_BUF_STOP, "Stop immediately"}, + {SR_BUF_UPLOAD,"Upload captured data"}, + {-1, NULL}, }; -static const char *thresholds[] = { - "1.8/2.5/3.3V Level", - "5.0V Level", +static const struct sr_list_item threshold_list[] = { + {SR_TH_3V3, "1.8/2.5/3.3V Level"}, + {SR_TH_5V0,"5.0V Level"}, + {-1, NULL}, }; -static const char *filters[] = { - "None", - "1 Sample Clock", +static const struct sr_list_item filter_list[] = { + {SR_FILTER_NONE, "None"}, + {SR_FILTER_1T,"1 Sample Clock"}, + {-1, NULL}, }; -static struct lang_text_map_item opmodes_map[] = +#define CHANNEL_MODE_LIST_LEN 25 +static struct sr_list_item channel_mode_list[CHANNEL_MODE_LIST_LEN]; + +static struct lang_text_map_item lang_text_map[] = { {SR_CONF_OPERATION_MODE, OP_BUFFER, "Buffer Mode", "Buffer模式"}, {SR_CONF_OPERATION_MODE, OP_STREAM, "Stream Mode", "Stream模式"}, @@ -102,6 +109,44 @@ static struct lang_text_map_item opmodes_map[] = {SR_CONF_FILTER, SR_FILTER_1T, "1 Sample Clock", "1个采样周期"}, }; +static struct sr_list_item channel_mode_cn_map[] = { + {DSL_STREAM20x16, "使用16个通道(最大采样率 20MHz)"}, + {DSL_STREAM25x12, "使用12个通道(最大采样率 25MHz)"}, + {DSL_STREAM50x6, "使用6个通道(最大采样率 50MHz)"}, + {DSL_STREAM100x3, "使用3个通道(最大采样率 100MHz)"}, + {DSL_STREAM20x16_3DN2, "使用16个通道(最大采样率 20MHz)"}, + {DSL_STREAM25x12_3DN2, "使用12个通道(最大采样率 25MHz)"}, + {DSL_STREAM50x6_3DN2, "使用6个通道(最大采样率 50MHz)"}, + {DSL_STREAM100x3_3DN2,"使用3个通道(最大采样率 100MHz)"}, + {DSL_STREAM10x32_32_3DN2, "使用32个通道(最大采样率 10MHz)"}, + {DSL_STREAM20x16_32_3DN2, "使用16个通道(最大采样率 20MHz)"}, + {DSL_STREAM25x12_32_3DN2, "使用12个通道(最大采样率 25MHz)"}, + {DSL_STREAM50x6_32_3DN2, "使用6个通道(最大采样率 50MHz)"}, + {DSL_STREAM100x3_32_3DN2, "使用3个通道(最大采样率 100MHz)"}, + {DSL_STREAM50x32, "使用32个通道(最大采样率 50MHz)"}, + {DSL_STREAM100x30, "使用30个通道(最大采样率 100MHz)"}, + {DSL_STREAM250x12, "使用12个通道(最大采样率 250MHz)"}, + {DSL_STREAM125x16_16, "使用16个通道(最大采样率 125MHz)"}, + {DSL_STREAM250x12_16, "使用12个通道(最大采样率 250MHz)"}, + {DSL_STREAM500x6, "使用6个通道(最大采样率 500MHz)"}, + {DSL_STREAM1000x3, "使用3个通道(最大采样率 1GHz)"}, + // LA Buffer + {DSL_BUFFER100x16, "使用通道 0~15 (最大采样率 100MHz)"}, + {DSL_BUFFER200x8, "使用通道 0~7 (最大采样率 200MHz)"}, + {DSL_BUFFER400x4, "使用通道 0~3 (最大采样率 400MHz)"}, + {DSL_BUFFER250x32, "使用通道 0~31 (最大采样率 250MHz)"}, + {DSL_BUFFER500x16, "使用通道 0~15 (最大采样率 500MHz)"}, + {DSL_BUFFER1000x8, "使用通道 0~7 (最大采样率 1GHz)"}, + + // DAQ + {DSL_ANALOG10x2, "使用通道 0~1 (最大采样率 10MHz)"}, + {DSL_ANALOG10x2_500, "使用通道 0~1 (最大采样率 10MHz)"}, + + // OSC + {DSL_DSO200x2, "使用通道 0~1 (最大采样率 200MHz)"}, + {DSL_DSO1000x2, "使用通道 0~1 (最大采样率 1GHz)"} +}; + static const int32_t hwoptions[] = { SR_CONF_OPERATION_MODE, SR_CONF_BUFFER_OPTIONS, @@ -179,8 +224,10 @@ static struct DSL_context *DSLogic_dev_new(const struct DSL_profile *prof) return NULL; } - for (i = 0; i < ARRAY_SIZE(channel_modes); i++) - assert(channel_modes[i].id == i); + for (i = 0; i < ARRAY_SIZE(channel_modes); i++){ + if(channel_modes[i].id != i) + assert(0); + } devc->channel = NULL; devc->profile = prof; @@ -586,28 +633,18 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, if (ret != SR_OK) { switch (id) { case SR_CONF_OPERATION_MODE: - if (!sdi) - return SR_ERR; - *data = g_variant_new_string(opmodes[devc->op_mode]); + *data = g_variant_new_int16(devc->op_mode); break; case SR_CONF_FILTER: - if (!sdi) - return SR_ERR; - *data = g_variant_new_string(filters[devc->filter]); + *data = g_variant_new_int16(devc->filter); break; case SR_CONF_RLE: - if (!sdi) - return SR_ERR; *data = g_variant_new_boolean(devc->rle_mode); break; case SR_CONF_TEST: - if (!sdi) - return SR_ERR; *data = g_variant_new_boolean(devc->test_mode != SR_TEST_NONE); break; case SR_CONF_WAIT_UPLOAD: - if (!sdi) - return SR_ERR; if (devc->buf_options == SR_BUF_UPLOAD && devc->status == DSL_START) { devc->status = DSL_ABORT; @@ -618,63 +655,39 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, } break; case SR_CONF_BUFFER_OPTIONS: - if (!sdi) - return SR_ERR; - *data = g_variant_new_string(bufoptions[devc->buf_options]); + *data = g_variant_new_int16(devc->buf_options); break; case SR_CONF_CHANNEL_MODE: - if (!sdi) - return SR_ERR; - *data = g_variant_new_string(channel_modes[devc->ch_mode].descr); + *data = g_variant_new_int16(devc->ch_mode); break; case SR_CONF_MAX_HEIGHT: - if (!sdi) - return SR_ERR; *data = g_variant_new_string(maxHeights[devc->max_height]); break; case SR_CONF_MAX_HEIGHT_VALUE: - if (!sdi) - return SR_ERR; *data = g_variant_new_byte(devc->max_height); break; case SR_CONF_THRESHOLD: - if (!sdi) - return SR_ERR; - *data = g_variant_new_string(thresholds[devc->th_level]); + *data = g_variant_new_int16(devc->th_level); break; case SR_CONF_VTH: - if (!sdi) - return SR_ERR; *data = g_variant_new_double(devc->vth); break; case SR_CONF_STREAM: - if (!sdi) - return SR_ERR; *data = g_variant_new_boolean(devc->stream); break; case SR_CONF_MAX_DSO_SAMPLERATE: - if (!sdi) - return SR_ERR; *data = g_variant_new_uint64(channel_modes[devc->ch_mode].max_samplerate); break; case SR_CONF_MAX_DSO_SAMPLELIMITS: - if (!sdi) - return SR_ERR; *data = g_variant_new_uint64(devc->profile->dev_caps.dso_depth); break; case SR_CONF_HW_DEPTH: - if (!sdi) - return SR_ERR; *data = g_variant_new_uint64(dsl_channel_depth(sdi)); break; case SR_CONF_VLD_CH_NUM: - if (!sdi) - return SR_ERR; *data = g_variant_new_int16(channel_modes[devc->ch_mode].vld_num); break; case SR_CONF_TOTAL_CH_NUM: - if (!sdi) - return SR_ERR; *data = g_variant_new_int16(devc->profile->dev_caps.total_ch_num); break; default: @@ -694,6 +707,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, int ret, num_probes = 0; struct sr_usb_dev_inst *usb; unsigned int i; + int nv; assert(sdi); assert(sdi->priv); @@ -701,8 +715,10 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, (void)cg; if (sdi->status != SR_ST_ACTIVE) { + sr_err("%s: Device is not opened.", __func__); return SR_ERR; } + //sr_info("key:%d", id); devc = sdi->priv; usb = sdi->conn; @@ -834,14 +850,12 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, } } else if (id == SR_CONF_FILTER) { - stropt = g_variant_get_string(data, NULL); - if (!strcmp(stropt, filters[SR_FILTER_NONE])) { - devc->filter = SR_FILTER_NONE; - } else if (!strcmp(stropt, filters[SR_FILTER_1T])) { - devc->filter = SR_FILTER_1T; - } else { + nv = g_variant_get_int16(data); + if (nv == SR_FILTER_NONE || nv == SR_FILTER_1T) + devc->filter = nv; + else ret = SR_ERR; - } + sr_dbg("%s: setting filter to %d", __func__, devc->filter); } @@ -863,6 +877,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, sdi->mode = g_variant_get_int16(data); if (sdi->mode == LOGIC) { dsl_wr_reg(sdi, CTR0_ADDR, bmSCOPE_CLR); + for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { if (channel_modes[i].mode == LOGIC && devc->profile->dev_caps.channels & (1 << i)) { @@ -879,6 +894,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, ret = dsl_wr_dso(sdi, dso_cmd_gen(sdi, NULL, SR_CONF_DSO_SYNC)); if (ret != SR_OK) sr_dbg("%s: DSO configuration sync failed", __func__); + for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { if (channel_modes[i].mode == DSO && devc->profile->dev_caps.channels & (1 << i)) { @@ -914,59 +930,61 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, ret = SR_ERR; } assert(num_probes != 0); + sr_dev_probes_free(sdi); dsl_setup_probes(sdi, num_probes); sr_dbg("%s: setting mode to %d", __func__, sdi->mode); + if (sdi->mode != LOGIC) { dso_init(sdi); } } else if (id == SR_CONF_OPERATION_MODE) { - stropt = g_variant_get_string(data, NULL); - if (sdi->mode == LOGIC) { - if (!strcmp(stropt, opmodes[OP_BUFFER])) { - if (devc->op_mode != OP_BUFFER) { - devc->op_mode = OP_BUFFER; - devc->test_mode = SR_TEST_NONE; - devc->stream = FALSE; - for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { - if (channel_modes[i].mode == LOGIC && - channel_modes[i].stream == devc->stream && - devc->profile->dev_caps.channels & (1 << i)) { - devc->ch_mode = channel_modes[i].id; - break; - } + nv = g_variant_get_int16(data); + + if (sdi->mode == LOGIC && devc->op_mode != nv) + { + if (nv == OP_BUFFER) { + devc->op_mode = OP_BUFFER; + devc->test_mode = SR_TEST_NONE; + devc->stream = FALSE; + + for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { + if (channel_modes[i].mode == LOGIC && + channel_modes[i].stream == devc->stream && + devc->profile->dev_caps.channels & (1 << i)) { + devc->ch_mode = channel_modes[i].id; + break; } } } - else if (!strcmp(stropt, opmodes[OP_STREAM])) { - if (devc->op_mode != OP_STREAM) { - devc->op_mode = OP_STREAM; - devc->test_mode = SR_TEST_NONE; - devc->stream = TRUE; - for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { - if (channel_modes[i].mode == LOGIC && - channel_modes[i].stream == devc->stream && - devc->profile->dev_caps.channels & (1 << i)) { - devc->ch_mode = channel_modes[i].id; - break; - } + else if (nv == OP_STREAM) { + devc->op_mode = OP_STREAM; + devc->test_mode = SR_TEST_NONE; + devc->stream = TRUE; + + for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { + if (channel_modes[i].mode == LOGIC && + channel_modes[i].stream == devc->stream && + devc->profile->dev_caps.channels & (1 << i)) { + devc->ch_mode = channel_modes[i].id; + break; } } } - else if (!strcmp(stropt, opmodes[OP_INTEST])) { - if (devc->op_mode != OP_INTEST) { - devc->op_mode = OP_INTEST; - devc->test_mode = SR_TEST_INTERNAL; - devc->ch_mode = devc->profile->dev_caps.intest_channel; - devc->stream = !(devc->profile->dev_caps.feature_caps & CAPS_FEATURE_BUF); - } + else if (nv == OP_INTEST) { + devc->op_mode = OP_INTEST; + devc->test_mode = SR_TEST_INTERNAL; + devc->ch_mode = devc->profile->dev_caps.intest_channel; + devc->stream = !(devc->profile->dev_caps.feature_caps & CAPS_FEATURE_BUF); } else { ret = SR_ERR; } + dsl_adjust_probes(sdi, channel_modes[devc->ch_mode].num); dsl_adjust_samplerate(devc); + if (devc->op_mode == OP_INTEST) { devc->cur_samplerate = devc->stream ? channel_modes[devc->ch_mode].max_samplerate / 10 : SR_MHZ(100); @@ -978,21 +996,18 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, __func__, devc->op_mode); } else if (id == SR_CONF_BUFFER_OPTIONS) { - stropt = g_variant_get_string(data, NULL); - if (sdi->mode == LOGIC) { - if (!strcmp(stropt, bufoptions[SR_BUF_STOP])) - devc->buf_options = SR_BUF_STOP; - else if (!strcmp(stropt, bufoptions[SR_BUF_UPLOAD])) - devc->buf_options = SR_BUF_UPLOAD; + nv = g_variant_get_int16(data); + if (sdi->mode == LOGIC && (nv == SR_BUF_STOP || nv == SR_BUF_UPLOAD)) { + devc->buf_options = nv; } } else if (id == SR_CONF_CHANNEL_MODE) { - stropt = g_variant_get_string(data, NULL); + nv = g_variant_get_int16(data); if (sdi->mode == LOGIC) { for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { if (devc->profile->dev_caps.channels & (1 << i)) { - if (!strcmp(stropt, channel_modes[i].descr)) { - devc->ch_mode = channel_modes[i].id; + if (channel_modes[i].id == nv) { + devc->ch_mode = nv; break; } } @@ -1003,40 +1018,42 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi, sr_dbg("%s: setting channel mode to %d", __func__, devc->ch_mode); } - else if (id == SR_CONF_THRESHOLD) { - if (sdi->mode == LOGIC) { - stropt = g_variant_get_string(data, NULL); - if (strcmp(stropt, thresholds[devc->th_level])) { - if (!strcmp(stropt, thresholds[SR_TH_3V3])) { - devc->th_level = SR_TH_3V3; - } else if (!strcmp(stropt, thresholds[SR_TH_5V0])) { - devc->th_level = SR_TH_5V0; - } else { - ret = SR_ERR; - } - char *fpga_bit; - char *res_path = DS_RES_PATH; - if (!(fpga_bit = g_try_malloc(strlen(res_path)+strlen(devc->profile->fpga_bit33)+1))) { - sr_err("fpag_bit path malloc error!"); - return SR_ERR_MALLOC; - } - strcpy(fpga_bit, res_path); - switch(devc->th_level) { - case SR_TH_3V3: - strcat(fpga_bit, devc->profile->fpga_bit33); - break; - case SR_TH_5V0: - strcat(fpga_bit, devc->profile->fpga_bit50); - break; - default: - return SR_ERR; - } - ret = dsl_fpga_config(usb->devhdl, fpga_bit); - g_free(fpga_bit); - if (ret != SR_OK) { - sr_err("Configure FPGA failed!"); - } + else if (id == SR_CONF_THRESHOLD) { + nv = g_variant_get_int16(data); + if (sdi->mode == LOGIC && nv != devc->th_level) { + if (nv == SR_TH_3V3) + devc->th_level = SR_TH_3V3; + else if (nv == SR_TH_5V0) + devc->th_level = SR_TH_5V0; + else + return SR_ERR; + + char *fpga_bit; + char *res_path = DS_RES_PATH; + if (!(fpga_bit = g_try_malloc(strlen(res_path) + strlen(devc->profile->fpga_bit33) + 1))) { + sr_err("fpag_bit path malloc error!"); + return SR_ERR_MALLOC; } + strcpy(fpga_bit, res_path); + + switch(devc->th_level) + { + case SR_TH_3V3: + strcat(fpga_bit, devc->profile->fpga_bit33); + break; + case SR_TH_5V0: + strcat(fpga_bit, devc->profile->fpga_bit50); + break; + default: + return SR_ERR; + } + + ret = dsl_fpga_config(usb->devhdl, fpga_bit); + g_free(fpga_bit); + if (ret != SR_OK) { + sr_err("Configure FPGA failed!"); + } + sr_dbg("%s: setting threshold to %d", __func__, devc->th_level); } @@ -1121,6 +1138,10 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, struct DSL_context *devc; GVariantBuilder gvb; unsigned int i; + int num; + + assert(sdi); + assert(sdi->priv); (void)cg; devc = sdi->priv; @@ -1138,6 +1159,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_from_data(G_VARIANT_TYPE("ai"), hwoptions, ARRAY_SIZE(hwoptions)*sizeof(int32_t), TRUE, NULL, NULL); break; + case SR_CONF_DEVICE_SESSIONS: if (devc->profile->dev_caps.feature_caps & CAPS_FEATURE_VTH) *data = g_variant_new_from_data(G_VARIANT_TYPE("ai"), @@ -1146,33 +1168,48 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_from_data(G_VARIANT_TYPE("ai"), sessions, ARRAY_SIZE(sessions)*sizeof(int32_t), TRUE, NULL, NULL); break; + case SR_CONF_OPERATION_MODE: - *data = g_variant_new_strv(opmodes, opmodes_show_count); + *data = g_variant_new_uint64((uint64_t)&opmode_list); break; + case SR_CONF_BUFFER_OPTIONS: - *data = g_variant_new_strv(bufoptions, ARRAY_SIZE(bufoptions)); + *data = g_variant_new_uint64((uint64_t)&bufoption_list); break; - case SR_CONF_CHANNEL_MODE: - g_variant_builder_init(&gvb, G_VARIANT_TYPE("as")); + + case SR_CONF_CHANNEL_MODE: + num = 0; for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { - if (channel_modes[i].stream == devc->stream && - devc->profile->dev_caps.channels & (1 << i)) { + if (channel_modes[i].stream == devc->stream && devc->profile->dev_caps.channels & (1 << i)) + { if (devc->test_mode != SR_TEST_NONE && devc->profile->dev_caps.intest_channel != channel_modes[i].id) continue; - g_variant_builder_add(&gvb, "s", channel_modes[i].descr); + + if (num == CHANNEL_MODE_LIST_LEN - 1){ + assert(0); + } + channel_mode_list[num].id = channel_modes[i].id; + channel_mode_list[num].name = channel_modes[i].descr; + num++; } } - *data = g_variant_builder_end(&gvb); + channel_mode_list[num].id = -1; + channel_mode_list[num].name = NULL; + *data = g_variant_new_uint64((uint64_t)&channel_mode_list); break; - case SR_CONF_THRESHOLD: - *data = g_variant_new_strv(thresholds, ARRAY_SIZE(thresholds)); + + case SR_CONF_THRESHOLD: + *data = g_variant_new_uint64((uint64_t)&threshold_list); break; - case SR_CONF_FILTER: - *data = g_variant_new_strv(filters, ARRAY_SIZE(filters)); + + case SR_CONF_FILTER: + *data = g_variant_new_uint64((uint64_t)&filter_list); break; + case SR_CONF_MAX_HEIGHT: *data = g_variant_new_strv(maxHeights, ARRAY_SIZE(maxHeights)); break; + default: return SR_ERR_NA; } @@ -1437,6 +1474,43 @@ static int dev_status_get(const struct sr_dev_inst *sdi, struct sr_status *statu return ret; } +SR_PRIV int sr_dslogic_option_value_to_code(const struct sr_dev_inst *sdi, int config_id, const char *value) +{ + int num; + int i; + int n; + struct DSL_context *devc; + + assert(sdi); + assert(sdi->priv); + + devc = sdi->priv; + + if (config_id == SR_CONF_CHANNEL_MODE) + { + for (i = 0; i < ARRAY_SIZE(channel_modes); i++) { + if (devc->profile->dev_caps.channels & (1 << i)) + { + if (strcmp(channel_modes[i].descr, value) == 0) + return channel_modes[i].id; + + if (i < ARRAY_SIZE(channel_mode_cn_map)){ + if (channel_modes[i].id != channel_mode_cn_map[i].id) + assert(0); + if (strcmp(channel_mode_cn_map[i].name, value) == 0) + return channel_modes[i].id; + } + } + } + + sr_err("Unkown lang text value:%s,config id:%d", value, config_id); + return -1; + } + + num = sizeof(lang_text_map) / sizeof(lang_text_map[0]); + return sr_option_value_to_code(config_id, value, &lang_text_map, num); +} + SR_PRIV struct sr_dev_driver DSLogic_driver_info = { .name = "DSLogic", .longname = "DSLogic (generic driver for DSLogic LA)", diff --git a/libsigrok4DSL/hardware/demo/demo.c b/libsigrok4DSL/hardware/demo/demo.c index ffc852ea..27a16257 100644 --- a/libsigrok4DSL/hardware/demo/demo.c +++ b/libsigrok4DSL/hardware/demo/demo.c @@ -49,6 +49,20 @@ #define BUFSIZE 512*1024 #define DSO_BUFSIZE 10*1024 +static const struct DEMO_channels channel_modes[] = { + // LA Stream + {DEMO_LOGIC100x16, LOGIC, SR_CHANNEL_LOGIC, 16, 1, SR_MHZ(1), SR_Mn(1), + SR_KHZ(10), SR_MHZ(100), "Use 16 Channels (Max 20MHz)"}, + + // DAQ + {DEMO_ANALOG10x2, ANALOG, SR_CHANNEL_ANALOG, 2, 8, SR_MHZ(1), SR_Mn(1), + SR_HZ(10), SR_MHZ(10), "Use Channels 0~1 (Max 10MHz)"}, + + // OSC + {DEMO_DSO200x2, DSO, SR_CHANNEL_DSO, 2, 8, SR_MHZ(100), SR_Kn(10), + SR_HZ(100), SR_MHZ(200), "Use Channels 0~1 (Max 200MHz)"} +}; + /* Private, per-device-instance driver context. */ /* TODO: struct context as with the other drivers. */ diff --git a/libsigrok4DSL/hardware/demo/demo.h b/libsigrok4DSL/hardware/demo/demo.h index 483b8000..4a407ea9 100644 --- a/libsigrok4DSL/hardware/demo/demo.h +++ b/libsigrok4DSL/hardware/demo/demo.h @@ -252,20 +252,6 @@ static const gboolean default_ms_en[] = { FALSE, /* DSO_MS_VP2P */ }; -static const struct DEMO_channels channel_modes[] = { - // LA Stream - {DEMO_LOGIC100x16, LOGIC, SR_CHANNEL_LOGIC, 16, 1, SR_MHZ(1), SR_Mn(1), - SR_KHZ(10), SR_MHZ(100), "Use 16 Channels (Max 20MHz)"}, - - // DAQ - {DEMO_ANALOG10x2, ANALOG, SR_CHANNEL_ANALOG, 2, 8, SR_MHZ(1), SR_Mn(1), - SR_HZ(10), SR_MHZ(10), "Use Channels 0~1 (Max 10MHz)"}, - - // OSC - {DEMO_DSO200x2, DSO, SR_CHANNEL_DSO, 2, 8, SR_MHZ(100), SR_Kn(10), - SR_HZ(100), SR_MHZ(200), "Use Channels 0~1 (Max 200MHz)"} -}; - static const struct DEMO_profile supported_Demo[] = { /* * Demo diff --git a/libsigrok4DSL/hwdriver.c b/libsigrok4DSL/hwdriver.c index aeb2281a..c292e42a 100644 --- a/libsigrok4DSL/hwdriver.c +++ b/libsigrok4DSL/hwdriver.c @@ -65,15 +65,15 @@ static struct sr_config_info sr_config_info_data[] = { {SR_CONF_TIMEBASE, SR_T_UINT64,"Time base"}, {SR_CONF_MAX_HEIGHT, SR_T_CHAR,"Max Height"}, {SR_CONF_MAX_HEIGHT_VALUE, SR_T_UINT8,"Max Height value"}, - {SR_CONF_FILTER, SR_T_CHAR,"Filter Targets"}, + {SR_CONF_FILTER, SR_T_LIST,"Filter Targets"}, {SR_CONF_DATALOG, SR_T_BOOL,"Datalog"}, - {SR_CONF_OPERATION_MODE, SR_T_CHAR,"Operation Mode"}, - {SR_CONF_BUFFER_OPTIONS, SR_T_CHAR,"Stop Options"}, - {SR_CONF_CHANNEL_MODE, SR_T_CHAR,"Channel Mode"}, - {SR_CONF_THRESHOLD, SR_T_CHAR,"Threshold Levels"}, + {SR_CONF_OPERATION_MODE, SR_T_LIST,"Operation Mode"}, + {SR_CONF_BUFFER_OPTIONS, SR_T_LIST,"Stop Options"}, + {SR_CONF_CHANNEL_MODE, SR_T_LIST,"Channel Mode"}, + {SR_CONF_THRESHOLD, SR_T_LIST,"Threshold Levels"}, {SR_CONF_VTH, SR_T_FLOAT,"Threshold Level"}, {SR_CONF_RLE_SUPPORT, SR_T_BOOL,"Enable RLE Compress"}, - {SR_CONF_BANDWIDTH_LIMIT, SR_T_CHAR,"Bandwidth Limit"}, + {SR_CONF_BANDWIDTH_LIMIT, SR_T_LIST,"Bandwidth Limit"}, {SR_CONF_PROBE_COUPLING, SR_T_CHAR,"Coupling"}, {SR_CONF_PROBE_VDIV, SR_T_RATIONAL_VOLT,"Volts/div"}, {SR_CONF_PROBE_FACTOR, SR_T_UINT64,"Probe Factor"}, diff --git a/libsigrok4DSL/lib_main.c b/libsigrok4DSL/lib_main.c index 1b527af0..43307aa6 100644 --- a/libsigrok4DSL/lib_main.c +++ b/libsigrok4DSL/lib_main.c @@ -195,6 +195,8 @@ SR_API int ds_lib_exit() } lib_ctx.sr_ctx = NULL; + sr_hw_cleanup_all(); + sr_log_uninit(); // try uninit log return SR_OK; @@ -919,6 +921,14 @@ SR_API void ds_free_config(struct sr_config *src) sr_config_free(src); } +SR_API int ds_dsl_option_value_to_code(int work_mode, int config_id, const char *value) +{ + if (work_mode == LOGIC) + return sr_dslogic_option_value_to_code(lib_ctx.actived_device_instance, config_id, value); + else + return sr_dscope_option_value_to_code(lib_ctx.actived_device_instance, config_id, value); +} + /**-----------channel -------------*/ SR_API int ds_enable_device_channel(const struct sr_channel *ch, gboolean enable) { diff --git a/libsigrok4DSL/libsigrok-internal.h b/libsigrok4DSL/libsigrok-internal.h index 947cdc62..8716f026 100644 --- a/libsigrok4DSL/libsigrok-internal.h +++ b/libsigrok4DSL/libsigrok-internal.h @@ -424,5 +424,13 @@ SR_PRIV int sr_status_get(const struct sr_dev_inst *sdi, struct sr_status *statu SR_PRIV struct sr_config *sr_config_new(int key, GVariant *data); SR_PRIV void sr_config_free(struct sr_config *src); +/*--- dsl.c ------------------------------------------------------------*/ +SR_PRIV int sr_option_value_to_code(int config_id, const char *value, const struct lang_text_map_item *array, int num); + +/*--- dslogic.c ------------------------------------------------------------*/ +SR_PRIV int sr_dslogic_option_value_to_code(const struct sr_dev_inst *sdi, int config_id, const char *value); + +/*--- dscope.c ------------------------------------------------------------*/ +SR_PRIV int sr_dscope_option_value_to_code(const struct sr_dev_inst *sdi, int config_id, const char *value); #endif diff --git a/libsigrok4DSL/libsigrok.h b/libsigrok4DSL/libsigrok.h index 0e0a7daf..43904cd1 100644 --- a/libsigrok4DSL/libsigrok.h +++ b/libsigrok4DSL/libsigrok.h @@ -182,6 +182,7 @@ enum { SR_T_RATIONAL_VOLT, SR_T_KEYVALUE, SR_T_LIST, + SR_T_INT16 }; /** Value for sr_datafeed_packet.type. */ @@ -742,6 +743,11 @@ struct sr_status { uint32_t ch1_acc_mean_p3; }; +struct sr_list_item{ + int id; + char *name; +}; + enum sr_config_option_id { /*--- Device classes ------------------------------------------------*/ @@ -1190,47 +1196,6 @@ enum DSL_CHANNEL_ID { DSL_DSO1000x2, }; -static char* DSL_CHANNEL_ID_NAMES[] = -{ - "DSL_STREAM20x16", - "DSL_STREAM25x12", - "DSL_STREAM50x6", - "DSL_STREAM100x3", - - "DSL_STREAM20x16_3DN2", - "DSL_STREAM25x12_3DN2", - "DSL_STREAM50x6_3DN2", - "DSL_STREAM100x3_3DN2", - - "DSL_STREAM10x32_32_3DN2", - "DSL_STREAM20x16_32_3DN2", - "DSL_STREAM25x12_32_3DN2", - "DSL_STREAM50x6_32_3DN2", - "DSL_STREAM100x3_32_3DN2", - - "DSL_STREAM50x32", - "DSL_STREAM100x30", - "DSL_STREAM250x12", - "DSL_STREAM125x16_16", - "DSL_STREAM250x12_16", - "DSL_STREAM500x6", - "DSL_STREAM1000x3", - - "DSL_BUFFER100x16", - "DSL_BUFFER200x8", - "DSL_BUFFER400x4", - - "DSL_BUFFER250x32", - "DSL_BUFFER500x16", - "DSL_BUFFER1000x8", - - "DSL_ANALOG10x2", - "DSL_ANALOG10x2_500", - - "DSL_DSO200x2", - "DSL_DSO1000x2", -}; - /*--- input/input.c ---------------------------------------------------------*/ SR_API struct sr_input_format **sr_input_list(void); @@ -1499,6 +1464,11 @@ SR_API struct sr_config *ds_new_config(int key, GVariant *data); SR_API void ds_free_config(struct sr_config *src); +/** + The session file options value text,convert to code. +*/ +SR_API int ds_dsl_option_value_to_code(int work_mode, int config_id, const char *value); + /*----------channel----------*/ SR_API int ds_enable_device_channel(const struct sr_channel *ch, gboolean enable);