Move the D-Star poll message to be run from the network class.
This commit is contained in:
parent
8860b72e6c
commit
c92434e474
|
@ -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);
|
||||
|
||||
|
|
|
@ -25,24 +25,29 @@
|
|||
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
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;
|
||||
|
|
|
@ -22,13 +22,14 @@
|
|||
#include "DStarDefines.h"
|
||||
#include "RingBuffer.h"
|
||||
#include "UDPSocket.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
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<unsigned char> m_buffer;
|
||||
CTimer m_pollTimer;
|
||||
|
||||
bool writePoll(const char* text);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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();
|
||||
|
|
2
Makefile
2
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
|
||||
|
|
Loading…
Reference in a new issue