NMEA Parser – GPS Messages

okay..enough boss.., gw jadi orang multitalenan d kantor. smua2 knp harus gw, tp okelah gw juga lagi nuntut ilmu..hehehe…

NMEA : whats NMEA ?

NMEA is a combined electrical and data specification for communication between marine electronic devices such as echo sounder, sonars, anemometer, gyrocompass, autopilot, GPS receivers and many other types of instruments. It has been defined by, and is controlled by, the U.S.-based National Marine Electronics Association

okeh, dont be pusing ya, NMEA is one of many Message Protocol from GPS Satellite.

These are how you get your location from NMEA message :

from your GPS receiver u just listen to Serial Ports that have configurations:

 CONFIGS:

1. ini pake alias this using fix baudrate 4800

2. databits 8

3. Parity – NONE

4. STOP bits 1

5. Handshake – None, if u wanna force of this handshake, just handshake with ur own hand..hahahahaha
ANSI C / Parser Program :

for example this is what u got from your receiver
$GPRMC,095146.000,A,0615.5814,S,10647.3518,E,0.16,238.45,090211,,,A*79

$GPVTG,238.45,T,,M,0.16,N,0.3,K,N*0E

$GPGGA,095147.000,0615.5811,S,10647.3526,E,1,03,3.2,57.6,M,2.9,M,,0000*4B

$GPGSA,A,2,12,18,25,,,,,,,,,,3.4,3.2,1.0*39

$GPRMC,095147.000,A,0615.5811,S,10647.3526,E,0.33,248.75,090211,,,A*73

$GPVTG,248.75,T,,M,0.33,N,0.6,K,N*08

$GPGGA,095148.000,0615.5808,S,10647.3532,E,1,03,3.2,57.6,M,2.9,M,,0000*49

$GPGGA,095149.000,0615.5803,S,10647.3542,E,1,03,3.2,57.7,M,2.9,M,,0000*45

$GPGSA,A,2,12,18,25,,,,,,,,,,3.4,3.2,1.0*39

$GPRMC,095149.000,A,0615.5803,S,10647.3542,E,1.11,73.30,090211,,,A*46

$GPVTG,73.30,T,,M,1.11,N,2.1,K,N*37

$GPGGA,095150.000,0615.5803,S,10647.3537,E,1,03,3.2,57.6,M,2.9,M,,0000*4E

$GPGSA,A,2,12,18,25,,,,,,,,,,3.4,3.2,1.0*39

$GPGGA,095151.000,0615.5802,S,10647.3536,E,1,03,3.2,57.7,M,2.9,M,,0000*4E

NOW can u read what they mean? hihihihihi…

in this program I just parse the GPGGA part that is enough to get your LATITUDE & LONGITUDE

#include <stdio.h>
#include <string.h>

int main()
{
FILE *file = fopen(“gps.txt”, “r”);
char Buffer[1024] = {0};
char temp [512] = {0};
while(fgets(Buffer,1024,file) != NULL)
{
if(Buffer[0] == ‘$’)
{
if (memcmp(Buffer+1,”GPGGA”,5) == 0)
{
printf(“—————————–\n”);
printf(“%s\n”, Buffer);
char *token = strtok(Buffer+6,”,”);
int i = 0;
while(token != NULL)
{
switch(i)
{
case 0:
// cout <<“Universal Time Coordinated (UTC): ” <<token << endl;
break;
case 1:
strcpy(temp,token);
token = strtok(NULL,”, “);
strcat(temp,”, “);
strcat(temp,token);
printf(“Latitude : %s\n”, temp);
i++;
break;
case 2:
// cout << “North or South :” <<token << endl;
break;
case 3:
strcpy(temp,token);
token = strtok(NULL,”, “);
strcat(temp,”, “);
strcat(temp,token);
i++;
printf(“Longitude : %s\n”, temp);
break;
case 4:
// cout <<“East or West :” <<token << endl;
break;
case 5:
// cout << “GPS Quality Indicator :”<<token << endl;
break;
case 6:
// cout << “Number of satellites in view, 00 – 12 :”<<token << endl;
break;
case 7:
// cout << “Horizontal Dilution of precision :”<<token << endl;
break;
case 8:
strcpy(temp,token);
token = strtok(NULL,”, “);
strcat(temp,”, “);
strcat(temp,token);
i++;
printf(“Altitude : %s\n”, temp);
break;
case 9:
// cout << “Units of antenna altitude, meters :”<<token << endl;
break;
case 10:
// cout << “Geoidal separation :”<<token << endl;
break;
case 11:
// cout << “Units of geoidal separation :”<<token << endl;
break;
case 12:
// cout << “Age of differential GPS data :”<<token << endl;
break;
case 13:
// cout << “Differential reference station ID :”<<token << endl;
break;
case 14:
// cout << “Checksum :”<<token << endl;
break;
default:
break;
}
i++;
token = strtok(NULL,”,”);
}
getchar();
}
}
}
}

Advertisements
NMEA Parser – GPS Messages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s