优化代码
This commit is contained in:
parent
6c908697bf
commit
f83cbfc753
@ -107,7 +107,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
@ -403,7 +403,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_8">
|
||||
<attribute name="title">
|
||||
|
@ -14,6 +14,7 @@ Connect::Connect(QWidget *parent) :
|
||||
QRegularExpression ipRegex(R"(^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$)");
|
||||
QRegularExpressionValidator *ipValidator = new QRegularExpressionValidator(ipRegex, this);
|
||||
ui->lineEdit_IP->setValidator(ipValidator);
|
||||
ui->lineEdit_IP->setText(g_strServerIp);
|
||||
}
|
||||
|
||||
Connect::~Connect()
|
||||
|
@ -216,6 +216,7 @@ enum CMTCommand {
|
||||
kCleanSubCardCfg = 29, // 清理子板配置
|
||||
kCleanSubCardLatch = 30, // 清理子板特定通道的Latch状态
|
||||
kConfigMQTTBrokerInfo = 31, // 配置与获取MQTT broker信息
|
||||
kConfigDeviceID = 32, // 配置设备编号,编号范围为1~99
|
||||
};
|
||||
enum RS485Baudrate {
|
||||
kBaudrate2400 = 0,
|
||||
@ -785,6 +786,23 @@ typedef struct {
|
||||
uint8_t sid; // 通道编号,1-4
|
||||
} CleanLatchStatusReq;
|
||||
|
||||
typedef struct {
|
||||
uint8_t head[3]; // 固定值:0xAA55AA
|
||||
uint8_t cmd; // kConfigDeviceID
|
||||
uint8_t version; // 版本号,默认为1
|
||||
uint8_t sub_cmd; // 0: get, 1: set
|
||||
uint8_t device_id; // 设备编号 0~99
|
||||
} DeviceIDConfigReq;
|
||||
|
||||
typedef struct {
|
||||
uint8_t head[3]; // 固定值:0xAA55AA
|
||||
uint8_t cmd; // kConfigDeviceID
|
||||
uint8_t version; // 版本号,默认为1
|
||||
uint8_t code; // success:0, failure: others
|
||||
uint8_t sub_cmd; // 0: get, 1: set
|
||||
uint8_t device_id; // 设备编号
|
||||
} DeviceIDConfigRsp;
|
||||
|
||||
struct BaseHeader {
|
||||
uint8_t head[3]; // 固定 0xAA 0x55 0xAA
|
||||
uint8_t cmd;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <QDateTime>
|
||||
#include "dc_outputs.h"
|
||||
#include "mqtt_config.h"
|
||||
#include <QInputDialog>
|
||||
|
||||
QString g_strServerIp;
|
||||
QString g_version;
|
||||
@ -100,6 +101,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
QObject::connect(ui->action_mac, &QAction::triggered, this, &MainWindow::onMACConfig);
|
||||
QObject::connect(ui->action_time, &QAction::triggered, this, &MainWindow::onSetTime);
|
||||
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);
|
||||
|
||||
QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat);
|
||||
g_strServerIp = settingsread.value("Server/IP").toString();
|
||||
@ -880,6 +883,18 @@ void MainWindow::readData(const QByteArray &data) {
|
||||
map_slot_config[config_sub_card_progress.subcard_id].slot_label->setStyleSheet("QLabel { color :#FF0000; font: bold 16px}");
|
||||
statusBar()->showMessage(status, 2000);
|
||||
}
|
||||
}else if(cmd == kConfigDeviceID){
|
||||
DeviceIDConfigRsp device_config_rsp;
|
||||
memcpy(&device_config_rsp, data.data(), sizeof(DeviceIDConfigRsp));
|
||||
if(device_config_rsp.code == 0){
|
||||
statusBar()->showMessage("配置成功!", 2000);
|
||||
}else if(device_config_rsp.code == 1){
|
||||
statusBar()->showMessage("配置失败!", 2000);
|
||||
}
|
||||
if(device_config_rsp.sub_cmd == 0){
|
||||
QString str = QString("设备ID: %1").arg(device_config_rsp.device_id);
|
||||
QMessageBox::information(this, QStringLiteral("提示"), str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -916,6 +931,31 @@ void MainWindow::onMqttConfig(){
|
||||
mqtt_config->setWindowModality(Qt::ApplicationModal);
|
||||
mqtt_config->show();
|
||||
}
|
||||
void MainWindow::onGetDeviceID(){
|
||||
DeviceIDConfigReq config_device_id = { {0xAA, 0x55, 0xAA}, kConfigDeviceID, 1,0,{}};
|
||||
int length = sizeof(DeviceIDConfigReq);
|
||||
qint64 bytesWritten = m_tcpClient->sendData((char*)&config_device_id, length);
|
||||
m_tcpClient->waitForRead();
|
||||
qDebug() << "bytesWritten: " << bytesWritten;
|
||||
}
|
||||
void MainWindow::onConfigDeviceID(){
|
||||
QString strTips =QString("请输入0到100之间的数值");
|
||||
|
||||
bool ok = false;
|
||||
int value = QInputDialog::getInt(this, tr("输入整数对话框"), strTips, 1, 1, 10, 1, &ok);
|
||||
if(!ok) return;
|
||||
|
||||
if(value < 1){
|
||||
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请输入正确的数字!"));
|
||||
return ;
|
||||
}
|
||||
DeviceIDConfigReq config_device_id = { {0xAA, 0x55, 0xAA}, kConfigDeviceID, 1,1,{}};
|
||||
config_device_id.device_id = value;
|
||||
int length = sizeof(DeviceIDConfigReq);
|
||||
qint64 bytesWritten = m_tcpClient->sendData((char*)&config_device_id, length);
|
||||
m_tcpClient->waitForRead();
|
||||
qDebug() << "bytesWritten: " << bytesWritten;
|
||||
}
|
||||
void MainWindow::onSetTime(){
|
||||
SetTimingReq set_time_req = { {0xAA, 0x55, 0xAA}, kTimingCmd, 1,0 };
|
||||
int length = sizeof(SetTimingReq);
|
||||
|
@ -77,6 +77,8 @@ private slots:
|
||||
void onMACConfig();
|
||||
void onSetTime();
|
||||
void onMqttConfig();
|
||||
void onConfigDeviceID();
|
||||
void onGetDeviceID();
|
||||
|
||||
void onMenuActionTriggered();
|
||||
void on_pushButton_slot_clicked();
|
||||
|
@ -1088,6 +1088,8 @@
|
||||
<addaction name="action_eth"/>
|
||||
<addaction name="action_mac"/>
|
||||
<addaction name="action_mqtt"/>
|
||||
<addaction name="action_deviveID"/>
|
||||
<addaction name="action_get_deviceID"/>
|
||||
</widget>
|
||||
<addaction name="menu_start"/>
|
||||
<addaction name="menu_tool"/>
|
||||
@ -1144,6 +1146,16 @@
|
||||
<string>MQTT配置</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_deviveID">
|
||||
<property name="text">
|
||||
<string>设备ID配置</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_get_deviceID">
|
||||
<property name="text">
|
||||
<string>获取设备ID</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -39,19 +39,6 @@
|
||||
<string>确 定</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>750</x>
|
||||
<y>535</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>NCS6100T</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
|
@ -261,19 +261,6 @@
|
||||
<string>取 消</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>740</x>
|
||||
<y>600</y>
|
||||
<width>71</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>NCS6100T</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="checkBox_sgcc">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
|
Loading…
x
Reference in New Issue
Block a user