TSI_Config/acceleration.cpp

334 lines
17 KiB
C++
Raw Normal View History

2024-12-17 18:53:41 +08:00
#include "acceleration.h"
#include "ui_acceleration.h"
2025-02-25 11:18:20 +08:00
#include <QDebug>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QFile>
2024-12-17 18:53:41 +08:00
2025-04-01 15:03:59 +08:00
#include "data_config.h"
#include "vibrationdata.h"
#include "config_mgr.h"
2025-03-28 10:17:18 +08:00
Acceleration::Acceleration(int slot_no_, int channel_, bool active, QWidget *parent) :
2024-12-17 18:53:41 +08:00
QWidget(parent),
2025-03-28 10:17:18 +08:00
ui(new Ui::Acceleration) {
2024-12-17 18:53:41 +08:00
ui->setupUi(this);
2025-02-25 11:18:20 +08:00
slot_no = slot_no_;
channel = channel_;
QString chan = QString("%1").arg(channel);
QString slot = QString("%1").arg(slot_no);
ui->label_channel->setText(chan);
ui->label_slot->setText(slot);
2025-03-28 10:17:18 +08:00
if (active) {
2025-02-25 11:18:20 +08:00
ui->label_active->setText("(启用)");
2025-03-28 10:17:18 +08:00
} else {
2025-02-25 11:18:20 +08:00
ui->label_active->setText("(停用)");
2025-03-28 10:17:18 +08:00
}
2025-04-01 15:03:59 +08:00
// QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
// readJsonFile(filePath_filter);
// QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\acceleration_variables_%2.json").arg(slot_no).arg(channel);
// readJsonFile(filePath_variables);
2025-02-25 11:18:20 +08:00
Init();
2024-12-17 18:53:41 +08:00
}
2025-03-28 10:17:18 +08:00
Acceleration::~Acceleration() {
2024-12-17 18:53:41 +08:00
delete ui;
}
2025-03-28 10:17:18 +08:00
2025-03-28 15:32:39 +08:00
void Acceleration::on_checkBox_rms_toggled(bool checked) {
2025-03-28 12:11:17 +08:00
// TODO: 自定义的回调
if (checked) {
if (ui->checkBox_integrate->isChecked()) {
QStringList items = {"0-25 mm/s rms", "0-50 mm/s rms", "自定义"};
ui->comboBox_direct_value_range->clear();
ui->comboBox_direct_value_range->addItems(items);
ui->comboBox_direct_value_range->setCurrentIndex(0);
ui->comboBox_1x_value_range->clear();
ui->comboBox_1x_value_range->addItems(items);
ui->comboBox_1x_value_range->setCurrentIndex(0);
ui->comboBox_2x_value_range->clear();
ui->comboBox_2x_value_range->addItems(items);
ui->comboBox_2x_value_range->setCurrentIndex(0);
} else {
QStringList items = {"0-20 m/s^2 rms", "0-50 m/s^2 rms", "0-100 m/s^2 rms", "0-200 m/s^2 rms", "自定义"};
ui->comboBox_direct_value_range->clear();
ui->comboBox_direct_value_range->addItems(items);
ui->comboBox_direct_value_range->setCurrentIndex(0);
ui->comboBox_1x_value_range->clear();
ui->comboBox_1x_value_range->addItems(items);
ui->comboBox_1x_value_range->setCurrentIndex(0);
ui->comboBox_2x_value_range->clear();
ui->comboBox_2x_value_range->addItems(items);
ui->comboBox_2x_value_range->setCurrentIndex(0);
}
return;
}
if (ui->checkBox_integrate->isChecked()) {
QStringList items = {"0-25 mm/s pk", "0-50 mm/s pk", "0-100 mm/s pk", "自定义"};
ui->comboBox_direct_value_range->clear();
ui->comboBox_direct_value_range->addItems(items);
ui->comboBox_direct_value_range->setCurrentIndex(0);
ui->comboBox_1x_value_range->clear();
ui->comboBox_1x_value_range->addItems(items);
ui->comboBox_1x_value_range->setCurrentIndex(0);
ui->comboBox_2x_value_range->clear();
ui->comboBox_2x_value_range->addItems(items);
ui->comboBox_2x_value_range->setCurrentIndex(0);
} else {
QStringList items = {"0-20 m/s^2 pk", "0-50 m/s^2 pk", "0-100 m/s^2 pk", "0-200 m/s^2 pk", "0-250 m/s^2 pk", "0-400 m/s^2 pk", "自定义"};
ui->comboBox_direct_value_range->clear();
ui->comboBox_direct_value_range->addItems(items);
ui->comboBox_direct_value_range->setCurrentIndex(0);
ui->comboBox_1x_value_range->clear();
ui->comboBox_1x_value_range->addItems(items);
ui->comboBox_1x_value_range->setCurrentIndex(0);
ui->comboBox_2x_value_range->clear();
ui->comboBox_2x_value_range->addItems(items);
ui->comboBox_2x_value_range->setCurrentIndex(0);
}
}
2025-03-28 15:32:39 +08:00
void Acceleration::on_checkBox_integrate_toggled(bool checked) {
2025-03-28 12:11:17 +08:00
// TODO: 自定义的回调
if (checked) {
if (ui->checkBox_rms->isChecked()) {
QStringList items = {"0-25 mm/s rms", "0-50 mm/s rms", "自定义"};
ui->comboBox_direct_value_range->clear();
ui->comboBox_direct_value_range->addItems(items);
ui->comboBox_direct_value_range->setCurrentIndex(0);
ui->comboBox_1x_value_range->clear();
ui->comboBox_1x_value_range->addItems(items);
ui->comboBox_1x_value_range->setCurrentIndex(0);
ui->comboBox_2x_value_range->clear();
ui->comboBox_2x_value_range->addItems(items);
ui->comboBox_2x_value_range->setCurrentIndex(0);
} else {
QStringList items = {"0-25 mm/s pk", "0-50 mm/s pk", "0-100 mm/s pk", "自定义"};
ui->comboBox_direct_value_range->clear();
ui->comboBox_direct_value_range->addItems(items);
ui->comboBox_direct_value_range->setCurrentIndex(0);
ui->comboBox_1x_value_range->clear();
ui->comboBox_1x_value_range->addItems(items);
ui->comboBox_1x_value_range->setCurrentIndex(0);
ui->comboBox_2x_value_range->clear();
ui->comboBox_2x_value_range->addItems(items);
ui->comboBox_2x_value_range->setCurrentIndex(0);
}
return;
}
if (ui->checkBox_rms->isChecked()) {
QStringList items = {"0-20 m/s^2 rms", "0-50 m/s^2 rms", "0-100 m/s^2 rms", "0-200 m/s^2 rms", "自定义"};
ui->comboBox_direct_value_range->clear();
ui->comboBox_direct_value_range->addItems(items);
ui->comboBox_direct_value_range->setCurrentIndex(0);
ui->comboBox_1x_value_range->clear();
ui->comboBox_1x_value_range->addItems(items);
ui->comboBox_1x_value_range->setCurrentIndex(0);
ui->comboBox_2x_value_range->clear();
ui->comboBox_2x_value_range->addItems(items);
ui->comboBox_2x_value_range->setCurrentIndex(0);
} else {
QStringList items = {"0-20 m/s^2 pk", "0-50 m/s^2 pk", "0-100 m/s^2 pk", "0-200 m/s^2 pk", "0-250 m/s^2 pk", "0-400 m/s^2 pk", "自定义"};
ui->comboBox_direct_value_range->clear();
ui->comboBox_direct_value_range->addItems(items);
ui->comboBox_direct_value_range->setCurrentIndex(0);
ui->comboBox_1x_value_range->clear();
ui->comboBox_1x_value_range->addItems(items);
ui->comboBox_1x_value_range->setCurrentIndex(0);
ui->comboBox_2x_value_range->clear();
ui->comboBox_2x_value_range->addItems(items);
ui->comboBox_2x_value_range->setCurrentIndex(0);
}
}
2025-03-28 15:32:39 +08:00
void Acceleration::on_checkBox_1x_ampl_toggled(bool checked) {
2025-03-28 10:17:18 +08:00
if (checked) {
ui->comboBox_1x_value_range->setEnabled(true);
ui->doubleSpinBox_1x_ampl_clamp->setEnabled(true);
ui->doubleSpinBox_1x_phase_lag_clamp->setEnabled(true);
return;
}
ui->comboBox_1x_value_range->setEnabled(false);
ui->doubleSpinBox_1x_ampl_clamp->setEnabled(false);
ui->doubleSpinBox_1x_phase_lag_clamp->setEnabled(false);
}
2025-03-28 15:32:39 +08:00
void Acceleration::on_checkBox_2x_ampl_toggled(bool checked) {
2025-03-28 10:17:18 +08:00
if (checked) {
ui->comboBox_2x_value_range->setEnabled(true);
ui->doubleSpinBox_2x_ampl_clamp->setEnabled(true);
ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(true);
return;
}
ui->comboBox_2x_value_range->setEnabled(false);
ui->doubleSpinBox_2x_ampl_clamp->setEnabled(false);
ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(false);
}
void Acceleration::Init() {
2025-04-01 15:03:59 +08:00
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
2025-04-01 15:29:35 +08:00
if (base_ptr == nullptr) {
qCritical() << "[Acceleration::Init] should not be here";
return;
}
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
if (ptr->base_config_[channel - 1].channel_type != kVibAcc) {
2025-04-01 16:29:19 +08:00
// user change the channel type, load acceleration template
// std::shared_ptr<VibrationData> vib_data = std::make_shared<VibrationData>();
// ConfigMgr::Instance()->AddCard(vib_data);
// UpdateData(vib_data);
2025-04-01 15:29:35 +08:00
return;
2025-02-25 11:18:20 +08:00
}
2025-04-01 15:29:35 +08:00
ui->checkBox_low_pass->setChecked(ptr->filter_[channel - 1].filter[0].checked);
ui->spinBox_low_pass_low->setValue(ptr->filter_[channel - 1].filter[0].low);
ui->spinBox_low_pass_high->setValue(ptr->filter_[channel - 1].filter[0].high);
ui->checkBox_high_pass->setChecked(ptr->filter_[channel - 1].filter[1].checked);
ui->spinBox_high_pass_low->setValue(ptr->filter_[channel - 1].filter[1].low);
ui->spinBox_high_pass_high->setValue(ptr->filter_[channel - 1].filter[1].high);
ui->checkBox_band_pass->setChecked(ptr->filter_[channel - 1].filter[2].checked);
ui->spinBox_band_pass_low->setValue(ptr->filter_[channel - 1].filter[2].low);
ui->spinBox_band_pass_high->setValue(ptr->filter_[channel - 1].filter[2].high);
2025-04-01 16:29:19 +08:00
std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel);
if (variable_base == nullptr) {
qDebug() << "no channel ptr";
return;
2025-02-25 11:18:20 +08:00
}
2025-04-01 16:29:19 +08:00
std::shared_ptr<AccVelVariable> variable_ptr = std::dynamic_pointer_cast<AccVelVariable>(variable_base);
ui->comboBox_direct_value_range->setCurrentIndex(variable_ptr->direct_.full_scale_range);
ui->doubleSpinBox_direct_clamp->setValue(variable_ptr->direct_.clamp_value);
// ui->label_bias_voltage->setText(QString::number(variable_ptr->direct_.bias_voltage));
// ui->doubleSpinBox_bias_volt_clamp->setValue(variables[i].clamp_value);
// ui->comboBox_bias_volt_range->setCurrentIndex();
ui->checkBox_1x_ampl->setChecked(variable_ptr->x1_.checked);
ui->comboBox_1x_value_range->setCurrentIndex(variable_ptr->x1_.full_scale_range);
ui->doubleSpinBox_1x_ampl_clamp->setValue(variable_ptr->x1_.clamp_value);
ui->doubleSpinBox_1x_phase_lag_clamp->setValue(variable_ptr->x1_.phase_lag);
ui->checkBox_2x_ampl->setChecked(variable_ptr->x2_.checked);
ui->comboBox_2x_value_range->setCurrentIndex(variable_ptr->x2_.full_scale_range);
ui->doubleSpinBox_2x_ampl_clamp->setValue(variable_ptr->x2_.clamp_value);
ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->x2_.phase_lag);
ui->spinBox_alert->setValue(variable_ptr->delay_.alert);
ui->doubleSpinBox_danger->setValue(variable_ptr->delay_.danger);
ui->checkBox_100ms->setChecked(variable_ptr->delay_.active_100ms);
ui->checkBox_rms->setChecked(variable_ptr->rms_active_);
ui->checkBox_integrate->setChecked(variable_ptr->integrate_active_);
ui->checkBox_alert_latching->setChecked(variable_ptr->alert_latching_);
ui->checkBox_danger_latching->setChecked(variable_ptr->danger_latching_);
ui->checkBox_timed_ok->setChecked(variable_ptr->timed_ok_);
ui->comboBox_recorder_output->setCurrentIndex(variable_ptr->recorder_out_.recorder_output);
ui->checkBox_two_ma_clamp->setChecked(variable_ptr->recorder_out_.two_ma_clamp);
ui->doubleSpinBox_trip_multiply->setValue(variable_ptr->recorder_out_.trip_multiply);
ui->comboBox_comparision->setCurrentIndex(variable_ptr->recorder_out_.comparision);
ui->spinBox_comparision_percentage->setValue(variable_ptr->recorder_out_.percentage);
2025-02-25 11:18:20 +08:00
}
2025-03-28 10:17:18 +08:00
void Acceleration::on_pushButton_confirm_clicked() {
2025-02-25 11:18:20 +08:00
for (int i = 0; i < 3; i++) {
2025-03-28 10:17:18 +08:00
if (filter[i].type == "band_pass") {
2025-03-23 14:03:48 +08:00
filter[i].checked = ui->checkBox_band_pass->isChecked();
filter[i].low = ui->spinBox_band_pass_low->value();
filter[i].high = ui->spinBox_band_pass_high->value();
2025-03-28 10:17:18 +08:00
} else if (filter[i].type == "low_pass") {
2025-03-23 14:03:48 +08:00
filter[i].checked = ui->checkBox_low_pass->isChecked();
filter[i].low = ui->spinBox_low_pass_low->value();
filter[i].high = ui->spinBox_low_pass_high->value();
2025-03-28 10:17:18 +08:00
} else if (filter[i].type == "high_pass") {
2025-03-23 14:03:48 +08:00
filter[i].checked = ui->checkBox_high_pass->isChecked();
filter[i].low = ui->spinBox_high_pass_low->value();
filter[i].high = ui->spinBox_high_pass_high->value();
2025-02-25 11:18:20 +08:00
}
}
for (int i = 0; i < 4; i++) {
2025-03-28 10:17:18 +08:00
if (variables[i].type == "direct") {
2025-03-28 15:32:39 +08:00
variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentIndex();
2025-02-25 11:18:20 +08:00
variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "bias_volt") {
2025-02-25 11:18:20 +08:00
variables[i].clamp_value = ui->doubleSpinBox_bias_volt_clamp->value();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "1x_ampl") {
2025-02-25 11:18:20 +08:00
variables[i].checked = ui->checkBox_1x_ampl->isChecked();
2025-03-28 15:32:39 +08:00
variables[i].full_sacle_range = ui->comboBox_1x_value_range->currentIndex();
2025-02-25 11:18:20 +08:00
variables[i].clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variables[i].clamp_value = ui->doubleSpinBox_1x_phase_lag_clamp->value();
2025-03-28 10:17:18 +08:00
} else if (variables[i].type == "2x_ampl") {
2025-02-25 11:18:20 +08:00
variables[i].checked = ui->checkBox_2x_ampl->isChecked();
2025-03-28 15:32:39 +08:00
variables[i].full_sacle_range = ui->comboBox_2x_value_range->currentIndex();
2025-02-25 11:18:20 +08:00
variables[i].clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
variables[i].clamp_value = ui->doubleSpinBox_2x_phase_lag_clamp->value();
}
}
delay.alert = ui->spinBox_alert->value();
delay.danger = ui->doubleSpinBox_danger->value();
delay.active_100ms = ui->checkBox_100ms->isChecked();
alert_variables.rms_active = ui->checkBox_rms->isChecked();
alert_variables.integrate_active = ui->checkBox_integrate->isChecked();
alert_variables.alert_latching = ui->checkBox_alert_latching->isChecked();
alert_variables.danger_latching = ui->checkBox_danger_latching->isChecked();
alert_variables.timed_ok = ui->checkBox_timed_ok->isChecked();
2025-03-28 15:32:39 +08:00
alert_variables.recorder_output = ui->comboBox_recorder_output->currentIndex();
2025-02-25 11:18:20 +08:00
alert_variables.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
2025-03-20 14:38:14 +08:00
alert_variables.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
2025-02-25 11:18:20 +08:00
alert_variables.comparision = ui->comboBox_comparision->currentText();
alert_variables.comparision_percentage = ui->spinBox_comparision_percentage->value();
2025-03-28 10:17:18 +08:00
QJsonObject filter_obj, variables_obj;
2025-02-25 11:18:20 +08:00
QJsonArray filter_array;
2025-03-28 10:17:18 +08:00
for (int i = 0; i < 3; i++) {
2025-02-25 11:18:20 +08:00
QJsonObject temp_obj;
2025-03-28 10:17:18 +08:00
temp_obj.insert("type", filter[i].type);
temp_obj.insert("low", filter[i].low);
temp_obj.insert("high", filter[i].high);
temp_obj.insert("checked", filter[i].checked);
2025-02-25 11:18:20 +08:00
filter_array.append(temp_obj);
}
2025-03-28 10:17:18 +08:00
filter_obj.insert("filter", filter_array);
filter_obj.insert("slot", slot_no);
filter_obj.insert("id", channel);
filter_obj.insert("version", 1);
2025-02-25 11:18:20 +08:00
QJsonArray variables_array;
2025-03-28 10:17:18 +08:00
for (int i = 0; i < 4; i++) {
2025-02-25 11:18:20 +08:00
QJsonObject temp_obj;
2025-03-28 10:17:18 +08:00
temp_obj.insert("type", variables[i].type);
if (variables[i].type == "direct") {
temp_obj.insert("full_sacle_range", variables[i].full_sacle_range);
temp_obj.insert("clamp_value", variables[i].clamp_value);
} else if (variables[i].type == "bias_volt") {
temp_obj.insert("clamp_value", variables[i].clamp_value);
temp_obj.insert("full_sacle_range", variables[i].full_sacle_range);
} else if (variables[i].type == "1x_ampl" || variables[i].type == "2x_ampl") {
temp_obj.insert("checked", variables[i].checked);
temp_obj.insert("full_sacle_range", variables[i].full_sacle_range);
temp_obj.insert("clamp_value", variables[i].clamp_value);
temp_obj.insert("phase_lag", variables[i].phase_lag);
2025-03-23 14:03:48 +08:00
}
2025-02-25 11:18:20 +08:00
variables_array.append(temp_obj);
}
2025-03-28 10:17:18 +08:00
variables_obj.insert("variables", variables_array);
2025-02-25 11:18:20 +08:00
QJsonObject delay_obj;
2025-03-28 10:17:18 +08:00
delay_obj.insert("alert", delay.alert);
delay_obj.insert("danger", delay.danger);
delay_obj.insert("100ms", delay.active_100ms);
variables_obj.insert("delay", delay_obj);
variables_obj.insert("rms_active", alert_variables.rms_active);
variables_obj.insert("integrate_active", alert_variables.integrate_active);
variables_obj.insert("alert_latching", alert_variables.alert_latching);
variables_obj.insert("danger_latching", alert_variables.danger_latching);
variables_obj.insert("timed_ok", alert_variables.timed_ok);
variables_obj.insert("recorder_output", alert_variables.recorder_output);
variables_obj.insert("two_ma_clamp", alert_variables.two_ma_clamp);
variables_obj.insert("trip_multiply", alert_variables.trip_multiply);
variables_obj.insert("comparision", alert_variables.comparision);
variables_obj.insert("comparision_percentage", alert_variables.comparision_percentage);
variables_obj.insert("slot", slot_no);
variables_obj.insert("id", channel);
variables_obj.insert("version", 1);
this->close();
2025-02-25 11:18:20 +08:00
}
2025-03-28 10:17:18 +08:00
void Acceleration::on_pushButton_set_default_clicked() {
2025-03-20 14:38:14 +08:00
}
2025-03-28 10:17:18 +08:00
void Acceleration::on_pushButton_cancel_clicked() {
this->close();
}