Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Crc32

 
Post new topic   Reply to topic Printable version
 View previous topic  Continuum and Wine on OpenSUSE 11.2 x8... Post :: Post Grab text in php  View next topic  
Author Message
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Fri Sep 24, 2010 5:29 pm    Post subject: Crc32 Reply to topic Reply with quote

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 tongue.gif
_________________
DCME co-developer
17th Parallel Head Sysop
Subspace: The Future
Back to top
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:31
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Fri Sep 24, 2010 10:50 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon Sep 27, 2010 9:07 am    Post subject: Reply to topic Reply with quote

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
icon_cool.gif 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 25 time(s)
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon Sep 27, 2010 9:33 am    Post subject: Reply to topic Reply with quote

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 21 time(s)
Back to top
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:31
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Mon Sep 27, 2010 9:59 am    Post subject: Reply to topic Reply with quote

Are you sure you're doing the CRC calculation correctly? For 'testtesttest' I get 0x44608E84, not the value you've displayed.
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon Sep 27, 2010 10:37 am    Post subject: Reply to topic Reply with quote

Read my edit ;D
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon Sep 27, 2010 11:13 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:31
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Mon Sep 27, 2010 11:17 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon Sep 27, 2010 11:31 am    Post subject: Reply to topic Reply with quote

?

Were you actually able to compute a CRC of 0 with that thing?
I tried a couple of things, no luck
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon Sep 27, 2010 11:42 am    Post subject: Reply to topic Reply with quote

OHH!

it worked

infinite thanks Brain, I owe you an e-beer
Back to top
View users profile Send private message Add User to Ignore List
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Mon Sep 27, 2010 11:56 am    Post subject: Reply to topic Reply with quote

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 45 time(s)


Last edited by Samapico on Tue Oct 05, 2010 7:48 am, edited 1 time in total
Back to top
View users profile Send private message Add User to Ignore List
L.C.
Server Help Squatter


Age:26
Gender:Gender:Male
Joined: Jan 03 2003
Posts: 572
Location: Missouri, US
Offline

PostPosted: Tue Oct 05, 2010 6:38 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address Yahoo Messenger MSN Messenger
Samapico
No, these DO NOT look like penises, ok?


Age:31
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Tue Oct 05, 2010 7:48 am    Post subject: Reply to topic Reply with quote

Fix ur face lulz
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Non-Subspace Related Coding All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 92 page(s) served in previous 5 minutes.

phpBB Created this page in 0.081593 seconds : 40 queries executed (41.3%): GZIP compression disabled