1 |
douglas |
23 |
// GPS |
2 |
douglas |
6 |
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
douglas |
25 |
#include <cerrno> |
8 |
|
|
#include <iostream> |
9 |
|
|
#include <sstream> |
10 |
douglas |
6 |
|
11 |
douglas |
25 |
#include <posix.hpp> |
12 |
|
|
|
13 |
douglas |
23 |
#include "GPS.hpp" |
14 |
douglas |
25 |
|
15 |
|
|
namespace GPS |
16 |
|
|
{ |
17 |
|
|
|
18 |
|
|
Error::Error() |
19 |
|
|
{ |
20 |
|
|
std::ostringstream message; |
21 |
|
|
|
22 |
|
|
message << _B("GPS[#") << errno << _B("] "); |
23 |
|
|
|
24 |
|
|
switch (errno) |
25 |
|
|
{ |
26 |
|
|
case NL_NOSERVICE: |
27 |
|
|
message << _B("can't get service entry"); |
28 |
|
|
|
29 |
|
|
break; |
30 |
|
|
case NL_NOHOST: |
31 |
|
|
message << _B("can't get host entry"); |
32 |
|
|
|
33 |
|
|
break; |
34 |
|
|
case NL_NOPROTO: |
35 |
|
|
message << _B("can't get protocol entry"); |
36 |
|
|
|
37 |
|
|
break; |
38 |
|
|
case NL_NOSOCK: |
39 |
|
|
message << _B("can't create socket"); |
40 |
|
|
|
41 |
|
|
break; |
42 |
|
|
case NL_NOSOCKOPT: |
43 |
|
|
message << _B("error SETSOCKOPT SO_REUSEADDR"); |
44 |
|
|
|
45 |
|
|
break; |
46 |
|
|
case NL_NOCONNECT: |
47 |
|
|
message << _B("can't connect to host"); |
48 |
|
|
|
49 |
|
|
break; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
this->message = message.str(); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
GPS::GPS(const std::string &host, const std::string &port) : gps(::gps_open(host.c_str(), port.c_str())) |
56 |
|
|
{ |
57 |
|
|
if (gps == NULL) |
58 |
|
|
throw Error(); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void GPS::Poll() |
62 |
|
|
{ |
63 |
|
|
Posix::CheckError(::gps_poll(gps)); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
void GPS::Query(const std::string &query) |
67 |
|
|
{ |
68 |
|
|
Posix::CheckError(::gps_query(gps, query.c_str())); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
} |