bug fix
This commit is contained in:
parent
6c7499efa4
commit
3e90c5f980
@ -1498,7 +1498,7 @@ void LightStripManager::syncSnListFromMainWindow(const QStringList &snList)
|
||||
|
||||
void LightStripManager::setupIdentityBindingArea()
|
||||
{
|
||||
identityBindingGroup = new QGroupBox("身份信息绑定", this);
|
||||
identityBindingGroup = new QGroupBox("身份信息绑定(未满10个下发绑定后需等1分钟,或继续补充满10个立即触发)", this);
|
||||
identityBindingGroup->setStyleSheet(
|
||||
"QGroupBox { "
|
||||
" color: #000000; "
|
||||
|
||||
@ -43,6 +43,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(otaDowngradeBtn, &QPushButton::clicked, this, &MainWindow::onOtaDowngradeClicked);
|
||||
connect(getVersionBtn, &QPushButton::clicked, this, &MainWindow::onGetVersionClicked);
|
||||
|
||||
// 添加设备SN输入框变化监听,自动重新订阅主题
|
||||
connect(deviceSnEdit, &QLineEdit::textChanged, this, &MainWindow::onDeviceSnChanged);
|
||||
|
||||
// 初始化灯条管理器
|
||||
lightStripManager = nullptr;
|
||||
|
||||
@ -517,45 +520,14 @@ void MainWindow::onSendLightAllClicked()
|
||||
}
|
||||
|
||||
void MainWindow::onMqttConnected() {
|
||||
statusLabel->setText("MQTT连接成功");
|
||||
statusLabel->setStyleSheet("QLabel { color: green; font-weight: bold; }");
|
||||
qDebug() << "MQTT连接成功";
|
||||
updateConnectionStatus(true);
|
||||
|
||||
|
||||
// 连接成功后,如果设备SN不为空,则订阅主题
|
||||
QString deviceSn = deviceSnEdit->text().trimmed();
|
||||
if (!deviceSn.isEmpty()) {
|
||||
// 订阅原有主题
|
||||
QString responseTopic = QString("iot/10045/%1/response").arg(deviceSn);
|
||||
QString stationTopic = QString("iot/10045/%1/station/report").arg(deviceSn);
|
||||
|
||||
// 订阅light report主题
|
||||
QString lightReportTopic = QString("iot/10045/%1/light/report").arg(deviceSn);
|
||||
|
||||
// 订阅adviceDevice主题(用于搜索灯条响应)
|
||||
QString adviceDeviceTopic = QString("iot/10045/%1/message/adviceDevice").arg(deviceSn);
|
||||
|
||||
QString resourceReportTopic = QString("iot/10045/%1/resource/report").arg(deviceSn);
|
||||
|
||||
mqttClient->subscribe(responseTopic);
|
||||
mqttClient->subscribe(stationTopic);
|
||||
mqttClient->subscribe(lightReportTopic);
|
||||
mqttClient->subscribe(adviceDeviceTopic);
|
||||
mqttClient->subscribe(resourceReportTopic);
|
||||
|
||||
messageDisplay->append(QString("[%1] 已订阅主题: %2")
|
||||
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
|
||||
.arg(responseTopic));
|
||||
messageDisplay->append(QString("[%1] 已订阅主题: %2")
|
||||
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
|
||||
.arg(stationTopic));
|
||||
messageDisplay->append(QString("[%1] 已订阅主题: %2")
|
||||
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
|
||||
.arg(lightReportTopic));
|
||||
messageDisplay->append(QString("[%1] 已订阅主题: %2")
|
||||
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
|
||||
.arg(adviceDeviceTopic));
|
||||
messageDisplay->append(QString("[%1] 已订阅主题: %2")
|
||||
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
|
||||
.arg(resourceReportTopic));
|
||||
qDebug() << "重新订阅";
|
||||
resubscribeTopics();
|
||||
}
|
||||
}
|
||||
|
||||
@ -956,11 +928,44 @@ void MainWindow::onGetVersionClicked() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onDeviceSnChanged()
|
||||
{
|
||||
// 只有在MQTT连接状态下才重新订阅主题
|
||||
if (mqttClient && mqttClient->isConnected()) {
|
||||
resubscribeTopics();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::resubscribeTopics()
|
||||
{
|
||||
if (!mqttClient || !mqttClient->isConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString deviceSn = deviceSnEdit->text().trimmed();
|
||||
if (deviceSn.isEmpty()) {
|
||||
qDebug() << "设备SN为空,不进行订阅";
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "重新订阅主题,设备SN:" << deviceSn;
|
||||
|
||||
// 订阅相关主题
|
||||
mqttClient->subscribe(QString("iot/10045/%1/light/report").arg(deviceSn));
|
||||
mqttClient->subscribe(QString("iot/10045/%1/station/report").arg(deviceSn));
|
||||
mqttClient->subscribe(QString("iot/10045/%1/version/report").arg(deviceSn));
|
||||
mqttClient->subscribe(QString("iot/10045/%1/response").arg(deviceSn));
|
||||
mqttClient->subscribe(QString("iot/10045/%1/resource/report").arg(deviceSn));
|
||||
}
|
||||
|
||||
void MainWindow::updateConnectionStatus(bool connected)
|
||||
{
|
||||
connectBtn->setEnabled(!connected);
|
||||
disconnectBtn->setEnabled(connected);
|
||||
sendLightAllBtn->setEnabled(connected);
|
||||
|
||||
// 控制设备SN输入框:只有连接成功后才能输入
|
||||
deviceSnEdit->setEnabled(connected);
|
||||
|
||||
// 新增:连接成功后禁用连接参数输入框,断开后重新启用
|
||||
usernameEdit->setEnabled(!connected);
|
||||
@ -1422,10 +1427,10 @@ void MainWindow::showUseGuide()
|
||||
{
|
||||
QMessageBox::about(this, "使用说明",
|
||||
"切换主题后看不清文字,请重启应用!!\n"
|
||||
"1. 连接MQTT服务器\n"
|
||||
"1. 连接MQTT服务器(用户名默认:TJ251679787196)\n"
|
||||
"2. 输入需要测试的设备SN\n"
|
||||
"3. 首次使用先升级版本,1.1.16及之前的版本可能不支持升级\n"
|
||||
"4. 可以做其他指令,如:查询版本、搜索灯带、灯带SN管理\n\n"
|
||||
"4. 可以正常操作其他指令,如:查询版本、全部点亮、搜索灯带、灯带SN管理\n\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -47,16 +47,35 @@ public:
|
||||
private slots:
|
||||
void showAbout(); // 简化为关于对话框
|
||||
void showUseGuide(); // 新增:使用说明对话框
|
||||
// MQTT相关槽函数
|
||||
void onConnectClicked();
|
||||
void onDisconnectClicked();
|
||||
void onSendLightAllClicked();
|
||||
void onMqttConnected();
|
||||
void onMqttDisconnected();
|
||||
void onMqttError(const QString &error);
|
||||
void onMessageReceived(const QString &topic, const QString &message);
|
||||
void onOtaUpgradeClicked();
|
||||
void onOtaDowngradeClicked();
|
||||
void onSearchLightStripClicked();
|
||||
void onGetVersionClicked();
|
||||
void onClearSnListClicked();
|
||||
void onLightStripManagerClosed();
|
||||
void onDeviceSnChanged(); // 新增:设备SN变化槽函数
|
||||
|
||||
private:
|
||||
void setupUI();
|
||||
void createMenus(); // 重命名为更清晰的函数名
|
||||
|
||||
// 不使用成员变量存储菜单指针,直接在函数中创建
|
||||
// void setupMenuBar();
|
||||
|
||||
// 注释掉菜单相关成员变量
|
||||
// QAction *versionUpdateAction;
|
||||
void updateConnectionStatus(bool connected);
|
||||
void resubscribeTopics(); // 添加这个声明
|
||||
void processOtaMessage(const QJsonObject &otaData);
|
||||
void sendOtaCommand(const QString &version, bool isUpgrade = true);
|
||||
void processLightReportMessage(const QString &message);
|
||||
void addSnToList(const QString &sn);
|
||||
void saveSnList();
|
||||
void loadSnList();
|
||||
void sendSearchLightStripCommand();
|
||||
void openLightStripManager(); // 添加这个声明
|
||||
|
||||
// 新增:公共接口
|
||||
QString getDeviceSn() const;
|
||||
@ -64,40 +83,6 @@ private:
|
||||
bool isMqttConnected() const;
|
||||
void publishMqttMessage(const QString &topic, const QString &message);
|
||||
|
||||
private slots:
|
||||
// MQTT相关槽函数
|
||||
void onConnectClicked();
|
||||
void onDisconnectClicked();
|
||||
void onSendLightAllClicked();
|
||||
void onMessageReceived(const QString &topic, const QString &message);
|
||||
void onMqttConnected();
|
||||
void onMqttDisconnected();
|
||||
void onMqttError(const QString &error);
|
||||
|
||||
// OTA相关槽函数
|
||||
void onOtaUpgradeClicked();
|
||||
void onOtaDowngradeClicked();
|
||||
void onGetVersionClicked();
|
||||
|
||||
// 灯条SN管理相关槽函数
|
||||
void onClearSnListClicked();
|
||||
void onSearchLightStripClicked();
|
||||
void openLightStripManager(); // 新增:打开灯条管理器
|
||||
void onLightStripManagerClosed(); // 新增:灯条管理器关闭时的处理
|
||||
|
||||
private:
|
||||
void setupToolBar();
|
||||
void updateConnectionStatus(bool connected);
|
||||
void processOtaMessage(const QJsonObject &otaData);
|
||||
void sendOtaCommand(const QString &version, bool isUpgrade = true);
|
||||
|
||||
// 灯条SN管理相关函数
|
||||
void processLightReportMessage(const QString &message);
|
||||
void addSnToList(const QString &sn);
|
||||
void saveSnList();
|
||||
void loadSnList();
|
||||
void sendSearchLightStripCommand();
|
||||
|
||||
// 添加OTA状态跟踪
|
||||
bool otaOperationPending;
|
||||
QString pendingOtaVersion;
|
||||
@ -120,7 +105,7 @@ private:
|
||||
QGroupBox *deviceGroup;
|
||||
QLineEdit *deviceSnEdit;
|
||||
|
||||
// 点亮参数控制区域
|
||||
// 灯光控制区域
|
||||
QGroupBox *lightGroup;
|
||||
QComboBox *colorCombo;
|
||||
QComboBox *flashCombo;
|
||||
@ -129,7 +114,7 @@ private:
|
||||
QComboBox *soundCombo;
|
||||
QPushButton *sendLightAllBtn;
|
||||
|
||||
// 灯条SN管理区域 - 修改为横向布局
|
||||
// SN管理区域
|
||||
QGroupBox *snGroup;
|
||||
QScrollArea *snScrollArea; // 添加滚动区域
|
||||
QWidget *snContainerWidget; // 添加容器widget
|
||||
@ -138,7 +123,7 @@ private:
|
||||
QPushButton *clearSnBtn;
|
||||
QPushButton *searchLightStripBtn;
|
||||
|
||||
// OTA升级区域 - 添加缺失的成员变量
|
||||
// OTA升级区域
|
||||
QGroupBox *otaGroup;
|
||||
QLineEdit *currentVersionEdit;
|
||||
QPushButton *getVersionBtn;
|
||||
@ -147,17 +132,17 @@ private:
|
||||
QProgressBar *otaProgressBar;
|
||||
QLabel *otaStatusLabel;
|
||||
|
||||
// 消息显示区域 - 添加缺失的成员变量
|
||||
// 消息显示区域
|
||||
QGroupBox *messageGroup;
|
||||
QTextEdit *messageDisplay;
|
||||
|
||||
// 状态栏 - 添加缺失的成员变量
|
||||
// 状态栏
|
||||
QLabel *statusLabel;
|
||||
|
||||
// MQTT客户端 - 添加缺失的成员变量
|
||||
// MQTT客户端
|
||||
MqttClient *mqttClient;
|
||||
|
||||
// 灯条SN管理相关成员变量
|
||||
// 数据管理
|
||||
QSet<QString> uniqueSnSet;
|
||||
QList<QCheckBox*> lightStripCheckBoxes; // 添加复选框列表
|
||||
QSettings *settings;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user