From 1d1c1f4137b52033a57e97d55b5b27bfa6293e8f Mon Sep 17 00:00:00 2001 From: sunwen Date: Wed, 26 Jun 2024 10:36:15 +0800 Subject: [PATCH] feat: Change getDmsVersion action form sync action to async action. --- src/device/DeviceManager.cpp | 42 +++++++++++++++++--------------- src/device/DeviceManager.h | 5 ++-- src/forms/settings/AboutForm.cpp | 17 ++++++++----- src/forms/settings/AboutForm.h | 2 ++ 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/device/DeviceManager.cpp b/src/device/DeviceManager.cpp index 673b144..b1f8b0a 100644 --- a/src/device/DeviceManager.cpp +++ b/src/device/DeviceManager.cpp @@ -39,6 +39,7 @@ namespace const int CHECK_RECON_CONNECTION_TIME = 30000; const int SHUT_DOWN_TIMEOUT = 180000;//3 minitues const int PUMP_TIMEOUT = 3000;//3 seconds + const int GETDMSVERSION_TIMEOUT = 5000; const int EFFECTIVE_POSITION_RADIUS = 125; const int EFFECTIVE_POSITION_Z_START = 150; const int EFFECTIVE_POSITION_Z_END = 225; @@ -88,13 +89,6 @@ QString getFullScanJson(QObject* obj) void DeviceManager::initDevice() { - if(!AppGlobalValues::DBconnected().toBool()) - { - emitErrorCallback(tr("Fail to connect to DB!Reboot device to try!")); - emit initializeFinished(); - return; - } - mReconTransferPath = JsonObject::Instance()->getReconTransferPath(); dmsmq_init(0); @@ -140,7 +134,6 @@ void DeviceManager::initDevice() mStartAutoLocateAction = new DmsSyncAction(USRV_CONTROL, ACT_CTL_MOTION_START, this, "responseStartAutoLocate(const QString&)", this); mStopAutoLocateAction = new DmsSyncAction(USRV_CONTROL, ACT_CTL_MOTION_STOP, this, "responseStopAutoLocate(const QString&)", this); mCheckDataQualityAction = new DmsSyncAction(USRV_SCAN, ACT_SCAN_IMGQUALITI, this, "responseCheckDataQuality(const QString&)", this); - mGetSoftwareVersionAction = new DmsSyncAction(USRV_INFOCFG, ACT_IFCFG_VERINFO, this,"responseGetSoftwareVersion(const QString&)", this); //Async action mGetScanProgressAction = new DmsAsyncAction(USRV_SCAN, ACT_SCAN_PROGRESS_PASSIVE, this,"responseGetScanProgress(const QString&)", this); @@ -151,6 +144,12 @@ void DeviceManager::initDevice() mPumpControlAction = new DmsAsyncAction(USRV_CONTROL, ACT_CTL_PUMP, this, "responsePumpControl(const QString&)", this); mPumpControlAction->setTimeoutInterval(PUMP_TIMEOUT); mGetAutoLocatePositionAction = new DmsAsyncAction(USRV_CONTROL, ACT_CTL_MOTION_POSITION, this, "responseGetAutoLocatePosition(const QString&)", this); + mGetSoftwareVersionAction = new DmsAsyncAction(USRV_INFOCFG, ACT_IFCFG_VERINFO, this,"responseGetSoftwareVersion(const QString&)", this); + mGetSoftwareVersionAction->setTimeoutInterval(GETDMSVERSION_TIMEOUT); + connect(mGetSoftwareVersionAction, &DmsAsyncAction::timeout, [this]() + { + emit getDmsVersionResponsed("DMS Version Fetch Error"); + }); connect(mPumpControlAction, &DmsAsyncAction::timeout, [this]() { this->processPumpResult("{\"code\":-1}"); @@ -215,14 +214,21 @@ void DeviceManager::initDevice() mSetHeartBeatAction->setSendData("{ \"code\":0, \"info\":\"0\"}"); mSetHeartBeatAction->execute(); - - initDmsVersion(); + mSoftwareVersion = "DMS Version Loading"; + mGetSoftwareVersionAction->execute(); mCheckInitStatusTimer = startTimer(500); } void DeviceManager::initGUI(bool aIsInitSucceed) { + if(!AppGlobalValues::DBconnected().toBool()) + { + emitErrorCallback(tr("Fail to connect to DB!Reboot device to try!")); + emit initializeFinished(); + return; + } + if(aIsInitSucceed) { if(getDeviceStatus() != DeviceStatus::Rready) @@ -714,6 +720,7 @@ void DeviceManager::processReceiveDMSInfoResult(int aServerID, int aActionID, co { case ACT_IFCFG_VERINFO : emit responseGetSoftwareVersion(aContents); + processGetSoftwareVersion(aContents); break; case ACT_IFCFG_HBCFG : emit responseSetHeartBeat(aContents); @@ -779,18 +786,15 @@ void DeviceManager::processAlarm(const QString& aAlarm) } } -void DeviceManager::initDmsVersion() +void DeviceManager::processGetSoftwareVersion(const QString& aSoftwareVersion) { - DmsSyncActionResult result = mGetSoftwareVersionAction->execute(); - QJsonObject jsonObj = toJsonObject(result.mData); - if(result.mIsSucessful && jsonObj.contains("code") && jsonObj["code"].toInt() == 0) + QJsonObject jsonObj = toJsonObject(aSoftwareVersion); + if(jsonObj["code"].toInt() != 0) { - mSoftwareVersion = jsonObj["info"].toString();; - } - else - { - mSoftwareVersion = "Dms Fetch Error"; + mSoftwareVersion = "DMS Version Fetch Error"; } + mSoftwareVersion = jsonObj["info"].toString(); + emit getDmsVersionResponsed(mSoftwareVersion); } void DeviceManager::scanTimeout() diff --git a/src/device/DeviceManager.h b/src/device/DeviceManager.h index 34647b9..3e50faf 100644 --- a/src/device/DeviceManager.h +++ b/src/device/DeviceManager.h @@ -112,7 +112,6 @@ private: void stopAutoLocate(); void initGUI(bool aIsInitSucceed); void checkDataQuality(); - void initDmsVersion(); void processScanProgress(const QString& aProgress); void processAutoLocatePosition(const QString& aProgress); @@ -125,6 +124,7 @@ private: void processTransferProgress(const QString& aProgress); void processShutDownDms(const QString& aResponse); void processPumpResult(const QString& aResponse); + void processGetSoftwareVersion(const QString& aResponse); void insertEmptyScanRecord(); void insertScanRecord(); @@ -184,6 +184,7 @@ signals: void autolocatePositionEffective(); void shutdownDmsSended(); void shutdownDmsFailed(); + void getDmsVersionResponsed(const QString& aDmsVersion); private: @@ -229,7 +230,6 @@ private: DmsSyncAction* mStartAutoLocateAction = nullptr; DmsSyncAction* mStopAutoLocateAction = nullptr; DmsSyncAction* mCheckDataQualityAction = nullptr; - DmsSyncAction* mGetSoftwareVersionAction = nullptr; DmsAsyncAction* mGetDeviceTemperatureAction = nullptr; DmsAsyncAction* mGetScanProgressAction = nullptr; @@ -237,6 +237,7 @@ private: DmsAsyncAction* mShutDownAction = nullptr; DmsAsyncAction* mPumpControlAction = nullptr; DmsAsyncAction* mGetAutoLocatePositionAction = nullptr; + DmsAsyncAction* mGetSoftwareVersionAction = nullptr; InfoReceiveWorker* mInfoReceiveWorker = nullptr; diff --git a/src/forms/settings/AboutForm.cpp b/src/forms/settings/AboutForm.cpp index 19c12b3..2095451 100644 --- a/src/forms/settings/AboutForm.cpp +++ b/src/forms/settings/AboutForm.cpp @@ -20,7 +20,8 @@ AboutForm::AboutForm(QWidget* aParent) : QWidget(aParent) -,mReconSotfVer( new QLabel(this)) + , mReconSotfVer( new QLabel(this)) + , mDmsVersion(new QLabel(this)) { initUiWidget(); mReconSotfVer->setSizePolicy(QSizePolicy::Policy::Expanding,QSizePolicy::Policy::Expanding); @@ -47,7 +48,6 @@ void AboutForm::initUiWidget() QPushButton* pBtnHelp; QLabel* pCompanyCopyRight; QLabel* pMainVer; - QLabel* pEmbededSoftVer; QLabel* pFEBVer; QLabel* pQtVer; QLabel* pQtCopyright; @@ -94,9 +94,8 @@ void AboutForm::initUiWidget() pMainVer->setText(QString(tr("USCT Software V0.1.0"))); pMainLayout->addWidget(pMainVer); - pEmbededSoftVer = new QLabel(this); - pEmbededSoftVer->setText(DeviceManager::Default()->getSoftwareVersion()); - pMainLayout->addWidget(pEmbededSoftVer); + mDmsVersion->setText(DeviceManager::Default()->getSoftwareVersion()); + pMainLayout->addWidget(mDmsVersion); mReconSotfVer->setText(tr("Reconstruction Software Loading...")); @@ -150,6 +149,7 @@ void AboutForm::initUiWidget() QMetaObject::invokeMethod(ReconManager::getInstance(), "getReconVersion", Qt::QueuedConnection); connect(ReconManager::getInstance(), &ReconManager::getReconVersionResponsed,this,&AboutForm::setReconVersion,Qt::QueuedConnection); + connect(DeviceManager::Default(), &DeviceManager::getDmsVersionResponsed,this,&AboutForm::setDmsVersion,Qt::QueuedConnection); connect(pBtnHelp, SIGNAL(clicked()), this, SLOT(openHelpFile())); connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() { @@ -157,7 +157,7 @@ void AboutForm::initUiWidget() pBtnHelp->setText(tr("?")); pCompanyCopyRight->setText(tr("Copyright © 2017-2020 Zhejiang Equilibrium Nine Medical Equipment Co., Ltd. All Rights Reversed")); pMainVer->setText(QString(tr("GUI Software V%1")).arg(getGUIVersion())); - pEmbededSoftVer->setText(tr("Embedded Software %1").arg(getEmbVersion())); + mDmsVersion->setText(tr("Embedded Software %1").arg(getEmbVersion())); mReconSotfVer->setText(tr("Reconstruction Software V1.2")); pFEBVer->setText(tr("FEB Information")); }); @@ -187,3 +187,8 @@ QString AboutForm::getEmbVersion() { return DeviceManager::Default()->getSoftwareVersion(); } + +void AboutForm::setDmsVersion(const QString& aVersion) +{ + mDmsVersion->setText(aVersion); +} diff --git a/src/forms/settings/AboutForm.h b/src/forms/settings/AboutForm.h index 9775e12..fe8c4ae 100644 --- a/src/forms/settings/AboutForm.h +++ b/src/forms/settings/AboutForm.h @@ -23,10 +23,12 @@ public: private slots: void openHelpFile(); void setReconVersion(const QString& version); + void setDmsVersion(const QString& aVersion); private: void initUiWidget(); QLabel* mReconSotfVer; + QLabel* mDmsVersion; };