Add debug log for real device debug

This commit is contained in:
Krad
2021-10-26 09:51:23 +08:00
parent 7a1476c4ad
commit 2715d5dee0
2 changed files with 75 additions and 22 deletions

View File

@@ -13,6 +13,7 @@
#include "event/EventCenter.h"
#include <QImage>
#include <QPainter>
#include <qdebug.h>
#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:"<<patientInf;
EventCenter::Default()->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:"<<patientInf;
EventCenter::Default()->triggerEvent(GUIEvents::RequestPatientScan, nullptr, (QObject*)(&patientInf));
});
connect(btnStop,&QToolButton::clicked,[=](){

View File

@@ -6,6 +6,7 @@
#include "../event/EventCenter.h"
#include <QVariant>
#include <QTimerEvent>
#include <qdebug.h>
#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()<<json.c_str();
processScan(json.c_str(), true);
});
// Patient scan
connect(EventCenter::Default(),&EventCenter::RequestPatientScan,[=](QObject* sender, QObject* detail){
std::string json= getJsonFromPatInf(detail);
printf("%s\r\n",json.c_str());
qDebug()<<json.c_str();
if (!json.empty())
{
processScan(json.c_str());
@@ -65,13 +70,17 @@ void DeviceManager::initDevice() {
// stop
connect(EventCenter::Default(),&EventCenter::RequestStop,[=]() {
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, nullptr);
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
printf("Stop request status, status:%s\r\n",getStatusString(inf.status));
qDebug()<<"Stop request status, status:%s"<<getStatusString(inf.status);
if (inf.status == SCANNING) {
//ScanControl fail
qDebug()<<"Request stop!";
if (ScanControl(STOP)) {
qDebug()<<"Stop fail!";
QString msg("Stop operation fail!");
THROW_ERROR(msg);
qDebug()<<"Error thrown!";
lastStatus = -1;
previewing = false;
return;
@@ -85,13 +94,16 @@ void DeviceManager::initDevice() {
// preview
connect(EventCenter::Default(),&EventCenter::RequestPreviewScan,[=](){
TRIGGER_EVENT(GUIEvents::InvokeOperationStart, nullptr, nullptr);
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
printf("PreviewScan request status, status:%s\r\n",getStatusString(inf.status));
qDebug() << "PreviewScan request status, status:" << getStatusString(inf.status);
if (inf.status==READY)
{
//ScanControl
qDebug()<<"Request preview!";
if(!ScanControl(PREVIEW_SCAN))
{
qDebug()<<"Preview success!";
lastStatus = SCANNING;
previewing = true;
// timerID = startTimer(500);
@@ -100,52 +112,81 @@ void DeviceManager::initDevice() {
return;
}
}
qDebug()<<"Preview fail!";
QString msg(inf.status!=READY?"Can't start preview,Device is not ready!":"Start preview operation fail!");
THROW_ERROR(msg);
qDebug()<<"Error thrown!";
});
previewDataCaller = QThread::create([=](){
while (!endLoop)
{
qDebug()<<"Preview data reader sleep!";
QThread::msleep(500);
if (!previewing) continue;
qDebug()<<"GetStatus";
StatusInfo inf = GetStatus();
qDebug() << "GetPreviewData request status, status:" << getStatusString(inf.status);
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);
if (!previewing) continue;
qDebug() << "Preview data response event start!";
TRIGGER_EVENT(GUIEvents::ResponsePreviewData, nullptr, (QObject *) (&bytes));
qDebug() << "Preview data response event end!";
}
}
});
previewDataCaller->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即可
return;
}
exitTimer:
killTimer(timerID);
timerID=-1;
lastStatus = -1;
previewing = false;
}
killTimer(timerID);
}
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);