Skip to content

Commit

Permalink
Remove the CRC4 processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Mar 28, 2021
1 parent 6ac672e commit 389bd3b
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 74 deletions.
60 changes: 0 additions & 60 deletions M17CRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ const uint16_t CRC16_TABLE[] = {0x0000U, 0x5935U, 0xB26AU, 0xEB5FU, 0x3DE1U, 0x6
0xAC02U, 0xF537U, 0x2389U, 0x7ABCU, 0x91E3U, 0xC8D6U, 0x65AAU, 0x3C9FU, 0xD7C0U, 0x8EF5U, 0x584BU,
0x017EU, 0xEA21U, 0xB314U};

const uint8_t CRC4_TABLE[] = {
0x0, 0x7, 0xe, 0x9, 0x5, 0x2, 0xb, 0xc, 0xa, 0xd, 0x4, 0x3, 0xf, 0x8, 0x1, 0x6,
0xd, 0xa, 0x3, 0x4, 0x8, 0xf, 0x6, 0x1, 0x7, 0x0, 0x9, 0xe, 0x2, 0x5, 0xc, 0xb,
0x3, 0x4, 0xd, 0xa, 0x6, 0x1, 0x8, 0xf, 0x9, 0xe, 0x7, 0x0, 0xc, 0xb, 0x2, 0x5,
0xe, 0x9, 0x0, 0x7, 0xb, 0xc, 0x5, 0x2, 0x4, 0x3, 0xa, 0xd, 0x1, 0x6, 0xf, 0x8,
0x6, 0x1, 0x8, 0xf, 0x3, 0x4, 0xd, 0xa, 0xc, 0xb, 0x2, 0x5, 0x9, 0xe, 0x7, 0x0,
0xb, 0xc, 0x5, 0x2, 0xe, 0x9, 0x0, 0x7, 0x1, 0x6, 0xf, 0x8, 0x4, 0x3, 0xa, 0xd,
0x5, 0x2, 0xb, 0xc, 0x0, 0x7, 0xe, 0x9, 0xf, 0x8, 0x1, 0x6, 0xa, 0xd, 0x4, 0x3,
0x8, 0xf, 0x6, 0x1, 0xd, 0xa, 0x3, 0x4, 0x2, 0x5, 0xc, 0xb, 0x7, 0x0, 0x9, 0xe,
0xc, 0xb, 0x2, 0x5, 0x9, 0xe, 0x7, 0x0, 0x6, 0x1, 0x8, 0xf, 0x3, 0x4, 0xd, 0xa,
0x1, 0x6, 0xf, 0x8, 0x4, 0x3, 0xa, 0xd, 0xb, 0xc, 0x5, 0x2, 0xe, 0x9, 0x0, 0x7,
0xf, 0x8, 0x1, 0x6, 0xa, 0xd, 0x4, 0x3, 0x5, 0x2, 0xb, 0xc, 0x0, 0x7, 0xe, 0x9,
0x2, 0x5, 0xc, 0xb, 0x7, 0x0, 0x9, 0xe, 0x8, 0xf, 0x6, 0x1, 0xd, 0xa, 0x3, 0x4,
0xa, 0xd, 0x4, 0x3, 0xf, 0x8, 0x1, 0x6, 0x0, 0x7, 0xe, 0x9, 0x5, 0x2, 0xb, 0xc,
0x7, 0x0, 0x9, 0xe, 0x2, 0x5, 0xc, 0xb, 0xd, 0xa, 0x3, 0x4, 0x8, 0xf, 0x6, 0x1,
0x9, 0xe, 0x7, 0x0, 0xc, 0xb, 0x2, 0x5, 0x3, 0x4, 0xd, 0xa, 0x6, 0x1, 0x8, 0xf,
0x4, 0x3, 0xa, 0xd, 0x1, 0x6, 0xf, 0x8, 0xe, 0x9, 0x0, 0x7, 0xb, 0xc, 0x5, 0x2};

bool CM17CRC::checkCRC16(const unsigned char* in, unsigned int nBytes)
{
assert(in != NULL);
Expand Down Expand Up @@ -100,45 +82,3 @@ uint16_t CM17CRC::createCRC16(const unsigned char* in, unsigned int nBytes)

return crc;
}

bool CM17CRC::checkCRC4(unsigned char* in, unsigned int nBytes)
{
assert(in != NULL);
assert(nBytes > 1U);

uint8_t save = in[nBytes - 1U] & 0x0FU;

// Mask out the 4-bit CRC location
in[nBytes - 1U] &= 0xF0U;

uint8_t crc = createCRC4(in, nBytes);

// Restore the original CRC
in[nBytes - 1U] |= save;

return save == crc;
}

void CM17CRC::encodeCRC4(unsigned char* in, unsigned int nBytes)
{
assert(in != NULL);
assert(nBytes > 1U);

in[nBytes - 1U] &= 0xF0U;

uint8_t crc = createCRC4(in, nBytes);

in[nBytes - 1U] |= crc & 0x0FU;
}

uint8_t CM17CRC::createCRC4(const unsigned char* in, unsigned int nBytes)
{
assert(in != NULL);

uint8_t crc = 0x0FU;

for (unsigned int i = 0U; i < nBytes; i++)
crc = CRC4_TABLE[crc ^ in[i]];

return crc;
}
4 changes: 0 additions & 4 deletions M17CRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ class CM17CRC
static bool checkCRC16(const unsigned char* in, unsigned int nBytes);
static void encodeCRC16(unsigned char* in, unsigned int nBytes);

static bool checkCRC4(unsigned char* in, unsigned int nBytes);
static void encodeCRC4(unsigned char* in, unsigned int nBytes);

private:
static uint16_t createCRC16(const unsigned char* in, unsigned int nBytes);
static uint8_t createCRC4(const unsigned char* in, unsigned int nBytes);
};

#endif
9 changes: 0 additions & 9 deletions M17Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
unsigned char lich[M17_LICH_FRAGMENT_LENGTH_BYTES];
CM17Utils::combineFragmentLICH(lich1, lich2, lich3, lich4, lich);

// if (!CM17CRC::checkCRC4(lich, M17_LICH_FRAGMENT_LENGTH_BYTES))
// return false;

m_rfLSFn = (lich4 >> 5) & 0x07U;
m_rfLSF.setFragment(lich, m_rfLSFn);

Expand Down Expand Up @@ -286,9 +283,6 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
// Add the fragment number
lich[5U] = (m_rfLSFn & 0x07U) << 5;

// Add the CRC
// CM17CRC::encodeCRC4(lich, M17_LICH_FRAGMENT_LENGTH_BYTES);

unsigned int frag1, frag2, frag3, frag4;
CM17Utils::splitFragmentLICH(lich, frag1, frag2, frag3, frag4);

Expand Down Expand Up @@ -508,9 +502,6 @@ void CM17Control::writeNetwork()
// Add the fragment number
lich[5U] = (m_netLSFn & 0x07U) << 5;

// Add the CRC
// CM17CRC::encodeCRC4(lich, M17_LICH_FRAGMENT_LENGTH_BYTES);

unsigned int frag1, frag2, frag3, frag4;
CM17Utils::splitFragmentLICH(lich, frag1, frag2, frag3, frag4);

Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H

const char* VERSION = "20210327";
const char* VERSION = "20210328";

#endif

0 comments on commit 389bd3b

Please sign in to comment.