From 2715d5dee0a6c823b7122e2a286b3f5223916f1a Mon Sep 17 00:00:00 2001 From: Krad Date: Tue, 26 Oct 2021 09:51:23 +0800 Subject: [PATCH] Add debug log for real device debug --- src/ScanFormWidget.cpp | 9 ++-- src/device/DeviceManager.cpp | 88 ++++++++++++++++++++++++++++-------- 2 files changed, 75 insertions(+), 22 deletions(-) diff --git a/src/ScanFormWidget.cpp b/src/ScanFormWidget.cpp index 75e29c3..00630be 100644 --- a/src/ScanFormWidget.cpp +++ b/src/ScanFormWidget.cpp @@ -13,6 +13,7 @@ #include "event/EventCenter.h" #include #include +#include #ifdef WIN32 #else @@ -208,16 +209,18 @@ ScanFormWidget::ScanFormWidget(QWidget *parent) : TabFormWidget(parent) { patient_information->setPatientInformation((PatientInformation*)data); }); connect(btnRefresh,&QToolButton::clicked,[=](){ - QString patientInf(patient_information->getCurrentPatientJsonString(true)); - printf("%s\r\n",patientInf.toStdString().data()); + qDebug()<<"Get patient Json string start!"; + QString patientInf(patient_information->getCurrentPatientJsonString(false)); + qDebug()<<"Get patient Json string end! string:"<triggerEvent(GUIEvents::RequestEmptyScan, nullptr, (QObject*)(&patientInf)); }); connect(btnPreview,&QToolButton::clicked,[=](){ EventCenter::Default()->triggerEvent(GUIEvents::RequestPreviewScan, nullptr, nullptr); }); connect(btnScan,&QToolButton::clicked,[=](){ + qDebug()<<"Get patient Json string start!"; QString patientInf(patient_information->getCurrentPatientJsonString(false)); - printf("%s\r\n",patientInf.toStdString().data()); + qDebug()<<"Get patient Json string end! string:"<triggerEvent(GUIEvents::RequestPatientScan, nullptr, (QObject*)(&patientInf)); }); connect(btnStop,&QToolButton::clicked,[=](){ diff --git a/src/device/DeviceManager.cpp b/src/device/DeviceManager.cpp index 4953956..9031ff9 100644 --- a/src/device/DeviceManager.cpp +++ b/src/device/DeviceManager.cpp @@ -6,6 +6,7 @@ #include "../event/EventCenter.h" #include #include +#include #define TRIGGER_EVENT EventCenter::Default()->triggerEvent @@ -47,16 +48,20 @@ void DeviceManager::initDevice() { InitLib(ErrorCallback); deviceInfTimerID = startTimer(1000); + // global error flag + connect(EventCenter::Default(),&EventCenter::GUIErrorRaise,[=](QObject* sender, QObject* detail){ + this->errorOccured = true; + }); // empty scan connect(EventCenter::Default(),&EventCenter::RequestEmptyScan,[=](QObject* sender, QObject* detail){ std::string json= getJsonFromPatInf(detail); - printf("%s\r\n",json.c_str()); + qDebug()<start(); } void DeviceManager::timerEvent(QTimerEvent *event) { + //scanning progress timer if (event->timerId() !=deviceInfTimerID) { + qDebug()<<"GetStatus"; StatusInfo inf = GetStatus(); -// printf("Timer request status, status:%s\r\n",getStatusString(inf.status)); + qDebug() << "Scanning request status, status:" << getStatusString(inf.status); + if (errorOccured) + { + qDebug() << "Error occurred, exit progress timer" << inf.progress; + goto exitTimer; + } + if (previewing) + { + //错误timer + goto exitTimer; + } + //设备正常扫描中 if (inf.status==SCANNING) { lastStatus = SCANNING; //normal scan QVariant var(inf.progress); + qDebug() << "Normal scan, invoke InvokeOperationProgress:" << inf.progress; TRIGGER_EVENT(GUIEvents::InvokeOperationProgress, nullptr, (QObject*)&var); } else{ - if (lastStatus == SCANNING && !errorOccured) + //未发生错误并且,之前状态是扫描,代表正常扫描完成 + if (lastStatus == SCANNING) { + qDebug() << "Scan finished" ; QVariant var(true); + qDebug() << "InvokeOperationEnd" ; TRIGGER_EVENT(GUIEvents::InvokeOperationEnd, nullptr, (QObject*)&var); lastStatus = -1; previewing = false; } - //内部错误,导致Scan停止 - else if (lastStatus == SCANNING && errorOccured) - { - //正常情况下,设备应该已经调用的错误callback,然后会回归Ready状态,清理lastStatus即可 - lastStatus = -1; - previewing = false; - } - killTimer(timerID); + return; } + exitTimer: + killTimer(timerID); + timerID=-1; + lastStatus = -1; + previewing = false; + return; } else{ QString temp = QString(GetDeviceInfo(MEAN_TEMPERATURE)); TRIGGER_EVENT(GUIEvents::ResponseDeviceTemperature, nullptr, (QObject*)&temp); @@ -155,22 +196,31 @@ void DeviceManager::timerEvent(QTimerEvent *event) { void DeviceManager::processScan(const char *json, bool empty) { static QString msg = "Start scan..."; 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" ; THROW_ERROR(errmsg); return; } + qDebug() << ">>>>>>>>>>>>>>>>>>>>SetScanInfo success"; + qDebug()<<"GetStatus"; StatusInfo inf = GetStatus(); - printf("ProcessScan request status, status:%s\r\n",getStatusString(inf.status)); + 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"; } QString errmsg("Start scan operation fail!"); THROW_ERROR(errmsg);