-
Notifications
You must be signed in to change notification settings - Fork 1
/
gps_parser.c
176 lines (164 loc) · 4.62 KB
/
gps_parser.c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include <stdio.h>
#include <string.h>
char gga[] = "$GPGGA,181908.00,3404.7041778,N,07044.3966270,W,4,13,1.00,495.144,M,29.200,M,0.10,0000*40";
char rmc[] = "$GPRMC,144326.00,A,5107.0017737,N,11402.3291611,W,0.080,323.3,210307,0.0,E,A*20";
char time1[9];
char date[6];
char lat[10];
char lng[11];
char lat_dir = 'N';
char lng_dir = 'W';
char gps_fix = 0;
char satellite[2];
char altitude[6];
char gps_valid;
char speed[5];
void parse_gga(char *ptr)
{
char *pchar;
char *str;//(char *)ptr;
strcpy(str,ptr); // if ptr where it originally declared is pointer than use this
// str = ptr; // use this if ptr is array
pchar = str;
int len = strlen(str);
printf("%d\n",len);
int comma_count= 0;
while(len)
{
len--;
if(*str == ',')
{
comma_count++;
*str = '\0';
if(pchar == str)
{
pchar = str + 1;
//printf("here");
continue;
}
switch(comma_count)
{
case 1:// gpgga
printf("gpgga %s\n",pchar);
break;
case 2:// time
strcpy(time1, pchar);
time1[6] = '\0';
printf("time %s\n",time1);
break;// lat
case 3:
strcpy(lat, pchar);
printf("lat %s",lat);
break;
case 4: // lat dir
lat_dir = pchar[0];
printf("%c\n",lat_dir);
break;
case 5:// lng
strcpy(lng, pchar);
printf("lng %s",lng);
break;
case 6: // lng dir
lng_dir = pchar[0];
printf("%c\n",lng_dir);
break;
case 7: // fix
gps_fix = pchar[0];
printf("gps fix %c\n",gps_fix);
break;
case 8: // num of satellite
strcpy(satellite, pchar);
printf("sat %s\n",satellite);
break;
case 10: //altitude
strcpy(altitude, pchar);
printf("alt %s\n",altitude);
break;
default:
break;
}
pchar = str+1;
}
str++;
}
}
void parse_rmc(char *ptr)
{
char *pchar;
char *str;//(char *)ptr;
strcpy(str,ptr); // if ptr where it originally declared is pointer than use this
// str = ptr; // use this if ptr is array
pchar = str;
int len = strlen(str);
printf("%d\n",len);
int comma_count= 0;
while(len)
{
len--;
if(*str == ',')
{
comma_count++;
*str = '\0';
if(pchar == str)
{
pchar = str + 1;
//printf("here");
continue;
}
switch(comma_count)
{
case 1:// gprmc
printf("gprmc %s\n",pchar);
break;
case 2:// time
strcpy(time1, pchar);
time1[6] = '\0';
printf("time %s\n",time1);
break;// gps valid
case 3:
gps_valid = pchar[0];
printf("gps_valid %c\n",gps_valid);
break;
case 4:// lat
strcpy(lat, pchar);
printf("lat %s",lat);
break;
case 5: // lat dir
lat_dir = pchar[0];
printf("%c\n",lat_dir);
break;
case 6:// lng
strncpy(lng, pchar,11);
printf("lng %s",lng);
break;
case 7: // lng dir
lng_dir = pchar[0];
printf("%c\n",lng_dir);
break;
case 8: // speed
strcpy(speed, pchar);
printf("speed %s\n",speed);
break;
case 9: //track true
//strcpy(satellite, pchar);
printf("track %s\n",pchar);
break;
case 10: //date
strcpy(date, pchar);
printf("date %s\n",date);
break;
default:
break;
}
pchar = str+1;
}
str++;
}
}
int main()
{
printf("Hello World\n");
parse_gga(gga);
parse_rmc(rmc);
return 0;
}