diff --git a/Common/APRSEntry.cpp b/Common/APRSEntry.cpp index 13d1b1a..26a9416 100644 --- a/Common/APRSEntry.cpp +++ b/Common/APRSEntry.cpp @@ -21,7 +21,7 @@ #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) : +CAPRSEntry::CAPRSEntry(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl, GATEWAY_TYPE gwType) : m_callsign(callsign), m_band(band), m_frequency(frequency), @@ -33,7 +33,8 @@ m_agl(agl), m_timer(1000U, 10U), m_first(true), m_collector(NULL), -m_linkStatus() +m_linkStatus(), +m_gatewayType(gwType) { boost::trim(m_callsign); @@ -95,6 +96,11 @@ CAPRSEntryStatus& CAPRSEntry::getStatus() return m_linkStatus; } +GATEWAY_TYPE CAPRSEntry::getType() const +{ + return m_gatewayType; +} + void CAPRSEntry::reset() { m_first = true; diff --git a/Common/APRSEntry.h b/Common/APRSEntry.h index e9bc5af..d5d17a0 100644 --- a/Common/APRSEntry.h +++ b/Common/APRSEntry.h @@ -28,7 +28,7 @@ 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(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl, GATEWAY_TYPE gwType); ~CAPRSEntry(); std::string getCallsign() const; @@ -41,6 +41,7 @@ public: double getAGL() const; CAPRSCollector* getCollector() const; CAPRSEntryStatus& getStatus(); + GATEWAY_TYPE getType() const; // Transmission timer void reset(); @@ -60,4 +61,5 @@ private: bool m_first; CAPRSCollector* m_collector; CAPRSEntryStatus m_linkStatus; + GATEWAY_TYPE m_gatewayType; }; diff --git a/Common/APRSFixedIdFrameProvider.cpp b/Common/APRSFixedIdFrameProvider.cpp index 1763b24..bf42ab9 100644 --- a/Common/APRSFixedIdFrameProvider.cpp +++ b/Common/APRSFixedIdFrameProvider.cpp @@ -116,8 +116,11 @@ bool CAPRSFixedIdFrameProvider::buildAPRSFramesInt(const CAPRSEntry * entry, std lon.c_str(), (entry->getLongitude() < 0.0F) ? 'W' : 'E', entry->getRange() * 0.6214, entry->getAGL() * 3.28, band.c_str(), desc.c_str()); + std::string toCall; + getToCall(entry->getType(), toCall); + CAPRSFrame * frame = new CAPRSFrame(m_gateway + "-S", - "APD5T1", + toCall, { "TCPIP*", "qAC" , m_gateway + "-GS" }, body, APFT_OBJECT); @@ -130,7 +133,7 @@ bool CAPRSFixedIdFrameProvider::buildAPRSFramesInt(const CAPRSEntry * entry, std entry->getRange() * 0.6214, entry->getAGL() * 3.28, band.c_str(), desc.c_str()); frame = new CAPRSFrame(entry->getCallsign() + "-" + entry->getBand(), - "APD5T2", + toCall, { "TCPIP*", "qAC", entry->getCallsign() + "-" + entry->getBand() + "S"}, body, APFT_POSITION); diff --git a/Common/APRSGPSDIdFrameProvider.cpp b/Common/APRSGPSDIdFrameProvider.cpp index 78cee71..7592305 100644 --- a/Common/APRSGPSDIdFrameProvider.cpp +++ b/Common/APRSGPSDIdFrameProvider.cpp @@ -188,9 +188,11 @@ bool CAPRSGPSDIdFrameProvider::buildAPRSFramesInt(const CAPRSEntry * entry, std: body.append(CStringUtils::string_format("RNG%04.0lf %s %s\r\n", entry->getRange() * 0.6214, band.c_str(), desc.c_str())); + std::string toCall; + getToCall(entry->getType(), toCall); CAPRSFrame * frame = new CAPRSFrame(m_gateway + "-S", - "APD5T1", + toCall, { "TCPIP*", "qAC" , m_gateway + "-GS" }, body, APFT_OBJECT); @@ -209,7 +211,7 @@ bool CAPRSGPSDIdFrameProvider::buildAPRSFramesInt(const CAPRSEntry * entry, std: lon.c_str(), (rawLongitude < 0.0) ? 'W' : 'E'); frame = new CAPRSFrame(m_gateway, - "APD5T2", + toCall, { "TCPIP*", "qAC" , m_gateway + "-GS" }, body, APFT_POSITION); diff --git a/Common/APRSHandler.cpp b/Common/APRSHandler.cpp index e39df77..f6668b8 100644 --- a/Common/APRSHandler.cpp +++ b/Common/APRSHandler.cpp @@ -51,13 +51,13 @@ CAPRSHandler::~CAPRSHandler() delete m_backend; } -void CAPRSHandler::setPort(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl) +void CAPRSHandler::setPort(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl, GATEWAY_TYPE gwType) { std::string temp = callsign; temp.resize(LONG_CALLSIGN_LENGTH - 1U, ' '); temp += band; - m_array[temp] = new CAPRSEntry(callsign, band, frequency, offset, range, latitude, longitude, agl); + m_array[temp] = new CAPRSEntry(callsign, band, frequency, offset, range, latitude, longitude, agl, gwType); } bool CAPRSHandler::open() @@ -182,9 +182,12 @@ void CAPRSHandler::sendStatusFrame(CAPRSEntry * entry) body.insert(0, ">"); std::string sourCall = entry->getCallsign() + '-' + entry->getBand(); + + std::string toCall; + CAPRSIdFrameProvider::getToCall(entry->getType(), toCall); CAPRSFrame frame(sourCall, - "APD5T3", + toCall, { "TCPIP*", "qAC", sourCall + "S" }, body, APFT_STATUS); diff --git a/Common/APRSHandler.h b/Common/APRSHandler.h index dea2046..3112c5e 100644 --- a/Common/APRSHandler.h +++ b/Common/APRSHandler.h @@ -44,7 +44,7 @@ public: void setIdFrameProvider(CAPRSIdFrameProvider * idFrameProvider) { m_idFrameProvider = idFrameProvider; } - void setPort(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl); + void setPort(const std::string& callsign, const std::string& band, double frequency, double offset, double range, double latitude, double longitude, double agl, GATEWAY_TYPE gwType); void writeHeader(const std::string& callsign, const CHeaderData& header); diff --git a/Common/APRSIdFrameProvider.cpp b/Common/APRSIdFrameProvider.cpp index fc8b6e0..b4e3be0 100644 --- a/Common/APRSIdFrameProvider.cpp +++ b/Common/APRSIdFrameProvider.cpp @@ -56,3 +56,21 @@ bool CAPRSIdFrameProvider::wantsToSend() return false; } + +void CAPRSIdFrameProvider::getToCall(GATEWAY_TYPE gwType, std::string& toCall) +{ + switch(gwType) + { + case GT_REPEATER: + toCall.assign("APD5TR"); + return; + case GT_HOTSPOT: + toCall.assign("APD5TH"); + return; + case GT_DONGLE: + toCall.assign("APD5TD"); + return; + default: + toCall.assign("APD5T0"); + } +} diff --git a/Common/APRSIdFrameProvider.h b/Common/APRSIdFrameProvider.h index f123118..b248b21 100644 --- a/Common/APRSIdFrameProvider.h +++ b/Common/APRSIdFrameProvider.h @@ -35,6 +35,7 @@ public: bool wantsToSend(); virtual void start() { }; virtual void close() { }; + static void getToCall(GATEWAY_TYPE gwType, std::string& toCall); protected: virtual bool buildAPRSFramesInt(const CAPRSEntry * aprsEntry, std::vector& frames) = 0; diff --git a/DStarGateway/DStarGatewayApp.cpp b/DStarGateway/DStarGatewayApp.cpp index a62550b..e9384fe 100644 --- a/DStarGateway/DStarGatewayApp.cpp +++ b/DStarGateway/DStarGatewayApp.cpp @@ -286,9 +286,9 @@ bool CDStarGatewayApp::createThread() rptrConfig.band3); if(outgoingAprsWriter != nullptr) - outgoingAprsWriter->setPort(rptrConfig.callsign, rptrConfig.band, rptrConfig.frequency, rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, rptrConfig.longitude, rptrConfig.agl); + outgoingAprsWriter->setPort(rptrConfig.callsign, rptrConfig.band, rptrConfig.frequency, rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, rptrConfig.longitude, rptrConfig.agl, gatewayConfig.type); if(incomingAprsWriter != nullptr) - incomingAprsWriter->setPort(rptrConfig.callsign, rptrConfig.band, rptrConfig.frequency, rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, rptrConfig.longitude, rptrConfig.agl); + incomingAprsWriter->setPort(rptrConfig.callsign, rptrConfig.band, rptrConfig.frequency, rptrConfig.offset, rptrConfig.range, rptrConfig.latitude, rptrConfig.longitude, rptrConfig.agl, gatewayConfig.type); if(!ddEnabled) ddEnabled = rptrConfig.band.length() > 1U; } diff --git a/README.md b/README.md index b13e116..2b7935a 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ The testing framwework used is Google Test. # 5. Version History ## 5.1. Version 1.0 -- [**Improvement**] APRS Improvements: Diplay 220MHz in APRS Posits ([#42](https://github.com/F4FXL/DStarGateway/issues/42)) +- [**Improvement**] APRS Improvements: Diplay 220MHz in APRS Posits, add different ToCalls depending on gateway type ([#42](https://github.com/F4FXL/DStarGateway/issues/42)) - [**Improvement**] Improve CI to include all variants of build configurations ([#40](https://github.com/F4FXL/DStarGateway/issues/40)) - [**Bugfix**] Fix #37 Unable to transmit multiple files (DGWVoiceTransmit) ([#37](https://github.com/F4FXL/DStarGateway/issues/37)) - [**Bugfix**] Fix #36 Error1 Build fails in some environment ([#36](https://github.com/F4FXL/DStarGateway/issues/36)) diff --git a/Tests/APRSIdFrameProvider/getToCall.cpp b/Tests/APRSIdFrameProvider/getToCall.cpp new file mode 100644 index 0000000..deb3562 --- /dev/null +++ b/Tests/APRSIdFrameProvider/getToCall.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021-2023 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 "APRSIdFrameProvider.h" + +namespace APRSIdFrameProviderTests +{ + class APRSIdFrameProvider_getToCall : public ::testing::Test { + + }; + + TEST_F(APRSIdFrameProvider_getToCall, RepeaterToCall) + { + std::string toCall; + CAPRSIdFrameProvider::getToCall(GT_REPEATER, toCall); + + EXPECT_STRCASEEQ(toCall.c_str(), "APD5TR") << "Unexpected toCall"; + } + + TEST_F(APRSIdFrameProvider_getToCall, HotspotToCall) + { + std::string toCall; + CAPRSIdFrameProvider::getToCall(GT_HOTSPOT, toCall); + + EXPECT_STRCASEEQ(toCall.c_str(), "APD5TH") << "Unexpected toCall"; + } + + TEST_F(APRSIdFrameProvider_getToCall, DongleToCall) + { + std::string toCall; + CAPRSIdFrameProvider::getToCall(GT_DONGLE, toCall); + + EXPECT_STRCASEEQ(toCall.c_str(), "APD5TD") << "Unexpected toCall"; + } + + TEST_F(APRSIdFrameProvider_getToCall, SmartGroupToCall) + { + std::string toCall; + CAPRSIdFrameProvider::getToCall(GT_SMARTGROUP, toCall); + + EXPECT_STRCASEEQ(toCall.c_str(), "APD5T0") << "Unexpected toCall"; + } + + TEST_F(APRSIdFrameProvider_getToCall, UnknownToCall) + { + std::string toCall; + CAPRSIdFrameProvider::getToCall((GATEWAY_TYPE)123456789, toCall); + + EXPECT_STRCASEEQ(toCall.c_str(), "APD5T0"); + } +}