Browse Source

add thread struct

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

14
Plx/include/LowLevel/HonaLowLevelAPI.h

@ -5,6 +5,9 @@
#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
{ {
@ -14,6 +17,12 @@ 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);
@ -24,7 +33,7 @@ public:
HonaSetting getConfig(); HonaSetting getConfig();
QString getSwVersion(); QString getSwVersion();
QString getDeviceId(); QString getDeviceId();
void hsruStarte(); void hsruStart();
void hiruStart(); void hiruStart();
void init(); void init();
@ -38,10 +47,11 @@ 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

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
{ {

48
Plx/src/LowLevel/HonaLowLevelAPI.cpp

@ -1,7 +1,9 @@
#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
{ {
@ -46,6 +48,11 @@ bool HonaLowLevelAPI::isHiruStarted()
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::deviceReset() void HonaLowLevelAPI::deviceReset()
{ {
ApiResult status;
if(ApiResult::success)
{
}
/* /*
QTime t; QTime t;
t.elapsed() t.elapsed()
@ -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