Skip to content

Commit

Permalink
NXDN: tolerate 1 symbol error on sync sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Jul 24, 2020
1 parent 2a314fb commit 565a6c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions dsd_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <stdlib.h>
#include <assert.h>
#include <algorithm>
#include "timeutil.h"
#include "dsd_decoder.h"

Expand Down Expand Up @@ -666,6 +667,7 @@ int DSDDecoder::getFrameSync()
else // Sync identification starts here
{
m_dmrBurstType = DSDDMR::DSDDMRBurstNone;
unsigned char tmp[64];

if (m_opts.frame_p25p1 == 1)
{
Expand Down Expand Up @@ -922,7 +924,7 @@ int DSDDecoder::getFrameSync()
}
if ((m_opts.frame_nxdn96 == 1) || (m_opts.frame_nxdn48 == 1))
{
if (memcmp(m_dsdSymbol.getSyncDibitBack(19), m_syncNXDNRDCHFull, 19) == 0) // long sync (with preamble)
if (countDiff(m_dsdSymbol.getSyncDibitBack(19), m_syncNXDNRDCHFull, tmp, 19) <= 1) // long sync (with preamble)
{
m_nxdnInterSyncCount = 0;
m_state.carrier = 1;
Expand Down Expand Up @@ -951,7 +953,7 @@ int DSDDecoder::getFrameSync()
m_mbeRate = DSDMBERate3600x2450;
return (int) DSDSyncNXDNP; // done
}
else if (memcmp(m_dsdSymbol.getSyncDibitBack(19), m_syncNXDNRDCHFullInv, 19) == 0) // long sync (with preamble) inverted
else if (countDiff(m_dsdSymbol.getSyncDibitBack(19), m_syncNXDNRDCHFullInv, tmp, 19) <= 1) // long sync (with preamble) inverted
{
m_nxdnInterSyncCount = 0;
m_state.carrier = 1;
Expand Down Expand Up @@ -980,7 +982,7 @@ int DSDDecoder::getFrameSync()
m_mbeRate = DSDMBERate3600x2450;
return (int) DSDSyncNXDNN; // done
}
else if (memcmp(m_dsdSymbol.getSyncDibitBack(10), m_syncNXDNRDCHFSW, 10) == 0) // short sync
else if (countDiff(m_dsdSymbol.getSyncDibitBack(10), m_syncNXDNRDCHFSW, tmp, 10) <= 1) // short sync
{
if ((m_nxdnInterSyncCount > 0) && (m_nxdnInterSyncCount % 192 == 0))
{
Expand Down Expand Up @@ -1014,7 +1016,7 @@ int DSDDecoder::getFrameSync()
m_nxdnInterSyncCount = 0;
}
}
else if (memcmp(m_dsdSymbol.getSyncDibitBack(10), m_syncNXDNRDCHFSWInv, 10) == 0) // short sync inverted
else if (countDiff(m_dsdSymbol.getSyncDibitBack(10), m_syncNXDNRDCHFSWInv, tmp, 10) <= 1) // short sync inverted
{
if ((m_nxdnInterSyncCount > 0) && (m_nxdnInterSyncCount % 192 == 0))
{
Expand Down Expand Up @@ -1468,4 +1470,10 @@ int DSDDecoder::comp(const void *a, const void *b)
return 1;
}

int DSDDecoder::countDiff(const unsigned char *a, const unsigned char *b, unsigned char *t, unsigned int len)
{
std::transform(a, a + len, b, t, std::bit_xor<unsigned char>());
return std::count_if(t, t + len, [](unsigned char& c) { return c != 0; });
}

} // namespace dsdcc
1 change: 1 addition & 0 deletions dsd_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class DSDCC_API DSDDecoder
void printFrameInfo();
void processFrameInit();
static int comp(const void *a, const void *b);
static int countDiff(const unsigned char *a, const unsigned char *b, unsigned char *t, unsigned int len);

DSDOpts m_opts;
DSDState m_state;
Expand Down

0 comments on commit 565a6c7

Please sign in to comment.