-
Notifications
You must be signed in to change notification settings - Fork 0
/
gps address collection
66 lines (50 loc) · 1.6 KB
/
gps address collection
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
int o = 0; // global variabe
void lat_long(){
char gps[80];
int i ;
const char s[2] = ","; // will be used later in seperating the address
char* token;
int j ;
// collecting and checking the form of address i want "GPRMC"
while(1)
{ i = 0;
gps[i]=read_uart();
if(gps[i] == '$')
{ gps[++i]=read_uart();
if(gps[i] == 'G')
{ gps[++i]=read_uart();
if(gps[i] == 'P')
{ gps[++i]=read_uart();
if(gps[i] == 'R')
{ gps[++i]=read_uart();
if(gps[i] == 'M')
{ gps[++i]=read_uart();
if(gps[i] == 'C')
{ break;
}
}
}
}
}
}
}
do {
// collecting the rest of address
gps[++i]=read_uart();
} while(i <79);
//char gps[80] = "$GPRMC,200751.00,A,4047.32510,N,02929.63031,E,9.879,105.80,301117,,,A*6C"; example
if ( gps[17]=='A') {
o = 1;
token = strtok(gps, s); // seperate the first string ("$GPRMC") until the comma
for (j = 0; j < 12; j++) {
token = strtok(NULL, s); //continue seperating strings
// exctracting latitude
if (j == 2) {
lat2 = floor(atof(token) / 100) + (atof(token) / 100 - floor(atof(token) / 100)) / 0.6;
}
// extracting longitude
if (j == 4) {
long2 = floor(atof(token) / 100) + (atof(token) / 100 - floor(atof(token) / 100)) / 0.6;
}
}
}