TSI_Config/seismic_monitor.cpp

337 lines
18 KiB
C++
Raw Normal View History

2025-03-09 11:53:05 +08:00
#include "seismic_monitor.h"
#include "ui_seismic_monitor.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QFile>
2025-03-11 16:42:00 +08:00
#include <QListView>
2025-03-09 11:53:05 +08:00
#include "acceleration.h"
#include "velocity.h"
#include "radial_vibration.h"
2025-04-01 15:03:59 +08:00
#include "data_config.h"
#include "config_mgr.h"
#include "vibrationdata.h"
2025-03-09 11:53:05 +08:00
Seismic_monitor::Seismic_monitor(int slot,int cardtype, QWidget *parent) :
2025-03-09 11:53:05 +08:00
QWidget(parent),
2025-03-29 09:53:29 +08:00
ui(new Ui::Seismic_monitor) {
2025-03-09 11:53:05 +08:00
ui->setupUi(this);
2025-03-11 16:42:00 +08:00
ui->widget_body->setProperty("flag", "body");
ui->comboBox_chan_type_1->setView(new QListView());
ui->comboBox_chan_type_2->setView(new QListView());
ui->comboBox_chan_type_3->setView(new QListView());
ui->comboBox_chan_type_4->setView(new QListView());
ui->comboBox_transducer_name_1->setView(new QListView());
ui->comboBox_transducer_name_2->setView(new QListView());
ui->comboBox_transducer_name_3->setView(new QListView());
ui->comboBox_transducer_name_4->setView(new QListView());
ui->comboBox_sample_rate_1->setView(new QListView());
ui->comboBox_sample_rate_2->setView(new QListView());
ui->comboBox_sample_rate_3->setView(new QListView());
ui->comboBox_sample_rate_4->setView(new QListView());
2025-03-09 11:53:05 +08:00
slot_no = slot;
car_type = static_cast<CardType>(cardtype);
2025-03-09 11:53:05 +08:00
QString slot_no_ = QString("%1").arg(slot_no);
ui->label_slot_no->setText(slot_no_);
Init();
}
2025-03-29 09:53:29 +08:00
Seismic_monitor::~Seismic_monitor() {
2025-03-09 11:53:05 +08:00
delete ui;
}
2025-04-01 15:03:59 +08:00
void Seismic_monitor::Init() {
// for (int var = 0; var < vec_transducer.size(); ++var) {
// ui->comboBox_transducer_name_1->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_2->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_3->addItem(vec_transducer[var].transducer_name);
// ui->comboBox_transducer_name_4->addItem(vec_transducer[var].transducer_name);
// }
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
qDebug() << "base_ptr";
2025-04-01 15:03:59 +08:00
// do nothing or use template to init it.
std::shared_ptr<VibrationData> vib_data = std::make_shared<VibrationData>();
vib_data->slot_ = slot_no;
vib_data->card_type_ = car_type;
2025-04-01 15:03:59 +08:00
ConfigMgr::Instance()->AddCard(vib_data);
UpdateData(vib_data);
return;
}
2025-04-01 15:03:59 +08:00
std::shared_ptr<VibrationData> vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
for (int i = 0; i < CHANNEL_COUNT; i++) {
if (i + 1 == 1) {
qDebug() << vib_data->base_config_[i].channel_type ;
ui->comboBox_chan_type_1->setCurrentIndex(vib_data->base_config_[i].channel_type);
2025-04-21 20:30:12 +08:00
ui->checkBox_standby_1->setChecked(vib_data->base_config_[i].standby);
2025-04-01 15:03:59 +08:00
ui->comboBox_transducer_name_1->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_1->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_1->setChecked(vib_data->base_config_[i].active);
2025-04-01 15:03:59 +08:00
ui->doubleSpinBox_low_1->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_1->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_1->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
ui->checkBox_power_1->setChecked(vib_data->base_config_[i].power);
2025-04-01 15:03:59 +08:00
} else if (i + 1 == 2) {
ui->comboBox_chan_type_2->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_2->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_2->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_2->setChecked(vib_data->base_config_[i].active);
2025-04-01 15:03:59 +08:00
ui->doubleSpinBox_low_2->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_2->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_2->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
ui->checkBox_power_2->setChecked(vib_data->base_config_[i].power);
2025-04-01 15:03:59 +08:00
} else if (i + 1 == 3) {
2025-04-21 20:30:12 +08:00
ui->checkBox_standby_2->setChecked(vib_data->base_config_[i].standby);
2025-04-01 15:03:59 +08:00
ui->comboBox_chan_type_3->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_3->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_3->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_3->setChecked(vib_data->base_config_[i].active);
2025-04-01 15:03:59 +08:00
ui->doubleSpinBox_low_3->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_3->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_3->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
ui->checkBox_power_3->setChecked(vib_data->base_config_[i].power);
2025-04-01 15:03:59 +08:00
} else if (i + 1 == 4) {
ui->comboBox_chan_type_4->setCurrentIndex(vib_data->base_config_[i].channel_type);
ui->comboBox_transducer_name_4->setCurrentIndex(vib_data->base_config_[i].transducer_id);
ui->doubleSpinBox_scale_factor_4->setValue(vib_data->base_config_[i].scale_factor);
ui->checkBox_enable_4->setChecked(vib_data->base_config_[i].active);
2025-04-01 15:03:59 +08:00
ui->doubleSpinBox_low_4->setValue(vib_data->base_config_[i].normal_voltage_low);
ui->doubleSpinBox_high_4->setValue(vib_data->base_config_[i].normal_voltage_high);
ui->comboBox_sample_rate_4->setCurrentIndex(vib_data->base_config_[i].sampling_rate);
ui->checkBox_power_4->setChecked(vib_data->base_config_[i].power);
2025-04-01 15:03:59 +08:00
}
}
2025-03-09 11:53:05 +08:00
}
2025-04-01 15:03:59 +08:00
void Seismic_monitor::UpdateData(std::shared_ptr<VibrationData> vib_data) {
for (int var = 0; var < CHANNEL_COUNT; ++var) {
if (var + 1 == 1) {
vib_data->base_config_[var].standby = ui->checkBox_standby_1->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_1->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_1->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_1->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_1->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_1->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_1->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_1->value();
vib_data->base_config_[var].power = ui->checkBox_power_1->isChecked();
2025-04-23 14:44:58 +08:00
vib_data->base_config_[var].chan_id = QString("S%1C%2").arg(QString::number(slot_no, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
2025-04-01 15:03:59 +08:00
} else if (var + 1 == 2) {
vib_data->base_config_[var].standby = ui->checkBox_standby_1->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_2->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_2->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_2->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_2->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_2->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_2->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_2->value();
vib_data->base_config_[var].power = ui->checkBox_power_2->isChecked();
2025-04-23 14:44:58 +08:00
vib_data->base_config_[var].chan_id = QString("S%1C%2").arg(QString::number(slot_no, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
2025-04-01 15:03:59 +08:00
} else if (var + 1 == 3) {
vib_data->base_config_[var].standby = ui->checkBox_standby_2->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_3->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_3->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_3->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_3->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_3->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_3->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_3->value();
vib_data->base_config_[var].power = ui->checkBox_power_3->isChecked();
2025-04-23 14:44:58 +08:00
vib_data->base_config_[var].chan_id = QString("S%1C%2").arg(QString::number(slot_no, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
2025-04-01 15:03:59 +08:00
} else if (var + 1 == 4) {
vib_data->base_config_[var].standby = ui->checkBox_standby_2->isChecked();
vib_data->base_config_[var].active = ui->checkBox_enable_4->isChecked();
vib_data->base_config_[var].rack_type = 0;
vib_data->base_config_[var].channel_type = ui->comboBox_chan_type_4->currentIndex();
vib_data->base_config_[var].transducer_id = ui->comboBox_transducer_name_4->currentIndex();
vib_data->base_config_[var].scale_factor = ui->doubleSpinBox_scale_factor_4->value();
vib_data->base_config_[var].sampling_rate = ui->comboBox_sample_rate_4->currentIndex();
vib_data->base_config_[var].normal_voltage_low = ui->doubleSpinBox_low_4->value();
vib_data->base_config_[var].normal_voltage_high = ui->doubleSpinBox_high_4->value();
vib_data->base_config_[var].power = ui->checkBox_power_4->isChecked();
2025-04-23 14:44:58 +08:00
vib_data->base_config_[var].chan_id = QString("S%1C%2").arg(QString::number(slot_no, 10).rightJustified(2, '0')).arg(QString::number(var+1, 10).rightJustified(2, '0'));
2025-03-09 11:53:05 +08:00
}
}
}
2025-04-01 15:03:59 +08:00
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_pushButton_confirm_clicked() {
2025-04-01 15:03:59 +08:00
std::shared_ptr<CardBase> base_ptr = ConfigMgr::Instance()->GetSlotPtr(slot_no);
if (base_ptr == nullptr) {
qCritical() << " should not be here";
// std::shared_ptr<VibrationData> vib_data = std::make_shared<VibrationData>();
// ConfigMgr::Instance()->AddCard(vib_data);
// UpdateData(vib_data);
return;
2025-03-09 11:53:05 +08:00
}
2025-04-01 15:03:59 +08:00
std::shared_ptr<VibrationData> vib_data = std::dynamic_pointer_cast<VibrationData>(base_ptr);
UpdateData(vib_data);
this->close();
2025-03-09 11:53:05 +08:00
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_pushButton_set_default_clicked() {
2025-03-09 11:53:05 +08:00
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_pushButton_config_1_clicked() {
2025-03-25 10:47:13 +08:00
channel = 1;
2025-03-29 09:53:29 +08:00
if (ui->comboBox_chan_type_1->currentIndex() == kVibAcc) {
Acceleration *acceleration = new Acceleration(slot_no, channel, ui->checkBox_enable_1->isChecked());
2025-03-25 10:47:13 +08:00
acceleration->setWindowModality(Qt::ApplicationModal);
acceleration->show();
2025-03-29 09:53:29 +08:00
} else if (ui->comboBox_chan_type_1->currentIndex() == kVibRadial) {
2025-04-02 10:13:03 +08:00
Radial *radial_vibration = new Radial(slot_no, channel, ui->checkBox_enable_1->isChecked());
2025-03-25 10:47:13 +08:00
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
2025-03-29 09:53:29 +08:00
} else if (ui->comboBox_chan_type_1->currentIndex() == kVibVelocity) {
Velocity *velocity = new Velocity(slot_no, channel, ui->checkBox_enable_1->isChecked());
2025-03-25 10:47:13 +08:00
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
2025-03-11 16:42:00 +08:00
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_pushButton_config_2_clicked() {
2025-03-25 10:47:13 +08:00
channel = 2;
2025-03-29 09:53:29 +08:00
if (ui->comboBox_chan_type_2->currentIndex() == kVibAcc) {
Acceleration *acceleration = new Acceleration(slot_no, channel, ui->checkBox_enable_2->isChecked());
2025-03-25 10:47:13 +08:00
acceleration->setWindowModality(Qt::ApplicationModal);
acceleration->show();
2025-03-29 09:53:29 +08:00
} else if (ui->comboBox_chan_type_2->currentIndex() == kVibRadial) {
2025-04-02 10:13:03 +08:00
Radial *radial_vibration = new Radial(slot_no, channel, ui->checkBox_enable_2->isChecked());
2025-03-25 10:47:13 +08:00
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
2025-03-29 09:53:29 +08:00
} else if (ui->comboBox_chan_type_2->currentIndex() == kVibVelocity) {
Velocity *velocity = new Velocity(slot_no, channel, ui->checkBox_enable_2->isChecked());
2025-03-25 10:47:13 +08:00
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_pushButton_config_3_clicked() {
2025-03-25 10:47:13 +08:00
channel = 3;
2025-03-29 09:53:29 +08:00
if (ui->comboBox_chan_type_3->currentIndex() == kVibAcc) {
Acceleration *acceleration = new Acceleration(slot_no, channel, ui->checkBox_enable_3->isChecked());
2025-03-25 10:47:13 +08:00
acceleration->setWindowModality(Qt::ApplicationModal);
acceleration->show();
2025-03-29 09:53:29 +08:00
} else if (ui->comboBox_chan_type_3->currentIndex() == kVibRadial) {
2025-04-02 10:13:03 +08:00
Radial *radial_vibration = new Radial(slot_no, channel, ui->checkBox_enable_3->isChecked());
2025-03-25 10:47:13 +08:00
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
2025-03-29 09:53:29 +08:00
} else if (ui->comboBox_chan_type_3->currentIndex() == kVibVelocity) {
Velocity *velocity = new Velocity(slot_no, channel, ui->checkBox_enable_3->isChecked());
2025-03-25 10:47:13 +08:00
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_pushButton_config_4_clicked() {
2025-03-25 10:47:13 +08:00
channel = 4;
2025-03-29 09:53:29 +08:00
if (ui->comboBox_chan_type_4->currentIndex() == kVibAcc) {
Acceleration *acceleration = new Acceleration(slot_no, channel, ui->checkBox_enable_4->isChecked());
2025-03-25 10:47:13 +08:00
acceleration->setWindowModality(Qt::ApplicationModal);
acceleration->show();
2025-03-29 09:53:29 +08:00
} else if (ui->comboBox_chan_type_4->currentIndex() == kVibRadial) {
2025-04-02 10:13:03 +08:00
Radial *radial_vibration = new Radial(slot_no, channel, ui->checkBox_enable_4->isChecked());
2025-03-25 10:47:13 +08:00
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
2025-03-29 09:53:29 +08:00
} else if (ui->comboBox_chan_type_4->currentIndex() == kVibVelocity) {
Velocity *velocity = new Velocity(slot_no, channel, ui->checkBox_enable_4->isChecked());
2025-03-25 10:47:13 +08:00
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
2025-03-09 11:53:05 +08:00
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_comboBox_chan_type_1_currentTextChanged(const QString &arg1) {
switch (ui->comboBox_chan_type_1->currentIndex()) {
case kVibRadial:
ui->label_unit_1->setText("mV / mm");
break;
case kVibAcc:
ui->label_unit_1->setText("mV / m/s^2");
break;
case kVibVelocity:
ui->label_unit_1->setText("mV / mm/s");
break;
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_comboBox_chan_type_2_currentTextChanged(const QString &arg1) {
2025-04-25 14:28:27 +08:00
switch (ui->comboBox_chan_type_2->currentIndex()) {
2025-03-29 09:53:29 +08:00
case kVibRadial:
ui->label_unit_2->setText("mV / mm");
break;
case kVibAcc:
ui->label_unit_2->setText("mV / m/s^2");
break;
case kVibVelocity:
ui->label_unit_2->setText("mV / mm/s");
break;
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_comboBox_chan_type_3_currentTextChanged(const QString &arg1) {
2025-04-25 14:28:27 +08:00
switch (ui->comboBox_chan_type_3->currentIndex()) {
2025-03-29 09:53:29 +08:00
case kVibRadial:
ui->label_unit_3->setText("mV / mm");
break;
case kVibAcc:
ui->label_unit_3->setText("mV / m/s^2");
break;
case kVibVelocity:
ui->label_unit_3->setText("mV / mm/s");
break;
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_comboBox_chan_type_4_currentTextChanged(const QString &arg1) {
2025-04-25 14:28:27 +08:00
switch (ui->comboBox_chan_type_4->currentIndex()) {
2025-03-29 09:53:29 +08:00
case kVibRadial:
ui->label_unit_4->setText("mV / mm");
break;
case kVibAcc:
ui->label_unit_4->setText("mV / m/s^2");
break;
case kVibVelocity:
ui->label_unit_4->setText("mV / mm/s");
break;
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_pushButton_cancel_clicked() {
this->close();
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_comboBox_transducer_name_1_currentTextChanged(const QString &arg1) {
for (int var = 0; var < vec_transducer.size(); ++var) {
if (ui->comboBox_transducer_name_1->currentText() == vec_transducer[var].transducer_name) {
ui->doubleSpinBox_scale_factor_1->setValue(vec_transducer[var].scale_factor);
}
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_comboBox_transducer_name_2_currentTextChanged(const QString &arg1) {
for (int var = 0; var < vec_transducer.size(); ++var) {
if (ui->comboBox_transducer_name_2->currentText() == vec_transducer[var].transducer_name) {
ui->doubleSpinBox_scale_factor_2->setValue(vec_transducer[var].scale_factor);
}
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_comboBox_transducer_name_3_currentTextChanged(const QString &arg1) {
for (int var = 0; var < vec_transducer.size(); ++var) {
if (ui->comboBox_transducer_name_3->currentText() == vec_transducer[var].transducer_name) {
ui->doubleSpinBox_scale_factor_3->setValue(vec_transducer[var].scale_factor);
}
}
}
2025-03-29 09:53:29 +08:00
void Seismic_monitor::on_comboBox_transducer_name_4_currentTextChanged(const QString &arg1) {
for (int var = 0; var < vec_transducer.size(); ++var) {
if (ui->comboBox_transducer_name_4->currentText() == vec_transducer[var].transducer_name) {
ui->doubleSpinBox_scale_factor_4->setValue(vec_transducer[var].scale_factor);
}
}
}