From da34f26c55ae8dc646b1cf2274c60f49892bad19 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 17 Mar 2016 19:31:12 +0000 Subject: [PATCH] Allow for a delay before processing a DMR slot. --- DMRRX.cpp | 6 ++++++ DMRRX.h | 1 + DMRSlotRX.cpp | 31 +++++++++++++++++++++---------- DMRSlotRX.h | 7 +++++-- SerialPort.cpp | 5 ++++- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/DMRRX.cpp b/DMRRX.cpp index 36923cb..9137b94 100644 --- a/DMRRX.cpp +++ b/DMRRX.cpp @@ -56,6 +56,12 @@ void CDMRRX::setColorCode(uint8_t colorCode) m_slot2RX.setColorCode(colorCode); } +void CDMRRX::setDelay(uint8_t delay) +{ + m_slot1RX.setDelay(delay); + m_slot2RX.setDelay(delay); +} + void CDMRRX::reset() { m_slot1RX.reset(); diff --git a/DMRRX.h b/DMRRX.h index f31f8ab..2f8810d 100644 --- a/DMRRX.h +++ b/DMRRX.h @@ -29,6 +29,7 @@ public: void samples(const q15_t* samples, const uint8_t* control, uint8_t length); void setColorCode(uint8_t colorCode); + void setDelay(uint8_t delay); void reset(); diff --git a/DMRSlotRX.cpp b/DMRSlotRX.cpp index 63157f3..bc7c40f 100644 --- a/DMRSlotRX.cpp +++ b/DMRSlotRX.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -// #define WANT_DEBUG +#define WANT_DEBUG #include "Config.h" #include "Globals.h" @@ -45,28 +45,32 @@ m_bitPtr(0U), m_dataPtr(0U), m_syncPtr(0U), m_endPtr(NOENDPTR), +m_delayPtr(0U), m_maxCorr(0), m_centre(0), m_threshold(0), m_control(0x00U), m_syncCount(0U), m_colorCode(0U), +m_delay(0U), m_n(0U) { } void CDMRSlotRX::start() { - m_dataPtr = 0U; - m_bitPtr = 0U; - m_maxCorr = 0; - m_control = 0x00U; + m_dataPtr = 0U; + m_delayPtr = 0U; + m_bitPtr = 0U; + m_maxCorr = 0; + m_control = 0x00U; } void CDMRSlotRX::reset() { m_syncPtr = 0U; m_dataPtr = 0U; + m_delayPtr = 0U; m_bitPtr = 0U; m_maxCorr = 0; m_control = 0x00U; @@ -78,6 +82,10 @@ void CDMRSlotRX::reset() bool CDMRSlotRX::processSample(q15_t sample) { + m_delayPtr++; + if (m_delayPtr < m_delay) + return m_endPtr != NOENDPTR; + // Ensure that the buffer doesn't overflow if (m_dataPtr > m_endPtr || m_dataPtr >= 900U) return m_endPtr != NOENDPTR; @@ -95,7 +103,7 @@ bool CDMRSlotRX::processSample(q15_t sample) if (m_dataPtr >= min && m_dataPtr <= max) correlateSync(sample); } else { - if (m_dataPtr >= 390U && m_dataPtr <= 500U) + if (m_dataPtr >= 420U && m_dataPtr <= 500U) correlateSync(sample); } @@ -226,10 +234,9 @@ void CDMRSlotRX::correlateSync(q15_t sample) errs += countBits8((sync[i] & DMR_SYNC_BYTES_MASK[i]) ^ DMR_MS_DATA_SYNC_BYTES[i]); if (errs <= MAX_SYNC_BYTES_ERRS) { - // DEBUG5("DMRSlotRX: data sync found slot/pos/centre/threshold", m_slot ? 2U : 1U, m_dataPtr, centre, threshold); #if defined(WANT_DEBUG) if (m_endPtr == NOENDPTR) - DEBUG5("DMRSlotRX: data sync found slot/pos/centre/threshold", m_slot ? 2U : 1U, m_dataPtr, centre, threshold); + DEBUG5("DMRSlotRX: data sync found slot/pos/centre/threshold", m_slot ? 2U : 1U, int16_t(m_dataPtr) - 420, centre, threshold); else DEBUG3("DMRSlotRX: data sync found slot/rel pos", m_slot ? 2U : 1U, int16_t(m_dataPtr) - int16_t(m_syncPtr)); #endif @@ -246,10 +253,9 @@ void CDMRSlotRX::correlateSync(q15_t sample) errs += countBits8((sync[i] & DMR_SYNC_BYTES_MASK[i]) ^ DMR_MS_VOICE_SYNC_BYTES[i]); if (errs <= MAX_SYNC_BYTES_ERRS) { - // DEBUG5("DMRSlotRX: voice sync found slot/pos/centre/threshold", m_slot ? 2U : 1U, m_dataPtr, centre, threshold); #if defined(WANT_DEBUG) if (m_endPtr == NOENDPTR) - DEBUG5("DMRSlotRX: voice sync found slot/pos/centre/threshold", m_slot ? 2U : 1U, m_dataPtr, centre, threshold); + DEBUG5("DMRSlotRX: voice sync found slot/pos/centre/threshold", m_slot ? 2U : 1U, int16_t(m_dataPtr) - 420, centre, threshold); else DEBUG3("DMRSlotRX: voice sync found slot/rel pos", m_slot ? 2U : 1U, int16_t(m_dataPtr) - int16_t(m_syncPtr)); #endif @@ -299,3 +305,8 @@ void CDMRSlotRX::setColorCode(uint8_t colorCode) m_colorCode = colorCode; } +void CDMRSlotRX::setDelay(uint8_t delay) +{ + m_delay = delay; +} + diff --git a/DMRSlotRX.h b/DMRSlotRX.h index 0ac8d92..aacbe2a 100644 --- a/DMRSlotRX.h +++ b/DMRSlotRX.h @@ -31,6 +31,7 @@ public: bool processSample(q15_t sample); void setColorCode(uint8_t colorCode); + void setDelay(uint8_t delay); void reset(); @@ -42,16 +43,18 @@ private: uint16_t m_dataPtr; uint16_t m_syncPtr; uint16_t m_endPtr; + uint16_t m_delayPtr; q31_t m_maxCorr; q15_t m_centre; q15_t m_threshold; uint8_t m_control; uint8_t m_syncCount; uint8_t m_colorCode; + uint16_t m_delay; uint8_t m_n; - void correlateSync(q15_t sample); - void samplesToBits(uint16_t start, uint8_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold); + void correlateSync(q15_t sample); + void samplesToBits(uint16_t start, uint8_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold); }; #endif diff --git a/SerialPort.cpp b/SerialPort.cpp index b16ebe0..d97dceb 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -176,7 +176,7 @@ void CSerialPort::getVersion() uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) { - if (length < 7U) + if (length < 8U) return 4U; bool rxInvert = (data[0U] & 0x01U) == 0x01U; @@ -209,6 +209,8 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) if (colorCode > 15U) return 4U; + uint8_t dmrDelay = data[7U]; + m_modemState = modemState; m_dstarEnable = dstarEnable; @@ -220,6 +222,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint8_t length) dmrTX.setColorCode(colorCode); dmrRX.setColorCode(colorCode); + dmrRX.setDelay(dmrDelay); dmrIdleRX.setColorCode(colorCode); io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, txLevel);