From 05063642b495a8c283ee71a997dd77a4cb883826 Mon Sep 17 00:00:00 2001 From: Mehrabi Date: Mon, 13 Dec 2021 04:49:24 -0500 Subject: [PATCH] add Wrapper --- Plx/include/LowLevel/HonaLowLevelAPI.h | 48 ++++++- Plx/include/LowLevel/HonaPacket.h | 99 +++++++------- Plx/include/LowLevel/Setting/Setting.h | 19 ++- Plx/include/LowLevel/Utils/Utils.h | 31 +++-- Plx/src/LowLevel/HonaLowLevelAPI.cpp | 177 ++++++++++++++++++++++++- Plx/src/Wrapper/PlxWrapper.cpp | 140 +++++++++++++++++++ 6 files changed, 431 insertions(+), 83 deletions(-) create mode 100644 Plx/src/Wrapper/PlxWrapper.cpp diff --git a/Plx/include/LowLevel/HonaLowLevelAPI.h b/Plx/include/LowLevel/HonaLowLevelAPI.h index 38947e9..c518271 100644 --- a/Plx/include/LowLevel/HonaLowLevelAPI.h +++ b/Plx/include/LowLevel/HonaLowLevelAPI.h @@ -2,16 +2,54 @@ #define HONALOWLEVELAPI_H #include +#include "include/LowLevel/Setting/Setting.h" +#include "include/LowLevel/HonaPacket.h" + class HonaLowLevelAPI : public QObject { - Q_OBJECT + Q_OBJECT + +private: + quint32 honaRegisterBuffer[8]; + + bool _hsruIsStarted; + bool _hiruIsStarted; + honaSettings _honaSettings; + + public: - explicit HonaLowLevelAPI(QObject *parent = nullptr); + explicit HonaLowLevelAPI(QObject* parent = nullptr); + bool isHsruStarted(); + bool isHiruStarted(); + void deviceReset(); + void setConfig(honaSettings* honaSettings); + honaSettings getConfig(); + QString getSwVersion(); + QString getDeviceId(); + void hsruStarte(); + void hiruStart(); + void init(); -signals: + bool getHsruIsStarted() const; + void setHsruIsStarted(bool hsruIsStarted); + + bool getHiruIsStarted() const; + void setHiruIsStarted(bool hiruIsStarted); -public slots: +private: + void writeSettingToRegisters(honaSettings& settings); + void setConfig(); + void hsruMainThread(); + void hiruReadThread(); + void hsruUpdateThread(); + int hiruGetDOA(); + +signals: + void signalToTop(QList honaPacketList, int i, int j); + //uncrustify off +public slots: + //uncrustify on }; -#endif // HONALOWLEVELAPI_H +#endif //HONALOWLEVELAPI_H diff --git a/Plx/include/LowLevel/HonaPacket.h b/Plx/include/LowLevel/HonaPacket.h index f9ae66a..505a033 100644 --- a/Plx/include/LowLevel/HonaPacket.h +++ b/Plx/include/LowLevel/HonaPacket.h @@ -2,62 +2,61 @@ #define HONAPACKET_H #include -#include "include/LowLevel/Utils/Utils.h" +#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; + 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); - void setPacketType(honaPacketType &temp); - /******************************************************************/ - quint32 getPacketNumber(void); - void setPacketNumber(quint32 temp); - /******************************************************************/ - qulonglong getToa(void); - void setToa(qulonglong temp); - /******************************************************************/ - quint32 getDoa(void); - void setDoa(quint32 temp); - /******************************************************************/ - quint32 getPa1(void); - void setPa1(quint32 temp); - /******************************************************************/ - quint32 getPa2(void); - void setPa2(quint32 temp); - /******************************************************************/ - quint32 getPa3(void); - void setPa3(quint32 temp); - /******************************************************************/ - quint32 getPa4(void); - void setPa4(quint32 temp); - /******************************************************************/ - quint32 getCode(void); - void setCode(quint32 temp); - /******************************************************************/ - quint32 getCodeL(void); - void setCodeL(quint32 temp); - /******************************************************************/ - quint32 getCodeM(void); - void setCodeM(quint32 temp); - /******************************************************************/ + 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 +#endif //HONAPACKET_H diff --git a/Plx/include/LowLevel/Setting/Setting.h b/Plx/include/LowLevel/Setting/Setting.h index 60aae31..566b057 100644 --- a/Plx/include/LowLevel/Setting/Setting.h +++ b/Plx/include/LowLevel/Setting/Setting.h @@ -1,12 +1,11 @@ - #ifndef SETTINGS_H #define SETTINGS_H #include +#include #include "include/LowLevel/Utils/Utils.h" - /***********************************************************************************************/ -typedef struct _HIRUSETTINGS + struct hiruSettings_t { recorderStart recordStard; recorderMode recordMode; @@ -15,9 +14,9 @@ typedef struct _HIRUSETTINGS quint32 timeout = 1000; quint32 count = 5; -}hiruSettings; +}; /***********************************************************************************************/ -typedef struct _HSRUSETTINGS + struct hsruSettings_t { bool isReal = true; quint32 honaInt123CTHR = 128; @@ -28,14 +27,14 @@ typedef struct _HSRUSETTINGS quint32 intM4_THR = 20; //mode4 quint32 resM4_THR = 20; //mode4 -}hsruSettings; +}; /***********************************************************************************************/ -typedef struct _HONASETTINGS + struct honaSettings { - quint32 hsruSettings; - quint32 hiruSettings; + hiruSettings_t hiruSettings; + hsruSettings_t hsruSettings; -}honaSettings; +}; /***********************************************************************************************/ #endif // SETTING_H diff --git a/Plx/include/LowLevel/Utils/Utils.h b/Plx/include/LowLevel/Utils/Utils.h index 7bbb95d..0a5f39f 100644 --- a/Plx/include/LowLevel/Utils/Utils.h +++ b/Plx/include/LowLevel/Utils/Utils.h @@ -1,25 +1,25 @@ #ifndef UTILS_H #define UTILS_H +#include /*************************************************************************************************/ -typedef enum _APIRESULT +enum apiResult : quint8 { success, alreadyStarted, busy, error - -}apiResult; +}; /*************************************************************************************************/ -typedef enum _DRXDEVICEIFCHANNEL +enum drxDeviceIfChannel : quint8 { ifChannel11, ifChannel12 -}drxDeviceIfChannel; +}; /*************************************************************************************************/ -typedef enum _HONARECEIVERS +enum honaReceivers : quint8 { int123C, intS, @@ -28,23 +28,22 @@ typedef enum _HONARECEIVERS res4, //Mode 4 signalPulse //Mode 4 -}honaReceivers; +}; /*************************************************************************************************/ -typedef enum _RECORDERMODE +enum recorderMode : quint8 { signalChannel, dualChannel -}recorderMode; +}; /*************************************************************************************************/ -typedef enum _RECORDSTART +enum recorderStart : quint8 { - selfTestCounter, - freeRunRecording - -}recorderStart; + selfTestCounter= 1, + freeRunRecording = 2 +}; /*************************************************************************************************/ -typedef enum _HONAPACKETTYPE +enum honaPacketType : quint8 { interrogationMode123C, interrogationModeS56, @@ -58,7 +57,7 @@ typedef enum _HONAPACKETTYPE responseMode4, signalPulseMode4 -}honaPacketType; +}; /*************************************************************************************************/ diff --git a/Plx/src/LowLevel/HonaLowLevelAPI.cpp b/Plx/src/LowLevel/HonaLowLevelAPI.cpp index ef38c38..1b82f27 100644 --- a/Plx/src/LowLevel/HonaLowLevelAPI.cpp +++ b/Plx/src/LowLevel/HonaLowLevelAPI.cpp @@ -1,6 +1,179 @@ -#include "../../include/LowLevel/HonaLowLevelAPI.h" +#include "qdebug.h" +#include "QTime" -HonaLowLevelAPI::HonaLowLevelAPI(QObject *parent) : QObject(parent) +#include "include/LowLevel/HonaLowLevelAPI.h" +#include "include/Wrapper/PlxWrapper.h" + + + + + +PlxWrapper plx; + + +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) +{ +} +/*************************************************************************************************/ +bool HonaLowLevelAPI::isHsruStarted() +{ + return getHsruIsStarted(); +} + +/*************************************************************************************************/ +bool HonaLowLevelAPI::isHiruStarted() +{ + return getHiruIsStarted(); +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::deviceReset() +{ +// deviceReset(); + + +// bool status = deviceReset(); +// qDebug() << "Board Reseted, status: " + status); + +// if (status == PLX_STATUS.ApiSuccess) +// { +// toaStartBoard = (ulong) (DateTime.Now.Ticks); +// return ApiResult.Success; +// } +// else +// return ApiResult.Error; +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::setConfig(honaSettings* settings) +{ + //Initial State Checking + /* + HonaRegisterBuffer = new uint[8]; // Mode4 :: changed from 5 to 8 by H.H + DeviceReadRegisters(0x10000000, ref HonaRegisterBuffer); + + _honaSettings = Settings; + HonaFillRegisters(Settings); + DeviceWriteRegisters(0x10000000, HonaRegisterBuffer); + + HonaRegisterBuffer = new uint[8]; // Mode4 :: changed from 5 to 8 by H.H + DeviceReadRegisters(0x10000000, ref HonaRegisterBuffer); + + return ApiResult.Success; */ +} + +/*************************************************************************************************/ +honaSettings HonaLowLevelAPI::getConfig() +{ } + +/*************************************************************************************************/ + +QString HonaLowLevelAPI::getSwVersion() +{ +} + +/*************************************************************************************************/ +QString HonaLowLevelAPI::getDeviceId() +{ + +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::hsruStarte() +{ +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::hiruStart() +{ +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::init() +{ +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::writeSettingToRegisters(honaSettings& settings) +{ + honaRegisterBuffer[0] = 0x00000000; + /************************************************************************/ + if(settings.hiruSettings.recordStard == recorderStart::selfTestCounter) + honaRegisterBuffer[0] = 0x80000000; + else + honaRegisterBuffer[0] = 0x7FFFFFFF; + /************************************************************************/ + if(settings.hiruSettings.recordChannel == drxDeviceIfChannel::ifChannel12) + honaRegisterBuffer[0] = 0x20000000; + else + honaRegisterBuffer[0] = 0xDFFFFFFF; + /************************************************************************/ + if(settings.hiruSettings.recordMode == recorderMode::dualChannel) + honaRegisterBuffer[0] = 0x10000000; + else + honaRegisterBuffer[0] = 0xEFFFFFFF; + /************************************************************************/ + + honaRegisterBuffer[0] += (settings.hiruSettings.threshold & 0x00000FFF); + + honaRegisterBuffer[1] = settings.hsruSettings.honaInt123CTHR; + honaRegisterBuffer[2] = settings.hsruSettings.honaRes123CTHR; + honaRegisterBuffer[3] = settings.hsruSettings.honaIntSTHR; + honaRegisterBuffer[4] = settings.hsruSettings.honaResSTHR; + honaRegisterBuffer[5] = settings.hsruSettings.honaSPTHR; + honaRegisterBuffer[6] = settings.hsruSettings.intM4_THR; + honaRegisterBuffer[7] = settings.hsruSettings.resM4_THR; +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::setConfig() +{ +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::hsruMainThread() +{ +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::hiruReadThread() +{ +} + +/*************************************************************************************************/ +void HonaLowLevelAPI::hsruUpdateThread() +{ +} + +/*************************************************************************************************/ +int HonaLowLevelAPI::hiruGetDOA() +{ +} + +/*************************************************************************************************/ diff --git a/Plx/src/Wrapper/PlxWrapper.cpp b/Plx/src/Wrapper/PlxWrapper.cpp new file mode 100644 index 0000000..e77198a --- /dev/null +++ b/Plx/src/Wrapper/PlxWrapper.cpp @@ -0,0 +1,140 @@ +#include +#include +#include "include/Wrapper/PlxWrapper.h" + +PlxWrapper::PlxWrapper() +{ + +} +/*************************************************************************************************/ +bool PlxWrapper::deviceInit(quint32 devicekey) +{ + return PlxPci_9054_SelDevice(devicekey); +} +/*************************************************************************************************/ +bool PlxWrapper::deviceOpen(void) +{ + return PlxPci_9054_Open(); +} +/*************************************************************************************************/ + +bool PlxWrapper::deviceClose(void) +{ + return PlxPci_9054_Close(); +} +/*************************************************************************************************/ +bool PlxWrapper::deviceReset(void) +{ + return PlxPci_9054_Reset(); +} +/*************************************************************************************************/ +bool PlxWrapper::deviceLoadE2pToFPGA(void) +{ + return PlxPci_9054_LoadE2pToFPGA(); +} +/*************************************************************************************************/ +bool PlxWrapper::deviceReadEeprom(quint16 offset,quint32 length, QVector &data) +{ + bool ret = true; + data.clear(); + + for(auto i = 0U; i < (length-1)*4; i+=4) + { + quint32 temp; + ret &= PlxPci_9054_ReadEep(offset+i, &temp); + data.append(temp); + } + return ret; +} +/*************************************************************************************************/ +bool PlxWrapper::deviceWriteEeprom(quint16 offset,quint32 data) +{ + return PlxPci_9054_WriteEep(offset,data); +} +/*************************************************************************************************/ +bool PlxWrapper::deviceReadRegister(quint32 address,QVector &data,quint32 length) +{ + bool ret = true; + data.clear(); + + quint32 temp[length]; + ret &= PlxPci_9054_ReadBar(address,&temp,length * 4); + if(ret == true) + { + for(auto i = 0U; i &data) +{ + bool ret = true; + auto length = data.length(); + quint32 temp[length]; + + for(auto i = 0U; i &data,quint32 length) +{ + bool ret = true; + data.clear(); + + quint32 temp[length]; + ret &= PlxPci_9054_DMATransfer(localAddress,&temp,(quint32)(length*4)); + + for(auto i = 0U; i