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;
|
||||
}
|
||||
|
||||
@@ -99,15 +99,20 @@ private:
|
||||
void stopPreviewScan();
|
||||
void getDeviceTemperature();
|
||||
void getScanProcess();
|
||||
void getAutoLocatePosition();
|
||||
bool getCEStatus();
|
||||
bool startCEScan();
|
||||
void startTransfer();
|
||||
void initEmptyScanMeasurementID();
|
||||
void controlDrainage(const QString& aCode);
|
||||
void checkInitStatus();
|
||||
bool startAutoLocate();
|
||||
void stopAutoLocate();
|
||||
void initGUI(bool aIsInitSucceed);
|
||||
void checkDataQuality();
|
||||
|
||||
void processScanProgress(const QString& aProgress);
|
||||
void processAutoLocatePosition(const QString& aProgress);
|
||||
void processInitializeProgress(const QString& aProgress);
|
||||
void prepareFinishScan(bool isNormalFinish, const QString& aReason = "");
|
||||
void prepareFinishInitialize();
|
||||
@@ -155,6 +160,10 @@ signals:
|
||||
void responseStopTransfer(const QString& aResponse);
|
||||
void responseShutDown(const QString& aResponse);
|
||||
void responseCheckInitStatus(const QString& aResponse);
|
||||
void responseStartAutoLocate(const QString& aResponse);
|
||||
void responseStopAutoLocate(const QString& aResponse);
|
||||
void responseGetAutoLocatePosition(const QString& aResponse);
|
||||
void responseCheckDataQuality(const QString& aResponse);
|
||||
//Recon
|
||||
void createEmptyScanToRecon(const QString& aScanID, const QString& aPath);
|
||||
void createScanToRecon(const QString& aScanID, const QString& aPatientID, const QString& aReferenceID, const QString& aPath);
|
||||
@@ -166,6 +175,9 @@ signals:
|
||||
void transferStatusUpdated();
|
||||
void startPreviewScanResult(bool aIsSucessful);
|
||||
void startPumpControlResult(bool aIsSucessful);
|
||||
void startAutoLocateResult(bool aIsSucessful);
|
||||
void updateAutoLocatePosition(int aX, int aY, int aZ);
|
||||
void autolocatePositionEffective();
|
||||
void shutdownDmsSended();
|
||||
void shutdownDmsFailed();
|
||||
|
||||
@@ -174,13 +186,16 @@ private:
|
||||
int mTemperatureTimer = -1;
|
||||
int mScanProgressTimer = -1;
|
||||
int mCheckInitStatusTimer = -1;
|
||||
int mGetAutoLocatePositionTimer = -1;
|
||||
int mTransferProgress = 0;
|
||||
int mEffectivePositionCount = 0;
|
||||
bool mIsEmptyScan = false;
|
||||
bool mIsTransferEmptyScan = false;
|
||||
bool mIsScanning = false;
|
||||
bool mIsTransfering = false;
|
||||
bool mIsPreviewing = false;
|
||||
bool mIsInitializing = false;
|
||||
bool mIsAutoLocating = false;
|
||||
|
||||
QString mCurrentScanMeasurementID = "";
|
||||
QString mCurrentEmptyMeasurementID = "";
|
||||
@@ -205,6 +220,9 @@ private:
|
||||
DmsSyncAction* mSetSimulatorModeAction = nullptr;
|
||||
DmsSyncAction* mSetHeartBeatAction = nullptr;
|
||||
DmsSyncAction* mCheckInitStatusAction = nullptr;
|
||||
DmsSyncAction* mStartAutoLocateAction = nullptr;
|
||||
DmsSyncAction* mStopAutoLocateAction = nullptr;
|
||||
DmsSyncAction* mCheckDataQualityAction = nullptr;
|
||||
|
||||
DmsAsyncAction* mGetDeviceTemperatureAction = nullptr;
|
||||
DmsAsyncAction* mGetScanProgressAction = nullptr;
|
||||
@@ -212,6 +230,7 @@ private:
|
||||
DmsAsyncAction* mStopTransferAction = nullptr;
|
||||
DmsAsyncAction* mShutDownAction = nullptr;
|
||||
DmsAsyncAction* mPumpControlAction = nullptr;
|
||||
DmsAsyncAction* mGetAutoLocatePositionAction = nullptr;
|
||||
|
||||
InfoReceiveWorker* mInfoReceiveWorker = nullptr;
|
||||
|
||||
|
||||
@@ -70,6 +70,8 @@ void InfoReceiveWorker::responsed(int aServerID, int aActionID)
|
||||
case ACT_SCAN_SIMULATOR:
|
||||
DeviceManager::Default()->mSetSimulatorModeAction->responsed();
|
||||
break;
|
||||
case ACT_SCAN_IMGQUALITI:
|
||||
DeviceManager::Default()->mCheckDataQualityAction->responsed();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -110,6 +112,15 @@ void InfoReceiveWorker::responsed(int aServerID, int aActionID)
|
||||
case ACT_CTL_PWRDOWN:
|
||||
DeviceManager::Default()->mShutDownAction->responsed();
|
||||
break;
|
||||
case ACT_CTL_MOTION_START:
|
||||
DeviceManager::Default()->mStartAutoLocateAction->responsed();
|
||||
break;
|
||||
case ACT_CTL_MOTION_STOP:
|
||||
DeviceManager::Default()->mStopAutoLocateAction->responsed();
|
||||
break;
|
||||
case ACT_CTL_MOTION_POSITION:
|
||||
DeviceManager::Default()->mGetAutoLocatePositionAction->responsed();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -36,6 +36,7 @@ enum{
|
||||
ACT_SCAN_PRERESP, //上位机处理完数据后的响应
|
||||
ACT_SCAN_CE_STATUS, //是否已经完成当天的扫查
|
||||
ACT_SCAN_DIAGNOSIS, //诊断扫查
|
||||
ACT_SCAN_IMGQUALITI, //图像质量判定结果
|
||||
};
|
||||
|
||||
//数据传输服务
|
||||
@@ -60,6 +61,7 @@ enum{
|
||||
ACT_IFCFG_HBCFG, //设置心跳频率
|
||||
ACT_IFCFG_DEFAULT, //将配置恢复到默认值(再次加载配置文件到结构体)
|
||||
ACT_IFCFG_INIT_STATUS, //查询设备是否完成初始化
|
||||
ACT_IFCFG_ECB_STATUS, //查询电控板信息状态。
|
||||
};
|
||||
|
||||
//杂类控制和调试服务
|
||||
@@ -85,7 +87,12 @@ enum{
|
||||
ACT_CTL_FEB_RESET,
|
||||
ACT_CTL_PUMP, //水泵启停
|
||||
ACT_CTL_PWRDOWN, //下电开关
|
||||
ACT_CTL_MOTION_START, //启动自动定位功能
|
||||
ACT_CTL_MOTION_STOP, //停止自动定位功能
|
||||
ACT_CTL_MOTION_POSITION, //查询自动定位状态(位置)
|
||||
ACT_CTL_DRIVER, //驱动控制(加载卸载驱动)
|
||||
ACT_CTL_EXIT, //退出程序和守护进程
|
||||
|
||||
};
|
||||
|
||||
//设备升级
|
||||
|
||||
Reference in New Issue
Block a user