From 160786d24f84e22778273ca2a47b819f08b4e373 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Tue, 30 May 2023 15:58:00 +0800 Subject: [PATCH] Able to input the serial trig value with hex format --- DSView/pv/data/decode/annotationrestable.cpp | 57 ++++++++++ DSView/pv/data/decode/annotationrestable.h | 3 + DSView/pv/dock/triggerdock.cpp | 114 ++++++++++++++++++- DSView/pv/dock/triggerdock.h | 11 +- lang/cn/dlg.json | 8 ++ lang/cn/msg.json | 2 +- lang/en/dlg.json | 8 ++ lang/en/msg.json | 2 +- 8 files changed, 198 insertions(+), 7 deletions(-) diff --git a/DSView/pv/data/decode/annotationrestable.cpp b/DSView/pv/data/decode/annotationrestable.cpp index c73edceb..c20e07b1 100644 --- a/DSView/pv/data/decode/annotationrestable.cpp +++ b/DSView/pv/data/decode/annotationrestable.cpp @@ -22,6 +22,7 @@ #include "annotationrestable.h" #include #include +#include #include "../../log.h" #include "../../dsvdef.h" @@ -339,4 +340,60 @@ void AnnotationResTable::reset() m_resourceTable.clear(); m_indexs.clear(); } + +int AnnotationResTable::hexToDecimal(char * hex) +{ + assert(hex); + int len = strlen(hex); + + double b = 16; + int result = 0; + char *p = hex; + + while(*p) { + if(*p >= '0' && *p <= '9') + result += (int)pow(b, --len) * (*p - '0'); + else if(*p >= 'a' && *p <= 'f') + result += (int)pow(b, --len) * (*p - 'a' + 10); + else if(*p >= 'A' && *p <= 'F') + result += (int)pow(b, --len) * (*p - 'A' + 10); + + p++; + } + + return result; +} + +void AnnotationResTable::decimalToBinString(unsigned long long num, int bitSize, char *buffer, int buffer_size) +{ + + assert(buffer); + assert(buffer_size); + + if (bitSize < 8) + bitSize = 8; + if (bitSize > 64) + bitSize = 64; + + assert(bitSize < buffer_size); + + int v; + char *wr = buffer + bitSize; + *wr = 0; + wr--; + + while (num > 0 && wr >= buffer) + { + v = num % 2; + *wr = v ? '1' : '0'; + wr--; + num = num / 2; + } + + while (wr >= buffer) + { + *wr = '0'; + wr--; + } +} diff --git a/DSView/pv/data/decode/annotationrestable.h b/DSView/pv/data/decode/annotationrestable.h index 0151ca0b..740c56f7 100644 --- a/DSView/pv/data/decode/annotationrestable.h +++ b/DSView/pv/data/decode/annotationrestable.h @@ -56,6 +56,9 @@ class AnnotationResTable void reset(); + static int hexToDecimal(char * hex); + static void decimalToBinString(unsigned long long num, int bitSize, char *buffer, int buffer_size); + private: const char* format_to_string(const char *hex_str, int fmt); diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index 53bdc55d..0f0c8e55 100644 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,8 @@ #include "../view/logicsignal.h" #include "../ui/langresource.h" #include "../ui/msgbox.h" +#include "../log.h" +#include "../data/decode/annotationrestable.h" namespace pv { namespace dock { @@ -57,6 +60,11 @@ TriggerDock::TriggerDock(QWidget *parent, SigSession *session) : _session->get_device()->get_config_int16(SR_CONF_TOTAL_CH_NUM, _cur_ch_num); } + _serial_hex_label = NULL; + _serial_hex_lineEdit = NULL; + _serial_hex_ck_label = NULL; + _is_serial_val_setting = false; + _widget = new QWidget(this); _simple_radioButton = new QRadioButton(_widget); _simple_radioButton->setChecked(true); @@ -142,6 +150,8 @@ void TriggerDock::retranslateUi() _serial_data_label->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_DATA_CHANNEL), "Data Channel: ")); _serial_value_label->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_DATA_VALUE), "Data Value: ")); _serial_groupBox->setTitle(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_SERIAL_TRIGGER), "Serial Trigger")); + _serial_hex_label->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_SERIAL_HEX), "Hex: ")); + _serial_hex_ck_label->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_SERIAL_INPUT_AS_HEX), "Input hex")); _adv_tabWidget->setTabText(0, L_S(STR_PAGE_DLG, S_ID(IDS_DLG_STAGE_TRIGGER), "Stage Trigger")); _adv_tabWidget->setTabText(1, L_S(STR_PAGE_DLG, S_ID(IDS_DLG_SERIAL_TRIGGER), "Serial Trigger")); @@ -225,7 +235,7 @@ void TriggerDock::widget_enable(int index) stages_comboBox->setDisabled(false); _adv_tabWidget->setDisabled(false); enable_stages = stages_comboBox->currentText().toInt(); - + for (int i = 0; i < enable_stages; i++) { _stage_tabWidget->setTabEnabled(i, true); } @@ -759,6 +769,31 @@ void TriggerDock::setup_adv_tab() QValidator *value_validator2 = new QRegularExpressionValidator(value_rx2, _stage_tabWidget); _serial_value_lineEdit->setValidator(value_validator2); + _serial_hex_label = new QLabel(_serial_groupBox); + _serial_hex_lineEdit = new QLineEdit("", _serial_groupBox); + _serial_hex_lineEdit->setMaxLength(4); + QRegularExpression value_rx_hex("[0-9a-fA-F]+"); + QValidator *value_validator_hex = new QRegularExpressionValidator(value_rx_hex, _stage_tabWidget); + _serial_hex_lineEdit->setValidator(value_validator_hex); + _serial_hex_lineEdit->setMaximumWidth(70); + _serial_hex_lineEdit->setReadOnly(true); + + QCheckBox *hex_ckbox = new QCheckBox(); + _serial_hex_ck_label = new QLabel(); + hex_ckbox->setMaximumWidth(18); + + QHBoxLayout *hex_lay = new QHBoxLayout(); + hex_lay->setSpacing(5); + hex_lay->setContentsMargins(0,0,0,0); + QWidget *hex_wid = new QWidget(); + hex_wid->setLayout(hex_lay); + hex_lay->setAlignment(Qt::AlignLeft); + hex_lay->addWidget(_serial_hex_lineEdit); + hex_lay->addWidget(hex_ckbox); + hex_lay->addWidget(_serial_hex_ck_label); + + connect(hex_ckbox, SIGNAL(clicked(bool)), this, SLOT(on_hex_checkbox_click(bool))); + _serial_bits_comboBox = new DsComboBox(_serial_groupBox); for(int i = 1; i <= 16; i++){ @@ -831,7 +866,8 @@ void TriggerDock::setup_adv_tab() serial_glayout->addWidget(serial5_value_exp_label, row++, 1, 1, 3); serial_glayout->addWidget(_serial_edge_label, row, 0); serial_glayout->addWidget(_serial_edge_lineEdit, row++, 1, 1, 3); - } else { + } + else { QLabel *serial0_value_exp_label = new QLabel("15 ---------- 8 7 ----------- 0 ", _serial_groupBox); serial0_value_exp_label->setFont(font); serial_glayout->addWidget(serial0_value_exp_label, row++, 1, 1, 3); @@ -864,6 +900,8 @@ void TriggerDock::setup_adv_tab() serial_glayout->addWidget(_serial_bits_comboBox, row++, 1); serial_glayout->addWidget(_serial_value_label, row, 0); serial_glayout->addWidget(_serial_value_lineEdit, row++, 1, 1, 3); + serial_glayout->addWidget(_serial_hex_label, row, 0); + serial_glayout->addWidget(hex_wid, row++, 1, 1, 3); _serial_note_label = new QLabel(_serial_groupBox); serial_layout->addLayout(serial_glayout); @@ -878,6 +916,12 @@ void TriggerDock::setup_adv_tab() connect(_serial_edge_lineEdit, SIGNAL(editingFinished()), this, SLOT(value_changed())); connect(_serial_value_lineEdit, SIGNAL(editingFinished()), this, SLOT(value_changed())); + connect(_serial_value_lineEdit, SIGNAL(textChanged(const QString&)), + this, SLOT(on_serial_value_changed(const QString&))); + + connect(_serial_hex_lineEdit, SIGNAL(editingFinished()), + this, SLOT(on_serial_hex_changed())); + _adv_tabWidget->addTab((QWidget *)_stage_tabWidget, L_S(STR_PAGE_DLG, S_ID(IDS_DLG_STAGE_TRIGGER), "Stage Trigger")); _adv_tabWidget->addTab((QWidget *)_serial_groupBox, L_S(STR_PAGE_DLG, S_ID(IDS_DLG_SERIAL_TRIGGER), "Serial Trigger")); } @@ -954,5 +998,71 @@ void TriggerDock::try_commit_trigger() } } +void TriggerDock::on_hex_checkbox_click(bool ck) +{ + _serial_hex_lineEdit->setReadOnly(!ck); + if (ck){ + _serial_hex_lineEdit->setFocus(); + } +} + +void TriggerDock::on_serial_value_changed(const QString &v) +{ + if (_is_serial_val_setting) + return; + + QString s(v); + s = s.replace(" ", "").toLower(); + _serial_hex_lineEdit->setText(""); + + if (s != "" && s.indexOf("x") == -1) + { + char *buf = s.toLocal8Bit().data(); + int len = s.length(); + unsigned long val = 0; + + if (len == 16) + { + for (int i=0; isetText(QString(tmp)); + } + } +} + +void TriggerDock::on_serial_hex_changed() +{ + if (_is_serial_val_setting) + return; + + _is_serial_val_setting = true; + + QString s = _serial_hex_lineEdit->text(); + _serial_hex_lineEdit->setText(s.toUpper()); + + if (s.length() <= 4) + { + while (s.length() < 4){ + s = "0" + s; + } + + const char *str = s.toLocal8Bit().data(); + char *endptr = NULL; + unsigned long val = strtoul(str, &endptr, 16); + char buffer[18]; + AnnotationResTable::decimalToBinString(val, 16, buffer, sizeof(buffer)); + _serial_value_lineEdit->setText(QString(buffer)); + } + + _is_serial_val_setting = false; +} + } // namespace dock } // namespace pv diff --git a/DSView/pv/dock/triggerdock.h b/DSView/pv/dock/triggerdock.h index c4024a2a..06309546 100644 --- a/DSView/pv/dock/triggerdock.h +++ b/DSView/pv/dock/triggerdock.h @@ -86,14 +86,15 @@ private: * 1: advanced trigger */ bool commit_trigger(); - private slots: void simple_trigger(); void adv_trigger(); void widget_enable(int index); - - void value_changed(); + void value_changed(); + void on_hex_checkbox_click(bool ck); + void on_serial_value_changed(const QString &v); + void on_serial_hex_changed(); private: SigSession *_session; @@ -141,9 +142,13 @@ private: QLabel *_serial_value_label; QLineEdit *_serial_value_lineEdit; DsComboBox *_serial_bits_comboBox; + QLabel *_serial_hex_label; + QLineEdit *_serial_hex_lineEdit; + QLabel *_serial_hex_ck_label; QLabel *_serial_note_label; QLabel *_data_bits_label; + bool _is_serial_val_setting; QVector _inv_exp_label_list; QVector _count_exp_label_list; diff --git a/lang/cn/dlg.json b/lang/cn/dlg.json index a496048b..ae1740e7 100644 --- a/lang/cn/dlg.json +++ b/lang/cn/dlg.json @@ -690,5 +690,13 @@ { "id": "IDS_DLG_DISPLAY_PROFILE_IN_BAR", "text": "将配置文件名显示在标题栏上" + }, + { + "id": "IDS_DLG_SERIAL_HEX", + "text": "十六进制 :" + }, + { + "id": "IDS_DLG_SERIAL_INPUT_AS_HEX", + "text": "以十六进制格式输入" } ] \ No newline at end of file diff --git a/lang/cn/msg.json b/lang/cn/msg.json index e07dfd52..67564bc9 100644 --- a/lang/cn/msg.json +++ b/lang/cn/msg.json @@ -96,7 +96,7 @@ }, { "id": "IDS_MSG_CLOSE_DEVICE", - "text": "是否确定关闭这个设备?" + "text": "是否确定要移除这个设备?" }, { "id": "IDS_MSG_SET_DEF_CAL_SETTING", diff --git a/lang/en/dlg.json b/lang/en/dlg.json index 611fb7e4..699519e8 100644 --- a/lang/en/dlg.json +++ b/lang/en/dlg.json @@ -690,5 +690,13 @@ { "id": "IDS_DLG_DISPLAY_PROFILE_IN_BAR", "text": "Display the profile in title bar" + }, + { + "id": "IDS_DLG_SERIAL_HEX", + "text": "Hex :" + }, + { + "id": "IDS_DLG_SERIAL_INPUT_AS_HEX", + "text": "Input with hex format" } ] \ No newline at end of file diff --git a/lang/en/msg.json b/lang/en/msg.json index c5645446..1fd0744d 100644 --- a/lang/en/msg.json +++ b/lang/en/msg.json @@ -97,7 +97,7 @@ }, { "id": "IDS_MSG_CLOSE_DEVICE", - "text": "Are you sure to close the device?" + "text": "Are you sure to remove this device?" }, { "id": "IDS_MSG_SET_DEF_CAL_SETTING",