新增灯条sn信息绑定功能
This commit is contained in:
parent
23afed3769
commit
f65924cc94
@ -16,7 +16,7 @@ LightStripManager::LightStripManager(QWidget *parent)
|
||||
setWindowIcon(QIcon(":/icons/lightstrip.png"));
|
||||
|
||||
// 设置初始窗口大小和位置
|
||||
resize(1000, 650);
|
||||
resize(1000, 800);
|
||||
|
||||
// 居中显示到父窗口
|
||||
if (parent) {
|
||||
@ -39,7 +39,7 @@ LightStripManager::LightStripManager(QWidget *parent)
|
||||
}
|
||||
|
||||
// 设置最小尺寸
|
||||
setMinimumSize(700, 500);
|
||||
setMinimumSize(700, 600);
|
||||
|
||||
// 彻底修复背景透明问题
|
||||
setStyleSheet(
|
||||
@ -104,11 +104,13 @@ void LightStripManager::setupUI()
|
||||
setupControlPanel();
|
||||
setupSnDisplayArea();
|
||||
setupLightControlArea();
|
||||
setupIdentityBindingArea(); // 添加身份信息绑定区域
|
||||
|
||||
// 设置分割器比例
|
||||
mainSplitter->setStretchFactor(0, 0); // 控制面板固定高度
|
||||
mainSplitter->setStretchFactor(1, 1); // SN显示区域可伸缩
|
||||
mainSplitter->setStretchFactor(2, 0); // 点亮控制区域固定高度
|
||||
mainSplitter->setStretchFactor(3, 0); // 身份信息绑定区域固定高度
|
||||
}
|
||||
|
||||
void LightStripManager::setupControlPanel()
|
||||
@ -286,6 +288,7 @@ void LightStripManager::setupControlPanel()
|
||||
void LightStripManager::setupSnDisplayArea()
|
||||
{
|
||||
snDisplayGroup = new QGroupBox("灯条SN列表", this);
|
||||
snDisplayGroup->setMinimumHeight(300);
|
||||
snDisplayGroup->setStyleSheet(
|
||||
"QGroupBox { "
|
||||
" color: #000000; "
|
||||
@ -835,6 +838,7 @@ void LightStripManager::onSendLightAllClicked()
|
||||
void LightStripManager::onCheckBoxStateChanged()
|
||||
{
|
||||
updateControlButtons();
|
||||
updateSnCount(); // 添加这行来实时更新选中数量显示
|
||||
emit snSelectionChanged(getSelectedSns());
|
||||
}
|
||||
|
||||
@ -879,11 +883,12 @@ void LightStripManager::filterSnDisplay(const QString &searchText)
|
||||
|
||||
void LightStripManager::updateSnCount()
|
||||
{
|
||||
int count = uniqueSnSet.size();
|
||||
snCountLabel->setText(QString("已发现灯条: %1 个").arg(count));
|
||||
int totalCount = uniqueSnSet.size();
|
||||
int selectedCount = getSelectedSns().size();
|
||||
snCountLabel->setText(QString("已发现灯条: %1 个 | 已选中: %2 个").arg(totalCount).arg(selectedCount));
|
||||
|
||||
// 发出数量变化信号
|
||||
emit snCountChanged(count);
|
||||
emit snCountChanged(totalCount);
|
||||
}
|
||||
|
||||
void LightStripManager::updateControlButtons()
|
||||
@ -936,4 +941,323 @@ void LightStripManager::loadSnList()
|
||||
for (const QString &sn : snList) {
|
||||
addSnToList(sn);
|
||||
}
|
||||
}
|
||||
|
||||
void LightStripManager::onBindIdentitySelectedClicked()
|
||||
{
|
||||
QStringList selectedSns = getSelectedSns();
|
||||
if (selectedSns.isEmpty()) {
|
||||
bindingStatusLabel->setText("状态: 请先选择灯条");
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #f44336; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
QMessageBox::warning(this, "警告", "请先选择要绑定身份信息的灯条");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查身份信息参数
|
||||
if (currentLabel1.isEmpty() || currentLabel2.isEmpty() || currentLabel3.isEmpty()) {
|
||||
bindingStatusLabel->setText("状态: 请填写完整参数");
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #f44336; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
QMessageBox::warning(this, "警告", "请填写完整的Label1、Label2、Label3参数");
|
||||
return;
|
||||
}
|
||||
|
||||
bindingStatusLabel->setText("状态: 正在绑定...");
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #FF9800; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
|
||||
// 为每个选中的灯条发送身份信息绑定消息
|
||||
for (const QString &sn : selectedSns) {
|
||||
sendIdentityBindingMessage(sn);
|
||||
}
|
||||
|
||||
bindingStatusLabel->setText(QString("状态: 已发送 %1 个绑定请求").arg(selectedSns.size()));
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #4CAF50; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
void LightStripManager::onBindIdentityAllClicked()
|
||||
{
|
||||
QStringList allSns = getAllSns();
|
||||
if (allSns.isEmpty()) {
|
||||
bindingStatusLabel->setText("状态: 没有可绑定的灯条");
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #f44336; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
QMessageBox::warning(this, "警告", "没有可绑定身份信息的灯条");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查身份信息参数
|
||||
if (currentLabel1.isEmpty() || currentLabel2.isEmpty() || currentLabel3.isEmpty()) {
|
||||
bindingStatusLabel->setText("状态: 请填写完整参数");
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #f44336; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
QMessageBox::warning(this, "警告", "请填写完整的Label1、Label2、Label3参数");
|
||||
return;
|
||||
}
|
||||
|
||||
bindingStatusLabel->setText("状态: 正在绑定全部...");
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #FF9800; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
|
||||
// 为所有灯条发送身份信息绑定消息
|
||||
for (const QString &sn : allSns) {
|
||||
sendIdentityBindingMessage(sn);
|
||||
}
|
||||
|
||||
bindingStatusLabel->setText(QString("状态: 已发送 %1 个绑定请求").arg(allSns.size()));
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #4CAF50; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
void LightStripManager::onLabel1Changed(const QString &text)
|
||||
{
|
||||
currentLabel1 = text.trimmed();
|
||||
saveIdentitySettings();
|
||||
}
|
||||
|
||||
void LightStripManager::onLabel2Changed(const QString &text)
|
||||
{
|
||||
currentLabel2 = text.trimmed();
|
||||
saveIdentitySettings();
|
||||
}
|
||||
|
||||
void LightStripManager::onLabel3Changed(const QString &text)
|
||||
{
|
||||
currentLabel3 = text.trimmed();
|
||||
saveIdentitySettings();
|
||||
}
|
||||
|
||||
void LightStripManager::sendIdentityBindingMessage(const QString &sn)
|
||||
{
|
||||
// 发出身份信息绑定信号,让MainWindow处理MQTT发送
|
||||
emit identityBindingRequested(sn, currentLabel1, currentLabel2, currentLabel3);
|
||||
}
|
||||
|
||||
QString LightStripManager::generateMessageId() const
|
||||
{
|
||||
// 生成唯一的消息ID
|
||||
return QString("msg_%1_%2")
|
||||
.arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmss"))
|
||||
.arg(QDateTime::currentMSecsSinceEpoch() % 1000);
|
||||
}
|
||||
|
||||
void LightStripManager::saveIdentitySettings()
|
||||
{
|
||||
settings->setValue("identityBinding/label1", currentLabel1);
|
||||
settings->setValue("identityBinding/label2", currentLabel2);
|
||||
settings->setValue("identityBinding/label3", currentLabel3);
|
||||
settings->sync();
|
||||
}
|
||||
|
||||
void LightStripManager::loadIdentitySettings()
|
||||
{
|
||||
currentLabel1 = settings->value("identityBinding/label1", "").toString();
|
||||
currentLabel2 = settings->value("identityBinding/label2", "").toString();
|
||||
currentLabel3 = settings->value("identityBinding/label3", "").toString();
|
||||
|
||||
// 设置到UI控件
|
||||
if (label1Edit) {
|
||||
label1Edit->setText(currentLabel1);
|
||||
}
|
||||
if (label2Edit) {
|
||||
label2Edit->setText(currentLabel2);
|
||||
}
|
||||
if (label3Edit) {
|
||||
label3Edit->setText(currentLabel3);
|
||||
}
|
||||
}
|
||||
|
||||
void LightStripManager::setMainWindow(MainWindow *mainWindow)
|
||||
{
|
||||
m_mainWindow = mainWindow;
|
||||
}
|
||||
void LightStripManager::setupIdentityBindingArea()
|
||||
{
|
||||
identityBindingGroup = new QGroupBox("身份信息绑定", this);
|
||||
identityBindingGroup->setStyleSheet(
|
||||
"QGroupBox { "
|
||||
" color: #000000; "
|
||||
" font-weight: bold; "
|
||||
" font-size: 14px; "
|
||||
" padding-top: 15px; "
|
||||
" border: 2px solid #ddd; "
|
||||
" border-radius: 8px; "
|
||||
" margin-top: 10px; "
|
||||
"}"
|
||||
);
|
||||
identityBindingGroup->setMaximumHeight(150);
|
||||
|
||||
QVBoxLayout *identityLayout = new QVBoxLayout(identityBindingGroup);
|
||||
|
||||
// 第一行:身份信息参数
|
||||
QHBoxLayout *row1Layout = new QHBoxLayout();
|
||||
|
||||
QLabel *label1Label = new QLabel("Label1:");
|
||||
label1Label->setStyleSheet("QLabel { color: #000000; }");
|
||||
row1Layout->addWidget(label1Label);
|
||||
|
||||
label1Edit = new QLineEdit();
|
||||
label1Edit->setPlaceholderText("输入Label1参数...");
|
||||
label1Edit->setMinimumHeight(30);
|
||||
label1Edit->setStyleSheet(
|
||||
"QLineEdit { "
|
||||
" color: #000000; "
|
||||
" border: 2px solid #ddd; "
|
||||
" border-radius: 6px; "
|
||||
" padding: 5px 10px; "
|
||||
" font-size: 12px; "
|
||||
"} "
|
||||
"QLineEdit:focus { border-color: #2196F3; }"
|
||||
);
|
||||
connect(label1Edit, &QLineEdit::textChanged, this, &LightStripManager::onLabel1Changed);
|
||||
row1Layout->addWidget(label1Edit);
|
||||
|
||||
QLabel *label2Label = new QLabel("Label2:");
|
||||
label2Label->setStyleSheet("QLabel { color: #000000; }");
|
||||
row1Layout->addWidget(label2Label);
|
||||
|
||||
label2Edit = new QLineEdit();
|
||||
label2Edit->setPlaceholderText("输入Label2参数...");
|
||||
label2Edit->setMinimumHeight(30);
|
||||
label2Edit->setStyleSheet(
|
||||
"QLineEdit { "
|
||||
" color: #000000; "
|
||||
" border: 2px solid #ddd; "
|
||||
" border-radius: 6px; "
|
||||
" padding: 5px 10px; "
|
||||
" font-size: 12px; "
|
||||
"} "
|
||||
"QLineEdit:focus { border-color: #2196F3; }"
|
||||
);
|
||||
connect(label2Edit, &QLineEdit::textChanged, this, &LightStripManager::onLabel2Changed);
|
||||
row1Layout->addWidget(label2Edit);
|
||||
|
||||
QLabel *label3Label = new QLabel("Label3:");
|
||||
label3Label->setStyleSheet("QLabel { color: #000000; }");
|
||||
row1Layout->addWidget(label3Label);
|
||||
|
||||
label3Edit = new QLineEdit();
|
||||
label3Edit->setPlaceholderText("输入Label3参数...");
|
||||
label3Edit->setMinimumHeight(30);
|
||||
label3Edit->setStyleSheet(
|
||||
"QLineEdit { "
|
||||
" color: #000000; "
|
||||
" border: 2px solid #ddd; "
|
||||
" border-radius: 6px; "
|
||||
" padding: 5px 10px; "
|
||||
" font-size: 12px; "
|
||||
"} "
|
||||
"QLineEdit:focus { border-color: #2196F3; }"
|
||||
);
|
||||
connect(label3Edit, &QLineEdit::textChanged, this, &LightStripManager::onLabel3Changed);
|
||||
row1Layout->addWidget(label3Edit);
|
||||
|
||||
identityLayout->addLayout(row1Layout);
|
||||
|
||||
// 第二行:绑定按钮和状态显示
|
||||
QHBoxLayout *row2Layout = new QHBoxLayout();
|
||||
|
||||
bindIdentitySelectedBtn = new QPushButton("绑定选中灯条");
|
||||
bindIdentitySelectedBtn->setMinimumHeight(40);
|
||||
bindIdentitySelectedBtn->setMinimumWidth(120);
|
||||
bindIdentitySelectedBtn->setStyleSheet(
|
||||
"QPushButton { "
|
||||
" background-color: #4CAF50; "
|
||||
" color: white; "
|
||||
" font-weight: bold; "
|
||||
" padding: 10px 20px; "
|
||||
" border-radius: 6px; "
|
||||
" font-size: 14px; "
|
||||
"} "
|
||||
"QPushButton:hover { background-color: #388E3C; }"
|
||||
);
|
||||
connect(bindIdentitySelectedBtn, &QPushButton::clicked, this, &LightStripManager::onBindIdentitySelectedClicked);
|
||||
row2Layout->addWidget(bindIdentitySelectedBtn);
|
||||
|
||||
bindIdentityAllBtn = new QPushButton("绑定全部灯条");
|
||||
bindIdentityAllBtn->setMinimumHeight(40);
|
||||
bindIdentityAllBtn->setMinimumWidth(120);
|
||||
bindIdentityAllBtn->setStyleSheet(
|
||||
"QPushButton { "
|
||||
" background-color: #2196F3; "
|
||||
" color: white; "
|
||||
" font-weight: bold; "
|
||||
" padding: 10px 20px; "
|
||||
" border-radius: 6px; "
|
||||
" font-size: 14px; "
|
||||
"} "
|
||||
"QPushButton:hover { background-color: #1976D2; }"
|
||||
);
|
||||
connect(bindIdentityAllBtn, &QPushButton::clicked, this, &LightStripManager::onBindIdentityAllClicked);
|
||||
row2Layout->addWidget(bindIdentityAllBtn);
|
||||
|
||||
row2Layout->addStretch();
|
||||
|
||||
bindingStatusLabel = new QLabel("状态: 就绪");
|
||||
bindingStatusLabel->setStyleSheet(
|
||||
"QLabel { "
|
||||
" font-weight: bold; "
|
||||
" font-size: 12px; "
|
||||
" color: #4CAF50; "
|
||||
" padding: 5px; "
|
||||
"}"
|
||||
);
|
||||
row2Layout->addWidget(bindingStatusLabel);
|
||||
|
||||
identityLayout->addLayout(row2Layout);
|
||||
|
||||
mainSplitter->addWidget(identityBindingGroup);
|
||||
|
||||
// 加载保存的身份信息设置
|
||||
loadIdentitySettings();
|
||||
}
|
||||
@ -22,6 +22,10 @@
|
||||
#include <QGridLayout>
|
||||
#include <QSplitter>
|
||||
#include <QResizeEvent>
|
||||
// 新增身份信息绑定需要的头文件
|
||||
#include <QDateTime>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
class MainWindow; // 前向声明
|
||||
|
||||
@ -38,7 +42,7 @@ public:
|
||||
QStringList getSelectedSns() const;
|
||||
QStringList getAllSns() const;
|
||||
int getSnCount() const;
|
||||
void clearSnList(); // 添加这个函数声明
|
||||
void clearSnList();
|
||||
|
||||
// 新增:设置主窗口引用
|
||||
void setMainWindow(MainWindow *mainWindow);
|
||||
@ -47,7 +51,9 @@ signals:
|
||||
void snSelectionChanged(const QStringList &selectedSns);
|
||||
void lightControlRequested(const QStringList &sns, const QString &color, bool flash, int interval, int duration, bool sound);
|
||||
void clearAllRequested();
|
||||
void snCountChanged(int count); // 新增:灯条数量变化信号
|
||||
void snCountChanged(int count);
|
||||
// 新增:身份信息绑定信号
|
||||
void identityBindingRequested(const QString &sn, const QString &label1, const QString &label2, const QString &label3);
|
||||
|
||||
private slots:
|
||||
void onClearSnListClicked();
|
||||
@ -60,13 +66,22 @@ private slots:
|
||||
void onSendLightAllClicked();
|
||||
void onCheckBoxStateChanged();
|
||||
void onRefreshClicked();
|
||||
// 删除这一行: void onRandomColorClicked();
|
||||
|
||||
// 新增:身份信息绑定相关槽函数
|
||||
void onBindIdentitySelectedClicked();
|
||||
void onBindIdentityAllClicked();
|
||||
void onLabel1Changed(const QString &text);
|
||||
void onLabel2Changed(const QString &text);
|
||||
void onLabel3Changed(const QString &text);
|
||||
|
||||
private:
|
||||
void setupUI();
|
||||
void setupControlPanel();
|
||||
void setupSnDisplayArea();
|
||||
void setupLightControlArea();
|
||||
// 新增:身份信息绑定区域
|
||||
void setupIdentityBindingArea();
|
||||
|
||||
void saveSnList();
|
||||
void loadSnList();
|
||||
void updateSnCount();
|
||||
@ -77,6 +92,12 @@ private:
|
||||
|
||||
// 新增:MQTT发送功能
|
||||
void sendLightControlMessage(const QStringList &sns);
|
||||
|
||||
// 新增:身份信息绑定相关私有函数
|
||||
void sendIdentityBindingMessage(const QString &sn);
|
||||
QString generateMessageId() const;
|
||||
void saveIdentitySettings();
|
||||
void loadIdentitySettings();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
@ -103,7 +124,7 @@ private:
|
||||
QGroupBox *snDisplayGroup;
|
||||
QScrollArea *snScrollArea;
|
||||
QWidget *snContainerWidget;
|
||||
QGridLayout *snGridLayout; // 改为网格布局以支持更好的响应式设计
|
||||
QGridLayout *snGridLayout;
|
||||
|
||||
// 点亮控制区域
|
||||
QGroupBox *lightControlGroup;
|
||||
@ -114,7 +135,15 @@ private:
|
||||
QComboBox *soundCombo;
|
||||
QPushButton *sendLightSelectedBtn;
|
||||
QPushButton *sendLightAllBtn;
|
||||
// 删除这一行: QPushButton *randomColorBtn;
|
||||
|
||||
// 新增:身份信息绑定区域
|
||||
QGroupBox *identityBindingGroup;
|
||||
QLineEdit *label1Edit;
|
||||
QLineEdit *label2Edit;
|
||||
QLineEdit *label3Edit;
|
||||
QPushButton *bindIdentitySelectedBtn;
|
||||
QPushButton *bindIdentityAllBtn;
|
||||
QLabel *bindingStatusLabel;
|
||||
|
||||
// 数据存储
|
||||
QSettings *settings;
|
||||
@ -124,11 +153,16 @@ private:
|
||||
MainWindow *m_mainWindow;
|
||||
|
||||
// 新增:缺失的成员变量
|
||||
QTimer *resizeTimer; // 调整大小定时器
|
||||
QSet<QString> uniqueSnSet; // 唯一SN集合
|
||||
QList<QWidget*> lightStripWidgets; // 灯条控件列表
|
||||
QList<QCheckBox*> lightStripCheckBoxes; // 灯条复选框列表
|
||||
int columnsPerRow; // 每行列数
|
||||
QTimer *resizeTimer;
|
||||
QSet<QString> uniqueSnSet;
|
||||
QList<QWidget*> lightStripWidgets;
|
||||
QList<QCheckBox*> lightStripCheckBoxes;
|
||||
int columnsPerRow;
|
||||
|
||||
// 新增:身份信息绑定相关数据
|
||||
QString currentLabel1;
|
||||
QString currentLabel2;
|
||||
QString currentLabel3;
|
||||
};
|
||||
|
||||
#endif // LIGHTSTRIPMANAGER_H
|
||||
@ -1121,6 +1121,76 @@ void MainWindow::openLightStripManager()
|
||||
snCountLabel->setText(QString("已发现灯条: %1 个").arg(count));
|
||||
});
|
||||
|
||||
// 新增:连接身份信息绑定信号
|
||||
connect(lightStripManager, &LightStripManager::identityBindingRequested,
|
||||
this, [this](const QString &sn, const QString &label1, const QString &label2, const QString &label3) {
|
||||
// 处理身份信息绑定请求
|
||||
|
||||
// 检查MQTT连接状态
|
||||
if (!mqttClient->isConnected()) {
|
||||
qDebug() << "MQTT未连接,无法发送身份信息绑定命令";
|
||||
QMessageBox::warning(this, "警告", "MQTT未连接,请先连接MQTT服务器");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取设备SN(从界面获取)
|
||||
QString deviceSn = deviceSnEdit->text().trimmed();
|
||||
if (deviceSn.isEmpty()) {
|
||||
QMessageBox::warning(this, "警告", "请先输入需要测试的设备SN");
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建身份信息绑定消息
|
||||
QJsonObject msgData;
|
||||
msgData["sn"] = sn;
|
||||
msgData["label1"] = label1;
|
||||
msgData["label2"] = label2;
|
||||
msgData["label3"] = label3;
|
||||
|
||||
// 构建完整的msg对象
|
||||
QJsonObject fullMsg;
|
||||
fullMsg["data"] = msgData;
|
||||
fullMsg["msgType"] = "3022"; // 身份信息绑定消息类型
|
||||
|
||||
// 转换msg为JSON字符串
|
||||
QJsonDocument msgDoc(fullMsg);
|
||||
QString msgString = msgDoc.toJson(QJsonDocument::Compact);
|
||||
|
||||
// 构建最外层消息
|
||||
QJsonObject outerMessage;
|
||||
outerMessage["deviceId"] = "";
|
||||
outerMessage["messageId"] = QString::number(QDateTime::currentMSecsSinceEpoch());
|
||||
outerMessage["msg"] = msgString;
|
||||
outerMessage["timestamp"] = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
// 转换为最终JSON字符串
|
||||
QJsonDocument finalDoc(outerMessage);
|
||||
QString finalMessage = finalDoc.toJson(QJsonDocument::Compact);
|
||||
|
||||
// 构建MQTT主题
|
||||
QString topic = QString("iot/10045/%1/message/adviceDevice").arg(deviceSn);
|
||||
|
||||
// 发送MQTT消息
|
||||
bool success = mqttClient->publish(topic, finalMessage);
|
||||
|
||||
if (success) {
|
||||
qDebug() << "成功发送身份信息绑定命令";
|
||||
qDebug() << "主题:" << topic;
|
||||
qDebug() << "消息:" << finalMessage;
|
||||
|
||||
// 在消息显示区域显示发送的消息
|
||||
messageDisplay->append(QString("[%1] 发送身份信息绑定到设备 %2")
|
||||
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
|
||||
.arg(deviceSn));
|
||||
messageDisplay->append(QString("主题: %1").arg(topic));
|
||||
messageDisplay->append(QString("灯条SN: %1, Label1: %2, Label2: %3, Label3: %4")
|
||||
.arg(sn).arg(label1).arg(label2).arg(label3));
|
||||
} else {
|
||||
qDebug() << "发送身份信息绑定命令失败";
|
||||
QMessageBox::warning(this, "错误", "发送MQTT消息失败,请检查网络连接");
|
||||
}
|
||||
});
|
||||
|
||||
// 连接关闭信号
|
||||
connect(lightStripManager, &QWidget::destroyed,
|
||||
this, &MainWindow::onLightStripManagerClosed);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user