Change pump action to AsyncAion from SyncAction.
This commit is contained in:
@@ -37,6 +37,7 @@ namespace
|
||||
const int PREVIEW_IMAGE_WH = 140;
|
||||
const unsigned int GET_TEMPERATURE_TIME = 60000;
|
||||
const int SHUT_DOWN_TIMEOUT = 180000;//3 minitues
|
||||
const int PUMP_TIMEOUT = 3000;//3 seconds
|
||||
const QString DEFAULT_DMS_START_FAILED = "Dms start failed.";
|
||||
const QString RECON_TRANSFER_PATH = "/home/krad/TestStore";
|
||||
|
||||
@@ -118,7 +119,6 @@ void DeviceManager::initDevice()
|
||||
mGetTransferProgressAction = new DmsSyncAction(USRV_XFR, ACT_XFR_PROGRESS_PASSIVE, this, "responseGetTransferProgress(const QString&)", this);
|
||||
mCEScanAction = new DmsSyncAction(USRV_SCAN, ACT_SCAN_CE, this, "responseCEScan(const QString&)", this);
|
||||
mGetCEStatusAction = new DmsSyncAction(USRV_SCAN, ACT_SCAN_CE_STATUS, this, "responseGetCEStatus(const QString&)", this);
|
||||
mPumpControlAction = new DmsSyncAction(USRV_CONTROL, ACT_CTL_PUMP, this, "responsePumpControl(const QString&)", this);
|
||||
mSetSimulatorModeAction = new DmsSyncAction(USRV_SCAN, ACT_SCAN_SIMULATOR, this, "responseSetSimulatorMode(const QString&)", this);
|
||||
mSetHeartBeatAction = new DmsSyncAction(USRV_INFOCFG, ACT_IFCFG_HBCFG, this, "responseSetHeartBeat(const QString&)", this);
|
||||
|
||||
@@ -129,6 +129,8 @@ void DeviceManager::initDevice()
|
||||
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);
|
||||
mPumpControlAction = new DmsAsyncAction(USRV_CONTROL, ACT_CTL_PUMP, this, "responsePumpControl(const QString&)", this);
|
||||
mPumpControlAction->setTimeoutInterval(PUMP_TIMEOUT);
|
||||
connect(mGetScanProgressAction, &DmsAsyncAction::timeout, this, &DeviceManager::scanTimeout);
|
||||
connect(mShutDownAction, &DmsAsyncAction::timeout, this, &DeviceManager::shutdownDmsFailed);
|
||||
|
||||
@@ -603,6 +605,7 @@ void DeviceManager::processReceiveDMSInfoResult(int aServerID, int aActionID, co
|
||||
{
|
||||
case ACT_CTL_PUMP:
|
||||
emit responsePumpControl(aContents);
|
||||
processPumpResult(aContents);
|
||||
break;
|
||||
case ACT_CTL_PWRDOWN:
|
||||
emit responseShutDown(aContents);
|
||||
@@ -1089,19 +1092,26 @@ bool DeviceManager::getCEStatus()
|
||||
void DeviceManager::controlDrainage(const QString& aCode)
|
||||
{
|
||||
mPumpControlAction->setSendData(QString("{\"pumb\":%1}").arg(aCode));
|
||||
auto result = mPumpControlAction->execute();
|
||||
if(result.mIsSucessful)
|
||||
if(!mPumpControlAction->execute())
|
||||
{
|
||||
QJsonObject jsonObj = toJsonObject(result.mData);
|
||||
if(jsonObj["code"].toInt() == 0 )
|
||||
{
|
||||
emit startPumpControlResult(true);
|
||||
return;
|
||||
}
|
||||
emit startPumpControlResult(false);
|
||||
QString msg = tr("Open pump failed.");
|
||||
THROW_ERROR(msg);
|
||||
}
|
||||
emit startPumpControlResult(false);
|
||||
QString msg = tr("Open pump failed.");
|
||||
THROW_ERROR(msg);
|
||||
}
|
||||
|
||||
void DeviceManager::processPumpResult(const QString& aResponse)
|
||||
{
|
||||
QJsonObject jsonObj = toJsonObject(aResponse);
|
||||
if(jsonObj["code"].toInt() == 0 )
|
||||
{
|
||||
emit startPumpControlResult(true);
|
||||
return;
|
||||
}
|
||||
|
||||
emit startPumpControlResult(false);
|
||||
QString msg = tr("Open pump failed.");
|
||||
THROW_ERROR(msg);
|
||||
}
|
||||
|
||||
void DeviceManager::updateReconConnectionState(bool aIsConnected)
|
||||
|
||||
@@ -117,6 +117,7 @@ private:
|
||||
void processDeviceTemperature(const QString& aResponseTemperature);
|
||||
void processTransferProgress(const QString& aProgress);
|
||||
void processShutDownDms(const QString& aResponse);
|
||||
void processPumpResult(const QString& aResponse);
|
||||
|
||||
void insertEmptyScanRecord();
|
||||
void insertScanRecord();
|
||||
@@ -199,7 +200,6 @@ private:
|
||||
DmsSyncAction* mTransferAction = nullptr;
|
||||
DmsSyncAction* mGetTransferProgressAction = nullptr;
|
||||
DmsSyncAction* mGetCEStatusAction = nullptr;
|
||||
DmsSyncAction* mPumpControlAction = nullptr;
|
||||
DmsSyncAction* mSetSimulatorModeAction = nullptr;
|
||||
DmsSyncAction* mSetHeartBeatAction = nullptr;
|
||||
|
||||
@@ -208,6 +208,7 @@ private:
|
||||
DmsAsyncAction* mGetSoftwareVersionAction = nullptr;
|
||||
DmsAsyncAction* mStopTransferAction = nullptr;
|
||||
DmsAsyncAction* mShutDownAction = nullptr;
|
||||
DmsAsyncAction* mPumpControlAction = nullptr;
|
||||
|
||||
friend class InfoReceiveWorker;
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ DmsAsyncAction::DmsAsyncAction(int aServerId, int aActionId, QObject* aObject, c
|
||||
, mResponseSignal(aResponseSignal)
|
||||
, mSendData()
|
||||
, mIsResponsed(false)
|
||||
, mIsRunning(false)
|
||||
{
|
||||
mTimer->setSingleShot(true);
|
||||
mTimer->setInterval(TIMEOUT_MSEC);
|
||||
@@ -30,9 +31,14 @@ DmsAsyncAction::~DmsAsyncAction()
|
||||
disconnect(mObject, ("2" + mResponseSignal).toStdString().c_str(), mTimer, SLOT(stop()));
|
||||
}
|
||||
|
||||
void DmsAsyncAction::setSendData(const QString& aData)
|
||||
{
|
||||
mSendData = aData;
|
||||
}
|
||||
|
||||
bool DmsAsyncAction::execute()
|
||||
{
|
||||
mIsResponsed = false;
|
||||
mIsResponsed = false;
|
||||
QByteArray byteArray = mSendData.toUtf8();
|
||||
uint8_t* data = reinterpret_cast<uint8_t*>(byteArray.data());
|
||||
if(dmsmq_send(mServerId, mActionId, data, byteArray.size()) < 0)
|
||||
@@ -45,7 +51,7 @@ bool DmsAsyncAction::execute()
|
||||
|
||||
void DmsAsyncAction::sendTimeoutSignal()
|
||||
{
|
||||
if(!mIsResponsed)
|
||||
if(!mIsResponsed)
|
||||
{
|
||||
emit timeout();
|
||||
}
|
||||
@@ -58,7 +64,7 @@ void DmsAsyncAction::setTimeoutInterval(int aMsec)
|
||||
|
||||
void DmsAsyncAction::responsed()
|
||||
{
|
||||
if(mTimer->isActive())
|
||||
if(mTimer->isActive())
|
||||
{
|
||||
mIsResponsed = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user