mirror of
https://github.com/g4klx/MMDVM_HS.git
synced 2025-12-06 07:02:00 +01:00
Clean up the M17 synchronisation.
This commit is contained in:
parent
4f1ed20d77
commit
2f52282c47
38
M17RX.cpp
38
M17RX.cpp
|
|
@ -25,7 +25,7 @@
|
||||||
const uint8_t MAX_SYNC_BIT_START_ERRS = 0U;
|
const uint8_t MAX_SYNC_BIT_START_ERRS = 0U;
|
||||||
const uint8_t MAX_SYNC_BIT_RUN_ERRS = 2U;
|
const uint8_t MAX_SYNC_BIT_RUN_ERRS = 2U;
|
||||||
|
|
||||||
const unsigned int MAX_SYNC_FRAMES = 5U + 1U;
|
const unsigned int MAX_SYNC_FRAMES = 3U + 1U;
|
||||||
|
|
||||||
const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
|
const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
|
||||||
|
|
||||||
|
|
@ -53,17 +53,17 @@ void CM17RX::reset()
|
||||||
void CM17RX::databit(bool bit)
|
void CM17RX::databit(bool bit)
|
||||||
{
|
{
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
case M17RXS_NONE:
|
case M17RXS_LINK_SETUP:
|
||||||
processNone(bit);
|
processLinkSetup(bit);
|
||||||
break;
|
break;
|
||||||
case M17RXS_HEADER:
|
case M17RXS_STREAM:
|
||||||
processHeader(bit);
|
processStream(bit);
|
||||||
break;
|
break;
|
||||||
case M17RXS_PACKET:
|
case M17RXS_PACKET:
|
||||||
processPacket(bit);
|
processPacket(bit);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
processStream(bit);
|
processNone(bit);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -74,15 +74,15 @@ void CM17RX::processNone(bool bit)
|
||||||
if (bit)
|
if (bit)
|
||||||
m_bitBuffer |= 0x01U;
|
m_bitBuffer |= 0x01U;
|
||||||
|
|
||||||
// Fuzzy matching of the header sync bit sequence
|
// Fuzzy matching of the link setup sync bit sequence
|
||||||
if (countBits16(m_bitBuffer ^ M17_LINK_SETUP_SYNC_BITS) <= MAX_SYNC_BIT_START_ERRS) {
|
if (countBits16(m_bitBuffer ^ M17_LINK_SETUP_SYNC_BITS) <= MAX_SYNC_BIT_START_ERRS) {
|
||||||
DEBUG1("M17RX: header sync found in None");
|
DEBUG1("M17RX: link setup sync found in None");
|
||||||
for (uint8_t i = 0U; i < M17_SYNC_BYTES_LENGTH; i++)
|
for (uint8_t i = 0U; i < M17_SYNC_BYTES_LENGTH; i++)
|
||||||
m_buffer[i] = M17_LINK_SETUP_SYNC_BYTES[i];
|
m_buffer[i] = M17_LINK_SETUP_SYNC_BYTES[i];
|
||||||
|
|
||||||
m_lostCount = MAX_SYNC_FRAMES;
|
m_lostCount = MAX_SYNC_FRAMES;
|
||||||
m_bufferPtr = M17_SYNC_LENGTH_BITS;
|
m_bufferPtr = M17_SYNC_LENGTH_BITS;
|
||||||
m_state = M17RXS_HEADER;
|
m_state = M17RXS_LINK_SETUP;
|
||||||
|
|
||||||
io.setDecode(true);
|
io.setDecode(true);
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +114,7 @@ void CM17RX::processNone(bool bit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CM17RX::processHeader(bool bit)
|
void CM17RX::processLinkSetup(bool bit)
|
||||||
{
|
{
|
||||||
m_bitBuffer <<= 1;
|
m_bitBuffer <<= 1;
|
||||||
if (bit)
|
if (bit)
|
||||||
|
|
@ -126,16 +126,6 @@ void CM17RX::processHeader(bool bit)
|
||||||
if (m_bufferPtr > M17_FRAME_LENGTH_BITS)
|
if (m_bufferPtr > M17_FRAME_LENGTH_BITS)
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
// Only search for a sync in the right place +-2 symbols
|
|
||||||
if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) {
|
|
||||||
// Fuzzy matching of the data sync bit sequence
|
|
||||||
if (countBits16(m_bitBuffer ^ M17_LINK_SETUP_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
|
|
||||||
DEBUG2("M17RX: found header sync in Data, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
|
|
||||||
m_lostCount = MAX_SYNC_FRAMES;
|
|
||||||
m_bufferPtr = M17_SYNC_LENGTH_BITS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send a data frame to the host if the required number of bits have been received
|
// Send a data frame to the host if the required number of bits have been received
|
||||||
if (m_bufferPtr == M17_FRAME_LENGTH_BITS) {
|
if (m_bufferPtr == M17_FRAME_LENGTH_BITS) {
|
||||||
m_lostCount--;
|
m_lostCount--;
|
||||||
|
|
@ -145,9 +135,7 @@ void CM17RX::processHeader(bool bit)
|
||||||
writeRSSIHeader(m_outBuffer);
|
writeRSSIHeader(m_outBuffer);
|
||||||
|
|
||||||
// Start the next frame, but we don't know the type
|
// Start the next frame, but we don't know the type
|
||||||
::memset(m_outBuffer, 0x00U, M17_FRAME_LENGTH_BYTES + 3U);
|
reset();
|
||||||
m_state = M17RXS_NONE;
|
|
||||||
m_bufferPtr = 0U;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -167,7 +155,7 @@ void CM17RX::processStream(bool bit)
|
||||||
if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) {
|
if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) {
|
||||||
// Fuzzy matching of the stream sync bit sequence
|
// Fuzzy matching of the stream sync bit sequence
|
||||||
if (countBits16(m_bitBuffer ^ M17_STREAM_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
|
if (countBits16(m_bitBuffer ^ M17_STREAM_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
|
||||||
DEBUG2("M17RX: found stream sync in Data, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
|
DEBUG2("M17RX: found stream sync, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
|
||||||
m_lostCount = MAX_SYNC_FRAMES;
|
m_lostCount = MAX_SYNC_FRAMES;
|
||||||
m_bufferPtr = M17_SYNC_LENGTH_BITS;
|
m_bufferPtr = M17_SYNC_LENGTH_BITS;
|
||||||
}
|
}
|
||||||
|
|
@ -211,7 +199,7 @@ void CM17RX::processPacket(bool bit)
|
||||||
if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) {
|
if (m_bufferPtr >= (M17_SYNC_LENGTH_BITS - 2U) && m_bufferPtr <= (M17_SYNC_LENGTH_BITS + 2U)) {
|
||||||
// Fuzzy matching of the packet sync bit sequence
|
// Fuzzy matching of the packet sync bit sequence
|
||||||
if (countBits16(m_bitBuffer ^ M17_PACKET_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
|
if (countBits16(m_bitBuffer ^ M17_PACKET_SYNC_BITS) <= MAX_SYNC_BIT_RUN_ERRS) {
|
||||||
DEBUG2("M17RX: found packet sync in Data, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
|
DEBUG2("M17RX: found packet sync, pos", m_bufferPtr - M17_SYNC_LENGTH_BITS);
|
||||||
m_lostCount = MAX_SYNC_FRAMES;
|
m_lostCount = MAX_SYNC_FRAMES;
|
||||||
m_bufferPtr = M17_SYNC_LENGTH_BITS;
|
m_bufferPtr = M17_SYNC_LENGTH_BITS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
M17RX.h
4
M17RX.h
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
enum M17RX_STATE {
|
enum M17RX_STATE {
|
||||||
M17RXS_NONE,
|
M17RXS_NONE,
|
||||||
M17RXS_HEADER,
|
M17RXS_LINK_SETUP,
|
||||||
M17RXS_STREAM,
|
M17RXS_STREAM,
|
||||||
M17RXS_PACKET
|
M17RXS_PACKET
|
||||||
};
|
};
|
||||||
|
|
@ -46,7 +46,7 @@ private:
|
||||||
uint16_t m_lostCount;
|
uint16_t m_lostCount;
|
||||||
|
|
||||||
void processNone(bool bit);
|
void processNone(bool bit);
|
||||||
void processHeader(bool bit);
|
void processLinkSetup(bool bit);
|
||||||
void processStream(bool bit);
|
void processStream(bool bit);
|
||||||
void processPacket(bool bit);
|
void processPacket(bool bit);
|
||||||
void writeRSSIHeader(uint8_t* data);
|
void writeRSSIHeader(uint8_t* data);
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#define VER_MAJOR "1"
|
#define VER_MAJOR "1"
|
||||||
#define VER_MINOR "5"
|
#define VER_MINOR "5"
|
||||||
#define VER_REV "2"
|
#define VER_REV "2"
|
||||||
#define VERSION_DATE "20210101"
|
#define VERSION_DATE "20210102"
|
||||||
|
|
||||||
#if defined(ZUMSPOT_ADF7021)
|
#if defined(ZUMSPOT_ADF7021)
|
||||||
#define BOARD_INFO "ZUMspot"
|
#define BOARD_INFO "ZUMspot"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue