add codes.

This commit is contained in:
pandx 2025-04-01 18:19:59 +08:00
parent 4c8d546c84
commit 44c0daefe8
4 changed files with 357 additions and 492 deletions

View File

@ -228,9 +228,6 @@ void Acceleration::on_pushButton_confirm_clicked() {
} }
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr); std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel); std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel);
if (variable_base->type_ != kVibAcc) {
return;
}
if (variable_base == nullptr || variable_base->type_ != kVibAcc) { if (variable_base == nullptr || variable_base->type_ != kVibAcc) {
if (variable_base == nullptr) { if (variable_base == nullptr) {
qDebug() << "no channel ptr"; qDebug() << "no channel ptr";

View File

@ -6,6 +6,10 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include "data_config.h"
#include "vibrationdata.h"
#include "config_mgr.h"
Radial_vibration::Radial_vibration(int slot_no_, int channel_, bool active, QWidget *parent) Radial_vibration::Radial_vibration(int slot_no_, int channel_, bool active, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::Radial_vibration) { , ui(new Ui::Radial_vibration) {
@ -21,10 +25,10 @@ Radial_vibration::Radial_vibration(int slot_no_, int channel_, bool active, QWid
} else { } else {
ui->label_active->setText("(停用)"); ui->label_active->setText("(停用)");
} }
QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel); // QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
readJsonFile(filePath_filter); // readJsonFile(filePath_filter);
QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\radial_vibration_variables_%2.json").arg(slot_no).arg(channel); // QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\radial_vibration_variables_%2.json").arg(slot_no).arg(channel);
readJsonFile(filePath_variables); // readJsonFile(filePath_variables);
Init(); Init();
} }
@ -80,256 +84,221 @@ void Radial_vibration::on_checkBox_smax_ampl_toggled(bool checked) {
ui->doubleSpinBox_smax_clamp->setEnabled(false); ui->doubleSpinBox_smax_clamp->setEnabled(false);
} }
void Radial_vibration::readJsonFile(const QString &filePath) { //void Radial_vibration::readJsonFile(const QString &filePath) {
// 创建文件对象 // // 创建文件对象
QFile file(filePath); // QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { // if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for reading:" << filePath; // qDebug() << "Cannot open file for reading:" << filePath;
return; // return;
} // }
QString content = file.readAll(); // QString content = file.readAll();
file.close(); // file.close();
QByteArray jsonData = content.toUtf8(); // QByteArray jsonData = content.toUtf8();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData); // QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (jsonDoc.isNull()) { // if (jsonDoc.isNull()) {
qDebug() << "Cannot parse JSON document"; // qDebug() << "Cannot parse JSON document";
return; // return;
} // }
if (!jsonDoc.isObject() && !jsonDoc.isArray()) { // if (!jsonDoc.isObject() && !jsonDoc.isArray()) {
qDebug() << "JSON document is not an object or an array"; // qDebug() << "JSON document is not an object or an array";
return; // return;
} // }
QJsonObject json_obj = jsonDoc.object(); // QJsonObject json_obj = jsonDoc.object();
if (filePath.contains("filter_")) { // if (filePath.contains("filter_")) {
QJsonArray filter_array = json_obj["filter"].toArray(); // QJsonArray filter_array = json_obj["filter"].toArray();
for (int i = 0; i < filter_array.size(); i++) { // for (int i = 0; i < filter_array.size(); i++) {
QJsonObject temp_obj = filter_array[i].toObject(); // QJsonObject temp_obj = filter_array[i].toObject();
filter[i].type = temp_obj["type"].toString(); // filter[i].type = temp_obj["type"].toString();
filter[i].low = temp_obj["low"].toInt(); // filter[i].low = temp_obj["low"].toInt();
filter[i].high = temp_obj["high"].toInt(); // filter[i].high = temp_obj["high"].toInt();
filter[i].checked = temp_obj["checked"].toBool(); // filter[i].checked = temp_obj["checked"].toBool();
} // }
} else if (filePath.contains("radial_vibration_variables_")) { // } else if (filePath.contains("radial_vibration_variables_")) {
QJsonArray variables_array = json_obj["variables"].toArray(); // QJsonArray variables_array = json_obj["variables"].toArray();
for (int i = 0; i < variables_array.size(); i++) { // for (int i = 0; i < variables_array.size(); i++) {
QJsonObject temp_obj = variables_array[i].toObject(); // QJsonObject temp_obj = variables_array[i].toObject();
variables[i].type = temp_obj["type"].toString(); // variables[i].type = temp_obj["type"].toString();
if (variables[i].type == "direct") { // if (variables[i].type == "direct") {
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
} else if (variables[i].type == "bias_volt") { // } else if (variables[i].type == "bias_volt") {
variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
} else if (variables[i].type == "1x_ampl" || variables[i].type == "2x_ampl") { // } else if (variables[i].type == "1x_ampl" || variables[i].type == "2x_ampl") {
variables[i].checked = temp_obj["checked"].toBool(); // variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].phase_lag = temp_obj["phase_lag"].toDouble(); // variables[i].phase_lag = temp_obj["phase_lag"].toDouble();
} else if (variables[i].type == "not_1x_ampl") { // } else if (variables[i].type == "not_1x_ampl") {
variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].checked = temp_obj["checked"].toBool(); // variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
} else if (variables[i].type == "smax_ampl") { // } else if (variables[i].type == "smax_ampl") {
variables[i].clamp_value = temp_obj["clamp_value"].toDouble(); // variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].checked = temp_obj["checked"].toBool(); // variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt(); // variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
} // }
} // }
QJsonObject delay_obj = json_obj["delay"].toObject(); // QJsonObject delay_obj = json_obj["delay"].toObject();
delay.alert = delay_obj["alert"].toInt(); // delay.alert = delay_obj["alert"].toInt();
delay.danger = delay_obj["danger"].toDouble(); // delay.danger = delay_obj["danger"].toDouble();
delay.active_100ms = delay_obj["active_100ms"].toBool(); // delay.active_100ms = delay_obj["active_100ms"].toBool();
alert_variables.alert_latching = json_obj["alert_latching"].toBool(); // alert_variables.alert_latching = json_obj["alert_latching"].toBool();
alert_variables.danger_latching = json_obj["danger_latching"].toBool(); // alert_variables.danger_latching = json_obj["danger_latching"].toBool();
alert_variables.timed_ok = json_obj["timed_ok"].toBool(); // alert_variables.timed_ok = json_obj["timed_ok"].toBool();
alert_variables.recorder_output = json_obj["recorder_output"].toInt(); // alert_variables.recorder_output = json_obj["recorder_output"].toInt();
alert_variables.two_ma_clamp = json_obj["two_ma_clamp"].toBool(); // alert_variables.two_ma_clamp = json_obj["two_ma_clamp"].toBool();
alert_variables.trip_multiply = json_obj["trip_multiply"].toDouble(); // alert_variables.trip_multiply = json_obj["trip_multiply"].toDouble();
alert_variables.comparision = json_obj["comparision"].toString(); // alert_variables.comparision = json_obj["comparision"].toString();
alert_variables.comparision_percentage = json_obj["comparision_percentage"].toInt(); // alert_variables.comparision_percentage = json_obj["comparision_percentage"].toInt();
} // }
} //}
void Radial_vibration::Init() { void Radial_vibration::Init() {
for (int i = 0; i < 3; i++) { std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (filter[i].type == "band_pass") { if (base_ptr == nullptr) {
ui->checkBox_band_pass->setChecked(filter[i].checked); qCritical() << "[Velocity::Init] should not be here";
ui->spinBox_band_pass_low->setValue(filter[i].low); return;
ui->spinBox_band_pass_high->setValue(filter[i].high);
} else if (filter[i].type == "low_pass") {
ui->checkBox_low_pass->setChecked(filter[i].checked);
ui->spinBox_low_pass_low->setValue(filter[i].low);
ui->spinBox_low_pass_high->setValue(filter[i].high);
} else if (filter[i].type == "high_pass") {
ui->checkBox_high_pass->setChecked(filter[i].checked);
ui->spinBox_high_pass_low->setValue(filter[i].low);
ui->spinBox_high_pass_high->setValue(filter[i].high);
} }
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
if (ptr->base_config_[channel - 1].channel_type != kVibRadial) {
qDebug() << " channel type changes";
return;
} }
for (int i = 0; i < 6; i++) { std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel);
if (variables[i].type == "direct") { if (variable_base == nullptr) {
ui->comboBox_direct_value_range->setCurrentIndex(variables[i].full_sacle_range); qDebug() << "no channel ptr";
ui->doubleSpinBox_direct_clamp->setValue(variables[i].clamp_value); return;
} else if (variables[i].type == "gap") {
ui->comboBox_gap_range->setCurrentIndex(variables[i].full_sacle_range);
ui->doubleSpinBox_gap_clamp->setValue(variables[i].clamp_value);
} else if (variables[i].type == "1x_ampl") {
ui->checkBox_1x_ampl->setChecked(variables[i].checked);
ui->comboBox_1x_value_range->setCurrentIndex(variables[i].full_sacle_range);
ui->doubleSpinBox_1x_ampl_clamp->setValue(variables[i].clamp_value);
ui->doubleSpinBox_1x_phase_lag_clamp->setValue(variables[i].phase_lag);
} else if (variables[i].type == "2x_ampl") {
ui->checkBox_2x_ampl->setChecked(variables[i].checked);
ui->comboBox_2x_value_range->setCurrentIndex(variables[i].full_sacle_range);
ui->doubleSpinBox_2x_ampl_clamp->setValue(variables[i].clamp_value);
ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variables[i].phase_lag);
} else if (variables[i].type == "not_1x_ampl") {
ui->checkBox_not_1x_ampl->setChecked(variables[i].checked);
ui->comboBox_not_1x_ampl->setCurrentIndex(variables[i].full_sacle_range);
ui->doubleSpinBox_not_1x_ampl_clamp->setValue(variables[i].clamp_value);
} else if (variables[i].type == "smax_ampl") {
ui->checkBox_smax_ampl->setChecked(variables[i].checked);
ui->comboBox_smax_range->setCurrentIndex(variables[i].full_sacle_range);
ui->doubleSpinBox_smax_clamp->setValue(variables[i].clamp_value);
} }
} std::shared_ptr<RadialVariable> variable_ptr = std::dynamic_pointer_cast<RadialVariable>(variable_base);
ui->spinBox_alert_delay->setValue(delay.alert); ui->checkBox_low_pass->setChecked(variable_ptr->filter_[0].checked);
ui->doubleSpinBox_danger_delay->setValue(delay.danger); ui->spinBox_low_pass_low->setValue(variable_ptr->filter_[0].low);
ui->checkBox_100ms_delay->setChecked(delay.active_100ms); ui->spinBox_low_pass_high->setValue(variable_ptr->filter_[0].high);
ui->checkBox_alert_latching->setChecked(alert_variables.alert_latching); ui->checkBox_high_pass->setChecked(variable_ptr->filter_[1].checked);
ui->checkBox_danger_latching->setChecked(alert_variables.danger_latching); ui->spinBox_high_pass_low->setValue(variable_ptr->filter_[1].low);
ui->comboBox_recorder_output->setCurrentIndex(alert_variables.recorder_output); ui->spinBox_high_pass_high->setValue(variable_ptr->filter_[1].high);
ui->checkBox_two_ma_clamp->setChecked(alert_variables.two_ma_clamp); ui->checkBox_band_pass->setChecked(variable_ptr->filter_[2].checked);
ui->doubleSpinBox_trip_multiply->setValue(alert_variables.trip_multiply); ui->spinBox_band_pass_low->setValue(variable_ptr->filter_[2].low);
ui->comboBox_comparision->setCurrentText(alert_variables.comparision); ui->spinBox_band_pass_high->setValue(variable_ptr->filter_[2].high);
ui->spinBox_comparision_percentage->setValue(alert_variables.comparision_percentage); 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->checkBox_not_1x_ampl->setChecked(variable_ptr->not1x_.checked);
ui->comboBox_not_1x_ampl->setCurrentIndex(variable_ptr->not1x_.full_scale_range);
ui->doubleSpinBox_not_1x_ampl_clamp->setValue(variable_ptr->not1x_.clamp_value);
// ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->not1x_.custom);
ui->checkBox_smax_ampl->setChecked(variable_ptr->smax_.checked);
ui->comboBox_smax_range->setCurrentIndex(variable_ptr->smax_.full_scale_range);
ui->doubleSpinBox_smax_clamp->setValue(variable_ptr->smax_.clamp_value);
// ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->smax_.custom);
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_alert_latching->setChecked(variable_ptr->alert_latching_);
ui->checkBox_danger_latching->setChecked(variable_ptr->danger_latching_);
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);
} }
void Radial_vibration::on_pushButton_confirm_clicked() { void Radial_vibration::on_pushButton_confirm_clicked() {
for (int i = 0; i < 3; i++) { std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (filter[i].checked) { if (base_ptr == nullptr) {
if (filter[i].type == "band_pass") { qCritical() << "[Acceleration::Init] should not be here";
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();
} else if (filter[i].type == "low_pass") {
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();
} else if (filter[i].type == "high_pass") {
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();
}
}
}
for (int i = 0; i < 6; i++) {
if (variables[i].type == "direct") {
variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value();
} else if (variables[i].type == "gap") {
variables[i].full_sacle_range = ui->comboBox_gap_range->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_gap_clamp->value();
} else if (variables[i].type == "1x_ampl") {
variables[i].checked = ui->checkBox_1x_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_1x_value_range->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variables[i].phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value();
} else if (variables[i].type == "2x_ampl") {
variables[i].checked = ui->checkBox_2x_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_2x_value_range->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
variables[i].phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value();
} else if (variables[i].type == "not_1x_ampl") {
variables[i].checked = ui->checkBox_not_1x_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_not_1x_ampl->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_not_1x_ampl_clamp->value();
} else if (variables[i].type == "smax_ampl") {
variables[i].checked = ui->checkBox_smax_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_smax_range->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_smax_clamp->value();
}
}
delay.alert = ui->spinBox_alert_delay->value();
delay.danger = ui->doubleSpinBox_danger_delay->value();
delay.active_100ms = ui->checkBox_100ms_delay->isChecked();
alert_variables.alert_latching = ui->checkBox_alert_latching->isChecked();
alert_variables.danger_latching = ui->checkBox_danger_latching->isChecked();
alert_variables.recorder_output = ui->comboBox_recorder_output->currentIndex();
alert_variables.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
alert_variables.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
alert_variables.comparision = ui->comboBox_comparision->currentText();
alert_variables.comparision_percentage = ui->spinBox_comparision_percentage->value();
QJsonObject filter_obj, variables_obj;
QJsonArray filter_array;
for (int i = 0; i < 3; i++) {
QJsonObject temp_obj;
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);
filter_array.append(temp_obj);
}
filter_obj.insert("filter", filter_array);
filter_obj.insert("slot", slot_no);
filter_obj.insert("id", channel);
filter_obj.insert("version", 1);
QJsonArray variables_array;
for (int i = 0; i < 6; i++) {
QJsonObject temp_obj;
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 == "gap") {
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);
} else if (variables[i].type == "not_1x_ampl" || variables[i].type == "smax_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);
}
variables_array.append(temp_obj);
}
variables_obj.insert("variables", variables_array);
QJsonObject delay_obj;
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("alert_latching", alert_variables.alert_latching);
variables_obj.insert("danger_latching", alert_variables.danger_latching);
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);
QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\radial_vibration_variables_%2.json").arg(slot_no).arg(channel);
QFile file_filter(filePath_filter);
QFile file_variables(filePath_variables);
if (!file_filter.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for writing:" << filePath_filter;
return; return;
} }
if (!file_variables.open(QIODevice::WriteOnly | QIODevice::Text)) { std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
qDebug() << "Cannot open file for writing:" << filePath_variables; std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel);
if (variable_base == nullptr || variable_base->type_ != kVibRadial) {
if (variable_base == nullptr) {
qDebug() << "no channel ptr";
} else {
ptr->RemoveChannel(channel);
qDebug() << "channel type change";
}
std::shared_ptr<AccVelVariable> variable = std::make_shared<AccVelVariable>();
variable->id_ = channel;
variable->type_ = kVibRadial;
variable->filter_[0].checked = ui->checkBox_low_pass->isChecked();
variable->filter_[0].low = ui->spinBox_low_pass_low->value();
variable->filter_[0].high = ui->spinBox_low_pass_high->value();
variable->filter_[1].checked = ui->checkBox_high_pass->isChecked();
variable->filter_[1].low = ui->spinBox_high_pass_low->value();
variable->filter_[1].high = ui->spinBox_high_pass_high->value();
variable->filter_[2].checked = ui->checkBox_band_pass->isChecked();
variable->filter_[2].low = ui->spinBox_band_pass_low->value();
variable->filter_[2].high = ui->spinBox_band_pass_high->value();
variable->direct_.full_scale_range = ui->comboBox_direct_value_range->currentIndex();
variable->direct_.clamp_value = ui->doubleSpinBox_direct_clamp->value();
variable->direct_.custom = 0; // TODO:
variable->x1_.checked = ui->checkBox_1x_ampl->isChecked();
variable->x1_.full_scale_range = ui->comboBox_1x_value_range->currentIndex();
variable->x1_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variable->x1_.custom = 0; // TODO:
variable->x1_.phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value();
variable->x2_.checked = ui->checkBox_2x_ampl->isChecked();
variable->x2_.full_scale_range = ui->comboBox_2x_value_range->currentIndex();
variable->x2_.clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
variable->x2_.custom = 0; // TODO:
variable->x2_.phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value();
variable->recorder_out_.recorder_output = ui->comboBox_recorder_output->currentIndex();
variable->recorder_out_.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
variable->recorder_out_.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
variable->recorder_out_.comparision = ui->comboBox_comparision->currentIndex();
variable->recorder_out_.percentage = ui->spinBox_comparision_percentage->value();
variable->delay_.alert = ui->spinBox_alert->value();
variable->delay_.danger = ui->doubleSpinBox_danger->value();
variable->delay_.active_100ms = ui->checkBox_100ms->isChecked();
variable->alert_latching_ = ui->checkBox_alert_latching->isChecked();
variable->danger_latching_ = ui->checkBox_danger_latching->isChecked();
ptr->variables_.push_back(variable);
return; return;
} }
QJsonDocument jsonDoc_filter(filter_obj); std::shared_ptr<AccVelVariable> variable = std::dynamic_pointer_cast<AccVelVariable>(variable_base);
QJsonDocument jsonDoc_variables(variables_obj); variable->filter_[0].checked = ui->checkBox_low_pass->isChecked();
file_filter.write(jsonDoc_filter.toJson()); variable->filter_[0].low = ui->spinBox_low_pass_low->value();
file_variables.write(jsonDoc_variables.toJson()); variable->filter_[0].high = ui->spinBox_low_pass_high->value();
file_filter.close(); variable->filter_[1].checked = ui->checkBox_high_pass->isChecked();
file_variables.close(); variable->filter_[1].low = ui->spinBox_high_pass_low->value();
variable->filter_[1].high = ui->spinBox_high_pass_high->value();
variable->filter_[2].checked = ui->checkBox_band_pass->isChecked();
variable->filter_[2].low = ui->spinBox_band_pass_low->value();
variable->filter_[2].high = ui->spinBox_band_pass_high->value();
variable->direct_.full_scale_range = ui->comboBox_direct_value_range->currentIndex();
variable->direct_.clamp_value = ui->doubleSpinBox_direct_clamp->value();
variable->direct_.custom = 0; // TODO:
variable->x1_.checked = ui->checkBox_1x_ampl->isChecked();
variable->x1_.full_scale_range = ui->comboBox_1x_value_range->currentIndex();
variable->x1_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variable->x1_.custom = 0; // TODO:
variable->x1_.phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value();
variable->x2_.checked = ui->checkBox_2x_ampl->isChecked();
variable->x2_.full_scale_range = ui->comboBox_2x_value_range->currentIndex();
variable->x2_.clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
variable->x2_.custom = 0; // TODO:
variable->x2_.phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value();
variable->recorder_out_.recorder_output = ui->comboBox_recorder_output->currentIndex();
variable->recorder_out_.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
variable->recorder_out_.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
variable->recorder_out_.comparision = ui->comboBox_comparision->currentIndex();
variable->recorder_out_.percentage = ui->spinBox_comparision_percentage->value();
variable->delay_.alert = ui->spinBox_alert->value();
variable->delay_.danger = ui->doubleSpinBox_danger->value();
variable->delay_.active_100ms = ui->checkBox_100ms->isChecked();
variable->alert_latching_ = ui->checkBox_alert_latching->isChecked();
variable->danger_latching_ = ui->checkBox_danger_latching->isChecked();
this->close(); this->close();
} }

View File

@ -872,7 +872,7 @@
<string> 危险</string> <string> 危险</string>
</property> </property>
</widget> </widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_danger_delay"> <widget class="QDoubleSpinBox" name="doubleSpinBox_danger">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>60</x> <x>60</x>
@ -891,7 +891,7 @@
<double>99.900000000000006</double> <double>99.900000000000006</double>
</property> </property>
</widget> </widget>
<widget class="QCheckBox" name="checkBox_100ms_delay"> <widget class="QCheckBox" name="checkBox_100ms">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>60</x> <x>60</x>
@ -930,7 +930,7 @@
<string>1.0 - 60.0s</string> <string>1.0 - 60.0s</string>
</property> </property>
</widget> </widget>
<widget class="QSpinBox" name="spinBox_alert_delay"> <widget class="QSpinBox" name="spinBox_alert">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>60</x> <x>60</x>

View File

@ -6,6 +6,9 @@
#include <QJsonObject> #include <QJsonObject>
#include <QFile> #include <QFile>
#include "velocity_ds.h" #include "velocity_ds.h"
#include "data_config.h"
#include "vibrationdata.h"
#include "config_mgr.h"
Velocity::Velocity(int slot_no_, int channel_, bool active, QWidget *parent) Velocity::Velocity(int slot_no_, int channel_, bool active, QWidget *parent)
: QWidget(parent) : QWidget(parent)
@ -22,10 +25,10 @@ Velocity::Velocity(int slot_no_, int channel_, bool active, QWidget *parent)
} else { } else {
ui->label_active->setText("(停用)"); ui->label_active->setText("(停用)");
} }
QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel); // QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
readJsonFile(filePath_filter); // readJsonFile(filePath_filter);
QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\velocity_variables_%2.json").arg(slot_no).arg(channel); // QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\velocity_variables_%2.json").arg(slot_no).arg(channel);
readJsonFile(filePath_variables); // readJsonFile(filePath_variables);
Init(); Init();
} }
@ -119,255 +122,151 @@ void Velocity::on_checkBox_2x_ampl_toggled(bool checked) {
ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(false); ui->doubleSpinBox_2x_phase_lag_clamp->setEnabled(false);
} }
void Velocity::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();
if (filePath.contains("filter_")) {
QJsonArray filter_array = json_obj["filter"].toArray();
for (int i = 0; i < filter_array.size(); i++) {
QJsonObject temp_obj = filter_array[i].toObject();
filter[i].type = temp_obj["type"].toString();
filter[i].low = temp_obj["low"].toInt();
filter[i].high = temp_obj["high"].toInt();
filter[i].checked = temp_obj["checked"].toBool();
}
} else if (filePath.contains("velocity_variables_")) {
QJsonArray variables_array = json_obj["variables"].toArray();
for (int i = 0; i < variables_array.size(); i++) {
QJsonObject temp_obj = variables_array[i].toObject();
variables[i].type = temp_obj["type"].toString();
if (variables[i].type == "direct") {
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].custom = temp_obj["custom"].toDouble();
} else if (variables[i].type == "bias_volt") {
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].bias_voltage = temp_obj["bias_voltage"].toInt();
} else if (variables[i].type == "1x_ampl") {
variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].phase_lag = temp_obj["phase_lag"].toDouble();
variables[i].custom = temp_obj["custom"].toDouble();
} else if (variables[i].type == "2x_ampl") {
variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toInt();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].phase_lag = temp_obj["phase_lag"].toDouble();
variables[i].custom = temp_obj["custom"].toDouble();
}
}
QJsonObject delay_obj = json_obj["delay"].toObject();
delay.alert = delay_obj["alert"].toInt();
delay.danger = delay_obj["danger"].toDouble();
delay.active_100ms = delay_obj["100ms"].toBool();
alert_variables.rms_active = json_obj["rms_active"].toBool();
alert_variables.integrate_active = json_obj["integrate_active"].toBool();
alert_variables.alert_latching = json_obj["alert_latching"].toBool();
alert_variables.danger_latching = json_obj["danger_latching"].toBool();
alert_variables.timed_ok = json_obj["timed_ok"].toBool();
alert_variables.recorder_output = json_obj["recorder_output"].toInt();
alert_variables.two_ma_clamp = json_obj["two_ma_clamp"].toBool();
alert_variables.trip_multiply = json_obj["trip_multiply"].toDouble();
alert_variables.comparision = json_obj["comparision"].toString();
alert_variables.comparision_percentage = json_obj["comparision_percentage"].toInt();
}
}
void Velocity::Init() { void Velocity::Init() {
for (int i = 0; i < 3; i++) { std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (filter[i].checked) { if (base_ptr == nullptr) {
if (filter[i].type == "band_pass") { qCritical() << "[Velocity::Init] should not be here";
ui->checkBox_band_pass->setChecked(filter[i].checked); return;
ui->spinBox_band_pass_low->setValue(filter[i].low);
ui->spinBox_band_pass_high->setValue(filter[i].high);
} else if (filter[i].type == "low_pass") {
ui->checkBox_low_pass->setChecked(filter[i].checked);
ui->spinBox_low_pass_low->setValue(filter[i].low);
ui->spinBox_low_pass_high->setValue(filter[i].high);
} else if (filter[i].type == "high_pass") {
ui->checkBox_high_pass->setChecked(filter[i].checked);
ui->spinBox_high_pass_low->setValue(filter[i].low);
ui->spinBox_high_pass_high->setValue(filter[i].high);
} }
std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
if (ptr->base_config_[channel - 1].channel_type != kVibVelocity) {
qDebug() << " channel type changes";
return;
} }
std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel);
if (variable_base == nullptr) {
qDebug() << "no channel ptr";
return;
} }
for (int i = 0; i < 4; i++) { std::shared_ptr<AccVelVariable> variable_ptr = std::dynamic_pointer_cast<AccVelVariable>(variable_base);
if (variables[i].type == "direct") { ui->checkBox_low_pass->setChecked(variable_ptr->filter_[0].checked);
ui->comboBox_direct_value_range->setCurrentIndex(variables[i].full_sacle_range); ui->spinBox_low_pass_low->setValue(variable_ptr->filter_[0].low);
ui->doubleSpinBox_direct_clamp->setValue(variables[i].clamp_value); ui->spinBox_low_pass_high->setValue(variable_ptr->filter_[0].high);
} else if (variables[i].type == "bias_volt") { ui->checkBox_high_pass->setChecked(variable_ptr->filter_[1].checked);
ui->label_bias_voltage->setText(QString::number(variables[i].bias_voltage)); ui->spinBox_high_pass_low->setValue(variable_ptr->filter_[1].low);
ui->doubleSpinBox_bias_volt_clamp->setValue(variables[i].clamp_value); ui->spinBox_high_pass_high->setValue(variable_ptr->filter_[1].high);
} else if (variables[i].type == "1x_ampl") { ui->checkBox_band_pass->setChecked(variable_ptr->filter_[2].checked);
ui->checkBox_1x_ampl->setChecked(variables[i].checked); ui->spinBox_band_pass_low->setValue(variable_ptr->filter_[2].low);
ui->comboBox_1x_value_range->setCurrentIndex(variables[i].full_sacle_range); ui->spinBox_band_pass_high->setValue(variable_ptr->filter_[2].high);
ui->doubleSpinBox_1x_ampl_clamp->setValue(variables[i].clamp_value); ui->comboBox_direct_value_range->setCurrentIndex(variable_ptr->direct_.full_scale_range);
ui->doubleSpinBox_1x_phase_lag_clamp->setValue(variables[i].phase_lag); ui->doubleSpinBox_direct_clamp->setValue(variable_ptr->direct_.clamp_value);
} else if (variables[i].type == "2x_ampl") { // ui->label_bias_voltage->setText(QString::number(variable_ptr->direct_.bias_voltage));
ui->checkBox_2x_ampl->setChecked(variables[i].checked); // ui->doubleSpinBox_bias_volt_clamp->setValue(variables[i].clamp_value);
ui->comboBox_2x_value_range->setCurrentIndex(variables[i].full_sacle_range); // ui->comboBox_bias_volt_range->setCurrentIndex();
ui->doubleSpinBox_2x_ampl_clamp->setValue(variables[i].clamp_value); ui->checkBox_1x_ampl->setChecked(variable_ptr->x1_.checked);
ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variables[i].phase_lag); 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->spinBox_alert->setValue(delay.alert); ui->checkBox_2x_ampl->setChecked(variable_ptr->x2_.checked);
ui->doubleSpinBox_danger->setValue(delay.danger); ui->comboBox_2x_value_range->setCurrentIndex(variable_ptr->x2_.full_scale_range);
ui->checkBox_100ms->setChecked(delay.active_100ms); ui->doubleSpinBox_2x_ampl_clamp->setValue(variable_ptr->x2_.clamp_value);
ui->checkBox_alert_latching->setChecked(alert_variables.alert_latching); ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variable_ptr->x2_.phase_lag);
ui->checkBox_danger_latching->setChecked(alert_variables.danger_latching); ui->spinBox_alert->setValue(variable_ptr->delay_.alert);
ui->checkBox_timed_ok->setChecked(alert_variables.timed_ok); ui->doubleSpinBox_danger->setValue(variable_ptr->delay_.danger);
ui->comboBox_recorder_output->setCurrentIndex(alert_variables.recorder_output); ui->checkBox_100ms->setChecked(variable_ptr->delay_.active_100ms);
ui->checkBox_two_ma_clamp->setChecked(alert_variables.two_ma_clamp); ui->checkBox_rms->setChecked(variable_ptr->rms_active_);
ui->doubleSpinBox_trip_multiply->setValue(alert_variables.trip_multiply); ui->checkBox_integrate->setChecked(variable_ptr->integrate_active_);
ui->comboBox_comparision->setCurrentText(alert_variables.comparision); ui->checkBox_alert_latching->setChecked(variable_ptr->alert_latching_);
ui->spinBox_comparision_percentage->setValue(alert_variables.comparision_percentage); 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);
} }
void Velocity::on_pushButton_confirm_clicked() { void Velocity::on_pushButton_confirm_clicked() {
for (int i = 0; i < 3; i++) { std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (filter[i].type == "band_pass") { if (base_ptr == nullptr) {
filter[i].checked = ui->checkBox_band_pass->isChecked(); qCritical() << "[Acceleration::Init] should not be here";
filter[i].low = ui->spinBox_band_pass_low->value();
filter[i].high = ui->spinBox_band_pass_high->value();
} else if (filter[i].type == "low_pass") {
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();
} else if (filter[i].type == "high_pass") {
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();
}
}
for (int i = 0; i < 4; i++) {
if (variables[i].type == "direct") {
variables[i].full_sacle_range = ui->comboBox_direct_value_range->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_direct_clamp->value();
// TODO: custom
} else if (variables[i].type == "bias_volt") {
variables[i].clamp_value = ui->doubleSpinBox_bias_volt_clamp->value();
} else if (variables[i].type == "1x_ampl") {
variables[i].checked = ui->checkBox_1x_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_1x_value_range->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variables[i].phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value();
// TODO: custom
} else if (variables[i].type == "2x_ampl") {
variables[i].checked = ui->checkBox_2x_ampl->isChecked();
variables[i].full_sacle_range = ui->comboBox_2x_value_range->currentIndex();
variables[i].clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
variables[i].phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value();
// TODO: custom
}
}
delay.alert = ui->spinBox_alert->value();
delay.danger = ui->doubleSpinBox_danger->value();
delay.active_100ms = ui->checkBox_100ms->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();
alert_variables.recorder_output = ui->comboBox_recorder_output->currentIndex();
alert_variables.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
alert_variables.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
alert_variables.comparision = ui->comboBox_comparision->currentText();
alert_variables.comparision_percentage = ui->spinBox_comparision_percentage->value();
// 保存到文件
QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
QJsonObject filter_obj;
QJsonArray filter_array;
for (int i = 0; i < 3; i++) {
QJsonObject temp_obj;
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);
filter_array.append(temp_obj);
}
filter_obj.insert("filter", filter_array);
filter_obj.insert("slot", slot_no);
filter_obj.insert("id", channel);
filter_obj.insert("version", 1);
QJsonDocument filter_doc;
filter_doc.setObject(filter_obj);
QByteArray filter_data = filter_doc.toJson();
QFile filter_file(filePath_filter);
if (!filter_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for writing:" << filePath_filter;
return; return;
} }
filter_file.write(filter_data); std::shared_ptr<VibrationData> ptr = std::dynamic_pointer_cast<VibrationData>(base_ptr);
filter_file.close(); std::shared_ptr<VariableBase> variable_base = ptr->GetChannelPtr(channel);
QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\velocity_variables_%2.json").arg(slot_no).arg(channel); if (variable_base == nullptr || variable_base->type_ != kVibVelocity) {
QJsonObject variables_obj; if (variable_base == nullptr) {
QJsonArray variables_array; qDebug() << "no channel ptr";
for (int i = 0; i < 4; i++) { } else {
QJsonObject temp_obj; ptr->RemoveChannel(channel);
temp_obj.insert("type", variables[i].type); qDebug() << "channel type change";
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("bias_voltage", variables[i].bias_voltage);
} else if (variables[i].type == "1x_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);
} else if (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);
} }
variables_array.append(temp_obj); std::shared_ptr<AccVelVariable> variable = std::make_shared<AccVelVariable>();
} variable->id_ = channel;
variables_obj.insert("variables", variables_array); variable->type_ = kVibVelocity;
QJsonObject delay_obj; variable->filter_[0].checked = ui->checkBox_low_pass->isChecked();
delay_obj.insert("alert", delay.alert); variable->filter_[0].low = ui->spinBox_low_pass_low->value();
delay_obj.insert("danger", delay.danger); variable->filter_[0].high = ui->spinBox_low_pass_high->value();
delay_obj.insert("100ms", delay.active_100ms); variable->filter_[1].checked = ui->checkBox_high_pass->isChecked();
variables_obj.insert("delay", delay_obj); variable->filter_[1].low = ui->spinBox_high_pass_low->value();
variables_obj.insert("rms_active", alert_variables.rms_active); variable->filter_[1].high = ui->spinBox_high_pass_high->value();
variables_obj.insert("integrate_active", alert_variables.integrate_active); variable->filter_[2].checked = ui->checkBox_band_pass->isChecked();
variables_obj.insert("alert_latching", alert_variables.alert_latching); variable->filter_[2].low = ui->spinBox_band_pass_low->value();
variables_obj.insert("danger_latching", alert_variables.danger_latching); variable->filter_[2].high = ui->spinBox_band_pass_high->value();
variables_obj.insert("timed_ok", alert_variables.timed_ok); variable->direct_.full_scale_range = ui->comboBox_direct_value_range->currentIndex();
variables_obj.insert("recorder_output", alert_variables.recorder_output); variable->direct_.clamp_value = ui->doubleSpinBox_direct_clamp->value();
variables_obj.insert("two_ma_clamp", alert_variables.two_ma_clamp); variable->direct_.custom = 0; // TODO:
variables_obj.insert("trip_multiply", alert_variables.trip_multiply); variable->x1_.checked = ui->checkBox_1x_ampl->isChecked();
variables_obj.insert("comparision", alert_variables.comparision); variable->x1_.full_scale_range = ui->comboBox_1x_value_range->currentIndex();
variables_obj.insert("comparision_percentage", alert_variables.comparision_percentage); variable->x1_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variables_obj.insert("slot", slot_no); variable->x1_.custom = 0; // TODO:
variables_obj.insert("channel", channel); variable->x1_.phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value();
variables_obj.insert("version", 1); variable->x2_.checked = ui->checkBox_2x_ampl->isChecked();
QJsonDocument variables_doc; variable->x2_.full_scale_range = ui->comboBox_2x_value_range->currentIndex();
variables_doc.setObject(variables_obj); variable->x2_.clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
QByteArray variables_data = variables_doc.toJson(); variable->x2_.custom = 0; // TODO:
QFile variables_file(filePath_variables); variable->x2_.phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value();
if (!variables_file.open(QIODevice::WriteOnly | QIODevice::Text)) { variable->recorder_out_.recorder_output = ui->comboBox_recorder_output->currentIndex();
qDebug() << "Cannot open file for writing:" << filePath_variables; variable->recorder_out_.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
variable->recorder_out_.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
variable->recorder_out_.comparision = ui->comboBox_comparision->currentIndex();
variable->recorder_out_.percentage = ui->spinBox_comparision_percentage->value();
variable->delay_.alert = ui->spinBox_alert->value();
variable->delay_.danger = ui->doubleSpinBox_danger->value();
variable->delay_.active_100ms = ui->checkBox_100ms->isChecked();
variable->rms_active_ = ui->checkBox_rms->isChecked();
variable->integrate_active_ = ui->checkBox_integrate->isChecked();
variable->alert_latching_ = ui->checkBox_alert_latching->isChecked();
variable->danger_latching_ = ui->checkBox_danger_latching->isChecked();
variable->timed_ok_ = ui->checkBox_timed_ok->isChecked();
ptr->variables_.push_back(variable);
return; return;
} }
variables_file.write(variables_data); std::shared_ptr<AccVelVariable> variable = std::dynamic_pointer_cast<AccVelVariable>(variable_base);
variables_file.close(); variable->filter_[0].checked = ui->checkBox_low_pass->isChecked();
variable->filter_[0].low = ui->spinBox_low_pass_low->value();
variable->filter_[0].high = ui->spinBox_low_pass_high->value();
variable->filter_[1].checked = ui->checkBox_high_pass->isChecked();
variable->filter_[1].low = ui->spinBox_high_pass_low->value();
variable->filter_[1].high = ui->spinBox_high_pass_high->value();
variable->filter_[2].checked = ui->checkBox_band_pass->isChecked();
variable->filter_[2].low = ui->spinBox_band_pass_low->value();
variable->filter_[2].high = ui->spinBox_band_pass_high->value();
variable->direct_.full_scale_range = ui->comboBox_direct_value_range->currentIndex();
variable->direct_.clamp_value = ui->doubleSpinBox_direct_clamp->value();
variable->direct_.custom = 0; // TODO:
variable->x1_.checked = ui->checkBox_1x_ampl->isChecked();
variable->x1_.full_scale_range = ui->comboBox_1x_value_range->currentIndex();
variable->x1_.clamp_value = ui->doubleSpinBox_1x_ampl_clamp->value();
variable->x1_.custom = 0; // TODO:
variable->x1_.phase_lag = ui->doubleSpinBox_1x_phase_lag_clamp->value();
variable->x2_.checked = ui->checkBox_2x_ampl->isChecked();
variable->x2_.full_scale_range = ui->comboBox_2x_value_range->currentIndex();
variable->x2_.clamp_value = ui->doubleSpinBox_2x_ampl_clamp->value();
variable->x2_.custom = 0; // TODO:
variable->x2_.phase_lag = ui->doubleSpinBox_2x_phase_lag_clamp->value();
variable->recorder_out_.recorder_output = ui->comboBox_recorder_output->currentIndex();
variable->recorder_out_.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
variable->recorder_out_.trip_multiply = ui->doubleSpinBox_trip_multiply->value();
variable->recorder_out_.comparision = ui->comboBox_comparision->currentIndex();
variable->recorder_out_.percentage = ui->spinBox_comparision_percentage->value();
variable->delay_.alert = ui->spinBox_alert->value();
variable->delay_.danger = ui->doubleSpinBox_danger->value();
variable->delay_.active_100ms = ui->checkBox_100ms->isChecked();
variable->rms_active_ = ui->checkBox_rms->isChecked();
variable->integrate_active_ = ui->checkBox_integrate->isChecked();
variable->alert_latching_ = ui->checkBox_alert_latching->isChecked();
variable->danger_latching_ = ui->checkBox_danger_latching->isChecked();
variable->timed_ok_ = ui->checkBox_timed_ok->isChecked();
this->close(); this->close();
} }