0
\$\begingroup\$

I have interfaced S1315RL GPS into PIC16LF1937 using MPLABXC8 compiler(MPLAB IDEv3.51).

I am trying to extract the latitude,longitude,time from the GPS output.

uint8_t *str = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47\n";

I have strtok() for remove the "," from the GPS output. But In c compiler its working well.I cant remove the "," in MPLAB XC8 compiler.

So,if anybody knows other methods inform to me .

\$\endgroup\$
3
  • 2
    \$\begingroup\$ I'm voting to close this question as off-topic because it is purely a programming question. \$\endgroup\$
    – Martin
    May 9, 2017 at 13:59
  • 1
    \$\begingroup\$ Do you have a constant string (as shown), or did you put the received string into some buffer? \$\endgroup\$
    – CL.
    May 9, 2017 at 14:05
  • 1
    \$\begingroup\$ @Martin it is purely programming however it's to do with issues related to a crappy embedded micro compiler rather than generic desktop programming. While technically off topic this is as good a place as any for them and there have been plenty of similar questions asked and answered here in the past. \$\endgroup\$
    – Andrew
    May 9, 2017 at 14:13

1 Answer 1

0
\$\begingroup\$

You can always make your own strTok like function and parse the string manually:

uint8_t *findNextSeperator(uint8_t *startPoint) {
  while ((*startPoint != ',') && (*startPoint != '*') && (*startPoint != '\n'))
    startPoint++;
  return startPoint;
}

{
...
// dummy sample string...
uint8_t str[] = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47\n";

uint8_t *tmpPtr = str; // begin at the beginning

tmpPtr = findNextSeperator(tmpPtr); // the , before time
tmpPtr = findNextSeperator(tmpPtr+1); // the , before lat

uint8_t *latPtr = tmpPtr + 1; // the first character in the latitude string

tmpPtr = findNextSeperator(tmpPtr+1); // the , before N
*tmpPtr = 0; // null terminate the latitude string

uint8_t latDir = *(tmpPtr + 1); // store the direction of the latitude

tmpPtr = findNextSeperator(tmpPtr+1); // the , before lon
uint8_t *lonPtr = tmpPtr + 1; // the first character in the longitude

tmpPtr = findNextSeperator(tmpPtr+1); // the , before E
*tmpPtr = 0; // null terminate the longitude

uint8_t lonDir = *(tmpPtr + 1); // store the direction of the longitude
...
}
\$\endgroup\$
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.