From 8efd77132f6c77f5484ee70e4f63f5bde3fea716 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Fri, 26 Mar 2021 22:45:33 +0000 Subject: [PATCH] Rename the CRC4 functions correctly. --- M17CRC.cpp | 10 +++++----- M17CRC.h | 6 +++--- M17Control.cpp | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/M17CRC.cpp b/M17CRC.cpp index 695511ef..1fd42f07 100644 --- a/M17CRC.cpp +++ b/M17CRC.cpp @@ -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); @@ -111,7 +111,7 @@ 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; @@ -119,19 +119,19 @@ bool CM17CRC::checkCRC8(unsigned char* in, unsigned int nBytes) 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); diff --git a/M17CRC.h b/M17CRC.h index 5bc33bb3..a1cfa53a 100644 --- a/M17CRC.h +++ b/M17CRC.h @@ -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 diff --git a/M17Control.cpp b/M17Control.cpp index 10238ce2..070ccfd1 100644 --- a/M17Control.cpp +++ b/M17Control.cpp @@ -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; @@ -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); @@ -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);