Browse Source

update exception and isHSRUStarted Func

mehrabi
mehrabi 3 years ago
parent
commit
1dc74f9d2a
  1. 3
      Plx/include/API/HonaAPI.h
  2. 11
      Plx/include/LowLevel/Exception/HonaAlreadyStartedException.h
  3. 24
      Plx/include/LowLevel/Exception/HonaBusyException.h
  4. 7
      Plx/include/LowLevel/Exception/HonaException.h
  5. 8
      Plx/include/LowLevel/HonaLowLevelAPI.h
  6. 81
      Plx/src/API/HonaAPI.cpp
  7. 98
      Plx/src/LowLevel/HonaLowLevelAPI.cpp
  8. 2
      Test/MainWindow.cpp

3
Plx/include/API/HonaAPI.h

@ -25,8 +25,6 @@ public:
{ {
} }
ApiResult isHsruStarted();
ApiResult isHiruStarted();
ApiResult deviceReset(); ApiResult deviceReset();
ApiResult setConfig(HonaSettings& settings); ApiResult setConfig(HonaSettings& settings);
@ -40,6 +38,7 @@ public:
signals: signals:
void honaDataResult(QList<HonaPacket> &honaPacketList, quint32 hsruLoss, quint32 Doa); void honaDataResult(QList<HonaPacket> &honaPacketList, quint32 hsruLoss, quint32 Doa);
}; };
#endif //HONAAPI_H #endif //HONAAPI_H

11
Plx/include/LowLevel/Exception/HonaAlreadyStartedException.h

@ -6,21 +6,16 @@
class HonaAlreadyStartedException : public std::exception class HonaAlreadyStartedException : public std::exception
{ {
private:
QString _str;
public: public:
HonaAlreadyStartedException(QString str) HonaAlreadyStartedException()
{ {
_str = str;
qDebug() << "HonaAlreadyStartedException " << str;
} }
virtual const char* what() const throw() virtual const char* what() const throw()
{ {
qDebug() << "HonaAlreadyStartedException return " << _str; return "";
return _str.toStdString().c_str();
} }
}; };

24
Plx/include/LowLevel/Exception/HonaBusyException.h

@ -1,24 +0,0 @@
#ifndef HONABUSYEXCEPTION_H
#define HONABUSYEXCEPTION_H
#include <QDebug>
#include <QString>
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

7
Plx/include/LowLevel/Exception/HonaException.h

@ -6,18 +6,15 @@
class HonaException : public std::exception class HonaException : public std::exception
{ {
private:
QString _str;
public: public:
HonaException(QString str) HonaException()
{ {
_str = str;
} }
virtual const char* what() const throw() virtual const char* what() const throw()
{ {
return _str.toStdString().c_str(); return "";
} }
}; };

8
Plx/include/LowLevel/HonaLowLevelAPI.h

@ -81,8 +81,6 @@ public:
{ {
} }
bool isHsruStarted();
bool isHiruStarted();
void deviceReset(); void deviceReset();
void setConfig(HonaSettings& settings); void setConfig(HonaSettings& settings);
@ -94,12 +92,6 @@ public:
void hsruStop(); void hsruStop();
void init(); void init();
bool getHsruIsStarted() const;
void setHsruIsStarted(bool hsruIsStarted);
bool getHiruIsStarted() const;
void setHiruIsStarted(bool hiruIsStarted);
private: private:
void writeSettingToRegisters(HonaSettings& settings); void writeSettingToRegisters(HonaSettings& settings);
void setConfig(); void setConfig();

81
Plx/src/API/HonaAPI.cpp

@ -1,75 +1,38 @@
#include "include/API/HonaAPI.h" #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() ApiResult HonaAPI::deviceReset()
{ {
try { try
{
_honaLowLevelAPI.deviceReset(); _honaLowLevelAPI.deviceReset();
} }
catch(HonaException ex) catch(HonaException ex)
{ {
return ApiResult::error; return ApiResult::error;
} }
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success; return ApiResult::success;
} }
/*************************************************************************************************/ /*************************************************************************************************/
ApiResult HonaAPI::setConfig(HonaSettings& settings) ApiResult HonaAPI::setConfig(HonaSettings& settings)
{ {
try { try
{
_honaLowLevelAPI.setConfig(settings); _honaLowLevelAPI.setConfig(settings);
} }
catch(HonaException ex) catch(HonaException ex)
{ {
return ApiResult::error; return ApiResult::error;
} }
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success; return ApiResult::success;
} }
/*************************************************************************************************/ /*************************************************************************************************/
ApiResult HonaAPI::getConfig(HonaSettings& settings) ApiResult HonaAPI::getConfig(HonaSettings& settings)
{ {
try { try
{
settings = _honaLowLevelAPI.getConfig(); settings = _honaLowLevelAPI.getConfig();
} }
catch(HonaException ex) catch(HonaException ex)
@ -83,7 +46,8 @@ ApiResult HonaAPI::getConfig(HonaSettings& settings)
/*************************************************************************************************/ /*************************************************************************************************/
ApiResult HonaAPI::getSwVersion(QString& swVerion) ApiResult HonaAPI::getSwVersion(QString& swVerion)
{ {
try { try
{
swVerion = _honaLowLevelAPI.getSwVersion(); swVerion = _honaLowLevelAPI.getSwVersion();
} }
catch(HonaException ex) catch(HonaException ex)
@ -97,7 +61,8 @@ ApiResult HonaAPI::getSwVersion(QString& swVerion)
/*************************************************************************************************/ /*************************************************************************************************/
ApiResult HonaAPI::getDeviceId(QString& deviceId) ApiResult HonaAPI::getDeviceId(QString& deviceId)
{ {
try { try
{
deviceId = _honaLowLevelAPI.getDeviceId(); deviceId = _honaLowLevelAPI.getDeviceId();
} }
catch(HonaException ex) catch(HonaException ex)
@ -111,7 +76,8 @@ ApiResult HonaAPI::getDeviceId(QString& deviceId)
/*************************************************************************************************/ /*************************************************************************************************/
ApiResult HonaAPI::hsruStart() ApiResult HonaAPI::hsruStart()
{ {
try { try
{
_honaLowLevelAPI.hsruStart(); _honaLowLevelAPI.hsruStart();
} }
catch(HonaException ex) catch(HonaException ex)
@ -120,7 +86,7 @@ ApiResult HonaAPI::hsruStart()
} }
catch(HonaAlreadyStartedException ex) catch(HonaAlreadyStartedException ex)
{ {
return ApiResult::error; return ApiResult::alreadyStarted;
} }
return ApiResult::success; return ApiResult::success;
@ -129,7 +95,8 @@ ApiResult HonaAPI::hsruStart()
/*************************************************************************************************/ /*************************************************************************************************/
ApiResult HonaAPI::hiruStart() ApiResult HonaAPI::hiruStart()
{ {
try { try
{
_honaLowLevelAPI.hiruStart(); _honaLowLevelAPI.hiruStart();
} }
catch(HonaException ex) catch(HonaException ex)
@ -138,7 +105,7 @@ ApiResult HonaAPI::hiruStart()
} }
catch(HonaAlreadyStartedException ex) catch(HonaAlreadyStartedException ex)
{ {
return ApiResult::error; return ApiResult::alreadyStarted;
} }
return ApiResult::success; return ApiResult::success;
@ -147,18 +114,14 @@ ApiResult HonaAPI::hiruStart()
/*************************************************************************************************/ /*************************************************************************************************/
ApiResult HonaAPI::hsruStop() ApiResult HonaAPI::hsruStop()
{ {
try { try
{
_honaLowLevelAPI.hsruStop(); _honaLowLevelAPI.hsruStop();
} }
catch(HonaException ex) catch(HonaException ex)
{ {
return ApiResult::error; return ApiResult::error;
} }
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success; return ApiResult::success;
} }
@ -167,18 +130,14 @@ ApiResult HonaAPI::init()
{ {
connect(&_honaLowLevelAPI, &HonaLowLevelAPI::lowLevelHonaData, this, &HonaAPI::honaDataResult,Qt::BlockingQueuedConnection); connect(&_honaLowLevelAPI, &HonaLowLevelAPI::lowLevelHonaData, this, &HonaAPI::honaDataResult,Qt::BlockingQueuedConnection);
try { try
{
_honaLowLevelAPI.init(); _honaLowLevelAPI.init();
} }
catch(HonaException ex) catch(HonaException ex)
{ {
return ApiResult::error; return ApiResult::error;
} }
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success; return ApiResult::success;
} }

98
Plx/src/LowLevel/HonaLowLevelAPI.cpp

@ -2,7 +2,10 @@
#include <include/LowLevel/Utils/Utils.h> #include <include/LowLevel/Utils/Utils.h>
#include "include/LowLevel/HonaLowLevelAPI.h" #include "include/LowLevel/HonaLowLevelAPI.h"
#include "include/Wrapper/PlxWrapper.h" #include "include/Wrapper/PlxWrapper.h"
#include <QDebug> #include <QDebug>
#include <QTimer>
quint32 HonaLowLevelAPI::packetLenInt4; quint32 HonaLowLevelAPI::packetLenInt4;
quint32 HonaLowLevelAPI::packetLenRes4; quint32 HonaLowLevelAPI::packetLenRes4;
quint32 HonaLowLevelAPI::packetLenSinglePulse; quint32 HonaLowLevelAPI::packetLenSinglePulse;
@ -21,29 +24,6 @@ quint32 HonaLowLevelAPI::nextInt123C;
quint32 HonaLowLevelAPI::nextRes123C; quint32 HonaLowLevelAPI::nextRes123C;
quint32 HonaLowLevelAPI::nextIntS; 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) HonaLowLevelAPI::HonaLowLevelAPI(QObject* parent) : QObject(parent)
{ {
@ -56,23 +36,11 @@ HonaLowLevelAPI::HonaLowLevelAPI(QObject* parent) : QObject(parent)
packetLenResS = 7; packetLenResS = 7;
} }
/*************************************************************************************************/
bool HonaLowLevelAPI::isHsruStarted()
{
return getHsruIsStarted();
}
/*************************************************************************************************/
bool HonaLowLevelAPI::isHiruStarted()
{
return getHiruIsStarted();
}
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::deviceReset() void HonaLowLevelAPI::deviceReset()
{ {
if(!plxWrapper.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)) if(!plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8))
{ {
throw HonaException("DeviceReadRegister Doesnt Occur"); throw HonaException();
} }
_honaSetting = settings; _honaSetting = settings;
writeSettingToRegisters(settings); writeSettingToRegisters(settings);
if(!plxWrapper.deviceWriteRegister(0x10000000, honaRegisterBuffer)) if(!plxWrapper.deviceWriteRegister(0x10000000, honaRegisterBuffer))
{ {
throw HonaException("DeviceWriteRegister Doesnt Occur"); throw HonaException();
} }
if(!plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8)) if(!plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8))
{ {
throw HonaException("DeviceReadRegister Doesnt Occur"); throw HonaException();
} }
} }
@ -117,13 +85,13 @@ QString HonaLowLevelAPI::getDeviceId()
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hsruStart() void HonaLowLevelAPI::hsruStart()
{ {
if(HonaLowLevelAPI::isHsruStarted()) if(_hsruIsStarted)
{ {
throw HonaAlreadyStartedException(" alreadyStarted"); throw HonaAlreadyStartedException();
} }
else else
{ {
setHsruIsStarted(true); _hsruIsStarted = true;
QtConcurrent::run(this, &HonaLowLevelAPI::hsruMainThread); QtConcurrent::run(this, &HonaLowLevelAPI::hsruMainThread);
} }
} }
@ -131,17 +99,23 @@ void HonaLowLevelAPI::hsruStart()
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hiruStart() void HonaLowLevelAPI::hiruStart()
{ {
if(!isHiruStarted())
throw HonaException("HiruStarted doesn't started "); if(_hiruIsStarted)
QtConcurrent::run(this, &HonaLowLevelAPI::hiruMainThread); {
setHiruIsStarted(true); throw HonaAlreadyStartedException();
}
else
{
_hiruIsStarted = true;
QtConcurrent::run(this, &HonaLowLevelAPI::hiruMainThread);
}
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hsruStop() void HonaLowLevelAPI::hsruStop()
{ {
if(isHiruStarted()) if(_hsruIsStarted)
setHsruIsStarted(false); _hsruIsStarted =false;
_hsruStopEvent.wakeAll(); _hsruStopEvent.wakeAll();
} }
@ -150,12 +124,12 @@ void HonaLowLevelAPI::init()
{ {
if(!plxWrapper.deviceInit(0X9054)) if(!plxWrapper.deviceInit(0X9054))
{ {
throw HonaException("Init Doesn't Occur"); throw HonaException();
} }
if(!plxWrapper.deviceOpen()) 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, 0xEFFFFFFF);
/************************************************************************/ /************************************************************************/
honaRegisterBuffer.insert(0, honaRegisterBuffer.insert(0,(honaRegisterBuffer.at(0) +
(honaRegisterBuffer.at(0) + (settings.hiruSettings.threshold & 0x00000FFF)));
(settings.hiruSettings.threshold & 0x00000FFF)));
honaRegisterBuffer.insert(1, settings.hsruSettings.honaInt123CTHR); honaRegisterBuffer.insert(1, settings.hsruSettings.honaInt123CTHR);
honaRegisterBuffer.insert(2, settings.hsruSettings.honaRes123CTHR); honaRegisterBuffer.insert(2, settings.hsruSettings.honaRes123CTHR);
@ -208,7 +181,7 @@ void HonaLowLevelAPI::hsruMainThread()
deviceReset(); deviceReset();
if(!plxWrapper.deviceEnableInterrupt()) if(!plxWrapper.deviceEnableInterrupt())
{ {
throw HonaException("DeviceEnableInterrupt Doesnt Occur"); throw HonaException();
} }
QtConcurrent::run(this, &HonaLowLevelAPI::hsruReadThread); QtConcurrent::run(this, &HonaLowLevelAPI::hsruReadThread);
@ -222,7 +195,7 @@ void HonaLowLevelAPI::hsruMainThread()
if(!plxWrapper.deviceDisableInterrupt()) if(!plxWrapper.deviceDisableInterrupt())
{ {
throw HonaException("DeviceEnableInterrupt Doesnt Occur"); throw HonaException();
} }
} }
@ -237,13 +210,13 @@ void HonaLowLevelAPI::hsruReadThread()
if(!plxWrapper.deviceWaitForInterrupt(1000)) if(!plxWrapper.deviceWaitForInterrupt(1000))
{ {
throw HonaException("DeviceWaitForInterrupt Doesnt Occur"); throw HonaException();
} }
honaPacketList.clear(); honaPacketList.clear();
_hsruLoss = 0; _hsruLoss = 0;
if(!plxWrapper.deviceOpenPCIChannel()) if(!plxWrapper.deviceOpenPCIChannel())
{ {
throw HonaException("DeviceOpenPCIChannel Doesnt Occur"); throw HonaException();
} }
_hsruLoss += hsruParserInt123C(hsruReadHonaBuffer(honaReceivers::int123C), _hsruLoss += hsruParserInt123C(hsruReadHonaBuffer(honaReceivers::int123C),
@ -258,11 +231,11 @@ void HonaLowLevelAPI::hsruReadThread()
honaPacketList); honaPacketList);
if(!plxWrapper.deviceClosePCIChannel()) if(!plxWrapper.deviceClosePCIChannel())
{ {
throw HonaException("DeviceClosePCIChannel Doesnt Occur"); throw HonaException();
} }
if(!plxWrapper.deviceEnableInterrupt()) if(!plxWrapper.deviceEnableInterrupt())
{ {
throw HonaException("DeviceEnableInterrupt Doesnt Occur"); throw HonaException();
} }
_mutex.lock(); _mutex.lock();
_hsruReadDone.wakeAll(); _hsruReadDone.wakeAll();
@ -317,7 +290,7 @@ quint32 HonaLowLevelAPI::hiruGetDOA()
quint32 Doa = 0; quint32 Doa = 0;
if(!plxWrapper.deviceReadRegister(0x30000004, Doa)) if(!plxWrapper.deviceReadRegister(0x30000004, Doa))
{ {
throw HonaException("DeviceReadRegister Doesnt Occur"); throw HonaException();
} }
Doa = Doa & 0x0000FFFF; Doa = Doa & 0x0000FFFF;
return Doa; return Doa;
@ -908,17 +881,18 @@ QVector<quint32> HonaLowLevelAPI::hsruReadHonaBuffer(honaReceivers receiver)
else if(receiver == honaReceivers::singlePulse) else if(receiver == honaReceivers::singlePulse)
address = 0XB0000000; address = 0XB0000000;
else else
throw HonaException("honaReceivers is Not Valid"); throw HonaException();
if(!plxWrapper.deviceReadMemory(address, honaData, honaData.size())) if(!plxWrapper.deviceReadMemory(address, honaData, honaData.size()))
{ {
throw HonaException("DeviceReadMemory Doesnt Occur"); throw HonaException();
} }
// qDebug() << " hsruReadHonaBuffer receiver "<< receiver; // qDebug() << " hsruReadHonaBuffer receiver "<< receiver;
// for(auto i = 0 ; i < 10; i++) // for(auto i = 0 ; i < 10; i++)
// qDebug() << "[" << i << "] " << "0x" << QString::number(honaData[i], 16); // qDebug() << "[" << i << "] " << "0x" << QString::number(honaData[i], 16);
// qDebug() << "------------------------------------------------------------"; // qDebug() << "------------------------------------------------------------";
return honaData; return honaData;
} }

2
Test/MainWindow.cpp

@ -2,6 +2,7 @@
#include "ui_MainWindow.h" #include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget* parent) MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
@ -32,7 +33,6 @@ void MainWindow::honaDataResultUi(QList<HonaPacket> &honaPacketList, quint32 hsr
_str += "\n[getCodeL] :" + QString::number(honaPacketList[i].getCodeL(), 16); _str += "\n[getCodeL] :" + QString::number(honaPacketList[i].getCodeL(), 16);
_str += "\n[getCodeM] :" + QString::number(honaPacketList[i].getCodeM(), 16); _str += "\n[getCodeM] :" + QString::number(honaPacketList[i].getCodeM(), 16);
} }
ui->dataFromMemory->setText(_str); ui->dataFromMemory->setText(_str);
} }

Loading…
Cancel
Save