1
0
Fork 0

Merge remote-tracking branch 'g4klx/master'

ycs232-kbc
Andy CA6JAU 6 years ago
commit d98bfe04e5

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -25,7 +25,7 @@
#include <cstring> #include <cstring>
#include <cmath> #include <cmath>
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_thread(NULL),
m_enabled(false), m_enabled(false),
m_idTimer(1000U, 20U * 60U), // 20 minutes m_idTimer(1000U, 20U * 60U), // 20 minutes
@ -35,16 +35,17 @@ m_rxFrequency(0U),
m_latitude(0.0F), m_latitude(0.0F),
m_longitude(0.0F), m_longitude(0.0F),
m_height(0), m_height(0),
m_desc() m_desc(),
m_suffix(suffix)
{ {
assert(!callsign.empty()); assert(!callsign.empty());
assert(!password.empty()); assert(!password.empty());
assert(!address.empty()); assert(!address.empty());
assert(port > 0U); assert(port > 0U);
if (!suffix.empty()) { if (!rptSuffix.empty()) {
m_callsign.append("-"); 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); 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(source != NULL);
assert(type != NULL); assert(type != NULL);
char callsign[11U]; char callsign[15U];
::memcpy(callsign, source, YSF_CALLSIGN_LENGTH); ::memcpy(callsign, source, YSF_CALLSIGN_LENGTH);
callsign[YSF_CALLSIGN_LENGTH] = 0x00U; callsign[YSF_CALLSIGN_LENGTH] = 0x00U;
size_t n = ::strspn(callsign, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); size_t n = ::strspn(callsign, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
callsign[n] = 0x00U; callsign[n] = 0x00U;
if (!m_suffix.empty()) {
::strcat(callsign, "-");
::strcat(callsign, m_suffix.substr(0U, 1U).c_str());
}
double tempLat = ::fabs(fLatitude); double tempLat = ::fabs(fLatitude);
double tempLong = ::fabs(fLongitude); double tempLong = ::fabs(fLongitude);
@ -116,7 +122,7 @@ void CAPRSWriter::write(const unsigned char* source, const char* type, unsigned
} }
char output[300U]; 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(), callsign, m_callsign.c_str(),
lat, (fLatitude < 0.0F) ? 'S' : 'N', lat, (fLatitude < 0.0F) ? 'S' : 'N',
lon, (fLongitude < 0.0F) ? 'W' : 'E', lon, (fLongitude < 0.0F) ? 'W' : 'E',

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -26,7 +26,7 @@
class CAPRSWriter { class CAPRSWriter {
public: 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(); ~CAPRSWriter();
bool open(); bool open();
@ -50,6 +50,7 @@ private:
float m_longitude; float m_longitude;
int m_height; int m_height;
std::string m_desc; std::string m_desc;
std::string m_suffix;
void sendIdFrames(); void sendIdFrames();
}; };

@ -63,6 +63,7 @@ m_aprsEnabled(false),
m_aprsServer(), m_aprsServer(),
m_aprsPort(0U), m_aprsPort(0U),
m_aprsPassword(), m_aprsPassword(),
m_aprsSuffix(),
m_aprsDescription(), m_aprsDescription(),
m_networkStartup(), m_networkStartup(),
m_networkInactivityTimeout(0U), m_networkInactivityTimeout(0U),
@ -189,6 +190,8 @@ bool CConf::read()
m_aprsPort = (unsigned int)::atoi(value); m_aprsPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Password") == 0) else if (::strcmp(key, "Password") == 0)
m_aprsPassword = value; m_aprsPassword = value;
else if (::strcmp(key, "Suffix") == 0)
m_aprsSuffix = value;
else if (::strcmp(key, "Description") == 0) else if (::strcmp(key, "Description") == 0)
m_aprsDescription = value; m_aprsDescription = value;
} else if (section == SECTION_NETWORK) { } else if (section == SECTION_NETWORK) {
@ -360,6 +363,11 @@ std::string CConf::getAPRSPassword() const
return m_aprsPassword; return m_aprsPassword;
} }
std::string CConf::getAPRSSuffix() const
{
return m_aprsSuffix;
}
std::string CConf::getAPRSDescription() const std::string CConf::getAPRSDescription() const
{ {
return m_aprsDescription; return m_aprsDescription;

@ -60,6 +60,7 @@ public:
std::string getAPRSServer() const; std::string getAPRSServer() const;
unsigned int getAPRSPort() const; unsigned int getAPRSPort() const;
std::string getAPRSPassword() const; std::string getAPRSPassword() const;
std::string getAPRSSuffix() const;
std::string getAPRSDescription() const; std::string getAPRSDescription() const;
// The Network section // The Network section
@ -116,6 +117,7 @@ private:
std::string m_aprsServer; std::string m_aprsServer;
unsigned int m_aprsPort; unsigned int m_aprsPort;
std::string m_aprsPassword; std::string m_aprsPassword;
std::string m_aprsSuffix;
std::string m_aprsDescription; std::string m_aprsDescription;
std::string m_networkStartup; std::string m_networkStartup;

@ -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 * 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 * 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 SHRT_GPS[] = {0x22U, 0x62U};
const unsigned char LONG_GPS[] = {0x47U, 0x64U}; 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) : 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, suffix, password, address, port), m_writer(callsign, rptSuffix, password, address, port, suffix),
m_buffer(NULL), m_buffer(NULL),
m_sent(false) m_sent(false)
{ {

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -25,7 +25,7 @@
class CGPS { class CGPS {
public: 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(); ~CGPS();
void setInfo(unsigned int txFrequency, unsigned int rxFrequency, float latitude, float longitude, int height, const std::string& desc); void setInfo(unsigned int txFrequency, unsigned int rxFrequency, float latitude, float longitude, int height, const std::string& desc);

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,21 +21,32 @@
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
CStopWatch::CStopWatch() : CStopWatch::CStopWatch() :
m_frequency(), m_frequencyS(),
m_frequencyMS(),
m_start() m_start()
{ {
::QueryPerformanceFrequency(&m_frequency); ::QueryPerformanceFrequency(&m_frequencyS);
m_frequencyMS.QuadPart = m_frequencyS.QuadPart / 1000ULL;
} }
CStopWatch::~CStopWatch() 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); ::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() unsigned int CStopWatch::elapsed()
@ -46,15 +57,16 @@ unsigned int CStopWatch::elapsed()
LARGE_INTEGER temp; LARGE_INTEGER temp;
temp.QuadPart = (now.QuadPart - m_start.QuadPart) * 1000; 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 #else
#include <cstdio> #include <cstdio>
#include <ctime>
CStopWatch::CStopWatch() : 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() unsigned int CStopWatch::elapsed()
{ {
struct timeval now; struct timespec now;
::gettimeofday(&now, NULL); ::clock_gettime(CLOCK_MONOTONIC, &now);
unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; unsigned long long nowMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL;
elapsed += now.tv_usec / 1000U;
elapsed -= m_start.tv_usec / 1000U;
return elapsed; return nowMS - m_startMS;
} }
#endif #endif

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -31,15 +31,18 @@ public:
CStopWatch(); CStopWatch();
~CStopWatch(); ~CStopWatch();
unsigned long start(); unsigned long long time() const;
unsigned int elapsed();
unsigned long long start();
unsigned int elapsed();
private: private:
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER m_frequency; LARGE_INTEGER m_frequencyS;
LARGE_INTEGER m_frequencyMS;
LARGE_INTEGER m_start; LARGE_INTEGER m_start;
#else #else
struct timeval m_start; unsigned long long m_startMS;
#endif #endif
}; };

@ -108,33 +108,28 @@ int CYSFGateway::run()
setlocale(LC_ALL, "C"); 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) #if !defined(_WIN32) && !defined(_WIN64)
bool m_daemon = m_conf.getDaemon(); bool m_daemon = m_conf.getDaemon();
if (m_daemon) { if (m_daemon) {
// Create new process // Create new process
pid_t pid = ::fork(); pid_t pid = ::fork();
if (pid == -1) { if (pid == -1) {
::LogWarning("Couldn't fork() , exiting"); ::fprintf(stderr, "Couldn't fork() , exiting\n");
return -1; return -1;
} }
else if (pid != 0) else if (pid != 0) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
}
// Create new session and process group // Create new session and process group
if (::setsid() == -1) { if (::setsid() == -1) {
::LogWarning("Couldn't setsid(), exiting"); ::fprintf(stderr, "Couldn't setsid(), exiting\n");
return -1; return -1;
} }
// Set the working directory to the root directory // Set the working directory to the root directory
if (::chdir("/") == -1) { if (::chdir("/") == -1) {
::LogWarning("Couldn't cd /, exiting"); ::fprintf(stderr, "Couldn't cd /, exiting\n");
return -1; return -1;
} }
@ -142,37 +137,43 @@ int CYSFGateway::run()
::close(STDOUT_FILENO); ::close(STDOUT_FILENO);
::close(STDERR_FILENO); ::close(STDERR_FILENO);
//If we are currently root... // If we are currently root...
if (getuid() == 0) { if (getuid() == 0) {
struct passwd* user = ::getpwnam("mmdvm"); struct passwd* user = ::getpwnam("mmdvm");
if (user == NULL) { if (user == NULL) {
::LogError("Could not get the mmdvm user, exiting"); ::fprintf(stderr, "Could not get the mmdvm user, exiting\n");
return -1; return -1;
} }
uid_t mmdvm_uid = user->pw_uid; uid_t mmdvm_uid = user->pw_uid;
gid_t mmdvm_gid = user->pw_gid; 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) { if (setgid(mmdvm_gid) != 0) {
::LogWarning("Could not set mmdvm GID, exiting"); ::fprintf(stderr, "Could not set mmdvm GID, exiting\n");
return -1; return -1;
} }
if (setuid(mmdvm_uid) != 0) { if (setuid(mmdvm_uid) != 0) {
::LogWarning("Could not set mmdvm UID, exiting"); ::fprintf(stderr, "Could not set mmdvm UID, exiting\n");
return -1; return -1;
} }
//Double check it worked (AKA Paranoia) // Double check it worked (AKA Paranoia)
if (setuid(0) != -1) { 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; return -1;
} }
} }
} }
#endif #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_callsign = m_conf.getCallsign();
m_suffix = m_conf.getSuffix(); m_suffix = m_conf.getSuffix();
@ -343,13 +344,10 @@ int CYSFGateway::run()
} }
m_current.clear(); m_current.clear();
m_inactivityTimer.stop();
m_lostTimer.stop(); m_lostTimer.stop();
m_linkType = LINK_NONE; m_linkType = LINK_NONE;
startupLinking(); startupLinking();
} else {
m_inactivityTimer.start();
} }
} else { } else {
if (m_linkType == LINK_YSF) { if (m_linkType == LINK_YSF) {
@ -366,10 +364,11 @@ int CYSFGateway::run()
} }
m_current.clear(); m_current.clear();
m_inactivityTimer.stop();
m_lostTimer.stop(); m_lostTimer.stop();
m_linkType = LINK_NONE; m_linkType = LINK_NONE;
} }
m_inactivityTimer.start();
} }
m_lostTimer.clock(ms); m_lostTimer.clock(ms);
@ -386,7 +385,7 @@ int CYSFGateway::run()
} }
m_current.clear(); m_current.clear();
m_inactivityTimer.stop(); m_inactivityTimer.start();
m_lostTimer.stop(); m_lostTimer.stop();
m_linkType = LINK_NONE; m_linkType = LINK_NONE;
} }
@ -427,9 +426,10 @@ void CYSFGateway::createGPS()
std::string hostname = m_conf.getAPRSServer(); std::string hostname = m_conf.getAPRSServer();
unsigned int port = m_conf.getAPRSPort(); unsigned int port = m_conf.getAPRSPort();
std::string password = m_conf.getAPRSPassword(); std::string password = m_conf.getAPRSPassword();
std::string suffix = m_conf.getAPRSSuffix();
std::string desc = m_conf.getAPRSDescription(); 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 txFrequency = m_conf.getTxFrequency();
unsigned int rxFrequency = m_conf.getRxFrequency(); 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_fcsNetwork->writeUnlink(3U);
m_current.clear(); m_current.clear();
m_inactivityTimer.stop(); m_inactivityTimer.start();
m_lostTimer.stop(); m_lostTimer.stop();
m_linkType = LINK_NONE; 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); bool ok = m_fcsNetwork->writeLink(name);
if (ok) { if (ok) {
m_current = name; m_current = name;
m_inactivityTimer.start();
m_lostTimer.start(); m_lostTimer.start();
m_linkType = LINK_FCS; m_linkType = LINK_FCS;
} else { } else {
@ -552,7 +551,7 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, u
m_ysfNetwork->clearDestination(); m_ysfNetwork->clearDestination();
m_current.clear(); m_current.clear();
m_inactivityTimer.stop(); m_inactivityTimer.start();
m_lostTimer.stop(); m_lostTimer.stop();
m_linkType = LINK_NONE; m_linkType = LINK_NONE;
} }
@ -563,7 +562,7 @@ void CYSFGateway::processWiresX(const unsigned char* buffer, unsigned char fi, u
m_fcsNetwork->clearDestination(); m_fcsNetwork->clearDestination();
m_current.clear(); m_current.clear();
m_inactivityTimer.stop(); m_inactivityTimer.start();
m_lostTimer.stop(); m_lostTimer.stop();
m_linkType = LINK_NONE; 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) void CYSFGateway::readFCSRoomsFile(const std::string& filename)

@ -33,6 +33,7 @@ Server=euro.aprs2.net
Port=14580 Port=14580
Password=9999 Password=9999
Description=APRS Description Description=APRS Description
Suffix=Y
[Network] [Network]
# Startup=FCS00120 # Startup=FCS00120

@ -166,7 +166,11 @@ void CYSFNetwork::clock(unsigned int ms)
return; return;
if (::memcmp(buffer, "YSFP", 4U) == 0 && !m_linked) { 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; m_linked = true;
} }

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,21 +21,32 @@
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
CStopWatch::CStopWatch() : CStopWatch::CStopWatch() :
m_frequency(), m_frequencyS(),
m_frequencyMS(),
m_start() m_start()
{ {
::QueryPerformanceFrequency(&m_frequency); ::QueryPerformanceFrequency(&m_frequencyS);
m_frequencyMS.QuadPart = m_frequencyS.QuadPart / 1000ULL;
} }
CStopWatch::~CStopWatch() 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); ::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() unsigned int CStopWatch::elapsed()
@ -46,15 +57,16 @@ unsigned int CStopWatch::elapsed()
LARGE_INTEGER temp; LARGE_INTEGER temp;
temp.QuadPart = (now.QuadPart - m_start.QuadPart) * 1000; 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 #else
#include <cstdio> #include <cstdio>
#include <ctime>
CStopWatch::CStopWatch() : 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() unsigned int CStopWatch::elapsed()
{ {
struct timeval now; struct timespec now;
::gettimeofday(&now, NULL); ::clock_gettime(CLOCK_MONOTONIC, &now);
unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; unsigned long long nowMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL;
elapsed += now.tv_usec / 1000U;
elapsed -= m_start.tv_usec / 1000U;
return elapsed; return nowMS - m_startMS;
} }
#endif #endif

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -31,15 +31,18 @@ public:
CStopWatch(); CStopWatch();
~CStopWatch(); ~CStopWatch();
unsigned long start(); unsigned long long time() const;
unsigned int elapsed();
unsigned long long start();
unsigned int elapsed();
private: private:
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER m_frequency; LARGE_INTEGER m_frequencyS;
LARGE_INTEGER m_frequencyMS;
LARGE_INTEGER m_start; LARGE_INTEGER m_start;
#else #else
struct timeval m_start; unsigned long long m_startMS;
#endif #endif
}; };

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,21 +21,32 @@
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
CStopWatch::CStopWatch() : CStopWatch::CStopWatch() :
m_frequency(), m_frequencyS(),
m_frequencyMS(),
m_start() m_start()
{ {
::QueryPerformanceFrequency(&m_frequency); ::QueryPerformanceFrequency(&m_frequencyS);
m_frequencyMS.QuadPart = m_frequencyS.QuadPart / 1000ULL;
} }
CStopWatch::~CStopWatch() 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); ::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() unsigned int CStopWatch::elapsed()
@ -46,15 +57,16 @@ unsigned int CStopWatch::elapsed()
LARGE_INTEGER temp; LARGE_INTEGER temp;
temp.QuadPart = (now.QuadPart - m_start.QuadPart) * 1000; 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 #else
#include <cstdio> #include <cstdio>
#include <ctime>
CStopWatch::CStopWatch() : 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() unsigned int CStopWatch::elapsed()
{ {
struct timeval now; struct timespec now;
::gettimeofday(&now, NULL); ::clock_gettime(CLOCK_MONOTONIC, &now);
unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U; unsigned long long nowMS = now.tv_sec * 1000ULL + now.tv_nsec / 1000000ULL;
elapsed += now.tv_usec / 1000U;
elapsed -= m_start.tv_usec / 1000U;
return elapsed; return nowMS - m_startMS;
} }
#endif #endif

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -31,15 +31,18 @@ public:
CStopWatch(); CStopWatch();
~CStopWatch(); ~CStopWatch();
unsigned long start(); unsigned long long time() const;
unsigned int elapsed();
unsigned long long start();
unsigned int elapsed();
private: private:
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER m_frequency; LARGE_INTEGER m_frequencyS;
LARGE_INTEGER m_frequencyMS;
LARGE_INTEGER m_start; LARGE_INTEGER m_start;
#else #else
struct timeval m_start; unsigned long long m_startMS;
#endif #endif
}; };

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -93,33 +93,27 @@ void CYSFReflector::run()
return; 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) #if !defined(_WIN32) && !defined(_WIN64)
bool m_daemon = m_conf.getDaemon(); bool m_daemon = m_conf.getDaemon();
if (m_daemon) { if (m_daemon) {
// Create new process // Create new process
pid_t pid = ::fork(); pid_t pid = ::fork();
if (pid == -1) { if (pid == -1) {
::LogWarning("Couldn't fork() , exiting"); ::fprintf(stderr, "Couldn't fork() , exiting\n");
return; return;
} } else if (pid != 0) {
else if (pid != 0)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
}
// Create new session and process group // Create new session and process group
if (::setsid() == -1) { if (::setsid() == -1) {
::LogWarning("Couldn't setsid(), exiting"); ::fprintf(stderr, "Couldn't setsid(), exiting\n");
return; return;
} }
// Set the working directory to the root directory // Set the working directory to the root directory
if (::chdir("/") == -1) { if (::chdir("/") == -1) {
::LogWarning("Couldn't cd /, exiting"); ::fprintf(stderr, "Couldn't cd /, exiting\n");
return; return;
} }
@ -127,37 +121,43 @@ void CYSFReflector::run()
::close(STDOUT_FILENO); ::close(STDOUT_FILENO);
::close(STDERR_FILENO); ::close(STDERR_FILENO);
//If we are currently root... // If we are currently root...
if (getuid() == 0) { if (getuid() == 0) {
struct passwd* user = ::getpwnam("mmdvm"); struct passwd* user = ::getpwnam("mmdvm");
if (user == NULL) { if (user == NULL) {
::LogError("Could not get the mmdvm user, exiting"); ::fprintf(stderr, "Could not get the mmdvm user, exiting\n");
return; return;
} }
uid_t mmdvm_uid = user->pw_uid; uid_t mmdvm_uid = user->pw_uid;
gid_t mmdvm_gid = user->pw_gid; 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) { if (setgid(mmdvm_gid) != 0) {
::LogWarning("Could not set mmdvm GID, exiting"); ::fprintf(stderr, "Could not set mmdvm GID, exiting\n");
return; return;
} }
if (setuid(mmdvm_uid) != 0) { if (setuid(mmdvm_uid) != 0) {
::LogWarning("Could not set mmdvm UID, exiting"); ::fprintf(stderr, "Could not set mmdvm UID, exiting\n");
return; return;
} }
//Double check it worked (AKA Paranoia) // Double check it worked (AKA Paranoia)
if (setuid(0) != -1) { 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; return;
} }
} }
} }
#endif #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()); CNetwork network(m_conf.getNetworkPort(), m_conf.getName(), m_conf.getDescription(), m_conf.getNetworkDebug());
ret = network.open(); ret = network.open();

Loading…
Cancel
Save