Remove the CRC4 processing.

This commit is contained in:
Jonathan Naylor 2021-03-28 15:29:26 +01:00
parent 6ac672e106
commit 389bd3b928
4 changed files with 1 additions and 74 deletions

View File

@ -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);
@ -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;
}

View File

@ -27,12 +27,8 @@ public:
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

View File

@ -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);
@ -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);
@ -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);

View File

@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H
const char* VERSION = "20210327";
const char* VERSION = "20210328";
#endif