Add G4KLX (MMDVM firmware) improvement for "transmission lost" in D-Star

AX5043
Andy CA6JAU 8 years ago
parent 4d66c27885
commit 4bfae22ef0

@ -22,11 +22,7 @@
#include "DStarRX.h" #include "DStarRX.h"
#include "Utils.h" #include "Utils.h"
const unsigned int MAX_SYNC_BITS = 50U * DSTAR_DATA_LENGTH_BITS; const unsigned int MAX_SYNC_BITS = 100U * DSTAR_DATA_LENGTH_BITS;
const unsigned int SYNC_POS = 21U * DSTAR_DATA_LENGTH_BITS;
const unsigned int SYNC_SCAN_START = SYNC_POS - 3U;
const unsigned int SYNC_SCAN_END = SYNC_POS + 3U;
// D-Star preamble sequence (only 32 bits of 101010...) // D-Star preamble sequence (only 32 bits of 101010...)
const uint32_t PREAMBLE_MASK = 0xFFFFFFFFU; const uint32_t PREAMBLE_MASK = 0xFFFFFFFFU;
@ -41,7 +37,7 @@ const uint8_t FRAME_SYNC_ERRS = 2U;
// D-Star bit order version of 0x55 0x2D 0x16 // D-Star bit order version of 0x55 0x2D 0x16
const uint32_t DATA_SYNC_DATA = 0x00AAB468U; const uint32_t DATA_SYNC_DATA = 0x00AAB468U;
const uint32_t DATA_SYNC_MASK = 0x00FFFFFFU; const uint32_t DATA_SYNC_MASK = 0x00FFFFFFU;
const uint8_t DATA_SYNC_ERRS = 2U; const uint8_t DATA_SYNC_ERRS = 3U;
// D-Star bit order version of 0x55 0x55 0xC8 0x7A // D-Star bit order version of 0x55 0x55 0xC8 0x7A
const uint32_t END_SYNC_DATA = 0xAAAA135EU; const uint32_t END_SYNC_DATA = 0xAAAA135EU;
@ -321,7 +317,7 @@ void CDStarRX::processNone(bool bit)
::memset(m_rxBuffer, 0x00U, DSTAR_DATA_LENGTH_BYTES + 2U); ::memset(m_rxBuffer, 0x00U, DSTAR_DATA_LENGTH_BYTES + 2U);
m_rxBufferBits = 0U; m_rxBufferBits = 0U;
m_dataBits = 0U; m_dataBits = MAX_SYNC_BITS;
m_rxState = DSRXS_DATA; m_rxState = DSRXS_DATA;
return; return;
} }
@ -344,13 +340,13 @@ void CDStarRX::processHeader(bool bit)
if (ok) { if (ok) {
io.setDecode(true); io.setDecode(true);
serial.writeDStarHeader(header, DSTAR_HEADER_LENGTH_BYTES); writeRSSIHeader(header);
::memset(m_rxBuffer, 0x00U, DSTAR_DATA_LENGTH_BYTES + 2U); ::memset(m_rxBuffer, 0x00U, DSTAR_DATA_LENGTH_BYTES + 2U);
m_rxBufferBits = 0U; m_rxBufferBits = 0U;
m_rxState = DSRXS_DATA; m_rxState = DSRXS_DATA;
m_dataBits = SYNC_POS - DSTAR_DATA_LENGTH_BITS + 1U; m_dataBits = MAX_SYNC_BITS;
} else { } else {
// The checksum failed, return to looking for syncs // The checksum failed, return to looking for syncs
m_rxState = DSRXS_NONE; m_rxState = DSRXS_NONE;
@ -380,39 +376,30 @@ void CDStarRX::processData(bool bit)
// Fuzzy matching of the data sync bit sequence // Fuzzy matching of the data sync bit sequence
bool syncSeen = false; bool syncSeen = false;
if (m_dataBits >= SYNC_SCAN_START && m_dataBits <= (SYNC_POS + 1U)) { if (m_rxBufferBits >= (DSTAR_DATA_LENGTH_BITS - 3U)) {
if (countBits32((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) <= DATA_SYNC_ERRS) { if (countBits32((m_patternBuffer & DATA_SYNC_MASK) ^ DATA_SYNC_DATA) <= DATA_SYNC_ERRS) {
if (m_dataBits < SYNC_POS) {
DEBUG2("DStarRX: found data sync in Data, early", SYNC_POS - m_dataBits);
}
else {
DEBUG1("DStarRX: found data sync in Data");
}
m_rxBufferBits = DSTAR_DATA_LENGTH_BITS; m_rxBufferBits = DSTAR_DATA_LENGTH_BITS;
m_dataBits = 0U; m_dataBits = MAX_SYNC_BITS;
syncSeen = true; syncSeen = true;
} }
} }
// Check to see if the sync is arriving late // Check to see if the sync is arriving late
if (m_dataBits == SYNC_POS) { if (m_rxBufferBits == DSTAR_DATA_LENGTH_BITS && !syncSeen) {
for (uint8_t i = 1U; i <= 3U; i++) { for (uint8_t i = 1U; i <= 3U; i++) {
uint32_t syncMask = DATA_SYNC_MASK >> i; uint32_t syncMask = DATA_SYNC_MASK >> i;
uint32_t syncData = DATA_SYNC_DATA >> i; uint32_t syncData = DATA_SYNC_DATA >> i;
if (countBits32((m_patternBuffer & syncMask) ^ syncData) <= DATA_SYNC_ERRS) { if (countBits32((m_patternBuffer & syncMask) ^ syncData) <= DATA_SYNC_ERRS) {
DEBUG2("DStarRX: found data sync in Data, late", i);
m_rxBufferBits -= i; m_rxBufferBits -= i;
m_dataBits -= i;
break; break;
} }
} }
} }
m_dataBits++; m_dataBits--;
// We've not seen a data sync for too long, signal RXLOST and change to RX_NONE // We've not seen a data sync for too long, signal RXLOST and change to RX_NONE
if (m_dataBits >= MAX_SYNC_BITS) { if (m_dataBits == 0U) {
DEBUG1("DStarRX: data sync timed out, lost lock"); DEBUG1("DStarRX: data sync timed out, lost lock");
io.setDecode(false); io.setDecode(false);
@ -656,6 +643,20 @@ bool CDStarRX::checksum(const uint8_t* header) const
return crc8[0U] == header[DSTAR_HEADER_LENGTH_BYTES - 2U] && crc8[1U] == header[DSTAR_HEADER_LENGTH_BYTES - 1U]; return crc8[0U] == header[DSTAR_HEADER_LENGTH_BYTES - 2U] && crc8[1U] == header[DSTAR_HEADER_LENGTH_BYTES - 1U];
} }
void CDStarRX::writeRSSIHeader(unsigned char* header)
{
#if defined(SEND_RSSI_DATA)
uint16_t rssi = io.readRSSI();
header[41U] = (rssi >> 8) & 0xFFU;
header[42U] = (rssi >> 0) & 0xFFU;
serial.writeDStarHeader(header, DSTAR_HEADER_LENGTH_BYTES + 2U);
#else
serial.writeDStarHeader(header, DSTAR_HEADER_LENGTH_BYTES + 0U);
#endif
}
void CDStarRX::writeRSSIData(unsigned char* data) void CDStarRX::writeRSSIData(unsigned char* data)
{ {
#if defined(SEND_RSSI_DATA) #if defined(SEND_RSSI_DATA)

@ -58,6 +58,7 @@ private:
void viterbiDecode(int* data); void viterbiDecode(int* data);
void traceBack(); void traceBack();
bool checksum(const uint8_t* header) const; bool checksum(const uint8_t* header) const;
void writeRSSIHeader(unsigned char* header);
void writeRSSIData(unsigned char* data); void writeRSSIData(unsigned char* data);
}; };

Loading…
Cancel
Save

Powered by TurnKey Linux.