Skip to content

Commit

Permalink
#42 add different APRS to Call depending on gateway type
Browse files Browse the repository at this point in the history
  • Loading branch information
F4FXL committed Dec 27, 2023
1 parent fa80327 commit e45103f
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 14 deletions.
10 changes: 8 additions & 2 deletions Common/APRSEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);

Expand Down Expand Up @@ -95,6 +96,11 @@ CAPRSEntryStatus& CAPRSEntry::getStatus()
return m_linkStatus;
}

GATEWAY_TYPE CAPRSEntry::getType() const
{
return m_gatewayType;
}

void CAPRSEntry::reset()
{
m_first = true;
Expand Down
4 changes: 3 additions & 1 deletion Common/APRSEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,6 +41,7 @@ class CAPRSEntry {
double getAGL() const;
CAPRSCollector* getCollector() const;
CAPRSEntryStatus& getStatus();
GATEWAY_TYPE getType() const;

// Transmission timer
void reset();
Expand All @@ -60,4 +61,5 @@ class CAPRSEntry {
bool m_first;
CAPRSCollector* m_collector;
CAPRSEntryStatus m_linkStatus;
GATEWAY_TYPE m_gatewayType;
};
7 changes: 5 additions & 2 deletions Common/APRSFixedIdFrameProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions Common/APRSGPSDIdFrameProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
9 changes: 6 additions & 3 deletions Common/APRSHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Common/APRSHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CAPRSHandler {

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);

Expand Down
18 changes: 18 additions & 0 deletions Common/APRSIdFrameProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
1 change: 1 addition & 0 deletions Common/APRSIdFrameProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CAPRSIdFrameProvider
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<CAPRSFrame *>& frames) = 0;
Expand Down
4 changes: 2 additions & 2 deletions DStarGateway/DStarGatewayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
68 changes: 68 additions & 0 deletions Tests/APRSIdFrameProvider/getToCall.cpp
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

#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");
}
}

0 comments on commit e45103f

Please sign in to comment.