• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

GPS.h

Go to the documentation of this file.
00001 // -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
00002 
00005 
00006 #ifndef GPS_h
00007 #define GPS_h
00008 
00009 #include <inttypes.h>
00010 #include <Stream.h>
00011 
00014 class GPS
00015 {
00016 public:
00017 
00025         void                    update(void);
00026 
00031         enum GPS_Status {
00032                 NO_GPS = 0,             
00033                 NO_FIX = 1,             
00034                 GPS_OK = 2              
00035         };
00036 
00044         GPS_Status              status(void) { return _status; }
00045 
00053         virtual void    init(void) = 0;
00054 
00055         // Properties
00056         long    time;                   
00057         long    latitude;               
00058         long    longitude;              
00059         long    altitude;               
00060         long    ground_speed;   
00061         long    ground_course;  
00062         long    speed_3d;               
00063         int             hdop;                   
00064         uint8_t num_sats;               
00065 
00069         bool    new_data;
00070 
00071         // Deprecated properties
00072         bool    fix;                    
00073         bool    valid_read;             
00074 
00075         // Debug support
00076         bool    print_errors;   
00077 
00078 protected:
00079         Stream  *_port;                 
00080 
00088         GPS(Stream *s) : _port(s) {};
00089 
00096         virtual bool    read(void) = 0;
00097 
00104         long                    _swapl(const void *bytes);
00105 
00111         int                             _swapi(const void *bytes);
00112 
00123         void                    _error(const char *msg);
00124 
00125 private:
00126 
00130         static const unsigned long      _idleTimeout = 500;
00131 
00134         unsigned long                           _idleTimer;
00135 
00137         GPS_Status                                      _status;
00138 };
00139 
00140 inline long
00141 GPS::_swapl(const void *bytes)
00142 {
00143         const uint8_t   *b = (const uint8_t *)bytes;
00144         union {
00145                 long    v;
00146                 uint8_t b[4];
00147         } u;
00148 
00149         u.b[0] = b[3];
00150         u.b[1] = b[2];
00151         u.b[2] = b[1];
00152         u.b[3] = b[0];
00153 
00154         return(u.v);
00155 }
00156 
00157 inline int16_t
00158 GPS::_swapi(const void *bytes)
00159 {
00160         const uint8_t   *b = (const uint8_t *)bytes;
00161         union {
00162                 int16_t v;
00163                 uint8_t b[2];
00164         } u;
00165 
00166         u.b[0] = b[1];
00167         u.b[1] = b[0];
00168 
00169         return(u.v);
00170 }
00171 
00172 #endif

Generated for ArduPilot Libraries by doxygen