|
@@ -18,53 +18,51 @@
|
|
|
#define ANSI_COLOR_GREEN "\x1B[32m"
|
|
|
#define ANSI_COLOR_RESET "\x1B[0m"
|
|
|
|
|
|
-firingWidget::firingWidget(const int& row,const bool& select,const QString& uuid,QWidget *parent) :
|
|
|
- QWidget(parent),
|
|
|
- ui(new Ui::firingWidget),
|
|
|
- m_uuid(uuid),
|
|
|
- m_row(row),
|
|
|
- m_select(select),
|
|
|
- dao(DatabaseManager::getInstance().getDatabase()),
|
|
|
- daoDet(DatabaseManager::getInstance().getDatabase()),
|
|
|
- daoReg(DatabaseManager::getInstance().getDatabase())
|
|
|
+firingWidget::firingWidget(const int &row, const bool &select, const QString &uuid, QWidget *parent) : QWidget(parent),
|
|
|
+ ui(new Ui::firingWidget),
|
|
|
+ m_uuid(uuid),
|
|
|
+ m_row(row),
|
|
|
+ m_select(select),
|
|
|
+ dao(DatabaseManager::getInstance().getDatabase()),
|
|
|
+ daoDet(DatabaseManager::getInstance().getDatabase()),
|
|
|
+ daoReg(DatabaseManager::getInstance().getDatabase())
|
|
|
{
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
ui->pushButton_2->setText("立即测试");
|
|
|
ui->textEdit->setStyleSheet("border: none;background: transparent;");
|
|
|
ui->frame_2->setStyleSheet("border: none;background: transparent;");
|
|
|
- QFrame *frame = ui->frame_2; // 使用你为 QFrame 设置的对象名称
|
|
|
+ QFrame *frame = ui->frame_2; // 使用你为 QFrame 设置的对象名称
|
|
|
navProgress = new NavProgress(frame);
|
|
|
ui->verticalLayout->setContentsMargins(0, 30, 0, 0);
|
|
|
ui->scrollArea->setStyleSheet("background: rgba(0, 0, 0, 22); border-radius: 20px;");
|
|
|
ui->verticalLayout->addWidget(navProgress);
|
|
|
mqttThread = new MqttThread(this);
|
|
|
- QStringList topics = {"hxgc/"+uuid+"/B"};
|
|
|
- mqttThread->setConnectionInfo("114.55.233.194", 1883, "hxgc", "hxgc123456", "P"+uuid, topics);
|
|
|
+ QStringList topics = {"hxgc/" + uuid + "/B"};
|
|
|
+ mqttThread->setConnectionInfo("114.55.233.194", 1883, "hxgc", "hxgc123456", "P" + uuid, topics);
|
|
|
connect(mqttThread, &MqttThread::mqttConnected, this, &firingWidget::onMqttConnected);
|
|
|
mqttThread->start();
|
|
|
connect(mqttThread, &MqttThread::messageAndTopicReceived, this, &firingWidget::handleMessageAndTopic);
|
|
|
|
|
|
connect(this, &firingWidget::lastStageChanged, this, &firingWidget::onLastStageChanged);
|
|
|
- connect(this, &firingWidget::updateData, this, &firingWidget::saveProjDataAndUpload);
|
|
|
+ connect(this, &firingWidget::updateData, this, &firingWidget::onBlastSucess);
|
|
|
startBlasting();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
firingWidget::~firingWidget()
|
|
|
{
|
|
|
delete ui;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-void firingWidget::sendMqttMessage(const QString& topic, const QByteArray& message)
|
|
|
+void firingWidget::sendMqttMessage(const QString &topic, const QByteArray &message)
|
|
|
{
|
|
|
|
|
|
- if (mqttThread && m_isMqttConnected) {
|
|
|
+ if (mqttThread && m_isMqttConnected)
|
|
|
+ {
|
|
|
emit mqttThread->sendMessageRequested(topic, message);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
qDebug() << "MQTT 未连接,无法发送消息";
|
|
|
}
|
|
|
}
|
|
@@ -72,59 +70,58 @@ void firingWidget::sendMqttMessage(const QString& topic, const QByteArray& messa
|
|
|
void firingWidget::startBlasting()
|
|
|
{
|
|
|
// TODO 检测起爆器是否在线
|
|
|
- QTimer::singleShot(1000, this, [this]() {
|
|
|
+ QTimer::singleShot(1000, this, [this]()
|
|
|
+ {
|
|
|
lastStage=0;
|
|
|
- emit lastStageChanged(0);
|
|
|
- });
|
|
|
-
|
|
|
+ emit lastStageChanged(0); });
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-void firingWidget::on_pushButton_2_clicked(){
|
|
|
- emit countdown(m_uuid,topic,"message");
|
|
|
+void firingWidget::on_pushButton_2_clicked()
|
|
|
+{
|
|
|
+ emit countdown(m_uuid, topic, "message");
|
|
|
}
|
|
|
|
|
|
+bool firingWidget::uploadToDanLing(const QJsonObject &jsonObj)
|
|
|
+{
|
|
|
|
|
|
-
|
|
|
-bool firingWidget::uploadToDanLing(const QJsonObject& jsonObj){
|
|
|
-
|
|
|
- QString htid = jsonObj["project_htid"].toString();
|
|
|
- QString htm = ""; //
|
|
|
- QString xmbh = jsonObj["project_xmbh"].toString();
|
|
|
- QString sbbh = jsonObj["equipment_sn"].toString();
|
|
|
- QString bprysfz = jsonObj["operator_identity"].toString();
|
|
|
- QString dwdm = jsonObj["company_code"].toString();
|
|
|
- QString xtm = ""; //
|
|
|
- QString jd = jsonObj["blast_longitude"].toString();
|
|
|
- QString bpsj = jsonObj["blast_time"].toString();
|
|
|
- QString wd = jsonObj["blast_latitude"].toString();
|
|
|
- QStringList uidList;
|
|
|
- QJsonArray regs = jsonObj["regs"].toArray();
|
|
|
- for (const auto& reg : regs) {
|
|
|
- QJsonObject regObj = reg.toObject();
|
|
|
- QJsonArray dets = regObj["dets"].toArray();
|
|
|
- for (const auto& det : dets) {
|
|
|
- QJsonObject detObj = det.toObject();
|
|
|
- uidList.append(detObj["uid"].toString());
|
|
|
- }
|
|
|
- }
|
|
|
- QString uid = uidList.join(",");
|
|
|
-
|
|
|
- QString plainText = QString("{\"htid\":\"%1\",\"htm\":\"%2\",\"xmbh\":\"%3\",\"sbbh\":\"%4\","
|
|
|
- "\"bprysfz\":\"%5\",\"dwdm\":\"%6\",\"xtm\":\"%7\",\"jd\":\"%8\","
|
|
|
- "\"bpsj\":\"%9\",\"wd\":\"%10\",\"uid\":\"%11\"}")
|
|
|
- .arg(htid)
|
|
|
- .arg(htm)
|
|
|
- .arg(xmbh)
|
|
|
- .arg(sbbh)
|
|
|
- .arg(bprysfz)
|
|
|
- .arg(dwdm)
|
|
|
- .arg(xtm)
|
|
|
- .arg(jd)
|
|
|
- .arg(bpsj)
|
|
|
- .arg(wd)
|
|
|
- .arg(uid);
|
|
|
+ QString htid = jsonObj["project_htid"].toString();
|
|
|
+ QString htm = ""; //
|
|
|
+ QString xmbh = jsonObj["project_xmbh"].toString();
|
|
|
+ QString sbbh = jsonObj["equipment_sn"].toString();
|
|
|
+ QString bprysfz = jsonObj["operator_identity"].toString();
|
|
|
+ QString dwdm = jsonObj["company_code"].toString();
|
|
|
+ QString xtm = ""; //
|
|
|
+ QString jd = jsonObj["blast_longitude"].toString();
|
|
|
+ QString bpsj = jsonObj["blast_time"].toString();
|
|
|
+ QString wd = jsonObj["blast_latitude"].toString();
|
|
|
+ QStringList uidList;
|
|
|
+ QJsonArray regs = jsonObj["regs"].toArray();
|
|
|
+ for (const auto ® : regs)
|
|
|
+ {
|
|
|
+ QJsonObject regObj = reg.toObject();
|
|
|
+ QJsonArray dets = regObj["dets"].toArray();
|
|
|
+ for (const auto &det : dets)
|
|
|
+ {
|
|
|
+ QJsonObject detObj = det.toObject();
|
|
|
+ uidList.append(detObj["uid"].toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ QString uid = uidList.join(",");
|
|
|
+
|
|
|
+ QString plainText = QString("{\"htid\":\"%1\",\"htm\":\"%2\",\"xmbh\":\"%3\",\"sbbh\":\"%4\","
|
|
|
+ "\"bprysfz\":\"%5\",\"dwdm\":\"%6\",\"xtm\":\"%7\",\"jd\":\"%8\","
|
|
|
+ "\"bpsj\":\"%9\",\"wd\":\"%10\",\"uid\":\"%11\"}")
|
|
|
+ .arg(htid)
|
|
|
+ .arg(htm)
|
|
|
+ .arg(xmbh)
|
|
|
+ .arg(sbbh)
|
|
|
+ .arg(bprysfz)
|
|
|
+ .arg(dwdm)
|
|
|
+ .arg(xtm)
|
|
|
+ .arg(jd)
|
|
|
+ .arg(bpsj)
|
|
|
+ .arg(wd)
|
|
|
+ .arg(uid);
|
|
|
Des3Encryption des3;
|
|
|
QByteArray key = "jadl12345678912345678912";
|
|
|
QByteArray encryptedData = des3.des3Encrypt(plainText.toUtf8(), key);
|
|
@@ -140,23 +137,28 @@ bool firingWidget::uploadToDanLing(const QJsonObject& jsonObj){
|
|
|
QNetworkRequest request(url);
|
|
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
|
|
QByteArray postData;
|
|
|
- QNetworkReply *reply = manager.post(request,postData);
|
|
|
+ QNetworkReply *reply = manager.post(request, postData);
|
|
|
QEventLoop loop;
|
|
|
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
|
|
loop.exec();
|
|
|
- if (reply->error() == QNetworkReply::NoError) {
|
|
|
+ if (reply->error() == QNetworkReply::NoError)
|
|
|
+ {
|
|
|
QByteArray responseData = reply->readAll();
|
|
|
qDebug() << "Response:" << QString(responseData);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
qDebug() << "Error:" << reply->errorString();
|
|
|
}
|
|
|
reply->deleteLater();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool firingWidget::addRegRecords(const QJsonObject& jsonObj) {
|
|
|
+bool firingWidget::recordBlastReg(const QJsonObject &jsonObj)
|
|
|
+{
|
|
|
QJsonArray regsArray = jsonObj["regs"].toArray();
|
|
|
- for (const auto& regValue : regsArray) {
|
|
|
+ for (const auto ®Value : regsArray)
|
|
|
+ {
|
|
|
QJsonObject regObj = regValue.toObject();
|
|
|
HBlastRegRecord recordReg;
|
|
|
reg_uuid = QUuid::createUuid().toString(QUuid::WithoutBraces).remove(QRegularExpression("-"));
|
|
@@ -175,39 +177,9 @@ bool firingWidget::addRegRecords(const QJsonObject& jsonObj) {
|
|
|
recordReg.setRecordUuid(blast_uuid);
|
|
|
recordReg.setCreatedAt(QDateTime::currentDateTime());
|
|
|
// 插入数据到数据库
|
|
|
- if (!daoReg.saveHBlastRegRecord(recordReg)) {
|
|
|
+ if (!daoReg.saveHBlastRegRecord(recordReg))
|
|
|
+ {
|
|
|
return false;
|
|
|
- } else {
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-bool firingWidget::handleBlastFinishedMsg(const QJsonObject& jsonObj) {
|
|
|
- QJsonArray regsArray = jsonObj["regs"].toArray();
|
|
|
- for (const auto& regValue : regsArray) {
|
|
|
- QJsonObject regObj = regValue.toObject();
|
|
|
- QJsonArray detsArray = regObj["dets"].toArray();
|
|
|
- for (const auto& detValue : detsArray) {
|
|
|
- QJsonObject detObj = detValue.toObject();
|
|
|
- HBlastRecordDet recordDet;
|
|
|
-
|
|
|
- recordDet.setId(0);
|
|
|
- recordDet.setUuid(QUuid::createUuid().toString(QUuid::WithoutBraces).remove(QRegularExpression("-")));
|
|
|
- recordDet.setOutCode(detObj["out_code"].toString());
|
|
|
- recordDet.setInnerCode(detObj["in_code"].toString());
|
|
|
- recordDet.setUid(detObj["uid"].toString());
|
|
|
- recordDet.setStatus(detObj["status"].toString());
|
|
|
- recordDet.setFreq(detObj["freq"].toString());
|
|
|
- recordDet.setDelayTime(detObj["delay_time"].toString());
|
|
|
- recordDet.setTag(detObj["tag"].toString());
|
|
|
- recordDet.setCreatedAt(QDateTime::currentDateTime());
|
|
|
- recordDet.setBlastRecordId(blast_uuid);
|
|
|
- recordDet.setRegId(reg_uuid);
|
|
|
- recordDet.setCreatedAt(QDateTime::currentDateTime());
|
|
|
- if (!daoDet.addHBlastRecordDet(recordDet)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
@@ -217,100 +189,107 @@ void firingWidget::handleMessageAndTopic(const QByteArray &message, const QMqttT
|
|
|
{
|
|
|
|
|
|
QString msgText = QString("Topic: %1, Message: %2").arg(topic.name(), QString(message));
|
|
|
- QTextEdit *textEdit = ui->scrollAreaWidgetContents->findChild<QTextEdit*>("textEdit");
|
|
|
- if (textEdit) {
|
|
|
+ QTextEdit *textEdit = ui->scrollAreaWidgetContents->findChild<QTextEdit *>("textEdit");
|
|
|
+ if (textEdit)
|
|
|
+ {
|
|
|
textEdit->append(msgText);
|
|
|
}
|
|
|
int stage = 0;
|
|
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(message);
|
|
|
- if (!jsonDoc.isNull() && jsonDoc.isObject()) {
|
|
|
+ if (!jsonDoc.isNull() && jsonDoc.isObject())
|
|
|
+ {
|
|
|
QJsonObject jsonObj = jsonDoc.object();
|
|
|
- if (jsonObj.contains("type") && jsonObj["type"].toInt() == 1) {
|
|
|
- if (jsonObj.contains("data") && jsonObj["data"].isObject()) {
|
|
|
+ if (jsonObj.contains("type") && jsonObj["type"].toInt() == 1)
|
|
|
+ {
|
|
|
+ if (jsonObj.contains("data") && jsonObj["data"].isObject())
|
|
|
+ {
|
|
|
QJsonObject dataObject = jsonObj["data"].toObject();
|
|
|
stage = dataObject["stage"].toInt();
|
|
|
- if (stage != lastStage) {
|
|
|
+ if (stage != lastStage)
|
|
|
+ {
|
|
|
lastStage = stage;
|
|
|
- switch (stage) {
|
|
|
- case 0:
|
|
|
- navProgress->setState(0);
|
|
|
- ui->pushButton_2->setText("立即测试");
|
|
|
- ui->pushButton_2->setEnabled(false);
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- navProgress->setState(1);
|
|
|
- emit progressChanged(1,m_row);
|
|
|
- emit updateBlastStatus(1,m_row);
|
|
|
- ui->pushButton_2->setText("立即测试");
|
|
|
- ui->pushButton_2->setEnabled(false);
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- ui->pushButton_2->setEnabled(true);
|
|
|
- emit progressChanged(2,m_row);
|
|
|
- emit updateBlastStatus(2,m_row);
|
|
|
- qDebug() << "stage:" << stage;
|
|
|
- ui->pushButton_2->setText("充电");
|
|
|
- navProgress->setState(2);
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- ui->pushButton_2->setEnabled(false);
|
|
|
- emit progressChanged(3,m_row);
|
|
|
- emit updateBlastStatus(3,m_row);
|
|
|
- ui->pushButton_2->setText("充电");
|
|
|
- navProgress->setState(3);
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- ui->pushButton_2->setEnabled(true);
|
|
|
- emit progressChanged(4,m_row);
|
|
|
- emit updateBlastStatus(4,m_row);
|
|
|
- ui->pushButton_2->setText("起爆");
|
|
|
- navProgress->setState(4);
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- ui->pushButton_2->setEnabled(false);
|
|
|
- emit progressChanged(5,m_row);
|
|
|
- emit updateBlastStatus(5,m_row);
|
|
|
- emit updateButton(5,m_row);
|
|
|
- ui->pushButton_2->setText("起爆");
|
|
|
- navProgress->setState(5);
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- ui->pushButton_2->setEnabled(false);
|
|
|
- emit progressChanged(6,m_row);
|
|
|
- emit updateBlastStatus(6,m_row);
|
|
|
- emit updateProjectStatus(m_uuid);
|
|
|
- ui->pushButton_2->setText("已完成起爆");
|
|
|
- navProgress->setState(6);
|
|
|
- break;
|
|
|
- case 7:
|
|
|
- qDebug() << "status:" << stage;
|
|
|
- ui->pushButton_2->setEnabled(false);
|
|
|
- emit progressChanged(0,m_row); // 发送进度值
|
|
|
- emit updateBlastStatus(0,m_row);//正在测试
|
|
|
- ui->pushButton_2->setText("已完成起爆");
|
|
|
- navProgress->setState(6);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ switch (stage)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ navProgress->setState(0);
|
|
|
+ ui->pushButton_2->setText("立即测试");
|
|
|
+ ui->pushButton_2->setEnabled(false);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ navProgress->setState(1);
|
|
|
+ emit progressChanged(1, m_row);
|
|
|
+ emit updateBlastStatus(1, m_row);
|
|
|
+ ui->pushButton_2->setText("立即测试");
|
|
|
+ ui->pushButton_2->setEnabled(false);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ ui->pushButton_2->setEnabled(true);
|
|
|
+ emit progressChanged(2, m_row);
|
|
|
+ emit updateBlastStatus(2, m_row);
|
|
|
+ qDebug() << "stage:" << stage;
|
|
|
+ ui->pushButton_2->setText("充电");
|
|
|
+ navProgress->setState(2);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ ui->pushButton_2->setEnabled(false);
|
|
|
+ emit progressChanged(3, m_row);
|
|
|
+ emit updateBlastStatus(3, m_row);
|
|
|
+ ui->pushButton_2->setText("充电");
|
|
|
+ navProgress->setState(3);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ ui->pushButton_2->setEnabled(true);
|
|
|
+ emit progressChanged(4, m_row);
|
|
|
+ emit updateBlastStatus(4, m_row);
|
|
|
+ ui->pushButton_2->setText("起爆");
|
|
|
+ navProgress->setState(4);
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ ui->pushButton_2->setEnabled(false);
|
|
|
+ emit progressChanged(5, m_row);
|
|
|
+ emit updateBlastStatus(5, m_row);
|
|
|
+ emit updateButton(5, m_row);
|
|
|
+ ui->pushButton_2->setText("起爆");
|
|
|
+ navProgress->setState(5);
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ ui->pushButton_2->setEnabled(false);
|
|
|
+ emit progressChanged(6, m_row);
|
|
|
+ emit updateBlastStatus(6, m_row);
|
|
|
+ emit updateProjectStatus(m_uuid);
|
|
|
+ ui->pushButton_2->setText("已完成起爆");
|
|
|
+ navProgress->setState(6);
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ qDebug() << "status:" << stage;
|
|
|
+ ui->pushButton_2->setEnabled(false);
|
|
|
+ emit progressChanged(0, m_row); // 发送进度值
|
|
|
+ emit updateBlastStatus(0, m_row); // 正在测试
|
|
|
+ ui->pushButton_2->setText("已完成起爆");
|
|
|
+ navProgress->setState(6);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
emit lastStageChanged(lastStage);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (jsonObj.contains("type") && jsonObj["type"].toInt() == 2){
|
|
|
- if (jsonObj.contains("data") && jsonObj["data"].isObject()) {
|
|
|
+ if (jsonObj.contains("type") && jsonObj["type"].toInt() == 2)
|
|
|
+ {
|
|
|
+ if (jsonObj.contains("data") && jsonObj["data"].isObject())
|
|
|
+ {
|
|
|
QJsonObject dataObject = jsonObj["data"].toObject();
|
|
|
emit updateData(dataObject);
|
|
|
emit closeFiring(m_uuid);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void firingWidget::onCountdownFinished(const QString &topic,const QString &message){
|
|
|
+void firingWidget::onCountdownFinished(const QString &topic, const QString &message)
|
|
|
+{
|
|
|
sendMqttMessage(topic, message.toUtf8());
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void firingWidget::onMqttConnected()
|
|
@@ -318,101 +297,115 @@ void firingWidget::onMqttConnected()
|
|
|
m_isMqttConnected = true;
|
|
|
}
|
|
|
|
|
|
-void firingWidget::onButtonPressedReceived(const QString &topic,const QString &message)
|
|
|
+void firingWidget::onButtonPressedReceived(const QString &topic, const QString &message)
|
|
|
{
|
|
|
QByteArray data = "\r\nDISABLE_BUTTON\r\n";
|
|
|
// 调用发送数据的方法
|
|
|
bool success = serialTool->sendData(data);
|
|
|
- if (success) {
|
|
|
+ if (success)
|
|
|
+ {
|
|
|
qDebug() << "Data sent successfully";
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
qDebug() << "Failed to send data";
|
|
|
}
|
|
|
- emit countdown(m_uuid,topic,message);
|
|
|
-
|
|
|
-
|
|
|
+ emit countdown(m_uuid, topic, message);
|
|
|
}
|
|
|
|
|
|
// 状态改变
|
|
|
void firingWidget::onLastStageChanged(int newStage)
|
|
|
{
|
|
|
- QString topic = "hxgc/"+m_uuid+"/P";
|
|
|
- QString message;
|
|
|
- QString buttonText;
|
|
|
- switch (lastStage) {
|
|
|
- case 0:
|
|
|
- message = "起爆测试";
|
|
|
- buttonText = "立即测试";
|
|
|
- sendMqttMessage(topic, message.toUtf8());
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- message = "开始充电";
|
|
|
- buttonText = "充电";
|
|
|
- sendMqttMessage(topic, message.toUtf8());
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- message = "起爆";
|
|
|
- buttonText = "起爆";
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- if(!m_select){
|
|
|
- if (connection) {
|
|
|
- disconnect(connection);
|
|
|
- qDebug() << "Connection disconnected.";
|
|
|
- }
|
|
|
- if (connectionPress) {
|
|
|
- disconnect(connectionPress);
|
|
|
- qDebug() << "connectionPress disconnected.";
|
|
|
- }
|
|
|
- serialTool->releaseInstance();
|
|
|
+ QString topic = "hxgc/" + m_uuid + "/P";
|
|
|
+ QString message;
|
|
|
+ QString buttonText;
|
|
|
+ switch (lastStage)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ message = "起爆测试";
|
|
|
+ buttonText = "立即测试";
|
|
|
+ sendMqttMessage(topic, message.toUtf8());
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ message = "开始充电";
|
|
|
+ buttonText = "充电";
|
|
|
+ sendMqttMessage(topic, message.toUtf8());
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ message = "起爆";
|
|
|
+ buttonText = "起爆";
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ if (!m_select)
|
|
|
+ {
|
|
|
+ if (connection)
|
|
|
+ {
|
|
|
+ disconnect(connection);
|
|
|
+ qDebug() << "Connection disconnected.";
|
|
|
+ }
|
|
|
+ if (connectionPress)
|
|
|
+ {
|
|
|
+ disconnect(connectionPress);
|
|
|
+ qDebug() << "connectionPress disconnected.";
|
|
|
}
|
|
|
+ serialTool->releaseInstance();
|
|
|
+ }
|
|
|
|
|
|
- qDebug() << ANSI_COLOR_GREEN << "释放按键 5" << ANSI_COLOR_RESET;
|
|
|
+ qDebug() << ANSI_COLOR_GREEN << "释放按键 5" << ANSI_COLOR_RESET;
|
|
|
|
|
|
- break;
|
|
|
- default:
|
|
|
+ break;
|
|
|
+ default:
|
|
|
|
|
|
- return;
|
|
|
- }
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (!message.isEmpty()) {
|
|
|
- if(lastStage == 4 && !m_select){
|
|
|
+ if (!message.isEmpty())
|
|
|
+ {
|
|
|
+ if (lastStage == 4 && !m_select)
|
|
|
+ {
|
|
|
bool success2;
|
|
|
serialTool = SerialTool::getInstance(nullptr, &success2);
|
|
|
- if(serialTool){
|
|
|
+ if (serialTool)
|
|
|
+ {
|
|
|
QByteArray data = "\r\nENABLE_BUTTON\r\n";
|
|
|
bool success = serialTool->sendData(data);
|
|
|
- if (success) {
|
|
|
+ if (success)
|
|
|
+ {
|
|
|
qDebug() << "Data sent successfully";
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
qDebug() << "Failed to send data";
|
|
|
}
|
|
|
- connection =connect(serialTool, &SerialTool::enableButtonReceived, [this]() {
|
|
|
- emit updateBlastStatus(10,m_row);
|
|
|
- });
|
|
|
- connectionPress = connect(serialTool, &SerialTool::buttonPressedReceived,[this, topic, message]() {
|
|
|
- this->onButtonPressedReceived(topic, message);
|
|
|
- });
|
|
|
-
|
|
|
- }else {
|
|
|
+ connection = connect(serialTool, &SerialTool::enableButtonReceived, [this]()
|
|
|
+ { emit updateBlastStatus(10, m_row); });
|
|
|
+ connectionPress = connect(serialTool, &SerialTool::buttonPressedReceived, [this, topic, message]()
|
|
|
+ { this->onButtonPressedReceived(topic, message); });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
qDebug() << "serialTool Not fond.";
|
|
|
- //在准备起爆状态下 但是没有获取串口
|
|
|
+ // 在准备起爆状态下 但是没有获取串口
|
|
|
lastStage = 10;
|
|
|
}
|
|
|
- }else if(lastStage == 4&&m_select){
|
|
|
- qDebug() << "多台起爆:待起爆状态";
|
|
|
- emit selectSignal(m_uuid);
|
|
|
- }else{//????
|
|
|
- qDebug() << "Stage 值变为: " << newStage<<"发送消息"<<message.toUtf8();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ else if (lastStage == 4 && m_select)
|
|
|
+ {
|
|
|
+ qDebug() << "多台起爆:待起爆状态";
|
|
|
+ emit selectSignal(m_uuid);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ { //????
|
|
|
+ qDebug() << "Stage 值变为: " << newStage << "发送消息" << message.toUtf8();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void firingWidget::cancelBlasting()
|
|
|
{
|
|
|
QString message = "取消流程";
|
|
|
- if (!message.isEmpty()) {
|
|
|
+ if (!message.isEmpty())
|
|
|
+ {
|
|
|
sendMqttMessage(topic, message.toUtf8());
|
|
|
}
|
|
|
}
|
|
@@ -427,7 +420,8 @@ void firingWidget::on_sendTest_4_clicked()
|
|
|
lat = labLat;
|
|
|
lon = labLon;
|
|
|
QSqlDatabase db = DatabaseManager::getInstance().getDatabase();
|
|
|
- if (!db.transaction()) {
|
|
|
+ if (!db.transaction())
|
|
|
+ {
|
|
|
qDebug() << "Failed to start transaction:" << db.lastError().text();
|
|
|
// return false;
|
|
|
}
|
|
@@ -488,7 +482,7 @@ void firingWidget::on_sendTest_4_clicked()
|
|
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(jsonData.toUtf8());
|
|
|
QJsonObject jsonObj = doc.object();
|
|
|
- // 创建 HBlastRecord 对象
|
|
|
+ // 创建 HBlastRecord 对象
|
|
|
HBlastRecord record;
|
|
|
record.setProjectName(jsonObj["project_name"].toString());
|
|
|
record.setProjectHtid(jsonObj["project_htid"].toString());
|
|
@@ -509,7 +503,7 @@ void firingWidget::on_sendTest_4_clicked()
|
|
|
record.setErrorDetCount(jsonObj["error_deto_count"].toInt());
|
|
|
record.setBlastAt(QDateTime::fromString(jsonObj["blast_time"].toString(), "yyyy-MM-dd hh:mm:ss"));
|
|
|
record.setCreatedAt(QDateTime::currentDateTime());
|
|
|
- qDebug() << "currentDateTime."<<QDateTime::currentDateTime();
|
|
|
+ qDebug() << "currentDateTime." << QDateTime::currentDateTime();
|
|
|
|
|
|
record.setUuid(QUuid::createUuid().toString(QUuid::WithoutBraces).remove(QRegularExpression("-")));
|
|
|
|
|
@@ -536,26 +530,37 @@ void firingWidget::on_sendTest_4_clicked()
|
|
|
|
|
|
// db.commit();
|
|
|
|
|
|
-
|
|
|
- if(lat=="定位失败"&&lat=="未知"&&lon=="定位失败"&&lon=="未知"){
|
|
|
+ if (lat == "定位失败" && lat == "未知" && lon == "定位失败" && lon == "未知")
|
|
|
+ {
|
|
|
// 数据出本地 不传丹灵
|
|
|
- if (dao.addHBlastRecord(record)) {
|
|
|
+ if (dao.addHBlastRecord(record))
|
|
|
+ {
|
|
|
qDebug() << "Record inserted successfully.";
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
qDebug() << "Failed to insert record.";
|
|
|
}
|
|
|
- if (!handleBlastFinishedMsg(jsonObj)) {
|
|
|
+ if (!recordDetsData(jsonObj))
|
|
|
+ {
|
|
|
qDebug() << "Insert failed for UID:"; // 假设 record 有 uid 成员
|
|
|
- if (db.rollback()) {
|
|
|
+ if (db.rollback())
|
|
|
+ {
|
|
|
qDebug() << "Transaction rolled back successfully.";
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
}
|
|
|
}
|
|
|
- if (!addRegRecords(jsonObj)) {
|
|
|
- if (db.rollback()) {
|
|
|
+ if (!recordBlastReg(jsonObj))
|
|
|
+ {
|
|
|
+ if (db.rollback())
|
|
|
+ {
|
|
|
qDebug() << "Transaction rolled back successfully.";
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
}
|
|
|
}
|
|
@@ -570,80 +575,174 @@ void firingWidget::on_sendTest_4_clicked()
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
-void firingWidget::saveProjDataAndUpload(const QJsonObject& jsonObj){
|
|
|
- blast_uuid =QUuid::createUuid().toString(QUuid::WithoutBraces).remove(QRegularExpression("-"));
|
|
|
+// 处理爆破成功,安全验证装置通过MQTT传回的数据
|
|
|
+void firingWidget::onBlastSucess(const QJsonObject &jsonObj)
|
|
|
+{
|
|
|
+ Logger::getInstance().info(QString("收到爆破完成回传记录. data: %1").arg(QJsonDocument(jsonObj).toJson(QJsonDocument::Indented)));
|
|
|
+ blast_uuid = QUuid::createUuid().toString(QUuid::WithoutBraces).remove(QRegularExpression("-"));
|
|
|
lat = labLat;
|
|
|
lon = labLon;
|
|
|
- qDebug() << "爆破记录"<< QJsonDocument( jsonObj).toJson(QJsonDocument::Indented);
|
|
|
- Logger::getInstance().info("收到爆破完成回传记录");
|
|
|
|
|
|
saveDataToLocalDB(jsonObj);
|
|
|
+ uploadToServer(jsonObj);
|
|
|
|
|
|
- if(lat=="定位失败"&&lat=="未知"&&lon=="定位失败"&&lon=="未知"){
|
|
|
- // 数据出本地 不传丹灵
|
|
|
+ if (lat == "定位失败" && lat == "未知" && lon == "定位失败" && lon == "未知"){
|
|
|
+ QMessageBox::critical(nullptr, "错误", "未获取有效定位数据,数据将暂不上传丹灵");
|
|
|
+ // 数据:存本地 不传丹灵
|
|
|
+ }
|
|
|
+ // TODO location数据如果错误,不提交丹灵
|
|
|
+ // danUpload(jsonObj);
|
|
|
+ // if (db.commit()) {
|
|
|
+ // qDebug() << "Transaction committed successfully.";
|
|
|
+ // } else {
|
|
|
+ // qDebug() << "Failed to commit transaction:" << db.lastError().text();
|
|
|
+ // }
|
|
|
+}
|
|
|
|
|
|
- }
|
|
|
- // danUpload(jsonObj);
|
|
|
- // if (db.commit()) {
|
|
|
- // qDebug() << "Transaction committed successfully.";
|
|
|
- // } else {
|
|
|
- // qDebug() << "Failed to commit transaction:" << db.lastError().text();
|
|
|
- // }
|
|
|
+/*
|
|
|
+ Id int `json:"-" comment:"主键编码"` // 主键编码
|
|
|
+ Uuid string `json:"uuid" comment:""`
|
|
|
+ ProjectName string `json:"project_name" comment:"工程名称"`
|
|
|
+ ProjectHtid string `json:"project_htid" comment:"合同编号"`
|
|
|
+ ProjectXmbh string `json:"project_xmbh" comment:"项目编号"`
|
|
|
+ OperatorName string `json:"operator_name" comment:"操作员"`
|
|
|
+ Phone string `json:"phone" comment:"操作员电话"`
|
|
|
+ OperatorIdentity string `json:"operator_identity" comment:"操作员身份证"`
|
|
|
+ EquipmentSn string `json:"equipment_sn" comment:"设备序列号"`
|
|
|
+ CompanyCode string `json:"company_code" comment:"公司代码"`
|
|
|
+ AppVersion string `json:"app_version" comment:"app版本"`
|
|
|
+ Longitude string `json:"blast_longitude" comment:"经度"`
|
|
|
+ Latitude string `json:"blast_latitude" comment:"纬度"`
|
|
|
+ EquipmentCount string `json:"equipment_count" comment:"设备数量"`
|
|
|
+ RegDetCount string `json:"reg_deto_count" comment:"注册雷管数量"`
|
|
|
+ ErrorDetCount string `json:"error_deto_count" comment:"异常雷管数量"`
|
|
|
+ BlastAt string `json:"blast_time" comment:"爆破时间"`
|
|
|
+ Regs []HBlastRecordEquipmentInsertReq `json:"regs"`
|
|
|
+ WBlasterId string `json:"w_blaster_id"`
|
|
|
+*/
|
|
|
+void firingWidget::uploadToServer(const QJsonObject &jsonObj)
|
|
|
+{
|
|
|
+ // upload blast project
|
|
|
+ // upload blast reg dets
|
|
|
+ // upload blast dets data
|
|
|
}
|
|
|
|
|
|
-void saveDataToLocalDB(const QJsonObject jsonObj) {
|
|
|
+void firingWidget::saveDataToLocalDB(const QJsonObject &jsonObj)
|
|
|
+{
|
|
|
QSqlDatabase db = DatabaseManager::getInstance().getDatabase();
|
|
|
- if (!db.transaction()) {
|
|
|
- qDebug() << "Failed to start transaction:" << db.lastError().text();
|
|
|
+ if (!db.transaction())
|
|
|
+ {
|
|
|
+ Logger::getInstance().critical(QString("Failed to start DB trasaction. Error: %1").arg(db.lastError().text()));
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- HBlastRecord record;
|
|
|
- record.setProjectName(jsonObj["project_name"].toString());
|
|
|
- record.setProjectHtid(jsonObj["project_htid"].toString());
|
|
|
- record.setProjectXmbh(jsonObj["project_xmbh"].toString());
|
|
|
- record.setOperatorName(jsonObj["operator_name"].toString());
|
|
|
- record.setPhone(jsonObj["phone"].toString());
|
|
|
- record.setOperatorIdentity(jsonObj["operator_identity"].toString());
|
|
|
- record.setEquipmentSn(jsonObj["equipment_sn"].toString());
|
|
|
- record.setCompanyCode(jsonObj["company_code"].toString());
|
|
|
- record.setAppVersion(jsonObj["app_version"].toString());
|
|
|
-
|
|
|
- record.setLongitude(jsonObj["blast_longitude"].toString());
|
|
|
- record.setLatitude(jsonObj["blast_latitude"].toString());
|
|
|
-
|
|
|
- //record.setLongitude(lat);
|
|
|
- //record.setLatitude(lon);
|
|
|
- record.setRegDetCount(jsonObj["reg_deto_count"].toString().toInt());
|
|
|
- record.setErrorDetCount(jsonObj["error_deto_count"].toString().toInt());
|
|
|
- QDateTime blastTime = QDateTime::fromString(jsonObj["blast_time"].toString(), "yyyy-MM-dd hh:mm:ss +08:00");
|
|
|
- blastTime.setTimeZone(QTimeZone(QByteArrayLiteral("Asia/Shanghai")));
|
|
|
- record.setBlastAt(blastTime);
|
|
|
- record.setCreatedAt(QDateTime::currentDateTime());
|
|
|
- qDebug() << "currentDateTime."<<QDateTime::currentDateTime();
|
|
|
- record.setUuid(blast_uuid);
|
|
|
-
|
|
|
- if (dao.addHBlastRecord(record)) {
|
|
|
- qDebug() << "Record inserted successfully.";
|
|
|
- }else{
|
|
|
- qDebug() << "Failed to insert record.";
|
|
|
- }
|
|
|
-
|
|
|
- if (!addRegRecords(jsonObj)) {
|
|
|
- if (db.rollback()) {
|
|
|
- qDebug() << "Transaction rolled back successfully.";
|
|
|
- } else {
|
|
|
- qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
- }
|
|
|
- }
|
|
|
- if (!recordDetUsages(jsonObj)) {
|
|
|
- qDebug() << "Insert failed for UID:"; // 假设 record 有 uid 成员
|
|
|
- if (db.rollback()) {
|
|
|
- qDebug() << "Transaction rolled back successfully.";
|
|
|
- } else {
|
|
|
- qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- db.commit();
|
|
|
+ if (!recordBlastData(jsonObj))
|
|
|
+ {
|
|
|
+ if (db.rollback())
|
|
|
+ {
|
|
|
+ qDebug() << "Transaction rolled back successfully.";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!recordBlastReg(jsonObj))
|
|
|
+ {
|
|
|
+ if (db.rollback())
|
|
|
+ {
|
|
|
+ qDebug() << "Transaction rolled back successfully.";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!recordDetsData(jsonObj))
|
|
|
+ {
|
|
|
+ qDebug() << "Insert failed for UID:"; // 假设 record 有 uid 成员
|
|
|
+ if (db.rollback())
|
|
|
+ {
|
|
|
+ qDebug() << "Transaction rolled back successfully.";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ db.commit();
|
|
|
+}
|
|
|
|
|
|
+HBlastRecord* firingWidget::recordBlastData(const QJsonObject &jsonObj)
|
|
|
+{
|
|
|
+ HBlastRecord record;
|
|
|
+ record.setProjectName(jsonObj["project_name"].toString());
|
|
|
+ record.setProjectHtid(jsonObj["project_htid"].toString());
|
|
|
+ record.setProjectXmbh(jsonObj["project_xmbh"].toString());
|
|
|
+ record.setOperatorName(jsonObj["operator_name"].toString());
|
|
|
+ record.setPhone(jsonObj["phone"].toString());
|
|
|
+ record.setOperatorIdentity(jsonObj["operator_identity"].toString());
|
|
|
+ record.setEquipmentSn(jsonObj["equipment_sn"].toString());
|
|
|
+ record.setCompanyCode(jsonObj["company_code"].toString());
|
|
|
+ record.setAppVersion(jsonObj["app_version"].toString());
|
|
|
+
|
|
|
+ record.setLongitude(jsonObj["blast_longitude"].toString());
|
|
|
+ record.setLatitude(jsonObj["blast_latitude"].toString());
|
|
|
+
|
|
|
+ // record.setLongitude(lat);
|
|
|
+ // record.setLatitude(lon);
|
|
|
+ record.setRegDetCount(jsonObj["reg_deto_count"].toString().toInt());
|
|
|
+ record.setErrorDetCount(jsonObj["error_deto_count"].toString().toInt());
|
|
|
+ QDateTime blastTime = QDateTime::fromString(jsonObj["blast_time"].toString(), "yyyy-MM-dd hh:mm:ss +08:00");
|
|
|
+ blastTime.setTimeZone(QTimeZone(QByteArrayLiteral("Asia/Shanghai")));
|
|
|
+ record.setBlastAt(blastTime);
|
|
|
+ record.setCreatedAt(QDateTime::currentDateTime());
|
|
|
+ qDebug() << "currentDateTime." << QDateTime::currentDateTime();
|
|
|
+ record.setUuid(blast_uuid);
|
|
|
+
|
|
|
+ if (dao.addHBlastRecord(record))
|
|
|
+ {
|
|
|
+ qDebug() << "Record inserted successfully.";
|
|
|
+ return &record;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ qDebug() << "Failed to insert record.";
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool firingWidget::recordDetsData(const QJsonObject &jsonObj)
|
|
|
+{
|
|
|
+ QJsonArray regsArray = jsonObj["regs"].toArray();
|
|
|
+ for (const auto ®Value : regsArray)
|
|
|
+ {
|
|
|
+ QJsonObject regObj = regValue.toObject();
|
|
|
+ QJsonArray detsArray = regObj["dets"].toArray();
|
|
|
+ for (const auto &detValue : detsArray)
|
|
|
+ {
|
|
|
+ QJsonObject detObj = detValue.toObject();
|
|
|
+ HBlastRecordDet recordDet;
|
|
|
+
|
|
|
+ recordDet.setId(0);
|
|
|
+ recordDet.setUuid(QUuid::createUuid().toString(QUuid::WithoutBraces).remove(QRegularExpression("-")));
|
|
|
+ recordDet.setOutCode(detObj["out_code"].toString());
|
|
|
+ recordDet.setInnerCode(detObj["in_code"].toString());
|
|
|
+ recordDet.setUid(detObj["uid"].toString());
|
|
|
+ recordDet.setStatus(detObj["status"].toString());
|
|
|
+ recordDet.setFreq(detObj["freq"].toString());
|
|
|
+ recordDet.setDelayTime(detObj["delay_time"].toString());
|
|
|
+ recordDet.setTag(detObj["tag"].toString());
|
|
|
+ recordDet.setCreatedAt(QDateTime::currentDateTime());
|
|
|
+ recordDet.setBlastRecordId(blast_uuid);
|
|
|
+ recordDet.setRegId(reg_uuid);
|
|
|
+ recordDet.setCreatedAt(QDateTime::currentDateTime());
|
|
|
+ if (!daoDet.addHBlastRecordDet(recordDet))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|