Allow for a delay before processing a DMR slot.

48kHz
Jonathan Naylor 2016-03-17 19:31:12 +00:00
parent c7ea8a68c6
commit da34f26c55
5 changed files with 37 additions and 13 deletions

View File

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

View File

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

View File

@ -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,12 +45,14 @@ 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)
{
}
@ -58,6 +60,7 @@ m_n(0U)
void CDMRSlotRX::start()
{
m_dataPtr = 0U;
m_delayPtr = 0U;
m_bitPtr = 0U;
m_maxCorr = 0;
m_control = 0x00U;
@ -67,6 +70,7 @@ 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;
}

View File

@ -31,6 +31,7 @@ public:
bool processSample(q15_t sample);
void setColorCode(uint8_t colorCode);
void setDelay(uint8_t delay);
void reset();
@ -42,12 +43,14 @@ 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);

View File

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