From 305f49c13c384996439ef0494a1e0a4191397c6a Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 29 Jan 2018 22:07:08 +0000 Subject: [PATCH 1/2] Remove logging from the parrot. --- YSFParrot/Log.cpp | 136 -------------------------- YSFParrot/Log.h | 36 ------- YSFParrot/Makefile | 2 +- YSFParrot/Makefile.Solaris | 2 +- YSFParrot/Network.cpp | 12 +-- YSFParrot/RingBuffer.h | 10 +- YSFParrot/UDPSocket.cpp | 39 ++++---- YSFParrot/Utils.cpp | 146 ---------------------------- YSFParrot/Utils.h | 36 ------- YSFParrot/YSFParrot.cpp | 41 ++------ YSFParrot/YSFParrot.h | 5 +- YSFParrot/YSFParrot.vcxproj | 4 - YSFParrot/YSFParrot.vcxproj.filters | 12 --- 13 files changed, 38 insertions(+), 443 deletions(-) delete mode 100644 YSFParrot/Log.cpp delete mode 100644 YSFParrot/Log.h delete mode 100644 YSFParrot/Utils.cpp delete mode 100644 YSFParrot/Utils.h diff --git a/YSFParrot/Log.cpp b/YSFParrot/Log.cpp deleted file mode 100644 index fc37ebf..0000000 --- a/YSFParrot/Log.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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 "Log.h" - -#if defined(_WIN32) || defined(_WIN64) -#include -#else -#include -#endif - -#include -#include -#include -#include -#include -#include - -static unsigned int m_fileLevel = 2U; -static std::string m_filePath; -static std::string m_fileRoot; - -static FILE* m_fpLog = NULL; - -static unsigned int m_displayLevel = 2U; - -static struct tm m_tm; - -static char LEVELS[] = " DMIWEF"; - -static bool LogOpen() -{ - if (m_fileLevel == 0U) - return true; - - time_t now; - ::time(&now); - - struct tm* tm = ::gmtime(&now); - - if (tm->tm_mday == m_tm.tm_mday && tm->tm_mon == m_tm.tm_mon && tm->tm_year == m_tm.tm_year) { - if (m_fpLog != NULL) - return true; - } else { - if (m_fpLog != NULL) - ::fclose(m_fpLog); - } - - char filename[100U]; -#if defined(_WIN32) || defined(_WIN64) - ::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); -#else - ::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); -#endif - - m_fpLog = ::fopen(filename, "a+t"); - m_tm = *tm; - - return m_fpLog != NULL; -} - -bool LogInitialise(const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel) -{ - m_filePath = filePath; - m_fileRoot = fileRoot; - m_fileLevel = fileLevel; - m_displayLevel = displayLevel; - return ::LogOpen(); -} - -void LogFinalise() -{ - if (m_fpLog != NULL) - ::fclose(m_fpLog); -} - -void Log(unsigned int level, const char* fmt, ...) -{ - assert(fmt != NULL); - - char buffer[300U]; -#if defined(_WIN32) || defined(_WIN64) - SYSTEMTIME st; - ::GetSystemTime(&st); - - ::sprintf(buffer, "%c: %04u-%02u-%02u %02u:%02u:%02u.%03u ", LEVELS[level], st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); -#else - struct timeval now; - ::gettimeofday(&now, NULL); - - 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); -#endif - - va_list vl; - va_start(vl, fmt); - - ::vsprintf(buffer + ::strlen(buffer), fmt, vl); - - va_end(vl); - - if (level >= m_fileLevel && m_fileLevel != 0U) { - bool ret = ::LogOpen(); - if (!ret) - return; - - ::fprintf(m_fpLog, "%s\n", buffer); - ::fflush(m_fpLog); - } - - if (level >= m_displayLevel && m_displayLevel != 0U) { - ::fprintf(stdout, "%s\n", buffer); - ::fflush(stdout); - } - - if (level == 6U) { // Fatal - ::fclose(m_fpLog); - exit(1); - } -} diff --git a/YSFParrot/Log.h b/YSFParrot/Log.h deleted file mode 100644 index d671ef9..0000000 --- a/YSFParrot/Log.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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(LOG_H) -#define LOG_H - -#include - -#define LogDebug(fmt, ...) Log(1U, fmt, ##__VA_ARGS__) -#define LogMessage(fmt, ...) Log(2U, fmt, ##__VA_ARGS__) -#define LogInfo(fmt, ...) Log(3U, fmt, ##__VA_ARGS__) -#define LogWarning(fmt, ...) Log(4U, fmt, ##__VA_ARGS__) -#define LogError(fmt, ...) Log(5U, fmt, ##__VA_ARGS__) -#define LogFatal(fmt, ...) Log(6U, fmt, ##__VA_ARGS__) - -extern void Log(unsigned int level, const char* fmt, ...); - -extern bool LogInitialise(const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel); -extern void LogFinalise(); - -#endif diff --git a/YSFParrot/Makefile b/YSFParrot/Makefile index ca00226..78b806c 100644 --- a/YSFParrot/Makefile +++ b/YSFParrot/Makefile @@ -4,7 +4,7 @@ CFLAGS = -g -O3 -Wall -std=c++0x -pthread LIBS = -lpthread LDFLAGS = -g -OBJECTS = Log.o Network.o Parrot.o StopWatch.o Thread.o Timer.o UDPSocket.o Utils.o YSFParrot.o +OBJECTS = Network.o Parrot.o StopWatch.o Thread.o Timer.o UDPSocket.o YSFParrot.o all: YSFParrot diff --git a/YSFParrot/Makefile.Solaris b/YSFParrot/Makefile.Solaris index ff947ae..5c3f51c 100644 --- a/YSFParrot/Makefile.Solaris +++ b/YSFParrot/Makefile.Solaris @@ -4,7 +4,7 @@ CFLAGS = -g -O3 -Wall -std=c++0x -pthread LIBS = -lsocket -lpthread LDFLAGS = -g -OBJECTS = Log.o Network.o Parrot.o StopWatch.o Thread.o Timer.o UDPSocket.o Utils.o YSFParrot.o +OBJECTS = Network.o Parrot.o StopWatch.o Thread.o Timer.o UDPSocket.o YSFParrot.o all: YSFParrot diff --git a/YSFParrot/Network.cpp b/YSFParrot/Network.cpp index 78a128f..d426cb6 100644 --- a/YSFParrot/Network.cpp +++ b/YSFParrot/Network.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2018 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 @@ -17,8 +17,6 @@ */ #include "Network.h" -#include "Utils.h" -#include "Log.h" #include #include @@ -40,7 +38,7 @@ CNetwork::~CNetwork() bool CNetwork::open() { - LogInfo("Opening YSF network connection"); + ::fprintf(stdout, "Opening YSF network connection\n"); return m_socket.open(); } @@ -52,8 +50,6 @@ bool CNetwork::write(const unsigned char* data) assert(data != NULL); - CUtils::dump(1U, "YSF Network Data Sent", data, 155U); - return m_socket.write(data, 155U, m_address, m_port); } @@ -115,8 +111,6 @@ void CNetwork::clock(unsigned int ms) m_address.s_addr = address.s_addr; m_port = port; - CUtils::dump(1U, "YSF Network Data Received", buffer, length); - m_buffer.addData(buffer, 155U); } @@ -141,5 +135,5 @@ void CNetwork::close() { m_socket.close(); - LogInfo("Closing YSF network connection"); + ::fprintf(stdout, "Closing YSF network connection\n"); } diff --git a/YSFParrot/RingBuffer.h b/YSFParrot/RingBuffer.h index 7805005..f93e7a2 100644 --- a/YSFParrot/RingBuffer.h +++ b/YSFParrot/RingBuffer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2009,2012,2013,2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 2006-2009,2012,2013,2015,2016,2018 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 @@ -19,8 +19,6 @@ #ifndef RingBuffer_H #define RingBuffer_H -#include "Log.h" - #include #include #include @@ -50,7 +48,7 @@ public: bool addData(const T* buffer, unsigned int nSamples) { if (nSamples >= freeSpace()) { - LogError("**** Overflow in %s ring buffer, %u >= %u", m_name, nSamples, freeSpace()); + ::fprintf(stderr, "**** Overflow in %s ring buffer, %u >= %u\n", m_name, nSamples, freeSpace()); return false; } @@ -67,7 +65,7 @@ public: bool getData(T* buffer, unsigned int nSamples) { if (dataSize() < nSamples) { - LogError("**** Underflow in %s ring buffer, %u < %u", m_name, dataSize(), nSamples); + ::fprintf(stderr, "**** Underflow in %s ring buffer, %u < %u\n", m_name, dataSize(), nSamples); return false; } @@ -84,7 +82,7 @@ public: bool peek(T* buffer, unsigned int nSamples) { if (dataSize() < nSamples) { - LogError("**** Underflow peek in %s ring buffer, %u < %u", m_name, dataSize(), nSamples); + ::fprintf(stderr, "**** Underflow peek in %s ring buffer, %u < %u\n", m_name, dataSize(), nSamples); return false; } diff --git a/YSFParrot/UDPSocket.cpp b/YSFParrot/UDPSocket.cpp index 733dd20..4a8c42d 100644 --- a/YSFParrot/UDPSocket.cpp +++ b/YSFParrot/UDPSocket.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2016 by Jonathan Naylor G4KLX + * Copyright (C) 2006-2016,2018 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 @@ -17,7 +17,6 @@ */ #include "UDPSocket.h" -#include "Log.h" #include @@ -38,7 +37,7 @@ m_fd(-1) WSAData data; int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data); if (wsaRet != 0) - LogError("Error from WSAStartup"); + ::fprintf(stderr, "Error from WSAStartup\n"); #endif } @@ -51,7 +50,7 @@ m_fd(-1) WSAData data; int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data); if (wsaRet != 0) - LogError("Error from WSAStartup"); + ::fprintf(stderr, "Error from WSAStartup\n"); #endif } @@ -78,7 +77,7 @@ in_addr CUDPSocket::lookup(const std::string& hostname) return addr; } - LogError("Cannot find address for host %s", hostname.c_str()); + ::fprintf(stderr, "Cannot find address for host %s\n", hostname.c_str()); addr.s_addr = INADDR_NONE; return addr; @@ -95,7 +94,7 @@ in_addr CUDPSocket::lookup(const std::string& hostname) return addr; } - LogError("Cannot find address for host %s", hostname.c_str()); + ::fprintf(stderr, "Cannot find address for host %s\n", hostname.c_str()); addr.s_addr = INADDR_NONE; return addr; @@ -107,9 +106,9 @@ bool CUDPSocket::open() m_fd = ::socket(PF_INET, SOCK_DGRAM, 0); if (m_fd < 0) { #if defined(_WIN32) || defined(_WIN64) - LogError("Cannot create the UDP socket, err: %lu", ::GetLastError()); + ::fprintf(stderr, "Cannot create the UDP socket, err: %lu\n", ::GetLastError()); #else - LogError("Cannot create the UDP socket, err: %d", errno); + ::fprintf(stderr, "Cannot create the UDP socket, err: %d\n", errno); #endif return false; } @@ -128,7 +127,7 @@ bool CUDPSocket::open() addr.sin_addr.s_addr = ::inet_addr(m_address.c_str()); #endif if (addr.sin_addr.s_addr == INADDR_NONE) { - LogError("The local address is invalid - %s", m_address.c_str()); + ::fprintf(stderr, "The local address is invalid - %s\n", m_address.c_str()); return false; } } @@ -136,23 +135,23 @@ bool CUDPSocket::open() int reuse = 1; if (::setsockopt(m_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1) { #if defined(_WIN32) || defined(_WIN64) - LogError("Cannot set the UDP socket option, err: %lu", ::GetLastError()); + ::fprintf(stderr, "Cannot set the UDP socket option, err: %lu\n", ::GetLastError()); #else - LogError("Cannot set the UDP socket option, err: %d", errno); + ::fprintf(stderr, "Cannot set the UDP socket option, err: %d\n", errno); #endif return false; } if (::bind(m_fd, (sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { #if defined(_WIN32) || defined(_WIN64) - LogError("Cannot bind the UDP address, err: %lu", ::GetLastError()); + ::fprintf(stderr, "Cannot bind the UDP address, err: %lu\n", ::GetLastError()); #else - LogError("Cannot bind the UDP address, err: %d", errno); + ::fprintf(stderr, "Cannot bind the UDP address, err: %d\n", errno); #endif return false; } - LogInfo("Opening UDP port on %u", m_port); + ::fprintf(stdout, "Opening UDP port on %u\n", m_port); } return true; @@ -180,9 +179,9 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, in_addr& addres int ret = ::select(m_fd + 1, &readFds, NULL, NULL, &tv); if (ret < 0) { #if defined(_WIN32) || defined(_WIN64) - LogError("Error returned from UDP select, err: %lu", ::GetLastError()); + ::fprintf(stderr, "Error returned from UDP select, err: %lu\n", ::GetLastError()); #else - LogError("Error returned from UDP select, err: %d", errno); + ::fprintf(stderr, "Error returned from UDP select, err: %d\n", errno); #endif return -1; } @@ -204,9 +203,9 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, in_addr& addres #endif if (len <= 0) { #if defined(_WIN32) || defined(_WIN64) - LogError("Error returned from recvfrom, err: %lu", ::GetLastError()); + ::fprintf(stderr, "Error returned from recvfrom, err: %lu\n", ::GetLastError()); #else - LogError("Error returned from recvfrom, err: %d", errno); + ::fprintf(stderr, "Error returned from recvfrom, err: %d\n", errno); #endif return -1; } @@ -236,9 +235,9 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const i #endif if (ret < 0) { #if defined(_WIN32) || defined(_WIN64) - LogError("Error returned from sendto, err: %lu", ::GetLastError()); + ::fprintf(stderr, "Error returned from sendto, err: %lu\n", ::GetLastError()); #else - LogError("Error returned from sendto, err: %d", errno); + ::fprintf(stderr, "Error returned from sendto, err: %d\n", errno); #endif return false; } diff --git a/YSFParrot/Utils.cpp b/YSFParrot/Utils.cpp deleted file mode 100644 index 49ded13..0000000 --- a/YSFParrot/Utils.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2009,2014,2015,2016 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; version 2 of the License. - * - * 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. - */ - -#include "Utils.h" -#include "Log.h" - -#include -#include - -void CUtils::dump(const std::string& title, const unsigned char* data, unsigned int length) -{ - assert(data != NULL); - - dump(2U, title, data, length); -} - -void CUtils::dump(int level, const std::string& title, const unsigned char* data, unsigned int length) -{ - assert(data != NULL); - - ::Log(level, "%s", title.c_str()); - - unsigned int offset = 0U; - - while (length > 0U) { - std::string output; - - unsigned int bytes = (length > 16U) ? 16U : length; - - for (unsigned i = 0U; i < bytes; i++) { - char temp[10U]; - ::sprintf(temp, "%02X ", data[offset + i]); - output += temp; - } - - for (unsigned int i = bytes; i < 16U; i++) - output += " "; - - output += " *"; - - for (unsigned i = 0U; i < bytes; i++) { - unsigned char c = data[offset + i]; - - if (::isprint(c)) - output += c; - else - output += '.'; - } - - output += '*'; - - ::Log(level, "%04X: %s", offset, output.c_str()); - - offset += 16U; - - if (length >= 16U) - length -= 16U; - else - length = 0U; - } -} - -void CUtils::dump(const std::string& title, const bool* bits, unsigned int length) -{ - assert(bits != NULL); - - dump(2U, title, bits, length); -} - -void CUtils::dump(int level, const std::string& title, const bool* bits, unsigned int length) -{ - assert(bits != NULL); - - unsigned char bytes[100U]; - unsigned int nBytes = 0U; - for (unsigned int n = 0U; n < length; n += 8U, nBytes++) - bitsToByteBE(bits + n, bytes[nBytes]); - - dump(level, title, bytes, nBytes); -} - -void CUtils::byteToBitsBE(unsigned char byte, bool* bits) -{ - assert(bits != NULL); - - bits[0U] = (byte & 0x80U) == 0x80U; - bits[1U] = (byte & 0x40U) == 0x40U; - bits[2U] = (byte & 0x20U) == 0x20U; - bits[3U] = (byte & 0x10U) == 0x10U; - bits[4U] = (byte & 0x08U) == 0x08U; - bits[5U] = (byte & 0x04U) == 0x04U; - bits[6U] = (byte & 0x02U) == 0x02U; - bits[7U] = (byte & 0x01U) == 0x01U; -} - -void CUtils::byteToBitsLE(unsigned char byte, bool* bits) -{ - assert(bits != NULL); - - bits[0U] = (byte & 0x01U) == 0x01U; - bits[1U] = (byte & 0x02U) == 0x02U; - bits[2U] = (byte & 0x04U) == 0x04U; - bits[3U] = (byte & 0x08U) == 0x08U; - bits[4U] = (byte & 0x10U) == 0x10U; - bits[5U] = (byte & 0x20U) == 0x20U; - bits[6U] = (byte & 0x40U) == 0x40U; - bits[7U] = (byte & 0x80U) == 0x80U; -} - -void CUtils::bitsToByteBE(const bool* bits, unsigned char& byte) -{ - assert(bits != NULL); - - byte = bits[0U] ? 0x80U : 0x00U; - byte |= bits[1U] ? 0x40U : 0x00U; - byte |= bits[2U] ? 0x20U : 0x00U; - byte |= bits[3U] ? 0x10U : 0x00U; - byte |= bits[4U] ? 0x08U : 0x00U; - byte |= bits[5U] ? 0x04U : 0x00U; - byte |= bits[6U] ? 0x02U : 0x00U; - byte |= bits[7U] ? 0x01U : 0x00U; -} - -void CUtils::bitsToByteLE(const bool* bits, unsigned char& byte) -{ - assert(bits != NULL); - - byte = bits[0U] ? 0x01U : 0x00U; - byte |= bits[1U] ? 0x02U : 0x00U; - byte |= bits[2U] ? 0x04U : 0x00U; - byte |= bits[3U] ? 0x08U : 0x00U; - byte |= bits[4U] ? 0x10U : 0x00U; - byte |= bits[5U] ? 0x20U : 0x00U; - byte |= bits[6U] ? 0x40U : 0x00U; - byte |= bits[7U] ? 0x80U : 0x00U; -} diff --git a/YSFParrot/Utils.h b/YSFParrot/Utils.h deleted file mode 100644 index ade28c0..0000000 --- a/YSFParrot/Utils.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2009,2014,2015 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; version 2 of the License. - * - * 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. - */ - -#ifndef Utils_H -#define Utils_H - -#include - -class CUtils { -public: - static void dump(const std::string& title, const unsigned char* data, unsigned int length); - static void dump(int level, const std::string& title, const unsigned char* data, unsigned int length); - - static void dump(const std::string& title, const bool* bits, unsigned int length); - static void dump(int level, const std::string& title, const bool* bits, unsigned int length); - - static void byteToBitsBE(unsigned char byte, bool* bits); - static void byteToBitsLE(unsigned char byte, bool* bits); - - static void bitsToByteBE(const bool* bits, unsigned char& byte); - static void bitsToByteLE(const bool* bits, unsigned char& byte); - -private: -}; - -#endif diff --git a/YSFParrot/YSFParrot.cpp b/YSFParrot/YSFParrot.cpp index 568fb12..1062bfd 100644 --- a/YSFParrot/YSFParrot.cpp +++ b/YSFParrot/YSFParrot.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2018 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 @@ -23,7 +23,6 @@ #include "Version.h" #include "Thread.h" #include "Timer.h" -#include "Log.h" #include #include @@ -32,22 +31,18 @@ int main(int argc, char** argv) { if (argc == 1) { - ::fprintf(stderr, "Usage: YSFParrot [-d|--debug] [-n|--nolog] \n"); + ::fprintf(stderr, "Usage: YSFParrot [-d|--debug] \n"); return 1; } int n = 1U; bool debug = false; - bool log = true; for (; n < argc-1; n++) { if (::strcmp(argv[n], "-d") == 0 || ::strcmp(argv[n], "--debug") == 0) { debug = true; } - if (::strcmp(argv[n], "-n") == 0 || ::strcmp(argv[n], "--nolog") == 0) { - log = false; - } } unsigned int port = ::atoi(argv[n]); @@ -56,16 +51,15 @@ int main(int argc, char** argv) return 1; } - CYSFParrot parrot(port, debug, log); + CYSFParrot parrot(port, debug); parrot.run(); return 0; } -CYSFParrot::CYSFParrot(unsigned int port, bool debug, bool log) : +CYSFParrot::CYSFParrot(unsigned int port, bool debug) : m_port(port), -m_debug(debug), -m_log(log) +m_debug(debug) { } @@ -75,27 +69,12 @@ CYSFParrot::~CYSFParrot() void CYSFParrot::run() { - int fileLevel = 0U; - if (m_log) { - fileLevel = m_debug ? 1U : 2U; - } - bool ret = ::LogInitialise(".", "YSFParrot", fileLevel, m_debug ? 1U : 2U); - if (!ret) { - ::fprintf(stderr, "YSFParrot: unable to open the log file\n"); - return; - } - - LogInfo("Debug: %s", m_debug ? "enabled" : "disabled"); - LogInfo("Logging to file: %s", m_log ? "enabled" : "disabled"); - CParrot parrot(180U); CNetwork network(m_port); - ret = network.open(); - if (!ret) { - ::LogFinalise(); + bool ret = network.open(); + if (!ret) return; - } CStopWatch stopWatch; stopWatch.start(); @@ -107,7 +86,7 @@ void CYSFParrot::run() unsigned int count = 0U; bool playing = false; - LogInfo("Starting YSFParrot-%s", VERSION); + ::fprintf(stdout, "Starting YSFParrot-%s\n", VERSION); for (;;) { unsigned char buffer[200U]; @@ -118,7 +97,6 @@ void CYSFParrot::run() watchdogTimer.start(); if ((buffer[34U] & 0x01U) == 0x01U) { - LogDebug("Received end of transmission"); turnaroundTimer.start(); watchdogTimer.stop(); parrot.end(); @@ -157,7 +135,6 @@ void CYSFParrot::run() turnaroundTimer.clock(ms); if (watchdogTimer.isRunning() && watchdogTimer.hasExpired()) { - LogDebug("Network watchdog has expired"); turnaroundTimer.start(); watchdogTimer.stop(); parrot.end(); @@ -168,6 +145,4 @@ void CYSFParrot::run() } network.close(); - - ::LogFinalise(); } diff --git a/YSFParrot/YSFParrot.h b/YSFParrot/YSFParrot.h index 03f2b47..343822f 100644 --- a/YSFParrot/YSFParrot.h +++ b/YSFParrot/YSFParrot.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2018 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 @@ -22,7 +22,7 @@ class CYSFParrot { public: - CYSFParrot(unsigned int port, bool debug, bool log); + CYSFParrot(unsigned int port, bool debug); ~CYSFParrot(); void run(); @@ -30,7 +30,6 @@ public: private: unsigned int m_port; bool m_debug; - bool m_log; }; #endif diff --git a/YSFParrot/YSFParrot.vcxproj b/YSFParrot/YSFParrot.vcxproj index b4da17c..885e461 100644 --- a/YSFParrot/YSFParrot.vcxproj +++ b/YSFParrot/YSFParrot.vcxproj @@ -146,7 +146,6 @@ - @@ -154,12 +153,10 @@ - - @@ -167,7 +164,6 @@ - diff --git a/YSFParrot/YSFParrot.vcxproj.filters b/YSFParrot/YSFParrot.vcxproj.filters index 476a86b..ffb1f1a 100644 --- a/YSFParrot/YSFParrot.vcxproj.filters +++ b/YSFParrot/YSFParrot.vcxproj.filters @@ -26,9 +26,6 @@ Header Files - - Header Files - Header Files @@ -38,9 +35,6 @@ Header Files - - Header Files - Header Files @@ -58,18 +52,12 @@ Source Files - - Source Files - Source Files Source Files - - Source Files - Source Files From 42bb42380a1e6991e43ba1b7ffcd8bb0ac85285c Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 30 Jan 2018 07:09:14 +0000 Subject: [PATCH 2/2] Remove the unused debug option. --- YSFParrot/YSFParrot.cpp | 21 +++++---------------- YSFParrot/YSFParrot.h | 3 +-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/YSFParrot/YSFParrot.cpp b/YSFParrot/YSFParrot.cpp index 1062bfd..437e06f 100644 --- a/YSFParrot/YSFParrot.cpp +++ b/YSFParrot/YSFParrot.cpp @@ -35,31 +35,20 @@ int main(int argc, char** argv) return 1; } - int n = 1U; - - bool debug = false; - - for (; n < argc-1; n++) { - if (::strcmp(argv[n], "-d") == 0 || ::strcmp(argv[n], "--debug") == 0) { - debug = true; - } - } - - unsigned int port = ::atoi(argv[n]); + unsigned int port = ::atoi(argv[1U]); if (port == 0U) { - ::fprintf(stderr, "YSFParrot: invalid port number - %s\n", argv[n]); + ::fprintf(stderr, "YSFParrot: invalid port number - %s\n", argv[1U]); return 1; } - CYSFParrot parrot(port, debug); + CYSFParrot parrot(port); parrot.run(); return 0; } -CYSFParrot::CYSFParrot(unsigned int port, bool debug) : -m_port(port), -m_debug(debug) +CYSFParrot::CYSFParrot(unsigned int port) : +m_port(port) { } diff --git a/YSFParrot/YSFParrot.h b/YSFParrot/YSFParrot.h index 343822f..930b456 100644 --- a/YSFParrot/YSFParrot.h +++ b/YSFParrot/YSFParrot.h @@ -22,14 +22,13 @@ class CYSFParrot { public: - CYSFParrot(unsigned int port, bool debug); + CYSFParrot(unsigned int port); ~CYSFParrot(); void run(); private: unsigned int m_port; - bool m_debug; }; #endif