From 2266f2d8a7d4d674471b0f94baf9341ac2b38fc6 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 25 Apr 2023 15:59:35 +0200 Subject: [PATCH 01/10] Process hyphen in callsign #33 --- .vscode/tasks.json | 10 ++--- APRS/APRSUtils.cpp | 6 +++ Tests/APRSUtils/calcGPSAIcomCRC.cpp | 2 +- Tests/APRSUtils/dstarCallsignToAPRS.cpp | 51 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 Tests/APRSUtils/dstarCallsignToAPRS.cpp diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6d6532b..9f00615 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,10 +13,7 @@ "USE_GPSD=1", "all" ], - "group": { - "kind": "build", - "isDefault": true - }, + "group": "build", "problemMatcher": [] }, { @@ -94,7 +91,10 @@ "ENABLE_DEBUG=1", "USE_GPSD=1" ], - "group": "build", + "group": { + "kind": "build", + "isDefault": true + }, "problemMatcher": [] } ] diff --git a/APRS/APRSUtils.cpp b/APRS/APRSUtils.cpp index 5684088..1d4694c 100644 --- a/APRS/APRSUtils.cpp +++ b/APRS/APRSUtils.cpp @@ -22,6 +22,12 @@ void CAPRSUtils::dstarCallsignToAPRS(std::string& dstarCallsign) { + // 20230425 Fix for https://github.com/F4FXL/DStarGateway/issues/33 + size_t hyphenIndex = dstarCallsign.find('-'); + if(hyphenIndex != std::string::npos) { + dstarCallsign = dstarCallsign.substr(0, hyphenIndex); + } + if(dstarCallsign[dstarCallsign.length() - 1] == ' ') { boost::trim(dstarCallsign); } else { diff --git a/Tests/APRSUtils/calcGPSAIcomCRC.cpp b/Tests/APRSUtils/calcGPSAIcomCRC.cpp index 9d5850c..d6a96d5 100644 --- a/Tests/APRSUtils/calcGPSAIcomCRC.cpp +++ b/Tests/APRSUtils/calcGPSAIcomCRC.cpp @@ -20,7 +20,7 @@ #include "APRSUtils.h" -namespace APRStoDPRSTests +namespace APRSUtilsTests { class APRSUtils_calcGPSAIcomCRC : public ::testing::Test { }; diff --git a/Tests/APRSUtils/dstarCallsignToAPRS.cpp b/Tests/APRSUtils/dstarCallsignToAPRS.cpp new file mode 100644 index 0000000..3bf5792 --- /dev/null +++ b/Tests/APRSUtils/dstarCallsignToAPRS.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021-2022 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 "APRSUtils.h" + +namespace APRSUtilsTests +{ + class APRSUtils_dstarCallsignToAPRS : public ::testing::Test { + }; + + TEST_F(APRSUtils_dstarCallsignToAPRS, noBlanks) + { + std::string call("N0CALL"); + CAPRSUtils::dstarCallsignToAPRS(call); + + EXPECT_STRCASEEQ(call.c_str(), "N0CALL") << "Call shall not have changed"; + } + + TEST_F(APRSUtils_dstarCallsignToAPRS, withHyphen) + { + std::string call("N0CALL-H"); + CAPRSUtils::dstarCallsignToAPRS(call); + + EXPECT_STRCASEEQ(call.c_str(), "N0CALL") << "-H shall have been removed"; + } + + TEST_F(APRSUtils_dstarCallsignToAPRS, threeBlanks) + { + std::string call("F4AB B"); + CAPRSUtils::dstarCallsignToAPRS(call); + + EXPECT_STRCASEEQ(call.c_str(), "F4AB-B") << "-H shall have been removed"; + } +} \ No newline at end of file From 30031eb8523706471f4a12c51925b0f8b4dc10d9 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 25 Apr 2023 16:08:52 +0200 Subject: [PATCH 02/10] Bump date --- Tests/APRSUtils/dstarCallsignToAPRS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/APRSUtils/dstarCallsignToAPRS.cpp b/Tests/APRSUtils/dstarCallsignToAPRS.cpp index 3bf5792..832b8fa 100644 --- a/Tests/APRSUtils/dstarCallsignToAPRS.cpp +++ b/Tests/APRSUtils/dstarCallsignToAPRS.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA + * 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 From 3a7cfeb46525a85d71b4f9b3c1f4ce8dc3a7667f Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 26 Apr 2023 05:28:49 +0200 Subject: [PATCH 03/10] Correctly handle "ssid" in dstar callsign #33 --- APRS/APRSUtils.cpp | 6 ------ Common/HeardData.cpp | 4 ++-- Common/NMEASentenceCollector.cpp | 9 ++++++++- Tests/APRSUtils/dstarCallsignToAPRS.cpp | 6 +++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/APRS/APRSUtils.cpp b/APRS/APRSUtils.cpp index 1d4694c..5684088 100644 --- a/APRS/APRSUtils.cpp +++ b/APRS/APRSUtils.cpp @@ -22,12 +22,6 @@ void CAPRSUtils::dstarCallsignToAPRS(std::string& dstarCallsign) { - // 20230425 Fix for https://github.com/F4FXL/DStarGateway/issues/33 - size_t hyphenIndex = dstarCallsign.find('-'); - if(hyphenIndex != std::string::npos) { - dstarCallsign = dstarCallsign.substr(0, hyphenIndex); - } - if(dstarCallsign[dstarCallsign.length() - 1] == ' ') { boost::trim(dstarCallsign); } else { diff --git a/Common/HeardData.cpp b/Common/HeardData.cpp index 8db0434..1b1ac8d 100644 --- a/Common/HeardData.cpp +++ b/Common/HeardData.cpp @@ -67,8 +67,8 @@ bool CHeardData::setIcomRepeaterData(const unsigned char *data, unsigned int len std::string suser((const char *)data + 10U); std::string srptr((const char *)data + 18U); - m_user = suser.substr(LONG_CALLSIGN_LENGTH); - m_repeater = srptr.substr(LONG_CALLSIGN_LENGTH); + m_user = suser.substr(0, LONG_CALLSIGN_LENGTH); + m_repeater = srptr.substr(0, LONG_CALLSIGN_LENGTH); m_address = address; m_port = port; diff --git a/Common/NMEASentenceCollector.cpp b/Common/NMEASentenceCollector.cpp index 5136a61..3e114dd 100644 --- a/Common/NMEASentenceCollector.cpp +++ b/Common/NMEASentenceCollector.cpp @@ -107,8 +107,15 @@ bool CNMEASentenceCollector::getDataInt(std::string& data) std::string fromCall = getMyCall1(); CAPRSUtils::dstarCallsignToAPRS(fromCall); + + // 20230425 Fix for https://github.com/F4FXL/DStarGateway/issues/33 + size_t hyphenIndex = fromCall.find('-'); + if(hyphenIndex != std::string::npos) { + fromCall = fromCall.append("-5"); + } + std::string aprsFrame(fromCall); - aprsFrame.append("-5>GPS30,DSTAR*:") + aprsFrame.append(">GPS30,DSTAR*:") .append(nmea); data.assign(aprsFrame); diff --git a/Tests/APRSUtils/dstarCallsignToAPRS.cpp b/Tests/APRSUtils/dstarCallsignToAPRS.cpp index 832b8fa..4f8cdcb 100644 --- a/Tests/APRSUtils/dstarCallsignToAPRS.cpp +++ b/Tests/APRSUtils/dstarCallsignToAPRS.cpp @@ -33,12 +33,12 @@ namespace APRSUtilsTests EXPECT_STRCASEEQ(call.c_str(), "N0CALL") << "Call shall not have changed"; } - TEST_F(APRSUtils_dstarCallsignToAPRS, withHyphen) + TEST_F(APRSUtils_dstarCallsignToAPRS, twoBlanks) { - std::string call("N0CALL-H"); + std::string call("F4ABC B"); CAPRSUtils::dstarCallsignToAPRS(call); - EXPECT_STRCASEEQ(call.c_str(), "N0CALL") << "-H shall have been removed"; + EXPECT_STRCASEEQ(call.c_str(), "F4ABC-B") << "-H shall have been removed"; } TEST_F(APRSUtils_dstarCallsignToAPRS, threeBlanks) From d24151a932d36c5413eb2343a5a317a148b9e212 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 26 Apr 2023 05:38:15 +0200 Subject: [PATCH 04/10] Make correct test and proper use of append #33 --- Common/NMEASentenceCollector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Common/NMEASentenceCollector.cpp b/Common/NMEASentenceCollector.cpp index 3e114dd..c69e9e5 100644 --- a/Common/NMEASentenceCollector.cpp +++ b/Common/NMEASentenceCollector.cpp @@ -108,10 +108,10 @@ bool CNMEASentenceCollector::getDataInt(std::string& data) std::string fromCall = getMyCall1(); CAPRSUtils::dstarCallsignToAPRS(fromCall); - // 20230425 Fix for https://github.com/F4FXL/DStarGateway/issues/33 + // 20230425 Fix for https://github.com/F4FXL/DStarGateway/issues/33 size_t hyphenIndex = fromCall.find('-'); - if(hyphenIndex != std::string::npos) { - fromCall = fromCall.append("-5"); + if(hyphenIndex == std::string::npos) { + fromCall.append("-5"); } std::string aprsFrame(fromCall); From 4e5e706c3647b0e741bca83983dacc09b719e9e4 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 26 Apr 2023 06:37:37 +0200 Subject: [PATCH 05/10] Add some behavior tests for #33 --- Tests/NMEASentenceCollector/callSignTests.cpp | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Tests/NMEASentenceCollector/callSignTests.cpp diff --git a/Tests/NMEASentenceCollector/callSignTests.cpp b/Tests/NMEASentenceCollector/callSignTests.cpp new file mode 100644 index 0000000..ca2e9a5 --- /dev/null +++ b/Tests/NMEASentenceCollector/callSignTests.cpp @@ -0,0 +1,85 @@ +/* + * 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 "NMEASentenceCollector.h" + +namespace NMEASentenceCollectorTests +{ + class NMEASentenceCollectorTests_APRSFrame: public ::testing::Test + { + protected: + CNMEASentenceCollector * m_collector; + + void SetUp() override + { + m_collector = new CNMEASentenceCollector("$GPRMC"); + + std::string nmea("$GPRMC,092751.000,A,5321.6802,N,00630.3371,W,0.06,31.66,280511,,,A*45\x0A"); + + unsigned char data[3]; + unsigned int len = nmea.length() + (nmea.length() % 3); + bool first = true; + + for (unsigned int i = 0; i < len;) { + if(first) { + data[0] = SLOW_DATA_TYPE_GPS ^ SCRAMBLER_BYTE1; + first = false; + } + else { + data[0] = (i < nmea.length() ? nmea[i] : 'f') ^ SCRAMBLER_BYTE1; + i++; + first = true; + } + data[1] = (i < nmea.length() ? nmea[i] : 'f') ^ SCRAMBLER_BYTE2; + i++; + data[2] = (i < nmea.length() ? nmea[i] : 'f') ^ SCRAMBLER_BYTE3; + i++; + + m_collector->writeData(data); + } + + } + + void TearDown() override + { + delete m_collector; + } + }; + + TEST_F(NMEASentenceCollectorTests_APRSFrame, noSSIDinCallsign) + { + std::string data; + + m_collector->setMyCall1("N0CALL"); + m_collector->getData(data); + + EXPECT_TRUE(data.find("N0CALL-5") != std::string::npos) << "Callsign in APRS frame shall be N0CALL-5"; + } + + TEST_F(NMEASentenceCollectorTests_APRSFrame, SSIDinCallsign) + { + std::string data; + + m_collector->setMyCall1("N0CALL H"); + m_collector->getData(data); + + EXPECT_TRUE(data.find("N0CALL") != std::string::npos) << "Callsign in APRS frame shall be N0CALL-H"; + } +} \ No newline at end of file From 867c0485b0500d515adc0f58221ec19d4dd1b2f0 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 26 Apr 2023 06:42:25 +0200 Subject: [PATCH 06/10] Also test with MyCall2 #33 --- Tests/NMEASentenceCollector/callSignTests.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/NMEASentenceCollector/callSignTests.cpp b/Tests/NMEASentenceCollector/callSignTests.cpp index ca2e9a5..38dc805 100644 --- a/Tests/NMEASentenceCollector/callSignTests.cpp +++ b/Tests/NMEASentenceCollector/callSignTests.cpp @@ -68,6 +68,7 @@ namespace NMEASentenceCollectorTests std::string data; m_collector->setMyCall1("N0CALL"); + m_collector->setMyCall2("5100"); m_collector->getData(data); EXPECT_TRUE(data.find("N0CALL-5") != std::string::npos) << "Callsign in APRS frame shall be N0CALL-5"; @@ -78,6 +79,7 @@ namespace NMEASentenceCollectorTests std::string data; m_collector->setMyCall1("N0CALL H"); + m_collector->setMyCall2("5100"); m_collector->getData(data); EXPECT_TRUE(data.find("N0CALL") != std::string::npos) << "Callsign in APRS frame shall be N0CALL-H"; From d82f1721c91ba33a476cdfbd2269a71b8467dd43 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 26 Apr 2023 06:47:40 +0200 Subject: [PATCH 07/10] Force to -5 #33 --- Common/NMEASentenceCollector.cpp | 6 +++--- Tests/NMEASentenceCollector/callSignTests.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Common/NMEASentenceCollector.cpp b/Common/NMEASentenceCollector.cpp index c69e9e5..4ad660c 100644 --- a/Common/NMEASentenceCollector.cpp +++ b/Common/NMEASentenceCollector.cpp @@ -110,12 +110,12 @@ bool CNMEASentenceCollector::getDataInt(std::string& data) // 20230425 Fix for https://github.com/F4FXL/DStarGateway/issues/33 size_t hyphenIndex = fromCall.find('-'); - if(hyphenIndex == std::string::npos) { - fromCall.append("-5"); + if(hyphenIndex != std::string::npos) { + fromCall = fromCall.substr(0, hyphenIndex); } std::string aprsFrame(fromCall); - aprsFrame.append(">GPS30,DSTAR*:") + aprsFrame.append("-5>GPS30,DSTAR*:") .append(nmea); data.assign(aprsFrame); diff --git a/Tests/NMEASentenceCollector/callSignTests.cpp b/Tests/NMEASentenceCollector/callSignTests.cpp index 38dc805..1cb6718 100644 --- a/Tests/NMEASentenceCollector/callSignTests.cpp +++ b/Tests/NMEASentenceCollector/callSignTests.cpp @@ -82,6 +82,6 @@ namespace NMEASentenceCollectorTests m_collector->setMyCall2("5100"); m_collector->getData(data); - EXPECT_TRUE(data.find("N0CALL") != std::string::npos) << "Callsign in APRS frame shall be N0CALL-H"; + EXPECT_TRUE(data.find("N0CALL-5") != std::string::npos) << "Callsign in APRS frame shall be N0CALL"; } } \ No newline at end of file From 1fae506faa0a72a8db6d311986bc3e9d9920694f Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 26 Apr 2023 06:48:57 +0200 Subject: [PATCH 08/10] Fix typpo in test #33 --- Tests/NMEASentenceCollector/callSignTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/NMEASentenceCollector/callSignTests.cpp b/Tests/NMEASentenceCollector/callSignTests.cpp index 1cb6718..868ca25 100644 --- a/Tests/NMEASentenceCollector/callSignTests.cpp +++ b/Tests/NMEASentenceCollector/callSignTests.cpp @@ -82,6 +82,6 @@ namespace NMEASentenceCollectorTests m_collector->setMyCall2("5100"); m_collector->getData(data); - EXPECT_TRUE(data.find("N0CALL-5") != std::string::npos) << "Callsign in APRS frame shall be N0CALL"; + EXPECT_TRUE(data.find("N0CALL-5") != std::string::npos) << "Callsign in APRS frame shall be N0CALL-5"; } } \ No newline at end of file From eaad5fe91abf1f0ade624192f1737450e151aed4 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 26 Apr 2023 20:08:04 +0200 Subject: [PATCH 09/10] Make test more generic #33 --- .../{callSignTests.cpp => getData.cpp} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename Tests/NMEASentenceCollector/{callSignTests.cpp => getData.cpp} (84%) diff --git a/Tests/NMEASentenceCollector/callSignTests.cpp b/Tests/NMEASentenceCollector/getData.cpp similarity index 84% rename from Tests/NMEASentenceCollector/callSignTests.cpp rename to Tests/NMEASentenceCollector/getData.cpp index 868ca25..1b6eb32 100644 --- a/Tests/NMEASentenceCollector/callSignTests.cpp +++ b/Tests/NMEASentenceCollector/getData.cpp @@ -22,7 +22,7 @@ namespace NMEASentenceCollectorTests { - class NMEASentenceCollectorTests_APRSFrame: public ::testing::Test + class NMEASentenceCollectorTests_getData: public ::testing::Test { protected: CNMEASentenceCollector * m_collector; @@ -63,7 +63,7 @@ namespace NMEASentenceCollectorTests } }; - TEST_F(NMEASentenceCollectorTests_APRSFrame, noSSIDinCallsign) + TEST_F(NMEASentenceCollectorTests_getData, noSSIDinCallsign) { std::string data; @@ -71,10 +71,10 @@ namespace NMEASentenceCollectorTests m_collector->setMyCall2("5100"); m_collector->getData(data); - EXPECT_TRUE(data.find("N0CALL-5") != std::string::npos) << "Callsign in APRS frame shall be N0CALL-5"; + EXPECT_STREQ(data.c_str(), "N0CALL-5>GPS30,DSTAR*:$GPRMC,092751.000,A,5321.6802,N,00630.3371,W,0.06,31.66,280511,,,A*45"); } - TEST_F(NMEASentenceCollectorTests_APRSFrame, SSIDinCallsign) + TEST_F(NMEASentenceCollectorTests_getData, SSIDinCallsign) { std::string data; @@ -82,6 +82,6 @@ namespace NMEASentenceCollectorTests m_collector->setMyCall2("5100"); m_collector->getData(data); - EXPECT_TRUE(data.find("N0CALL-5") != std::string::npos) << "Callsign in APRS frame shall be N0CALL-5"; + EXPECT_STREQ(data.c_str(), "N0CALL-5>GPS30,DSTAR*:$GPRMC,092751.000,A,5321.6802,N,00630.3371,W,0.06,31.66,280511,,,A*45"); } } \ No newline at end of file From 7b3123d91dacfc98a51828421a24b2442ae64085 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Wed, 26 Apr 2023 20:09:37 +0200 Subject: [PATCH 10/10] Update readme #33 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b709a3a..2a95cc1 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ The testing framwework used is Google Test. # 5. Version History ## 5.1. Version 0.7 +- [**Bugfix**] Malformed callsign in some cases when using DV-G (NMEA) ([#33](https://github.com/F4FXL/DStarGateway/issues/33)) - [**Bugfix**] Crash on startup with Icom Hardware. Thanks to Josh AB9FT for reporting the issue.([#31](https://github.com/F4FXL/DStarGateway/issues/31)) - [**Improvement**] Add/Fix DPRS Object support([#28](https://github.com/F4FXL/DStarGateway/issues/28)) - [**Improvement**] Log incoming DPRS frames so they can be used in e.g. dashboards([#29](https://github.com/F4FXL/DStarGateway/issues/29))