Add shutdown widget.

This commit is contained in:
sunwen
2023-09-11 16:29:30 +08:00
parent ae1b063b72
commit 2bbef648f5
10 changed files with 140 additions and 7 deletions

View File

@@ -36,6 +36,7 @@ namespace
{
const int PREVIEW_IMAGE_WH = 140;
const unsigned int GET_TEMPERATURE_TIME = 60000;
const int SHUT_DOWN_TIMEOUT = 180000;//3 minitues
const QString DEFAULT_DMS_START_FAILED = "Dms start failed.";
const QString RECON_TRANSFER_PATH = "/home/krad/TestStore";
@@ -101,7 +102,7 @@ void DeviceManager::initDevice()
// preview
connect(EventCenter::Default(), &EventCenter::RequestPreviewScan,this, &DeviceManager::startPreview);
//shutdown
connect(EventCenter::Default(), &EventCenter::RequestShutdown, this, &DeviceManager::shutdown);
connect(EventCenter::Default(), &EventCenter::RequestShutdown, this, &DeviceManager::shutdownDms);
//Drainage
connect(EventCenter::Default(), &EventCenter::RequestDrainage, this, [this](QObject* sender, QObject* detail)
{
@@ -126,7 +127,10 @@ void DeviceManager::initDevice()
mGetSoftwareVersionAction = new DmsAsyncAction(USRV_INFOCFG, ACT_IFCFG_VERINFO, this,"responseGetSoftwareVersion(const QString&)", this);
mGetDeviceTemperatureAction = new DmsAsyncAction(USRV_SCAN, ACT_SCAN_TEMP, this, "responseGetDeviceTemperature(const QString&)", this);
mStopTransferAction = new DmsAsyncAction(USRV_XFR, ACT_XFR_STOP, this, "responseStopTransfer(const QString&)", this);
mShutDownAction = new DmsAsyncAction(USRV_CONTROL, ACT_CTL_PWRDOWN, this, "responseShutDown(const QString&)", this);
mShutDownAction->setTimeoutInterval(SHUT_DOWN_TIMEOUT);
connect(mGetScanProgressAction, &DmsAsyncAction::timeout, this, &DeviceManager::scanTimeout);
connect(mShutDownAction, &DmsAsyncAction::timeout, this, &DeviceManager::shutdownDmsFailed);
//dmsInfoReceiverThread
@@ -600,6 +604,10 @@ void DeviceManager::processReceiveDMSInfoResult(int aServerID, int aActionID, co
case ACT_CTL_PUMP:
emit responsePumpControl(aContents);
break;
case ACT_CTL_PWRDOWN:
emit responseShutDown(aContents);
processShutDownDms(aContents);
break;
}
break;
default:
@@ -731,14 +739,42 @@ void DeviceManager::getScanProcess()
mGetScanProgressAction->execute();
}
void DeviceManager::shutdown()
void DeviceManager::shutdownDms()
{
if(mIsTransfering)
{
QString msg = "Data is currently being transmitted, please shut down later.";
QString msg = tr("Data is currently being transmitted, please shut down later.");
THROW_ERROR(msg);
return;
}
QProcess::startDetached("shutdown", QStringList() << "-h" << "now");
if(!mShutDownAction->execute())
{
QString msg = tr("Shut down failed, please push emergency button to shutdown.");
THROW_ERROR(msg);
return;
}
AppGlobalValues::setInProcessing(true);
emit shutdownDmsSended();
}
void DeviceManager::processShutDownDms(const QString& aResponse)
{
QJsonObject jsonObj = toJsonObject(aResponse);
if(jsonObj.contains("code") && jsonObj["code"].toInt() == 0)
{
shutdownOperationSystem();
return;
}
AppGlobalValues::setInProcessing(false);
emit shutdownDmsFailed();
}
void DeviceManager::shutdownOperationSystem()
{
qDebug()<< "shut down OS";
//QProcess::startDetached("shutdown", QStringList() << "-h" << "now");
}
void DeviceManager::insertEmptyScanRecord()

View File

@@ -91,7 +91,8 @@ private:
*/
void startScan(const QString& json, bool empty = false);
void startPreview();
void shutdown();
void shutdownDms();
void shutdownOperationSystem();
//-----------------new
DeviceStatus getDeviceStatus();
@@ -115,6 +116,7 @@ private:
void processGetSoftwareVersion(const QString& aSoftwareVersion);
void processDeviceTemperature(const QString& aResponseTemperature);
void processTransferProgress(const QString& aProgress);
void processShutDownDms(const QString& aResponse);
void insertEmptyScanRecord();
void insertScanRecord();
@@ -150,6 +152,7 @@ signals:
void responseSetSimulatorMode(const QString& aResponse);
void responseSetHeartBeat(const QString& aResponese);
void responseStopTransfer(const QString& aResponse);
void responseShutDown(const QString& aResponse);
//Recon
void createEmptyScanToRecon(const QString& aScanID, const QString& aPath);
void createScanToRecon(const QString& aScanID, const QString& aPatientID, const QString& aReferenceID, const QString& aPath);
@@ -161,6 +164,8 @@ signals:
void transferStatusUpdated();
void startPreviewScanResult(bool aIsSucessful);
void startPumpControlResult(bool aIsSucessful);
void shutdownDmsSended();
void shutdownDmsFailed();
private:
@@ -202,6 +207,7 @@ private:
DmsAsyncAction* mGetScanProgressAction = nullptr;
DmsAsyncAction* mGetSoftwareVersionAction = nullptr;
DmsAsyncAction* mStopTransferAction = nullptr;
DmsAsyncAction* mShutDownAction = nullptr;
};

View File

@@ -18,6 +18,7 @@ DmsAsyncAction::DmsAsyncAction(int aServerId, int aActionId, QObject* aObject, c
, mSendData()
{
mTimer->setSingleShot(true);
mTimer->setInterval(TIMEOUT_MSEC);
connect(mTimer, &QTimer::timeout, this, &DmsAsyncAction::sendTimeoutSignal);
connect(mObject, ("2" + mResponseSignal).toStdString().c_str(), mTimer, SLOT(stop()));
}
@@ -36,7 +37,7 @@ bool DmsAsyncAction::execute()
{
return false;
}
mTimer->start(TIMEOUT_MSEC);
mTimer->start();
return true;
}
@@ -44,3 +45,8 @@ void DmsAsyncAction::sendTimeoutSignal()
{
emit timeout();
}
void DmsAsyncAction::setTimeoutInterval(int aMsec)
{
mTimer->setInterval(aMsec);
}

View File

@@ -26,6 +26,7 @@ public:
bool execute();
void setSendData(const QString& aData);
void setTimeoutInterval(int aMsec);
signals:
void timeout();