From c09d8c78ee1ce9f17d8a50592b31cbbad995a15e Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 23 Feb 2016 20:51:57 +0000 Subject: [PATCH] Allow for sync-less data frames. --- DMRSlotRX.cpp | 41 ++++++++++++++++++++++++++++++++++------- DMRSlotRX.h | 7 +++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/DMRSlotRX.cpp b/DMRSlotRX.cpp index a076f61..15c843f 100644 --- a/DMRSlotRX.cpp +++ b/DMRSlotRX.cpp @@ -49,7 +49,8 @@ m_threshold(0), m_control(0x00U), m_syncCount(0U), m_colorCode(0U), -m_n(0U) +m_n(0U), +m_state(DMRSRXS_NONE) { } @@ -72,13 +73,14 @@ void CDMRSlotRX::reset() m_threshold = 0; m_centre = 0; m_endPtr = NOENDPTR; + m_state = DMRSRXS_NONE; } bool CDMRSlotRX::processSample(q15_t sample) { // Ensure that the buffer doesn't overflow if (m_dataPtr > m_endPtr || m_dataPtr >= 900U) - return m_endPtr != NOENDPTR; + return m_state != DMRSRXS_NONE; m_buffer[m_dataPtr] = sample; @@ -119,14 +121,24 @@ bool CDMRSlotRX::processSample(q15_t sample) switch (dataType) { case DT_DATA_HEADER: + m_state = DMRSRXS_DATA; + DEBUG3("DMRSlotRX: data header for slot/data type", m_slot ? 2U : 1U, dataType); + serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U); + break; case DT_VOICE_LC_HEADER: + m_state = DMRSRXS_VOICE; + DEBUG3("DMRSlotRX: voice header for slot/data type", m_slot ? 2U : 1U, dataType); + serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U); + break; case DT_VOICE_PI_HEADER: - DEBUG3("DMRSlotRX: header for slot/data type", m_slot ? 2U : 1U, dataType); + m_state = DMRSRXS_VOICE; + DEBUG3("DMRSlotRX: pi header for slot/data type", m_slot ? 2U : 1U, dataType); serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U); break; case DT_TERMINATOR_WITH_LC: DEBUG2("DMRSlotRX: terminator for slot", m_slot ? 2U : 1U); m_endPtr = NOENDPTR; + m_state = DMRSRXS_NONE; serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U); break; default: @@ -139,6 +151,7 @@ bool CDMRSlotRX::processSample(q15_t sample) // Voice sync DEBUG2("DMRSlotRX: voice sync for slot", m_slot ? 2U : 1U); serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U); + m_state = DMRSRXS_VOICE; m_syncCount = 0U; m_n = 0U; } else { @@ -150,12 +163,26 @@ bool CDMRSlotRX::processSample(q15_t sample) m_threshold = 0; m_centre = 0; m_endPtr = NOENDPTR; + m_state = DMRSRXS_NONE; return false; } - // Voice data - frame[0U] |= ++m_n; - serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U); + if (m_state == DMRSRXS_VOICE) { + // Voice data + frame[0U] |= ++m_n; + serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U); + } else if (m_state == DMRSRXS_DATA) { + // Data data + uint8_t colorCode; + uint8_t dataType; + CDMRSlotType slotType; + slotType.decode(frame + 1U, colorCode, dataType); + + if (colorCode == m_colorCode) { + frame[0U] |= dataType; + serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U); + } + } } } @@ -165,7 +192,7 @@ bool CDMRSlotRX::processSample(q15_t sample) if (m_bitPtr >= DMR_RADIO_SYMBOL_LENGTH) m_bitPtr = 0U; - return m_endPtr != NOENDPTR; + return m_state != DMRSRXS_NONE; } void CDMRSlotRX::correlateSync(q15_t sample) diff --git a/DMRSlotRX.h b/DMRSlotRX.h index 0ac8d92..99aef33 100644 --- a/DMRSlotRX.h +++ b/DMRSlotRX.h @@ -22,6 +22,12 @@ #include "Config.h" #include "DMRDefines.h" +enum DMRSRXS { + DMRSRXS_NONE, + DMRSRXS_VOICE, + DMRSRXS_DATA +}; + class CDMRSlotRX { public: CDMRSlotRX(bool slot); @@ -49,6 +55,7 @@ private: uint8_t m_syncCount; uint8_t m_colorCode; uint8_t m_n; + DMRSRXS m_state; 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);