// // Created by Krad on 2021/10/12. // #include "ShimLib/ShimLib.h" #include "DeviceManager.h" #include "../event/EventCenter.h" #include #include #include #include #include #define TRIGGER_EVENT EventCenter::Default()->triggerEvent #define THROW_ERROR(errormsg)\ TRIGGER_EVENT(GUIEvents::GUIErrorRaise, nullptr, (QObject*)&errormsg); const char * getStatusString(int status) { switch (status) { case SCANNING: return "SCANNING"; case READY: return "Ready"; case BUSY: return "BUSY"; case ERROR: return "ERROR"; } return ""; } std::string getJsonFromPatInf(QObject* obj) { return ((QString*)obj)->toStdString(); } void ErrorCallback(const char * msg) { DeviceManager::Default()->setErrorOccurred(true); printf("Error Callback , message:%s\r\n", msg); QString m(msg); THROW_ERROR(m); } void DeviceManager::initDevice() { InitLib(ErrorCallback); deviceInfTimerID = startTimer(1000); // empty scan connect(EventCenter::Default(),&EventCenter::RequestEmptyScan,[=](QObject* sender, QObject* detail){ std::string json= getJsonFromPatInf(detail); qDebug()<start(); } 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); if (errorOccurred) { 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); return; } else{ //未发生错误并且,之前状态是扫描,代表正常扫描完成 if (lastStatus == SCANNING) { qDebug() << "Scan finished" ; QVariant var(true); qDebug() << "InvokeOperationEnd" ; TRIGGER_EVENT(GUIEvents::InvokeOperationEnd, nullptr, (QObject*)&var); lastStatus = -1; previewing = false; QString s("%1 %2"); s = s.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd HH:mm:ss")).arg("Scan finished"); TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr,(QObject*)&s); } } exitTimer: qDebug() << "Scanning progress Timer exit"; killTimer(timerID); timerID=-1; lastStatus = -1; previewing = false; // TRIGGER_EVENT(GUIEvents::GlobalBannerMessage, nullptr,nullptr); return; } else{ QString temp = QString(GetDeviceInfo(MEAN_TEMPERATURE)); TRIGGER_EVENT(GUIEvents::ResponseDeviceTemperature, nullptr, (QObject*)&temp); } } 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(); 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); }