|
@@ -43,51 +43,44 @@ firingWidget::firingWidget(const int &row, const bool &select, const QString &uu
|
|
ui->verticalLayout->setContentsMargins(0, 30, 0, 0);
|
|
ui->verticalLayout->setContentsMargins(0, 30, 0, 0);
|
|
ui->scrollArea->setStyleSheet("background: rgba(0, 0, 0, 22); border-radius: 20px;");
|
|
ui->scrollArea->setStyleSheet("background: rgba(0, 0, 0, 22); border-radius: 20px;");
|
|
ui->verticalLayout->addWidget(navProgress);
|
|
ui->verticalLayout->addWidget(navProgress);
|
|
- mqttThread = new MqttThread(this);
|
|
|
|
m_topic = "hxgc/" + uuid + "/B";
|
|
m_topic = "hxgc/" + uuid + "/B";
|
|
QStringList topics = {m_topic};
|
|
QStringList topics = {m_topic};
|
|
m_connectionCheckTimer = new QTimer(this);
|
|
m_connectionCheckTimer = new QTimer(this);
|
|
- mqttThread->setConnectionInfo("114.55.233.194", 1883, "hxgc", "hxgc123456", "aP" + uuid, topics);
|
|
|
|
- connect(mqttThread, &MqttThread::mqttConnected, this, &firingWidget::onMqttConnected);
|
|
|
|
- connect(mqttThread, &MqttThread::mqttDisconnected, this, &firingWidget::onMqttDisconnected);
|
|
|
|
- mqttThread->start();
|
|
|
|
- connect(mqttThread, &MqttThread::projectMqttMessageReceived, this, &firingWidget::handleProjectFiringMqttMessage);
|
|
|
|
|
|
+
|
|
|
|
+ m_subscription = mainMqttClient->subscribeToTopic(m_topic);
|
|
|
|
+ connect(m_subscription, &QMqttSubscription::messageReceived, this, &firingWidget::handleProjectFiringMqttMessage);
|
|
|
|
+
|
|
connect(this, &firingWidget::lastStageChanged, this, &firingWidget::handleFiringStageChanged);
|
|
connect(this, &firingWidget::lastStageChanged, this, &firingWidget::handleFiringStageChanged);
|
|
connect(this, &firingWidget::updateData, this, &firingWidget::onBlastSuccess);
|
|
connect(this, &firingWidget::updateData, this, &firingWidget::onBlastSuccess);
|
|
}
|
|
}
|
|
|
|
|
|
firingWidget::~firingWidget() {
|
|
firingWidget::~firingWidget() {
|
|
- m_connectionCheckTimer->deleteLater();
|
|
|
|
- mqttThread->stopThread();
|
|
|
|
- mqttThread->wait();
|
|
|
|
- qDebug() << "firingWidget::~firingWidget()";
|
|
|
|
|
|
+ m_subscription->unsubscribe();
|
|
delete ui;
|
|
delete ui;
|
|
}
|
|
}
|
|
|
|
|
|
void firingWidget::sendMqttMessage(const QString &topic, const QByteArray &message) {
|
|
void firingWidget::sendMqttMessage(const QString &topic, const QByteArray &message) {
|
|
- if (mqttThread && m_isMqttConnected) {
|
|
|
|
- emit mqttThread->sendMessageRequested(topic, message, quint8(2), false);
|
|
|
|
|
|
+ if (mainMqttClient->isConnected()) {
|
|
|
|
+ mainMqttClient->sendMessage(topic, message, quint8(2), false);
|
|
} else {
|
|
} else {
|
|
- QMessageBox::warning(this, "MQTT未连接", "MQTT未连接, 无法发送消息: " + topic + ", " + message);
|
|
|
|
|
|
+ QMessageBox::warning(nullptr, "MQTT未连接", "MQTT未连接, 无法发送消息: " + topic + ", " + message);
|
|
Logger::getInstance().error("MQTT未连接, 无法发送消息" + topic + ", " + message);
|
|
Logger::getInstance().error("MQTT未连接, 无法发送消息" + topic + ", " + message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void firingWidget::startBlasting() {
|
|
void firingWidget::startBlasting() {
|
|
- checkBlasterConnection();
|
|
|
|
// 等待3s mqtt连接后再发送mqtt消息
|
|
// 等待3s mqtt连接后再发送mqtt消息
|
|
- QTimer::singleShot(3000, this, [this]() {
|
|
|
|
- m_lastStage = FiringStages::Starting;
|
|
|
|
- emit lastStageChanged(FiringStages::Starting);
|
|
|
|
- });
|
|
|
|
|
|
+ m_lastStage = FiringStages::Starting;
|
|
|
|
+ emit lastStageChanged(FiringStages::Starting);
|
|
|
|
+ checkBlasterConnection();
|
|
}
|
|
}
|
|
|
|
|
|
// 定间隔检查有没有收到爆破器返回信息
|
|
// 定间隔检查有没有收到爆破器返回信息
|
|
void firingWidget::checkBlasterConnection() {
|
|
void firingWidget::checkBlasterConnection() {
|
|
m_lastMsgTime = QDateTime::currentDateTime();
|
|
m_lastMsgTime = QDateTime::currentDateTime();
|
|
- connect(mqttThread, &MqttThread::projectMqttMessageReceived, this,
|
|
|
|
- [&]() { m_lastMsgTime = QDateTime::currentDateTime(); });
|
|
|
|
|
|
|
|
|
|
+ connect(m_subscription, &QMqttSubscription::messageReceived, this,
|
|
|
|
+ [&]() { m_lastMsgTime = QDateTime::currentDateTime(); });
|
|
connect(m_connectionCheckTimer, &QTimer::timeout, this, [this]() {
|
|
connect(m_connectionCheckTimer, &QTimer::timeout, this, [this]() {
|
|
if (m_lastStage == FiringStages::CancelConfirmed || m_lastStage == FiringStages::BlastFinished) {
|
|
if (m_lastStage == FiringStages::CancelConfirmed || m_lastStage == FiringStages::BlastFinished) {
|
|
return;
|
|
return;
|
|
@@ -186,16 +179,14 @@ bool firingWidget::uploadToDanLing(const QJsonObject &jsonObj) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-void firingWidget::handleProjectFiringMqttMessage(const QByteArray &message, const QMqttTopicName &topic) {
|
|
|
|
- QString msgText = QString("Topic: %1, Message: %2").arg(topic.name(), QString(message));
|
|
|
|
|
|
+void firingWidget::handleProjectFiringMqttMessage(const QMqttMessage &message) {
|
|
|
|
+ QString msgText = QString("Topic: %1, Message: %2").arg(message.topic().name(), QString(message.payload()));
|
|
QTextEdit *textEdit = ui->scrollAreaWidgetContents->findChild<QTextEdit *>("textEdit");
|
|
QTextEdit *textEdit = ui->scrollAreaWidgetContents->findChild<QTextEdit *>("textEdit");
|
|
if (textEdit) {
|
|
if (textEdit) {
|
|
textEdit->append(msgText);
|
|
textEdit->append(msgText);
|
|
}
|
|
}
|
|
- qDebug() << ANSI_COLOR_GREEN << "Received message on topic:" << topic.name() << ", Message:" << QString(message)
|
|
|
|
- << ANSI_COLOR_RESET;
|
|
|
|
int stage = 0;
|
|
int stage = 0;
|
|
- QJsonDocument jsonDoc = QJsonDocument::fromJson(message);
|
|
|
|
|
|
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(message.payload());
|
|
if (!jsonDoc.isNull() && jsonDoc.isObject()) {
|
|
if (!jsonDoc.isNull() && jsonDoc.isObject()) {
|
|
QJsonObject jsonObj = jsonDoc.object();
|
|
QJsonObject jsonObj = jsonDoc.object();
|
|
|
|
|
|
@@ -320,14 +311,12 @@ void firingWidget::onCountdownFinished(const QString &topic, const QString &mess
|
|
sendMqttMessage(topic, message.toUtf8());
|
|
sendMqttMessage(topic, message.toUtf8());
|
|
}
|
|
}
|
|
|
|
|
|
-void firingWidget::onMqttConnected() {
|
|
|
|
- Logger::getInstance().info(QString("Project(%1) firing MQTT connected successfully.").arg(m_curProjUuid));
|
|
|
|
- m_isMqttConnected = true;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void firingWidget::onMqttDisconnected() {
|
|
void firingWidget::onMqttDisconnected() {
|
|
Logger::getInstance().info(QString("Project(%1) firing MQTT disconncted.").arg(m_curProjUuid));
|
|
Logger::getInstance().info(QString("Project(%1) firing MQTT disconncted.").arg(m_curProjUuid));
|
|
- m_isMqttConnected = false;
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void firingWidget::onMqttConnected() {
|
|
|
|
+ Logger::getInstance().info(QString("Project(%1) firing MQTT connected.").arg(m_curProjUuid));
|
|
}
|
|
}
|
|
|
|
|
|
void firingWidget::onButtonPressedReceived(const QString &topic, const QString &message) {
|
|
void firingWidget::onButtonPressedReceived(const QString &topic, const QString &message) {
|