Change the EOF sync pattern for simplicity.

This commit is contained in:
Jonathan Naylor
2021-08-26 16:50:18 +01:00
parent 63a8e61a45
commit 2200945857
5 changed files with 32 additions and 100 deletions
+21 -80
View File
@@ -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;