From 2e94745ca449a1986c22e4671aec786af54d69c3 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Thu, 30 Dec 2021 17:56:52 +0100 Subject: [PATCH] #6 first try with GPSD --- APRSEntry.cpp | 119 +++++++++++++++++++++ APRSEntry.h | 59 +++++++++++ APRSWriter.cpp | 232 +++++++++++++++++------------------------ APRSWriter.h | 51 +++------ DStarGatewayApp.cpp | 38 +++++-- DStarGatewayConfig.cpp | 30 ++++++ DStarGatewayConfig.h | 16 +++ Defs.h | 5 + Makefile | 9 +- 9 files changed, 374 insertions(+), 185 deletions(-) create mode 100644 APRSEntry.cpp create mode 100644 APRSEntry.h diff --git a/APRSEntry.cpp b/APRSEntry.cpp new file mode 100644 index 0000000..a9fbdcf --- /dev/null +++ b/APRSEntry.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2010,2011,2012,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2021 by Geoffrey Merck F4FXL / KC3FRA + * + * 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 + +#include "APRSEntry.h" + +CAPRSEntry::CAPRSEntry(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl) : +m_callsign(callsign), +m_band(band), +m_frequency(frequency), +m_offset(offset), +m_range(range), +m_latitude(latitude), +m_longitude(longitude), +m_agl(agl), +m_timer(1000U, 10U), +m_first(true), +m_collector(NULL) +{ + boost::trim(m_callsign); + + m_collector = new CAPRSCollector; +} + +CAPRSEntry::~CAPRSEntry() +{ + delete m_collector; +} + +std::string CAPRSEntry::getCallsign() const +{ + return m_callsign; +} + +std::string CAPRSEntry::getBand() const +{ + return m_band; +} + +double CAPRSEntry::getFrequency() const +{ + return m_frequency; +} + +double CAPRSEntry::getOffset() const +{ + return m_offset; +} + +double CAPRSEntry::getRange() const +{ + return m_range; +} + +double CAPRSEntry::getLatitude() const +{ + return m_latitude; +} + +double CAPRSEntry::getLongitude() const +{ + return m_longitude; +} + +double CAPRSEntry::getAGL() const +{ + return m_agl; +} + +CAPRSCollector* CAPRSEntry::getCollector() const +{ + return m_collector; +} + +void CAPRSEntry::reset() +{ + m_first = true; + m_timer.stop(); + m_collector->reset(); +} + +void CAPRSEntry::clock(unsigned int ms) +{ + m_timer.clock(ms); +} + +bool CAPRSEntry::isOK() +{ + if (m_first) { + m_first = false; + m_timer.start(); + return true; + } + + if (m_timer.hasExpired()) { + m_timer.start(); + return true; + } else { + m_timer.start(); + return false; + } +} \ No newline at end of file diff --git a/APRSEntry.h b/APRSEntry.h new file mode 100644 index 0000000..3ad5484 --- /dev/null +++ b/APRSEntry.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2010,2011,2012,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2021 by Geoffrey Merck F4FXL / KC3FRA + * + * 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. + */ + +#pragma once + +#include + +#include "APRSCollector.h" +#include "Timer.h" + +class CAPRSEntry { +public: + CAPRSEntry(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl); + ~CAPRSEntry(); + + std::string getCallsign() const; + std::string getBand() const; + double getFrequency() const; + double getOffset() const; + double getRange() const; + double getLatitude() const; + double getLongitude() const; + double getAGL() const; + CAPRSCollector* getCollector() const; + + // Transmission timer + void reset(); + void clock(unsigned int ms); + bool isOK(); + +private: + std::string m_callsign; + std::string m_band; + double m_frequency; + double m_offset; + double m_range; + double m_latitude; + double m_longitude; + double m_agl; + CTimer m_timer; + bool m_first; + CAPRSCollector* m_collector; +}; diff --git a/APRSWriter.cpp b/APRSWriter.cpp index 63df80d..426183a 100644 --- a/APRSWriter.cpp +++ b/APRSWriter.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "StringUtils.h" #include "Log.h" @@ -28,103 +29,6 @@ #include "Defs.h" #include "Log.h" -CAPRSEntry::CAPRSEntry(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl) : -m_callsign(callsign), -m_band(band), -m_frequency(frequency), -m_offset(offset), -m_range(range), -m_latitude(latitude), -m_longitude(longitude), -m_agl(agl), -m_timer(1000U, 10U), -m_first(true), -m_collector(NULL) -{ - boost::trim(m_callsign); - - m_collector = new CAPRSCollector; -} - -CAPRSEntry::~CAPRSEntry() -{ - delete m_collector; -} - -std::string CAPRSEntry::getCallsign() const -{ - return m_callsign; -} - -std::string CAPRSEntry::getBand() const -{ - return m_band; -} - -double CAPRSEntry::getFrequency() const -{ - return m_frequency; -} - -double CAPRSEntry::getOffset() const -{ - return m_offset; -} - -double CAPRSEntry::getRange() const -{ - return m_range; -} - -double CAPRSEntry::getLatitude() const -{ - return m_latitude; -} - -double CAPRSEntry::getLongitude() const -{ - return m_longitude; -} - -double CAPRSEntry::getAGL() const -{ - return m_agl; -} - -CAPRSCollector* CAPRSEntry::getCollector() const -{ - return m_collector; -} - -void CAPRSEntry::reset() -{ - m_first = true; - m_timer.stop(); - m_collector->reset(); -} - -void CAPRSEntry::clock(unsigned int ms) -{ - m_timer.clock(ms); -} - -bool CAPRSEntry::isOK() -{ - if (m_first) { - m_first = false; - m_timer.start(); - return true; - } - - if (m_timer.hasExpired()) { - m_timer.start(); - return true; - } else { - m_timer.start(); - return false; - } -} - CAPRSWriter::CAPRSWriter(const std::string& hostname, unsigned int port, const std::string& gateway, const std::string& password, const std::string& address) : m_thread(NULL), m_idTimer(1000U), @@ -133,6 +37,12 @@ m_address(), m_port(0U), m_socket(NULL), m_array() +#ifdef USE_GPSD +, m_gpsdEnabled(false), +m_gpsdAddress(), +m_gpsdPort(), +m_gpsdData() +#endif { assert(!hostname.empty()); assert(port > 0U); @@ -164,24 +74,40 @@ void CAPRSWriter::setPortFixed(const std::string& callsign, const std::string& b m_array[temp] = new CAPRSEntry(callsign, band, frequency, offset, range, latitude, longitude, agl); } -void CAPRSWriter::setPortMobile(const std::string& callsign, const std::string& band, double frequency, double offset, double range, const std::string& address, unsigned int port) +#ifdef USE_GPSD +void CAPRSWriter::setPortGPSD(const std::string& callsign, const std::string& band, double frequency, double offset, double range, const std::string& address, const std::string& port) { + assert(!address.empty()); + assert(!port.empty()); + std::string temp = callsign; temp.resize(LONG_CALLSIGN_LENGTH - 1U, ' '); - temp += band; + temp.append(band); m_array[temp] = new CAPRSEntry(callsign, band, frequency, offset, range, 0.0, 0.0, 0.0); - if (m_socket == NULL) { - m_address = CUDPReaderWriter::lookup(address); - m_port = port; - - m_socket = new CUDPReaderWriter(); - } + m_gpsdEnabled = true; + m_gpsdAddress = address; + m_gpsdPort = port; } +#endif bool CAPRSWriter::open() { +#ifdef USE_GPSD + if (m_gpsdEnabled) { + int ret = ::gps_open(m_gpsdAddress.c_str(), m_gpsdPort.c_str(), &m_gpsdData); + if (ret != 0) { + CLog::logError("Error when opening access to gpsd - %d - %s", errno, ::gps_errstr(errno)); + return false; + } + + ::gps_stream(&m_gpsdData, WATCH_ENABLE | WATCH_JSON, NULL); + + CLog::logError("Connected to GPSD"); + } +#endif + if (m_socket != NULL) { bool ret = m_socket->open(); if (!ret) { @@ -293,19 +219,22 @@ void CAPRSWriter::clock(unsigned int ms) m_thread->clock(ms); - if (m_socket != NULL) { +#ifdef USE_GPSD + if (m_gpsdEnabled) { if (m_idTimer.hasExpired()) { - pollGPS(); + sendIdFramesMobile(); m_idTimer.start(); } - sendIdFramesMobile(); } else { +#endif if (m_idTimer.hasExpired()) { sendIdFramesFixed(); m_idTimer.start(); } +#ifdef USE_GPSD } +#endif for (auto it = m_array.begin(); it != m_array.end(); ++it) { if(it->second != NULL) @@ -320,6 +249,13 @@ bool CAPRSWriter::isConnected() const void CAPRSWriter::close() { +#ifdef USE_GPSD + if (m_gpsdEnabled) { + ::gps_stream(&m_gpsdData, WATCH_DISABLE, NULL); + ::gps_close(&m_gpsdData); + } +#endif + if (m_socket != NULL) { m_socket->close(); delete m_socket; @@ -447,34 +383,48 @@ void CAPRSWriter::sendIdFramesFixed() } } +#ifdef USE_GPSD void CAPRSWriter::sendIdFramesMobile() { - // Grab GPS data if it's available - unsigned char buffer[200U]; - in_addr address; - unsigned int port; - int ret = m_socket->read(buffer, 200U, address, port); - if (ret <= 0) + if (!m_gpsdEnabled) return; - if (!m_thread->isConnected()) + if (!::gps_waiting(&m_gpsdData, 0)) + return; + +#if GPSD_API_MAJOR_VERSION >= 7 + if (::gps_read(&m_gpsdData, NULL, 0) <= 0) + return; +#else + if (::gps_read(&m_gpsdData) <= 0) return; +#endif - buffer[ret] = '\0'; +#if GPSD_API_MAJOR_VERSION >= 11 // F4FXL 2021-12-31 not sure if 11 is porper version, best guess as i could not find any change log + if(m_gpsdData.fix.mode < MODE_3D) + return; +#else + if (m_gpsdData.status != STATUS_FIX) + return; +#endif - // Parse the GPS data - char* pLatitude = ::strtok((char*)buffer, ",\n"); // Latitude - char* pLongitude = ::strtok(NULL, ",\n"); // Longitude - char* pAltitude = ::strtok(NULL, ",\n"); // Altitude (m) - char* pVelocity = ::strtok(NULL, ",\n"); // Velocity (kms/h) - char* pBearing = ::strtok(NULL, "\n"); // Bearing + bool latlonSet = (m_gpsdData.set & LATLON_SET) == LATLON_SET; + bool altitudeSet = (m_gpsdData.set & ALTITUDE_SET) == ALTITUDE_SET; + bool velocitySet = (m_gpsdData.set & SPEED_SET) == SPEED_SET; + bool bearingSet = (m_gpsdData.set & TRACK_SET) == TRACK_SET; - if (pLatitude == NULL || pLongitude == NULL || pAltitude == NULL) + if (!latlonSet) return; - double rawLatitude = ::atof(pLatitude); - double rawLongitude = ::atof(pLongitude); - double rawAltitude = ::atof(pAltitude); + float rawLatitude = float(m_gpsdData.fix.latitude); + float rawLongitude = float(m_gpsdData.fix.longitude); +#if GPSD_API_MAJOR_VERSION >= 9 + float rawAltitude = float(m_gpsdData.fix.altMSL); +#else + float rawAltitude = float(m_gpsdData.fix.altitude); +#endif + float rawVelocity = float(m_gpsdData.fix.speed); + float rawBearing = float(m_gpsdData.fix.track); time_t now; ::time(&now); @@ -557,15 +507,11 @@ void CAPRSWriter::sendIdFramesMobile() rawAltitude * 3.28); std::string output2; - if (pBearing != NULL && pVelocity != NULL) { - double rawBearing = ::atof(pBearing); - double rawVelocity = ::atof(pVelocity); - + if (bearingSet && velocitySet) output2 = CStringUtils::string_format("%03.0lf/%03.0lf", rawBearing, rawVelocity * 0.539957F); - } std::string output3; - output3 = CStringUtils::string_format("RNG%04.0lf %s %s", entry->getRange() * 0.6214, band.c_str(), desc.c_str()); + output3 = CStringUtils::string_format("RNG%04.0lf %s %s\r\n", entry->getRange() * 0.6214, band.c_str(), desc.c_str()); char ascii[300U]; ::memset(ascii, 0x00, 300U); @@ -577,14 +523,22 @@ void CAPRSWriter::sendIdFramesMobile() for (unsigned int i = 0U; i < output3.length(); i++, n++) ascii[n] = output3[i]; + CLog::logDebug("APRS ==> %s%s%s", output1.c_str(), output2.c_str(), output3.c_str()); + m_thread->write(ascii); if (entry->getBand().length() == 1U) { - output1 = CStringUtils::string_format("%s-%s>APD5T2,TCPIP*,qAC,%s-%sS:!%s%cD%s%c&/A=%06.0lf", - entry->getCallsign().c_str(), entry->getBand().c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(), - lat.c_str(), (rawLatitude < 0.0) ? 'S' : 'N', - lon.c_str(), (rawLongitude < 0.0) ? 'W' : 'E', - rawAltitude * 3.28); + if (altitudeSet) + output1 = CStringUtils::string_format("%s-%s>APD5T2,TCPIP*,qAC,%s-%sS:!%s%cD%s%c&/A=%06.0lf", + entry->getCallsign().c_str(), entry->getBand().c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(), + lat.c_str(), (rawLatitude < 0.0) ? 'S' : 'N', + lon.c_str(), (rawLongitude < 0.0) ? 'W' : 'E', + rawAltitude * 3.28); + else + output1 = CStringUtils::string_format("%s-%s>APD5T2,TCPIP*,qAC,%s-%sS:!%s%cD%s%c&", + entry->getCallsign().c_str(), entry->getBand().c_str(), entry->getCallsign().c_str(), entry->getBand().c_str(), + lat.c_str(), (rawLatitude < 0.0) ? 'S' : 'N', + lon.c_str(), (rawLongitude < 0.0) ? 'W' : 'E'); ::memset(ascii, 0x00, 300U); unsigned int n = 0U; @@ -595,8 +549,10 @@ void CAPRSWriter::sendIdFramesMobile() for (unsigned int i = 0U; i < output3.length(); i++, n++) ascii[n] = output3[i]; + CLog::logDebug("APRS ==> %s%s%s", output1.c_str(), output2.c_str(), output3.c_str()); + m_thread->write(ascii); } } } - +#endif diff --git a/APRSWriter.h b/APRSWriter.h index 54c672c..42ba576 100644 --- a/APRSWriter.h +++ b/APRSWriter.h @@ -22,7 +22,11 @@ #include #include +#ifdef USE_GPSD +#include +#endif +#include "APRSEntry.h" #include "APRSWriterThread.h" #include "UDPReaderWriter.h" #include "APRSCollector.h" @@ -32,40 +36,6 @@ #include "Timer.h" #include "Defs.h" -class CAPRSEntry { -public: - CAPRSEntry(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl); - ~CAPRSEntry(); - - std::string getCallsign() const; - std::string getBand() const; - double getFrequency() const; - double getOffset() const; - double getRange() const; - double getLatitude() const; - double getLongitude() const; - double getAGL() const; - CAPRSCollector* getCollector() const; - - // Transmission timer - void reset(); - void clock(unsigned int ms); - bool isOK(); - -private: - std::string m_callsign; - std::string m_band; - double m_frequency; - double m_offset; - double m_range; - double m_latitude; - double m_longitude; - double m_agl; - CTimer m_timer; - bool m_first; - CAPRSCollector* m_collector; -}; - class CAPRSWriter { public: CAPRSWriter(const std::string& hostname, unsigned int port, const std::string& gateway, const std::string& password, const std::string& address); @@ -74,9 +44,9 @@ public: bool open(); void setPortFixed(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl); - - void setPortMobile(const std::string& callsign, const std::string& band, double frequency, double offset, double range, const std::string& address, unsigned int port); - +#ifdef USE_GPSD + void setPortGPSD(const std::string& callsign, const std::string& band, double frequency, double offset, double range, const std::string& address, const std::string& port); +#endif void writeHeader(const std::string& callsign, const CHeaderData& header); void writeData(const std::string& callsign, const CAMBEData& data); @@ -96,6 +66,13 @@ private: CUDPReaderWriter* m_socket; std::unordered_map m_array; +#ifdef USE_GPSD + bool m_gpsdEnabled; + std::string m_gpsdAddress; + std::string m_gpsdPort; + struct gps_data_t m_gpsdData; +#endif + bool pollGPS(); void sendIdFramesFixed(); void sendIdFramesMobile(); diff --git a/DStarGatewayApp.cpp b/DStarGatewayApp.cpp index 33c6239..d5a450e 100644 --- a/DStarGatewayApp.cpp +++ b/DStarGatewayApp.cpp @@ -125,15 +125,14 @@ bool CDStarGatewayApp::createThread() CAPRSWriter * aprsWriter = NULL; if(aprsConfig.enabled && !aprsConfig.password.empty()) { aprsWriter = new CAPRSWriter(aprsConfig.hostname, aprsConfig.port, gatewayConfig.callsign, aprsConfig.password, gatewayConfig.address); - if(aprsWriter->open()) { - m_thread->setAPRSWriter(aprsWriter); - } - else { - delete aprsWriter; - aprsWriter = NULL; - } } +#ifdef USE_GPSD + // Setup GPSD + TGPSD gpsdConfig; + config.getGPSD(gpsdConfig); +#endif + // Setup the repeaters if(config.getRepeaterCount() == 0U) { CLog::logInfo("No repeater configured\n"); @@ -165,13 +164,34 @@ bool CDStarGatewayApp::createThread() rptrConfig.band1, rptrConfig.band2, rptrConfig.band3); - - if(aprsWriter != NULL) aprsWriter->setPortFixed(rptrConfig.callsign, rptrConfig.band, rptrConfig.frequency, rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, rptrConfig.longitude, rptrConfig.agl); +#ifdef USE_GPSD + if(aprsWriter != NULL) { + if(aprsConfig.m_positionSource == POSSRC_GPSD) + aprsWriter->setPortGPSD(rptrConfig.callsign, rptrConfig.band, rptrConfig.frequency, rptrConfig.offset, rptrConfig.range, gpsdConfig.m_address, gpsdConfig.m_port); + else + aprsWriter->setPortFixed(rptrConfig.callsign, rptrConfig.band, rptrConfig.frequency, rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, rptrConfig.longitude, rptrConfig.agl); + + } +#else + aprsWriter->setPortFixed(rptrConfig.callsign, rptrConfig.band, rptrConfig.frequency, rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, rptrConfig.longitude, rptrConfig.agl); +#endif + if(!ddEnabled) ddEnabled = rptrConfig.band.length() > 1U; } m_thread->setDDModeEnabled(ddEnabled); CLog::logInfo("DD Mode enabled: %d", int(ddEnabled)); + // open APRS after setting the repeaters because of GPSD + if(aprsWriter != nullptr) { + if(aprsWriter->open()) { + m_thread->setAPRSWriter(aprsWriter); + } + else { + delete aprsWriter; + aprsWriter = NULL; + } + } + // Setup ircddb std::vector clients; for(unsigned int i=0; i < config.getIrcDDBCount(); i++) { diff --git a/DStarGatewayConfig.cpp b/DStarGatewayConfig.cpp index d2ad9af..a976c1f 100644 --- a/DStarGatewayConfig.cpp +++ b/DStarGatewayConfig.cpp @@ -52,6 +52,9 @@ bool CDStarGatewayConfig::load() ret = loadDPlus(cfg) && ret; ret = loadRemote(cfg) && ret; ret = loadXLX(cfg) && ret; +#ifdef USE_GPSD + ret = loadGPSD(cfg) && ret; +#endif } if(ret) { @@ -118,6 +121,16 @@ bool CDStarGatewayConfig::loadAPRS(const CConfig & cfg) ret = cfg.getValue("aprs", "port", m_aprs.port, 1U, 65535U, 14580U) && ret; ret = cfg.getValue("aprs", "hostname", m_aprs.hostname, 0, 1024, "rotate.aprs2.net") && ret; ret = cfg.getValue("aprs", "password", m_aprs.password, 0U, 30U, "") && ret; +#ifdef USE_GPSD + std::string positionSource; + ret = cfg.getValue("aprs", "positionSource", positionSource, "fixed", {"fixed", "gpsd"}) && ret; + if(ret) { + if(positionSource == "fixed") m_aprs.m_positionSource = POSSRC_FIXED; + else if(positionSource == "gpsd") m_aprs.m_positionSource = POSSRC_GPSD; + } +#else + m_aprs.m_positionSource = POSSRC_FIXED; +#endif m_aprs.enabled = m_aprs.enabled && !m_aprs.password.empty(); @@ -319,6 +332,16 @@ bool CDStarGatewayConfig::loadGateway(const CConfig & cfg) return ret; } +#ifdef USE_GPSD +bool CDStarGatewayConfig::loadGPSD(const CConfig & cfg) +{ + bool ret = cfg.getValue("gpsd", "address", m_gpsd.m_address, 0U, 15U, "127.0.0.1"); + ret = cfg.getValue("gpsd", "port", m_gpsd.m_port, 0U, 5U, "2947") && ret; + + return ret; +} +#endif + bool CDStarGatewayConfig::open(CConfig & cfg) { try { @@ -408,3 +431,10 @@ void CDStarGatewayConfig::getXLX(TXLX & xlx) const { xlx = m_xlx; } + +#ifdef USE_GPSD +void CDStarGatewayConfig::getGPSD(TGPSD & gpsd) const +{ + gpsd = m_gpsd; +} +#endif diff --git a/DStarGatewayConfig.h b/DStarGatewayConfig.h index a406dc0..b27ca44 100644 --- a/DStarGatewayConfig.h +++ b/DStarGatewayConfig.h @@ -91,6 +91,7 @@ typedef struct { std::string hostname; unsigned int port; std::string password; + POSITION_SOURCE m_positionSource; } TAPRS; typedef struct { @@ -120,6 +121,12 @@ typedef struct { std::string password; } TRemote; +#ifdef USE_GPSD +typedef struct { + std::string m_address; + std::string m_port; +} TGPSD; +#endif class CDStarGatewayConfig { public: @@ -140,6 +147,9 @@ public: void getDCS(TDCS & dcs) const; void getRemote(TRemote & remote) const; void getXLX(TXLX & xlx) const; +#ifdef USE_GPSD + void getGPSD(TGPSD & gpsd) const; +#endif private: bool open(CConfig & cfg); @@ -154,6 +164,9 @@ private: bool loadDCS(const CConfig & cfg); bool loadRemote(const CConfig & cfg); bool loadXLX(const CConfig & cfg); +#ifdef USE_GPSD + bool loadGPSD(const CConfig & cfg); +#endif std::string m_fileName; TGateway m_gateway; @@ -165,6 +178,9 @@ private: TRemote m_remote; TXLX m_xlx; TLog m_log; +#ifdef USE_GPSD + TGPSD m_gpsd; +#endif std::vector m_repeaters; std::vector m_ircDDB; }; diff --git a/Defs.h b/Defs.h index 273ed25..2f12568 100644 --- a/Defs.h +++ b/Defs.h @@ -137,5 +137,10 @@ enum GATEWAY_TYPE { GT_SMARTGROUP }; +enum POSITION_SOURCE { + POSSRC_FIXED, + POSSRC_GPSD +}; + const unsigned int TIME_PER_TIC_MS = 5U; diff --git a/Makefile b/Makefile index 3e1e2e4..efa44c5 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,13 @@ CPPFLAGS=-g -ggdb -W -Wall -std=c++17 # or, you can choose this for a much smaller executable without debugging help #CPPFLAGS=-W -Wall -std=c++17 +LDFLAGS:=-lcurl -pthread + +ifeq ($(USE_GPSD), 1) +CPPFLAGS+= -DUSE_GPSD +LDFLAGS+= -lgps +endif + SRCS = $(wildcard *.cpp) OBJS = $(SRCS:.cpp=.o) DEPS = $(SRCS:.cpp=.d) @@ -34,7 +41,7 @@ DEPS = $(SRCS:.cpp=.d) all: dstargateway dstargateway : GitVersion.h $(OBJS) - g++ $(CPPFLAGS) -o dstargateway $(OBJS) -lcurl -pthread + g++ $(CPPFLAGS) -o dstargateway $(OBJS) $(LDFLAGS) %.o : %.cpp g++ $(CPPFLAGS) -MMD -MD -c $< -o $@