Go Down

Topic: Parsing a string. (Read 333 times) previous topic - next topic

Gin319

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!

--Gin319

nid69ita

#1
Jul 10, 2013, 11:14 am Last Edit: Jul 10, 2013, 11:20 am by nid69ita Reason: 1
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



my name is IGOR, not AIGOR

PaulS

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

Nick Gammon

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.

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up