-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPSConnection.cpp
59 lines (53 loc) · 997 Bytes
/
GPSConnection.cpp
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
#include "GPSConnection.h"
void GPSConnection::getPosition(float* latitude, float* longitude)
{
GPS.getData(&info);
char latit[20];
char longit[20];
char buf[20];
const char* p = (char*)info.GPGGA;
p = nextToken(p, 0); // GGA
p = nextToken(p, 0); // Time
p = nextToken(p, latit); // Latitude
p = nextToken(p, 0); // N
p = nextToken(p, longit); // Longitude
p = nextToken(p, 0); // E
p = nextToken(p, buf); // fix quality
//if (buf[0]=='1')
{
*latitude = atof(latit) / 100;
*longitude = atof(longit) / 100;
}
//else
{
// *latitude = 0.0;
// *longitude = 0.0;
}
}
char* GPSConnection::getGPGGA()
{
GPS.getData(&info);
return (char*)info.GPGGA;
}
void GPSConnection::powerOn()
{
GPS.powerOn();
}
void GPSConnection::powerOff()
{
GPS.powerOff();
}
const char* GPSConnection::nextToken(const char* src, char* buf)
{
int i = 0;
while (src[i] != 0 && src[i] != ',')
i++;
if (buf)
{
strncpy(buf, src, i);
buf[i] = 0;
}
if (src[i])
i++;
return src + i;
}