Merge pull request #8806 from iNavFlight/MrD_OSD-Throttle-Options
[inav.git] / src / main / io / gps.h
blob92241c95602259926fd8117c08b92a9d92401e94
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #pragma once
20 #include <stdbool.h>
21 #include <time.h>
23 #include "config/parameter_group.h"
25 #include "common/time.h"
27 #define GPS_DBHZ_MIN 0
28 #define GPS_DBHZ_MAX 55
30 #define LAT 0
31 #define LON 1
33 #define GPS_DEGREES_DIVIDER 10000000L
35 typedef enum {
36 GPS_NMEA = 0,
37 GPS_UBLOX,
38 GPS_UBLOX7PLUS,
39 GPS_MSP,
40 GPS_FAKE,
41 GPS_PROVIDER_COUNT
42 } gpsProvider_e;
44 typedef enum {
45 SBAS_AUTO = 0,
46 SBAS_EGNOS,
47 SBAS_WAAS,
48 SBAS_MSAS,
49 SBAS_GAGAN,
50 SBAS_NONE
51 } sbasMode_e;
53 #define SBAS_MODE_MAX SBAS_GAGAN
55 typedef enum {
56 GPS_BAUDRATE_115200 = 0,
57 GPS_BAUDRATE_57600,
58 GPS_BAUDRATE_38400,
59 GPS_BAUDRATE_19200,
60 GPS_BAUDRATE_9600,
61 GPS_BAUDRATE_230400,
62 GPS_BAUDRATE_COUNT
63 } gpsBaudRate_e;
65 typedef enum {
66 GPS_AUTOCONFIG_OFF = 0,
67 GPS_AUTOCONFIG_ON,
68 } gpsAutoConfig_e;
70 typedef enum {
71 GPS_AUTOBAUD_OFF = 0,
72 GPS_AUTOBAUD_ON
73 } gpsAutoBaud_e;
75 typedef enum {
76 GPS_DYNMODEL_PEDESTRIAN = 0,
77 GPS_DYNMODEL_AIR_1G,
78 GPS_DYNMODEL_AIR_4G,
79 } gpsDynModel_e;
81 typedef enum {
82 GPS_NO_FIX = 0,
83 GPS_FIX_2D,
84 GPS_FIX_3D
85 } gpsFixType_e;
87 #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600
89 typedef struct gpsConfig_s {
90 gpsProvider_e provider;
91 sbasMode_e sbasMode;
92 gpsAutoConfig_e autoConfig;
93 gpsAutoBaud_e autoBaud;
94 gpsDynModel_e dynModel;
95 bool ubloxUseGalileo;
96 uint8_t gpsMinSats;
97 } gpsConfig_t;
99 PG_DECLARE(gpsConfig_t, gpsConfig);
101 typedef struct gpsCoordinateDDDMMmmmm_s {
102 int16_t dddmm;
103 int16_t mmmm;
104 } gpsCoordinateDDDMMmmmm_t;
106 /* LLH Location in NEU axis system */
107 typedef struct gpsLocation_s {
108 int32_t lat; // Latitude * 1e+7
109 int32_t lon; // Longitude * 1e+7
110 int32_t alt; // Altitude in centimeters (meters * 100)
111 } gpsLocation_t;
113 #define HDOP_SCALE (100)
115 typedef struct gpsSolutionData_s {
116 struct {
117 bool hasNewData;
118 bool gpsHeartbeat; // Toggle each update
119 bool validVelNE;
120 bool validVelD;
121 bool validMag;
122 bool validEPE; // EPH/EPV values are valid - actual accuracy
123 bool validTime;
124 } flags;
126 gpsFixType_e fixType;
127 uint8_t numSat;
129 gpsLocation_t llh;
130 int16_t magData[3];
131 int16_t velNED[3];
133 int16_t groundSpeed;
134 int16_t groundCourse;
136 uint16_t eph; // horizontal accuracy (cm)
137 uint16_t epv; // vertical accuracy (cm)
139 uint16_t hdop; // generic HDOP value (*HDOP_SCALE)
141 dateTime_t time; // GPS time in UTC
143 } gpsSolutionData_t;
145 typedef struct {
146 uint16_t lastMessageDt;
147 uint32_t errors; // gps error counter - crc error/lost of data/sync etc..
148 uint32_t timeouts;
149 uint32_t packetCount;
150 } gpsStatistics_t;
152 extern gpsSolutionData_t gpsSol;
153 extern gpsStatistics_t gpsStats;
155 struct magDev_s;
156 void gpsPreInit(void);
157 void gpsInit(void);
158 // Called periodically from GPS task. Returns true iff the GPS
159 // information was updated.
160 bool gpsUpdate(void);
161 void updateGpsIndicator(timeUs_t currentTimeUs);
162 bool isGPSHealthy(void);
163 bool isGPSHeadingValid(void);
164 struct serialPort_s;
165 void gpsEnablePassthrough(struct serialPort_s *gpsPassthroughPort);
166 void mspGPSReceiveNewData(const uint8_t * bufferPtr);
168 #if defined(USE_GPS_FAKE)
169 void gpsFakeSet(
170 gpsFixType_e fixType,
171 uint8_t numSat,
172 int32_t lat,
173 int32_t lon,
174 int32_t alt,
175 int16_t groundSpeed,
176 int16_t groundCourse,
177 int16_t velNED_X,
178 int16_t velNED_Y,
179 int16_t velNED_Z,
180 time_t time);
181 #endif