Skip to content

Commit

Permalink
Rename the CRC4 functions correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Mar 26, 2021
1 parent 0a94b0d commit 8efd771
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions M17CRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ uint16_t CM17CRC::createCRC16(const unsigned char* in, unsigned int nBytes)
return crc;
}

bool CM17CRC::checkCRC8(unsigned char* in, unsigned int nBytes)
bool CM17CRC::checkCRC4(unsigned char* in, unsigned int nBytes)
{
assert(in != NULL);
assert(nBytes > 1U);
Expand All @@ -111,27 +111,27 @@ bool CM17CRC::checkCRC8(unsigned char* in, unsigned int nBytes)
// Mask out the 4-bit CRC location
in[nBytes - 1U] &= 0xF0U;

uint8_t crc = createCRC8(in, nBytes);
uint8_t crc = createCRC4(in, nBytes);

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

return save == crc;
}

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

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

uint8_t crc = createCRC8(in, nBytes);
uint8_t crc = createCRC4(in, nBytes);

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

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

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

static bool checkCRC8(unsigned char* in, unsigned int nBytes);
static void encodeCRC8(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 createCRC8(const unsigned char* in, unsigned int nBytes);
static uint8_t createCRC4(const unsigned char* in, unsigned int nBytes);
};

#endif
6 changes: 3 additions & 3 deletions M17Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ 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::checkCRC8(lich, M17_LICH_FRAGMENT_LENGTH_BYTES))
if (!CM17CRC::checkCRC4(lich, M17_LICH_FRAGMENT_LENGTH_BYTES))
return false;

m_rfLSFn = (lich4 >> 5) & 0x07U;
Expand Down Expand Up @@ -301,7 +301,7 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
lich[5U] = (m_rfLSFn & 0x07U) << 5;

// Add the CRC
CM17CRC::encodeCRC8(lich, M17_LICH_FRAGMENT_LENGTH_BYTES);
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 @@ -523,7 +523,7 @@ void CM17Control::writeNetwork()
lich[5U] = (m_netLSFn & 0x07U) << 5;

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

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

0 comments on commit 8efd771

Please sign in to comment.