From c2a940bee7af88b36a7f0b1985cf7f52815371e0 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Thu, 24 Mar 2022 18:57:12 +0100 Subject: [PATCH 1/4] #23 add possibility to override text --- .vscode/launch.json | 2 +- .vscode/tasks.json | 10 ++--- DGWVoiceTransmit/VoiceTransmit.cpp | 72 +++++++++++++++++++++--------- DGWVoiceTransmit/VoiceTransmit.h | 5 ++- 4 files changed, 59 insertions(+), 30 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 55284ba..94b71b0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -109,7 +109,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/DGWVoiceTransmit/dgwvoicetransmit", - "args": ["F4FXL B", "${workspaceFolder}/Sandbox/Announce_F5ZEE__B.dvtool"], + "args": ["F4FXL B", "${workspaceFolder}/Sandbox/Announce_F5ZEE__B.dvtool", "-text", "www.F5KAV.fr"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 995a9f1..df6906d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -78,7 +78,10 @@ "USE_GPSD=1", "DGWVoiceTransmit/dgwvoicetransmit" ], - "group": "build", + "group": { + "kind": "build", + "isDefault": true + }, "problemMatcher": [] }, { @@ -91,10 +94,7 @@ "ENABLE_DEBUG=1", "USE_GPSD=1" ], - "group": { - "kind": "build", - "isDefault": true - }, + "group": "build", "problemMatcher": [] } ] diff --git a/DGWVoiceTransmit/VoiceTransmit.cpp b/DGWVoiceTransmit/VoiceTransmit.cpp index d173241..67b76ca 100644 --- a/DGWVoiceTransmit/VoiceTransmit.cpp +++ b/DGWVoiceTransmit/VoiceTransmit.cpp @@ -22,16 +22,18 @@ #include #include +#include "ProgramArgs.h" #include "DStarDefines.h" #include "VoiceTransmit.h" +#include "SlowDataEncoder.h" -int main(int argc, char** argv) +int main(int argc, const char * argv[]) { - std::string repeater; + std::string repeater, text; std::vector filenames; - if (!parseCLIArgs(argc, argv, repeater, filenames)) { - ::fprintf(stderr, "dgwvoicetransmit: invalid command line usage: dgwvoicetransmit ..., exiting\n"); + if (!parseCLIArgs(argc, argv, repeater, filenames, text)) { + ::fprintf(stderr, "dgwvoicetransmit: invalid command line usage: dgwvoicetransmit [-text text] ..., exiting\n"); return 1; } @@ -44,7 +46,7 @@ int main(int argc, char** argv) return 1; } - CVoiceTransmit tt(repeater, &store); + CVoiceTransmit tt(repeater, &store, text); bool ret = tt.run(); store.close(); @@ -53,30 +55,36 @@ int main(int argc, char** argv) return ret ? 0 : 1; } -bool parseCLIArgs(int argc, char * argv[], std::string& repeater, std::vector& files) +bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector& files, std::string& text) { if(argc < 3) return false; - repeater.assign(argv[1]); - boost::to_upper(repeater); - boost::replace_all(repeater, "_", " "); - repeater.resize(LONG_CALLSIGN_LENGTH, ' '); + std::unordered_map namedArgs; + std::vector positionalArgs; - files.clear(); + CProgramArgs::eatArguments(argc, argv, namedArgs, positionalArgs); - for(int i = 2; i < argc; i++) { - if(argv[i] != nullptr) { - files.push_back(std::string(argv[i])); - } + if(positionalArgs.size() < 2U) + return false; + + repeater.assign(positionalArgs[0]); + files.assign(positionalArgs.begin() + 1, positionalArgs.end()); + + if(namedArgs.count("text") > 0U) { + text.assign(namedArgs["text"]); + } + else { + text.assign(""); } - return files.size() > 0U; + return true; } -CVoiceTransmit::CVoiceTransmit(const std::string& callsign, CVoiceStore* store) : +CVoiceTransmit::CVoiceTransmit(const std::string& callsign, CVoiceStore* store, const std::string& text) : m_socket("", 0U), m_callsign(callsign), +m_text(text), m_store(store) { assert(store != NULL); @@ -88,6 +96,7 @@ CVoiceTransmit::~CVoiceTransmit() bool CVoiceTransmit::run() { + CSlowDataEncoder * slowData = nullptr; bool opened = m_socket.open(); if (!opened) return false; @@ -110,6 +119,12 @@ bool CVoiceTransmit::run() header->setRptCall2(m_callsign); header->setDestination(address, G2_DV_PORT); + if(!m_text.empty()) { + slowData = new CSlowDataEncoder(); + slowData->setHeaderData(*header); + slowData->setTextData(m_text); + } + sendHeader(header); delete header; @@ -127,10 +142,6 @@ bool CVoiceTransmit::run() CAMBEData* ambe = m_store->getAMBE(); if (ambe == NULL) { - seqNo++; - if (seqNo >= 21U) - seqNo = 0U; - CAMBEData data; data.setData(END_PATTERN_BYTES, DV_FRAME_LENGTH_BYTES); data.setDestination(address, G2_DV_PORT); @@ -145,8 +156,22 @@ bool CVoiceTransmit::run() return true; } - seqNo = ambe->getSeq(); + if(slowData != nullptr) { // Override slowdata if specified so + unsigned char buffer[DV_FRAME_LENGTH_BYTES]; + ambe->getData(buffer, DV_FRAME_LENGTH_BYTES); + + // Insert sync bytes when the sequence number is zero, slow data otherwise + if (seqNo == 0U) { + ::memcpy(buffer + VOICE_FRAME_LENGTH_BYTES, DATA_SYNC_BYTES, DATA_FRAME_LENGTH_BYTES); + slowData->sync(); + } else { + slowData->getInterleavedData(buffer + VOICE_FRAME_LENGTH_BYTES); + } + ambe->setData(buffer, DV_FRAME_LENGTH_BYTES); + } + + ambe->setSeq(seqNo); ambe->setDestination(address, G2_DV_PORT); ambe->setEnd(false); ambe->setId(id); @@ -156,6 +181,9 @@ bool CVoiceTransmit::run() delete ambe; out++; + + seqNo++; + if(seqNo >= 21U) seqNo = 0U; } std::this_thread::sleep_for(std::chrono::milliseconds(10U)); diff --git a/DGWVoiceTransmit/VoiceTransmit.h b/DGWVoiceTransmit/VoiceTransmit.h index 3a72384..2bc0fb8 100644 --- a/DGWVoiceTransmit/VoiceTransmit.h +++ b/DGWVoiceTransmit/VoiceTransmit.h @@ -28,11 +28,11 @@ #include "HeaderData.h" #include "AMBEData.h" -bool parseCLIArgs(int argc, char * argv[], std::string& repeater, std::vector& vector); +bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector& vector, std::string& text); class CVoiceTransmit { public: - CVoiceTransmit(const std::string& callsign, CVoiceStore* store); + CVoiceTransmit(const std::string& callsign, CVoiceStore* store, const std::string& text); ~CVoiceTransmit(); bool run(); @@ -40,6 +40,7 @@ class CVoiceTransmit { private: CUDPReaderWriter m_socket; std::string m_callsign; + std::string m_text; CVoiceStore* m_store; bool sendHeader(CHeaderData* header); From b3522c5750c4d204e655e983eca3d38f1a750e2e Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Thu, 24 Mar 2022 20:31:45 +0100 Subject: [PATCH 2/4] #23 detect CRC header in calc CRC, add test --- .vscode/launch.json | 2 +- APRS/APRSUtils.cpp | 6 ++++- Tests/APRSUtils/calcGPSAIcomCRC.cpp | 41 +++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 Tests/APRSUtils/calcGPSAIcomCRC.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json index 94b71b0..d6dd4ae 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -109,7 +109,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/DGWVoiceTransmit/dgwvoicetransmit", - "args": ["F4FXL B", "${workspaceFolder}/Sandbox/Announce_F5ZEE__B.dvtool", "-text", "www.F5KAV.fr"], + "args": ["F4FXL B", "${workspaceFolder}/Sandbox/Announce_F5ZEE__B.dvtool", "-text", "www.F5KAV.fr", "-dprs", "!4858.72ND00736.91E&RNG0037/A=000098 440 Voice 439.80000MHz -9.4000MHz"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], diff --git a/APRS/APRSUtils.cpp b/APRS/APRSUtils.cpp index 2309344..5684088 100644 --- a/APRS/APRSUtils.cpp +++ b/APRS/APRSUtils.cpp @@ -37,8 +37,12 @@ unsigned int CAPRSUtils::calcGPSAIcomCRC(const std::string& gpsa) { unsigned int icomcrc = 0xFFFFU; + unsigned int dataBegin = 0U; + if(boost::starts_with(gpsa, "$$CRC") && gpsa.length() >= 10 && gpsa[9] == ',') + dataBegin = 10U; + auto length = gpsa.length(); - for (unsigned int j = 10U; j < length; j++) { + for (unsigned int j = dataBegin; j < length; j++) { unsigned char ch = (unsigned char)gpsa[j]; for (unsigned int i = 0U; i < 8U; i++) { diff --git a/Tests/APRSUtils/calcGPSAIcomCRC.cpp b/Tests/APRSUtils/calcGPSAIcomCRC.cpp new file mode 100644 index 0000000..9d5850c --- /dev/null +++ b/Tests/APRSUtils/calcGPSAIcomCRC.cpp @@ -0,0 +1,41 @@ +/* + * 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 APRStoDPRSTests +{ + class APRSUtils_calcGPSAIcomCRC : public ::testing::Test { + }; + + TEST_F(APRSUtils_calcGPSAIcomCRC, withCRCHeader) + { + auto crc = CAPRSUtils::calcGPSAIcomCRC("$$CRC6F5E,ABCDEF"); + + EXPECT_EQ(crc, 0x6f5e) << "CRC shall be valid"; + } + + TEST_F(APRSUtils_calcGPSAIcomCRC, withoutCRCHeader) + { + auto crc = CAPRSUtils::calcGPSAIcomCRC("ABCDEF"); + + EXPECT_EQ(crc, 0x6f5e) << "CRC shall be valid"; + } +} \ No newline at end of file From c10c7151d4d79034c763989f1f1acf0cfeec363e Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Fri, 25 Mar 2022 16:28:59 +0100 Subject: [PATCH 3/4] #23 add possibility to override dprs --- .vscode/launch.json | 2 +- DGWVoiceTransmit/Makefile | 7 ++--- DGWVoiceTransmit/VoiceTransmit.cpp | 43 +++++++++++++++++++++--------- DGWVoiceTransmit/VoiceTransmit.h | 7 ++--- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d6dd4ae..ae32c96 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -109,7 +109,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/DGWVoiceTransmit/dgwvoicetransmit", - "args": ["F4FXL B", "${workspaceFolder}/Sandbox/Announce_F5ZEE__B.dvtool", "-text", "www.F5KAV.fr", "-dprs", "!4858.72ND00736.91E&RNG0037/A=000098 440 Voice 439.80000MHz -9.4000MHz"], + "args": ["F4FXL B", "${workspaceFolder}/Sandbox/Announce_F5ZEE__B.dvtool", "-text", "www.F5KAV.fr", "-dprs", "!4858.72N/00736.91Er/"], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], diff --git a/DGWVoiceTransmit/Makefile b/DGWVoiceTransmit/Makefile index 4579621..d214adb 100644 --- a/DGWVoiceTransmit/Makefile +++ b/DGWVoiceTransmit/Makefile @@ -2,11 +2,11 @@ SRCS = $(wildcard *.cpp) OBJS = $(SRCS:.cpp=.o) DEPS = $(SRCS:.cpp=.d) -dgwvoicetransmit: ../VersionInfo/GitVersion.h $(OBJS) ../DStarBase/DStarBase.a ../BaseCommon/BaseCommon.a - $(CC) $(CPPFLAGS) -o dgwvoicetransmit $(OBJS) ../DStarBase/DStarBase.a ../BaseCommon/BaseCommon.a $(LDFLAGS) +dgwvoicetransmit: ../VersionInfo/GitVersion.h $(OBJS) ../DStarBase/DStarBase.a ../APRS/APRS.a ../BaseCommon/BaseCommon.a + $(CC) $(CPPFLAGS) -o dgwvoicetransmit $(OBJS) ../DStarBase/DStarBase.a ../APRS/APRS.a ../BaseCommon/BaseCommon.a $(LDFLAGS) %.o : %.cpp - $(CC) -I../BaseCommon -I../DStarBase -I../VersionInfo -DCFG_DIR='"$(CFG_DIR)"' $(CPPFLAGS) -MMD -MD -c $< -o $@ + $(CC) -I../BaseCommon -I../APRS -I../DStarBase -I../VersionInfo -DCFG_DIR='"$(CFG_DIR)"' $(CPPFLAGS) -MMD -MD -c $< -o $@ .PHONY clean: clean: @@ -17,6 +17,7 @@ install: dgwvoicetransmit # copy executable @cp -f dgwvoicetransmit $(BIN_DIR) +../APRS/APRS.a: ../BaseCommon/BaseCommon.a: ../DStarBase/DStarBase.a: ../VersionInfo/GitVersion.h: diff --git a/DGWVoiceTransmit/VoiceTransmit.cpp b/DGWVoiceTransmit/VoiceTransmit.cpp index 67b76ca..655f5c7 100644 --- a/DGWVoiceTransmit/VoiceTransmit.cpp +++ b/DGWVoiceTransmit/VoiceTransmit.cpp @@ -26,13 +26,15 @@ #include "DStarDefines.h" #include "VoiceTransmit.h" #include "SlowDataEncoder.h" +#include "APRSUtils.h" +#include "StringUtils.h" int main(int argc, const char * argv[]) { - std::string repeater, text; + std::string repeater, text, dprs; std::vector filenames; - if (!parseCLIArgs(argc, argv, repeater, filenames, text)) { + if (!parseCLIArgs(argc, argv, repeater, filenames, text, dprs)) { ::fprintf(stderr, "dgwvoicetransmit: invalid command line usage: dgwvoicetransmit [-text text] ..., exiting\n"); return 1; } @@ -46,7 +48,7 @@ int main(int argc, const char * argv[]) return 1; } - CVoiceTransmit tt(repeater, &store, text); + CVoiceTransmit tt(repeater, &store, text, dprs); bool ret = tt.run(); store.close(); @@ -55,7 +57,7 @@ int main(int argc, const char * argv[]) return ret ? 0 : 1; } -bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector& files, std::string& text) +bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector& files, std::string& text, std::string& dprs) { if(argc < 3) return false; @@ -68,7 +70,7 @@ bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vec if(positionalArgs.size() < 2U) return false; - repeater.assign(positionalArgs[0]); + repeater.assign(boost::replace_all_copy(positionalArgs[0], "_", " ")); files.assign(positionalArgs.begin() + 1, positionalArgs.end()); if(namedArgs.count("text") > 0U) { @@ -78,13 +80,24 @@ bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vec text.assign(""); } + if(namedArgs.count("dprs") > 0U) { + std::string dprsRepeater(repeater); + CAPRSUtils::dstarCallsignToAPRS(dprsRepeater); + std::string dprsnoCrc = CStringUtils::string_format("%s>DPRS:%s\r", dprsRepeater.c_str(), namedArgs["dprs"].c_str()); + dprs = CStringUtils::string_format("$$CRC%04X,%s", CAPRSUtils::calcGPSAIcomCRC(dprsnoCrc), dprsnoCrc.c_str()); + } + else { + dprs.assign(""); + } + return true; } -CVoiceTransmit::CVoiceTransmit(const std::string& callsign, CVoiceStore* store, const std::string& text) : +CVoiceTransmit::CVoiceTransmit(const std::string& callsign, CVoiceStore* store, const std::string& text, const std::string& dprs) : m_socket("", 0U), m_callsign(callsign), m_text(text), +m_dprs(dprs), m_store(store) { assert(store != NULL); @@ -121,8 +134,9 @@ bool CVoiceTransmit::run() if(!m_text.empty()) { slowData = new CSlowDataEncoder(); - slowData->setHeaderData(*header); - slowData->setTextData(m_text); + // slowData->setHeaderData(*header); + if(!m_text.empty()) slowData->setTextData(m_text); + if(!m_dprs.empty()) slowData->setGPSData(m_dprs); } sendHeader(header); @@ -133,8 +147,9 @@ bool CVoiceTransmit::run() unsigned int out = 0U; unsigned int seqNo = 0U; + bool loop = true; - for (;;) { + while (loop) { unsigned int needed = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start).count(); needed /= DSTAR_FRAME_TIME_MS; @@ -153,7 +168,8 @@ bool CVoiceTransmit::run() m_socket.close(); - return true; + loop = false; + break; } if(slowData != nullptr) { // Override slowdata if specified so @@ -163,7 +179,6 @@ bool CVoiceTransmit::run() // Insert sync bytes when the sequence number is zero, slow data otherwise if (seqNo == 0U) { ::memcpy(buffer + VOICE_FRAME_LENGTH_BYTES, DATA_SYNC_BYTES, DATA_FRAME_LENGTH_BYTES); - slowData->sync(); } else { slowData->getInterleavedData(buffer + VOICE_FRAME_LENGTH_BYTES); } @@ -177,17 +192,19 @@ bool CVoiceTransmit::run() ambe->setId(id); sendData(ambe); - delete ambe; out++; - seqNo++; if(seqNo >= 21U) seqNo = 0U; } std::this_thread::sleep_for(std::chrono::milliseconds(10U)); } + + if(slowData != nullptr) delete slowData; + + return true; } bool CVoiceTransmit::sendHeader(CHeaderData* header) diff --git a/DGWVoiceTransmit/VoiceTransmit.h b/DGWVoiceTransmit/VoiceTransmit.h index 2bc0fb8..38838cc 100644 --- a/DGWVoiceTransmit/VoiceTransmit.h +++ b/DGWVoiceTransmit/VoiceTransmit.h @@ -28,11 +28,11 @@ #include "HeaderData.h" #include "AMBEData.h" -bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector& vector, std::string& text); +bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector& vector, std::string& text, std::string& dprs); class CVoiceTransmit { public: - CVoiceTransmit(const std::string& callsign, CVoiceStore* store, const std::string& text); + CVoiceTransmit(const std::string& callsign, CVoiceStore* store, const std::string& text, const std::string& dprs); ~CVoiceTransmit(); bool run(); @@ -41,7 +41,8 @@ class CVoiceTransmit { CUDPReaderWriter m_socket; std::string m_callsign; std::string m_text; - CVoiceStore* m_store; + std::string m_dprs; + CVoiceStore* m_store; bool sendHeader(CHeaderData* header); bool sendData(CAMBEData* data); From 4715ca404179cb1cd92f6a3f734eeb3d83320d5f Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Fri, 25 Mar 2022 16:49:58 +0100 Subject: [PATCH 4/4] #25 make callsing upper --- DGWVoiceTransmit/VoiceTransmit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DGWVoiceTransmit/VoiceTransmit.cpp b/DGWVoiceTransmit/VoiceTransmit.cpp index 655f5c7..9403756 100644 --- a/DGWVoiceTransmit/VoiceTransmit.cpp +++ b/DGWVoiceTransmit/VoiceTransmit.cpp @@ -70,7 +70,7 @@ bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vec if(positionalArgs.size() < 2U) return false; - repeater.assign(boost::replace_all_copy(positionalArgs[0], "_", " ")); + repeater.assign(boost::replace_all_copy(boost::to_upper_copy(positionalArgs[0]), "_", " ")); files.assign(positionalArgs.begin() + 1, positionalArgs.end()); if(namedArgs.count("text") > 0U) {