127 lines
3.8 KiB
C++
127 lines
3.8 KiB
C++
|
|
//
|
|||
|
|
// Created by Krad on 2021/10/12.
|
|||
|
|
//
|
|||
|
|
#include "ShimLib/ShimLib.h"
|
|||
|
|
#include "DeviceManager.h"
|
|||
|
|
#include "../event/EventCenter.h"
|
|||
|
|
#include <QVariant>
|
|||
|
|
|
|||
|
|
#define triggerEvent EventCenter::Default()->triggerEvent
|
|||
|
|
|
|||
|
|
const char * getJsonFromPatInf(QObject* obj)
|
|||
|
|
{
|
|||
|
|
return nullptr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DeviceManager::initDevice() {
|
|||
|
|
// empty scan
|
|||
|
|
connect(EventCenter::Default(),&EventCenter::RequestEmptyScan,[=](){
|
|||
|
|
const char * json = "";
|
|||
|
|
processScan(json);
|
|||
|
|
});
|
|||
|
|
// Patient scan
|
|||
|
|
connect(EventCenter::Default(),&EventCenter::RequestPatientScan,[=](QObject* sender, QObject* detail){
|
|||
|
|
const char * json = getJsonFromPatInf(detail);
|
|||
|
|
if (json)
|
|||
|
|
{
|
|||
|
|
processScan(json);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
// stop
|
|||
|
|
connect(EventCenter::Default(),&EventCenter::RequestStop,[=](){
|
|||
|
|
triggerEvent(GUIEvents::InvokeOperationStart, nullptr, nullptr);
|
|||
|
|
StatusInfo inf = GetStatus();
|
|||
|
|
if (inf.status==SCANING)
|
|||
|
|
{
|
|||
|
|
//ScanControl fail
|
|||
|
|
if(ScanControl(STOP))
|
|||
|
|
{
|
|||
|
|
triggerEvent(GUIEvents::GUIErrorRaise, nullptr, nullptr);
|
|||
|
|
lastStatus = -1;
|
|||
|
|
previewing = false;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
lastStatus = -1;
|
|||
|
|
previewing = false;
|
|||
|
|
triggerEvent(GUIEvents::InvokeOperationEnd, nullptr, nullptr);
|
|||
|
|
triggerEvent(GUIEvents::ResponseStop, nullptr, nullptr);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
// preview
|
|||
|
|
connect(EventCenter::Default(),&EventCenter::RequestPreviewScan,[=](){
|
|||
|
|
triggerEvent(GUIEvents::InvokeOperationStart, nullptr, nullptr);
|
|||
|
|
StatusInfo inf = GetStatus();
|
|||
|
|
if (inf.status==READY)
|
|||
|
|
{
|
|||
|
|
//ScanControl
|
|||
|
|
if(!ScanControl(PREVIEW_SCAN))
|
|||
|
|
{
|
|||
|
|
lastStatus = SCANING;
|
|||
|
|
previewing = true;
|
|||
|
|
timerID = startTimer(500);
|
|||
|
|
triggerEvent(GUIEvents::ResponsePreview, nullptr, nullptr);
|
|||
|
|
triggerEvent(GUIEvents::InvokeOperationEnd, nullptr, nullptr);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
triggerEvent(GUIEvents::GUIErrorRaise, nullptr, nullptr);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DeviceManager::timerEvent(QTimerEvent *event) {
|
|||
|
|
StatusInfo inf = GetStatus();
|
|||
|
|
if (inf.status==SCANING)
|
|||
|
|
{
|
|||
|
|
lastStatus = SCANING;
|
|||
|
|
//normal scan
|
|||
|
|
if(!previewing)
|
|||
|
|
{
|
|||
|
|
QVariant var(inf.progress);
|
|||
|
|
triggerEvent(GUIEvents::InvokeOperationProgress, nullptr, (QObject*)&var);
|
|||
|
|
}
|
|||
|
|
//preview scan
|
|||
|
|
else{
|
|||
|
|
const char * data = GetPreviewData();
|
|||
|
|
QByteArray* bytes = new QByteArray(data);
|
|||
|
|
triggerEvent(GUIEvents::ResponsePreviewData, nullptr, (QObject*)bytes);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
} else{
|
|||
|
|
if (lastStatus == SCANING && !errorOccured)
|
|||
|
|
{
|
|||
|
|
QVariant var(true);
|
|||
|
|
triggerEvent(GUIEvents::InvokeOperationEnd, nullptr, (QObject*)&var);
|
|||
|
|
lastStatus = -1;
|
|||
|
|
previewing = false;
|
|||
|
|
}
|
|||
|
|
//内部错误,导致Scan停止
|
|||
|
|
else if (lastStatus == SCANING && errorOccured)
|
|||
|
|
{
|
|||
|
|
//正常情况下,设备应该已经调用的错误callback,然后会回归Ready状态,清理lastStatus即可
|
|||
|
|
lastStatus = -1;
|
|||
|
|
previewing = false;
|
|||
|
|
}
|
|||
|
|
killTimer(timerID);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DeviceManager::processScan(const char *json) {
|
|||
|
|
triggerEvent(GUIEvents::InvokeOperationStart, nullptr, nullptr);
|
|||
|
|
int ret = SetScanInf(json);
|
|||
|
|
if (ret){
|
|||
|
|
triggerEvent(GUIEvents::GUIErrorRaise, nullptr, nullptr);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
StatusInfo inf = GetStatus();
|
|||
|
|
if (inf.status==READY)
|
|||
|
|
{
|
|||
|
|
//ScanControl fail
|
|||
|
|
if(!ScanControl(SCAN)) {
|
|||
|
|
lastStatus = SCANING;
|
|||
|
|
timerID = startTimer(300);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
triggerEvent(GUIEvents::GUIErrorRaise, nullptr, nullptr);
|
|||
|
|
}
|