Browse Source

thread edit for start/stop change with H.H

mehrabi
mehrabi 3 years ago
parent
commit
0a43a11850
  1. 7
      Plx/include/LowLevel/HonaLowLevelAPI.h
  2. 8
      Plx/src/API/HonaAPI.cpp
  3. 60
      Plx/src/LowLevel/HonaLowLevelAPI.cpp
  4. 13
      Test/MainWindow.cpp

7
Plx/include/LowLevel/HonaLowLevelAPI.h

@ -20,13 +20,17 @@ class HonaLowLevelAPI : public QObject
private: private:
bool _hsruIsStarted = false; bool _hsruIsStarted = false;
bool _hiruIsStarted = false; bool _hiruIsStarted = false;
bool _hsruFirstStarted = false;
quint32 _hsruLoss; quint32 _hsruLoss;
HonaSettings _honaSetting; HonaSettings _honaSetting;
QWaitCondition _hsruReadDone, _hsruUpdateAck, _hsruStopEvent, _hiruReadDone0, _hiruCountDone, QWaitCondition _hsruReadDone, _hsruUpdateAck, _hsruStopEvent, _hiruReadDone0, _hiruCountDone,
_hiruUpdateAck1; _hiruUpdateAck1;
QList<HonaPacket> honaPacketList; QList<HonaPacket> honaPacketList;
QMutex _mutex; QMutex _readMutex;
QMutex _updateMutex;
QMutex _mainMutex;
int _threadSforValue = 0; int _threadSforValue = 0;
bool _isHsruMainThreadFree = false; bool _isHsruMainThreadFree = false;
bool _isHsruReaderThreadFree = false; bool _isHsruReaderThreadFree = false;
@ -93,6 +97,7 @@ public:
void hiruStart(); void hiruStart();
void hsruStop(); void hsruStop();
void init(); void init();
bool isHsruStarted();
private: private:
void writeSettingToRegisters(HonaSettings& settings); void writeSettingToRegisters(HonaSettings& settings);

8
Plx/src/API/HonaAPI.cpp

@ -97,18 +97,22 @@ ApiResult HonaAPI::hsruStop()
{ {
_honaLowLevelAPI.hsruStop(); _honaLowLevelAPI.hsruStop();
disconnect(&_honaLowLevelAPI, &HonaLowLevelAPI::lowLevelHonaData, this, &HonaAPI::honaDataResult);
return ApiResult::success; return ApiResult::success;
} }
/*************************************************************************************************/ /*************************************************************************************************/
ApiResult HonaAPI::init() ApiResult HonaAPI::init()
{ {
connect(&_honaLowLevelAPI, &HonaLowLevelAPI::lowLevelHonaData, this, &HonaAPI::honaDataResult);
try try
{ {
if(!_honaLowLevelAPI.isHsruStarted())
{
connect(&_honaLowLevelAPI, &HonaLowLevelAPI::lowLevelHonaData, this, &HonaAPI::honaDataResult);
_honaLowLevelAPI.init(); _honaLowLevelAPI.init();
} }
}
catch(HonaException ex) catch(HonaException ex)
{ {
return ApiResult::error; return ApiResult::error;

60
Plx/src/LowLevel/HonaLowLevelAPI.cpp

@ -138,9 +138,6 @@ void HonaLowLevelAPI::hiruStart()
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hsruStop() void HonaLowLevelAPI::hsruStop()
{ {
if(_hsruIsStarted)
_hsruIsStarted = false;
_hsruStopEvent.wakeAll(); _hsruStopEvent.wakeAll();
} }
@ -158,6 +155,11 @@ void HonaLowLevelAPI::init()
} }
} }
bool HonaLowLevelAPI::isHsruStarted()
{
return _hsruIsStarted;
}
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::writeSettingToRegisters(HonaSettings& settings) void HonaLowLevelAPI::writeSettingToRegisters(HonaSettings& settings)
{ {
@ -204,6 +206,7 @@ void HonaLowLevelAPI::hsruMainThread()
deviceReset(); deviceReset();
setConfig(); setConfig();
deviceReset(); deviceReset();
if(!plxWrapper.deviceEnableInterrupt()) if(!plxWrapper.deviceEnableInterrupt())
{ {
throw HonaException(); throw HonaException();
@ -215,13 +218,18 @@ void HonaLowLevelAPI::hsruMainThread()
QtConcurrent::run(this, &HonaLowLevelAPI::hsruReadThread); QtConcurrent::run(this, &HonaLowLevelAPI::hsruReadThread);
QtConcurrent::run(this, &HonaLowLevelAPI::hsruUpdateThread); QtConcurrent::run(this, &HonaLowLevelAPI::hsruUpdateThread);
_mutex.lock(); _mainMutex.lock();
_hsruStopEvent.wait(&_mutex); _hsruStopEvent.wait(&_mainMutex);
_mutex.unlock(); _mainMutex.unlock();
_isHsruReaderThreadFree = true; _isHsruReaderThreadFree = true;
_isHsruUpdateThreadFree = true; _isHsruUpdateThreadFree = true;
_hsruReadDone.wakeAll();
_hsruUpdateAck.wakeAll();
_hsruIsStarted = false;
if(!plxWrapper.deviceDisableInterrupt()) if(!plxWrapper.deviceDisableInterrupt())
{ {
throw HonaException(); throw HonaException();
@ -241,8 +249,8 @@ void HonaLowLevelAPI::hsruReadThread()
{ {
throw HonaException(); throw HonaException();
} }
honaPacketList.clear();
_hsruLoss = 0;
if(!plxWrapper.deviceOpenPCIChannel()) if(!plxWrapper.deviceOpenPCIChannel())
{ {
throw HonaException(); throw HonaException();
@ -250,11 +258,11 @@ void HonaLowLevelAPI::hsruReadThread()
_hsruLoss += hsruParserInt123C(hsruReadHonaBuffer(honaReceivers::int123C), honaPacketList); _hsruLoss += hsruParserInt123C(hsruReadHonaBuffer(honaReceivers::int123C), honaPacketList);
_hsruLoss += hsruParserRes123C(hsruReadHonaBuffer(honaReceivers::res123C), honaPacketList); _hsruLoss += hsruParserRes123C(hsruReadHonaBuffer(honaReceivers::res123C), honaPacketList);
_hsruLoss += hsruParserIntS(hsruReadHonaBuffer(honaReceivers::intS), honaPacketList); // _hsruLoss += hsruParserIntS(hsruReadHonaBuffer(honaReceivers::intS), honaPacketList);
_hsruLoss += hsruParserResS(hsruReadHonaBuffer(honaReceivers::resS), honaPacketList); _hsruLoss += hsruParserResS(hsruReadHonaBuffer(honaReceivers::resS), honaPacketList);
_hsruLoss += hsruParserInt4(hsruReadHonaBuffer(honaReceivers::int4), honaPacketList); // _hsruLoss += hsruParserInt4(hsruReadHonaBuffer(honaReceivers::int4), honaPacketList);
_hsruLoss += hsruParserRes4(hsruReadHonaBuffer(honaReceivers::res4), honaPacketList); // _hsruLoss += hsruParserRes4(hsruReadHonaBuffer(honaReceivers::res4), honaPacketList);
_hsruLoss += hsruParserSinglePulse(hsruReadHonaBuffer(honaReceivers::singlePulse),honaPacketList); // _hsruLoss += hsruParserSinglePulse(hsruReadHonaBuffer(honaReceivers::singlePulse),honaPacketList);
if(!plxWrapper.deviceClosePCIChannel()) if(!plxWrapper.deviceClosePCIChannel())
{ {
@ -264,11 +272,11 @@ void HonaLowLevelAPI::hsruReadThread()
{ {
throw HonaException(); throw HonaException();
} }
QThread::usleep(200000);
_mutex.lock(); _readMutex.lock();
_hsruReadDone.wakeAll(); _hsruReadDone.wakeAll();
_hsruUpdateAck.wait(&_mutex); _hsruUpdateAck.wait(&_readMutex);
_mutex.unlock(); _readMutex.unlock();
} }
} }
@ -277,14 +285,19 @@ void HonaLowLevelAPI::hsruUpdateThread()
{ {
while(true) while(true)
{ {
_mutex.lock();
_hsruReadDone.wait(&_mutex);
_mutex.unlock();
if(_isHsruUpdateThreadFree) if(_isHsruUpdateThreadFree)
break; break;
_updateMutex.lock();
_hsruReadDone.wait(&_updateMutex);
_updateMutex.unlock();
quint32 Doa = 0; quint32 Doa = 0;
Doa = hiruGetDOA(); Doa = hiruGetDOA();
emit lowLevelHonaData(honaPacketList, _hsruLoss, Doa); emit lowLevelHonaData(honaPacketList, _hsruLoss, Doa);
_hsruLoss = 0;
honaPacketList.clear();
QThread::usleep(200000);
_hsruUpdateAck.wakeAll(); _hsruUpdateAck.wakeAll();
} }
} }
@ -292,14 +305,7 @@ void HonaLowLevelAPI::hsruUpdateThread()
/*************************************************************************************************/ /*************************************************************************************************/
void HonaLowLevelAPI::hiruMainThread() void HonaLowLevelAPI::hiruMainThread()
{ {
QtConcurrent::run(this, &HonaLowLevelAPI::hiruReadThread);
QtConcurrent::run(this, &HonaLowLevelAPI::hiruUpdateThread);
while(true)
{
_mutex.lock();
_hsruStopEvent.wait(&_mutex);
_mutex.unlock();
}
} }
/*************************************************************************************************/ /*************************************************************************************************/

13
Test/MainWindow.cpp

@ -60,7 +60,6 @@ QString resultString(ApiResult res){
return ""; return "";
}; };
void MainWindow::on_startHsru_clicked() void MainWindow::on_startHsru_clicked()
{ {
//******************************************************** //********************************************************
@ -77,8 +76,16 @@ void MainWindow::on_startHsru_clicked()
void MainWindow::on_resetDevice_clicked() void MainWindow::on_resetDevice_clicked()
{ {
ApiResult _hsruStop = _honaAPI.deviceReset(); ApiResult _hsruStop = _honaAPI.hsruStop();
ui->errorMonitoring->setText("deviceReset: " + resultString(_hsruStop)); ui->errorMonitoring->setText("hsruStop: " + resultString(_hsruStop));
ApiResult _resultInit = _honaAPI.init();
ui->errorMonitoring->setText("_resultInit: " + resultString(_resultInit));
ApiResult _hsruStartResult = _honaAPI.hsruStart();
QString temp = ui->errorMonitoring->text();
ui->errorMonitoring->setText(temp + "\n _hsruStartResult: " + resultString(_hsruStartResult));
} }
void MainWindow::on_stopHsru_clicked() void MainWindow::on_stopHsru_clicked()

Loading…
Cancel
Save