BMP280 Code cleanup
[openXsensor.git] / openXsensor / oXs_gps.h
blob8dcbcf2b19e24c1feda18667e984642e6521e67e
1 #ifndef OXS_GPS_h
2 #define OXS_GPS_h
4 #include <Arduino.h>
5 #include "oXs_config_basic.h"
6 #include "oXs_config_advanced.h"
7 #include "oXs_config_macros.h"
11 // from the UBlox6 document, the largest payout we receive i the NAV-SVINFO and the payload size
12 // is calculated as 8 + 12*numCh. numCh in the case of a Glonass receiver is 28.
13 #define UBLOX_PAYLOAD_SIZE 344 // 344 is the absolute max size
14 #define UBLOX_BUFFER_SIZE 50 // but the message that we read should not exceed about 50 bytes
16 // UBX support
17 //typedef struct { // not used I think
18 // uint8_t preamble1;
19 // uint8_t preamble2;
20 // uint8_t msg_class;
21 // uint8_t msg_id;
22 // uint16_t length;
23 //} ubx_header;
25 typedef struct {
26 uint32_t time; // GPS msToW
27 int32_t longitude; // in degree with 7 decimals
28 int32_t latitude; // in degree with 7 decimals
29 int32_t altitude_ellipsoid; // in mm
30 int32_t altitude_msl; // in mm
31 uint32_t horizontal_accuracy;
32 uint32_t vertical_accuracy; // in mm
33 } ubx_nav_posllh;
35 typedef struct {
36 uint32_t time; // GPS msToW
37 uint8_t fix_type;
38 uint8_t fix_status;
39 uint8_t differential_status;
40 uint8_t res;
41 uint32_t time_to_first_fix;
42 uint32_t uptime; // milliseconds
43 } ubx_nav_status;
45 typedef struct {
46 uint32_t time;
47 int32_t time_nsec;
48 int16_t week;
49 uint8_t fix_type;
50 uint8_t fix_status;
51 int32_t ecef_x;
52 int32_t ecef_y;
53 int32_t ecef_z;
54 uint32_t position_accuracy_3d;
55 int32_t ecef_x_velocity;
56 int32_t ecef_y_velocity;
57 int32_t ecef_z_velocity;
58 uint32_t speed_accuracy;
59 uint16_t position_DOP;
60 uint8_t res;
61 uint8_t satellites;
62 uint32_t res2;
63 } ubx_nav_solution;
65 typedef struct {
66 uint32_t time; // GPS msToW
67 int32_t ned_north;
68 int32_t ned_east;
69 int32_t ned_down;
70 uint32_t speed_3d;
71 uint32_t speed_2d;
72 int32_t heading_2d;
73 uint32_t speed_accuracy;
74 uint32_t heading_accuracy;
75 } ubx_nav_velned;
77 typedef struct {
78 uint8_t chn; // Channel number, 255 for SVx not assigned to channel
79 uint8_t svid; // Satellite ID
80 uint8_t flags; // Bitmask
81 uint8_t quality; // Bitfield
82 uint8_t cno; // Carrier to Noise Ratio (Signal Strength) // dbHz, 0-55.
83 uint8_t elev; // Elevation in integer degrees
84 int16_t azim; // Azimuth in integer degrees
85 int32_t prRes; // Pseudo range residual in centimetres
86 } ubx_nav_svinfo_channel;
88 typedef struct {
89 uint32_t time; // GPS Millisecond time of week
90 uint8_t numCh; // Number of channels
91 uint8_t globalFlags; // Bitmask, Chip hardware generation 0:Antaris, 1:u-blox 5, 2:u-blox 6
92 uint16_t reserved2; // Reserved
93 ubx_nav_svinfo_channel channel[16]; // 16 satellites * 12 byte
94 } ubx_nav_svinfo;
96 // GPS codes that could be used
97 #define PREAMBLE1 0xb5
98 #define PREAMBLE2 0x62
99 #define CLASS_NAV 0x01
100 #define CLASS_ACK 0x05
101 #define CLASS_CFG 0x06
102 #define MSG_ACK_NACK 0x00
103 #define MSG_ACK_ACK 0x01
104 #define MSG_POSLLH 0x2
105 #define MSG_STATUS 0x3
106 #define MSG_SOL 0x6
107 #define MSG_VELNED 0x12
108 #define MSG_SVINFO 0x30
109 #define MSG_CFG_PRT 0x00
110 #define MSG_CFG_RATE 0x08
111 #define MSG_CFG_SET_RATE 0x01
112 #define MSG_CFG_NAV_SETTINGS 0x24
114 #define FIX_NONE 0
115 #define FIX_DEAD_RECKONING 1
116 #define FIX_2D 2
117 #define FIX_3D 3
118 #define FIX_GPS_DEAD_RECKONING 4
119 #define FIX_TIME 5
121 #define NAV_STATUS_FIX_VALID 1
126 class OXS_GPS {
127 public:
128 #ifdef DEBUG
129 OXS_GPS( HardwareSerial &print);
130 #else
131 OXS_GPS( uint8_t x );
132 #endif
133 void setupGps() ;
134 void readGps();
135 // void OXS_GPS::_update_checksum(uint8_t *data, uint8_t len, uint8_t *ck_a, uint8_t *ck_b) ;
136 bool UBLOX_parse_gps(void) ;
137 bool gpsNewFrameUBLOX(uint8_t data) ;
140 private:
141 #ifdef DEBUG
142 HardwareSerial* printer;
143 #endif
150 #endif // OXS_GPS_h