On Dec 31, 2004, at 10:44 AM, James 'Mac' Read wrote:
Let me start out, I am an experienced programmer but, I am brand new
to C and xCode.
I have a need to calculate a CRC value using a CRC16 algorithm. This
is going to be used to communicate with a timing device that transmits
timing information via a serial or network connection. The
commercially available plug-ins that calculate a CRC16 do not seem to
return the same value as what I am getting from the timing device.
Fortunately the manufacturer supplies their CRC16 source code in their
documentation. The source code is only a dozen lines or so, so I
thought I would take a crack at building my own plug in. I pulled down
the SDK and read up on using xCode to build a plug in, looked at the
examples, copied and pasted and the source code into xCode. Now I am
having some trouble compiling it. I expect is has something to do with
linking the headers, but I am at a loss as to how to correct it.
Here is the source (I added the line numbers for easy reference):
1 #include "rb_plugin.h"
2 char CRC16Table[256];
3 // calculate the CRC of a string pointed at by p
4 static REALString CalcCRC16( char * p ) {
5 REALString CRC ;
Both the previous lines should be REALstring, instead of REALString.
6 for ( CRC = 0xFFFF ; *p != 0 ; p++ ) // for all chars of a string
7 CRC = CRC16Table[ ( ( CRC >> 8 ) & 255 ) ] ^ ( CRC << 8 ) ^ *p ;
8 return CRC ;
9 }
I don't understand this code. Why are you initializing a REALstring to
0xFFFF? I would venture that doing this would cause crashes either
during this code or shortly after. You should only use REALBuildString
to create new strings.
10 // initialize the CRC16 table
11 static void InitCRC16( void ) {
12 int i, j ;
13 char crc ;
14 for ( i = 0 ; i < 256 ; i += 1 ) {
15 for ( crc = i << 8, j = 0 ; j < 8 ; j += 1 )
16 crc = ( crc << 1 ) ^ ( ( crc & 0x8000 ) ? 0x1021 : 0 ) ;
17 CRC16Table[ i ] = crc ;
18 }
19 }
I didn't see anything wrong in this block.
20 REALmethodDefinition CalcCRC16def = {
21 (REALproc) CalcCRC16,
22 REALnoImplementation,
23 "CalcCRC16(stg as string) as string"
24 };
25 void PluginEntry() {
26 REALRegisterMethod(&CalcCRC16def);
27 InitCRC16();
28 }
When I click the build button I get the following errors:
At line 4: error: syntax error before '(' token
At line 6: error: syntax error before '++' token
At line 6: error: syntax error before '!=' token
At line 21: 'CalcCRC16' was not declared in this scope
With my limited knowledge, I believe, xCode thinks the REALString data
type on lines 4 and 5 is not defined... but I see where it is defined
in the header file.
Can someone give me a clue as to what I am doing wrong? And point me
in the right direction to fix it?
I think it's the capitalization that's fooling it.
Thanks and Happy New Year!
Happy New Year!
-Jon
--
Jonathan Johnson
REAL Software, Inc.
--
REAL World 2005 - The REALbasic User Conference
March 23-25, 2005, Austin, Texas
<http://www.realsoftware.com/realworld>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|