#23 add possibility to override text

pull/32/head
Geoffrey Merck 4 years ago
parent a1cca3fbea
commit c2a940bee7

@ -109,7 +109,7 @@
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/DGWVoiceTransmit/dgwvoicetransmit", "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, "stopAtEntry": false,
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"environment": [], "environment": [],

10
.vscode/tasks.json vendored

@ -78,7 +78,10 @@
"USE_GPSD=1", "USE_GPSD=1",
"DGWVoiceTransmit/dgwvoicetransmit" "DGWVoiceTransmit/dgwvoicetransmit"
], ],
"group": "build", "group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [] "problemMatcher": []
}, },
{ {
@ -91,10 +94,7 @@
"ENABLE_DEBUG=1", "ENABLE_DEBUG=1",
"USE_GPSD=1" "USE_GPSD=1"
], ],
"group": { "group": "build",
"kind": "build",
"isDefault": true
},
"problemMatcher": [] "problemMatcher": []
} }
] ]

@ -22,16 +22,18 @@
#include <thread> #include <thread>
#include <chrono> #include <chrono>
#include "ProgramArgs.h"
#include "DStarDefines.h" #include "DStarDefines.h"
#include "VoiceTransmit.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<std::string> filenames; std::vector<std::string> filenames;
if (!parseCLIArgs(argc, argv, repeater, filenames)) { if (!parseCLIArgs(argc, argv, repeater, filenames, text)) {
::fprintf(stderr, "dgwvoicetransmit: invalid command line usage: dgwvoicetransmit <repeater> <file1> <file2> ..., exiting\n"); ::fprintf(stderr, "dgwvoicetransmit: invalid command line usage: dgwvoicetransmit [-text text] <repeater> <file1> <file2> ..., exiting\n");
return 1; return 1;
} }
@ -44,7 +46,7 @@ int main(int argc, char** argv)
return 1; return 1;
} }
CVoiceTransmit tt(repeater, &store); CVoiceTransmit tt(repeater, &store, text);
bool ret = tt.run(); bool ret = tt.run();
store.close(); store.close();
@ -53,30 +55,36 @@ int main(int argc, char** argv)
return ret ? 0 : 1; return ret ? 0 : 1;
} }
bool parseCLIArgs(int argc, char * argv[], std::string& repeater, std::vector<std::string>& files) bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector<std::string>& files, std::string& text)
{ {
if(argc < 3) if(argc < 3)
return false; return false;
repeater.assign(argv[1]); std::unordered_map<std::string, std::string> namedArgs;
boost::to_upper(repeater); std::vector<std::string> positionalArgs;
boost::replace_all(repeater, "_", " ");
repeater.resize(LONG_CALLSIGN_LENGTH, ' ');
files.clear(); CProgramArgs::eatArguments(argc, argv, namedArgs, positionalArgs);
for(int i = 2; i < argc; i++) { if(positionalArgs.size() < 2U)
if(argv[i] != nullptr) { return false;
files.push_back(std::string(argv[i]));
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_socket("", 0U),
m_callsign(callsign), m_callsign(callsign),
m_text(text),
m_store(store) m_store(store)
{ {
assert(store != NULL); assert(store != NULL);
@ -88,6 +96,7 @@ CVoiceTransmit::~CVoiceTransmit()
bool CVoiceTransmit::run() bool CVoiceTransmit::run()
{ {
CSlowDataEncoder * slowData = nullptr;
bool opened = m_socket.open(); bool opened = m_socket.open();
if (!opened) if (!opened)
return false; return false;
@ -110,6 +119,12 @@ bool CVoiceTransmit::run()
header->setRptCall2(m_callsign); header->setRptCall2(m_callsign);
header->setDestination(address, G2_DV_PORT); header->setDestination(address, G2_DV_PORT);
if(!m_text.empty()) {
slowData = new CSlowDataEncoder();
slowData->setHeaderData(*header);
slowData->setTextData(m_text);
}
sendHeader(header); sendHeader(header);
delete header; delete header;
@ -127,10 +142,6 @@ bool CVoiceTransmit::run()
CAMBEData* ambe = m_store->getAMBE(); CAMBEData* ambe = m_store->getAMBE();
if (ambe == NULL) { if (ambe == NULL) {
seqNo++;
if (seqNo >= 21U)
seqNo = 0U;
CAMBEData data; CAMBEData data;
data.setData(END_PATTERN_BYTES, DV_FRAME_LENGTH_BYTES); data.setData(END_PATTERN_BYTES, DV_FRAME_LENGTH_BYTES);
data.setDestination(address, G2_DV_PORT); data.setDestination(address, G2_DV_PORT);
@ -145,8 +156,22 @@ bool CVoiceTransmit::run()
return true; 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->setDestination(address, G2_DV_PORT);
ambe->setEnd(false); ambe->setEnd(false);
ambe->setId(id); ambe->setId(id);
@ -156,6 +181,9 @@ bool CVoiceTransmit::run()
delete ambe; delete ambe;
out++; out++;
seqNo++;
if(seqNo >= 21U) seqNo = 0U;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(10U)); std::this_thread::sleep_for(std::chrono::milliseconds(10U));

@ -28,11 +28,11 @@
#include "HeaderData.h" #include "HeaderData.h"
#include "AMBEData.h" #include "AMBEData.h"
bool parseCLIArgs(int argc, char * argv[], std::string& repeater, std::vector<std::string>& vector); bool parseCLIArgs(int argc, const char * argv[], std::string& repeater, std::vector<std::string>& vector, std::string& text);
class CVoiceTransmit { class CVoiceTransmit {
public: public:
CVoiceTransmit(const std::string& callsign, CVoiceStore* store); CVoiceTransmit(const std::string& callsign, CVoiceStore* store, const std::string& text);
~CVoiceTransmit(); ~CVoiceTransmit();
bool run(); bool run();
@ -40,6 +40,7 @@ public:
private: private:
CUDPReaderWriter m_socket; CUDPReaderWriter m_socket;
std::string m_callsign; std::string m_callsign;
std::string m_text;
CVoiceStore* m_store; CVoiceStore* m_store;
bool sendHeader(CHeaderData* header); bool sendHeader(CHeaderData* header);

Loading…
Cancel
Save

Powered by TurnKey Linux.