|
|
|
@ -24,6 +24,8 @@
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <chrono>
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
#include <future>
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
|
|
#include "TimeServerThread.h"
|
|
|
|
#include "TimeServerThread.h"
|
|
|
|
#include "DStarDefines.h"
|
|
|
|
#include "DStarDefines.h"
|
|
|
|
@ -39,10 +41,7 @@ const unsigned int SILENCE_LENGTH = 10U;
|
|
|
|
CTimeServerThread::CTimeServerThread() :
|
|
|
|
CTimeServerThread::CTimeServerThread() :
|
|
|
|
CThread("Time Server"),
|
|
|
|
CThread("Time Server"),
|
|
|
|
m_callsign(),
|
|
|
|
m_callsign(),
|
|
|
|
m_callsignA(),
|
|
|
|
m_repeaters(),
|
|
|
|
m_callsignB(),
|
|
|
|
|
|
|
|
m_callsignC(),
|
|
|
|
|
|
|
|
m_callsignD(),
|
|
|
|
|
|
|
|
m_callsignG(),
|
|
|
|
m_callsignG(),
|
|
|
|
m_address(),
|
|
|
|
m_address(),
|
|
|
|
m_addressStr(),
|
|
|
|
m_addressStr(),
|
|
|
|
@ -80,7 +79,7 @@ CTimeServerThread::~CTimeServerThread()
|
|
|
|
void * CTimeServerThread::Entry()
|
|
|
|
void * CTimeServerThread::Entry()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Wait here until we have the essentials to run
|
|
|
|
// Wait here until we have the essentials to run
|
|
|
|
while (!m_killed && m_address.s_addr == INADDR_NONE && m_callsignA.empty() && m_callsignB.empty() && m_callsignC.empty() && m_callsignD.empty())
|
|
|
|
while (!m_killed && m_address.s_addr == INADDR_NONE && m_repeaters.size() == 0U)
|
|
|
|
Sleep(500UL); // 1/2 sec
|
|
|
|
Sleep(500UL); // 1/2 sec
|
|
|
|
|
|
|
|
|
|
|
|
if (m_killed)
|
|
|
|
if (m_killed)
|
|
|
|
@ -143,19 +142,19 @@ bool CTimeServerThread::setGateway(const std::string& callsign, const std::strin
|
|
|
|
m_callsignG.push_back('G');
|
|
|
|
m_callsignG.push_back('G');
|
|
|
|
|
|
|
|
|
|
|
|
if (!rpt1.empty()) {
|
|
|
|
if (!rpt1.empty()) {
|
|
|
|
m_callsignA = m_callsign + rpt1;
|
|
|
|
m_repeaters.push_back(m_callsign + rpt1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!rpt2.empty()) {
|
|
|
|
if (!rpt2.empty()) {
|
|
|
|
m_callsignB = m_callsign + rpt2;
|
|
|
|
m_repeaters.push_back(m_callsign + rpt2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!rpt3.empty()) {
|
|
|
|
if (!rpt3.empty()) {
|
|
|
|
m_callsignC = m_callsign + rpt3;
|
|
|
|
m_repeaters.push_back(m_callsign + rpt3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!rpt4.empty()) {
|
|
|
|
if (!rpt4.empty()) {
|
|
|
|
m_callsignD = m_callsign + rpt4;
|
|
|
|
m_repeaters.push_back(m_callsign + rpt4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_callsign.push_back(' ');
|
|
|
|
m_callsign.push_back(' ');
|
|
|
|
@ -1182,11 +1181,6 @@ void CTimeServerThread::end()
|
|
|
|
|
|
|
|
|
|
|
|
bool CTimeServerThread::send(const std::vector<std::string> &words, unsigned int hour, unsigned int min)
|
|
|
|
bool CTimeServerThread::send(const std::vector<std::string> &words, unsigned int hour, unsigned int min)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned int idA = CHeaderData::createId();
|
|
|
|
|
|
|
|
unsigned int idB = CHeaderData::createId();
|
|
|
|
|
|
|
|
unsigned int idC = CHeaderData::createId();
|
|
|
|
|
|
|
|
unsigned int idD = CHeaderData::createId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CHeaderData header;
|
|
|
|
CHeaderData header;
|
|
|
|
header.setMyCall1(m_callsign);
|
|
|
|
header.setMyCall1(m_callsign);
|
|
|
|
header.setRptCall1(m_callsignG);
|
|
|
|
header.setRptCall1(m_callsignG);
|
|
|
|
@ -1321,43 +1315,47 @@ bool CTimeServerThread::send(const std::vector<std::string> &words, unsigned int
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CUDPReaderWriter * socketA = nullptr;
|
|
|
|
bool res = true;
|
|
|
|
CUDPReaderWriter * socketB = nullptr;
|
|
|
|
for(auto rpt : m_repeaters) {
|
|
|
|
CUDPReaderWriter * socketC = nullptr;
|
|
|
|
res = sendToRepeater(header, rpt) && res;
|
|
|
|
CUDPReaderWriter * socketD = nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_callsignA.empty()) {
|
|
|
|
|
|
|
|
socketA = new CUDPReaderWriter("", 0U);
|
|
|
|
|
|
|
|
socketA->open();
|
|
|
|
|
|
|
|
header.setRptCall2(m_callsignA);
|
|
|
|
|
|
|
|
header.setId(idA);
|
|
|
|
|
|
|
|
sendHeader(*socketA, header);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_callsignB.empty()) {
|
|
|
|
// std::vector<std::packaged_task<bool()> *> tasks;
|
|
|
|
socketB = new CUDPReaderWriter("", 0U);
|
|
|
|
|
|
|
|
socketB->open();
|
|
|
|
|
|
|
|
header.setRptCall2(m_callsignB);
|
|
|
|
|
|
|
|
header.setId(idB);
|
|
|
|
|
|
|
|
sendHeader(*socketB, header);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_callsignC.empty()) {
|
|
|
|
// for(auto rpt : m_repeaters) {
|
|
|
|
socketC = new CUDPReaderWriter("", 0U);
|
|
|
|
// std::packaged_task<bool()> * task = new std::packaged_task<bool()>([header, rpt, this] { return sendToRepeater(header, rpt);} );
|
|
|
|
socketC->open();
|
|
|
|
// std::thread t(std::move(*task));
|
|
|
|
header.setRptCall2(m_callsignC);
|
|
|
|
// }
|
|
|
|
header.setId(idC);
|
|
|
|
|
|
|
|
sendHeader(*socketC, header);
|
|
|
|
// bool res = true;
|
|
|
|
}
|
|
|
|
// for(auto task : tasks) {
|
|
|
|
|
|
|
|
// auto future = task->get_future();
|
|
|
|
|
|
|
|
// future.wait();
|
|
|
|
|
|
|
|
// res = future.get() && res;
|
|
|
|
|
|
|
|
// delete task;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_callsignD.empty()) {
|
|
|
|
for(unsigned int i = 0U; i < MAX_FRAMES; i++) {
|
|
|
|
socketD = new CUDPReaderWriter("", 0U);
|
|
|
|
delete m_data[i];
|
|
|
|
socketD->open();
|
|
|
|
m_data[i] = nullptr;
|
|
|
|
header.setRptCall2(m_callsignD);
|
|
|
|
|
|
|
|
header.setId(idD);
|
|
|
|
|
|
|
|
sendHeader(*socketD, header);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CTimeServerThread::sendToRepeater(const CHeaderData& h, const std::string& rptCall2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CUDPReaderWriter socket("", 0U);
|
|
|
|
|
|
|
|
if(!socket.open())
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto id = CHeaderData::createId();
|
|
|
|
|
|
|
|
CHeaderData header(h);
|
|
|
|
|
|
|
|
header.setId(id);
|
|
|
|
|
|
|
|
header.setRptCall2(rptCall2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sendHeader(socket, header);
|
|
|
|
|
|
|
|
|
|
|
|
bool loop = true;
|
|
|
|
bool loop = true;
|
|
|
|
unsigned int out = 0U;
|
|
|
|
unsigned int out = 0U;
|
|
|
|
auto start = std::chrono::high_resolution_clock::now();
|
|
|
|
auto start = std::chrono::high_resolution_clock::now();
|
|
|
|
@ -1367,31 +1365,10 @@ bool CTimeServerThread::send(const std::vector<std::string> &words, unsigned int
|
|
|
|
needed /= DSTAR_FRAME_TIME_MS;
|
|
|
|
needed /= DSTAR_FRAME_TIME_MS;
|
|
|
|
|
|
|
|
|
|
|
|
while (out < needed) {
|
|
|
|
while (out < needed) {
|
|
|
|
CAMBEData* data = m_data[out];
|
|
|
|
CAMBEData data(*(m_data[out]));
|
|
|
|
m_data[out] = NULL;
|
|
|
|
|
|
|
|
out++;
|
|
|
|
out++;
|
|
|
|
|
|
|
|
data.setId(id);
|
|
|
|
if (!m_callsignA.empty()) {
|
|
|
|
sendData(socket, data);
|
|
|
|
data->setId(idA);
|
|
|
|
|
|
|
|
sendData(*socketA, *data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_callsignB.empty()) {
|
|
|
|
|
|
|
|
data->setId(idB);
|
|
|
|
|
|
|
|
sendData(*socketB, *data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_callsignC.empty()) {
|
|
|
|
|
|
|
|
data->setId(idC);
|
|
|
|
|
|
|
|
sendData(*socketC, *data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_callsignD.empty()) {
|
|
|
|
|
|
|
|
data->setId(idD);
|
|
|
|
|
|
|
|
sendData(*socketD, *data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete data;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_in == out) {
|
|
|
|
if (m_in == out) {
|
|
|
|
loop = false;
|
|
|
|
loop = false;
|
|
|
|
@ -1402,22 +1379,7 @@ bool CTimeServerThread::send(const std::vector<std::string> &words, unsigned int
|
|
|
|
Sleep(10UL);
|
|
|
|
Sleep(10UL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(socketA != nullptr) {
|
|
|
|
socket.close();
|
|
|
|
socketA->close();
|
|
|
|
|
|
|
|
delete socketA;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(socketB != nullptr) {
|
|
|
|
|
|
|
|
socketB->close();
|
|
|
|
|
|
|
|
delete socketB;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(socketC != nullptr) {
|
|
|
|
|
|
|
|
socketC->close();
|
|
|
|
|
|
|
|
delete socketC;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(socketD != nullptr) {
|
|
|
|
|
|
|
|
socketD->close();
|
|
|
|
|
|
|
|
delete socketD;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|