refactor: Scan process.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QProcess>
|
||||
#include <QtMath>
|
||||
#include <qdebug.h>
|
||||
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
@@ -22,6 +23,7 @@
|
||||
#include "recon/ReconManager.h"
|
||||
#include "dialogs/MultyMessageDialog.h"
|
||||
#include "UsctStateManager.h"
|
||||
#include "utilities/ScanProcessSequence.h"
|
||||
|
||||
#define TRIGGER_EVENT EventCenter::Default()->triggerEvent
|
||||
|
||||
@@ -36,6 +38,9 @@ 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 EFFECTIVE_POSITION_RADIUS = 125;
|
||||
const int EFFECTIVE_POSITION_Z_START = 150;
|
||||
const int EFFECTIVE_POSITION_Z_END = 225;
|
||||
const QString DEFAULT_DMS_START_FAILED = "Dms start failed.";
|
||||
const QString RECON_TRANSFER_PATH = "/home/krad/TestStore";
|
||||
|
||||
@@ -113,6 +118,9 @@ void DeviceManager::initDevice()
|
||||
{
|
||||
controlDrainage(*(QString*)detail);
|
||||
});
|
||||
//AutoLocate
|
||||
connect(EventCenter::Default(), &EventCenter::StartScanProcess, this, &DeviceManager::startAutoLocate);
|
||||
connect(EventCenter::Default(), &EventCenter::StopScanProcess, this, &DeviceManager::stopAutoLocate);
|
||||
|
||||
//Sync action
|
||||
mGetDeviceStatusAction = new DmsSyncAction(USRV_SCAN, ACT_SCAN_STATUS, this, "responseGetDeviceStatus(const QString&)", this);
|
||||
@@ -126,6 +134,9 @@ void DeviceManager::initDevice()
|
||||
mSetSimulatorModeAction = new DmsSyncAction(USRV_SCAN, ACT_SCAN_SIMULATOR, this, "responseSetSimulatorMode(const QString&)", this);
|
||||
mSetHeartBeatAction = new DmsSyncAction(USRV_INFOCFG, ACT_IFCFG_HBCFG, this, "responseSetHeartBeat(const QString&)", this);
|
||||
mCheckInitStatusAction = new DmsSyncAction(USRV_INFOCFG, ACT_IFCFG_INIT_STATUS, this, "responseCheckInitStatus(const QString&)", this);
|
||||
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);
|
||||
|
||||
//Async action
|
||||
mGetScanProgressAction = new DmsAsyncAction(USRV_SCAN, ACT_SCAN_PROGRESS_PASSIVE, this,"responseGetScanProgress(const QString&)", this);
|
||||
@@ -136,12 +147,24 @@ void DeviceManager::initDevice()
|
||||
mShutDownAction->setTimeoutInterval(SHUT_DOWN_TIMEOUT);
|
||||
mPumpControlAction = new DmsAsyncAction(USRV_CONTROL, ACT_CTL_PUMP, this, "responsePumpControl(const QString&)", this);
|
||||
mPumpControlAction->setTimeoutInterval(PUMP_TIMEOUT);
|
||||
connect(mPumpControlAction, &DmsAsyncAction::timeout, this, [this]()
|
||||
mGetAutoLocatePositionAction = new DmsAsyncAction(USRV_CONTROL, ACT_CTL_MOTION_POSITION, this, "responseGetAutoLocatePosition(const QString&)", this);
|
||||
connect(mPumpControlAction, &DmsAsyncAction::timeout, [this]()
|
||||
{
|
||||
this->processPumpResult("{\"code\":-1}");
|
||||
});
|
||||
connect(mGetScanProgressAction, &DmsAsyncAction::timeout, this, &DeviceManager::scanTimeout);
|
||||
connect(mShutDownAction, &DmsAsyncAction::timeout, this, &DeviceManager::shutdownDmsFailed);
|
||||
connect(mGetAutoLocatePositionAction, &DmsAsyncAction::timeout, [this]()
|
||||
{
|
||||
if(mGetAutoLocatePositionTimer != -1)
|
||||
{
|
||||
this->killTimer(mGetAutoLocatePositionTimer);
|
||||
mGetAutoLocatePositionTimer = -1;
|
||||
}
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
QString errorMessage = tr("DMS connection error");
|
||||
THROW_ERROR(errorMessage)
|
||||
});
|
||||
|
||||
|
||||
//dmsInfoReceiverThread
|
||||
@@ -200,7 +223,6 @@ void DeviceManager::initGUI(bool aIsInitSucceed)
|
||||
}
|
||||
else
|
||||
{
|
||||
UsctStateManager::getInstance()->setState(DmsState, false);
|
||||
emit initializeProgress("33");
|
||||
QThread::msleep(500);
|
||||
emit initializeProgress("66");
|
||||
@@ -316,19 +338,26 @@ void DeviceManager::processScanProgress(const QString& aProgress)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
QVariant var(QString("progress:%1%").arg(msg));
|
||||
QVariant var(tr("progress:%1%").arg(msg));
|
||||
TRIGGER_EVENT(InvokeOperationProgress, nullptr, (QObject *) &var);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
QVariant var( (mIsEmptyScan ? QString("") : tr("Patient can leave.\n")) + QString("progress:%1%").arg(msg));
|
||||
ScanProcessSequence::getInstance()->fullScanDataExport();
|
||||
QVariant var( (mIsEmptyScan ? QString("") : tr("Patient can leave.\nprogress:%1%")).arg(msg));
|
||||
TRIGGER_EVENT(InvokeOperationProgress, nullptr, (QObject *) &var);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
prepareFinishScan(true);
|
||||
{
|
||||
QVariant var( tr("Data quality assessment in progress\nprogress:99%"));
|
||||
TRIGGER_EVENT(InvokeOperationProgress, nullptr, (QObject *) &var);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
checkDataQuality();
|
||||
break;
|
||||
default:
|
||||
prepareFinishScan(false, msg);
|
||||
break;
|
||||
@@ -356,6 +385,7 @@ void DeviceManager::prepareFinishScan(bool isNormalFinish, const QString& aReaso
|
||||
if(!isNormalFinish)
|
||||
{
|
||||
TRIGGER_EVENT(InvokeOperationEnd, nullptr, var);
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -384,6 +414,11 @@ void DeviceManager::prepareFinishScan(bool isNormalFinish, const QString& aReaso
|
||||
{
|
||||
TRIGGER_EVENT(EmptyScanFinished, nullptr, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
ScanProcessSequence::getInstance()->popPosition();
|
||||
startAutoLocate();
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::prepareFinishInitialize()
|
||||
@@ -435,12 +470,8 @@ void DeviceManager::stopPreviewScan()
|
||||
AppGlobalValues::setInProcessing(false);
|
||||
}
|
||||
|
||||
void DeviceManager::close() {
|
||||
// #ifdef _WIN32
|
||||
// StopDevice();
|
||||
// #endif
|
||||
// mPreviewDataCaller->terminate();
|
||||
// delete mPreviewDataCaller;
|
||||
void DeviceManager::close()
|
||||
{
|
||||
}
|
||||
|
||||
void DeviceManager::processPreviewData(const QString& aPreviewData)
|
||||
@@ -547,23 +578,31 @@ void DeviceManager::checkInitStatus()
|
||||
|
||||
void DeviceManager::timerEvent(QTimerEvent* event)
|
||||
{
|
||||
if (event->timerId() == mTemperatureTimer)
|
||||
{
|
||||
getDeviceTemperature();
|
||||
return QObject::timerEvent(event);
|
||||
}
|
||||
|
||||
if(event->timerId() == mScanProgressTimer)
|
||||
{
|
||||
getScanProcess();
|
||||
return QObject::timerEvent(event);
|
||||
}
|
||||
|
||||
if(event->timerId() == mGetAutoLocatePositionTimer)
|
||||
{
|
||||
getAutoLocatePosition();
|
||||
return QObject::timerEvent(event);
|
||||
}
|
||||
|
||||
if(event->timerId() == mCheckInitStatusTimer)
|
||||
{
|
||||
checkInitStatus();
|
||||
return QObject::timerEvent(event);
|
||||
}
|
||||
|
||||
if (event->timerId() == mTemperatureTimer)
|
||||
{
|
||||
getDeviceTemperature();
|
||||
return QObject::timerEvent(event);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DeviceManager::emitErrorCallback(const char *msg)
|
||||
@@ -629,6 +668,8 @@ void DeviceManager::processReceiveDMSInfoResult(int aServerID, int aActionID, co
|
||||
case ACT_SCAN_SIMULATOR:
|
||||
emit responseSetSimulatorMode(aContents);
|
||||
break;
|
||||
case ACT_SCAN_IMGQUALITI:
|
||||
emit responseCheckDataQuality(aContents);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -686,6 +727,16 @@ void DeviceManager::processReceiveDMSInfoResult(int aServerID, int aActionID, co
|
||||
emit responseShutDown(aContents);
|
||||
processShutDownDms(aContents);
|
||||
break;
|
||||
case ACT_CTL_MOTION_START:
|
||||
emit responseStartAutoLocate(aContents);
|
||||
break;
|
||||
case ACT_CTL_MOTION_STOP:
|
||||
emit responseStopAutoLocate(aContents);
|
||||
break;
|
||||
case ACT_CTL_MOTION_POSITION:
|
||||
emit responseGetAutoLocatePosition(aContents);
|
||||
processAutoLocatePosition(aContents);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -1202,3 +1253,108 @@ void DeviceManager::updateReconConnectionState(bool aIsConnected)
|
||||
{
|
||||
EventCenter::Default()->triggerEvent(ReconConnectionUpdated, nullptr, (QObject*)&aIsConnected);
|
||||
}
|
||||
|
||||
bool DeviceManager::startAutoLocate()
|
||||
{
|
||||
if(ScanProcessSequence::getInstance()->getScanPositionSize() == 0)
|
||||
{
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
return false;
|
||||
}
|
||||
auto result = mStartAutoLocateAction->execute();
|
||||
if(result.mIsSucessful)
|
||||
{
|
||||
mIsAutoLocating = true;
|
||||
QJsonObject jsonObj = toJsonObject(result.mData);
|
||||
if(jsonObj["code"].toInt() == 0 )
|
||||
{
|
||||
emit startAutoLocateResult(true);
|
||||
mGetAutoLocatePositionTimer = startTimer(1000);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
stopAutoLocate();
|
||||
}
|
||||
}
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
QString errorMessage = tr("Start auto locate failed");
|
||||
THROW_ERROR(errorMessage)
|
||||
return false;
|
||||
}
|
||||
|
||||
void DeviceManager::stopAutoLocate()
|
||||
{
|
||||
if(mIsAutoLocating)
|
||||
{
|
||||
mStopAutoLocateAction->execute();
|
||||
mIsAutoLocating = false;
|
||||
}
|
||||
if(mGetAutoLocatePositionTimer != -1)
|
||||
{
|
||||
killTimer(mGetAutoLocatePositionTimer);
|
||||
mGetAutoLocatePositionTimer = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::getAutoLocatePosition()
|
||||
{
|
||||
mGetAutoLocatePositionAction->execute();
|
||||
}
|
||||
|
||||
void DeviceManager::processAutoLocatePosition(const QString& aProgress)
|
||||
{
|
||||
QJsonObject jsonObj = toJsonObject(aProgress);
|
||||
int code = jsonObj["code"].toInt();
|
||||
int x = jsonObj["x"].toInt();
|
||||
int y = jsonObj["y"].toInt();
|
||||
int z = jsonObj["z"].toInt();
|
||||
if(code == 0)
|
||||
{
|
||||
if(qSqrt(x*x + y*y)<EFFECTIVE_POSITION_RADIUS && z > EFFECTIVE_POSITION_Z_START && z< EFFECTIVE_POSITION_Z_END)
|
||||
{
|
||||
if(++mEffectivePositionCount >= 5)
|
||||
{
|
||||
mEffectivePositionCount = 0;
|
||||
stopAutoLocate();
|
||||
emit autolocatePositionEffective();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mEffectivePositionCount = 0;;
|
||||
}
|
||||
emit updateAutoLocatePosition(x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
QString errorMessage = tr("Start auto locate failed");
|
||||
THROW_ERROR(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::checkDataQuality()
|
||||
{
|
||||
auto result = mCheckDataQualityAction->execute();
|
||||
if(result.mIsSucessful)
|
||||
{
|
||||
QJsonObject jsonObj = toJsonObject(result.mData);
|
||||
if(jsonObj["qualities"].toInt() == 1 )
|
||||
{
|
||||
prepareFinishScan(true);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString errorMessage = tr("The data quality is low, please restart the data scan.") + jsonObj["info"].toString();
|
||||
prepareFinishScan(false, errorMessage);
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
QString errorMessage = tr("Dms connection error");
|
||||
prepareFinishScan(false, errorMessage);
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user