Fix M17 Rx LED
Now LED turns on when a syncword is successfully detected, not just when the correlation is sufficiently high. TG-81
This commit is contained in:
parent
c4483edff0
commit
63bd864674
|
|
@ -146,7 +146,8 @@ private:
|
||||||
frame_t *activeFrame; ///< Half frame, in demodulation.
|
frame_t *activeFrame; ///< Half frame, in demodulation.
|
||||||
frame_t *idleFrame; ///< Half frame, free to be processed.
|
frame_t *idleFrame; ///< Half frame, free to be processed.
|
||||||
bool isLSF; ///< Indicates that we demodualated an LSF.
|
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.
|
bool newFrame; ///< A new frame has been fully decoded.
|
||||||
int16_t basebandBridge[M17_BRIDGE_SIZE] = { 0 }; ///< Bridge buffer
|
int16_t basebandBridge[M17_BRIDGE_SIZE] = { 0 }; ///< Bridge buffer
|
||||||
uint16_t phase; ///< Phase of the signal w.r.t. sampling
|
uint16_t phase; ///< Phase of the signal w.r.t. sampling
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ void M17Demodulator::init()
|
||||||
idleFrame = new frame_t;
|
idleFrame = new frame_t;
|
||||||
frame_index = 0;
|
frame_index = 0;
|
||||||
phase = 0;
|
phase = 0;
|
||||||
|
syncDetected = false;
|
||||||
locked = false;
|
locked = false;
|
||||||
newFrame = 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);
|
int32_t maxLen = static_cast < int32_t >(baseband.len - M17_BRIDGE_SIZE);
|
||||||
for(int32_t i = offset; (syncword.index == -1) && (i < maxLen); i++)
|
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);
|
int32_t conv = convolution(i, stream_syncword, M17_SYNCWORD_SYMBOLS);
|
||||||
updateCorrelationStats(conv);
|
updateCorrelationStats(conv);
|
||||||
|
|
||||||
|
|
@ -288,7 +288,7 @@ uint8_t M17Demodulator::hammingDistance(uint8_t x, uint8_t y)
|
||||||
bool M17Demodulator::update()
|
bool M17Demodulator::update()
|
||||||
{
|
{
|
||||||
M17::sync_t syncword = { 0, false };
|
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;
|
uint16_t decoded_syms = 0;
|
||||||
|
|
||||||
// Read samples from the ADC
|
// Read samples from the ADC
|
||||||
|
|
@ -316,20 +316,20 @@ bool M17Demodulator::update()
|
||||||
offset + phase) < static_cast < int32_t >(baseband.len)))
|
offset + phase) < static_cast < int32_t >(baseband.len)))
|
||||||
{
|
{
|
||||||
|
|
||||||
// If we are not locked search for a syncword
|
// If we are not demodulating a syncword, search for one
|
||||||
if (!locked)
|
if (!syncDetected)
|
||||||
{
|
{
|
||||||
syncword = nextFrameSync(offset);
|
syncword = nextFrameSync(offset);
|
||||||
if (syncword.index != -1) // Valid syncword found
|
if (syncword.index != -1) // Valid syncword found
|
||||||
{
|
{
|
||||||
locked = true;
|
syncDetected = true;
|
||||||
isLSF = syncword.lsf;
|
isLSF = syncword.lsf;
|
||||||
offset = syncword.index + 4;
|
offset = syncword.index + 4;
|
||||||
phase = 0;
|
phase = 0;
|
||||||
frame_index = 0;
|
frame_index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// While we are locked, demodulate available samples
|
// While we detected a syncword, demodulate available samples
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Slice the input buffer to extract a frame and quantize
|
// 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
|
// Too many errors in the syncword, lock is lost
|
||||||
if ((hammingSync > 1) && (hammingLsf > 1))
|
if ((hammingSync > 1) && (hammingLsf > 1))
|
||||||
{
|
{
|
||||||
|
syncDetected = false;
|
||||||
locked = false;
|
locked = false;
|
||||||
std::swap(activeFrame, idleFrame);
|
std::swap(activeFrame, idleFrame);
|
||||||
frame_index = 0;
|
frame_index = 0;
|
||||||
newFrame = true;
|
newFrame = true;
|
||||||
|
|
||||||
#ifdef PLATFORM_MOD17
|
|
||||||
gpio_clearPin(SYNC_LED);
|
|
||||||
#endif // PLATFORM_MOD17
|
|
||||||
}
|
}
|
||||||
// Correct syncword found
|
// Correct syncword found
|
||||||
else
|
else
|
||||||
{
|
locked = true;
|
||||||
#ifdef PLATFORM_MOD17
|
|
||||||
gpio_setPin(SYNC_LED);
|
|
||||||
#endif // PLATFORM_MOD17
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are at the end of the buffer
|
// We are at the end of the buffer
|
||||||
if (locked)
|
if (syncDetected)
|
||||||
{
|
{
|
||||||
// Compute phase of next buffer
|
// Compute phase of next buffer
|
||||||
phase = (static_cast<int32_t> (phase) + offset + baseband.len) % M17_SAMPLES_PER_SYMBOL;
|
phase = (static_cast<int32_t> (phase) + offset + baseband.len) % M17_SAMPLES_PER_SYMBOL;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue