Skip to content

Commit

Permalink
Move the D-Star poll message to be run from the network class.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Jan 25, 2016
1 parent 8860b72 commit c92434e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
7 changes: 2 additions & 5 deletions DMRSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -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);

Expand Down
33 changes: 25 additions & 8 deletions DStarNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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';
Expand All @@ -145,12 +152,10 @@ bool CDStarNetwork::writePoll(const std::string& text)

buffer[4] = 0x0A; // Poll with text

unsigned int length = text.length();

for (unsigned int i = 0U; i < length; i++)
buffer[5U + i] = text.at(i);
unsigned int length = ::strlen(text);

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);
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions DStarNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -37,7 +38,6 @@ class CDStarNetwork {

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);

Expand All @@ -51,12 +51,16 @@ class CDStarNetwork {
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
8 changes: 1 addition & 7 deletions MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H

const char* VERSION = "20160122";
const char* VERSION = "20160125";

#endif

0 comments on commit c92434e

Please sign in to comment.