Interesting topic! Has anyone got that CRC working? I played around it and could not get a matching CRC from telegrams posted by ulihuber.
I generated CRC calculation code with https://ghsi.de/CRC/index.php?Polyno...ssage=E100CDFE by using ITU CRC-5 polynomial. I tried tried removing bits from beginning and/or end of input data and modified the code to walk through input bits backwards without any luck of getting matching CRC.
It's easy to experiment with this code online at:
Compile and Execute C online
Any suggestions?
This code walks through input bits backwards:
Code:
// ==========================================================================
// CRC Generation Unit - Linear Feedback Shift Register implementation
// (c) Kay Gorontzi, GHSi.de, distributed under the terms of LGPL
// ==========================================================================
char *MakeCRC(char *BitString)
{
static char Res[6]; // CRC Result
char CRC[5];
int i;
char DoInvert;
for (i=0; i<5; ++i) CRC[i] = 0; // Init before calculation
// for (i=0; i<strlen(BitString); ++i)//walk forwards
for (i=strlen(BitString)-1; i>=0; i--)//walk backwards
{
DoInvert = ('1'==BitString[i]) ^ CRC[4]; // XOR required?
CRC[4] = CRC[3] ^ DoInvert;
CRC[3] = CRC[2];
CRC[2] = CRC[1] ^ DoInvert;
CRC[1] = CRC[0];
CRC[0] = DoInvert;
}
for (i=0; i<5; ++i) Res[4-i] = CRC[i] ? '1' : '0'; // Convert binary to ASCII
Res[5] = 0; // Set string terminator
return(Res);
}
// A simple test driver:
#include <stdio.h>
int main()
{
char *Data, *Result; // Declare two strings
//raw telegram: 0101001001001001110010100000000000100000000000000000100000011111000001100001111
Data = "0101001001001001110010100000000000100000000000000000100000011111000001";
//should get 10000?
Result = MakeCRC(Data); // Calculate CRC
printf("CRC of [%s] is\n [%s]\n", Data, Result);
return(0);
}