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 "HonaPacket.h"
#include "QWaitCondition"
#include "QMutex"
#include "include/LowLevel/Exception/HonaAlreadyStartedException.h"
class HonaLowLevelAPI : public QObject
{
@ -14,6 +17,12 @@ private:
bool _hsruIsStarted;
bool _hiruIsStarted;
HonaSetting _honaSetting;
QWaitCondition HsruReadDone, HsruUpdateAck, HsruStopEvent;
QMutex _mutex;
int _threadSforValue = 0;
bool _isReaderThreadFree = false;
bool _isUpdateThreadFree = false;
public:
explicit HonaLowLevelAPI(QObject* parent = nullptr);
@ -24,7 +33,7 @@ public:
HonaSetting getConfig();
QString getSwVersion();
QString getDeviceId();
void hsruStarte();
void hsruStart();
void hiruStart();
void init();
@ -38,10 +47,11 @@ private:
void writeSettingToRegisters(HonaSetting& honaSetting);
void setConfig();
void hsruMainThread();
void hiruReadThread();
void hsruReadThread();
void hsruUpdateThread();
int hiruGetDOA();
signals:
void signalToTop(QList<HonaPacket*> honaPacketList, int i, int j);
//uncrustify off

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

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

48
Plx/src/LowLevel/HonaLowLevelAPI.cpp

@ -1,7 +1,9 @@
#include "../../include/LowLevel/HonaLowLevelAPI.h"
#include <include/LowLevel/Utils/Utils.h>
#include "qdebug.h"
#include "QTime"
#include "QtConcurrent/QtConcurrent"
bool HonaLowLevelAPI::getHsruIsStarted() const
{
@ -46,6 +48,11 @@ bool HonaLowLevelAPI::isHiruStarted()
/*************************************************************************************************/
void HonaLowLevelAPI::deviceReset()
{
ApiResult status;
if(ApiResult::success)
{
}
/*
QTime t;
t.elapsed()
@ -97,13 +104,17 @@ QString HonaLowLevelAPI::getDeviceId()
}
/*************************************************************************************************/
void HonaLowLevelAPI::hsruStarte()
void HonaLowLevelAPI::hsruStart()
{
}
/*************************************************************************************************/
void HonaLowLevelAPI::hiruStart()
{
if (isHiruStarted())
//exceptiom
QtConcurrent::run(this,&HonaLowLevelAPI::hsruMainThread);
}
/*************************************************************************************************/
@ -114,6 +125,7 @@ void HonaLowLevelAPI::init()
/*************************************************************************************************/
void HonaLowLevelAPI::writeSettingToRegisters(HonaSetting& honaSetting)
{
}
/*************************************************************************************************/
@ -124,16 +136,48 @@ void HonaLowLevelAPI::setConfig()
/*************************************************************************************************/
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()
{
while (true)
{
_mutex.lock();
HsruReadDone.wait(&_mutex);
_mutex.unlock();
if (_isUpdateThreadFree)
break;
//dosth
HsruUpdateAck.wakeAll();
}
}
/*************************************************************************************************/

Loading…
Cancel
Save