Phase control workflow logic

This commit is contained in:
Krad
2022-05-12 14:53:17 +08:00
parent 6ba9786efb
commit ae89aeffe4
5 changed files with 121 additions and 58 deletions

View File

@@ -13,17 +13,18 @@ error_cb innerCallback = NULL;
void ThreadFunc(void*); void ThreadFunc(void*);
HANDLE th; HANDLE th;
HANDLE e1; HANDLE e1,e2;
int InitLib(error_cb cb) { int InitLib(error_cb cb) {
innerCallback = cb; innerCallback = cb;
innerCallback("11111"); innerCallback("11111");
e1 = CreateEvent(NULL, FALSE, FALSE, "e1"); e1 = CreateEvent(NULL, FALSE, FALSE, "e1");
e2 = CreateEvent(NULL, FALSE, FALSE, "e2");
th = _beginthread(ThreadFunc,0, NULL); th = _beginthread(ThreadFunc,0, NULL);
return 0; return 0;
} }
volatile int running = 1; volatile int running = 1;
volatile float progress = 0.0f; volatile int progress = 0;
volatile int status = READY; volatile int status = READY;
volatile int stop_flag = 0; volatile int stop_flag = 0;
char output_path[256] = {0}; char output_path[256] = {0};
@@ -33,16 +34,25 @@ void ThreadFunc(void* args){
WaitForSingleObject(e1, INFINITE); WaitForSingleObject(e1, INFINITE);
status = SCANNING; status = SCANNING;
stop_flag = 0; stop_flag = 0;
progress = 0.0f; progress = 0;
for (int i = 0; i < 30; ++i) { for (int i = 0; i < 50; ++i) {
if (stop_flag > 0){ if (stop_flag > 0){
stop_flag = 0; stop_flag = 0;
break; break;
} }
progress = (float)i * 0.1f; if (i == 20){
if (i == 10){ progress = 139;
WaitForSingleObject(e1, INFINITE); WaitForSingleObject(e2, INFINITE);
}
else if ( i > 20 && i<35){
progress = i * 2 + 100;
}
else if(i >= 35){
progress = i * 2 + 200;
}
else{
progress = i *2;
} }
Sleep(300); Sleep(300);
} }
@@ -58,7 +68,7 @@ int ScanControl(ScanAction actionType) {
statusCountFlag = 2; statusCountFlag = 2;
SYSTEMTIME st = {0}; SYSTEMTIME st = {0};
GetLocalTime(&st); GetLocalTime(&st);
sprintf(output_path,"%d%02d%02dT%02d%02d%02d", sprintf(output_path, "%d%02d%02dT%02d%02d%02d",
st.wYear, st.wYear,
st.wMonth, st.wMonth,
st.wDay, st.wDay,
@@ -74,10 +84,13 @@ int ScanControl(ScanAction actionType) {
case STOP: case STOP:
statusCountFlag = 0; statusCountFlag = 0;
stop_flag = 1; stop_flag = 1;
progress = 0.0f; progress = 0;
status = READY; status = READY;
printf("Stop everything!\r\n"); printf("Stop everything!\r\n");
break; break;
case SCAN_CONTINUE:
SetEvent(e2);
break;
} }
return 0; return 0;
} }
@@ -135,5 +148,6 @@ const char* GetDeviceInfo(DeviceInfo infoType) {
#ifdef _WIN32 #ifdef _WIN32
void StopDevice(){ void StopDevice(){
CloseHandle(e1); CloseHandle(e1);
CloseHandle(e2);
} }
#endif #endif

View File

@@ -16,7 +16,7 @@ typedef enum {
typedef struct StatusInfo { typedef struct StatusInfo {
DeviceStatus status;// a enum represent device current status DeviceStatus status;// a enum represent device current status
float progress;// percent value of operation int progress;// percent value of operation
} StatusInfo; } StatusInfo;
@@ -25,6 +25,7 @@ typedef enum {
SCAN,// Start scan action SCAN,// Start scan action
PREVIEW_SCAN,// Start preview scan action PREVIEW_SCAN,// Start preview scan action
STOP,// Stop current scan STOP,// Stop current scan
SCAN_CONTINUE,//Continue pending scan
} ScanAction; } ScanAction;
//kinds of device information //kinds of device information

View File

@@ -69,6 +69,10 @@ void DeviceManager::initDevice() {
processScan(json.c_str()); processScan(json.c_str());
} }
}); });
// Continue Scan
connect(EventCenter::Default(), &EventCenter::RequestContinueScan, [=](QObject* sender, QObject* detail) {
postContinueCommand(true);
});
// stop // stop
connect(EventCenter::Default(), &EventCenter::RequestStop, [=]() { connect(EventCenter::Default(), &EventCenter::RequestStop, [=]() {
qDebug() << "GetStatus"; qDebug() << "GetStatus";
@@ -207,12 +211,34 @@ void DeviceManager::timerEvent(QTimerEvent* event) {
qDebug() << "Scanning request status, status:" << getStatusString(inf.status); qDebug() << "Scanning request status, status:" << getStatusString(inf.status);
//设备正常扫描中 //设备正常扫描中
if (inf.status == SCANNING) { if (inf.status == SCANNING) {
qDebug() <<"current output path:"<<getScanOutputPath(); qDebug() << "current output path:" << getScanOutputPath();
lastStatus = SCANNING; lastStatus = SCANNING;
//normal scan
QVariant var(inf.progress); //normal scan pending
qDebug() << "Normal scan, invoke InvokeOperationProgress:" << inf.progress; int phase = inf.progress/100 + 1;
TRIGGER_EVENT(GUIEvents::InvokeOperationProgress, nullptr, (QObject*)&var); int progress = inf.progress % 100;
QString extraMsg = (AppGlobalValues::EmptyScanFlag().toBool()||(scanPhase != 3))?"":", patient can leave";
QVariant var(QString("Phase %1%3\r\n progress:%2%").arg(scanPhase).arg(progress).arg(extraMsg));
TRIGGER_EVENT(GUIEvents::InvokeOperationProgress, nullptr, (QObject *) &var);
if (scanPhase != phase) {
if (phase > 3 || scanPhase > phase ){
QString errorMsg = QString("Error Scan Phase code, current Phase code:%1, new Phase code:%2!").arg(scanPhase,phase);
THROW_ERROR(errorMsg)
goto exitTimer;
}
scanPhase = phase;
if (scanPhase == 2){
if (!AppGlobalValues::EmptyScanFlag().toBool()) {
var.setValue(QString("Scan phase 2 waiting for patient!\r\n Click \"Next\" to continue!"));
TRIGGER_EVENT(GUIEvents::InvokeOperationPending, nullptr, (QObject *) &var);
goto exitTimer;
}
//empty scan no pending, auto continue
else {
postContinueCommand();
}
}
}
return; return;
} }
else { else {
@@ -293,22 +319,38 @@ void DeviceManager::processScan(const char* json, bool empty) {
return; return;
} }
qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success"; qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success";
//ScanControl fail
postScanCommand();
}
void DeviceManager::postScanCommand() {
qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>"; qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>";
if (!ScanControl(SCAN)) { if (!ScanControl(SCAN)) {
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success"; qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success";
//set current state //set current state
lastStatus = SCANNING; lastStatus = SCANNING;
previewing = false; previewing = false;
scanPhase = 1;
qDebug() << "Start progress timer"; qDebug() << "Start progress timer";
timerID = startTimer(500); timerID = startTimer(500);
return; return;
} }
//ScanControl fail
QString errmsg("ScanControl start fail!"); QString errmsg("ScanControl start fail!");
THROW_ERROR(errmsg); THROW_ERROR(errmsg);
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed"; qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed";
} }
void DeviceManager::postContinueCommand(bool useTimer) {
if (!ScanControl(SCAN_CONTINUE)) {
if (useTimer)timerID = startTimer(500);
return;
}
//ScanControl fail
QString errmsg("ScanControl start fail!");
THROW_ERROR(errmsg);
}
void DeviceManager::close() { void DeviceManager::close() {
#ifdef _WIN32 #ifdef _WIN32
StopDevice(); StopDevice();
@@ -324,3 +366,5 @@ QString DeviceManager::getSoftwareVersion() {
QString DeviceManager::getScanOutputPath() { QString DeviceManager::getScanOutputPath() {
return GetDeviceInfo(DEV_OUTPATH); return GetDeviceInfo(DEV_OUTPATH);
} }

View File

@@ -34,6 +34,9 @@ protected:
private: private:
void processScan(const char* json, bool empty = false); void processScan(const char* json, bool empty = false);
void postScanCommand();
void postContinueCommand(bool useTimer = false);
int scanPhase = 1;
int timerID = -1; int timerID = -1;
int deviceInfTimerID = -1; int deviceInfTimerID = -1;
int lastStatus = -1; int lastStatus = -1;

View File

@@ -1,4 +1,4 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <qtabwidget.h> #include <qtabwidget.h>
#include <QSizePolicy> #include <QSizePolicy>
@@ -126,7 +126,8 @@ MainWindow::MainWindow(QWidget* parent) :
if (msg) if (msg)
{ {
QVariant* var = (QVariant*)msg; QVariant* var = (QVariant*)msg;
msgDialog->showMessage(QString("Scanning %1%").arg((int)(var->toFloat() * 100.0f))); if (msgDialog->Pending())msgDialog->stopPending();
msgDialog->showMessage(var->toString());
} }
else { else {
msgDialog->hideMessage(); msgDialog->hideMessage();