Skip to content

Commit

Permalink
Merge branch 'SimpleDMR' into AX25_FM
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Oct 5, 2020
2 parents 20e8d40 + 64a20d9 commit 7c81128
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
22 changes: 12 additions & 10 deletions Log.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2020 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
Expand Down Expand Up @@ -84,7 +84,7 @@ static bool LogOpen()

m_tm = *tm;

return status;
return status;
}

bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel)
Expand All @@ -94,18 +94,19 @@ bool LogInitialise(bool daemon, const std::string& filePath, const std::string&
m_fileLevel = fileLevel;
m_displayLevel = displayLevel;
m_daemon = daemon;
return ::LogOpen();

return ::LogOpen();
}

void LogFinalise()
{
if (m_fpLog != NULL)
::fclose(m_fpLog);
if (m_fpLog != NULL)
::fclose(m_fpLog);
}

void Log(unsigned int level, const char* fmt, ...)
{
assert(fmt != NULL);
assert(fmt != NULL);

char buffer[300U];
#if defined(_WIN32) || defined(_WIN64)
Expand All @@ -119,7 +120,7 @@ void Log(unsigned int level, const char* fmt, ...)

struct tm* tm = ::gmtime(&now.tv_sec);

::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03lu ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000U);
::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03ld ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000L);
#endif

va_list vl;
Expand All @@ -144,7 +145,8 @@ void Log(unsigned int level, const char* fmt, ...)
}

if (level == 6U) { // Fatal
::fclose(m_fpLog);
exit(1);
}
::fclose(m_fpLog);
exit(1);
}
}

7 changes: 6 additions & 1 deletion Makefile.Pi.OLED
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
CC = cc
CXX = c++
CFLAGS = -g -O3 -Wall -std=c++0x -pthread -DHAVE_LOG_H -DOLED -I/usr/local/include
LIBS = -lArduiPi_OLED -lwiringPi -lpthread -lsamplerate -lutil
LIBS = -lArduiPi_OLED -lpthread -lsamplerate -lutil

# If you use NetBSD, add following CFLAGS
#CFLAGS += -L/usr/local/lib -Wl,-rpath=/usr/local/lib

LDFLAGS = -g -L/usr/local/lib

OBJECTS = AMBEFEC.o AX25Control.o AX25Network.o BCH.o BPTC19696.o CASTInfo.o Conf.o CRC.o Display.o DMRControl.o DMRCSBK.o DMRData.o \
Expand Down Expand Up @@ -65,3 +69,4 @@ ifneq ("$(wildcard .git/index)","")
else
echo "const char *gitversion = \"0000000000000000000000000000000000000000\";" > $@
endif

34 changes: 20 additions & 14 deletions Thread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2020 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
Expand Down Expand Up @@ -31,27 +31,27 @@ CThread::~CThread()

bool CThread::run()
{
m_handle = ::CreateThread(NULL, 0, &helper, this, 0, NULL);
m_handle = ::CreateThread(NULL, 0, &helper, this, 0, NULL);

return m_handle != NULL;
return m_handle != NULL;
}


void CThread::wait()
{
::WaitForSingleObject(m_handle, INFINITE);
::WaitForSingleObject(m_handle, INFINITE);

::CloseHandle(m_handle);
::CloseHandle(m_handle);
}


DWORD CThread::helper(LPVOID arg)
{
CThread* p = (CThread*)arg;
CThread* p = (CThread*)arg;

p->entry();
p->entry();

return 0UL;
return 0UL;
}

void CThread::sleep(unsigned int ms)
Expand All @@ -74,28 +74,34 @@ CThread::~CThread()

bool CThread::run()
{
return ::pthread_create(&m_thread, NULL, helper, this) == 0;
return ::pthread_create(&m_thread, NULL, helper, this) == 0;
}


void CThread::wait()
{
::pthread_join(m_thread, NULL);
::pthread_join(m_thread, NULL);
}


void* CThread::helper(void* arg)
{
CThread* p = (CThread*)arg;
CThread* p = (CThread*)arg;

p->entry();
p->entry();

return NULL;
return NULL;
}

void CThread::sleep(unsigned int ms)
{
::usleep(ms * 1000);
struct timespec ts;

ts.tv_sec = ms / 1000U;
ts.tv_nsec = (ms % 1000U) * 1000000U;

::nanosleep(&ts, NULL);
}

#endif

0 comments on commit 7c81128

Please sign in to comment.