Author |
Message |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Fri Sep 24, 2010 5:29 pm Post subject: Crc32 |
 |
|
|
|
I implemented a CRC32 algorythm in both LabVIEW and a Fanuc industrial robot so files sent from the computer to the robot can be checked for errors.
The CRC value for a file is correct; it gives the same value as, say, WinRAR.
But....
I read everywhere about this, but somehow I can't get it to work:
If I append 32 0 bits ((u32)0) to a byte buffer, calculate the CRC of it, then replace the appended zeroes by the CRC value, the receiver should be able to read the whole thing, and get a CRC of 0.
It doesn't seem to work for me...
Is there something I understand wrong in this? Is there something in this particular implementation of the CRC that makes this property invalid? It uses 0xFFFFFFFF as initial value, and XOR's with 0xFFFFFFFF at the end... Though this is pretty standard.
Here are some sources (other than the obvious wikipedia) if you want to save up on the googling:
source 1: http://www.relisoft.com/science/crcmath.html
Quote: | There is one more trick used in packaging CRCs. First calculate the CRC for a message to which you have appended 32 zero bits. Suppose that the message had N bits, thus corresponding to degree N-1 polynomial. After appending 32 bits, it will correspond to a degree N + 31 polynomial. The top-level bit that was multiplying xN-1 will be now multiplying xN+31 and so on. In all, this operation is equivalent to multiplying the message polynomial by x32. If we denote the original message polynomial by M (x), the key polynomial by K (x) and the CRC by R (x) (remainder) we have:
M * x32 = Q (x) * K (x) + R (x)
Now add the CRC to the augmented message and send it away. When the recipient calculates the CRC for this sum, and there was no transmission error, he will get zero. That's because:
M * x32 + R (x) = Q (x) * K (x) (no remainder!)
You might think I made a sign mistake--it should be -R (x) on the left. Remember, however, that in arithmetic modulo 2 addition and subtraction are the same! |
source 2: http://www.repairfaq.org/filipg/LINK/F_crc_v34.html#CRCV_003
source 3: http://marcel.wanda.ch/Tutorial/CRC/CyclicRedundancyCheck
My implementation is a translated version of this VB code:
http://www.vbaccelerator.com/home/vb/code/libraries/CRC32/article.asp
It was the closest to the language used in the Fanuc robot, so I used that. Shift registers are a pain in vb6... but these fanuc robots have no shift registers, no XOR operator, no way to define hexadecimal values, and no way to define unsigned values  _________________ (Insert a bunch of dead links here)
|
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Fri Sep 24, 2010 10:50 pm Post subject: |
 |
|
|
|
I think to get the CRC to come out to zero you have to append the actual CRC (not an XORed one). I'm not sure if initial value matters, since you're using the same initial on both computations. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Sep 27, 2010 9:07 am Post subject: |
 |
|
|
|
The attached screenshot shows what I'm doing:
1) The file is closed after the data has been written to it
2) The file is reopened (I need to do that since I open it as a 'file', while it was opened as a 'config file' before)
3) I scroll to the end of the file
4) I get the current position (to go back there later; let's call this END_POS)
5) I write a u32 0
6) I close the file, and calculate the CRC32 of it (Let's call it CRC_A)
7) I open the file once again
I scroll to END_POS to replace the four zero-bytes by CRC_A
9) I write CRC_A in the file
10) I check the CRC once again, and this one should be 0... I'm trying it both with initial value of 0 or 0xFFFFFFFF (default), and I even tried xor'ing the output. None of these outputs are equal to CRC_A
Labview block diagram
CRC32.png - 19.62 KB
File downloaded or viewed 189 time(s)
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Sep 27, 2010 9:33 am Post subject: |
 |
|
|
|
Here's another simple test, with the values I got at runtime. Using "testtesttest" as data string.
Edit: outputs on the screenshot are bypassing the final XOR in the CRC32 function... Outputs with the XOR as it should:
0x44608E84
0xBC9826D4
0x5A5CAB57
Labview block diagram
crc32_test2.png - 17.18 KB
File downloaded or viewed 169 time(s)
|
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Mon Sep 27, 2010 9:59 am Post subject: |
 |
|
|
|
Are you sure you're doing the CRC calculation correctly? For 'testtesttest' I get 0x44608E84, not the value you've displayed.
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Sep 27, 2010 10:37 am Post subject: |
 |
|
|
|
Read my edit ;D
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Sep 27, 2010 11:13 am Post subject: |
 |
|
|
|
This guy:
http://cs.nju.edu.cn/yangxc/dcc_teach/fcs-calc.pdf
says something about reversing the bits and bytes and crap... I'll try it out.
It's kind of confusing cause all the info I can find about this is related to serial communication... so there's a lot of inversions and crap.
Last edited by Samapico on Mon Sep 27, 2010 11:18 am, edited 1 time in total |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Mon Sep 27, 2010 11:17 am Post subject: |
 |
|
|
|
http://zorc.breitbandkatze.de/crc.html
1.) The CRC has to be appended. This means testtesttest into testtesttest<CRC> not testtesttest\0\0\0\0 into testtesttest<CRC>
2.) The CRC to be appended can't be XORed or reversed.
3.) The data bytes can't be reversed if you want to append things. If you want to keep the reversal, prepend the bytes (in reverse order) instead.
4.) Initial value doesn't matter.
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Sep 27, 2010 11:31 am Post subject: |
 |
|
|
|
?
Were you actually able to compute a CRC of 0 with that thing?
I tried a couple of things, no luck
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Sep 27, 2010 11:42 am Post subject: |
 |
|
|
|
OHH!
it worked
infinite thanks Brain, I owe you an e-beer
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Sep 27, 2010 11:56 am Post subject: |
 |
|
|
|
Here's how I did it : <screenshot attached>
So I get to keep the IEEE standard CRC32 algorithm, only thing I need to do is invert the resulting CRC on the robot's side, or simply expect -1 (0xFFFFFFFF)
crc32_works.png - 14.41 KB
File downloaded or viewed 181 time(s)
Last edited by Samapico on Tue Oct 05, 2010 7:48 am, edited 1 time in total |
|
Back to top |
|
 |
L.C. Server Help Squatter

Age:34 Gender: Joined: Jan 03 2003 Posts: 574 Location: Missouri, US Offline
|
Posted: Tue Oct 05, 2010 6:38 am Post subject: |
 |
|
|
|
Samapico wrote: | Here's how I did it : <screenshot attached>
So I get to keep the IEEE standard CRC32 algorithm, only thing I need to do is invert the resulting CRC on the robot's side, or simply expect -1 (0xFFFFFFFF) | Fixed.
|
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Tue Oct 05, 2010 7:48 am Post subject: |
 |
|
|
|
Fix ur face lulz
|
|
Back to top |
|
 |
|