diff --git a/YSFGateway/APRSWriter.cpp b/YSFGateway/APRSWriter.cpp index eac1077..03db91c 100644 --- a/YSFGateway/APRSWriter.cpp +++ b/YSFGateway/APRSWriter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014,2016,2017 by Jonathan Naylor G4KLX + * Copyright (C) 2010-2014,2016,2017,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 @@ -25,7 +25,7 @@ #include #include -CAPRSWriter::CAPRSWriter(const std::string& callsign, const std::string& suffix, const std::string& password, const std::string& address, unsigned int port) : +CAPRSWriter::CAPRSWriter(const std::string& callsign, const std::string& rptSuffix, const std::string& password, const std::string& address, unsigned int port, const std::string& suffix) : m_thread(NULL), m_enabled(false), m_idTimer(1000U, 20U * 60U), // 20 minutes @@ -35,16 +35,17 @@ m_rxFrequency(0U), m_latitude(0.0F), m_longitude(0.0F), m_height(0), -m_desc() +m_desc(), +m_suffix(suffix) { assert(!callsign.empty()); assert(!password.empty()); assert(!address.empty()); assert(port > 0U); - if (!suffix.empty()) { + if (!rptSuffix.empty()) { m_callsign.append("-"); - m_callsign.append(suffix.substr(0U, 1U)); + m_callsign.append(rptSuffix.substr(0U, 1U)); } m_thread = new CAPRSWriterThread(m_callsign, password, address, port); @@ -75,13 +76,18 @@ void CAPRSWriter::write(const unsigned char* source, const char* type, unsigned assert(source != NULL); assert(type != NULL); - char callsign[11U]; + char callsign[15U]; ::memcpy(callsign, source, YSF_CALLSIGN_LENGTH); callsign[YSF_CALLSIGN_LENGTH] = 0x00U; size_t n = ::strspn(callsign, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); callsign[n] = 0x00U; + if (!m_suffix.empty()) { + ::strcat(callsign, "-"); + ::strcat(callsign, m_suffix.substr(0U, 1U).c_str()); + } + double tempLat = ::fabs(fLatitude); double tempLong = ::fabs(fLongitude); @@ -116,7 +122,7 @@ void CAPRSWriter::write(const unsigned char* source, const char* type, unsigned } char output[300U]; - ::sprintf(output, "%s-Y>APDPRS,C4FM*,qAR,%s:!%s%c/%s%c%c %s via MMDVM", + ::sprintf(output, "%s>APDPRS,C4FM*,qAR,%s:!%s%c/%s%c%c %s via MMDVM", callsign, m_callsign.c_str(), lat, (fLatitude < 0.0F) ? 'S' : 'N', lon, (fLongitude < 0.0F) ? 'W' : 'E', diff --git a/YSFGateway/APRSWriter.h b/YSFGateway/APRSWriter.h index 442dd17..22e1111 100644 --- a/YSFGateway/APRSWriter.h +++ b/YSFGateway/APRSWriter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010,2011,2012,2016,2017 by Jonathan Naylor G4KLX + * Copyright (C) 2010,2011,2012,2016,2017,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 @@ -26,7 +26,7 @@ class CAPRSWriter { public: - CAPRSWriter(const std::string& callsign, const std::string& suffix, const std::string& password, const std::string& address, unsigned int port); + CAPRSWriter(const std::string& callsign, const std::string& rptSuffix, const std::string& password, const std::string& address, unsigned int port, const std::string& suffix); ~CAPRSWriter(); bool open(); @@ -50,6 +50,7 @@ private: float m_longitude; int m_height; std::string m_desc; + std::string m_suffix; void sendIdFrames(); }; diff --git a/YSFGateway/Conf.cpp b/YSFGateway/Conf.cpp index cf00739..3cccc84 100644 --- a/YSFGateway/Conf.cpp +++ b/YSFGateway/Conf.cpp @@ -63,6 +63,7 @@ m_aprsEnabled(false), m_aprsServer(), m_aprsPort(0U), m_aprsPassword(), +m_aprsSuffix(), m_aprsDescription(), m_networkStartup(), m_networkInactivityTimeout(0U), @@ -189,6 +190,8 @@ bool CConf::read() m_aprsPort = (unsigned int)::atoi(value); else if (::strcmp(key, "Password") == 0) m_aprsPassword = value; + else if (::strcmp(key, "Suffix") == 0) + m_aprsSuffix = value; else if (::strcmp(key, "Description") == 0) m_aprsDescription = value; } else if (section == SECTION_NETWORK) { @@ -360,6 +363,11 @@ std::string CConf::getAPRSPassword() const return m_aprsPassword; } +std::string CConf::getAPRSSuffix() const +{ + return m_aprsSuffix; +} + std::string CConf::getAPRSDescription() const { return m_aprsDescription; diff --git a/YSFGateway/Conf.h b/YSFGateway/Conf.h index a7310f8..0cef458 100644 --- a/YSFGateway/Conf.h +++ b/YSFGateway/Conf.h @@ -60,6 +60,7 @@ public: std::string getAPRSServer() const; unsigned int getAPRSPort() const; std::string getAPRSPassword() const; + std::string getAPRSSuffix() const; std::string getAPRSDescription() const; // The Network section @@ -116,6 +117,7 @@ private: std::string m_aprsServer; unsigned int m_aprsPort; std::string m_aprsPassword; + std::string m_aprsSuffix; std::string m_aprsDescription; std::string m_networkStartup; diff --git a/YSFGateway/GPS.cpp b/YSFGateway/GPS.cpp index 8d0012e..0932e25 100644 --- a/YSFGateway/GPS.cpp +++ b/YSFGateway/GPS.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2017,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 @@ -31,8 +31,8 @@ const unsigned char NULL_GPS[] = {0x47U, 0x63U}; const unsigned char SHRT_GPS[] = {0x22U, 0x62U}; const unsigned char LONG_GPS[] = {0x47U, 0x64U}; -CGPS::CGPS(const std::string& callsign, const std::string& suffix, const std::string& password, const std::string& address, unsigned int port) : -m_writer(callsign, suffix, password, address, port), +CGPS::CGPS(const std::string& callsign, const std::string& rptSuffix, const std::string& password, const std::string& address, unsigned int port, const std::string suffix) : +m_writer(callsign, rptSuffix, password, address, port, suffix), m_buffer(NULL), m_sent(false) { diff --git a/YSFGateway/GPS.h b/YSFGateway/GPS.h index f168dfd..3a163f4 100644 --- a/YSFGateway/GPS.h +++ b/YSFGateway/GPS.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016,2017 by Jonathan Naylor G4KLX +* Copyright (C) 2016,2017,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 @@ -25,7 +25,7 @@ class CGPS { public: - CGPS(const std::string& callsign, const std::string& suffix, const std::string& password, const std::string& address, unsigned int port); + CGPS(const std::string& callsign, const std::string& rptSuffix, const std::string& password, const std::string& address, unsigned int port, const std::string suffix); ~CGPS(); void setInfo(unsigned int txFrequency, unsigned int rxFrequency, float latitude, float longitude, int height, const std::string& desc); diff --git a/YSFGateway/StopWatch.cpp b/YSFGateway/StopWatch.cpp index 77d539d..481241b 100644 --- a/YSFGateway/StopWatch.cpp +++ b/YSFGateway/StopWatch.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 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 @@ -21,21 +21,32 @@ #if defined(_WIN32) || defined(_WIN64) CStopWatch::CStopWatch() : -m_frequency(), +m_frequencyS(), +m_frequencyMS(), m_start() { - ::QueryPerformanceFrequency(&m_frequency); + ::QueryPerformanceFrequency(&m_frequencyS); + + m_frequencyMS.QuadPart = m_frequencyS.QuadPart / 1000ULL; } CStopWatch::~CStopWatch() { } -unsigned long CStopWatch::start() +unsigned long long CStopWatch::time() const +{ + LARGE_INTEGER now; + ::QueryPerformanceCounter(&now); + + return (unsigned long long)(now.QuadPart / m_frequencyMS.QuadPart); +} + +unsigned long long CStopWatch::start() { ::QueryPerformanceCounter(&m_start); - return (unsigned long)(m_start.QuadPart / m_frequency.QuadPart); + return (unsigned long long)(m_start.QuadPart / m_frequencyS.QuadPart); } unsigned int CStopWatch::elapsed() @@ -46,15 +57,16 @@ unsigned int CStopWatch::elapsed() LARGE_INTEGER temp; temp.QuadPart = (now.QuadPart - m_start.QuadPart) * 1000; - return (unsigned int)(temp.QuadPart / m_frequency.QuadPart); + return (unsigned int)(temp.QuadPart / m_frequencyS.QuadPart); } #else #include +#include CStopWatch::CStopWatch() : -m_start() +m_startMS(0ULL) { } @@ -62,23 +74,32 @@ CStopWatch::~CStopWatch() { } -unsigned long CStopWatch::start() +unsigned long long CStopWatch::time() const { - ::gettimeofday(&m_start, NULL); + struct timeval now; + ::gettimeofday(&now, NULL); + + return now.tv_sec * 1000ULL + now.tv_usec / 1000ULL; +} + +unsigned long long CStopWatch::start() +{ + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); + + m_startMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL; - return m_start.tv_usec; + return m_startMS; } unsigned int CStopWatch::elapsed() { - struct timeval now; - ::gettimeofday(&now, NULL); + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); - unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; - elapsed += now.tv_usec / 1000U; - elapsed -= m_start.tv_usec / 1000U; + unsigned long long nowMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL; - return elapsed; + return nowMS - m_startMS; } #endif diff --git a/YSFGateway/StopWatch.h b/YSFGateway/StopWatch.h index 811047e..3f8fa19 100644 --- a/YSFGateway/StopWatch.h +++ b/YSFGateway/StopWatch.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 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 @@ -31,15 +31,18 @@ public: CStopWatch(); ~CStopWatch(); - unsigned long start(); - unsigned int elapsed(); + unsigned long long time() const; + + unsigned long long start(); + unsigned int elapsed(); private: #if defined(_WIN32) || defined(_WIN64) - LARGE_INTEGER m_frequency; + LARGE_INTEGER m_frequencyS; + LARGE_INTEGER m_frequencyMS; LARGE_INTEGER m_start; #else - struct timeval m_start; + unsigned long long m_startMS; #endif }; diff --git a/YSFGateway/YSFGateway.cpp b/YSFGateway/YSFGateway.cpp index 746869e..2ae0bb0 100644 --- a/YSFGateway/YSFGateway.cpp +++ b/YSFGateway/YSFGateway.cpp @@ -108,33 +108,28 @@ int CYSFGateway::run() setlocale(LC_ALL, "C"); - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); - if (!ret) { - ::fprintf(stderr, "YSFGateway: unable to open the log file\n"); - return 1; - } - #if !defined(_WIN32) && !defined(_WIN64) bool m_daemon = m_conf.getDaemon(); if (m_daemon) { // Create new process pid_t pid = ::fork(); if (pid == -1) { - ::LogWarning("Couldn't fork() , exiting"); + ::fprintf(stderr, "Couldn't fork() , exiting\n"); return -1; } - else if (pid != 0) + else if (pid != 0) { exit(EXIT_SUCCESS); + } // Create new session and process group if (::setsid() == -1) { - ::LogWarning("Couldn't setsid(), exiting"); + ::fprintf(stderr, "Couldn't setsid(), exiting\n"); return -1; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return -1; } @@ -142,37 +137,43 @@ int CYSFGateway::run() ::close(STDOUT_FILENO); ::close(STDERR_FILENO); - //If we are currently root... + // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); if (user == NULL) { - ::LogError("Could not get the mmdvm user, exiting"); + ::fprintf(stderr, "Could not get the mmdvm user, exiting\n"); return -1; } uid_t mmdvm_uid = user->pw_uid; gid_t mmdvm_gid = user->pw_gid; - //Set user and group ID's to mmdvm:mmdvm + // Set user and group ID's to mmdvm:mmdvm if (setgid(mmdvm_gid) != 0) { - ::LogWarning("Could not set mmdvm GID, exiting"); + ::fprintf(stderr, "Could not set mmdvm GID, exiting\n"); return -1; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return -1; } - //Double check it worked (AKA Paranoia) + // Double check it worked (AKA Paranoia) if (setuid(0) != -1) { - ::LogWarning("It's possible to regain root - something is wrong!, exiting"); + ::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n"); return -1; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); + if (!ret) { + ::fprintf(stderr, "YSFGateway: unable to open the log file\n"); + return 1; + } + m_callsign = m_conf.getCallsign(); m_suffix = m_conf.getSuffix(); @@ -343,13 +344,10 @@ int CYSFGateway::run() } m_current.clear(); - m_inactivityTimer.stop(); m_lostTimer.stop(); m_linkType = LINK_NONE; startupLinking(); - } else { - m_inactivityTimer.start(); } } else { if (m_linkType == LINK_YSF) { @@ -366,10 +364,11 @@ int CYSFGateway::run() } m_current.clear(); - m_inactivityTimer.stop(); m_lostTimer.stop(); m_linkType = LINK_NONE; } + + m_inactivityTimer.start(); } m_lostTimer.clock(ms); @@ -386,7 +385,7 @@ int CYSFGateway::run() } m_current.clear(); - m_inactivityTimer.stop(); + m_inactivityTimer.start(); m_lostTimer.stop(); m_linkType = LINK_NONE; } @@ -427,9 +426,10 @@ void CYSFGateway::createGPS() std::string hostname = m_conf.getAPRSServer(); unsigned int port = m_conf.getAPRSPort(); std::string password = m_conf.getAPRSPassword(); + std::string suffix = m_conf.getAPRSSuffix(); std::string desc = m_conf.getAPRSDescription(); - m_gps = new CGPS(m_callsign, m_suffix, password, hostname, port); + m_gps = new CGPS(m_callsign, m_suffix, password, hostname, port, suffix); unsigned int txFrequency = m_conf.getTxFrequency(); unsigned int rxFrequency = m_conf.getRxFrequency(); @@ -523,7 +523,7 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, u m_fcsNetwork->writeUnlink(3U); m_current.clear(); - m_inactivityTimer.stop(); + m_inactivityTimer.start(); m_lostTimer.stop(); m_linkType = LINK_NONE; @@ -536,7 +536,6 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, u bool ok = m_fcsNetwork->writeLink(name); if (ok) { m_current = name; - m_inactivityTimer.start(); m_lostTimer.start(); m_linkType = LINK_FCS; } else { @@ -552,7 +551,7 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, u m_ysfNetwork->clearDestination(); m_current.clear(); - m_inactivityTimer.stop(); + m_inactivityTimer.start(); m_lostTimer.stop(); m_linkType = LINK_NONE; } @@ -563,7 +562,7 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, u m_fcsNetwork->clearDestination(); m_current.clear(); - m_inactivityTimer.stop(); + m_inactivityTimer.start(); m_lostTimer.stop(); m_linkType = LINK_NONE; } @@ -774,6 +773,8 @@ void CYSFGateway::startupLinking() } } } + if (m_startup.empty()) + LogMessage("No connection startup"); } void CYSFGateway::readFCSRoomsFile(const std::string& filename) diff --git a/YSFGateway/YSFGateway.ini b/YSFGateway/YSFGateway.ini index 977ba17..acb6a67 100644 --- a/YSFGateway/YSFGateway.ini +++ b/YSFGateway/YSFGateway.ini @@ -33,6 +33,7 @@ Server=euro.aprs2.net Port=14580 Password=9999 Description=APRS Description +Suffix=Y [Network] # Startup=FCS00120 diff --git a/YSFGateway/YSFNetwork.cpp b/YSFGateway/YSFNetwork.cpp index b291be6..cb97f4f 100644 --- a/YSFGateway/YSFNetwork.cpp +++ b/YSFGateway/YSFNetwork.cpp @@ -166,7 +166,11 @@ void CYSFNetwork::clock(unsigned int ms) return; if (::memcmp(buffer, "YSFP", 4U) == 0 && !m_linked) { - LogMessage("Linked to %s", m_name.c_str()); + if (strcmp(m_name.c_str(),"MMDVM")== 0) + LogMessage("Link successful to %s", m_name.c_str()); + else + LogMessage("Linked to %s", m_name.c_str()); + m_linked = true; } diff --git a/YSFParrot/StopWatch.cpp b/YSFParrot/StopWatch.cpp index 77d539d..481241b 100644 --- a/YSFParrot/StopWatch.cpp +++ b/YSFParrot/StopWatch.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 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 @@ -21,21 +21,32 @@ #if defined(_WIN32) || defined(_WIN64) CStopWatch::CStopWatch() : -m_frequency(), +m_frequencyS(), +m_frequencyMS(), m_start() { - ::QueryPerformanceFrequency(&m_frequency); + ::QueryPerformanceFrequency(&m_frequencyS); + + m_frequencyMS.QuadPart = m_frequencyS.QuadPart / 1000ULL; } CStopWatch::~CStopWatch() { } -unsigned long CStopWatch::start() +unsigned long long CStopWatch::time() const +{ + LARGE_INTEGER now; + ::QueryPerformanceCounter(&now); + + return (unsigned long long)(now.QuadPart / m_frequencyMS.QuadPart); +} + +unsigned long long CStopWatch::start() { ::QueryPerformanceCounter(&m_start); - return (unsigned long)(m_start.QuadPart / m_frequency.QuadPart); + return (unsigned long long)(m_start.QuadPart / m_frequencyS.QuadPart); } unsigned int CStopWatch::elapsed() @@ -46,15 +57,16 @@ unsigned int CStopWatch::elapsed() LARGE_INTEGER temp; temp.QuadPart = (now.QuadPart - m_start.QuadPart) * 1000; - return (unsigned int)(temp.QuadPart / m_frequency.QuadPart); + return (unsigned int)(temp.QuadPart / m_frequencyS.QuadPart); } #else #include +#include CStopWatch::CStopWatch() : -m_start() +m_startMS(0ULL) { } @@ -62,23 +74,32 @@ CStopWatch::~CStopWatch() { } -unsigned long CStopWatch::start() +unsigned long long CStopWatch::time() const { - ::gettimeofday(&m_start, NULL); + struct timeval now; + ::gettimeofday(&now, NULL); + + return now.tv_sec * 1000ULL + now.tv_usec / 1000ULL; +} + +unsigned long long CStopWatch::start() +{ + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); + + m_startMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL; - return m_start.tv_usec; + return m_startMS; } unsigned int CStopWatch::elapsed() { - struct timeval now; - ::gettimeofday(&now, NULL); + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); - unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; - elapsed += now.tv_usec / 1000U; - elapsed -= m_start.tv_usec / 1000U; + unsigned long long nowMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL; - return elapsed; + return nowMS - m_startMS; } #endif diff --git a/YSFParrot/StopWatch.h b/YSFParrot/StopWatch.h index 811047e..3f8fa19 100644 --- a/YSFParrot/StopWatch.h +++ b/YSFParrot/StopWatch.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 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 @@ -31,15 +31,18 @@ public: CStopWatch(); ~CStopWatch(); - unsigned long start(); - unsigned int elapsed(); + unsigned long long time() const; + + unsigned long long start(); + unsigned int elapsed(); private: #if defined(_WIN32) || defined(_WIN64) - LARGE_INTEGER m_frequency; + LARGE_INTEGER m_frequencyS; + LARGE_INTEGER m_frequencyMS; LARGE_INTEGER m_start; #else - struct timeval m_start; + unsigned long long m_startMS; #endif }; diff --git a/YSFReflector/StopWatch.cpp b/YSFReflector/StopWatch.cpp index 77d539d..481241b 100644 --- a/YSFReflector/StopWatch.cpp +++ b/YSFReflector/StopWatch.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 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 @@ -21,21 +21,32 @@ #if defined(_WIN32) || defined(_WIN64) CStopWatch::CStopWatch() : -m_frequency(), +m_frequencyS(), +m_frequencyMS(), m_start() { - ::QueryPerformanceFrequency(&m_frequency); + ::QueryPerformanceFrequency(&m_frequencyS); + + m_frequencyMS.QuadPart = m_frequencyS.QuadPart / 1000ULL; } CStopWatch::~CStopWatch() { } -unsigned long CStopWatch::start() +unsigned long long CStopWatch::time() const +{ + LARGE_INTEGER now; + ::QueryPerformanceCounter(&now); + + return (unsigned long long)(now.QuadPart / m_frequencyMS.QuadPart); +} + +unsigned long long CStopWatch::start() { ::QueryPerformanceCounter(&m_start); - return (unsigned long)(m_start.QuadPart / m_frequency.QuadPart); + return (unsigned long long)(m_start.QuadPart / m_frequencyS.QuadPart); } unsigned int CStopWatch::elapsed() @@ -46,15 +57,16 @@ unsigned int CStopWatch::elapsed() LARGE_INTEGER temp; temp.QuadPart = (now.QuadPart - m_start.QuadPart) * 1000; - return (unsigned int)(temp.QuadPart / m_frequency.QuadPart); + return (unsigned int)(temp.QuadPart / m_frequencyS.QuadPart); } #else #include +#include CStopWatch::CStopWatch() : -m_start() +m_startMS(0ULL) { } @@ -62,23 +74,32 @@ CStopWatch::~CStopWatch() { } -unsigned long CStopWatch::start() +unsigned long long CStopWatch::time() const { - ::gettimeofday(&m_start, NULL); + struct timeval now; + ::gettimeofday(&now, NULL); + + return now.tv_sec * 1000ULL + now.tv_usec / 1000ULL; +} + +unsigned long long CStopWatch::start() +{ + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); + + m_startMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL; - return m_start.tv_usec; + return m_startMS; } unsigned int CStopWatch::elapsed() { - struct timeval now; - ::gettimeofday(&now, NULL); + struct timespec now; + ::clock_gettime(CLOCK_MONOTONIC, &now); - unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; - elapsed += now.tv_usec / 1000U; - elapsed -= m_start.tv_usec / 1000U; + unsigned long long nowMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL; - return elapsed; + return nowMS - m_startMS; } #endif diff --git a/YSFReflector/StopWatch.h b/YSFReflector/StopWatch.h index 811047e..3f8fa19 100644 --- a/YSFReflector/StopWatch.h +++ b/YSFReflector/StopWatch.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016 by Jonathan Naylor G4KLX + * Copyright (C) 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 @@ -31,15 +31,18 @@ public: CStopWatch(); ~CStopWatch(); - unsigned long start(); - unsigned int elapsed(); + unsigned long long time() const; + + unsigned long long start(); + unsigned int elapsed(); private: #if defined(_WIN32) || defined(_WIN64) - LARGE_INTEGER m_frequency; + LARGE_INTEGER m_frequencyS; + LARGE_INTEGER m_frequencyMS; LARGE_INTEGER m_start; #else - struct timeval m_start; + unsigned long long m_startMS; #endif }; diff --git a/YSFReflector/YSFReflector.cpp b/YSFReflector/YSFReflector.cpp index e822bcb..51f7ea0 100644 --- a/YSFReflector/YSFReflector.cpp +++ b/YSFReflector/YSFReflector.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 @@ -93,33 +93,27 @@ void CYSFReflector::run() return; } - ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); - if (!ret) { - ::fprintf(stderr, "YSFReflector: unable to open the log file\n"); - return; - } - #if !defined(_WIN32) && !defined(_WIN64) bool m_daemon = m_conf.getDaemon(); if (m_daemon) { // Create new process pid_t pid = ::fork(); if (pid == -1) { - ::LogWarning("Couldn't fork() , exiting"); + ::fprintf(stderr, "Couldn't fork() , exiting\n"); return; - } - else if (pid != 0) + } else if (pid != 0) { exit(EXIT_SUCCESS); + } // Create new session and process group if (::setsid() == -1) { - ::LogWarning("Couldn't setsid(), exiting"); + ::fprintf(stderr, "Couldn't setsid(), exiting\n"); return; } // Set the working directory to the root directory if (::chdir("/") == -1) { - ::LogWarning("Couldn't cd /, exiting"); + ::fprintf(stderr, "Couldn't cd /, exiting\n"); return; } @@ -127,37 +121,43 @@ void CYSFReflector::run() ::close(STDOUT_FILENO); ::close(STDERR_FILENO); - //If we are currently root... + // If we are currently root... if (getuid() == 0) { struct passwd* user = ::getpwnam("mmdvm"); if (user == NULL) { - ::LogError("Could not get the mmdvm user, exiting"); + ::fprintf(stderr, "Could not get the mmdvm user, exiting\n"); return; } uid_t mmdvm_uid = user->pw_uid; gid_t mmdvm_gid = user->pw_gid; - //Set user and group ID's to mmdvm:mmdvm + // Set user and group ID's to mmdvm:mmdvm if (setgid(mmdvm_gid) != 0) { - ::LogWarning("Could not set mmdvm GID, exiting"); + ::fprintf(stderr, "Could not set mmdvm GID, exiting\n"); return; } if (setuid(mmdvm_uid) != 0) { - ::LogWarning("Could not set mmdvm UID, exiting"); + ::fprintf(stderr, "Could not set mmdvm UID, exiting\n"); return; } - //Double check it worked (AKA Paranoia) + // Double check it worked (AKA Paranoia) if (setuid(0) != -1) { - ::LogWarning("It's possible to regain root - something is wrong!, exiting"); + ::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n"); return; } } } #endif + ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel()); + if (!ret) { + ::fprintf(stderr, "YSFReflector: unable to open the log file\n"); + return; + } + CNetwork network(m_conf.getNetworkPort(), m_conf.getName(), m_conf.getDescription(), m_conf.getNetworkDebug()); ret = network.open();