From 67429d6b30e20179d5000f7db20af99e9ae0e2e5 Mon Sep 17 00:00:00 2001 From: "DESKTOP-7I8SUIC\\zhang" Date: Fri, 31 Oct 2025 15:53:17 +0800 Subject: [PATCH] add redis config --- TSI_Config.pro | 3 + data_config.h | 26 ++++++- mainwindow.cpp | 8 +++ mainwindow.h | 2 + mainwindow.ui | 6 ++ redis_config.cpp | 61 +++++++++++++++++ redis_config.h | 30 ++++++++ redis_config.ui | 174 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 redis_config.cpp create mode 100644 redis_config.h create mode 100644 redis_config.ui diff --git a/TSI_Config.pro b/TSI_Config.pro index a800707..f13f848 100644 --- a/TSI_Config.pro +++ b/TSI_Config.pro @@ -31,6 +31,7 @@ SOURCES += \ pressure_pulsation.cpp \ radial_vibration.cpp \ rangeslider.cpp \ + redis_config.cpp \ relaysetting.cpp \ seismic_monitor.cpp \ setpoint_tachometer.cpp \ @@ -69,6 +70,7 @@ HEADERS += \ pressure_pulsation.h \ radial_vibration.h \ rangeslider.h \ + redis_config.h \ relaysetting.h \ seismic_monitor.h \ setpoint_tachometer.h \ @@ -100,6 +102,7 @@ FORMS += \ pointname.ui \ pressure_pulsation.ui \ radial_vibration.ui \ + redis_config.ui \ relaysetting.ui \ seismic_monitor.ui \ setpoint_tachometer.ui \ diff --git a/data_config.h b/data_config.h index 76309ec..d83985b 100644 --- a/data_config.h +++ b/data_config.h @@ -220,7 +220,8 @@ enum CMTCommand { kCleanSubCardLatch = 30, // 清理子板特定通道的Latch状态 kConfigMQTTBrokerInfo = 31, // 配置与获取MQTT broker信息 kConfigDeviceID = 32, // 配置设备编号,编号范围为1~99 - kGetVoltageRangeValue = 33 // 获取子板动态电压范围 + kGetVoltageRangeValue = 33, // 获取子板动态电压范围 + kConfigRedisServer = 34 // 配置redis服务器 }; enum RS485Baudrate { kBaudrate2400 = 0, @@ -828,6 +829,29 @@ typedef struct { uint8_t device_id; // 设备编号 } DeviceIDConfigRsp; +typedef struct { + uint8_t head[3]; // 固定值:0xAA55AA + uint8_t cmd; // kConfigRedisServer + uint8_t version; // 版本号,默认为1 + uint8_t sub_cmd; // 0: get, 1: set + char ip[16]; + uint16_t port; + char redis_key[32]; + char vib_code[32]; +} RedisCfgReq; + +typedef struct { + uint8_t head[3]; // 固定值:0xAA55AA + uint8_t cmd; // kConfigMQTTBrokerInfo + uint8_t version; // 版本号,默认为1 + uint8_t code; // success:0, failure: others + uint8_t sub_cmd; // 0: get, 1: set + char ip[16]; + uint16_t port; + char redis_key[32]; + char vib_code[32]; +} RedisCfgRsp; + struct BaseHeader { uint8_t head[3]; // 固定 0xAA 0x55 0xAA uint8_t cmd; diff --git a/mainwindow.cpp b/mainwindow.cpp index c6b99bd..d38639f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -29,6 +29,7 @@ #include "dc_outputs.h" #include "mqtt_config.h" #include +#include "redis_config.h" QString g_strServerIp; QString g_version; @@ -103,6 +104,8 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->action_mqtt, &QAction::triggered, this, &MainWindow::onMqttConfig); QObject::connect(ui->action_deviveID, &QAction::triggered, this, &MainWindow::onConfigDeviceID); QObject::connect(ui->action_get_deviceID, &QAction::triggered, this, &MainWindow::onGetDeviceID); + QObject::connect(ui->action_redis, &QAction::triggered, this, &MainWindow::onRedisConfig); + QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat); g_strServerIp = settingsread.value("Server/IP").toString(); @@ -980,6 +983,11 @@ void MainWindow::onConfigDeviceID(){ m_tcpClient->waitForRead(); qDebug() << "bytesWritten: " << bytesWritten; } +void MainWindow::onRedisConfig(){ + RedisConfig *redis_config = new RedisConfig(); + redis_config->setWindowModality(Qt::ApplicationModal); + redis_config->show(); +} void MainWindow::onSetTime(){ SetTimingReq set_time_req = { {0xAA, 0x55, 0xAA}, kTimingCmd, 1,0 }; int length = sizeof(SetTimingReq); diff --git a/mainwindow.h b/mainwindow.h index 9af83a8..2555bf6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -81,6 +81,8 @@ private slots: void onMqttConfig(); void onConfigDeviceID(); void onGetDeviceID(); + void onRedisConfig(); + void onMenuActionTriggered(); void on_pushButton_slot_clicked(); diff --git a/mainwindow.ui b/mainwindow.ui index 8f2ed9a..7cfe413 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1090,6 +1090,7 @@ + @@ -1156,6 +1157,11 @@ 获取设备ID + + + Redis配置 + + diff --git a/redis_config.cpp b/redis_config.cpp new file mode 100644 index 0000000..630c51f --- /dev/null +++ b/redis_config.cpp @@ -0,0 +1,61 @@ +#include "redis_config.h" +#include "ui_redis_config.h" +#include +#include +RedisConfig::RedisConfig(QWidget *parent) : + QWidget(parent), + ui(new Ui::RedisConfig) +{ + ui->setupUi(this); + + QString exp = "\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.)" + "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"; + QRegExp rege(exp); + QValidator *Validator = new QRegExpValidator(rege); + ui->lineEdit_ip->setValidator(Validator); + m_tcpClient = MyTcpClient::instance(); + connect(m_tcpClient, SIGNAL(dataReceived(const QByteArray &)), this, SLOT(readData(const QByteArray &))); +} + +RedisConfig::~RedisConfig() +{ + delete ui; +} +void RedisConfig::readData(const QByteArray &data) { + qDebug() << "Received from server:" << data; + uint8_t cmd = data[3]; + if (cmd == kConfigRedisServer) { + RedisCfgRsp redis_config_rsp; + memcpy(&redis_config_rsp, data.data(), sizeof(RedisCfgRsp)); + qDebug() << "mqtt_config_rsp code" << redis_config_rsp.code ; + if(redis_config_rsp.code == 0){ + QMessageBox::information(this, QStringLiteral("提示"), "配置成功!"); + }else{ + QMessageBox::warning(this, QStringLiteral("提示"), "配置失败!"); + } + } +} +void RedisConfig::on_pushButton_confirm_clicked() +{ + RedisCfgReq redis_config = { {0xAA, 0x55, 0xAA}, kConfigRedisServer, 1,1,{},0,{},{} }; + memcpy(redis_config.ip,ui->lineEdit_ip->text().toStdString().c_str(),sizeof(redis_config.ip)); + redis_config.port = ui->lineEdit_port->text().toInt(); + memcpy(redis_config.redis_key,ui->lineEdit_redis_key->text().toStdString().c_str(),sizeof(redis_config.redis_key)); + memcpy(redis_config.vib_code,ui->lineEdit_code->text().toStdString().c_str(),sizeof(redis_config.vib_code)); + + char send_buf[100] ={0}; + memcpy(send_buf, (char*)&redis_config, sizeof(RedisCfgReq)); + + int length = sizeof(RedisCfgReq); + qint64 bytesWritten = m_tcpClient->sendData(send_buf, length); + m_tcpClient->waitForRead(); + qDebug() << "bytesWritten: " << bytesWritten; + +} + + +void RedisConfig::on_pushButton_cancel_clicked() +{ + +} + diff --git a/redis_config.h b/redis_config.h new file mode 100644 index 0000000..5fab1fc --- /dev/null +++ b/redis_config.h @@ -0,0 +1,30 @@ +#ifndef REDIS_CONFIG_H +#define REDIS_CONFIG_H + +#include +#include "MyTcpClient.h" +namespace Ui { +class RedisConfig; +} + +class RedisConfig : public QWidget +{ + Q_OBJECT + +public: + explicit RedisConfig(QWidget *parent = nullptr); + ~RedisConfig(); + +private slots: + void on_pushButton_confirm_clicked(); + + void on_pushButton_cancel_clicked(); + void readData(const QByteArray&); + +private: + Ui::RedisConfig *ui; + MyTcpClient* m_tcpClient; + +}; + +#endif // REDIS_CONFIG_H diff --git a/redis_config.ui b/redis_config.ui new file mode 100644 index 0000000..f5aac8a --- /dev/null +++ b/redis_config.ui @@ -0,0 +1,174 @@ + + + RedisConfig + + + + 0 + 0 + 337 + 292 + + + + Redis 配置 + + + + + 50 + 230 + 75 + 23 + + + + 确定 + + + + + + 90 + 60 + 151 + 25 + + + + + 0 + 25 + + + + + + + 170 + 230 + 75 + 23 + + + + 取消 + + + + + + 100 + 10 + 111 + 16 + + + + Redis 服务器配置 + + + + + + 20 + 110 + 54 + 12 + + + + 端口: + + + + + + 20 + 70 + 54 + 12 + + + + IP: + + + + + + 90 + 140 + 151 + 25 + + + + + 0 + 25 + + + + + + + 20 + 150 + 61 + 16 + + + + redis key: + + + + + + 90 + 180 + 151 + 25 + + + + + 0 + 25 + + + + + + + 20 + 190 + 54 + 12 + + + + code: + + + + + + 90 + 100 + 151 + 25 + + + + + 0 + 25 + + + + + + +