I have a variable which contains 32 bytes or 28 hexadecimal Values: The variable is defined like the following:
unsigned char cAll_Data[200] = {0};
And has got the following value inside by compiling the code:
3074F701CC0D90C000000A6A3030303000000000313030303030303000010484
Since I would like to calculate the CRC checksum of the value of this variable, the variable cAll_Data should have only 32 Bytes for each byte spot as the following:
30 74 F7 01 CC 0D 90 C0 00 00 0A 6A 30 30 30 30 00 00 00 00 31 30 30
30 30 30 30 30 00 01 04 84
But the problem is that each one digit is considered as 1 byte which results at the end 64 Bytes.
Is there any way how to put each two digets instead of one in a variable of 32 bytes?
The code has mainly the function call and the definition of the variable, so I only need how to put these data in a 32 bytes variable. Edit: Since I am working with ANSI C, here is the part of the code that contains the informations abotu the variables:
char x_Result_B0 [10] = {0};
char x_Result_B1 [10] = {0};
char x_Result_B2 [10] = {0};
char x_Result_B3 [10] = {0};
char x_Result_B4 [10] = {0};
char x_Result_B5 [10] = {0};
char x_Result_B6 [10] = {0};
char x_Result_B7 [10] = {0};
char x_Result_B8 [10] = {0};
Fmt(cWrite_All_Data,"%s<%s%s%s%s%s%s%s%s",Block0,Block1,Block2,Block3,Block4,Block5,Block6,Block7);
and each Block contains the 4 Hex values, e. g.:
Block0 = 3074F701 00 01 04 84
Block1 = CC0D90C0
Block2 = 00000A6A
Block3 = 30303030
Block4 = 00000000
Block5 = 31303030
Block6 = 00010484
Block7 = 00010484
// and the CRC function looks like the following:
void Daten_calculate_crc (unsigned char cWrite_All_Data, const char *ucCRC_MSB, const char *ucCRC_LSB)
{
unsigned char ucCRC_H = {0};
unsigned char ucCRC_L = {0};
const char cDummy [5] = {0};
unsigned char x = 0;
unsigned int uiCRC = 0x0000; // Initial value for CRC
int iNumberofBytes= 64;
while (iNumberofBytes>0)
{
uiCRC ^= ucBuffer[x];
for (int iBit=0;iBit<16;iBit++)
{
if (uiCRC&1)
uiCRC = (uiCRC >> 1) ^ 0xA001; // Polynomial
else
uiCRC>>=1;
}
iNumberofBytes--;
x++;
}
ucCRC_H = (uiCRC>>16)&0xFF; // CRC in MSB und LSB
ucCRC_L = uiCRC&0xFF;
ucCRC_H = ucCRC_H^0xFF; // Final Xor- with FF for LSB and MSB
ucCRC_L = ucCRC_L^0xFF;
Fmt(ucCRC_MSB,"%s<%x",ucCRC_L); // HEX-values
Fmt(ucCRC_LSB,"%s<%x",ucCRC_H);
strcpy(cDummy,ucCRC_MSB);
if (StringLength(ucCRC_MSB) == 1)
Fmt(ucCRC_MSB, "%s<%s%s","0",cDummy);
strcpy(cDummy,ucCRC_LSB);
if (StringLength(ucCRC_LSB) == 1)
Fmt(ucCRC_LSB, "%s<%s%s","0",cDummy);
StringUpperCase (ucCRC_MSB);
StringUpperCase (ucCRC_LSB);
}
I changed the number of bytes from 32 to 64 to match with the Byte numbers that the variable has. But when I double check the CRC result (which are ucCRC_MSB and ucCRC_LSB). with the following website: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html I get other CRC-result numbers. This is the actual problem. Thanks a lot in advance for the help.. Note: The CRC-16 Type is Maxim. But with another polynomial value in the code (0xA001), but in the website the maxim type is used.