From d1676609113d75269c66d0ca94aacad91be693b1 Mon Sep 17 00:00:00 2001 From: pandx Date: Wed, 2 Apr 2025 14:07:37 +0800 Subject: [PATCH] add tachometer codes. --- TSI_Config.pro | 2 + config_mgr.cpp | 53 ++++++- data_config.h | 8 +- keyphase.cpp | 2 +- keyphase.h | 2 +- tachometer.cpp | 320 ++++++++++++++++++----------------------- tachometer.h | 8 +- tachometer.ui | 338 +++++++++++++++++++++++++++++++++++++++++--- tachometer_data.cpp | 6 + tachometer_data.h | 13 ++ 10 files changed, 543 insertions(+), 209 deletions(-) create mode 100644 tachometer_data.cpp create mode 100644 tachometer_data.h diff --git a/TSI_Config.pro b/TSI_Config.pro index 315466a..1e61790 100644 --- a/TSI_Config.pro +++ b/TSI_Config.pro @@ -23,6 +23,7 @@ SOURCES += \ setpoint.cpp \ singlerelay.cpp \ tachometer.cpp \ + tachometer_data.cpp \ velocity.cpp \ vibrationdata.cpp @@ -43,6 +44,7 @@ HEADERS += \ setpoint.h \ singlerelay.h \ tachometer.h \ + tachometer_data.h \ velocity.h \ velocity_ds.h \ vibrationdata.h diff --git a/config_mgr.cpp b/config_mgr.cpp index 7a407ea..256dd2d 100644 --- a/config_mgr.cpp +++ b/config_mgr.cpp @@ -6,6 +6,7 @@ #include "data_config.h" #include "vibrationdata.h" +#include "tachometer_data.h" ConfigMgr *ConfigMgr::instance = nullptr; @@ -191,8 +192,28 @@ void ConfigMgr::Save() { variables["latching"] = latching; } channel_item["variable"] = variables; - } else { - // TODO: save speed, keyphase + } else if (card_type_[i] == kCardSpeedSingle || card_type_[i] == kCardSpeedTMRPrimary) { + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot); + if (base_ptr == nullptr) { + continue; + } + std::shared_ptr ptr = std::dynamic_pointer_cast(base_ptr); + QJsonArray voltage_range_array; + voltage_range_array.append(ptr->variables_[cid].normal_voltage_low); + voltage_range_array.append(ptr->variables_[cid].normal_voltage_high); + channel_item.insert("active", ptr->variables_[cid].active); + channel_item.insert("normal_voltage_range", voltage_range_array); + channel_item.insert("threshold", ptr->variables_[cid].threshold); + channel_item.insert("hysteresis", ptr->variables_[cid].hysteresis); + channel_item.insert("events_per_revolution", ptr->variables_[cid].events_per_revolution); + channel_item.insert("record_output", ptr->variables_[cid].record_output); + channel_item.insert("two_ma_clamp", ptr->variables_[cid].two_ma_clamp); + channel_item.insert("alert_latching", ptr->variables_[cid].alert_latching); + channel_item.insert("overspeed_latching", ptr->variables_[cid].overspeed_latching); + channel_item.insert("normal_latching", ptr->variables_[cid].normal_latching); + channel_item.insert("speed_peak", ptr->variables_[cid].speed_peek); + channel_item.insert("default_speed", ptr->variables_[cid].default_speed); + } else if (card_type_[i] == kCardKeyphase) { } slot_item[QString::number(cid + 1)] = channel_item; } @@ -256,6 +277,9 @@ void ConfigMgr::Load(QString filename) { temp_obj = json_obj[QString::number(slot)].toObject(); if (card_type_[i] == kCardVibSingle) { std::shared_ptr vib_data = std::make_shared(); + vib_data->version_ = temp_obj["version"].toInt(); + vib_data->card_type_ = static_cast(card_type_[i]); + vib_data->slot_ = slot; for (int j = 0; j < CHANNEL_COUNT; ++j) { channel = temp_obj[QString::number(j + 1)].toObject(); // base info @@ -377,6 +401,31 @@ void ConfigMgr::Load(QString filename) { } } cards_.push_back(vib_data); + } else if (card_type_[i] == kCardSpeedSingle || + card_type_[i] == kCardSpeedTMRPrimary) { + std::shared_ptr speed_data = std::make_shared(); + speed_data->slot_ = slot; + speed_data->card_type_ = static_cast(card_type_[i]); + speed_data->version_ = temp_obj["version"].toInt(); + for (int j = 0; j < CHANNEL_COUNT; ++j) { + channel = temp_obj[QString::number(j + 1)].toObject(); + speed_data->variables_[j].active = channel["active"].toBool(); + QJsonArray voltage_range_array = channel["normal_voltage_range"].toArray(); + speed_data->variables_[j].normal_voltage_high = voltage_range_array[1].toDouble(); + speed_data->variables_[j].normal_voltage_low = voltage_range_array[0].toDouble(); + speed_data->variables_[j].threshold = channel["threshold"].toDouble(); + speed_data->variables_[j].hysteresis = channel["hysteresis"].toDouble(); + speed_data->variables_[j].events_per_revolution = channel["events_per_revolution"].toInt(); + speed_data->variables_[j].record_output = channel["record_output"].toInt(); + speed_data->variables_[j].two_ma_clamp = channel["two_ma_clamp"].toBool(); + speed_data->variables_[j].alert_latching = channel["alert_latching"].toBool(); + speed_data->variables_[j].overspeed_latching = channel["overspeed_latching"].toBool(); + speed_data->variables_[j].normal_latching = channel["normal_latching"].toBool(); + speed_data->variables_[j].speed_peek = channel["speed_peak"].toInt(); + speed_data->variables_[j].default_speed = channel["default_speed"].toInt(); + } + cards_.push_back(speed_data); + } else if (card_type_[i] == kCardKeyphase) { } } } diff --git a/data_config.h b/data_config.h index 247f675..e46c9f1 100644 --- a/data_config.h +++ b/data_config.h @@ -165,18 +165,18 @@ typedef struct { bool active; float normal_voltage_low; float normal_voltage_high; + int speed_peek; + int default_speed; bool automatic_threshold; float threshold; float hysteresis; int events_per_revolution; - QString record_output; + int record_output; bool two_ma_clamp; bool alert_latching; bool overspeed_latching; bool normal_latching; - int alert_response_time; - int danger_response_time; -} Tachometer_Variables; +} TachometerVariables; typedef struct { QString transducer_name; diff --git a/keyphase.cpp b/keyphase.cpp index 383c105..20aaedc 100644 --- a/keyphase.cpp +++ b/keyphase.cpp @@ -102,7 +102,7 @@ void KeyPhase::readJsonFile(const QString &filePath) { keyphase_variables[i].threshold = temp_obj["threshold"].toDouble(); keyphase_variables[i].hysteresis = temp_obj["hysteresis"].toDouble(); keyphase_variables[i].events_per_revolution = temp_obj["events_per_revolution"].toInt(); - keyphase_variables[i].record_output = temp_obj["record_output"].toString(); + keyphase_variables[i].record_output = temp_obj["record_output"].toInt(); keyphase_variables[i].two_ma_clamp = temp_obj["two_ma_clamp"].toBool(); keyphase_variables[i].alert_latching = temp_obj["alert_latching"].toBool(); keyphase_variables[i].overspeed_latching = temp_obj["overspeed_latching"].toBool(); diff --git a/keyphase.h b/keyphase.h index fd8874c..7eb2475 100644 --- a/keyphase.h +++ b/keyphase.h @@ -24,7 +24,7 @@ class KeyPhase : public QDialog { void on_manual_threshold_4_clicked(bool checked); private: Ui::KeyPhase *ui; - Tachometer_Variables keyphase_variables[4]; + TachometerVariables keyphase_variables[4]; void readJsonFile(const QString &filePath); void Init(); }; diff --git a/tachometer.cpp b/tachometer.cpp index bcaa53c..7cd628d 100644 --- a/tachometer.cpp +++ b/tachometer.cpp @@ -7,6 +7,10 @@ #include #include +#include "data_config.h" +#include "config_mgr.h" +#include "tachometer_data.h" + Tachometer::Tachometer(int slot_no_, QWidget *parent) : QDialog(parent) , ui(new Ui::Tachometer) { @@ -16,8 +20,6 @@ Tachometer::Tachometer(int slot_no_, QWidget *parent) slot_no = slot_no_; QString slot = QString("%1").arg(slot_no); ui->label_slot->setText(slot); - QString filePath_tachometer = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\tachometer.json").arg(slot_no); - readJsonFile(filePath_tachometer); Init(); connect(ui->radioButton_manual_threshold_1, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_1_clicked); connect(ui->radioButton_manual_threshold_2, &QRadioButton::toggled, this, &Tachometer::on_manual_threshold_2_clicked); @@ -69,142 +71,182 @@ void Tachometer::on_manual_threshold_4_clicked(bool checked) { ui->doubleSpinBox_hysteresis_4->setEnabled(false); } -void Tachometer::readJsonFile(const QString &filePath) { - QFile file(filePath); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << "Cannot open file for reading:" << filePath; - return; - } - QString content = file.readAll(); - file.close(); - QByteArray jsonData = content.toUtf8(); - QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData); - if (jsonDoc.isNull()) { - qDebug() << "Cannot parse JSON document"; - return; - } - if (!jsonDoc.isObject() && !jsonDoc.isArray()) { - qDebug() << "JSON document is not an object or an array"; - return; - } - QJsonObject json_obj = jsonDoc.object(); - QJsonArray chan_array = json_obj["chan"].toArray(); - for (int i = 0; i < chan_array.size(); i++) { - QJsonObject temp_obj = chan_array[i].toObject(); - tachometer_variables[i].id = temp_obj["id"].toInt(); - tachometer_variables[i].active = temp_obj["active"].toBool(); - QJsonArray voltage_range_array = temp_obj["normal_voltage_range"].toArray(); - tachometer_variables[i].normal_voltage_high = voltage_range_array[1].toDouble(); - tachometer_variables[i].normal_voltage_low = voltage_range_array[0].toDouble(); - tachometer_variables[i].threshold = temp_obj["threshold"].toDouble(); - tachometer_variables[i].hysteresis = temp_obj["hysteresis"].toDouble(); - tachometer_variables[i].events_per_revolution = temp_obj["events_per_revolution"].toInt(); - tachometer_variables[i].record_output = temp_obj["record_output"].toString(); - tachometer_variables[i].two_ma_clamp = temp_obj["two_ma_clamp"].toBool(); - tachometer_variables[i].alert_latching = temp_obj["alert_latching"].toBool(); - tachometer_variables[i].overspeed_latching = temp_obj["overspeed_latching"].toBool(); - tachometer_variables[i].normal_latching = temp_obj["normal_latching"].toBool(); - tachometer_variables[i].alert_response_time = temp_obj["alert_response_time"].toInt(); - tachometer_variables[i].danger_response_time = temp_obj["danger_response_time"].toInt(); +void Tachometer::UpdateData(std::shared_ptr &speed_data) { + speed_data->card_type_ = kCardSpeedSingle; + speed_data->slot_ = slot_no; + speed_data->version_ = 1; + for (int i = 0; i < CHANNEL_COUNT; i++) { + if (i + 1 == 1) { + speed_data->variables_[i].active = ui->checkBox_chan_1->isChecked(); + speed_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_1->value(); + speed_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_1->value(); + speed_data->variables_[i].speed_peek = ui->full_scale_range_1->value(); + speed_data->variables_[i].default_speed = ui->default_value_1->value(); + speed_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_1->isChecked(); + speed_data->variables_[i].threshold = ui->doubleSpinBox_threshold_1->value(); + speed_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_1->value(); + speed_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_1->value(); + speed_data->variables_[i].record_output = ui->comboBox_record_output_1->currentIndex(); + speed_data->variables_[i].two_ma_clamp = ui->checkBox_two_ma_clamp_1->isChecked(); + speed_data->variables_[i].alert_latching = ui->radioButton_alert_latching_1->isChecked(); + speed_data->variables_[i].overspeed_latching = ui->radioButton_overspeed_latching_1->isChecked(); + } else if (i + 1 == 2) { + speed_data->variables_[i].active = ui->checkBox_chan_2->isChecked(); + speed_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_2->value(); + speed_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_2->value(); + speed_data->variables_[i].speed_peek = ui->full_scale_range_2->value(); + speed_data->variables_[i].default_speed = ui->default_value_2->value(); + speed_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_2->isChecked(); + speed_data->variables_[i].threshold = ui->doubleSpinBox_threshold_2->value(); + speed_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_2->value(); + speed_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_2->value(); + speed_data->variables_[i].record_output = ui->comboBox_record_output_2->currentIndex(); + speed_data->variables_[i].two_ma_clamp = ui->checkBox_two_ma_clamp_2->isChecked(); + speed_data->variables_[i].alert_latching = ui->radioButton_alert_latching_2->isChecked(); + speed_data->variables_[i].overspeed_latching = ui->radioButton_overspeed_latching_2->isChecked(); + } else if (i + 1 == 3) { + speed_data->variables_[i].active = ui->checkBox_chan_3->isChecked(); + speed_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_3->value(); + speed_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_3->value(); + speed_data->variables_[i].speed_peek = ui->full_scale_range_3->value(); + speed_data->variables_[i].default_speed = ui->default_value_3->value(); + speed_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_3->isChecked(); + speed_data->variables_[i].threshold = ui->doubleSpinBox_threshold_3->value(); + speed_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_3->value(); + speed_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_3->value(); + speed_data->variables_[i].record_output = ui->comboBox_record_output_3->currentIndex(); + speed_data->variables_[i].two_ma_clamp = ui->checkBox_two_ma_clamp_3->isChecked(); + speed_data->variables_[i].alert_latching = ui->radioButton_alert_latching_3->isChecked(); + speed_data->variables_[i].overspeed_latching = ui->radioButton_overspeed_latching_3->isChecked(); + } else if (i + 1 == 4) { + speed_data->variables_[i].active = ui->checkBox_chan_4->isChecked(); + speed_data->variables_[i].normal_voltage_high = ui->doubleSpinBox_high_4->value(); + speed_data->variables_[i].normal_voltage_low = ui->doubleSpinBox_low_4->value(); + speed_data->variables_[i].speed_peek = ui->full_scale_range_4->value(); + speed_data->variables_[i].default_speed = ui->default_value_4->value(); + speed_data->variables_[i].automatic_threshold = ui->radioButton_automatic_threshold_4->isChecked(); + speed_data->variables_[i].threshold = ui->doubleSpinBox_threshold_4->value(); + speed_data->variables_[i].hysteresis = ui->doubleSpinBox_hysteresis_4->value(); + speed_data->variables_[i].events_per_revolution = ui->spinBox_events_per_revolution_4->value(); + speed_data->variables_[i].record_output = ui->comboBox_record_output_4->currentIndex(); + speed_data->variables_[i].two_ma_clamp = ui->checkBox_two_ma_clamp_4->isChecked(); + speed_data->variables_[i].alert_latching = ui->radioButton_alert_latching_4->isChecked(); + speed_data->variables_[i].overspeed_latching = ui->radioButton_overspeed_latching_4->isChecked(); + } } } + void Tachometer::Init() { + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + if (base_ptr == nullptr) { + // do nothing or use template to init it. + std::shared_ptr speed_data = std::make_shared(); + ConfigMgr::Instance()->AddCard(speed_data); + UpdateData(speed_data); + return; + } + std::shared_ptr speed_data = std::dynamic_pointer_cast(base_ptr); for (int i = 0; i < CHANNEL_COUNT; i++) { - if (tachometer_variables[i].id == 1) { - ui->checkBox_chan_1->setChecked(tachometer_variables[i].active); - ui->doubleSpinBox_high_1->setValue(tachometer_variables[i].normal_voltage_high); - ui->doubleSpinBox_low_1->setValue(tachometer_variables[i].normal_voltage_low); - if (tachometer_variables[i].automatic_threshold) { + if (i + 1 == 1) { + ui->checkBox_chan_1->setChecked(speed_data->variables_[i].active); + ui->doubleSpinBox_high_1->setValue(speed_data->variables_[i].normal_voltage_high); + ui->doubleSpinBox_low_1->setValue(speed_data->variables_[i].normal_voltage_low); + ui->full_scale_range_1->setValue(speed_data->variables_[i].speed_peek); + ui->default_value_1->setValue(speed_data->variables_[i].default_speed); + if (speed_data->variables_[i].automatic_threshold) { ui->radioButton_automatic_threshold_1->setChecked(true); } else { ui->radioButton_manual_threshold_1->setChecked(true); } - ui->doubleSpinBox_threshold_1->setValue(tachometer_variables[i].threshold); - ui->doubleSpinBox_hysteresis_1->setValue(tachometer_variables[i].hysteresis); - ui->spinBox_events_per_revolution_1->setValue(tachometer_variables[i].events_per_revolution); - ui->comboBox_record_output_1->setCurrentText(tachometer_variables[i].record_output); - ui->checkBox_two_ma_clamp_1->setChecked(tachometer_variables[i].two_ma_clamp); - if (tachometer_variables[i].alert_latching) { + ui->doubleSpinBox_threshold_1->setValue(speed_data->variables_[i].threshold); + ui->doubleSpinBox_hysteresis_1->setValue(speed_data->variables_[i].hysteresis); + ui->spinBox_events_per_revolution_1->setValue(speed_data->variables_[i].events_per_revolution); + ui->comboBox_record_output_1->setCurrentIndex(speed_data->variables_[i].record_output); + ui->checkBox_two_ma_clamp_1->setChecked(speed_data->variables_[i].two_ma_clamp); + if (speed_data->variables_[i].alert_latching) { ui->radioButton_alert_latching_1->setCheckable(true); } else { ui->radioButton_alert_latching_1->setCheckable(false); } - if (tachometer_variables[i].overspeed_latching) { + if (speed_data->variables_[i].overspeed_latching) { ui->radioButton_overspeed_latching_1->setCheckable(true); } else { ui->radioButton_overspeed_latching_1->setCheckable(false); } - } - if (tachometer_variables[i].id == 2) { - ui->checkBox_chan_2->setChecked(tachometer_variables[i].active); - ui->doubleSpinBox_high_2->setValue(tachometer_variables[i].normal_voltage_high); - ui->doubleSpinBox_low_2->setValue(tachometer_variables[i].normal_voltage_low); - if (tachometer_variables[i].automatic_threshold) { + } else if (i + 1 == 2) { + ui->checkBox_chan_2->setChecked(speed_data->variables_[i].active); + ui->doubleSpinBox_high_2->setValue(speed_data->variables_[i].normal_voltage_high); + ui->doubleSpinBox_low_2->setValue(speed_data->variables_[i].normal_voltage_low); + ui->full_scale_range_2->setValue(speed_data->variables_[i].speed_peek); + ui->default_value_2->setValue(speed_data->variables_[i].default_speed); + if (speed_data->variables_[i].automatic_threshold) { ui->radioButton_automatic_threshold_2->setChecked(true); } else { ui->radioButton_manual_threshold_2->setChecked(true); } - ui->doubleSpinBox_threshold_2->setValue(tachometer_variables[i].threshold); - ui->doubleSpinBox_hysteresis_2->setValue(tachometer_variables[i].hysteresis); - ui->spinBox_events_per_revolution_2->setValue(tachometer_variables[i].events_per_revolution); - ui->comboBox_record_output_2->setCurrentText(tachometer_variables[i].record_output); - ui->checkBox_two_ma_clamp_2->setChecked(tachometer_variables[i].two_ma_clamp); - if (tachometer_variables[i].alert_latching) { + ui->doubleSpinBox_threshold_2->setValue(speed_data->variables_[i].threshold); + ui->doubleSpinBox_hysteresis_2->setValue(speed_data->variables_[i].hysteresis); + ui->spinBox_events_per_revolution_2->setValue(speed_data->variables_[i].events_per_revolution); + ui->comboBox_record_output_2->setCurrentIndex(speed_data->variables_[i].record_output); + ui->checkBox_two_ma_clamp_2->setChecked(speed_data->variables_[i].two_ma_clamp); + if (speed_data->variables_[i].alert_latching) { ui->radioButton_alert_latching_2->setCheckable(true); } else { ui->radioButton_alert_latching_2->setCheckable(false); } - if (tachometer_variables[i].overspeed_latching) { + if (speed_data->variables_[i].overspeed_latching) { ui->radioButton_overspeed_latching_2->setCheckable(true); } else { ui->radioButton_overspeed_latching_2->setCheckable(false); } - } - if (tachometer_variables[i].id == 3) { - ui->checkBox_chan_3->setChecked(tachometer_variables[i].active); - ui->doubleSpinBox_high_3->setValue(tachometer_variables[i].normal_voltage_high); - ui->doubleSpinBox_low_3->setValue(tachometer_variables[i].normal_voltage_low); - if (tachometer_variables[i].automatic_threshold) { + } else if (i + 1 == 3) { + ui->checkBox_chan_3->setChecked(speed_data->variables_[i].active); + ui->doubleSpinBox_high_3->setValue(speed_data->variables_[i].normal_voltage_high); + ui->doubleSpinBox_low_3->setValue(speed_data->variables_[i].normal_voltage_low); + ui->full_scale_range_3->setValue(speed_data->variables_[i].speed_peek); + ui->default_value_3->setValue(speed_data->variables_[i].default_speed); + if (speed_data->variables_[i].automatic_threshold) { ui->radioButton_automatic_threshold_3->setChecked(true); } else { ui->radioButton_manual_threshold_3->setChecked(true); } - ui->doubleSpinBox_threshold_3->setValue(tachometer_variables[i].threshold); - ui->doubleSpinBox_hysteresis_3->setValue(tachometer_variables[i].hysteresis); - ui->spinBox_events_per_revolution_3->setValue(tachometer_variables[i].events_per_revolution); - ui->comboBox_record_output_3->setCurrentText(tachometer_variables[i].record_output); - ui->checkBox_two_ma_clamp_3->setChecked(tachometer_variables[i].two_ma_clamp); - if (tachometer_variables[i].alert_latching) { + ui->doubleSpinBox_threshold_3->setValue(speed_data->variables_[i].threshold); + ui->doubleSpinBox_hysteresis_3->setValue(speed_data->variables_[i].hysteresis); + ui->spinBox_events_per_revolution_3->setValue(speed_data->variables_[i].events_per_revolution); + ui->comboBox_record_output_3->setCurrentIndex(speed_data->variables_[i].record_output); + ui->checkBox_two_ma_clamp_3->setChecked(speed_data->variables_[i].two_ma_clamp); + if (speed_data->variables_[i].alert_latching) { ui->radioButton_alert_latching_3->setCheckable(true); } else { ui->radioButton_alert_latching_3->setCheckable(false); } - if (tachometer_variables[i].overspeed_latching) { + if (speed_data->variables_[i].overspeed_latching) { ui->radioButton_overspeed_latching_3->setCheckable(true); } else { ui->radioButton_overspeed_latching_3->setCheckable(false); } - } - if (tachometer_variables[i].id == 4) { - ui->checkBox_chan_4->setChecked(tachometer_variables[i].active); - ui->doubleSpinBox_high_4->setValue(tachometer_variables[i].normal_voltage_high); - ui->doubleSpinBox_low_4->setValue(tachometer_variables[i].normal_voltage_low); - if (tachometer_variables[i].automatic_threshold) { + } else if (i + 1 == 4) { + ui->checkBox_chan_4->setChecked(speed_data->variables_[i].active); + ui->doubleSpinBox_high_4->setValue(speed_data->variables_[i].normal_voltage_high); + ui->doubleSpinBox_low_4->setValue(speed_data->variables_[i].normal_voltage_low); + ui->full_scale_range_4->setValue(speed_data->variables_[i].speed_peek); + ui->default_value_4->setValue(speed_data->variables_[i].default_speed); + if (speed_data->variables_[i].automatic_threshold) { ui->radioButton_automatic_threshold_4->setChecked(true); } else { ui->radioButton_manual_threshold_4->setChecked(true); } - ui->doubleSpinBox_threshold_4->setValue(tachometer_variables[i].threshold); - ui->doubleSpinBox_hysteresis_4->setValue(tachometer_variables[i].hysteresis); - ui->spinBox_events_per_revolution_4->setValue(tachometer_variables[i].events_per_revolution); - ui->comboBox_record_output_4->setCurrentText(tachometer_variables[i].record_output); - ui->checkBox_two_ma_clamp_4->setChecked(tachometer_variables[i].two_ma_clamp); - if (tachometer_variables[i].alert_latching) { + ui->doubleSpinBox_threshold_4->setValue(speed_data->variables_[i].threshold); + ui->doubleSpinBox_hysteresis_4->setValue(speed_data->variables_[i].hysteresis); + ui->spinBox_events_per_revolution_4->setValue(speed_data->variables_[i].events_per_revolution); + ui->comboBox_record_output_4->setCurrentIndex(speed_data->variables_[i].record_output); + ui->checkBox_two_ma_clamp_4->setChecked(speed_data->variables_[i].two_ma_clamp); + if (speed_data->variables_[i].alert_latching) { ui->radioButton_alert_latching_4->setCheckable(true); } else { ui->radioButton_alert_latching_4->setCheckable(false); } - if (tachometer_variables[i].overspeed_latching) { + if (speed_data->variables_[i].overspeed_latching) { ui->radioButton_overspeed_latching_4->setCheckable(true); } else { ui->radioButton_overspeed_latching_4->setCheckable(false); @@ -212,100 +254,18 @@ void Tachometer::Init() { } } } + void Tachometer::on_pushButton_confirm_clicked() { - for (int i = 0; i < CHANNEL_COUNT; i++) { - if (tachometer_variables[i].id == 1) { - tachometer_variables[i].active = ui->checkBox_chan_1->isChecked(); - tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_1->value(); - tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_1->value(); - tachometer_variables[i].automatic_threshold = ui->radioButton_automatic_threshold_1->isChecked(); - tachometer_variables[i].threshold = ui->doubleSpinBox_threshold_1->value(); - tachometer_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_1->value(); - tachometer_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_1->value(); - tachometer_variables[i].record_output = ui->comboBox_record_output_1->currentText(); - tachometer_variables[i].two_ma_clamp = ui->checkBox_two_ma_clamp_1->isChecked(); - tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_1->isChecked(); - tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_1->isChecked(); - } - if (tachometer_variables[i].id == 2) { - tachometer_variables[i].active = ui->checkBox_chan_2->isChecked(); - tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_2->value(); - tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_2->value(); - tachometer_variables[i].automatic_threshold = ui->radioButton_automatic_threshold_2->isChecked(); - tachometer_variables[i].threshold = ui->doubleSpinBox_threshold_2->value(); - tachometer_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_2->value(); - tachometer_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_2->value(); - tachometer_variables[i].record_output = ui->comboBox_record_output_2->currentText(); - tachometer_variables[i].two_ma_clamp = ui->checkBox_two_ma_clamp_2->isChecked(); - tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_2->isChecked(); - tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_2->isChecked(); - } - if (tachometer_variables[i].id == 3) { - tachometer_variables[i].active = ui->checkBox_chan_3->isChecked(); - tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_3->value(); - tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_3->value(); - tachometer_variables[i].automatic_threshold = ui->radioButton_automatic_threshold_3->isChecked(); - tachometer_variables[i].threshold = ui->doubleSpinBox_threshold_3->value(); - tachometer_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_3->value(); - tachometer_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_3->value(); - tachometer_variables[i].record_output = ui->comboBox_record_output_3->currentText(); - tachometer_variables[i].two_ma_clamp = ui->checkBox_two_ma_clamp_3->isChecked(); - tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_3->isChecked(); - tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_3->isChecked(); - } - if (tachometer_variables[i].id == 4) { - tachometer_variables[i].active = ui->checkBox_chan_4->isChecked(); - tachometer_variables[i].normal_voltage_high = ui->doubleSpinBox_high_4->value(); - tachometer_variables[i].normal_voltage_low = ui->doubleSpinBox_low_4->value(); - tachometer_variables[i].automatic_threshold = ui->radioButton_automatic_threshold_4->isChecked(); - tachometer_variables[i].threshold = ui->doubleSpinBox_threshold_4->value(); - tachometer_variables[i].hysteresis = ui->doubleSpinBox_hysteresis_4->value(); - tachometer_variables[i].events_per_revolution = ui->spinBox_events_per_revolution_4->value(); - tachometer_variables[i].record_output = ui->comboBox_record_output_4->currentText(); - tachometer_variables[i].two_ma_clamp = ui->checkBox_two_ma_clamp_4->isChecked(); - tachometer_variables[i].alert_latching = ui->radioButton_alert_latching_4->isChecked(); - tachometer_variables[i].overspeed_latching = ui->radioButton_overspeed_latching_4->isChecked(); - } - } - QString slot = QString("%1").arg(slot_no); - QString filePath_tachometer = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\tachometer.json").arg(slot_no); - QFile file(filePath_tachometer); - if (!file.open(QIODevice::WriteOnly)) { - qDebug() << "Could not open file for writing"; + std::shared_ptr base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no); + if (base_ptr == nullptr) { + qCritical() << " should not be here"; return; } - QJsonObject json_obj; - QJsonArray chan_array; - for (int i = 0; i < CHANNEL_COUNT; i++) { - QJsonObject temp_obj; - temp_obj.insert("id", tachometer_variables[i].id); - temp_obj.insert("active", tachometer_variables[i].active); - QJsonArray voltage_range_array; - voltage_range_array.append(tachometer_variables[i].normal_voltage_low); - voltage_range_array.append(tachometer_variables[i].normal_voltage_high); - temp_obj.insert("normal_voltage_range", voltage_range_array); - temp_obj.insert("threshold", tachometer_variables[i].threshold); - temp_obj.insert("hysteresis", tachometer_variables[i].hysteresis); - temp_obj.insert("events_per_revolution", tachometer_variables[i].events_per_revolution); - temp_obj.insert("record_output", tachometer_variables[i].record_output); - temp_obj.insert("two_ma_clamp", tachometer_variables[i].two_ma_clamp); - temp_obj.insert("alert_latching", tachometer_variables[i].alert_latching); - temp_obj.insert("overspeed_latching", tachometer_variables[i].overspeed_latching); - temp_obj.insert("normal_latching", tachometer_variables[i].normal_latching); - temp_obj.insert("alert_response_time", tachometer_variables[i].alert_response_time); - temp_obj.insert("danger_response_time", tachometer_variables[i].danger_response_time); - chan_array.append(temp_obj); - } - json_obj.insert("chan", chan_array); - json_obj.insert("version", 1); - json_obj.insert("slot", slot_no); - json_obj.insert("card_type", 2); - QJsonDocument json_doc; - json_doc.setObject(json_obj); - QByteArray byte_array = json_doc.toJson(); - file.write(byte_array); - file.close(); + std::shared_ptr speed_data = std::dynamic_pointer_cast(base_ptr); + UpdateData(speed_data); + this->close(); } + void Tachometer::on_pushButton_cancel_clicked() { this->close(); } diff --git a/tachometer.h b/tachometer.h index 716e595..6a28768 100644 --- a/tachometer.h +++ b/tachometer.h @@ -3,6 +3,8 @@ #include #include "data_config.h" +#include "config_mgr.h" +#include "tachometer_data.h" namespace Ui { class Tachometer; } @@ -23,10 +25,10 @@ class Tachometer : public QDialog { void on_manual_threshold_4_clicked(bool checked); private: Ui::Tachometer *ui; + void UpdateData(std::shared_ptr &speed_data); +// Tachometer_Variables tachometer_variables[4]; - Tachometer_Variables tachometer_variables[4]; - - void readJsonFile(const QString &filePath); +// void readJsonFile(const QString &filePath); void Init(); }; diff --git a/tachometer.ui b/tachometer.ui index 0dd6559..b237a99 100644 --- a/tachometer.ui +++ b/tachometer.ui @@ -344,7 +344,7 @@ - 1 - 255 + 1 - 10000 @@ -503,7 +503,7 @@ 50.000000000000000 - 2.000000000000000 + 0.500000000000000 @@ -621,7 +621,7 @@ 60 310 - 51 + 71 22 @@ -629,13 +629,13 @@ 1 - 255 + 10000 - 310 + 480 10 191 91 @@ -755,6 +755,77 @@ + + + + 280 + 20 + 191 + 71 + + + + 转速 + + + + + 40 + 17 + 31 + 16 + + + + 上限 + + + + + + 120 + 20 + 54 + 12 + + + + 默认值 + + + + + + 20 + 40 + 81 + 22 + + + + 100000 + + + 1 + + + 5000 + + + + + + 120 + 40 + 42 + 22 + + + + 10000 + + + @@ -929,7 +1000,7 @@ 60 310 - 51 + 81 22 @@ -937,7 +1008,7 @@ 1 - 255 + 10000 @@ -950,7 +1021,7 @@ - 1 - 255 + 1 - 10000 @@ -1053,7 +1124,7 @@ - 310 + 480 20 191 91 @@ -1135,6 +1206,9 @@ + + false + 180 @@ -1151,6 +1225,9 @@ + + false + 180 @@ -1321,6 +1398,77 @@ + + + + 280 + 20 + 191 + 71 + + + + 转速 + + + + + 40 + 17 + 31 + 16 + + + + 上限 + + + + + + 120 + 20 + 54 + 12 + + + + 默认值 + + + + + + 20 + 40 + 81 + 22 + + + + 100000 + + + 1 + + + 5000 + + + + + + 120 + 40 + 42 + 22 + + + + 10000 + + + @@ -1495,7 +1643,7 @@ 60 310 - 51 + 71 22 @@ -1503,7 +1651,7 @@ 1 - 255 + 10000 @@ -1516,7 +1664,7 @@ - 1 - 255 + 1 - 10000 @@ -1619,7 +1767,7 @@ - 310 + 480 20 191 91 @@ -1701,6 +1849,9 @@ + + false + 180 @@ -1717,6 +1868,9 @@ + + false + 180 @@ -1887,6 +2041,77 @@ + + + + 280 + 20 + 191 + 71 + + + + 转速 + + + + + 40 + 17 + 31 + 16 + + + + 上限 + + + + + + 120 + 20 + 54 + 12 + + + + 默认值 + + + + + + 20 + 40 + 81 + 22 + + + + 100000 + + + 1 + + + 5000 + + + + + + 120 + 40 + 42 + 22 + + + + 10000 + + + @@ -2056,7 +2281,7 @@ - 1 - 255 + 1 - 10000 @@ -2064,7 +2289,7 @@ 60 310 - 51 + 71 22 @@ -2072,7 +2297,7 @@ 1 - 255 + 10000 @@ -2188,7 +2413,7 @@ - 310 + 490 20 191 91 @@ -2270,6 +2495,9 @@ + + false + 180 @@ -2286,6 +2514,9 @@ + + false + 180 @@ -2456,6 +2687,77 @@ + + + + 280 + 20 + 191 + 71 + + + + 转速 + + + + + 40 + 17 + 31 + 16 + + + + 上限 + + + + + + 120 + 20 + 54 + 12 + + + + 默认值 + + + + + + 20 + 40 + 81 + 22 + + + + 100000 + + + 1 + + + 5000 + + + + + + 120 + 40 + 42 + 22 + + + + 10000 + + + @@ -2518,8 +2820,8 @@ - + diff --git a/tachometer_data.cpp b/tachometer_data.cpp new file mode 100644 index 0000000..16f736c --- /dev/null +++ b/tachometer_data.cpp @@ -0,0 +1,6 @@ +#include "tachometer_data.h" + +TachometerData::TachometerData() +{ + +} diff --git a/tachometer_data.h b/tachometer_data.h new file mode 100644 index 0000000..3ce955f --- /dev/null +++ b/tachometer_data.h @@ -0,0 +1,13 @@ +#ifndef TACHOMETERDATA_H +#define TACHOMETERDATA_H + +#include "cardbase.h" + +class TachometerData : public CardBase { + public: + TachometerData(); + + TachometerVariables variables_[4]; +}; + +#endif // TACHOMETERDATA_H