diff --git a/src/device/DeviceManager.h b/src/device/DeviceManager.h index 42519ed..661039d 100644 --- a/src/device/DeviceManager.h +++ b/src/device/DeviceManager.h @@ -209,6 +209,7 @@ private: DmsAsyncAction* mStopTransferAction = nullptr; DmsAsyncAction* mShutDownAction = nullptr; + friend class InfoReceiveWorker; }; diff --git a/src/device/DmsAsyncAction.cpp b/src/device/DmsAsyncAction.cpp index 75f9f23..6439962 100644 --- a/src/device/DmsAsyncAction.cpp +++ b/src/device/DmsAsyncAction.cpp @@ -50,3 +50,8 @@ void DmsAsyncAction::setTimeoutInterval(int aMsec) { mTimer->setInterval(aMsec); } + +void DmsAsyncAction::responsed() +{ + mTimer->stop(); +} diff --git a/src/device/DmsAsyncAction.h b/src/device/DmsAsyncAction.h index 0077ae2..b366b16 100644 --- a/src/device/DmsAsyncAction.h +++ b/src/device/DmsAsyncAction.h @@ -27,6 +27,7 @@ public: bool execute(); void setSendData(const QString& aData); void setTimeoutInterval(int aMsec); + void responsed(); signals: void timeout(); diff --git a/src/device/DmsSyncAction.cpp b/src/device/DmsSyncAction.cpp index 2891df6..531e8bd 100644 --- a/src/device/DmsSyncAction.cpp +++ b/src/device/DmsSyncAction.cpp @@ -3,7 +3,7 @@ #include #include -#include + namespace { const int TIMEOUT_MSEC = 500; @@ -20,10 +20,12 @@ DmsSyncAction::DmsSyncAction(int aServerId, int aActionId, QObject* aObject, con , mTimeoutMsec(TIMEOUT_MSEC) , mSendData() , mActionResult() + , mIsTimeout(false) { mTimer->setSingleShot(true); connect(mObject, ("2" + mSignal).toStdString().c_str(), this, SLOT(saveActionResult(const QString&))); connect(mObject, ("2" + mSignal).toStdString().c_str(), mLoop, SLOT(quit())); + connect(mTimer, &QTimer::timeout, this, &DmsSyncAction::responsed); connect(mTimer, &QTimer::timeout, mLoop, &QEventLoop::quit); } @@ -31,6 +33,7 @@ DmsSyncAction::~DmsSyncAction() { disconnect(mObject, ("2" + mSignal).toStdString().c_str(), mLoop, SLOT(quit())); disconnect(mObject, ("2" + mSignal).toStdString().c_str(), this, SLOT(saveActionResult(const QString&))); + disconnect(mTimer, &QTimer::timeout, this, &DmsSyncAction::responsed); disconnect(mTimer, &QTimer::timeout, mLoop, &QEventLoop::quit); } @@ -65,10 +68,22 @@ bool DmsSyncAction::waitUntilSignalReceived() { mTimer->start(mTimeoutMsec); mLoop->exec(); - if(!mTimer->isActive()) + if(mIsTimeout) { return false; } - mTimer->stop(); return true; } + +void DmsSyncAction::responsed() +{ + if(mTimer->isActive()) + { + mTimer->stop(); + mIsTimeout = false; + } + else + { + mIsTimeout = true; + } +} diff --git a/src/device/DmsSyncAction.h b/src/device/DmsSyncAction.h index 658f89b..169060f 100644 --- a/src/device/DmsSyncAction.h +++ b/src/device/DmsSyncAction.h @@ -26,6 +26,7 @@ public: DmsSyncActionResult execute(); void setSendData(const QString& aData); + void responsed(); private slots: void saveActionResult(const QString& aResult); @@ -43,6 +44,7 @@ private: int mTimeoutMsec; QString mSendData; QString mActionResult; + bool mIsTimeout; }; #endif // DMSSYNCACTION_H diff --git a/src/device/InfoReceiveWorker.cpp b/src/device/InfoReceiveWorker.cpp index 5613ae7..37e2d0d 100644 --- a/src/device/InfoReceiveWorker.cpp +++ b/src/device/InfoReceiveWorker.cpp @@ -1,4 +1,7 @@ #include "InfoReceiveWorker.h" +#include "DeviceManager.h" +#include "DmsAsyncAction.h" +#include "DmsSyncAction.h" #include "dms_mq.h" #include "daq_define.h" @@ -17,6 +20,7 @@ void InfoReceiveWorker::startListen() for(;;) { count = dmsmq_recv(&serverID, &actionID,data); + responsed(serverID, actionID); if(count >= 0) { uint8_t* copyData = data; @@ -26,3 +30,82 @@ void InfoReceiveWorker::startListen() } } } + +void InfoReceiveWorker::responsed(int aServerID, int aActionID) +{ + switch(aServerID) + { + case USRV_SCAN : + switch(aActionID) + { + case ACT_SCAN_STATUS : + DeviceManager::Default()->mGetDeviceStatusAction->responsed(); + break; + case ACT_SCAN_FULLSCAN : + DeviceManager::Default()->mFullScanAction->responsed(); + break; + case ACT_SCAN_PREVIEW: + DeviceManager::Default()->mPreviewScanAction->responsed(); + break; + case ACT_SCAN_TEMP : + DeviceManager::Default()->mGetDeviceTemperatureAction->responsed(); + break; + case ACT_SCAN_PROGRESS_PASSIVE : + DeviceManager::Default()->mGetScanProgressAction->responsed(); + break; + case ACT_SCAN_STOP : + DeviceManager::Default()->mStopScanAction->responsed(); + break; + case ACT_SCAN_CE : + DeviceManager::Default()->mCEScanAction->responsed(); + break; + case ACT_SCAN_CE_STATUS : + DeviceManager::Default()->mGetCEStatusAction->responsed(); + break; + case ACT_SCAN_SIMULATOR: + DeviceManager::Default()->mSetSimulatorModeAction->responsed(); + break; + default: + break; + } + break; + case USRV_XFR : + switch(aActionID) + { + case ACT_XFR_START : + DeviceManager::Default()->mTransferAction->responsed(); + break; + case ACT_XFR_STOP : + DeviceManager::Default()->mStopTransferAction->responsed(); + break; + case ACT_XFR_PROGRESS_PASSIVE : + DeviceManager::Default()->mGetTransferProgressAction->responsed(); + break; + } + break; + case USRV_INFOCFG: + switch(aActionID) + { + case ACT_IFCFG_VERINFO : + DeviceManager::Default()->mGetSoftwareVersionAction->responsed(); + break; + case ACT_IFCFG_HBCFG : + DeviceManager::Default()->mSetHeartBeatAction->responsed(); + break; + } + break; + case USRV_CONTROL: + switch(aActionID) + { + case ACT_CTL_PUMP: + DeviceManager::Default()->mPumpControlAction->responsed(); + break; + case ACT_CTL_PWRDOWN: + DeviceManager::Default()->mShutDownAction->responsed(); + break; + } + break; + default: + break; + } +} diff --git a/src/device/InfoReceiveWorker.h b/src/device/InfoReceiveWorker.h index e1f9de5..12f5be1 100644 --- a/src/device/InfoReceiveWorker.h +++ b/src/device/InfoReceiveWorker.h @@ -16,6 +16,9 @@ public slots: signals: void infoReceived(int aServerID, int aActionID, const QString& aContents); +private: + void responsed(int aServerID, int aActionID); + }; #endif // INFORECEIVEWORKER_H