Browse Source

work on honaapilowlevel honaapi

heydari
Alireza 3 years ago
parent
commit
e806f5dca5
  1. 13
      Plx/Plx.pro
  2. 40
      Plx/include/API/HonaAPI.h
  3. 1
      Plx/include/LowLevel/HonaLowLevelAPI.h
  4. 6
      Plx/include/LowLevel/HonaPacket.h
  5. 62
      Plx/include/LowLevel/HonaPacket.h.autosave
  6. 2
      Plx/include/LowLevel/Utils/Utils.h
  7. 183
      Plx/src/API/HonaAPI.cpp
  8. 81
      Plx/src/LowLevel/HonaLowLevelAPI.cpp
  9. 3
      Test/MainWindow.cpp
  10. 8
      Test/MainWindow.h
  11. 44
      Test/MainWindow.ui
  12. 5
      Test/Test.pro

13
Plx/Plx.pro

@ -17,12 +17,15 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
$$files(*.cpp, true) \ \
src/Wrapper/PlxWrapper.cpp
$$files(*.cpp, true) \ \ \
HEADERS += \
$$files(*.h, true) \
$$files(*.h, true) \ \ \
INCLUDEPATH += $$PWD/include
@ -32,3 +35,7 @@ unix {
target.path = $$[QT_INSTALL_PLUGINS]/generic
}
!isEmpty(target.path): INSTALLS += target

40
Plx/include/API/HonaAPI.h

@ -0,0 +1,40 @@
#ifndef HONAAPI_H
#define HONAAPI_H
#include <QObject>
#include "LowLevel/Setting/Setting.h"
#include "include/LowLevel/Exception/HonaAlreadyStartedException.h"
#include "include/LowLevel/Exception/HonaException.h"
#include "include/LowLevel/Utils/Utils.h"
#include "include/LowLevel/HonaLowLevelAPI.h"
class HonaAPI : public QObject
{
Q_OBJECT
private:
HonaLowLevelAPI _honaLowLevelAPI;
public:
explicit HonaAPI(QObject* parent = nullptr);
ApiResult isHsruStarted();
ApiResult isHiruStarted();
ApiResult deviceReset();
ApiResult setConfig(HonaSettings& settings);
ApiResult getConfig(HonaSettings& settings);
ApiResult getSwVersion(QString& swVerion);
ApiResult getDeviceId(QString& deviceId);
ApiResult hsruStart();
ApiResult hiruStart();
ApiResult hsruStop();
ApiResult init();
signals:
//uncrustify off
public slots:
//uncrustify on
};
#endif //HONAAPI_H

1
Plx/include/LowLevel/HonaLowLevelAPI.h

@ -89,6 +89,7 @@ public:
QString getDeviceId();
void hsruStart();
void hiruStart();
void hsruStop();
void init();
bool getHsruIsStarted() const;

6
Plx/include/LowLevel/HonaPacket.h

@ -20,12 +20,13 @@ private:
quint32 m_Code;
quint32 m_CodeL;
quint32 m_CodeM;
quint8 m4Status;
public:
HonaPacket();
/******************************************************************/
honaPacketType getPacketType();
void setPacketType(honaPacketType& temp);
void setPacketType(honaPacketType temp);
/******************************************************************/
quint32 getPacketNumber();
void setPacketNumber(quint32 temp);
@ -57,6 +58,9 @@ public:
quint32 getCodeM();
void setCodeM(quint32 temp);
/******************************************************************/
quint8 getm4Status();
void setm4Status(quint8 temp);
/******************************************************************/
};
#endif //HONAPACKET_H

62
Plx/include/LowLevel/HonaPacket.h.autosave

@ -1,62 +0,0 @@
#ifndef HONAPACKET_H
#define HONAPACKET_H
#include <QtGlobal>
#include "include/LowLevel/Utils/Utils.h"
class HonaPacket
{
private:
qreal toaClock;
honaPacketType m_PacketType;
quint32 m_PacketNumber;
qulonglong m_Toa;
quint32 m_Doa;
quint32 m_Pa1;
quint32 m_Pa2;
quint32 m_Pa3;
quint32 m_Pa4;
quint32 m_Code;
quint32 m_CodeL;
quint32 m_CodeM;
public:
HonaPacket();
/******************************************************************/
honaPacketType getPacketType();
void setPacketType(honaPacketType temp);
/******************************************************************/
quint32 getPacketNumber();
void setPacketNumber(quint32 temp);
/******************************************************************/
qulonglong getToa();
void setToa(qulonglong temp);
/******************************************************************/
quint32 getDoa();
void setDoa(quint32 temp);
/******************************************************************/
quint32 getPa1();
void setPa1(quint32 temp);
/******************************************************************/
quint32 getPa2();
void setPa2(quint32 temp);
/******************************************************************/
quint32 getPa3();
void setPa3(quint32 temp);
/******************************************************************/
quint32 getPa4();
void setPa4(quint32 temp);
/******************************************************************/
quint32 getCode();
void setCode(quint32 temp);
/******************************************************************/
quint32 getCodeL();
void setCodeL(quint32 temp);
/******************************************************************/
quint32 getCodeM();
void setCodeM(quint32 temp);
/******************************************************************/
};
#endif //HONAPACKET_H

2
Plx/include/LowLevel/Utils/Utils.h

@ -4,7 +4,7 @@
#include <QtCore>
/*************************************************************************************************/
enum apiResult : quint8
enum ApiResult : quint8
{
success,
alreadyStarted,

183
Plx/src/API/HonaAPI.cpp

@ -0,0 +1,183 @@
#include "include/API/HonaAPI.h"
HonaAPI::HonaAPI(QObject* parent) : QObject(parent)
{
}
/*************************************************************************************************/
ApiResult HonaAPI::isHsruStarted()
{
try {
if(_honaLowLevelAPI.isHsruStarted())
return ApiResult::success;
}
catch(HonaException ex)
{
return ApiResult::error;
}
}
/*************************************************************************************************/
ApiResult HonaAPI::isHiruStarted()
{
try {
if(_honaLowLevelAPI.isHiruStarted())
return ApiResult::success;
}
catch(HonaException ex)
{
return ApiResult::error;
}
}
/*************************************************************************************************/
ApiResult HonaAPI::deviceReset()
{
try {
_honaLowLevelAPI.deviceReset();
}
catch(HonaException ex)
{
return ApiResult::error;
}
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success;
}
/*************************************************************************************************/
ApiResult HonaAPI::setConfig(HonaSettings& settings)
{
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 {
settings = _honaLowLevelAPI.getConfig();
}
catch(HonaException ex)
{
return ApiResult::error;
}
return ApiResult::success;
}
/*************************************************************************************************/
ApiResult HonaAPI::getSwVersion(QString& swVerion)
{
try {
swVerion = _honaLowLevelAPI.getSwVersion();
}
catch(HonaException ex)
{
return ApiResult::error;
}
return ApiResult::success;
}
/*************************************************************************************************/
ApiResult HonaAPI::getDeviceId(QString& deviceId)
{
try {
deviceId = _honaLowLevelAPI.getDeviceId();
}
catch(HonaException ex)
{
return ApiResult::error;
}
return ApiResult::success;
}
/*************************************************************************************************/
ApiResult HonaAPI::hsruStart()
{
try {
_honaLowLevelAPI.hsruStart();
}
catch(HonaException ex)
{
return ApiResult::error;
}
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success;
}
/*************************************************************************************************/
ApiResult HonaAPI::hiruStart()
{
try {
_honaLowLevelAPI.hiruStart();
}
catch(HonaException ex)
{
return ApiResult::error;
}
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success;
}
/*************************************************************************************************/
ApiResult HonaAPI::hsruStop()
{
try {
_honaLowLevelAPI.hsruStop();
}
catch(HonaException ex)
{
return ApiResult::error;
}
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success;
}
/*************************************************************************************************/
ApiResult HonaAPI::init()
{
try {
_honaLowLevelAPI.init();
}
catch(HonaException ex)
{
return ApiResult::error;
}
catch(HonaAlreadyStartedException ex)
{
return ApiResult::error;
}
return ApiResult::success;
}
/*************************************************************************************************/

81
Plx/src/LowLevel/HonaLowLevelAPI.cpp

@ -56,17 +56,27 @@ bool HonaLowLevelAPI::isHiruStarted()
void HonaLowLevelAPI::deviceReset()
{
if(!plxWrapper.deviceReset())
throw HonaAlreadyStartedException("reset Doesnt Occur");
throw HonaAlreadyStartedException("Reset Doesnt Occur");
}
/*************************************************************************************************/
void HonaLowLevelAPI::setConfig(HonaSettings& settings)
{
plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8);
if(!plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8))
{
throw HonaAlreadyStartedException("DeviceReadRegister Doesnt Occur");
}
_honaSetting = settings;
writeSettingToRegisters(settings);
plxWrapper.deviceWriteRegister(0x10000000, honaRegisterBuffer);
plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8);
if(!plxWrapper.deviceWriteRegister(0x10000000, honaRegisterBuffer))
{
throw HonaAlreadyStartedException("DeviceWriteRegister Doesnt Occur");
}
if(!plxWrapper.deviceReadRegister(0x10000000, honaRegisterBuffer, 8))
{
throw HonaAlreadyStartedException("DeviceReadRegister Doesnt Occur");
}
}
/*************************************************************************************************/
@ -92,7 +102,7 @@ QString HonaLowLevelAPI::getDeviceId()
void HonaLowLevelAPI::hsruStart()
{
if(!isHsruStarted())
throw HonaAlreadyStartedException("HsruStarted doesn't started ");
throw HonaException("HsruStarted doesn't started ");
QtConcurrent::run(this, &HonaLowLevelAPI::hsruMainThread);
setHsruIsStarted(true);
}
@ -101,14 +111,26 @@ void HonaLowLevelAPI::hsruStart()
void HonaLowLevelAPI::hiruStart()
{
if(!isHiruStarted())
throw HonaAlreadyStartedException("HiruStarted doesn't started ");
throw HonaException("HiruStarted doesn't started ");
QtConcurrent::run(this, &HonaLowLevelAPI::hiruMainThread);
setHiruIsStarted(true);
}
/*************************************************************************************************/
void HonaLowLevelAPI::hsruStop()
{
if(isHiruStarted())
setHsruIsStarted(false);
_hsruStopEvent.wakeAll();
}
/*************************************************************************************************/
void HonaLowLevelAPI::init()
{
if(!plxWrapper.deviceInit(0X9054))
{
throw HonaAlreadyStartedException("Init Doesnt Occur");
}
}
/*************************************************************************************************/
@ -160,7 +182,10 @@ void HonaLowLevelAPI::hsruMainThread()
deviceReset();
setConfig();
deviceReset();
plxWrapper.deviceEnableInterrupt();
if(!plxWrapper.deviceEnableInterrupt())
{
throw HonaAlreadyStartedException("DeviceEnableInterrupt Doesnt Occur");
}
QtConcurrent::run(this, &HonaLowLevelAPI::hsruReadThread);
QtConcurrent::run(this, &HonaLowLevelAPI::hsruUpdateThread);
@ -169,7 +194,7 @@ void HonaLowLevelAPI::hsruMainThread()
{
_isHsruReaderThreadFree = true;
_isHsruUpdateThreadFree = true;
setHiruIsStarted(false);
hsruStop();
}
_mutex.lock();
@ -178,7 +203,10 @@ void HonaLowLevelAPI::hsruMainThread()
_isHsruReaderThreadFree = true;
_isHsruUpdateThreadFree = true;
plxWrapper.deviceDisableInterrupt();
if(!plxWrapper.deviceDisableInterrupt())
{
throw HonaAlreadyStartedException("DeviceEnableInterrupt Doesnt Occur");
}
}
/*************************************************************************************************/
@ -190,10 +218,16 @@ void HonaLowLevelAPI::hsruReadThread()
if(_isHsruReaderThreadFree)
break;
plxWrapper.deviceWaitForInterrupt(1000);
if(!plxWrapper.deviceWaitForInterrupt(1000))
{
throw HonaAlreadyStartedException("DeviceWaitForInterrupt Doesnt Occur");
}
honaPacketList.clear();
_hsruLoss = 0;
plxWrapper.deviceOpenPCIChannel();
if(!plxWrapper.deviceOpenPCIChannel())
{
throw HonaAlreadyStartedException("DeviceOpenPCIChannel Doesnt Occur");
}
_hsruLoss += hsruParserInt123C(hsruReadHonaBuffer(honaReceivers::int123C),
honaPacketList);
@ -205,8 +239,14 @@ void HonaLowLevelAPI::hsruReadThread()
_hsruLoss += hsruParserRes4(hsruReadHonaBuffer(honaReceivers::res4), honaPacketList);
_hsruLoss += hsruParserSinglePulse(hsruReadHonaBuffer(honaReceivers::singlePulse),
honaPacketList);
plxWrapper.deviceClosePCIChannel();
plxWrapper.deviceEnableInterrupt();
if(!plxWrapper.deviceClosePCIChannel())
{
throw HonaAlreadyStartedException("DeviceClosePCIChannel Doesnt Occur");
}
if(!plxWrapper.deviceEnableInterrupt())
{
throw HonaAlreadyStartedException("DeviceEnableInterrupt Doesnt Occur");
}
_mutex.lock();
_hsruReadDone.wakeAll();
@ -242,9 +282,6 @@ void HonaLowLevelAPI::hiruMainThread()
_mutex.lock();
_hsruStopEvent.wait(&_mutex);
_mutex.unlock();
//_isReaderThreadFree = true;
//_isUpdateThreadFree = true;
}
}
@ -262,7 +299,10 @@ void HonaLowLevelAPI::hiruUpdateThread()
quint32 HonaLowLevelAPI::hiruGetDOA()
{
quint32 Doa = 0;
plxWrapper.deviceReadRegister(0x30000004, Doa);
if(!plxWrapper.deviceReadRegister(0x30000004, Doa))
{
throw HonaAlreadyStartedException("DeviceReadRegister Doesnt Occur");
}
Doa = Doa & 0x0000FFFF;
return Doa;
@ -711,7 +751,7 @@ quint32 HonaLowLevelAPI::hsruParserInt4(const QVector<quint32>& honaData,
tempHonaPacketInt4.setCodeL(tempHonaPacketInt4.getCodeL() +
((static_cast<qulonglong>(honaData.at(Ind) & 0x000F0000)) <<
12));
tempHonaPacketInt4.M4Status = ((byte)((honaData.at(Ind) & 0x0F000000) >> 20));
tempHonaPacketInt4.setm4Status((quint8)((honaData.at(Ind) & 0x0F000000) >> 20));
nextInt4 = 7;
}
else if(honaData.at(Ind) == 0xEEEEEEEE)
@ -912,7 +952,10 @@ QVector<quint32> HonaLowLevelAPI::hsruReadHonaBuffer(honaReceivers receiver)
else
throw HonaException("honaReceivers is Not Valid");
plxWrapper.deviceReadMemory(address, honaData, honaData.size());
if(!plxWrapper.deviceReadMemory(address, honaData, honaData.size()))
{
throw HonaAlreadyStartedException("DeviceReadMemory Doesnt Occur");
}
return honaData;
}

3
Test/MainWindow.cpp

@ -13,3 +13,6 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::on_testPLX_clicked()
{
}

8
Test/MainWindow.h

@ -4,7 +4,8 @@
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
namespace Ui { class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
@ -15,7 +16,12 @@ public:
MainWindow(QWidget* parent = nullptr);
~MainWindow();
//uncrustify off
private slots:
void on_testPLX_clicked();
//uncrustify on
private:
Ui::MainWindow* ui;
};
#endif //MAINWINDOW_H

44
Test/MainWindow.ui

@ -6,15 +6,51 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>311</width>
<height>281</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar"/>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="testPLX">
<property name="geometry">
<rect>
<x>100</x>
<y>120</y>
<width>89</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>Test PLX</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>60</x>
<y>30</y>
<width>171</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:20pt;&quot;&gt;Test PLX&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>311</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>

5
Test/Test.pro

@ -22,14 +22,9 @@ SOURCES += \
HEADERS += \
MainWindow.h
INCLUDEPATH += $$PWD/../Plx/include
FORMS += \
MainWindow.ui
LIBS += -L$$OUT_PWD/../Plx/ -lPlx
PRE_TARGETDEPS += $$OUT_PWD/../Plx/libPlx.a
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin

Loading…
Cancel
Save