Reply by Dan March 26, 20042004-03-26
On Wed, 24 Mar 2004 21:25:03 -0700, Dan Henry <dhenry@sprynet.com>
wrote:

>If you want it, I guess you'll have to divulge your e-mail address so >I can send it to you, as the one given suggests that it's a fake and >that you don't have spam filters.
Thanks Dan, dan_nelson123 at hotmail.com Dan
Reply by David Brown March 25, 20042004-03-25
"Bob Stephens" <stephensyomamadigital@earthlink.net> wrote in message
news:ct7oxhusnjye.1sekmxocmcbtu.dlg@40tude.net...
> On Thu, 25 Mar 2004 13:48:43 GMT, Rick Merrill wrote: > > > you might prefer > >> unsigned char calcCrc(void *data, unsigned int size) { > >> unsigned char crc = 0; > >> while (0<size--) { > >> crc = crcTable[crc^(*data)++]; > >> }; > >> return crc; > >> } > > [++ has higher precedence than *] > > Huh?
For some reason, I don't seem to have got Rick's post on my newserver... Yes, ++ has higher precedence than * . Normally I like to add extra brackets to make these things clearer, but expressions of the form *p++ are so commonly used that I didn't bother. The original expression was crc = crcTable[crc ^ *data++] which means crc = crcTable[crc ^ ( * (data++) ) ] The expression (*data)++ would mean something else entirely - it would increment the value at address "data" instead - what I am doing here is running through "size" bytes at address "data" onwards.
Reply by Bob Stephens March 25, 20042004-03-25
On Thu, 25 Mar 2004 13:48:43 GMT, Rick Merrill wrote:

> you might prefer >> unsigned char calcCrc(void *data, unsigned int size) { >> unsigned char crc = 0; >> while (0<size--) { >> crc = crcTable[crc^(*data)++]; >> }; >> return crc; >> } > [++ has higher precedence than *]
Huh?
Reply by Rick Merrill March 25, 20042004-03-25
you might prefer
> unsigned char calcCrc(void *data, unsigned int size) { > unsigned char crc = 0; > while (0<size--) { > crc = crcTable[crc^(*data)++]; > }; > return crc; > }
[++ has higher precedence than *]
Reply by David Brown March 25, 20042004-03-25
There is a very popular paper by Ross N. Williams entitled "A Painless Guide
to CRC Error Detection Algorithms", which is available at dozens of web
sites, such as:
http://www.repairfaq.org/filipg/LINK/F_crc_v3.html

It is definitely worth reading before you get in too deep.  By far the
easiest and fastest method of implementing crc checks is to use a lookup
table (at the cost of 256 bytes of program memory).  Once you have generated
your table, the crc check function is something like:

unsigned char calcCrc(void *data, unsigned int size) {
    unsigned char crc = 0;
    while (size--) {
        crc = crcTable[crc ^ *data++];
    };
    return crc;
}




"Dan" <dan@dontspammecauseidontlikit.com> wrote in message
news:tvf460h6phqol5emtte8t8r1u331ed33ua@4ax.com...
> > I'm trying to implement the mux protocol (GSM 07.10) with a Motorola > G18 modem. I have the spec ETSI TS 101 369 which describes the CRC > as: > > The FCS shall be the ones complement of the sum (modulo 2) of > a) the remainder of > xk (x7 + x6 + x5 + x4 + x3 + x2 + x1 + 1) > divided (modulo 2) by the generator polynomial > x8 + x2 + x + 1, > etcetera... > > What I really want is the C code that implements the algorithm. I've > found some examples on the web, but they're 16 bit or 32 bit, whereas > this algorithm is 8 bit. > > I know that if I perservere, I can figure out how to implement it, but > I can see a lot of unsuccessful attempts along the way. Does anyone > have C code for this? > > Thanks > > Dan
Reply by Dan Henry March 25, 20042004-03-25
On Thu, 25 Mar 2004 10:20:15 +0800, Dan
<dan@dontspammecauseidontlikit.com> wrote:

> >I'm trying to implement the mux protocol (GSM 07.10) with a Motorola >G18 modem. I have the spec ETSI TS 101 369 which describes the CRC >as: > >The FCS shall be the ones complement of the sum (modulo 2) of >a) the remainder of >xk (x7 + x6 + x5 + x4 + x3 + x2 + x1 + 1) >divided (modulo 2) by the generator polynomial >x8 + x2 + x + 1, >etcetera... > >What I really want is the C code that implements the algorithm. I've >found some examples on the web, but they're 16 bit or 32 bit, whereas >this algorithm is 8 bit. > >I know that if I perservere, I can figure out how to implement it, but >I can see a lot of unsuccessful attempts along the way. Does anyone >have C code for this? > >Thanks > >Dan
I have what you are looking for, but posting 500 lines of source code here would be frowned upon -- 500 lines because of heavy commenting and multiple implementations to select from via conditional compilation paths, not because the CRC is difficult to implement. If you want it, I guess you'll have to divulge your e-mail address so I can send it to you, as the one given suggests that it's a fake and that you don't have spam filters. -- Dan Henry
Reply by Gary Kato March 25, 20042004-03-25
You might try grabbing a copy of "Programming Embedded Systems in C and C++"
from O'Reilly. It has a short section showing how CRCs are described and has
code you can modify to fit whatever parameters are given. I haven't used it
though. The parameters are the width, polynomial, initial remainder, and final
xor value.
Reply by Dan March 24, 20042004-03-24
I'm trying to implement the mux protocol (GSM 07.10) with a Motorola
G18 modem.  I have the spec ETSI TS 101 369 which describes the CRC
as:

The FCS shall be the ones complement of the sum (modulo 2) of
a) the remainder of
xk (x7 + x6 + x5 + x4 + x3 + x2 + x1 + 1)
divided (modulo 2) by the generator polynomial
x8 + x2 + x + 1,
etcetera...

What I really want is the C code that implements the algorithm.  I've
found some examples on the web, but they're 16 bit or 32 bit, whereas
this algorithm is 8 bit.

I know that if I perservere, I can figure out how to implement it, but
I can see a lot of unsuccessful attempts along the way.  Does anyone
have C code for this?

Thanks

Dan