mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-23 08:45:48 +08:00
Rename the CRC4 functions correctly.
This commit is contained in:
10
M17CRC.cpp
10
M17CRC.cpp
@@ -101,7 +101,7 @@ uint16_t CM17CRC::createCRC16(const unsigned char* in, unsigned int nBytes)
|
|||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CM17CRC::checkCRC8(unsigned char* in, unsigned int nBytes)
|
bool CM17CRC::checkCRC4(unsigned char* in, unsigned int nBytes)
|
||||||
{
|
{
|
||||||
assert(in != NULL);
|
assert(in != NULL);
|
||||||
assert(nBytes > 1U);
|
assert(nBytes > 1U);
|
||||||
@@ -111,7 +111,7 @@ bool CM17CRC::checkCRC8(unsigned char* in, unsigned int nBytes)
|
|||||||
// Mask out the 4-bit CRC location
|
// Mask out the 4-bit CRC location
|
||||||
in[nBytes - 1U] &= 0xF0U;
|
in[nBytes - 1U] &= 0xF0U;
|
||||||
|
|
||||||
uint8_t crc = createCRC8(in, nBytes);
|
uint8_t crc = createCRC4(in, nBytes);
|
||||||
|
|
||||||
// Restore the original CRC
|
// Restore the original CRC
|
||||||
in[nBytes - 1U] |= save;
|
in[nBytes - 1U] |= save;
|
||||||
@@ -119,19 +119,19 @@ bool CM17CRC::checkCRC8(unsigned char* in, unsigned int nBytes)
|
|||||||
return save == crc;
|
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(in != NULL);
|
||||||
assert(nBytes > 1U);
|
assert(nBytes > 1U);
|
||||||
|
|
||||||
in[nBytes - 1U] &= 0xF0U;
|
in[nBytes - 1U] &= 0xF0U;
|
||||||
|
|
||||||
uint8_t crc = createCRC8(in, nBytes);
|
uint8_t crc = createCRC4(in, nBytes);
|
||||||
|
|
||||||
in[nBytes - 1U] |= crc & 0x0FU;
|
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);
|
assert(in != NULL);
|
||||||
|
|
||||||
|
|||||||
6
M17CRC.h
6
M17CRC.h
@@ -27,12 +27,12 @@ public:
|
|||||||
static bool checkCRC16(const unsigned char* in, unsigned int nBytes);
|
static bool checkCRC16(const unsigned char* in, unsigned int nBytes);
|
||||||
static void encodeCRC16(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 bool checkCRC4(unsigned char* in, unsigned int nBytes);
|
||||||
static void encodeCRC8(unsigned char* in, unsigned int nBytes);
|
static void encodeCRC4(unsigned char* in, unsigned int nBytes);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uint16_t createCRC16(const unsigned char* in, unsigned int nBytes);
|
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
|
#endif
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
|
|||||||
unsigned char lich[M17_LICH_FRAGMENT_LENGTH_BYTES];
|
unsigned char lich[M17_LICH_FRAGMENT_LENGTH_BYTES];
|
||||||
CM17Utils::combineFragmentLICH(lich1, lich2, lich3, lich4, lich);
|
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;
|
return false;
|
||||||
|
|
||||||
m_rfLSFn = (lich4 >> 5) & 0x07U;
|
m_rfLSFn = (lich4 >> 5) & 0x07U;
|
||||||
@@ -301,7 +301,7 @@ bool CM17Control::writeModem(unsigned char* data, unsigned int len)
|
|||||||
lich[5U] = (m_rfLSFn & 0x07U) << 5;
|
lich[5U] = (m_rfLSFn & 0x07U) << 5;
|
||||||
|
|
||||||
// Add the CRC
|
// 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;
|
unsigned int frag1, frag2, frag3, frag4;
|
||||||
CM17Utils::splitFragmentLICH(lich, frag1, frag2, frag3, frag4);
|
CM17Utils::splitFragmentLICH(lich, frag1, frag2, frag3, frag4);
|
||||||
@@ -523,7 +523,7 @@ void CM17Control::writeNetwork()
|
|||||||
lich[5U] = (m_netLSFn & 0x07U) << 5;
|
lich[5U] = (m_netLSFn & 0x07U) << 5;
|
||||||
|
|
||||||
// Add the CRC
|
// 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;
|
unsigned int frag1, frag2, frag3, frag4;
|
||||||
CM17Utils::splitFragmentLICH(lich, frag1, frag2, frag3, frag4);
|
CM17Utils::splitFragmentLICH(lich, frag1, frag2, frag3, frag4);
|
||||||
|
|||||||
Reference in New Issue
Block a user