From 22009458573649754cbc5d877460aab1514131e1 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 26 Aug 2021 16:50:18 +0100 Subject: [PATCH] Change the EOF sync pattern for simplicity. --- M17Defines.h | 20 ++++------ M17RX.cpp | 101 +++++++++++---------------------------------------- M17RX.h | 3 -- M17TX.cpp | 6 +-- Version.h | 2 +- 5 files changed, 32 insertions(+), 100 deletions(-) diff --git a/M17Defines.h b/M17Defines.h index 8f870e9..27f91c9 100644 --- a/M17Defines.h +++ b/M17Defines.h @@ -31,19 +31,13 @@ const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U; const unsigned int M17_SYNC_LENGTH_SYMBOLS = M17_SYNC_LENGTH_BITS / 2U; const unsigned int M17_SYNC_LENGTH_SAMPLES = M17_SYNC_LENGTH_SYMBOLS * M17_RADIO_SYMBOL_LENGTH; -const unsigned int M17_EOF_LENGTH_BITS = 26U; -const unsigned int M17_EOF_LENGTH_BYTES = 4U; -const unsigned int M17_EOF_LENGTH_SYMBOLS = M17_EOF_LENGTH_BITS / 2U; -const unsigned int M17_EOF_LENGTH_SAMPLES = M17_EOF_LENGTH_SYMBOLS * M17_RADIO_SYMBOL_LENGTH; - const uint8_t M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U}; const uint8_t M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU}; - -const uint8_t M17_EOF_MASK[] = {0xFFU, 0xFFU, 0xFFU, 0xC0U}; -const uint8_t M17_EOF_BYTES[] = {0x55U, 0x7DU, 0x77U, 0x40U}; +const uint8_t M17_EOF_SYNC_BYTES[] = {0x55U, 0x5DU}; const uint16_t M17_LINK_SETUP_SYNC_BITS = 0x55F7U; const uint16_t M17_STREAM_SYNC_BITS = 0xFF5DU; +const uint16_t M17_EOF_SYNC_BITS = 0x555DU; // 5 5 F 7 // 01 01 01 01 11 11 01 11 @@ -61,13 +55,13 @@ const int8_t M17_STREAM_SYNC_SYMBOLS_VALUES[] = {-3, -3, -3, -3, +3, +3, -3, +3} const uint8_t M17_STREAM_SYNC_SYMBOLS = 0x0DU; -// 5 5 7 D 7 7 4 -// 01 01 01 01 01 11 11 01 01 11 01 11 01 -// +3 +3 +3 +3 +3 -3 -3 +3 +3 -3 +3 -3 +3 +// 5 5 5 D +// 01 01 01 01 01 01 11 01 +// +3 +3 +3 +3 +3 +3 -3 +3 -const int8_t M17_EOF_SYMBOLS_VALUES[] = {+3, +3, +3, +3, +3, -3, -3, +3, +3, -3, +3, -3, +3}; +const int8_t M17_EOF_SYNC_SYMBOLS_VALUES[] = {+3, +3, +3, +3, +3, +3, -3, +3}; -const uint16_t M17_EOF_SYMBOLS = 0x1F35U; +const uint8_t M17_EOF_SYNC_SYMBOLS = 0xFDU; #endif diff --git a/M17RX.cpp b/M17RX.cpp index fcf71c9..44ee13f 100644 --- a/M17RX.cpp +++ b/M17RX.cpp @@ -28,7 +28,6 @@ const q15_t SCALING_FACTOR = 18750; // Q15(0.55) const uint8_t MAX_SYNC_BIT_START_ERRS = 0U; const uint8_t MAX_SYNC_BIT_RUN_ERRS = 2U; -const uint8_t MAX_EOF_BIT_ERRS = 2U; const uint8_t MAX_SYNC_SYMBOL_START_ERRS = 0U; const uint8_t MAX_SYNC_SYMBOL_RUN_ERRS = 1U; @@ -54,8 +53,6 @@ m_endPtr(NOENDPTR), m_syncPtr(NOENDPTR), m_minSyncPtr(NOENDPTR), m_maxSyncPtr(NOENDPTR), -m_minEOFPtr(NOENDPTR), -m_maxEOFPtr(NOENDPTR), m_maxCorr(0), m_lostCount(0U), m_countdown(0U), @@ -82,8 +79,6 @@ void CM17RX::reset() m_syncPtr = NOENDPTR; m_minSyncPtr = NOENDPTR; m_maxSyncPtr = NOENDPTR; - m_minEOFPtr = NOENDPTR; - m_maxEOFPtr = NOENDPTR; m_centreVal = 0; m_thresholdVal = 0; m_lostCount = 0U; @@ -162,14 +157,6 @@ void CM17RX::processNone(q15_t sample) if (m_maxSyncPtr >= M17_FRAME_LENGTH_SAMPLES) m_maxSyncPtr -= M17_FRAME_LENGTH_SAMPLES; - m_minEOFPtr = m_minSyncPtr + M17_EOF_LENGTH_SAMPLES - M17_SYNC_LENGTH_SAMPLES; - if (m_minEOFPtr >= M17_FRAME_LENGTH_SAMPLES) - m_minEOFPtr -= M17_FRAME_LENGTH_SAMPLES; - - m_maxEOFPtr = m_maxSyncPtr + M17_EOF_LENGTH_SAMPLES - M17_SYNC_LENGTH_SAMPLES; - if (m_maxEOFPtr >= M17_FRAME_LENGTH_SAMPLES) - m_maxEOFPtr -= M17_FRAME_LENGTH_SAMPLES; - m_state = m_nextState; m_countdown = 0U; m_nextState = M17RXS_NONE; @@ -178,62 +165,40 @@ void CM17RX::processNone(q15_t sample) void CM17RX::processData(q15_t sample) { + bool eof = false; + if (m_minSyncPtr < m_maxSyncPtr) { if (m_dataPtr >= m_minSyncPtr && m_dataPtr <= m_maxSyncPtr) { - bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); - bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); + bool ret = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); - if (ret1) m_state = M17RXS_LINK_SETUP; - if (ret2) m_state = M17RXS_STREAM; + eof = correlateSync(M17_EOF_SYNC_SYMBOLS, M17_EOF_SYNC_SYMBOLS_VALUES, M17_EOF_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); + + if (ret) m_state = M17RXS_STREAM; } } else { if (m_dataPtr >= m_minSyncPtr || m_dataPtr <= m_maxSyncPtr) { - bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); - bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); + bool ret = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); - if (ret1) m_state = M17RXS_LINK_SETUP; - if (ret2) m_state = M17RXS_STREAM; + eof = correlateSync(M17_EOF_SYNC_SYMBOLS, M17_EOF_SYNC_SYMBOLS_VALUES, M17_EOF_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS); + + if (ret) m_state = M17RXS_STREAM; } } - if (m_minEOFPtr < m_maxEOFPtr) { - if (m_dataPtr >= m_minEOFPtr && m_dataPtr <= m_maxEOFPtr) { - bool ret = detectEOF(); - if (ret) { - DEBUG2("M17RX: eof found pos", m_dataPtr); + if (eof) { + DEBUG4("M17RX: eof sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal); - io.setDecode(false); - io.setADCDetection(false); + io.setDecode(false); + io.setADCDetection(false); - serial.writeM17EOT(); + serial.writeM17EOT(); - m_state = M17RXS_NONE; - m_endPtr = NOENDPTR; - m_averagePtr = NOAVEPTR; - m_countdown = 0U; - m_nextState = M17RXS_NONE; - m_maxCorr = 0; - } - } - } else { - if (m_dataPtr >= m_minEOFPtr || m_dataPtr <= m_maxEOFPtr) { - bool ret = detectEOF(); - if (ret) { - DEBUG2("M17RX: eof found pos", m_dataPtr); - - io.setDecode(false); - io.setADCDetection(false); - - serial.writeM17EOT(); - - m_state = M17RXS_NONE; - m_endPtr = NOENDPTR; - m_averagePtr = NOAVEPTR; - m_countdown = 0U; - m_nextState = M17RXS_NONE; - m_maxCorr = 0; - } - } + m_state = M17RXS_NONE; + m_endPtr = NOENDPTR; + m_averagePtr = NOAVEPTR; + m_countdown = 0U; + m_nextState = M17RXS_NONE; + m_maxCorr = 0; } if (m_dataPtr == m_endPtr) { @@ -246,14 +211,6 @@ void CM17RX::processData(q15_t sample) m_maxSyncPtr = m_syncPtr + 1U; if (m_maxSyncPtr >= M17_FRAME_LENGTH_SAMPLES) m_maxSyncPtr -= M17_FRAME_LENGTH_SAMPLES; - - m_minEOFPtr = m_minSyncPtr + M17_EOF_LENGTH_SAMPLES - M17_SYNC_LENGTH_SAMPLES; - if (m_minEOFPtr >= M17_FRAME_LENGTH_SAMPLES) - m_minEOFPtr -= M17_FRAME_LENGTH_SAMPLES; - - m_maxEOFPtr = m_maxSyncPtr + M17_EOF_LENGTH_SAMPLES - M17_SYNC_LENGTH_SAMPLES; - if (m_maxEOFPtr >= M17_FRAME_LENGTH_SAMPLES) - m_maxEOFPtr -= M17_FRAME_LENGTH_SAMPLES; } calculateLevels(m_startPtr, M17_FRAME_LENGTH_SYMBOLS); @@ -385,22 +342,6 @@ bool CM17RX::correlateSync(uint8_t syncSymbols, const int8_t* syncSymbolValues, return false; } -bool CM17RX::detectEOF() -{ - uint16_t startPtr = m_dataPtr + M17_FRAME_LENGTH_SAMPLES - M17_EOF_LENGTH_SAMPLES + M17_RADIO_SYMBOL_LENGTH; - if (startPtr >= M17_FRAME_LENGTH_SAMPLES) - startPtr -= M17_FRAME_LENGTH_SAMPLES; - - uint8_t eof[M17_EOF_LENGTH_BYTES]; - samplesToBits(startPtr, M17_EOF_LENGTH_SYMBOLS, eof, 0U, m_centreVal, m_thresholdVal); - - uint8_t errs = 0U; - for (uint8_t i = 0U; i < M17_EOF_LENGTH_BYTES; i++) - errs += countBits8((eof[i] ^ M17_EOF_BYTES[i]) & M17_EOF_MASK[i]); - - return errs <= MAX_EOF_BIT_ERRS; -} - void CM17RX::calculateLevels(uint16_t start, uint16_t count) { q15_t maxPos = -16000; diff --git a/M17RX.h b/M17RX.h index b4a9048..de6ed6d 100644 --- a/M17RX.h +++ b/M17RX.h @@ -50,8 +50,6 @@ private: uint16_t m_syncPtr; uint16_t m_minSyncPtr; uint16_t m_maxSyncPtr; - uint16_t m_minEOFPtr; - uint16_t m_maxEOFPtr; q31_t m_maxCorr; uint16_t m_lostCount; uint8_t m_countdown; @@ -67,7 +65,6 @@ private: void processNone(q15_t sample); void processData(q15_t sample); bool correlateSync(uint8_t syncSymbols, const int8_t* syncSymbolValues, const uint8_t* syncBytes, uint8_t maxSymbolErrs, uint8_t maxBitErrs); - bool detectEOF(); void calculateLevels(uint16_t start, uint16_t count); void samplesToBits(uint16_t start, uint16_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold); void writeRSSILinkSetup(uint8_t* data); diff --git a/M17TX.cpp b/M17TX.cpp index 6129623..05acce2 100644 --- a/M17TX.cpp +++ b/M17TX.cpp @@ -147,11 +147,11 @@ uint8_t CM17TX::writeStream(const uint8_t* data, uint8_t length) uint8_t CM17TX::writeEOT() { uint16_t space = m_buffer.getSpace(); - if (space < M17_EOF_LENGTH_BYTES) + if (space < M17_SYNC_LENGTH_BYTES) return 5U; - for (uint8_t i = 0U; i < M17_EOF_LENGTH_BYTES; i++) - m_buffer.put(M17_EOF_BYTES[i]); + for (uint8_t i = 0U; i < M17_SYNC_LENGTH_BYTES; i++) + m_buffer.put(M17_EOF_SYNC_BYTES[i]); return 0U; } diff --git a/Version.h b/Version.h index 49872f5..8c0e12f 100644 --- a/Version.h +++ b/Version.h @@ -19,7 +19,7 @@ #if !defined(VERSION_H) #define VERSION_H -#define VERSION "20210825" +#define VERSION "20210826" #endif