how to extract only particular data from GPS data format

Status
Not open for further replies.

rahol

Junior Member level 3
Joined
Sep 13, 2012
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
gujarat/india
Visit site
Activity points
1,484
hello everyone,

I am working on CortexM4F120H5Q controller and i went to send data ( Longitude - E/W and Latitude - N/S only) from one Controller to another via GPS. my GPS data output is in accordance to NMEA 0183 and my GPS Reciever gives output in GPGGA data format.

my output comes like in this format $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh<CR><LF>.. this is just the example .

my problem is that ,i am receiving the whole data as mention above, but i only want to fetch Longitude - E/W and Latitude - N/S. so how can i extract only this particular info. from the whole data.,and i also want to stored that fetched data in particular variable.

Rx pin of GPS reciever is connected with Tx pin of controller. via UART protocol. i am getting output on GPSCockpit Terminal.

thanxs in advance
Regards
-raghu(rahol)
 

This is a classic example of "parsing" data. Your implementation will depend on the programming language you use, but the basic steps are:
Wait til yu recieve the $ and correct 'G' code
Reset a counter
On the recipt of every comma, increment the counter
When you reach the comma just before the data you want extract the field that follows
 
Reactions: rahol

    rahol

    Points: 2
    Helpful Answer Positive Rating
hello,
GSM Man

Could you plz give me example,
means program that show how to extract data from string
 

If the data is always the same length there are two other options. 1 - read the whole string and extract the wanted data from known positions within it, 2 - load the string into a union consisting of each of the fields then read the ones you want. Otherwise, do as GSM Man suggests, your compiler may have a 'strtok' function or something similar which will help delimit the fields.

Brian.
 

hello betwixt,
thanx for the reply,
i am able to read the string but still confuse with the logic behind tht how to extract wanted data from the whole string.
Could you plz tell me how to extract the particular data from the string "$--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M, x.x,M,x.x,xxxx*hh<CR><LF>" . Could you just mention the logic for extracting only yyyy.yy and llll.ll from the string?
 

As mentioned, there are several ways. You have not told us what language you are programming in so it's difficult to advise.

Generally there are 3 ways:
1. Read all the characters into a single string (or character array) then read the first character and see if it's a comma. Move on to the next character and again look for a comma, keep repeating until you reach the end of the string. When you find a comma, you know you are the divider between fields. All you have to do then is count how many fields you have found then read the data inside it up to the next comma.

2. (in 'C') If the data is always in exectly the same format, create a union consisting of several char strings, make each the length of the data in the fields and make extra single char fields for the commas. Copy the string into the union and it will populate each of the fields with the data. You can then read any of the fields to retrieve their contents.

3. (in 'C') Use the 'strtok' function with a comma as the search character. It will break the string into sections wherever a comma is found and return a pointer to the data after it. Each time you use strtok it returns a pointer to the next field so it gives you "hhmmss.ss" then "llll.ll" then "a" and so on. All you have to do is ignore the fields you do not want and use the ones you need.

Brian.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…