Skip to content

Commit

Permalink
#23 add possibility to override dprs
Browse files Browse the repository at this point in the history
  • Loading branch information
F4FXL committed Mar 25, 2022
1 parent b3522c5 commit c10c715
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
7 changes: 4 additions & 3 deletions DGWVoiceTransmit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
43 changes: 30 additions & 13 deletions DGWVoiceTransmit/VoiceTransmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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] <repeater> <file1> <file2> ..., exiting\n");
return 1;
}
Expand All @@ -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();
Expand All @@ -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<std::string>& files, std::string& text)
bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector<std::string>& files, std::string& text, std::string& dprs)
{
if(argc < 3)
return false;
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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::milliseconds>(std::chrono::high_resolution_clock::now() - start).count();
needed /= DSTAR_FRAME_TIME_MS;

Expand All @@ -153,7 +168,8 @@ bool CVoiceTransmit::run()

m_socket.close();

return true;
loop = false;
break;
}

if(slowData != nullptr) { // Override slowdata if specified so
Expand All @@ -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);
}
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions DGWVoiceTransmit/VoiceTransmit.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#include "HeaderData.h"
#include "AMBEData.h"

bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector<std::string>& vector, std::string& text);
bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector<std::string>& 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();
Expand All @@ -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);
Expand Down

0 comments on commit c10c715

Please sign in to comment.