From 88273f3f3be8a9f93f7cdb50657721870c9a8809 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Fri, 9 Feb 2018 14:32:52 -0300 Subject: [PATCH 1/6] Improving packet loss detection --- DMRSlot.cpp | 39 +++++++++++---------------------------- DMRSlot.h | 1 - 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 5b0178b..d8d4b4d 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -45,8 +45,8 @@ unsigned int CDMRSlot::m_hangCount = 3U * 17U; CRSSIInterpolator* CDMRSlot::m_rssiMapper = NULL; -unsigned int CDMRSlot::m_jitterTime = 300U; -unsigned int CDMRSlot::m_jitterSlots = 5U; +unsigned int CDMRSlot::m_jitterTime = 360U; +unsigned int CDMRSlot::m_jitterSlots = 6U; unsigned char* CDMRSlot::m_idle = NULL; @@ -87,7 +87,6 @@ m_netTalkerId(TALKER_ID_NONE), m_rfLC(NULL), m_netLC(NULL), m_rfSeqNo(0U), -m_netSeqNo(0U), m_rfN(0U), m_netN(0U), m_networkWatchdog(1000U, 0U, 1500U), @@ -1349,13 +1348,12 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) if (m_netFrames == 0U) { ::memcpy(m_lastFrame, data, DMR_FRAME_LENGTH_BYTES + 2U); m_lastFrameValid = true; - m_netSeqNo = dmrData.getSeqNo(); - m_netN = dmrData.getN(); + m_netN = 5U; m_netLost = 0U; - } else { - insertSilence(data, dmrData.getSeqNo()); } + insertSilence(data, dmrData.getN()); + if (!m_netTimeout) writeQueueNet(data); @@ -1370,7 +1368,6 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) m_netFrames++; // Save details in case we need to infill data - m_netSeqNo = dmrData.getSeqNo(); m_netN = dmrData.getN(); #if defined(DUMP_DMR) @@ -1503,13 +1500,12 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) if (m_netFrames == 0U) { ::memcpy(m_lastFrame, data, DMR_FRAME_LENGTH_BYTES + 2U); m_lastFrameValid = true; - m_netSeqNo = dmrData.getSeqNo(); - m_netN = dmrData.getN(); + m_netN = 5U; m_netLost = 0U; - } else { - insertSilence(data, dmrData.getSeqNo()); } + insertSilence(data, dmrData.getN()); + if (!m_netTimeout) writeQueueNet(data); @@ -1519,7 +1515,6 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) m_netFrames++; // Save details in case we need to infill data - m_netSeqNo = dmrData.getSeqNo(); m_netN = dmrData.getN(); #if defined(DUMP_DMR) @@ -1992,7 +1987,8 @@ bool CDMRSlot::insertSilence(const unsigned char* data, unsigned char seqNo) assert(data != NULL); // Check to see if we have any spaces to fill? - unsigned char seq = m_netSeqNo + 1U; + unsigned char seq = (m_netN + 1U) % 6U; + if (seq == seqNo) { // Just copy the data, nothing else to do here ::memcpy(m_lastFrame, data, DMR_FRAME_LENGTH_BYTES + 2U); @@ -2000,17 +1996,7 @@ bool CDMRSlot::insertSilence(const unsigned char* data, unsigned char seqNo) return true; } - unsigned int oldSeqNo = m_netSeqNo + 1U; - unsigned int newSeqNo = seqNo; - - unsigned int count; - if (newSeqNo > oldSeqNo) - count = newSeqNo - oldSeqNo; - else - count = (256U + newSeqNo) - oldSeqNo; - - if (count >= 10U) - return false; + unsigned int count = (seqNo - seq + 6U) % 6U; insertSilence(count); @@ -2036,7 +2022,6 @@ void CDMRSlot::insertSilence(unsigned int count) } unsigned char n = (m_netN + 1U) % 6U; - unsigned char seqNo = m_netSeqNo + 1U; unsigned char fid = m_netLC->getFID(); @@ -2062,13 +2047,11 @@ void CDMRSlot::insertSilence(unsigned int count) writeQueueNet(data); - m_netSeqNo = seqNo; m_netN = n; m_netFrames++; m_netLost++; - seqNo++; n = (n + 1U) % 6U; } } diff --git a/DMRSlot.h b/DMRSlot.h index e2df1a4..4dfbde4 100644 --- a/DMRSlot.h +++ b/DMRSlot.h @@ -78,7 +78,6 @@ private: CDMRLC* m_rfLC; CDMRLC* m_netLC; unsigned char m_rfSeqNo; - unsigned char m_netSeqNo; unsigned char m_rfN; unsigned char m_netN; CTimer m_networkWatchdog; From 051f8c46e3ea461c53f7121bc16a2a2e67bd569b Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Fri, 9 Feb 2018 14:49:18 -0300 Subject: [PATCH 2/6] Jitter slots insert should be always multiple of 6 to avoid break DMR sequence --- DMRSlot.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DMRSlot.cpp b/DMRSlot.cpp index d8d4b4d..7da67dc 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -30,6 +30,7 @@ #include #include #include +#include unsigned int CDMRSlot::m_colorCode = 0U; @@ -1835,7 +1836,9 @@ void CDMRSlot::init(unsigned int colorCode, bool embeddedLCOnly, bool dumpTAData m_rssiMapper = rssiMapper; m_jitterTime = jitter; - m_jitterSlots = jitter / DMR_SLOT_TIME; + + float jitter_tmp = float(jitter) / 360.0F; + m_jitterSlots = (unsigned int) (std::ceil(jitter_tmp) * 6.0F); m_idle = new unsigned char[DMR_FRAME_LENGTH_BYTES + 2U]; ::memcpy(m_idle, DMR_IDLE_DATA, DMR_FRAME_LENGTH_BYTES + 2U); From 349cc43a1d6f034cb51b8854b8ba4529c298b956 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Fri, 9 Feb 2018 14:57:09 -0300 Subject: [PATCH 3/6] Change of the DMR Silence Data for AMBE+2 silence pattern --- DMRDefines.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/DMRDefines.h b/DMRDefines.h index f0ab1db..5b53c33 100644 --- a/DMRDefines.h +++ b/DMRDefines.h @@ -61,12 +61,9 @@ const unsigned char DMR_IDLE_DATA[] = {TAG_DATA, 0x00U, // A silence frame only const unsigned char DMR_SILENCE_DATA[] = {TAG_DATA, 0x00U, - 0xACU, 0xAAU, 0x40U, 0x20U, 0x00U, 0x44U, 0x40U, 0x80U, 0x80U, 0xACU, 0xAAU, - 0x40U, 0x20U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x44U, 0x40U, - 0x80U, 0x80U, 0xACU, 0xAAU, 0x40U, 0x20U, 0x00U, 0x44U, 0x40U, 0x80U, 0x80U}; -// 0x88U, 0xC8U, 0xA3U, 0x54U, 0x22U, 0x16U, 0x31U, 0x69U, 0x6AU, 0xAAU, 0xCAU, -// 0x81U, 0x54U, 0x20U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x27U, 0x13U, -// 0x29U, 0x48U, 0xAAU, 0xCAU, 0x81U, 0x54U, 0x21U, 0x27U, 0x31U, 0x39U, 0x6AU}; + 0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU, 0xB9U, 0xE8U, + 0x81U, 0x52U, 0x60U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x01U, 0x73U, 0x00U, + 0x2AU, 0x6BU, 0xB9U, 0xE8U, 0x81U, 0x52U, 0x61U, 0x73U, 0x00U, 0x2AU, 0x6BU}; const unsigned char PAYLOAD_LEFT_MASK[] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xF0U}; const unsigned char PAYLOAD_RIGHT_MASK[] = {0x0FU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU}; From 04934c5dcca5ad5ff89b427afb10cd7606115a99 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Fri, 9 Feb 2018 17:30:53 -0300 Subject: [PATCH 4/6] Drop duplicate packets --- DMRSlot.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 7da67dc..6eeee6c 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -1353,10 +1353,10 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) m_netLost = 0U; } - insertSilence(data, dmrData.getN()); - - if (!m_netTimeout) - writeQueueNet(data); + if (insertSilence(data, dmrData.getN())) { + if (!m_netTimeout) + writeQueueNet(data); + } m_netEmbeddedReadN = (m_netEmbeddedReadN + 1U) % 2U; m_netEmbeddedWriteN = (m_netEmbeddedWriteN + 1U) % 2U; @@ -1505,10 +1505,10 @@ void CDMRSlot::writeNetwork(const CDMRData& dmrData) m_netLost = 0U; } - insertSilence(data, dmrData.getN()); - - if (!m_netTimeout) - writeQueueNet(data); + if (insertSilence(data, dmrData.getN())) { + if (!m_netTimeout) + writeQueueNet(data); + } m_packetTimer.start(); m_elapsed.start(); @@ -1989,6 +1989,10 @@ bool CDMRSlot::insertSilence(const unsigned char* data, unsigned char seqNo) { assert(data != NULL); + // Do not send duplicate + if (seqNo == m_netN) + return false; + // Check to see if we have any spaces to fill? unsigned char seq = (m_netN + 1U) % 6U; From aa77b9f37a7101c43cb6d8d819ddc2cc940408f9 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Fri, 9 Feb 2018 17:43:26 -0300 Subject: [PATCH 5/6] Set LCSS in insertSilence --- DMRSlot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 6eeee6c..e08db32 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -2034,7 +2034,6 @@ void CDMRSlot::insertSilence(unsigned int count) CDMREMB emb; emb.setColorCode(m_colorCode); - emb.setLCSS(0U); for (unsigned int i = 0U; i < count; i++) { // Only use our silence frame if its AMBE audio data @@ -2048,7 +2047,8 @@ void CDMRSlot::insertSilence(unsigned int count) if (n == 0U) { CSync::addDMRAudioSync(data + 2U, m_duplex); } else { - m_netEmbeddedLC.getData(data + 2U, 0U); + unsigned char lcss = m_netEmbeddedLC.getData(data + 2U, n); + emb.setLCSS(lcss); emb.getData(data + 2U); } From cb618a9b85314bfcb8c6ebe22663316989edb4bc Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sat, 10 Feb 2018 12:35:12 -0300 Subject: [PATCH 6/6] Changing default Jitter time to 360 ms --- MMDVM.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMDVM.ini b/MMDVM.ini index 6f0ce32..ea89710 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -119,7 +119,7 @@ Debug=0 Enable=1 Address=44.131.4.1 Port=62031 -Jitter=300 +Jitter=360 # Local=62032 Password=PASSWORD # Options=