添加速度和位移配置读写

This commit is contained in:
zhangsheng 2025-03-20 14:38:14 +08:00
parent 2b81cf0f6b
commit e65572b684
17 changed files with 87 additions and 2475 deletions

View File

@ -1,6 +1,8 @@
#include "MyTcpClient.h"
#include <QDebug>
MyTcpClient* MyTcpClient::m_instance = nullptr;
MyTcpClient::MyTcpClient(QObject *parent) : QObject(parent), shouldReconnect(true) {
socket = new QTcpSocket(this);
@ -21,7 +23,13 @@ MyTcpClient::~MyTcpClient() {
socket->deleteLater();
}
}
MyTcpClient* MyTcpClient::instance()
{
if (!m_instance) {
m_instance = new MyTcpClient();
}
return m_instance;
}
void MyTcpClient::connectToServer(const QString &host, quint16 port) {
serverHost = host;
serverPort = port;

View File

@ -9,6 +9,7 @@ class MyTcpClient : public QObject {
Q_OBJECT
public:
static MyTcpClient* instance();
explicit MyTcpClient(QObject *parent = nullptr);
~MyTcpClient();
@ -37,6 +38,7 @@ private:
QString serverHost;
quint16 serverPort;
bool shouldReconnect; // 标记是否需要重连
static MyTcpClient* m_instance;
};
#endif // MYTCPCLIENT_H

View File

@ -21,9 +21,9 @@ Acceleration::Acceleration(int slot_no_,int channel_,bool active,QWidget *parent
ui->label_active->setText("(启用)");
else
ui->label_active->setText("(停用)");
QString filePath_filter = QCoreApplication::applicationDirPath() + QString("\\config\\filter_%1_%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);
QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\acceleration_variables_%1_%2.json").arg(slot_no).arg(channel);
QString filePath_variables = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\acceleration_variables_%2.json").arg(slot_no).arg(channel);
readJsonFile(filePath_variables);
Init();
}
@ -77,14 +77,12 @@ void Acceleration::readJsonFile(const QString &filePath)
variables[i].checked = temp_obj["checked"].toBool();
variables[i].full_sacle_range = temp_obj["full_sacle_range"].toString();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
}else if(variables[i].type == "1x_phase_lag"){
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].phase_lag = temp_obj["phase_lag"].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"].toString();
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
}else if(variables[i].type == "2x_phase_lag"){
variables[i].clamp_value = temp_obj["clamp_value"].toDouble();
variables[i].phase_lag = temp_obj["phase_lag"].toDouble();
}
}
QJsonObject delay_obj = json_obj["delay"].toObject();
@ -98,7 +96,7 @@ void Acceleration::readJsonFile(const QString &filePath)
alert_variables.timed_ok = json_obj["timed_ok"].toBool();
alert_variables.recorder_output = json_obj["recorder_output"].toString();
alert_variables.two_ma_clamp = json_obj["two_ma_clamp"].toBool();
alert_variables.trip_mutiply = json_obj["trip_mutiply"].toDouble();
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();
}
@ -132,12 +130,10 @@ void Acceleration::Init()
}else if(variables[i].type == "1x_ampl"){
ui->comboBox_1x_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_1x_ampl_clamp->setValue(variables[i].clamp_value);
}else if(variables[i].type == "1x_phase_lag"){
ui->doubleSpinBox_1x_phase_lag_clamp->setValue(variables[i].clamp_value);
}else if(variables[i].type == "2x_ampl"){
ui->comboBox_2x_value_range->setCurrentText(variables[i].full_sacle_range);
ui->doubleSpinBox_2x_ampl_clamp->setValue(variables[i].clamp_value);
}else if(variables[i].type == "2x_phase_lag"){
ui->doubleSpinBox_2x_phase_lag_clamp->setValue(variables[i].clamp_value);
}
}
@ -151,7 +147,7 @@ void Acceleration::Init()
ui->checkBox_timed_ok->setChecked(alert_variables.timed_ok);
ui->comboBox_recorder_output->setCurrentText(alert_variables.recorder_output);
ui->checkBox_two_ma_clamp->setChecked(alert_variables.two_ma_clamp);
ui->doubleSpinBox_trip_mutiply->setValue(alert_variables.trip_mutiply);
ui->doubleSpinBox_trip_multiply->setValue(alert_variables.trip_multiply);
ui->comboBox_comparision->setCurrentText(alert_variables.comparision);
ui->spinBox_comparision_percentage->setValue(alert_variables.comparision_percentage);
}
@ -205,7 +201,7 @@ void Acceleration::on_pushButton_confirm_clicked()
alert_variables.timed_ok = ui->checkBox_timed_ok->isChecked();
alert_variables.recorder_output = ui->comboBox_recorder_output->currentText();
alert_variables.two_ma_clamp = ui->checkBox_two_ma_clamp->isChecked();
alert_variables.trip_mutiply = ui->doubleSpinBox_trip_mutiply->value();
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();
@ -246,13 +242,13 @@ void Acceleration::on_pushButton_confirm_clicked()
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_mutiply",alert_variables.trip_mutiply);
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);
QJsonDocument jsonDoc_filter(filter_obj);
QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\filter_%1_%2.json").arg(slot_no).arg(channel);
QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\filter_%2.json").arg(slot_no).arg(channel);
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for writing:" << filePath;
@ -261,7 +257,7 @@ void Acceleration::on_pushButton_confirm_clicked()
file.write(jsonDoc_filter.toJson());
file.close();
QJsonDocument jsonDoc_variables(variables_obj);
filePath = QCoreApplication::applicationDirPath() + QString("\\config\\acceleration_variables_%1_%2.json").arg(slot_no).arg(channel);
filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\acceleration_variables_%2.json").arg(slot_no).arg(channel);
file.setFileName(filePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qDebug() << "Cannot open file for writing:" << filePath;
@ -271,3 +267,9 @@ void Acceleration::on_pushButton_confirm_clicked()
file.close();
}
void Acceleration::on_pushButton_set_default_clicked()
{
}

View File

@ -21,6 +21,8 @@ public:
private slots:
void on_pushButton_confirm_clicked();
void on_pushButton_set_default_clicked();
private:
Ui::Acceleration *ui;

View File

@ -107,7 +107,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -126,13 +126,6 @@
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="checkBox_high_pass">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>高通:</string>
</property>
@ -224,13 +217,6 @@
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QCheckBox" name="checkBox_low_pass">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>低通:</string>
</property>
@ -301,13 +287,6 @@
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QCheckBox" name="checkBox_band_pass">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>带通:</string>
</property>
@ -713,8 +692,8 @@
<rect>
<x>60</x>
<y>50</y>
<width>62</width>
<height>16</height>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="decimals">
@ -769,7 +748,7 @@
<x>60</x>
<y>20</y>
<width>61</width>
<height>16</height>
<height>21</height>
</rect>
</property>
<property name="minimum">
@ -830,7 +809,7 @@
<string>倍增</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox_trip_mutiply">
<widget class="QDoubleSpinBox" name="doubleSpinBox_trip_multiply">
<property name="geometry">
<rect>
<x>460</x>
@ -1052,7 +1031,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_pushButton_set_default">
<widget class="QPushButton" name="pushButton_set_default">
<property name="minimumSize">
<size>
<width>100</width>

View File

@ -82,7 +82,7 @@ typedef struct{
bool timed_ok;
QString recorder_output;
bool two_ma_clamp;
float trip_mutiply;
float trip_multiply;
QString comparision;
int comparision_percentage;
} Alert_Variables;

View File

@ -49,7 +49,7 @@
"danger_latching":true,
"recorder_output":"direct",
"two_ma_clamp":true,
"trip_mutiply":1.00,
"trip_multiply":1.00,
"comparision":"direct",
"comparision_percentage":5
}

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>660</width>
<height>686</height>
<height>661</height>
</rect>
</property>
<property name="windowTitle">
@ -1601,13 +1601,13 @@
</widget>
</widget>
</widget>
<widget class="QWidget" name="layoutWidget">
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>40</x>
<x>41</x>
<y>10</y>
<width>478</width>
<height>23</height>
<width>431</width>
<height>22</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
@ -1619,16 +1619,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QLabel" name="label_40">
<property name="text">
<string>5</string>
</property>
@ -1655,7 +1646,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2">
<widget class="QLabel" name="label_41">
<property name="text">
<string>5-6</string>
</property>

View File

@ -109,31 +109,24 @@ MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onDisConnected()
{
statusBar()->showMessage("连接失败!正在重连……", 3000); // 显示3秒
}
void MainWindow::onConnected()
{
statusBar()->showMessage("连接成功!", 3000); // 显示3秒
}
void MainWindow::connectServer()
{
m_tcpClient = MyTcpClient::instance();
// 监听信号
connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray&)), this, SLOT(readData(const QByteArray&)));
connect(m_tcpClient, SIGNAL(disconnected()), this, SLOT(onDisConnected()));
connect(m_tcpClient, SIGNAL(connected()), this, SLOT(onConnected()));
// 连接服务器
client.connectToServer(g_strServerIp, 10000);
//client.sendData("send_buf", 1);
// // 监听信号
// QObject::connect(&client, &MyTcpClient::connected, []() {
// qDebug() << "Client connected!";
// });
// // QObject::connect(&client, &MyTcpClient::dataReceived, [](const QByteArray &data) {
// // qDebug() << "Received from server:" << data;
// // });
connect(&client, SIGNAL(dataReceived(const QByteArray&)), this, SLOT(readData(const QByteArray&)));
connect(&client, SIGNAL(disconnected()), this, SLOT(onDisConnected()));
// // QObject::connect(&client, &MyTcpClient::errorOccurred, [](const QString &error) {
// // qDebug() << "Error:" << error;
// // });
// socket = new QTcpSocket(this);
// connect(socket, &QTcpSocket::connected, this, &MainWindow::onConnected);
// connect(socket, &QTcpSocket::readyRead, this, &MainWindow::readData);
// socket->connectToHost(g_strServerIp, 10000);
m_tcpClient->connectToServer(g_strServerIp, 10000);
}
@ -204,29 +197,29 @@ void MainWindow::createMenu(const QString& rootTitle, QPushButton* parent )
// 创建主菜单
QMenu *mainMenu = new QMenu(rootTitle, parent);
// 创建第一层子菜单/30 振电器模块
// 创建第一层子菜单
QMenu *monitors = new QMenu("监视器", mainMenu);
QMenu *relays = new QMenu("/30 继电器模块", mainMenu);
QMenu *keyphasor = new QMenu("/25 键相模块", mainMenu);
QMenu *relays = new QMenu("/DOM810 继电器模块", mainMenu);
QMenu *keyphasor = new QMenu("/KPM834 键相模块", mainMenu);
// 创建第二层子菜单:/40 振动板卡
QMenu *proximitor_menu = new QMenu("/40 振动板卡", monitors);
QMenu *rpm_menu = new QMenu("/50 转速板卡", monitors);
// 创建第二层子菜单:/HAM824 振动板卡
QMenu *proximitor_menu = new QMenu("/HAM824 振动板卡", monitors);
QMenu *rpm_menu = new QMenu("/OPM844 转速板卡", monitors);
// 创建第三层子菜单:/40 单板卡、三冗余板卡
QAction *proximitor_1 = proximitor_menu->addAction("/40 单板卡");
QAction *proximitor_2 = proximitor_menu->addAction("/40 三冗余板卡");
// 创建第三层子菜单:/HAM824 单板卡、三冗余板卡
QAction *proximitor_1 = proximitor_menu->addAction("/HAM824 单板卡");
QAction *proximitor_2 = proximitor_menu->addAction("/HAM824 三冗余板卡");
QAction *rpm_1 = rpm_menu->addAction("/50 单板卡");
QAction *rpm_1 = rpm_menu->addAction("/OPM844 单板卡");
// 创建第二层子菜单:/25 键相模块
QAction *keyphasor_1 = keyphasor->addAction("/25 单板卡");
QAction *keyphasor_2 = keyphasor->addAction("/25 两板卡");
// 创建第二层子菜单:/KPM834 键相模块
QAction *keyphasor_1 = keyphasor->addAction("/KPM834 单板卡");
QAction *keyphasor_2 = keyphasor->addAction("/KPM834 两板卡");
// 创建第二层子菜单:/30 继电器模块
QAction *relays_1 = relays->addAction("/30 单板卡");
QAction *relays_2 = relays->addAction("/30 三冗余板卡");
// 创建第二层子菜单:/DOM810 继电器模块
QAction *relays_1 = relays->addAction("/DOM810 单板卡");
QAction *relays_2 = relays->addAction("/DOM810 三冗余板卡");
// 将子菜单加入上一级菜单
monitors->addMenu(proximitor_menu); // 将第二层加入第一层
@ -635,7 +628,7 @@ void MainWindow::sendUpgradePackage(int slot)
}else{
chunkSize = totalBytes - bytesSent;
}
qint64 bytesWritten = client.sendData(send_buf + bytesSent, chunkSize);
qint64 bytesWritten = m_tcpClient->sendData(send_buf + bytesSent, chunkSize);
qDebug() << "bytesWritten" << bytesWritten << "bytesSent" << bytesSent ;
if (bytesWritten == -1) {
break;
@ -643,7 +636,7 @@ void MainWindow::sendUpgradePackage(int slot)
bytesSent += bytesWritten;
}
qDebug() << "bytesSent" << bytesSent ;
client.waitForRead();
m_tcpClient->waitForRead();
progressBar->reset();
progressBar->setVisible(true);
QString upgrade_text = QStringLiteral("正在上传板卡 [ %1 ] …… %p%").arg(slot);
@ -667,14 +660,10 @@ void MainWindow::getVersion(int slot)
memcpy(send_buf, (char*)&header, sizeof(PackageHead));
memcpy(send_buf + sizeof(PackageHead), (char*)&get_version_req, sizeof(GetVersionReq));
int length = sizeof(PackageHead) + sizeof(GetVersionReq);
qint64 bytesWritten = client.sendData(send_buf, length);
client.waitForRead();
qint64 bytesWritten = m_tcpClient->sendData(send_buf, length);
m_tcpClient->waitForRead();
qDebug() << "bytesWritten: " << bytesWritten;
}
void MainWindow::onDisConnected()
{
statusBar()->showMessage("连接失败!", 30000); // 显示3秒
}
void MainWindow::readData(const QByteArray& data)
{

View File

@ -39,10 +39,10 @@ private:
QList<QLabel*> list_label;
QButtonGroup * btnGroup_slot = nullptr;
MyTcpClient* m_tcpClient;
int slot_no = 0;
QTcpSocket *socket;
MyTcpClient client;
QProgressBar *progressBar;
@ -59,6 +59,7 @@ private:
private slots:
void onDisConnected();
void onConnected();
void readData(const QByteArray&);
void onMenuAction_relay();
void OnButtonGroup(QAbstractButton *);

View File

@ -1,14 +0,0 @@
#include "Radial_vibration.h"
#include "ui_Radial_vibration.h"
Radial_vibration::Radial_vibration(QWidget *parent) :
QWidget(parent),
ui(new Ui::Radial_vibration)
{
ui->setupUi(this);
}
Radial_vibration::~Radial_vibration()
{
delete ui;
}

View File

@ -1,22 +0,0 @@
#ifndef Radial_vibration_H
#define Radial_vibration_H
#include <QWidget>
namespace Ui {
class Radial_vibration;
}
class Radial_vibration : public QWidget
{
Q_OBJECT
public:
explicit Radial_vibration(QWidget *parent = nullptr);
~Radial_vibration();
private:
Ui::Radial_vibration *ui;
};
#endif // Radial_vibration_H

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@ Seismic_monitor::Seismic_monitor(int slot,QWidget *parent) :
QString slot_no_ = QString("%1").arg(slot_no);
ui->label_slot_no->setText(slot_no_);
QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\seismic_monitor_slot_%1.json").arg(slot_no);
QString filePath = QCoreApplication::applicationDirPath() + QString("\\config\\%1\\seismic_monitor_slot.json").arg(slot_no);
readJsonFile(filePath);
Init();
}
@ -228,17 +228,16 @@ void Seismic_monitor::on_pushButton_config_1_clicked()
acceleration->show();
}else if(seismic_monitor[i].channel_type == "proximeter"){
channel = 1;
Radial_vibration *radial_vibration = new Radial_vibration();
Radial_vibration *radial_vibration = new Radial_vibration(slot_no,channel,seismic_monitor[i].active);
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
}else if(seismic_monitor[i].channel_type == "velocity"){
channel = 1;
Velocity *velocity = new Velocity();
Velocity *velocity = new Velocity(slot_no,channel,seismic_monitor[i].active);
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
}
}
}
}
@ -254,12 +253,12 @@ void Seismic_monitor::on_pushButton_config_3_clicked()
acceleration->show();
}else if(seismic_monitor[i].channel_type == "proximeter"){
channel = 3;
Radial_vibration *radial_vibration = new Radial_vibration();
Radial_vibration *radial_vibration = new Radial_vibration(slot_no,channel,seismic_monitor[i].active);
radial_vibration->setWindowModality(Qt::ApplicationModal);
radial_vibration->show();
}else if(seismic_monitor[i].channel_type == "velocity"){
channel = 3;
Velocity *velocity = new Velocity();
Velocity *velocity = new Velocity(slot_no,channel,seismic_monitor[i].active);
velocity->setWindowModality(Qt::ApplicationModal);
velocity->show();
}

View File

@ -1,14 +0,0 @@
#include "Velocity.h"
#include "ui_Velocity.h"
Velocity::Velocity(QWidget *parent) :
QWidget(parent),
ui(new Ui::Velocity)
{
ui->setupUi(this);
}
Velocity::~Velocity()
{
delete ui;
}

View File

@ -1,22 +0,0 @@
#ifndef velocity_H
#define velocity_H
#include <QWidget>
namespace Ui {
class Velocity;
}
class Velocity : public QWidget
{
Q_OBJECT
public:
explicit Velocity(QWidget *parent = nullptr);
~Velocity();
private:
Ui::Velocity *ui;
};
#endif // velocity_H

File diff suppressed because it is too large Load Diff