Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
sdk:gps-udp-client-gnsstogps [2019/07/08 14:13] fachetsdk:gps-udp-client-gnsstogps [2019/07/09 13:52] fachet
Line 58: Line 58:
  
  return gpsd;  return gpsd;
 +}
 +
 +string checksum(string s)
 +{
 + pos = strchr(s, "*");
 +
 +  if (is_void(pos))
 + return s; /* no checksum to correct */
 +
 + cs = 0;
 + chars = explode(s);
 +        for (i = 1; i < pos; i++) { /* skip $ and *XX */ 
 +     printf(" %s ", chars[i]);
 +            c = ord(chars[i]);
 +            cs ^= c;
 +        }
 +        r = sprintf("%s%02X%s", substr(s, 0, pos + 1), cs, substr(s, pos + 3));
 + return r;
 } }
  
Line 126: Line 144:
  a_arr = explode(data);  a_arr = explode(data);
  a_arr[2] = "P";  a_arr[2] = "P";
- data = implode(a_arr);+ data = checksum(implode(a_arr));
  }  }
  /* skip all messages different from GPGGA   /* skip all messages different from GPGGA