Pages: [1]   Go Down
Author Topic: Parsing a string.  (Read 257 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Guys, I want to parse data sent through the serial connection:

Here's the example sting:

$GPRMC,082354.000,A,1324.9294,N,12135.8584,E,0.0,344.9,100713,,,A*6B

It spits out other data with a different starting header, and I only want the $GPRMC data to be read, and sent to me. plus, I only want these data points:


1324.9294
12135.8584

Another problem is, is that the data should be expressed like this:

13 24.9294 & 121 35.8584

how do I get about this dilemma?

Thanks guys!

Logged

--Gin319

ivrea (to)
Offline Offline
Faraday Member
**
Karma: 79
Posts: 4666
miaaao ^-^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can try using strtok() function and use ',' as token if it is a real string (array of char null terminated).
http://www.cplusplus.com/reference/cstring/strtok/?kw=strtok



« Last Edit: July 10, 2013, 04:20:36 am by nid69ita » Logged

my name is IGOR, not AIGOR

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could also look at (or use) the TinyGPS library which already knows how to parse GPS data.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I used a regular expression to parse a similar (or identical) string from my GPS.

http://www.gammon.com.au/forum/?id=11991

I was too lazy to work out dozens of strtok calls, so one regular expression call did it instead.

Logged

Pages: [1]   Go Up
Jump to: