From 63bd864674e362c2fafc85fd68a728f5c7f8cef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Sat, 23 Apr 2022 13:46:23 +0200 Subject: [PATCH] Fix M17 Rx LED Now LED turns on when a syncword is successfully detected, not just when the correlation is sufficiently high. TG-81 --- .../include/protocols/M17/M17Demodulator.h | 3 ++- openrtx/src/protocols/M17/M17Demodulator.cpp | 26 +++++++------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/openrtx/include/protocols/M17/M17Demodulator.h b/openrtx/include/protocols/M17/M17Demodulator.h index d98be7f1..831d00f3 100644 --- a/openrtx/include/protocols/M17/M17Demodulator.h +++ b/openrtx/include/protocols/M17/M17Demodulator.h @@ -146,7 +146,8 @@ private: frame_t *activeFrame; ///< Half frame, in demodulation. frame_t *idleFrame; ///< Half frame, free to be processed. bool isLSF; ///< Indicates that we demodualated an LSF. - bool locked; ///< A syncword was detected. + bool syncDetected; ///< A syncword was detected. + bool locked; ///< A syncword was correctly demodulated. bool newFrame; ///< A new frame has been fully decoded. int16_t basebandBridge[M17_BRIDGE_SIZE] = { 0 }; ///< Bridge buffer uint16_t phase; ///< Phase of the signal w.r.t. sampling diff --git a/openrtx/src/protocols/M17/M17Demodulator.cpp b/openrtx/src/protocols/M17/M17Demodulator.cpp index 910d32a5..894c9845 100644 --- a/openrtx/src/protocols/M17/M17Demodulator.cpp +++ b/openrtx/src/protocols/M17/M17Demodulator.cpp @@ -62,6 +62,7 @@ void M17Demodulator::init() idleFrame = new frame_t; frame_index = 0; phase = 0; + syncDetected = false; locked = false; newFrame = false; @@ -206,7 +207,6 @@ sync_t M17Demodulator::nextFrameSync(int32_t offset) int32_t maxLen = static_cast < int32_t >(baseband.len - M17_BRIDGE_SIZE); for(int32_t i = offset; (syncword.index == -1) && (i < maxLen); i++) { - // If we are not locked search for a syncword int32_t conv = convolution(i, stream_syncword, M17_SYNCWORD_SYMBOLS); updateCorrelationStats(conv); @@ -288,7 +288,7 @@ uint8_t M17Demodulator::hammingDistance(uint8_t x, uint8_t y) bool M17Demodulator::update() { M17::sync_t syncword = { 0, false }; - int32_t offset = locked ? 0 : -(int32_t) M17_BRIDGE_SIZE; + int32_t offset = syncDetected ? 0 : -(int32_t) M17_BRIDGE_SIZE; uint16_t decoded_syms = 0; // Read samples from the ADC @@ -316,20 +316,20 @@ bool M17Demodulator::update() offset + phase) < static_cast < int32_t >(baseband.len))) { - // If we are not locked search for a syncword - if (!locked) + // If we are not demodulating a syncword, search for one + if (!syncDetected) { syncword = nextFrameSync(offset); if (syncword.index != -1) // Valid syncword found { - locked = true; + syncDetected = true; isLSF = syncword.lsf; offset = syncword.index + 4; phase = 0; frame_index = 0; } } - // While we are locked, demodulate available samples + // While we detected a syncword, demodulate available samples else { // Slice the input buffer to extract a frame and quantize @@ -403,29 +403,21 @@ bool M17Demodulator::update() // Too many errors in the syncword, lock is lost if ((hammingSync > 1) && (hammingLsf > 1)) { + syncDetected = false; locked = false; std::swap(activeFrame, idleFrame); frame_index = 0; newFrame = true; - - #ifdef PLATFORM_MOD17 - gpio_clearPin(SYNC_LED); - #endif // PLATFORM_MOD17 } // Correct syncword found else - { - #ifdef PLATFORM_MOD17 - gpio_setPin(SYNC_LED); - #endif // PLATFORM_MOD17 - - } + locked = true; } } } // We are at the end of the buffer - if (locked) + if (syncDetected) { // Compute phase of next buffer phase = (static_cast (phase) + offset + baseband.len) % M17_SAMPLES_PER_SYMBOL;