1 |
< |
// GPS |
1 |
> |
// Display (Crystalfontz CFA-635 USB LCD) |
2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
< |
#ifndef _GPS_hpp_ |
8 |
< |
#define _GPS_hpp_ |
9 |
< |
|
10 |
< |
#include <cmath> |
11 |
< |
#include <string> |
7 |
> |
#ifndef _Display_hpp_ |
8 |
> |
#define _Display_hpp_ |
9 |
|
|
10 |
+ |
#include <posix.hpp> |
11 |
|
#include <truck.hpp> |
12 |
|
|
13 |
< |
#include <gps.h> |
16 |
< |
|
17 |
< |
namespace GPS |
13 |
> |
class Display |
14 |
|
{ |
15 |
+ |
int ucom; |
16 |
+ |
struct Packet |
17 |
+ |
{ |
18 |
+ |
enum Command |
19 |
+ |
{ |
20 |
+ |
PingCommand = 0x00, |
21 |
+ |
GetHardwareAndFirmwareVersion = 0x01, |
22 |
+ |
WriteUserFlashArea = 0x02, |
23 |
+ |
ReadUserFlashArea = 0x03, |
24 |
+ |
StoreCurrentStateAsBootState = 0x04, |
25 |
+ |
RebootResetHostOrPowerOffHost = 0x05, |
26 |
+ |
ClearLCDScreen = 0x06, |
27 |
+ |
SetLCDSpecialCharacterData = 0x09, |
28 |
+ |
Read8ByesOfLCDMemory = 0x0a, |
29 |
+ |
SetLCDCursorPosition = 0x0b, |
30 |
+ |
SetLCDCursorStyle = 0x0c, |
31 |
+ |
SetLCDContrast = 0x0d, |
32 |
+ |
SetLCDKeypadAndBacklight = 0x0e, |
33 |
+ |
SetUpFanReporting = 0x10, |
34 |
+ |
SetFanPower = 0x11, |
35 |
+ |
ReadDOWDeviceInformation = 0x12, |
36 |
+ |
SetUpTemperatureReporting = 0x13, |
37 |
+ |
ArbitraryDOWTransaction = 0x14, |
38 |
+ |
SendCommandDirectlyToTheLCDController = 0x16, |
39 |
+ |
ConfigureKeyReporting = 0x17, |
40 |
+ |
ReadKeypad = 0x18, |
41 |
+ |
SetFanPowerFailSafe = 0x19, |
42 |
+ |
SetFanTachometerGlitchFilter = 0x1a, |
43 |
+ |
QueryFanPowerAndFailSafeMask = 0x1b, |
44 |
+ |
SetATXPowerSwitchFunctionality = 0x1c, |
45 |
+ |
EnableDisableAndResetTheWatchdog = 0x1d, |
46 |
+ |
ReadReportingAndStatus = 0x1e, |
47 |
+ |
SendDataToLCD = 0x1f, |
48 |
+ |
SetBaudRate = 0x21, |
49 |
+ |
SetOrSetAndConfigureGPIOPin = 0x22, |
50 |
+ |
ReadGPIOPinLevelsAndConfigurationState = 0x23, |
51 |
+ |
Response = 0x40, |
52 |
+ |
KeyActivity = 0x80, |
53 |
+ |
FanSpeedReport = 0x81, |
54 |
+ |
TemperatureSensorReport = 0x82, |
55 |
+ |
Error = 0xc0, |
56 |
+ |
}; |
57 |
+ |
|
58 |
+ |
uint8_t command; |
59 |
+ |
uint8_t length; |
60 |
+ |
uint8_t data[22]; |
61 |
+ |
uint16_t crc; |
62 |
+ |
|
63 |
+ |
Packet() {} |
64 |
+ |
Packet(Command command, const std::string &data = std::string()); |
65 |
+ |
}; |
66 |
|
|
20 |
– |
class Error : public std::exception |
21 |
– |
{ |
22 |
– |
std::string message; |
67 |
|
public: |
68 |
< |
Error(); |
69 |
< |
virtual ~Error() throw() {} |
26 |
< |
virtual const char *what() const throw() { return message.c_str(); } |
27 |
< |
}; |
68 |
> |
Display(const std::string &device); |
69 |
> |
~Display() { Posix::Close(ucom); } |
70 |
|
|
71 |
< |
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; } |
71 |
> |
bool Ping(const std::string &data = std::string()); |
72 |
|
}; |
73 |
|
|
74 |
< |
} |
50 |
< |
|
51 |
< |
#endif//_GPS_hpp_ |
74 |
> |
#endif//_Display_hpp_ |