From c92434e474dbaa594e71d312617f6eef7aca906b Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 25 Jan 2016 23:08:34 +0000 Subject: [PATCH] Move the D-Star poll message to be run from the network class. --- DMRSlot.cpp | 7 ++----- DStarNetwork.cpp | 33 +++++++++++++++++++++++++-------- DStarNetwork.h | 8 ++++++-- MMDVMHost.cpp | 8 +------- Makefile | 2 +- Version.h | 2 +- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 4c9bb4c..ca32fb5 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -171,7 +171,8 @@ void CDMRSlot::writeModem(unsigned char *data) data[0U] = TAG_EOT; data[1U] = 0x00U; - writeNetwork(data, DT_TERMINATOR_WITH_LC); + for (unsigned int i = 0U; i < 2U; i++) + writeNetwork(data, DT_TERMINATOR_WITH_LC); // 480ms of terminator to space things out for (unsigned int i = 0U; i < 8U; i++) @@ -443,10 +444,6 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) m_bits = 1U; m_errs = 0U; - // 120ms of idle to give breathing space for lost frames - for (unsigned int i = 0U; i < 2U; i++) - writeQueue(m_idle); - for (unsigned int i = 0U; i < 3U; i++) writeQueue(data); diff --git a/DStarNetwork.cpp b/DStarNetwork.cpp index 2994797..a3db914 100644 --- a/DStarNetwork.cpp +++ b/DStarNetwork.cpp @@ -25,24 +25,29 @@ #include #include +#include const unsigned int BUFFER_LENGTH = 100U; -CDStarNetwork::CDStarNetwork(const std::string& gatewayAddress, unsigned int gatewayPort, unsigned int localPort, bool debug) : +CDStarNetwork::CDStarNetwork(const std::string& gatewayAddress, unsigned int gatewayPort, unsigned int localPort, const std::string& version, bool debug) : m_socket(localPort), m_address(), m_port(gatewayPort), +m_version(version), m_debug(debug), m_enabled(false), m_outId(0U), m_outSeq(0U), m_inId(0U), -m_buffer(1000U) +m_buffer(1000U), +m_pollTimer(1000U, 60U) { m_address = CUDPSocket::lookup(gatewayAddress); CStopWatch stopWatch; ::srand(stopWatch.start()); + + m_pollTimer.start(); } CDStarNetwork::~CDStarNetwork() @@ -134,8 +139,10 @@ bool CDStarNetwork::writeData(const unsigned char* data, unsigned int length, un return m_socket.write(buffer, length + 9U, m_address, m_port); } -bool CDStarNetwork::writePoll(const std::string& text) +bool CDStarNetwork::writePoll(const char* text) { + assert(text != NULL); + unsigned char buffer[40U]; buffer[0] = 'D'; @@ -145,12 +152,10 @@ bool CDStarNetwork::writePoll(const std::string& text) buffer[4] = 0x0A; // Poll with text - unsigned int length = text.length(); + unsigned int length = ::strlen(text); - for (unsigned int i = 0U; i < length; i++) - buffer[5U + i] = text.at(i); - - buffer[5U + length] = 0x00; + // Include the nul at the end also + ::memcpy(buffer + 5U, text, length + 1U); if (m_debug) CUtils::dump(1U, "D-Star Transmitted", buffer, 6U + length); @@ -160,6 +165,18 @@ bool CDStarNetwork::writePoll(const std::string& text) void CDStarNetwork::clock(unsigned int ms) { + m_pollTimer.clock(ms); + if (m_pollTimer.hasExpired()) { + char text[60U]; +#if defined(_WIN32) || defined(_WIN64) + ::sprintf(text, "win_mmdvm-%s", m_version.c_str()); +#else + ::sprintf(text, "linux_mmdvm-%s", m_version.c_str()); +#endif + writePoll(text); + m_pollTimer.start(); + } + unsigned char buffer[BUFFER_LENGTH]; in_addr address; diff --git a/DStarNetwork.h b/DStarNetwork.h index 1fa3d75..288715f 100644 --- a/DStarNetwork.h +++ b/DStarNetwork.h @@ -22,13 +22,14 @@ #include "DStarDefines.h" #include "RingBuffer.h" #include "UDPSocket.h" +#include "Timer.h" #include #include class CDStarNetwork { public: - CDStarNetwork(const std::string& gatewayAddress, unsigned int gatewayPort, unsigned int localPort, bool debug); + CDStarNetwork(const std::string& gatewayAddress, unsigned int gatewayPort, unsigned int localPort, const std::string& version, bool debug); ~CDStarNetwork(); bool open(); @@ -37,7 +38,6 @@ public: bool writeHeader(const unsigned char* header, unsigned int length, bool busy); bool writeData(const unsigned char* data, unsigned int length, unsigned int errors, bool end, bool busy); - bool writePoll(const std::string& text); unsigned int read(unsigned char* data, unsigned int length); @@ -51,12 +51,16 @@ private: CUDPSocket m_socket; in_addr m_address; unsigned int m_port; + std::string m_version; bool m_debug; bool m_enabled; uint16_t m_outId; uint8_t m_outSeq; uint16_t m_inId; CRingBuffer m_buffer; + CTimer m_pollTimer; + + bool writePoll(const char* text); }; #endif diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 13ae898..6f8f47e 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -436,9 +436,6 @@ bool CMMDVMHost::createModem() bool CMMDVMHost::createDStarNetwork() { - if (!m_conf.getDStarNetworkEnabled()) - return false; - std::string gatewayAddress = m_conf.getDStarGatewayAddress(); unsigned int gatewayPort = m_conf.getDStarGatewayPort(); unsigned int localPort = m_conf.getDStarLocalPort(); @@ -449,7 +446,7 @@ bool CMMDVMHost::createDStarNetwork() LogInfo(" Gateway Port: %u", gatewayPort); LogInfo(" Local Port: %u", localPort); - m_dstarNetwork = new CDStarNetwork(gatewayAddress, gatewayPort, localPort, debug); + m_dstarNetwork = new CDStarNetwork(gatewayAddress, gatewayPort, localPort, VERSION, debug); bool ret = m_dstarNetwork->open(); if (!ret) { @@ -465,9 +462,6 @@ bool CMMDVMHost::createDStarNetwork() bool CMMDVMHost::createDMRNetwork() { - if (!m_conf.getDMRNetworkEnabled()) - return false; - std::string address = m_conf.getDMRNetworkAddress(); unsigned int port = m_conf.getDMRNetworkPort(); unsigned int id = m_conf.getDMRId(); diff --git a/Makefile b/Makefile index 61c770e..d40a51d 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ DMRSync.o: DMRSync.cpp DMRSync.h DMRDefines.h DStarEcho.o: DStarEcho.cpp DStarEcho.h RingBuffer.h Timer.h $(CC) $(CFLAGS) -c DStarEcho.cpp -DStarNetwork.o: DStarNetwork.cpp DStarNetwork.h Log.h UDPSocket.h RingBuffer.h Utils.h StopWatch.h DStarDefines.h Defines.h +DStarNetwork.o: DStarNetwork.cpp DStarNetwork.h Log.h UDPSocket.h RingBuffer.h Utils.h StopWatch.h DStarDefines.h Defines.h Timer.h $(CC) $(CFLAGS) -c DStarNetwork.cpp EMB.o: EMB.cpp EMB.h diff --git a/Version.h b/Version.h index cd33272..4638d80 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20160122"; +const char* VERSION = "20160125"; #endif