add redis config
This commit is contained in:
parent
7e79055671
commit
67429d6b30
@ -31,6 +31,7 @@ SOURCES += \
|
|||||||
pressure_pulsation.cpp \
|
pressure_pulsation.cpp \
|
||||||
radial_vibration.cpp \
|
radial_vibration.cpp \
|
||||||
rangeslider.cpp \
|
rangeslider.cpp \
|
||||||
|
redis_config.cpp \
|
||||||
relaysetting.cpp \
|
relaysetting.cpp \
|
||||||
seismic_monitor.cpp \
|
seismic_monitor.cpp \
|
||||||
setpoint_tachometer.cpp \
|
setpoint_tachometer.cpp \
|
||||||
@ -69,6 +70,7 @@ HEADERS += \
|
|||||||
pressure_pulsation.h \
|
pressure_pulsation.h \
|
||||||
radial_vibration.h \
|
radial_vibration.h \
|
||||||
rangeslider.h \
|
rangeslider.h \
|
||||||
|
redis_config.h \
|
||||||
relaysetting.h \
|
relaysetting.h \
|
||||||
seismic_monitor.h \
|
seismic_monitor.h \
|
||||||
setpoint_tachometer.h \
|
setpoint_tachometer.h \
|
||||||
@ -100,6 +102,7 @@ FORMS += \
|
|||||||
pointname.ui \
|
pointname.ui \
|
||||||
pressure_pulsation.ui \
|
pressure_pulsation.ui \
|
||||||
radial_vibration.ui \
|
radial_vibration.ui \
|
||||||
|
redis_config.ui \
|
||||||
relaysetting.ui \
|
relaysetting.ui \
|
||||||
seismic_monitor.ui \
|
seismic_monitor.ui \
|
||||||
setpoint_tachometer.ui \
|
setpoint_tachometer.ui \
|
||||||
|
|||||||
@ -220,7 +220,8 @@ enum CMTCommand {
|
|||||||
kCleanSubCardLatch = 30, // 清理子板特定通道的Latch状态
|
kCleanSubCardLatch = 30, // 清理子板特定通道的Latch状态
|
||||||
kConfigMQTTBrokerInfo = 31, // 配置与获取MQTT broker信息
|
kConfigMQTTBrokerInfo = 31, // 配置与获取MQTT broker信息
|
||||||
kConfigDeviceID = 32, // 配置设备编号,编号范围为1~99
|
kConfigDeviceID = 32, // 配置设备编号,编号范围为1~99
|
||||||
kGetVoltageRangeValue = 33 // 获取子板动态电压范围
|
kGetVoltageRangeValue = 33, // 获取子板动态电压范围
|
||||||
|
kConfigRedisServer = 34 // 配置redis服务器
|
||||||
};
|
};
|
||||||
enum RS485Baudrate {
|
enum RS485Baudrate {
|
||||||
kBaudrate2400 = 0,
|
kBaudrate2400 = 0,
|
||||||
@ -828,6 +829,29 @@ typedef struct {
|
|||||||
uint8_t device_id; // 设备编号
|
uint8_t device_id; // 设备编号
|
||||||
} DeviceIDConfigRsp;
|
} 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 {
|
struct BaseHeader {
|
||||||
uint8_t head[3]; // 固定 0xAA 0x55 0xAA
|
uint8_t head[3]; // 固定 0xAA 0x55 0xAA
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
#include "dc_outputs.h"
|
#include "dc_outputs.h"
|
||||||
#include "mqtt_config.h"
|
#include "mqtt_config.h"
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include "redis_config.h"
|
||||||
|
|
||||||
QString g_strServerIp;
|
QString g_strServerIp;
|
||||||
QString g_version;
|
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_mqtt, &QAction::triggered, this, &MainWindow::onMqttConfig);
|
||||||
QObject::connect(ui->action_deviveID, &QAction::triggered, this, &MainWindow::onConfigDeviceID);
|
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_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);
|
QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat);
|
||||||
g_strServerIp = settingsread.value("Server/IP").toString();
|
g_strServerIp = settingsread.value("Server/IP").toString();
|
||||||
@ -980,6 +983,11 @@ void MainWindow::onConfigDeviceID(){
|
|||||||
m_tcpClient->waitForRead();
|
m_tcpClient->waitForRead();
|
||||||
qDebug() << "bytesWritten: " << bytesWritten;
|
qDebug() << "bytesWritten: " << bytesWritten;
|
||||||
}
|
}
|
||||||
|
void MainWindow::onRedisConfig(){
|
||||||
|
RedisConfig *redis_config = new RedisConfig();
|
||||||
|
redis_config->setWindowModality(Qt::ApplicationModal);
|
||||||
|
redis_config->show();
|
||||||
|
}
|
||||||
void MainWindow::onSetTime(){
|
void MainWindow::onSetTime(){
|
||||||
SetTimingReq set_time_req = { {0xAA, 0x55, 0xAA}, kTimingCmd, 1,0 };
|
SetTimingReq set_time_req = { {0xAA, 0x55, 0xAA}, kTimingCmd, 1,0 };
|
||||||
int length = sizeof(SetTimingReq);
|
int length = sizeof(SetTimingReq);
|
||||||
|
|||||||
@ -81,6 +81,8 @@ private slots:
|
|||||||
void onMqttConfig();
|
void onMqttConfig();
|
||||||
void onConfigDeviceID();
|
void onConfigDeviceID();
|
||||||
void onGetDeviceID();
|
void onGetDeviceID();
|
||||||
|
void onRedisConfig();
|
||||||
|
|
||||||
|
|
||||||
void onMenuActionTriggered();
|
void onMenuActionTriggered();
|
||||||
void on_pushButton_slot_clicked();
|
void on_pushButton_slot_clicked();
|
||||||
|
|||||||
@ -1090,6 +1090,7 @@
|
|||||||
<addaction name="action_mqtt"/>
|
<addaction name="action_mqtt"/>
|
||||||
<addaction name="action_deviveID"/>
|
<addaction name="action_deviveID"/>
|
||||||
<addaction name="action_get_deviceID"/>
|
<addaction name="action_get_deviceID"/>
|
||||||
|
<addaction name="action_redis"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menu_start"/>
|
<addaction name="menu_start"/>
|
||||||
<addaction name="menu_tool"/>
|
<addaction name="menu_tool"/>
|
||||||
@ -1156,6 +1157,11 @@
|
|||||||
<string>获取设备ID</string>
|
<string>获取设备ID</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="action_redis">
|
||||||
|
<property name="text">
|
||||||
|
<string>Redis配置</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
61
redis_config.cpp
Normal file
61
redis_config.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "redis_config.h"
|
||||||
|
#include "ui_redis_config.h"
|
||||||
|
#include <QRegExpValidator>
|
||||||
|
#include <QMessageBox>
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
30
redis_config.h
Normal file
30
redis_config.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef REDIS_CONFIG_H
|
||||||
|
#define REDIS_CONFIG_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#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
|
||||||
174
redis_config.ui
Normal file
174
redis_config.ui
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>RedisConfig</class>
|
||||||
|
<widget class="QWidget" name="RedisConfig">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>337</width>
|
||||||
|
<height>292</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Redis 配置</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QPushButton" name="pushButton_confirm">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>50</x>
|
||||||
|
<y>230</y>
|
||||||
|
<width>75</width>
|
||||||
|
<height>23</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>确定</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_ip">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>90</x>
|
||||||
|
<y>60</y>
|
||||||
|
<width>151</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="pushButton_cancel">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>170</x>
|
||||||
|
<y>230</y>
|
||||||
|
<width>75</width>
|
||||||
|
<height>23</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>取消</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>100</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>111</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Redis 服务器配置</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>110</y>
|
||||||
|
<width>54</width>
|
||||||
|
<height>12</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>端口:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>70</y>
|
||||||
|
<width>54</width>
|
||||||
|
<height>12</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>IP:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_redis_key">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>90</x>
|
||||||
|
<y>140</y>
|
||||||
|
<width>151</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>150</y>
|
||||||
|
<width>61</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>redis key:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_code">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>90</x>
|
||||||
|
<y>180</y>
|
||||||
|
<width>151</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>20</x>
|
||||||
|
<y>190</y>
|
||||||
|
<width>54</width>
|
||||||
|
<height>12</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>code:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_port">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>90</x>
|
||||||
|
<y>100</y>
|
||||||
|
<width>151</width>
|
||||||
|
<height>25</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Loading…
x
Reference in New Issue
Block a user