ELC2 CRC check, čištění
This commit is contained in:
@@ -338,6 +338,33 @@ void appendStringToVector(const std::string &str, std::vector<unsigned char> &ch
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t calculateCRC16(std::vector<char> &charVector)
|
||||
{
|
||||
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
|
||||
uint16_t crc = 0xFFFF; // Initial value
|
||||
|
||||
size_t length = charVector.size();
|
||||
|
||||
for (size_t i = 0; i < length; i++)
|
||||
{
|
||||
crc ^= charVector[i]; // XOR with the current data byte
|
||||
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
if (crc & 0x0001)
|
||||
{
|
||||
crc = (crc >> 1) ^ polynomial;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc = crc >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint16_t calculateCRC16(std::vector<unsigned char> &charVector)
|
||||
{
|
||||
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
|
||||
@@ -365,6 +392,34 @@ uint16_t calculateCRC16(std::vector<unsigned char> &charVector)
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint16_t calculateCRC16(std::vector<unsigned char> &charVector, int removeCount)
|
||||
{
|
||||
const uint16_t polynomial = 0xA001; // CRC16-CCITT polynomial
|
||||
uint16_t crc = 0xFFFF; // Initial value
|
||||
|
||||
size_t length = charVector.size();
|
||||
length = length-removeCount;
|
||||
|
||||
for (size_t i = 0; i < length; i++)
|
||||
{
|
||||
crc ^= charVector[i]; // XOR with the current data byte
|
||||
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
if (crc & 0x0001)
|
||||
{
|
||||
crc = (crc >> 1) ^ polynomial;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc = crc >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
|
||||
{
|
||||
return static_cast<uint32_t>(byte1) |
|
||||
|
||||
Reference in New Issue
Block a user