Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Interpreting some code in C


I am trying to find out how the checksum is computed for a Megellan
Explorist GPS Waypoint (POI) file. Below is the first 3 lines of a typical
file. I understand everything except how the "a*23" at the end of the line
is arrived at.

$PMGNFMT,%WPL,LAT,HEMI,LON,HEMI,ALT,UNIT,NAME,MSG, ICON,CHKSUM,%META,ASCII
$PMGNWPL,3137.54374,S,01914.37622,E,0,M,WPT001,,a* 23
$PMGNWPL,3122.18567,S,01906.50683,E,0,M,WPT002,,a* 21

Below is an extract of the code for a program that calculates the checksum
(It looks like the relevant section). The full code can be found he
http://gpsbabel.cvs.sourceforge.net/...revision=1.155

The code is in C of which I understand nothing. My only experience at this
stage is Excel VBA. Can someone please explain in plain text (or VBA) how
the checksum is calculated.

Many thanks
Laurence


/*
* Given a protocol message, compute the checksum as needed by
* the Magellan protocol.
*/
unsigned int
mag_checksum(const char * const buf)
{
int csum = 0;
const char *p;

for(p = buf; *p; p++) {
csum ^= *p;
}

return csum;
}
static unsigned int
mag_pchecksum(const char * const buf, int len)
{
int csum = 0;
const char *p = buf;
for (; len ; len--) {
csum ^= *p++;
}
return csum;
}

static void
mag_writemsg(const char * const buf)
{
unsigned int osum = mag_checksum(buf);
int retry_cnt = 5;
int i;
char obuf[1000];

if (debug_serial) {
warning("WRITE: $%s*%02X\r\n",buf, osum);
}

retry:

i = sprintf(obuf, "$%s*%02X\r\n",buf, osum);
termwrite(obuf, i);
if (magrxstate == mrs_handon || magrxstate == mrs_awaiting_ack) {
magrxstate = mrs_awaiting_ack;
mag_readmsg(trkdata);
if (last_rx_csum != osum) {
if (debug_serial) {
warning("COMM ERROR: Expected %02x, got %02x",
osum, last_rx_csum);
}
if (retry_cnt--)
goto retry;
else {
mag_handoff();
fatal(MYNAME
": Too many communication errors.\n");
}
}
}
}


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interpreting Values mrsatroy Charts and Charting in Excel 2 May 27th 10 10:51 PM
Excel is interpreting my TEXT... I wish it would not! Puddles Excel Discussion (Misc queries) 6 November 7th 07 05:16 PM
Interpreting graph of a slope Graphing a function Charts and Charting in Excel 2 November 27th 06 06:11 PM
help interpreting expression anny Excel Worksheet Functions 3 February 5th 06 06:38 PM
Excel interpreting HTML and CR/LF Steve Flook Excel Programming 3 February 4th 04 03:33 PM


All times are GMT +1. The time now is 06:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"