Revert "Revert "Simplify the logic by removing the ring buffer.""

This reverts commit d4d26fc05f.
This commit is contained in:
Jonathan Naylor 2017-11-28 10:19:13 +00:00
parent fc3328fb60
commit 71bd38f9e9
3 changed files with 70 additions and 107 deletions

View file

@ -31,7 +31,7 @@ const unsigned int BUFFER_LENGTH = 500U;
const unsigned int HOMEBREW_DATA_PACKET_LENGTH = 55U;
CDMRNetwork::CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType, unsigned int jitter) :
CDMRNetwork::CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType) :
m_address(),
m_port(port),
m_id(NULL),
@ -43,7 +43,6 @@ m_socket(local),
m_enabled(false),
m_slot1(slot1),
m_slot2(slot2),
m_jitterBuffers(NULL),
m_hwType(hwType),
m_status(WAITING_CONNECT),
m_retryTimer(1000U, 10U),
@ -70,22 +69,17 @@ m_beacon(false)
assert(port > 0U);
assert(id > 1000U);
assert(!password.empty());
assert(jitter > 0U);
m_address = CUDPSocket::lookup(address);
m_buffer = new unsigned char[BUFFER_LENGTH];
m_salt = new unsigned char[sizeof(uint32_t)];
m_id = new uint8_t[4U];
m_streamId = new uint32_t[2U];
m_jitterBuffers = new CJitterBuffer*[3U];
m_buffer = new unsigned char[BUFFER_LENGTH];
m_salt = new unsigned char[sizeof(uint32_t)];
m_id = new uint8_t[4U];
m_streamId = new uint32_t[2U];
m_streamId[0U] = 0x00U;
m_streamId[1U] = 0x00U;
m_jitterBuffers[1U] = new CJitterBuffer(60U, DMR_SLOT_TIME, jitter, 256U);
m_jitterBuffers[2U] = new CJitterBuffer(60U, DMR_SLOT_TIME, jitter, 256U);
m_id[0U] = id >> 24;
m_id[1U] = id >> 16;
m_id[2U] = id >> 8;
@ -97,14 +91,10 @@ m_beacon(false)
CDMRNetwork::~CDMRNetwork()
{
delete m_jitterBuffers[1U];
delete m_jitterBuffers[2U];
delete[] m_buffer;
delete[] m_buffer;
delete[] m_salt;
delete[] m_streamId;
delete[] m_id;
delete[] m_jitterBuffers;
}
void CDMRNetwork::setOptions(const std::string& options)
@ -148,77 +138,64 @@ bool CDMRNetwork::read(CDMRData& data)
if (m_status != RUNNING)
return false;
if (!m_rxData.isEmpty()) {
unsigned char length = 0U;
if (m_rxData.isEmpty())
return false;
m_rxData.getData(&length, 1U);
m_rxData.getData(m_buffer, length);
unsigned char length = 0U;
// Is this a data packet?
if (::memcmp(m_buffer, "DMRD", 4U) == 0) {
unsigned int slotNo = (m_buffer[15U] & 0x80U) == 0x80U ? 2U : 1U;
m_rxData.getData(&length, 1U);
m_rxData.getData(m_buffer, length);
bool wanted = true;
// Is this a data packet?
if (::memcmp(m_buffer, "DMRD", 4U) != 0)
return false;
// DMO mode slot disabling
if (slotNo == 1U && !m_duplex)
wanted = false;
unsigned char seqNo = m_buffer[4U];
// Individual slot disabling
if (slotNo == 1U && !m_slot1)
wanted = false;
if (slotNo == 2U && !m_slot2)
wanted = false;
unsigned int srcId = (m_buffer[5U] << 16) | (m_buffer[6U] << 8) | (m_buffer[7U] << 0);
if (wanted) {
unsigned char seqNo = m_buffer[4U];
m_jitterBuffers[slotNo]->addData(m_buffer, seqNo);
}
}
unsigned int dstId = (m_buffer[8U] << 16) | (m_buffer[9U] << 8) | (m_buffer[10U] << 0);
unsigned int slotNo = (m_buffer[15U] & 0x80U) == 0x80U ? 2U : 1U;
// DMO mode slot disabling
if (slotNo == 1U && !m_duplex)
return false;
// Individual slot disabling
if (slotNo == 1U && !m_slot1)
return false;
if (slotNo == 2U && !m_slot2)
return false;
FLCO flco = (m_buffer[15U] & 0x40U) == 0x40U ? FLCO_USER_USER : FLCO_GROUP;
data.setSeqNo(seqNo);
data.setSlotNo(slotNo);
data.setSrcId(srcId);
data.setDstId(dstId);
data.setFLCO(flco);
bool dataSync = (m_buffer[15U] & 0x20U) == 0x20U;
bool voiceSync = (m_buffer[15U] & 0x10U) == 0x10U;
if (dataSync) {
unsigned char dataType = m_buffer[15U] & 0x0FU;
data.setData(m_buffer + 20U);
data.setDataType(dataType);
data.setN(0U);
} else if (voiceSync) {
data.setData(m_buffer + 20U);
data.setDataType(DT_VOICE_SYNC);
data.setN(0U);
} else {
unsigned char n = m_buffer[15U] & 0x0FU;
data.setData(m_buffer + 20U);
data.setDataType(DT_VOICE);
data.setN(n);
}
for (unsigned int slotNo = 1U; slotNo <= 2U; slotNo++) {
JB_STATUS status = m_jitterBuffers[slotNo]->getData(m_buffer);
if (status != JBS_NO_DATA) {
unsigned char seqNo = m_buffer[4U];
unsigned int srcId = (m_buffer[5U] << 16) | (m_buffer[6U] << 8) | (m_buffer[7U] << 0);
unsigned int dstId = (m_buffer[8U] << 16) | (m_buffer[9U] << 8) | (m_buffer[10U] << 0);
FLCO flco = (m_buffer[15U] & 0x40U) == 0x40U ? FLCO_USER_USER : FLCO_GROUP;
data.setSeqNo(seqNo);
data.setSlotNo(slotNo);
data.setSrcId(srcId);
data.setDstId(dstId);
data.setFLCO(flco);
data.setMissing(status == JBS_MISSING);
bool dataSync = (m_buffer[15U] & 0x20U) == 0x20U;
bool voiceSync = (m_buffer[15U] & 0x10U) == 0x10U;
if (dataSync) {
unsigned char dataType = m_buffer[15U] & 0x0FU;
data.setData(m_buffer + 20U);
data.setDataType(dataType);
data.setN(0U);
} else if (voiceSync) {
data.setData(m_buffer + 20U);
data.setDataType(DT_VOICE_SYNC);
data.setN(0U);
} else {
unsigned char n = m_buffer[15U] & 0x0FU;
data.setData(m_buffer + 20U);
data.setDataType(DT_VOICE);
data.setN(n);
}
return true;
}
}
return false;
return true;
}
bool CDMRNetwork::write(const CDMRData& data)
@ -362,9 +339,6 @@ void CDMRNetwork::close()
void CDMRNetwork::clock(unsigned int ms)
{
m_jitterBuffers[1U]->clock(ms);
m_jitterBuffers[2U]->clock(ms);
if (m_status == WAITING_CONNECT) {
m_retryTimer.clock(ms);
if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
@ -506,13 +480,6 @@ void CDMRNetwork::clock(unsigned int ms)
}
}
void CDMRNetwork::reset(unsigned int slotNo)
{
assert(slotNo == 1U || slotNo == 2U);
m_jitterBuffers[slotNo]->reset();
}
bool CDMRNetwork::writeLogin()
{
unsigned char buffer[8U];

View file

@ -19,7 +19,6 @@
#if !defined(DMRNetwork_H)
#define DMRNetwork_H
#include "JitterBuffer.h"
#include "UDPSocket.h"
#include "Timer.h"
#include "RingBuffer.h"
@ -32,7 +31,7 @@
class CDMRNetwork
{
public:
CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType, unsigned int jitter);
CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, HW_TYPE hwType);
~CDMRNetwork();
void setOptions(const std::string& options);
@ -55,24 +54,21 @@ public:
void clock(unsigned int ms);
void reset(unsigned int slotNo);
void close();
private:
in_addr m_address;
unsigned int m_port;
uint8_t* m_id;
std::string m_password;
bool m_duplex;
const char* m_version;
bool m_debug;
CUDPSocket m_socket;
bool m_enabled;
bool m_slot1;
bool m_slot2;
CJitterBuffer** m_jitterBuffers;
HW_TYPE m_hwType;
in_addr m_address;
unsigned int m_port;
uint8_t* m_id;
std::string m_password;
bool m_duplex;
const char* m_version;
bool m_debug;
CUDPSocket m_socket;
bool m_enabled;
bool m_slot1;
bool m_slot2;
HW_TYPE m_hwType;
enum STATUS {
WAITING_CONNECT,

View file

@ -946,7 +946,7 @@ bool CMMDVMHost::createDMRNetwork()
LogInfo(" Slot 2: %s", slot2 ? "enabled" : "disabled");
LogInfo(" Mode Hang: %us", m_dmrNetModeHang);
m_dmrNetwork = new CDMRNetwork(address, port, local, id, password, m_duplex, VERSION, debug, slot1, slot2, hwType, jitter);
m_dmrNetwork = new CDMRNetwork(address, port, local, id, password, m_duplex, VERSION, debug, slot1, slot2, hwType);
std::string options = m_conf.getDMRNetworkOptions();
if (!options.empty()) {