Hi!
I have a big problem because I have a heat device and I wan't to know how it generate CRC checksum.
data send/retrieve by this device are as below:
The last byte is a CRC.
7 0 0 0 105 1 51 ; CRC=51
4 0 0 16 ; CRC=16
7 2 0 0 0 4 196
8 0 0 151 4 11 2 234
7 0 0 0 108 1 57
4 0 11 27
7 0 0 0 100 1 41
4 0 5 21
7 0 0 0 33 1 163
4 0 2 18
7 0 0 0 22 3 207
6 0 2 228 0 185
7 0 0 0 23 3 205
6 0 2 228 0 185
7 0 0 0 23 3 205
6 0 2 241 0 147
7 0 0 0 25 2 208
5 0 4 176 144
7 0 0 0 1 2 224
5 0 2 249 213
7 0 0 0 4 2 234
5 0 3 44 2
7 0 0 0 14 1 253
where first byte signs that sequence has x bytes lenght. Maximum bytes lenght is 8 and minimum is 4.
I have asm code of this exe driver but there's no comment and almost 10 MB so I'll put it on my desk!
The last byte is a CRC, I almost quess how this CRC is calculated because:
for eq.:
7 0 0 0 105 1 51 : so the CRC is 51
Hi sergiusz_m,
> And here I don't know how these values where xor is greather than 255
> are generated
CRC-8 only uses the lowest 8 bits, so use in your matlab notation
crc=bitand(crc,255)
In ASM you achieve the same just by storing your result as a byte, or by using the "and" instruction.
Cheers,
Stefan
0
sergiusz_mAuthor Commented:
I know about it but I'm not asking about it!
look at this example:
8 0 0 151 4 11 2 234
so I use 6 steps:
1. 2*8^0=16
2. 2*16^0=32
3. 2*32^151=215 ; a.... ant there is problem because 2*215=430 >255
and now I'd like to know how to go to 234?? So what next in steep 4,5,6????
4. sth ^4= sth2 ; and now if 2*sth2^4 <255 in step 5 use 2*sth2^11 and etc..
5.
6.
there are others examples that makes xor >255:
6 0 2 228 0 185
6 0 2 241 0 147
7 0 0 0 158 1 196
for example:
7 0 0 0 158 1 196
five steps:
1.2*7^0=14
2.2*14^0=28
3.2*28^0=56
4.2*56^158=238 ; and 2*238>255 but 196 xor 1=197 so I can quess 197 in step 5
5. 197 ^1=196
but how to go to 197 ?????? xor table or what????
So the control querende would be if ( (2*a^b) &128 !=0) ....... and what here????
The solution could be also in C/C++/Java not only in matlab.
Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)
twobitadder that's OK but I have my own case described below, so don't write how to write crc in C or how CRC works when I know nothing about used polyval in this chesksum and about behaviour when xor > 255. I've spend hours sitting on it and I don't know what is "played" where xor >255 - the solution for it is my problem solution!!!!!! I only know (alghoritm in matlab see below) what if xor is lower than 255 so 50% of alghoritm.
I think I understand this CRC, but check me, because I may be wrong.
If your current (CRC & 0x80) == 0x80 (it means that next shift will be > 255) then you need to XOR it with 0x19.
Take a look at the code:
sergiusz_m,
Byte overflows are ignored. If you look at Dimitry's code, you'll see that all intermediate values are casted to unsigned char in the updcrc macro. That's very much like doing "& 0xff".
In other words: You just use the lower 8 bits and discard all others.
Stefan
0
sergiusz_mAuthor Commented:
Thanks for All
Dimitry you are genious, yes it works llike that
A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.
> And here I don't know how these values where xor is greather than 255
> are generated
CRC-8 only uses the lowest 8 bits, so use in your matlab notation
crc=bitand(crc,255)
In ASM you achieve the same just by storing your result as a byte, or by using the "and" instruction.
Cheers,
Stefan