This commit is contained in:
2024-06-14 11:54:43 +02:00
parent 4e783ee6fd
commit bc00d25ded
5 changed files with 116 additions and 138 deletions
+6 -34
View File
@@ -43,28 +43,9 @@ namespace TU {
return htobe16(((j / 10) + 0x30) << 8) | ((j % 10) + 0x30);
}
//https://lxp32.github.io/docs/a-simple-example-crc32-calculation/
uint32_t crc32(const char *s, size_t n) {
uint32_t crc=0xFFFFFFFF;
uint32_t crc32(uint32_t crc, unsigned char* pData, size_t len) {
for(size_t i=0;i<n;i++) {
char ch=s[i];
for(size_t j=0;j<8;j++) {
uint32_t b=(ch^crc)&1;
crc>>=1;
if(b) crc=crc^0xEDB88320;
ch>>=1;
}
}
return ~crc;
}
uint32_t CRC32(uint32_t crc, unsigned char* pData, size_t len) {
QByteArray a((char *)pData, len);
qCritical() << "updateCRC" << a.toHex(' ');
qCritical() << "updateCRC" << QByteArray((char *)pData, len).toHex();
int i = 0;
int j = 0;
@@ -72,7 +53,8 @@ namespace TU {
crc = ~crc;
while (len > 0) {
crc ^= (uint32_t) pData[i];
uint32_t const c = pData[i];
crc ^= c;
++i;
for (j = 0; j < 8; ++j) {
@@ -91,18 +73,8 @@ namespace TU {
}
uint32_t crc32(QByteArray const &ba) {
uint32_t crc = 0x00000000;
unsigned char posIDLength = ba[0];
crc = CRC32(crc, &posIDLength, 1);
unsigned char *posID = (unsigned char *)ba.mid(1, 16).data();
crc = CRC32(crc, posID, 16);
unsigned char *rest = (unsigned char *)ba.mid(16).data();
crc = CRC32(crc, rest, ba.size()-16);
return crc;
uint32_t crc = 0;
return crc32(crc, (uint8_t *)ba.data(), ba.size());
}
char lrc(QByteArray const &ba) {