Browse Source

add thread struct

heydari
nasicurious 3 years ago
parent
commit
a1116abb74
  1. 70
      Plx/include/LowLevel/HonaLowLevelAPI.h
  2. 5
      Plx/include/LowLevel/Utils/Utils.h
  3. 104
      Plx/src/LowLevel/HonaLowLevelAPI.cpp

70
Plx/include/LowLevel/HonaLowLevelAPI.h

@ -5,48 +5,58 @@
#include "LowLevel/Setting/Setting.h" #include "LowLevel/Setting/Setting.h"
#include "HonaPacket.h" #include "HonaPacket.h"
#include "QWaitCondition"
#include "QMutex"
#include "include/LowLevel/Exception/HonaAlreadyStartedException.h"
class HonaLowLevelAPI : public QObject class HonaLowLevelAPI : public QObject
{ {
Q_OBJECT Q_OBJECT
private: private:
bool _hsruIsStarted; bool _hsruIsStarted;
bool _hiruIsStarted; bool _hiruIsStarted;
HonaSetting _honaSetting; HonaSetting _honaSetting;
QWaitCondition HsruReadDone, HsruUpdateAck, HsruStopEvent;
QMutex _mutex;
int _threadSforValue = 0;
bool _isReaderThreadFree = false;
bool _isUpdateThreadFree = false;
public: public:
explicit HonaLowLevelAPI(QObject* parent = nullptr); explicit HonaLowLevelAPI(QObject* parent = nullptr);
bool isHsruStarted(); bool isHsruStarted();
bool isHiruStarted(); bool isHiruStarted();
void deviceReset(); void deviceReset();
void setConfig(HonaSetting* honaSetting); void setConfig(HonaSetting* honaSetting);
HonaSetting getConfig(); HonaSetting getConfig();
QString getSwVersion(); QString getSwVersion();
QString getDeviceId(); QString getDeviceId();
void hsruStarte(); void hsruStart();
void hiruStart(); void hiruStart();
void init(); void init();
bool getHsruIsStarted() const; bool getHsruIsStarted() const;
void setHsruIsStarted(bool hsruIsStarted); void setHsruIsStarted(bool hsruIsStarted);
bool getHiruIsStarted() const; bool getHiruIsStarted() const;
void setHiruIsStarted(bool hiruIsStarted); void setHiruIsStarted(bool hiruIsStarted);
private: private:
void writeSettingToRegisters(HonaSetting& honaSetting); void writeSettingToRegisters(HonaSetting& honaSetting);
void setConfig(); void setConfig();
void hsruMainThread(); void hsruMainThread();
void hiruReadThread(); void hsruReadThread();
void hsruUpdateThread(); void hsruUpdateThread();
int hiruGetDOA(); int hiruGetDOA();
signals: signals:
void signalToTop(QList<HonaPacket*> honaPacketList, int i, int j); void signalToTop(QList<HonaPacket*> honaPacketList, int i, int j);
//uncrustify off //uncrustify off
public slots: public slots:
//uncrustify on //uncrustify on
}; };
#endif //HONALOWLEVELAPI_H #endif //HONALOWLEVELAPI_H

5
Plx/include/LowLevel/Utils/Utils.h

@ -3,14 +3,13 @@
/*************************************************************************************************/ /*************************************************************************************************/
typedef enum _APIRESULT enum ApiResult
{ {
success, success,
alreadyStarted, alreadyStarted,
busy, busy,
error error
};
}apiResult;
/*************************************************************************************************/ /*************************************************************************************************/
typedef enum _DRXDEVICEIFCHANNEL typedef enum _DRXDEVICEIFCHANNEL
{ {

104
Plx/src/LowLevel/HonaLowLevelAPI.cpp

@ -1,29 +1,31 @@
#include "../../include/LowLevel/HonaLowLevelAPI.h" #include "../../include/LowLevel/HonaLowLevelAPI.h"
#include <include/LowLevel/Utils/Utils.h>
#include "qdebug.h" #include "qdebug.h"
#include "QTime" #include "QTime"
#include "QtConcurrent/QtConcurrent"
bool HonaLowLevelAPI::getHsruIsStarted() const bool HonaLowLevelAPI::getHsruIsStarted() const
{ {
return _hsruIsStarted; return _hsruIsStarted;
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::setHsruIsStarted(bool hsruIsStarted) void HonaLowLevelAPI::setHsruIsStarted(bool hsruIsStarted)
{ {
_hsruIsStarted = hsruIsStarted; _hsruIsStarted = hsruIsStarted;
} }
/*************************************************************************************************/ /*************************************************************************************************/
bool HonaLowLevelAPI::getHiruIsStarted() const bool HonaLowLevelAPI::getHiruIsStarted() const
{ {
return _hiruIsStarted; return _hiruIsStarted;
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::setHiruIsStarted(bool hiruIsStarted) void HonaLowLevelAPI::setHiruIsStarted(bool hiruIsStarted)
{ {
_hiruIsStarted = hiruIsStarted; _hiruIsStarted = hiruIsStarted;
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -34,50 +36,55 @@ HonaLowLevelAPI::HonaLowLevelAPI(QObject* parent) : QObject(parent)
/*************************************************************************************************/ /*************************************************************************************************/
bool HonaLowLevelAPI::isHsruStarted() bool HonaLowLevelAPI::isHsruStarted()
{ {
return getHsruIsStarted(); return getHsruIsStarted();
} }
/*************************************************************************************************/ /*************************************************************************************************/
bool HonaLowLevelAPI::isHiruStarted() bool HonaLowLevelAPI::isHiruStarted()
{ {
return getHiruIsStarted(); return getHiruIsStarted();
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::deviceReset() void HonaLowLevelAPI::deviceReset()
{ {
/* ApiResult status;
QTime t; if(ApiResult::success)
t.elapsed() {
PLX_STATUS status = base.DeviceReset(); }
qDebug() << "Board Reseted, status: " + status.ToString()); /*
QTime t;
t.elapsed()
if (status == PLX_STATUS.ApiSuccess) PLX_STATUS status = base.DeviceReset();
{ qDebug() << "Board Reseted, status: " + status.ToString());
toaStartBoard = (ulong) (DateTime.Now.Ticks);
return ApiResult.Success; if (status == PLX_STATUS.ApiSuccess)
} {
else toaStartBoard = (ulong) (DateTime.Now.Ticks);
return ApiResult.Error; */ return ApiResult.Success;
}
else
return ApiResult.Error; */
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::setConfig(HonaSetting* honaSetting) void HonaLowLevelAPI::setConfig(HonaSetting* honaSetting)
{ {
//Initial State Checking //Initial State Checking
/* /*
HonaRegisterBuffer = new uint[8]; // Mode4 :: changed from 5 to 8 by H.H HonaRegisterBuffer = new uint[8]; // Mode4 :: changed from 5 to 8 by H.H
DeviceReadRegisters(0x10000000, ref HonaRegisterBuffer); DeviceReadRegisters(0x10000000, ref HonaRegisterBuffer);
_honaSetting = Settings; _honaSetting = Settings;
HonaFillRegisters(Settings); HonaFillRegisters(Settings);
DeviceWriteRegisters(0x10000000, HonaRegisterBuffer); DeviceWriteRegisters(0x10000000, HonaRegisterBuffer);
HonaRegisterBuffer = new uint[8]; // Mode4 :: changed from 5 to 8 by H.H HonaRegisterBuffer = new uint[8]; // Mode4 :: changed from 5 to 8 by H.H
DeviceReadRegisters(0x10000000, ref HonaRegisterBuffer); DeviceReadRegisters(0x10000000, ref HonaRegisterBuffer);
return ApiResult.Success; */ return ApiResult.Success; */
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -97,13 +104,17 @@ QString HonaLowLevelAPI::getDeviceId()
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hsruStarte() void HonaLowLevelAPI::hsruStart()
{ {
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hiruStart() void HonaLowLevelAPI::hiruStart()
{ {
if (isHiruStarted())
//exceptiom
QtConcurrent::run(this,&HonaLowLevelAPI::hsruMainThread);
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -114,6 +125,7 @@ void HonaLowLevelAPI::init()
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::writeSettingToRegisters(HonaSetting& honaSetting) void HonaLowLevelAPI::writeSettingToRegisters(HonaSetting& honaSetting)
{ {
} }
/*************************************************************************************************/ /*************************************************************************************************/
@ -124,16 +136,48 @@ void HonaLowLevelAPI::setConfig()
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hsruMainThread() void HonaLowLevelAPI::hsruMainThread()
{ {
QtConcurrent::run(this, &HonaLowLevelAPI::hsruReadThread);
QtConcurrent::run(this, &HonaLowLevelAPI::hsruUpdateThread);
_mutex.lock();
HsruStopEvent.wait(&_mutex);
_mutex.unlock();
_isReaderThreadFree = true;
_isUpdateThreadFree = true;
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hiruReadThread() void HonaLowLevelAPI::hsruReadThread()
{ {
while (true)
{
if (_isReaderThreadFree)
break;
//dosth
_mutex.lock();
HsruReadDone.wakeAll();
HsruUpdateAck.wait(&_mutex);
_mutex.unlock();
}
} }
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hsruUpdateThread() void HonaLowLevelAPI::hsruUpdateThread()
{ {
while (true)
{
_mutex.lock();
HsruReadDone.wait(&_mutex);
_mutex.unlock();
if (_isUpdateThreadFree)
break;
//dosth
HsruUpdateAck.wakeAll();
}
} }
/*************************************************************************************************/ /*************************************************************************************************/

Loading…
Cancel
Save