From 657e71238db319e8341a7e1ef3d450e1447103ed Mon Sep 17 00:00:00 2001 From: Tim Stewart Date: Sat, 28 Nov 2020 22:29:34 -0500 Subject: [PATCH] Detect full 48 bits of last data frame in a transmission While testing new support for DV Fast Data, I ran across a particular image that reliably generated a bit sequence that the MDMVM firmware interpreted as an end-of-transmission. I dug a bit and discovered that MMDVM only matches on 32 bits of the last data frame instead of the full 48 bits. See http://www.arrl.org/files/file/D-STAR.pdf section 2.1.2, item (6) for details. --- DStarRX.cpp | 20 +++++++++++++++++--- DStarRX.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/DStarRX.cpp b/DStarRX.cpp index f14f3fd6..72b143ef 100644 --- a/DStarRX.cpp +++ b/DStarRX.cpp @@ -41,8 +41,8 @@ const uint32_t DATA_SYNC_MASK = 0x00FFFFFFU; const uint8_t DATA_SYNC_ERRS = 2U; // D-Star bit order version of 0x55 0x55 0xC8 0x7A -const uint32_t END_SYNC_DATA = 0xAAAA135EU; -const uint32_t END_SYNC_MASK = 0xFFFFFFFFU; +const uint64_t END_SYNC_DATA = 0x0000AAAAAAAA135EU; +const uint64_t END_SYNC_MASK = 0x0000FFFFFFFFFFFFU; const uint8_t END_SYNC_ERRS = 1U; const uint8_t BIT_MASK_TABLE0[] = {0x7FU, 0xBFU, 0xDFU, 0xEFU, 0xF7U, 0xFBU, 0xFDU, 0xFEU}; @@ -242,6 +242,7 @@ m_pll(0U), m_prev(false), m_rxState(DSRXS_NONE), m_patternBuffer(0x00U), +m_patternBuffer64(0x00U), m_rxBuffer(), m_rxBufferBits(0U), m_dataBits(0U), @@ -263,6 +264,7 @@ void CDStarRX::reset() m_prev = false; m_rxState = DSRXS_NONE; m_patternBuffer = 0x00U; + m_patternBuffer64 = 0x00U; m_rxBufferBits = 0U; m_dataBits = 0U; m_rssiAccum = 0U; @@ -314,6 +316,10 @@ void CDStarRX::processNone(bool bit) if (bit) m_patternBuffer |= 0x01U; + m_patternBuffer64 <<= 1; + if (bit) + m_patternBuffer64 |= 0x01U; + // Fuzzy matching of the frame sync sequence if (countBits32((m_patternBuffer & FRAME_SYNC_MASK) ^ FRAME_SYNC_DATA) <= FRAME_SYNC_ERRS) { DEBUG1("DStarRX: found frame sync in None"); @@ -357,6 +363,10 @@ void CDStarRX::processHeader(bool bit) if (bit) m_patternBuffer |= 0x01U; + m_patternBuffer64 <<= 1; + if (bit) + m_patternBuffer64 |= 0x01U; + WRITE_BIT2(m_rxBuffer, m_rxBufferBits, bit); m_rxBufferBits++; @@ -389,11 +399,15 @@ void CDStarRX::processData(bool bit) if (bit) m_patternBuffer |= 0x01U; + m_patternBuffer64 <<= 1; + if (bit) + m_patternBuffer64 |= 0x01U; + WRITE_BIT2(m_rxBuffer, m_rxBufferBits, bit); m_rxBufferBits++; // Fuzzy matching of the end frame sequences - if (countBits32((m_patternBuffer & END_SYNC_MASK) ^ END_SYNC_DATA) <= END_SYNC_ERRS) { + if (countBits64((m_patternBuffer64 & END_SYNC_MASK) ^ END_SYNC_DATA) <= END_SYNC_ERRS) { DEBUG1("DStarRX: Found end sync in Data"); io.setDecode(false); diff --git a/DStarRX.h b/DStarRX.h index d636cdee..cc327ce4 100644 --- a/DStarRX.h +++ b/DStarRX.h @@ -41,6 +41,7 @@ class CDStarRX { bool m_prev; DSRX_STATE m_rxState; uint32_t m_patternBuffer; + uint64_t m_patternBuffer64; uint8_t m_rxBuffer[100U]; unsigned int m_rxBufferBits; unsigned int m_dataBits;