Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - CRC8

CRC8

Discuss OrbForms Designer and PocketC Architect

Postby kda406 on Tue Nov 18, 2003 7:02 pm

I really don't mean to be beating a dead horse about the unsigned int thing (http://64.78.17.111/forum/topic.asp?TOPIC_ID=3031) that caused me a tons of grief trying to write a 32 bit encryption algorithm. Honest. :?

But now I'm trying to add a CRC8 to my IR packets. All of my other devices and programs use this code to create CRC8:
<font face="Courier New">
//-----------------------------------------------------
// CRC8 calculator
// Typical usage:
// lastcrc8=0; // Clear the CRC value
// for(i=0;i<8;i++) { // Calculate the CRC
// lastcrc8=CRC_Calc8Bit(lastcrc8,tmp_serial_num[i]);
// }
unsigned char CRC_Calc8Bit (unsigned char crc, unsigned char val) {
unsigned char inc, tmp;

for(inc = 0; inc < 8; inc++) {
tmp = crc << 7; // save X7 bit value
crc >>= 1; // shift crc
if((tmp >> 7) ^ (val & 0x01)) { // if X7 xor X8 (input data)
crc ^= 0x8c; // xor crc with X4 and X5, X1 = X7^X8
crc |= 0x80; // carry
}
val >>= 1;
}
return(crc);
}
</font id="Courier New">

Unfortunately, it appears OrbForms Designer doesn't support unsigned chars. [:0] Simply changing the bit shifts to OFD's syntax and removing the word unsigned does not work.

Does anybody have any suggestions or code snippets for how to do an 8 bit CRC with signed chars?

-Kyle
kda406
 
Posts: 86
Joined: Wed Sep 10, 2003 1:24 pm
Location: Atlanta, GA, USA

Postby kda406 on Fri Dec 05, 2003 12:43 pm

I thought the forum may benefit from what I created. After much toil, here is the modified code that makes CRC8 possible when limited to by only being able to used signed chars:

char CRC_Calc8Bit (char crc, char val) {
char i;
int tmp, crci=0, vali=0;

if(crc < 0) {
crc &= 0x7F;
crci += 0x80;
}
crci += crc;

if(val < 0) {
val &= 0x7F;
vali += 0x80;
}
vali += val;

for(i=0;i<8;i++) {
tmp = crci << 7; // save X7 bit value
tmp &= 0xFF; // make it emulate a char
crci = crci >> 1; // shift crc
if((tmp >> 7) ^ (vali & 0x01)) { // if X7 xor X8 (input data)
crci ^= 0x8c; // xor crc with X4 and X5, X1 = X7^X8
crci |= 0x80; // carry
}
vali = vali >> 1;
}
return((char)crci);
}

This works and returns the CRC8 results equivalent to the traditional, unsigned CRC8 algorithm I showed previously. Enjoy. :)

-Kyle
kda406
 
Posts: 86
Joined: Wed Sep 10, 2003 1:24 pm
Location: Atlanta, GA, USA

Postby parthasaradhi on Mon Jun 05, 2006 4:11 am

Iam using the same function for CRC8 Calculation of Hex values. The function not giving the correct value for few values. Can you help me out by providing the correct solution.
Ex: 11A64D6A773BC2100A04039A8CDFF7F0
The function giving "CD"
Correct CRC8 is "F0"
ASAP.
Thanks in advance....
parthasaradhi
 
Posts: 1
Joined: Mon Jun 05, 2006 4:06 am


Return to OrbForms Designer and PocketC Architect

Who is online

Users browsing this forum: No registered users and 1 guest

cron