Skip to content

Commit

Permalink
Simplify the logic by removing the ring buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Naylor committed Nov 24, 2017
1 parent d87877e commit baef6c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
54 changes: 20 additions & 34 deletions DMRNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ m_timeoutTimer(1000U, 60U),
m_buffer(NULL),
m_salt(NULL),
m_streamId(NULL),
m_rxData(1000U, "DMR Network"),
m_options(),
m_callsign(),
m_rxFrequency(0U),
Expand Down Expand Up @@ -148,35 +147,6 @@ bool CDMRNetwork::read(CDMRData& data)
if (m_status != RUNNING)
return false;

if (!m_rxData.isEmpty()) {
unsigned char length = 0U;

m_rxData.getData(&length, 1U);
m_rxData.getData(m_buffer, length);

// Is this a data packet?
if (::memcmp(m_buffer, "DMRD", 4U) == 0) {
unsigned int slotNo = (m_buffer[15U] & 0x80U) == 0x80U ? 2U : 1U;

bool wanted = true;

// DMO mode slot disabling
if (slotNo == 1U && !m_duplex)
wanted = false;

// Individual slot disabling
if (slotNo == 1U && !m_slot1)
wanted = false;
if (slotNo == 2U && !m_slot2)
wanted = false;

if (wanted) {
unsigned char seqNo = m_buffer[4U];
m_jitterBuffers[slotNo]->addData(m_buffer, length, seqNo);
}
}
}

for (unsigned int slotNo = 1U; slotNo <= 2U; slotNo++) {
unsigned int length = 0U;
JB_STATUS status = m_jitterBuffers[slotNo]->getData(m_buffer, length);
Expand Down Expand Up @@ -403,10 +373,7 @@ void CDMRNetwork::clock(unsigned int ms)
if (m_enabled) {
if (m_debug)
CUtils::dump(1U, "Network Received", m_buffer, length);

unsigned char len = length;
m_rxData.addData(&len, 1U);
m_rxData.addData(m_buffer, len);
receiveData(m_buffer, length);
}
} else if (::memcmp(m_buffer, "MSTNAK", 6U) == 0) {
if (m_status == RUNNING) {
Expand Down Expand Up @@ -514,6 +481,25 @@ void CDMRNetwork::reset(unsigned int slotNo)
m_jitterBuffers[slotNo]->reset();
}

void CDMRNetwork::receiveData(const unsigned char* data, unsigned int length)
{
unsigned int slotNo = (m_buffer[15U] & 0x80U) == 0x80U ? 2U : 1U;

// DMO mode slot disabling
if (slotNo == 1U && !m_duplex)
return;

// Individual slot disabling
if (slotNo == 1U && !m_slot1)
return;
if (slotNo == 2U && !m_slot2)
return;

unsigned char seqNo = m_buffer[4U];

m_jitterBuffers[slotNo]->addData(m_buffer, length, seqNo);
}

bool CDMRNetwork::writeLogin()
{
unsigned char buffer[8U];
Expand Down
5 changes: 2 additions & 3 deletions DMRNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "JitterBuffer.h"
#include "UDPSocket.h"
#include "Timer.h"
#include "RingBuffer.h"
#include "DMRData.h"
#include "Defines.h"

Expand Down Expand Up @@ -90,8 +89,6 @@ class CDMRNetwork
unsigned char* m_salt;
uint32_t* m_streamId;

CRingBuffer<unsigned char> m_rxData;

std::string m_options;

std::string m_callsign;
Expand All @@ -115,6 +112,8 @@ class CDMRNetwork
bool writePing();

bool write(const unsigned char* data, unsigned int length);

void receiveData(const unsigned char* data, unsigned int length);
};

#endif

0 comments on commit baef6c9

Please sign in to comment.