From 1dc74f9d2a23ed84a8c3d4b6ca8219dca425ef7f Mon Sep 17 00:00:00 2001 From: mehrabi Date: Sun, 19 Dec 2021 07:39:14 -0500 Subject: [PATCH] update exception and isHSRUStarted Func --- Plx/include/API/HonaAPI.h | 3 +- .../Exception/HonaAlreadyStartedException.h | 11 +-- .../LowLevel/Exception/HonaBusyException.h | 24 ----- .../LowLevel/Exception/HonaException.h | 7 +- Plx/include/LowLevel/HonaLowLevelAPI.h | 8 -- Plx/src/API/HonaAPI.cpp | 81 ++++----------- Plx/src/LowLevel/HonaLowLevelAPI.cpp | 98 +++++++------------ Test/MainWindow.cpp | 2 +- 8 files changed, 63 insertions(+), 171 deletions(-) delete mode 100755 Plx/include/LowLevel/Exception/HonaBusyException.h diff --git a/Plx/include/API/HonaAPI.h b/Plx/include/API/HonaAPI.h index a4db1fb..92f940f 100644 --- a/Plx/include/API/HonaAPI.h +++ b/Plx/include/API/HonaAPI.h @@ -25,8 +25,6 @@ public: { } - ApiResult isHsruStarted(); - ApiResult isHiruStarted(); ApiResult deviceReset(); ApiResult setConfig(HonaSettings& settings); @@ -40,6 +38,7 @@ public: signals: void honaDataResult(QList &honaPacketList, quint32 hsruLoss, quint32 Doa); + }; #endif //HONAAPI_H diff --git a/Plx/include/LowLevel/Exception/HonaAlreadyStartedException.h b/Plx/include/LowLevel/Exception/HonaAlreadyStartedException.h index 32c5d19..65ad341 100755 --- a/Plx/include/LowLevel/Exception/HonaAlreadyStartedException.h +++ b/Plx/include/LowLevel/Exception/HonaAlreadyStartedException.h @@ -6,21 +6,16 @@ class HonaAlreadyStartedException : public std::exception { -private: - QString _str; + public: - HonaAlreadyStartedException(QString str) + HonaAlreadyStartedException() { - _str = str; - qDebug() << "HonaAlreadyStartedException " << str; } virtual const char* what() const throw() { - qDebug() << "HonaAlreadyStartedException return " << _str; - - return _str.toStdString().c_str(); + return ""; } }; diff --git a/Plx/include/LowLevel/Exception/HonaBusyException.h b/Plx/include/LowLevel/Exception/HonaBusyException.h deleted file mode 100755 index eb031d7..0000000 --- a/Plx/include/LowLevel/Exception/HonaBusyException.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef HONABUSYEXCEPTION_H -#define HONABUSYEXCEPTION_H - -#include -#include - -class HonaBusyException : public std::exception -{ -private: - QString _str; - -public: - HonaBusyException(QString str) - { - _str = str; - } - - virtual const char* what() const throw() - { - return _str.toStdString().c_str(); - } -}; - -#endif //HONABUSYEXCEPTION_H diff --git a/Plx/include/LowLevel/Exception/HonaException.h b/Plx/include/LowLevel/Exception/HonaException.h index ab5b04e..fe78556 100755 --- a/Plx/include/LowLevel/Exception/HonaException.h +++ b/Plx/include/LowLevel/Exception/HonaException.h @@ -6,18 +6,15 @@ class HonaException : public std::exception { -private: - QString _str; public: - HonaException(QString str) + HonaException() { - _str = str; } virtual const char* what() const throw() { - return _str.toStdString().c_str(); + return ""; } }; diff --git a/Plx/include/LowLevel/HonaLowLevelAPI.h b/Plx/include/LowLevel/HonaLowLevelAPI.h index 6bc66ff..1515cdb 100755 --- a/Plx/include/LowLevel/HonaLowLevelAPI.h +++ b/Plx/include/LowLevel/HonaLowLevelAPI.h @@ -81,8 +81,6 @@ public: { } - bool isHsruStarted(); - bool isHiruStarted(); void deviceReset(); void setConfig(HonaSettings& settings); @@ -94,12 +92,6 @@ public: void hsruStop(); void init(); - bool getHsruIsStarted() const; - void setHsruIsStarted(bool hsruIsStarted); - - bool getHiruIsStarted() const; - void setHiruIsStarted(bool hiruIsStarted); - private: void writeSettingToRegisters(HonaSettings& settings); void setConfig(); diff --git a/Plx/src/API/HonaAPI.cpp b/Plx/src/API/HonaAPI.cpp index dbb5ca9..42b1565 100644 --- a/Plx/src/API/HonaAPI.cpp +++ b/Plx/src/API/HonaAPI.cpp @@ -1,75 +1,38 @@ #include "include/API/HonaAPI.h" -/*************************************************************************************************/ -ApiResult HonaAPI::isHsruStarted() -{ - try { - if(_honaLowLevelAPI.isHsruStarted()) - return ApiResult::success; - } - catch(HonaException ex) - { - return ApiResult::error; - } - - return ApiResult::success; -} - -/*************************************************************************************************/ -ApiResult HonaAPI::isHiruStarted() -{ - try { - if(_honaLowLevelAPI.isHiruStarted()) - return ApiResult::success; - } - catch(HonaException ex) - { - return ApiResult::error; - } - - return ApiResult::success; -} - /*************************************************************************************************/ ApiResult HonaAPI::deviceReset() { - try { + try + { _honaLowLevelAPI.deviceReset(); } catch(HonaException ex) { return ApiResult::error; } - catch(HonaAlreadyStartedException ex) - { - return ApiResult::error; - } - return ApiResult::success; } /*************************************************************************************************/ ApiResult HonaAPI::setConfig(HonaSettings& settings) { - try { + try + { _honaLowLevelAPI.setConfig(settings); } catch(HonaException ex) { return ApiResult::error; } - catch(HonaAlreadyStartedException ex) - { - return ApiResult::error; - } - return ApiResult::success; } /*************************************************************************************************/ ApiResult HonaAPI::getConfig(HonaSettings& settings) { - try { + try + { settings = _honaLowLevelAPI.getConfig(); } catch(HonaException ex) @@ -83,7 +46,8 @@ ApiResult HonaAPI::getConfig(HonaSettings& settings) /*************************************************************************************************/ ApiResult HonaAPI::getSwVersion(QString& swVerion) { - try { + try + { swVerion = _honaLowLevelAPI.getSwVersion(); } catch(HonaException ex) @@ -97,7 +61,8 @@ ApiResult HonaAPI::getSwVersion(QString& swVerion) /*************************************************************************************************/ ApiResult HonaAPI::getDeviceId(QString& deviceId) { - try { + try + { deviceId = _honaLowLevelAPI.getDeviceId(); } catch(HonaException ex) @@ -111,7 +76,8 @@ ApiResult HonaAPI::getDeviceId(QString& deviceId) /*************************************************************************************************/ ApiResult HonaAPI::hsruStart() { - try { + try + { _honaLowLevelAPI.hsruStart(); } catch(HonaException ex) @@ -120,7 +86,7 @@ ApiResult HonaAPI::hsruStart() } catch(HonaAlreadyStartedException ex) { - return ApiResult::error; + return ApiResult::alreadyStarted; } return ApiResult::success; @@ -129,7 +95,8 @@ ApiResult HonaAPI::hsruStart() /*************************************************************************************************/ ApiResult HonaAPI::hiruStart() { - try { + try + { _honaLowLevelAPI.hiruStart(); } catch(HonaException ex) @@ -138,7 +105,7 @@ ApiResult HonaAPI::hiruStart() } catch(HonaAlreadyStartedException ex) { - return ApiResult::error; + return ApiResult::alreadyStarted; } return ApiResult::success; @@ -147,18 +114,14 @@ ApiResult HonaAPI::hiruStart() /*************************************************************************************************/ ApiResult HonaAPI::hsruStop() { - try { + try + { _honaLowLevelAPI.hsruStop(); } catch(HonaException ex) { return ApiResult::error; } - catch(HonaAlreadyStartedException ex) - { - return ApiResult::error; - } - return ApiResult::success; } @@ -167,18 +130,14 @@ ApiResult HonaAPI::init() { connect(&_honaLowLevelAPI, &HonaLowLevelAPI::lowLevelHonaData, this, &HonaAPI::honaDataResult,Qt::BlockingQueuedConnection); - try { + try + { _honaLowLevelAPI.init(); } catch(HonaException ex) { return ApiResult::error; } - catch(HonaAlreadyStartedException ex) - { - return ApiResult::error; - } - return ApiResult::success; } diff --git a/Plx/src/LowLevel/HonaLowLevelAPI.cpp b/Plx/src/LowLevel/HonaLowLevelAPI.cpp index 9d0cf28..3d371b7 100755 --- a/Plx/src/LowLevel/HonaLowLevelAPI.cpp +++ b/Plx/src/LowLevel/HonaLowLevelAPI.cpp @@ -2,7 +2,10 @@ #include #include "include/LowLevel/HonaLowLevelAPI.h" #include "include/Wrapper/PlxWrapper.h" + #include +#include + quint32 HonaLowLevelAPI::packetLenInt4; quint32 HonaLowLevelAPI::packetLenRes4; quint32 HonaLowLevelAPI::packetLenSinglePulse; @@ -21,29 +24,6 @@ quint32 HonaLowLevelAPI::nextInt123C; quint32 HonaLowLevelAPI::nextRes123C; quint32 HonaLowLevelAPI::nextIntS; -bool HonaLowLevelAPI::getHsruIsStarted() const -{ - return _hsruIsStarted; -} - -/*************************************************************************************************/ -void HonaLowLevelAPI::setHsruIsStarted(bool hsruIsStarted) -{ - _hsruIsStarted = hsruIsStarted; -} - -/*************************************************************************************************/ -bool HonaLowLevelAPI::getHiruIsStarted() const -{ - return _hiruIsStarted; -} - -/*************************************************************************************************/ -void HonaLowLevelAPI::setHiruIsStarted(bool hiruIsStarted) -{ - _hiruIsStarted = hiruIsStarted; -} - /*************************************************************************************************/ HonaLowLevelAPI::HonaLowLevelAPI(QObject* parent) : QObject(parent) { @@ -56,23 +36,11 @@ HonaLowLevelAPI::HonaLowLevelAPI(QObject* parent) : QObject(parent) packetLenResS = 7; } -/*************************************************************************************************/ -bool HonaLowLevelAPI::isHsruStarted() -{ - return getHsruIsStarted(); -} - -/*************************************************************************************************/ -bool HonaLowLevelAPI::isHiruStarted() -{ - return getHiruIsStarted(); -} - /*************************************************************************************************/ void HonaLowLevelAPI::deviceReset() { if(!plxWrapper.deviceReset()) - throw HonaException("Reset Doesnt Occur"); + throw HonaException(); } /*************************************************************************************************/ @@ -80,18 +48,18 @@ void HonaLowLevelAPI::setConfig(HonaSettings& settings) { if(!plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8)) { - throw HonaException("DeviceReadRegister Doesnt Occur"); + throw HonaException(); } _honaSetting = settings; writeSettingToRegisters(settings); if(!plxWrapper.deviceWriteRegister(0x10000000, honaRegisterBuffer)) { - throw HonaException("DeviceWriteRegister Doesnt Occur"); + throw HonaException(); } if(!plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8)) { - throw HonaException("DeviceReadRegister Doesnt Occur"); + throw HonaException(); } } @@ -117,13 +85,13 @@ QString HonaLowLevelAPI::getDeviceId() /*************************************************************************************************/ void HonaLowLevelAPI::hsruStart() { - if(HonaLowLevelAPI::isHsruStarted()) + if(_hsruIsStarted) { - throw HonaAlreadyStartedException(" alreadyStarted"); + throw HonaAlreadyStartedException(); } else { - setHsruIsStarted(true); + _hsruIsStarted = true; QtConcurrent::run(this, &HonaLowLevelAPI::hsruMainThread); } } @@ -131,17 +99,23 @@ void HonaLowLevelAPI::hsruStart() /*************************************************************************************************/ void HonaLowLevelAPI::hiruStart() { - if(!isHiruStarted()) - throw HonaException("HiruStarted doesn't started "); - QtConcurrent::run(this, &HonaLowLevelAPI::hiruMainThread); - setHiruIsStarted(true); + + if(_hiruIsStarted) + { + throw HonaAlreadyStartedException(); + } + else + { + _hiruIsStarted = true; + QtConcurrent::run(this, &HonaLowLevelAPI::hiruMainThread); + } } /*************************************************************************************************/ void HonaLowLevelAPI::hsruStop() { - if(isHiruStarted()) - setHsruIsStarted(false); + if(_hsruIsStarted) + _hsruIsStarted =false; _hsruStopEvent.wakeAll(); } @@ -150,12 +124,12 @@ void HonaLowLevelAPI::init() { if(!plxWrapper.deviceInit(0X9054)) { - throw HonaException("Init Doesn't Occur"); + throw HonaException(); } if(!plxWrapper.deviceOpen()) { - throw HonaException("deviceOpen Doesn't Occur"); + throw HonaException(); } } @@ -181,9 +155,8 @@ void HonaLowLevelAPI::writeSettingToRegisters(HonaSettings& settings) honaRegisterBuffer.insert(0, 0xEFFFFFFF); /************************************************************************/ - honaRegisterBuffer.insert(0, - (honaRegisterBuffer.at(0) + - (settings.hiruSettings.threshold & 0x00000FFF))); + honaRegisterBuffer.insert(0,(honaRegisterBuffer.at(0) + + (settings.hiruSettings.threshold & 0x00000FFF))); honaRegisterBuffer.insert(1, settings.hsruSettings.honaInt123CTHR); honaRegisterBuffer.insert(2, settings.hsruSettings.honaRes123CTHR); @@ -208,7 +181,7 @@ void HonaLowLevelAPI::hsruMainThread() deviceReset(); if(!plxWrapper.deviceEnableInterrupt()) { - throw HonaException("DeviceEnableInterrupt Doesnt Occur"); + throw HonaException(); } QtConcurrent::run(this, &HonaLowLevelAPI::hsruReadThread); @@ -222,7 +195,7 @@ void HonaLowLevelAPI::hsruMainThread() if(!plxWrapper.deviceDisableInterrupt()) { - throw HonaException("DeviceEnableInterrupt Doesnt Occur"); + throw HonaException(); } } @@ -237,13 +210,13 @@ void HonaLowLevelAPI::hsruReadThread() if(!plxWrapper.deviceWaitForInterrupt(1000)) { - throw HonaException("DeviceWaitForInterrupt Doesnt Occur"); + throw HonaException(); } honaPacketList.clear(); _hsruLoss = 0; if(!plxWrapper.deviceOpenPCIChannel()) { - throw HonaException("DeviceOpenPCIChannel Doesnt Occur"); + throw HonaException(); } _hsruLoss += hsruParserInt123C(hsruReadHonaBuffer(honaReceivers::int123C), @@ -258,11 +231,11 @@ void HonaLowLevelAPI::hsruReadThread() honaPacketList); if(!plxWrapper.deviceClosePCIChannel()) { - throw HonaException("DeviceClosePCIChannel Doesnt Occur"); + throw HonaException(); } if(!plxWrapper.deviceEnableInterrupt()) { - throw HonaException("DeviceEnableInterrupt Doesnt Occur"); + throw HonaException(); } _mutex.lock(); _hsruReadDone.wakeAll(); @@ -317,7 +290,7 @@ quint32 HonaLowLevelAPI::hiruGetDOA() quint32 Doa = 0; if(!plxWrapper.deviceReadRegister(0x30000004, Doa)) { - throw HonaException("DeviceReadRegister Doesnt Occur"); + throw HonaException(); } Doa = Doa & 0x0000FFFF; return Doa; @@ -908,17 +881,18 @@ QVector HonaLowLevelAPI::hsruReadHonaBuffer(honaReceivers receiver) else if(receiver == honaReceivers::singlePulse) address = 0XB0000000; else - throw HonaException("honaReceivers is Not Valid"); + throw HonaException(); if(!plxWrapper.deviceReadMemory(address, honaData, honaData.size())) { - throw HonaException("DeviceReadMemory Doesnt Occur"); + throw HonaException(); } // qDebug() << " hsruReadHonaBuffer receiver "<< receiver; // for(auto i = 0 ; i < 10; i++) // qDebug() << "[" << i << "] " << "0x" << QString::number(honaData[i], 16); // qDebug() << "------------------------------------------------------------"; + return honaData; } diff --git a/Test/MainWindow.cpp b/Test/MainWindow.cpp index 6c4fadf..98316d1 100755 --- a/Test/MainWindow.cpp +++ b/Test/MainWindow.cpp @@ -2,6 +2,7 @@ #include "ui_MainWindow.h" + MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -32,7 +33,6 @@ void MainWindow::honaDataResultUi(QList &honaPacketList, quint32 hsr _str += "\n[getCodeL] :" + QString::number(honaPacketList[i].getCodeL(), 16); _str += "\n[getCodeM] :" + QString::number(honaPacketList[i].getCodeM(), 16); } - ui->dataFromMemory->setText(_str); }