1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
| /*
Program: Parse String
Author: Jayanth Devarayanadurga
Date: 14/09/2013
File Name: nmea.c
*/
#pragma hdrstop
#pragma argsused
#include <stdio.h>
#include <tchar.h>
#include <string.h>
/*
$GPGGA,025526.000,0653.409140,N,07954.150015,E,1,7 ,1.08,22.013,M,-96.608,M,,*4D
$GPGLL,0653.409140,N,07954.150015,E,025526.000,A,A *58
$GPGSA,A,3,21,29,18,24,22,25,15,,,,,,1.98,1.08,1.6 7*0F
$GPGSV,4,1,14,21,58,020,36,14,56,246,25,29,38,173, 36,18,32,354,36*7E
$GPGSV,4,2,14,24,30,071,49,22,25,317,34,06,19,304, 20,25,11,157,33*7E
$GPGSV,4,3,14,15,06,035,32,03,04,310,,31,03,205,,3 0,00,240,*78
$GPGSV,4,4,14,42,,,39,50,,,39*7F
$GPRMC,025526.000,A,0653.409140,N,07954.150015,E,0 .000,115.0,260313,,,A*6F
$GPVTG,115.0,T,,M,0.000,N,0.000,K,A*08
$GPZDA,025526.000,26,03,2013,,*57
*/
unsigned char gpsData[] = {'$','G','P','G','G','A',',','0','2','5','5','2','6','.','0','0','0',',','0','6','5','3','.','4','0','9','1','4','0',',','N',',','0','7','9','5','4','.','1','5','0','0','1','5',',','E',',','1',',','7',' ',',','1','.','0','8',',','2','2','.','0','1','3',',','M',',','-','9','6','.','6','0','8',',','M',',',',','*','4','D',
'$','G','P','G','L','L',',','0','6','5','3','.','4','0','9','1','4','0',',','N',',','0','7','9','5','4','.','1','5','0','0','1','5',',','E',',','0','2','5','5','2','6','.','0','0','0',',','A',',','A',' ','*','5','8',
'$','G','P','G','S','A',',','A',',','3',',','2','1',',','2','9',',','1','8',',','2','4',',','2','2',',','2','5',',','1','5',',',',',',',',',',',',','1','.','9','8',',','1','.','0','8',',','1','.','6',' ','7','*','0','F',
'$','G','P','G','S','V',',','4',',','1',',','1','4',',','2','1',',','5','8',',','0','2','0',',','3','6',',','1','4',',','5','6',',','2','4','6',',','2','5',',','2','9',',','3','8',',','1','7','3',',',' ','3','6',',','1','8',',','3','2',',','3','5','4',',','3','6','*','7','E',
'$','G','P','G','S','V',',','4',',','2',',','1','4',',','2','4',',','3','0',',','0','7','1',',','4','9',',','2','2',',','2','5',',','3','1','7',',','3','4',',','0','6',',','1','9',',','3','0','4',',',' ','2','0',',','2','5',',','1','1',',','1','5','7',',','3','3','*','7','E',
'$','G','P','G','S','V',',','4',',','3',',','1','4',',','1','5',',','0','6',',','0','3','5',',','3','2',',','0','3',',','0','4',',','3','1','0',',',',','3','1',',','0','3',',','2','0','5',',',',','3',' ','0',',','0','0',',','2','4','0',',','*','7','8',
'$','G','P','G','S','V',',','4',',','4',',','1','4',',','4','2',',',',',',','3','9',',','5','0',',',',',',','3','9','*','7','F',
'$','G','P','R','M','C','0','2','5','5','2','6','.','0','0','0',',','A',',','0','6','5','3','.','4','0','9','1','4','0',',','N',',','0','7','9','5','4','.','1','5','0','0','1','5',',','E',',','0',' ','.','0','0','0',',','1','1','5','.','0',',','2','6','0','3','1','3',',',',',',','A','*','6','F',
'$','G','P','V','T','G',',','1','1','5','.','0',',','T',',',',','M',',','0','.','0','0','0',',','N',',','0','.','0','0','0',',','K',',','A','*','0','8',
'$','G','P','Z','D','A',',','0','2','5','5','2','6','.','0','0','0',',','2','6',',','0','3',',','2','0','1','3',',',',','*','5','7','\0'};
unsigned char latitude[15], longitude[15], input;
unsigned int i, j, k;
int _tmain(int argc, _TCHAR* argv[])
{
start: printf("gpsDATA = %s\n\n", gpsData);
input = '\0';
printf("Parse String? Y/N: ");
scanf("%s", &input);
if((input == 'Y') || (input == 'y'))
;
else
goto exit;
input = '\0';
i = 0;
j = 0;
k = 0;
next: while(gpsData[i] != '$'){
i++;
}
if((gpsData[i+1] == 'G') && (gpsData[i+2] == 'P') && (gpsData[i+3] == 'R') && (gpsData[i+4] == 'M') && (gpsData[i+5] == 'C')){
while(gpsData[i++] != 'A');
i++;
while(gpsData[i] != ',')
latitude[k++] = gpsData[i++];
i += 3;
latitude[k] = '\0';
printf("Latitude = %s\n", latitude);
k = 0;
while(gpsData[i] != ',')
longitude[k++] = gpsData[i++];
longitude[k] = '\0';
printf("Longitude = %s\n\n", longitude);
}
else{
i++;
goto next;
}
printf("Parse again? Y/N: ");
scanf("%s", &input);
if((input == 'Y') || (input == 'y')){
goto start;
}
else
exit: return 0;
} |