Phase control workflow logic

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

View File

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

View File

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

View File

@@ -69,6 +69,10 @@ void DeviceManager::initDevice() {
processScan(json.c_str());
}
});
// Continue Scan
connect(EventCenter::Default(), &EventCenter::RequestContinueScan, [=](QObject* sender, QObject* detail) {
postContinueCommand(true);
});
// stop
connect(EventCenter::Default(), &EventCenter::RequestStop, [=]() {
qDebug() << "GetStatus";
@@ -207,12 +211,34 @@ void DeviceManager::timerEvent(QTimerEvent* event) {
qDebug() << "Scanning request status, status:" << getStatusString(inf.status);
//设备正常扫描中
if (inf.status == SCANNING) {
qDebug() <<"current output path:"<<getScanOutputPath();
qDebug() << "current output path:" << getScanOutputPath();
lastStatus = SCANNING;
//normal scan
QVariant var(inf.progress);
qDebug() << "Normal scan, invoke InvokeOperationProgress:" << inf.progress;
TRIGGER_EVENT(GUIEvents::InvokeOperationProgress, nullptr, (QObject*)&var);
//normal scan pending
int phase = inf.progress/100 + 1;
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;
}
else {
@@ -293,22 +319,38 @@ void DeviceManager::processScan(const char* json, bool empty) {
return;
}
qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success";
//ScanControl fail
postScanCommand();
}
void DeviceManager::postScanCommand() {
qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>";
if (!ScanControl(SCAN)) {
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success";
//set current state
lastStatus = SCANNING;
previewing = false;
scanPhase = 1;
qDebug() << "Start progress timer";
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() {
#ifdef _WIN32
StopDevice();
@@ -324,3 +366,5 @@ QString DeviceManager::getSoftwareVersion() {
QString DeviceManager::getScanOutputPath() {
return GetDeviceInfo(DEV_OUTPATH);
}

View File

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

View File

@@ -1,4 +1,4 @@
#include "mainwindow.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <qtabwidget.h>
#include <QSizePolicy>
@@ -126,7 +126,8 @@ MainWindow::MainWindow(QWidget* parent) :
if (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 {
msgDialog->hideMessage();