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