mirror of
https://github.com/g4klx/MMDVMHost.git
synced 2025-12-06 05:32:00 +01:00
Use the Thread class for delays.
This commit is contained in:
parent
d2b9128162
commit
eba4ddeb2a
|
|
@ -27,6 +27,7 @@
|
||||||
#include "NullDisplay.h"
|
#include "NullDisplay.h"
|
||||||
#include "YSFControl.h"
|
#include "YSFControl.h"
|
||||||
#include "Nextion.h"
|
#include "Nextion.h"
|
||||||
|
#include "Thread.h"
|
||||||
|
|
||||||
#if defined(HD44780)
|
#if defined(HD44780)
|
||||||
#include "HD44780.h"
|
#include "HD44780.h"
|
||||||
|
|
@ -568,13 +569,8 @@ int CMMDVMHost::run()
|
||||||
m_dmrTXTimer.stop();
|
m_dmrTXTimer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ms < 5U) {
|
if (ms < 5U)
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
CThread::sleep(5U);
|
||||||
::Sleep(5UL); // 5ms
|
|
||||||
#else
|
|
||||||
::usleep(5000); // 5ms
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LogMessage("MMDVMHost-%s is exiting on receipt of SIGHUP1", VERSION);
|
LogMessage("MMDVMHost-%s is exiting on receipt of SIGHUP1", VERSION);
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,7 @@
|
||||||
<ClInclude Include="StopWatch.h" />
|
<ClInclude Include="StopWatch.h" />
|
||||||
<ClInclude Include="Sync.h" />
|
<ClInclude Include="Sync.h" />
|
||||||
<ClInclude Include="TFTSerial.h" />
|
<ClInclude Include="TFTSerial.h" />
|
||||||
|
<ClInclude Include="Thread.h" />
|
||||||
<ClInclude Include="Timer.h" />
|
<ClInclude Include="Timer.h" />
|
||||||
<ClInclude Include="UDPSocket.h" />
|
<ClInclude Include="UDPSocket.h" />
|
||||||
<ClInclude Include="Utils.h" />
|
<ClInclude Include="Utils.h" />
|
||||||
|
|
@ -236,6 +237,7 @@
|
||||||
<ClCompile Include="StopWatch.cpp" />
|
<ClCompile Include="StopWatch.cpp" />
|
||||||
<ClCompile Include="Sync.cpp" />
|
<ClCompile Include="Sync.cpp" />
|
||||||
<ClCompile Include="TFTSerial.cpp" />
|
<ClCompile Include="TFTSerial.cpp" />
|
||||||
|
<ClCompile Include="Thread.cpp" />
|
||||||
<ClCompile Include="Timer.cpp" />
|
<ClCompile Include="Timer.cpp" />
|
||||||
<ClCompile Include="UDPSocket.cpp" />
|
<ClCompile Include="UDPSocket.cpp" />
|
||||||
<ClCompile Include="Utils.cpp" />
|
<ClCompile Include="Utils.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,9 @@
|
||||||
<ClInclude Include="YSFNetwork.h">
|
<ClInclude Include="YSFNetwork.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Thread.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="BPTC19696.cpp">
|
<ClCompile Include="BPTC19696.cpp">
|
||||||
|
|
@ -301,5 +304,8 @@
|
||||||
<ClCompile Include="YSFNetwork.cpp">
|
<ClCompile Include="YSFNetwork.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Thread.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
4
Makefile
4
Makefile
|
|
@ -9,8 +9,8 @@ LDFLAGS = -g
|
||||||
OBJECTS = \
|
OBJECTS = \
|
||||||
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
|
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
|
||||||
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o \
|
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o Log.o MMDVMHost.o Modem.o \
|
||||||
Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFControl.o YSFConvolution.o \
|
Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \
|
||||||
YSFFICH.o YSFNetwork.o YSFPayload.o
|
YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
|
||||||
|
|
||||||
all: MMDVMHost
|
all: MMDVMHost
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ LDFLAGS = -g -L/usr/local/lib
|
||||||
OBJECTS = \
|
OBJECTS = \
|
||||||
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
|
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
|
||||||
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o \
|
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o \
|
||||||
Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFControl.o \
|
Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \
|
||||||
YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
|
YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
|
||||||
|
|
||||||
all: MMDVMHost
|
all: MMDVMHost
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ LDFLAGS = -g -L/usr/local/lib
|
||||||
OBJECTS = \
|
OBJECTS = \
|
||||||
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
|
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
|
||||||
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o \
|
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o HD44780.o Log.o MMDVMHost.o \
|
||||||
Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFControl.o \
|
Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \
|
||||||
YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
|
YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
|
||||||
|
|
||||||
all: MMDVMHost
|
all: MMDVMHost
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ LDFLAGS = -g -L/usr/local/lib
|
||||||
OBJECTS = \
|
OBJECTS = \
|
||||||
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
|
AMBEFEC.o BPTC19696.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o DMRDataHeader.o DMREMB.o DMREmbeddedLC.o DMRFullLC.o DMRIPSC.o DMRLookup.o DMRLC.o \
|
||||||
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o OLED.o Log.o MMDVMHost.o \
|
DMRShortLC.o DMRSlot.o DMRSlotType.o DStarControl.o DStarHeader.o DStarNetwork.o DStarSlowData.o Golay2087.o Golay24128.o Hamming.o OLED.o Log.o MMDVMHost.o \
|
||||||
Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Timer.o UDPSocket.o Utils.o YSFControl.o \
|
Modem.o Nextion.o NullDisplay.o QR1676.o RS129.o SerialController.o SHA256.o StopWatch.o Sync.o TFTSerial.o Thread.o Timer.o UDPSocket.o Utils.o YSFControl.o \
|
||||||
YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
|
YSFConvolution.o YSFFICH.o YSFNetwork.o YSFPayload.o
|
||||||
|
|
||||||
all: MMDVMHost
|
all: MMDVMHost
|
||||||
|
|
|
||||||
29
Modem.cpp
29
Modem.cpp
|
|
@ -20,6 +20,7 @@
|
||||||
#include "DMRDefines.h"
|
#include "DMRDefines.h"
|
||||||
#include "YSFDefines.h"
|
#include "YSFDefines.h"
|
||||||
#include "Defines.h"
|
#include "Defines.h"
|
||||||
|
#include "Thread.h"
|
||||||
#include "Modem.h"
|
#include "Modem.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
@ -717,11 +718,7 @@ bool CModem::readVersion()
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (unsigned int count = 0U; count < MAX_RESPONSES; count++) {
|
for (unsigned int count = 0U; count < MAX_RESPONSES; count++) {
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
CThread::sleep(10U);
|
||||||
::Sleep(10UL);
|
|
||||||
#else
|
|
||||||
::usleep(10000UL);
|
|
||||||
#endif
|
|
||||||
RESP_TYPE_MMDVM resp = getResponse();
|
RESP_TYPE_MMDVM resp = getResponse();
|
||||||
if (resp == RTM_OK && m_buffer[2U] == MMDVM_GET_VERSION) {
|
if (resp == RTM_OK && m_buffer[2U] == MMDVM_GET_VERSION) {
|
||||||
LogInfo("MMDVM protocol version: %u, description: %.*s", m_buffer[3U], m_length - 4U, m_buffer + 4U);
|
LogInfo("MMDVM protocol version: %u, description: %.*s", m_buffer[3U], m_length - 4U, m_buffer + 4U);
|
||||||
|
|
@ -729,11 +726,7 @@ bool CModem::readVersion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
CThread::sleep(1000U);
|
||||||
::Sleep(1000UL); // 1s
|
|
||||||
#else
|
|
||||||
::sleep(1UL); // 1s
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LogError("Unable to read the firmware version after six attempts");
|
LogError("Unable to read the firmware version after six attempts");
|
||||||
|
|
@ -802,13 +795,9 @@ bool CModem::setConfig()
|
||||||
unsigned int count = 0U;
|
unsigned int count = 0U;
|
||||||
RESP_TYPE_MMDVM resp;
|
RESP_TYPE_MMDVM resp;
|
||||||
do {
|
do {
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
CThread::sleep(10U);
|
||||||
::Sleep(10UL);
|
|
||||||
#else
|
|
||||||
::usleep(10000UL);
|
|
||||||
#endif
|
|
||||||
resp = getResponse();
|
|
||||||
|
|
||||||
|
resp = getResponse();
|
||||||
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
||||||
count++;
|
count++;
|
||||||
if (count >= MAX_RESPONSES) {
|
if (count >= MAX_RESPONSES) {
|
||||||
|
|
@ -861,13 +850,9 @@ bool CModem::setFrequency()
|
||||||
unsigned int count = 0U;
|
unsigned int count = 0U;
|
||||||
RESP_TYPE_MMDVM resp;
|
RESP_TYPE_MMDVM resp;
|
||||||
do {
|
do {
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
CThread::sleep(10U);
|
||||||
::Sleep(10UL);
|
|
||||||
#else
|
|
||||||
::usleep(10000UL);
|
|
||||||
#endif
|
|
||||||
resp = getResponse();
|
|
||||||
|
|
||||||
|
resp = getResponse();
|
||||||
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
||||||
count++;
|
count++;
|
||||||
if (count >= MAX_RESPONSES) {
|
if (count >= MAX_RESPONSES) {
|
||||||
|
|
|
||||||
99
Thread.cpp
Normal file
99
Thread.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Thread.h"
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
|
||||||
|
CThread::CThread() :
|
||||||
|
m_handle()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CThread::~CThread()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CThread::run()
|
||||||
|
{
|
||||||
|
m_handle = ::CreateThread(NULL, 0, &helper, this, 0, NULL);
|
||||||
|
|
||||||
|
return m_handle != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CThread::wait()
|
||||||
|
{
|
||||||
|
::WaitForSingleObject(m_handle, INFINITE);
|
||||||
|
|
||||||
|
::CloseHandle(m_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DWORD CThread::helper(LPVOID arg)
|
||||||
|
{
|
||||||
|
CThread* p = (CThread*)arg;
|
||||||
|
|
||||||
|
p->entry();
|
||||||
|
|
||||||
|
return 0UL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CThread::sleep(unsigned int ms)
|
||||||
|
{
|
||||||
|
::Sleep(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
CThread::CThread() :
|
||||||
|
m_thread()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CThread::~CThread()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CThread::run()
|
||||||
|
{
|
||||||
|
return ::pthread_create(&m_thread, NULL, helper, this) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CThread::wait()
|
||||||
|
{
|
||||||
|
::pthread_join(m_thread, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* CThread::helper(void* arg)
|
||||||
|
{
|
||||||
|
CThread* p = (CThread*)arg;
|
||||||
|
|
||||||
|
p->entry();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CThread::sleep(unsigned int ms)
|
||||||
|
{
|
||||||
|
::usleep(ms * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
56
Thread.h
Normal file
56
Thread.h
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(THREAD_H)
|
||||||
|
#define THREAD_H
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class CThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CThread();
|
||||||
|
virtual ~CThread();
|
||||||
|
|
||||||
|
virtual bool run();
|
||||||
|
|
||||||
|
virtual void entry() = 0;
|
||||||
|
|
||||||
|
virtual void wait();
|
||||||
|
|
||||||
|
static void sleep(unsigned int ms);
|
||||||
|
|
||||||
|
private:
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
HANDLE m_handle;
|
||||||
|
#else
|
||||||
|
pthread_t m_thread;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
static DWORD __stdcall helper(LPVOID arg);
|
||||||
|
#else
|
||||||
|
static void* helper(void* arg);
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in a new issue