New status check logic

This commit is contained in:
Krad
2021-10-27 18:04:05 +08:00
parent 9b5113fd1e
commit c36d0b5cce

View File

@@ -55,10 +55,11 @@ void DeviceManager::initDevice() {
// empty scan
connect(EventCenter::Default(),&EventCenter::RequestEmptyScan,[=](QObject* sender, QObject* detail){
std::string json= getJsonFromPatInf(detail);
qDebug()<<json.c_str();
void * jss = malloc(json.size());
memcpy(jss,json.c_str(),json.size());
processScan((char*)jss,true);
// qDebug()<<json.c_str();
// void * jss = malloc(json.size());
// memcpy(jss,json.c_str(),json.size());
// processScan((char*)jss,true);
processScan(json.c_str(),true);
});
// Patient scan
connect(EventCenter::Default(),&EventCenter::RequestPatientScan,[=](QObject* sender, QObject* detail){
@@ -66,20 +67,31 @@ void DeviceManager::initDevice() {
qDebug()<<json.c_str();
if (!json.empty())
{
void * jss = malloc(json.size());
memcpy(jss,json.c_str(),json.size());
processScan((char*)jss);
// void * jss = malloc(json.size());
// memcpy(jss,json.c_str(),json.size());
// processScan((char*)jss);
processScan(json.c_str());
}
});
// stop
connect(EventCenter::Default(),&EventCenter::RequestStop,[=]() {
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, nullptr);
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
qDebug()<<"Stop request status, status:%s"<<getStatusString(inf.status);
// check device status=========================================
//device is ready return
if (inf.status == READY) return;
if (inf.status == BUSY) {
QString msg("Device is busy, Stop operation fail!");
THROW_ERROR(msg);
return;
};
if (inf.status == SCANNING) {
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, nullptr);
//ScanControl fail
qDebug()<<"Request stop!";
if (timerID!=-1)killTimer(timerID);
if (ScanControl(STOP)) {
qDebug()<<"Stop fail!";
QString msg("Stop operation fail!");
@@ -97,20 +109,22 @@ void DeviceManager::initDevice() {
QString s("%1 %2");
s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss"),("Scan Stopped!"));
TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr,(QObject*)&s);
TRIGGER_EVENT(GUIEvents::InvokeOperationEnd, nullptr, nullptr);
TRIGGER_EVENT(GUIEvents::ResponseStop, nullptr, nullptr);
}
TRIGGER_EVENT(GUIEvents::InvokeOperationEnd, nullptr, nullptr);
TRIGGER_EVENT(GUIEvents::ResponseStop, nullptr, nullptr);
});
// preview
connect(EventCenter::Default(),&EventCenter::RequestPreviewScan,[=](){
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, nullptr);
// check device status=========================================
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
qDebug() << "PreviewScan request status, status:" << getStatusString(inf.status);
if (inf.status==READY)
{
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, nullptr);
//ScanControl
qDebug()<<"Request preview!";
if(!ScanControl(PREVIEW_SCAN))
@@ -140,15 +154,18 @@ void DeviceManager::initDevice() {
QThread::sleep(3);
continue;
}
// check device status=========================================
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
qDebug() << "GetPreviewData request status, status:" << getStatusString(inf.status);
// device is preview scanning, try get preview data
if (inf.status==SCANNING) {
qDebug() << "Preview data reader read start!";
const char *data = GetPreviewData();
if (!data)continue;
qDebug() << "Preview data reader read end!";
QByteArray bytes = QByteArray::fromRawData(data, 140 * 140);
//double check
if (!previewing) {
qDebug()<<"Preview data reader long sleep!";
QThread::sleep(3);
@@ -168,19 +185,22 @@ void DeviceManager::timerEvent(QTimerEvent *event) {
//scanning progress timer
if (event->timerId() !=deviceInfTimerID)
{
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
qDebug() << "Scanning request status, status:" << getStatusString(inf.status);
//error exit
if (errorOccurred)
{
qDebug() << "Error occurred, exit progress timer" << inf.progress;
qDebug() << "Error occurred, exit progress timer";
goto exitTimer;
}
// previewing exit
if (previewing)
{
//错误timer
goto exitTimer;
}
// check device status=========================================
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
qDebug() << "Scanning request status, status:" << getStatusString(inf.status);
//设备正常扫描中
if (inf.status==SCANNING)
{
@@ -204,6 +224,11 @@ void DeviceManager::timerEvent(QTimerEvent *event) {
s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss")).arg("Scan finished");
TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr,(QObject*)&s);
}
//一般不会出现其他情况
else{
QString msg("Unknown error in scanning progress timer");
THROW_ERROR(msg);
}
}
exitTimer:
qDebug() << "Scanning progress Timer exit";
@@ -211,7 +236,6 @@ void DeviceManager::timerEvent(QTimerEvent *event) {
timerID=-1;
lastStatus = -1;
previewing = false;
// TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr,nullptr);
return;
} else{
QString temp = QString(GetDeviceInfo(MEAN_TEMPERATURE));
@@ -220,34 +244,38 @@ void DeviceManager::timerEvent(QTimerEvent *event) {
}
void DeviceManager::processScan(const char *json, bool empty) {
// check device status=========================================
qDebug() << "GetStatus";
StatusInfo inf = GetStatus();
qDebug() << "Scan start request status, status:" << getStatusString(inf.status);
if (inf.status != READY) {
QString errmsg("Device is not ready, start scan operation fail!status is %1");
errmsg = errmsg.arg(getStatusString(inf.status));
THROW_ERROR(errmsg);
return;
}
static QString msg = "Start scan...";
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, (QObject*)&msg);
qDebug() << "SetScanInfo>>>>>>>>>>>>>>>>>>>>" ;
int ret = SetScanInfo(json,empty?1:0);
if (ret){
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, (QObject *) &msg);
qDebug() << "SetScanInfo>>>>>>>>>>>>>>>>>>>>";
int ret = SetScanInfo(json, empty ? 1 : 0);
if (ret) {
qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo failed";
QString errmsg("Transfer patient information fail!");
qDebug() << "Error thrown" ;
qDebug() << "Error thrown";
THROW_ERROR(errmsg);
return;
}
qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success";
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
qDebug() << "Scan start request status, status:" << getStatusString(inf.status);
if (inf.status==READY)
{
//ScanControl fail
qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>";
if(!ScanControl(SCAN)) {
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success";
lastStatus = SCANNING;
qDebug() << "Start progress timer";
timerID = startTimer(300);
return;
}
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed";
//ScanControl fail
qDebug() << "ScanControl start>>>>>>>>>>>>>>>>>>>>>";
if (!ScanControl(SCAN)) {
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl success";
lastStatus = SCANNING;
qDebug() << "Start progress timer";
timerID = startTimer(300);
return;
}
QString errmsg("Start scan operation fail!");
QString errmsg("ScanControl start fail!");
THROW_ERROR(errmsg);
qDebug() << ">>>>>>>>>>>>>>>>>>>>>ScanControl failed";
}