Phase control workflow logic
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -53,32 +63,35 @@ void ThreadFunc(void* args){
|
|||||||
int ScanControl(ScanAction actionType) {
|
int ScanControl(ScanAction actionType) {
|
||||||
|
|
||||||
switch (actionType) {
|
switch (actionType) {
|
||||||
case SCAN:
|
case SCAN:
|
||||||
printf("Do Scan!\r\n");
|
printf("Do Scan!\r\n");
|
||||||
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,
|
||||||
st.wHour,
|
st.wHour,
|
||||||
st.wMinute,
|
st.wMinute,
|
||||||
st.wSecond);
|
st.wSecond);
|
||||||
SetEvent(e1);
|
SetEvent(e1);
|
||||||
break;
|
break;
|
||||||
case PREVIEW_SCAN:
|
case PREVIEW_SCAN:
|
||||||
statusCountFlag = 1;
|
statusCountFlag = 1;
|
||||||
printf("Do preview!\r\n");
|
printf("Do preview!\r\n");
|
||||||
break;
|
break;
|
||||||
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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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,14 +211,36 @@ 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;
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
//未发生错误并且,之前状态是扫描,代表正常扫描完成
|
//未发生错误并且,之前状态是扫描,代表正常扫描完成
|
||||||
if (lastStatus == SCANNING) {
|
if (lastStatus == SCANNING) {
|
||||||
@@ -293,20 +319,36 @@ void DeviceManager::processScan(const char* json, bool empty) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success";
|
qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success";
|
||||||
//ScanControl fail
|
|
||||||
qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>";
|
postScanCommand();
|
||||||
if (!ScanControl(SCAN)) {
|
}
|
||||||
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success";
|
|
||||||
//set current state
|
void DeviceManager::postScanCommand() {
|
||||||
lastStatus = SCANNING;
|
qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>";
|
||||||
previewing = false;
|
if (!ScanControl(SCAN)) {
|
||||||
qDebug() << "Start progress timer";
|
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success";
|
||||||
timerID = startTimer(500);
|
//set current state
|
||||||
return;
|
lastStatus = SCANNING;
|
||||||
}
|
previewing = false;
|
||||||
QString errmsg("ScanControl start fail!");
|
scanPhase = 1;
|
||||||
THROW_ERROR(errmsg);
|
qDebug() << "Start progress timer";
|
||||||
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed";
|
timerID = startTimer(500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//ScanControl fail
|
||||||
|
QString errmsg("ScanControl start fail!");
|
||||||
|
THROW_ERROR(errmsg);
|
||||||
|
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() {
|
||||||
@@ -324,3 +366,5 @@ QString DeviceManager::getSoftwareVersion() {
|
|||||||
QString DeviceManager::getScanOutputPath() {
|
QString DeviceManager::getScanOutputPath() {
|
||||||
return GetDeviceInfo(DEV_OUTPATH);
|
return GetDeviceInfo(DEV_OUTPATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user