1 |
douglas |
23 |
// GPS |
2 |
douglas |
6 |
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
douglas |
23 |
#ifndef _GPS_hpp_ |
8 |
|
|
#define _GPS_hpp_ |
9 |
douglas |
6 |
|
10 |
douglas |
25 |
#include <cmath> |
11 |
|
|
#include <string> |
12 |
|
|
|
13 |
|
|
#include <truck.hpp> |
14 |
|
|
|
15 |
|
|
#include <gps.h> |
16 |
|
|
|
17 |
|
|
namespace GPS |
18 |
|
|
{ |
19 |
|
|
|
20 |
|
|
class Error : public std::exception |
21 |
|
|
{ |
22 |
|
|
std::string message; |
23 |
|
|
public: |
24 |
|
|
Error(); |
25 |
|
|
virtual ~Error() throw() {} |
26 |
|
|
virtual const char *what() const throw() { return message.c_str(); } |
27 |
|
|
}; |
28 |
|
|
|
29 |
|
|
class GPS |
30 |
|
|
{ |
31 |
|
|
gps_data_t *gps; |
32 |
|
|
public: |
33 |
|
|
GPS(const std::string &host = _B("localhost"), const std::string &port = _B(DEFAULT_GPSD_PORT)); |
34 |
|
|
~GPS() { ::gps_close(gps); } |
35 |
|
|
void Poll(); |
36 |
|
|
void Query(const std::string &query); |
37 |
|
|
double GetLatitude() { return gps->fix.latitude; } |
38 |
|
|
double GetLongitude() { return gps->fix.longitude; } |
39 |
|
|
double GetAltitude() { return gps->fix.altitude; } |
40 |
|
|
double GetAltitudeFeet() { return GetAltitude() * METERS_TO_FEET; } |
41 |
|
|
double GetTrack() { return gps->fix.track; } |
42 |
|
|
double GetSpeed() { return gps->fix.speed; } |
43 |
|
|
double GetSpeedMPH() { return GetSpeed() * MPS_TO_MPH; } |
44 |
|
|
double GetSpeedKMH() { return GetSpeed() * MPS_TO_KPH; } |
45 |
|
|
double GetSpeedKnots() { return GetSpeed() * MPS_TO_KNOTS; } |
46 |
|
|
double GetClimb() { return gps->fix.climb; } |
47 |
|
|
}; |
48 |
|
|
|
49 |
|
|
} |
50 |
|
|
|
51 |
douglas |
23 |
#endif//_GPS_hpp_ |