Merge pull request #9890 from iNavFlight/MrD_Add-extra-description-to-the-min-ground...
[inav.git] / src / main / io / gps.h
blob3e9d073c54ca02f6055f3f0ada6c7d2c4994b30f
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_UBLOX = 0,
37 GPS_UBLOX7PLUS,
38 GPS_MSP,
39 GPS_FAKE,
40 GPS_PROVIDER_COUNT
41 } gpsProvider_e;
43 typedef enum {
44 SBAS_AUTO = 0,
45 SBAS_EGNOS,
46 SBAS_WAAS,
47 SBAS_MSAS,
48 SBAS_GAGAN,
49 SBAS_SPAN,
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_460800,
63 GPS_BAUDRATE_921600,
64 GPS_BAUDRATE_COUNT
65 } gpsBaudRate_e;
67 typedef enum {
68 GPS_AUTOCONFIG_OFF = 0,
69 GPS_AUTOCONFIG_ON,
70 } gpsAutoConfig_e;
72 typedef enum {
73 GPS_AUTOBAUD_OFF = 0,
74 GPS_AUTOBAUD_ON
75 } gpsAutoBaud_e;
77 typedef enum {
78 GPS_DYNMODEL_PEDESTRIAN = 0,
79 GPS_DYNMODEL_AUTOMOTIVE,
80 GPS_DYNMODEL_AIR_1G,
81 GPS_DYNMODEL_AIR_2G,
82 GPS_DYNMODEL_AIR_4G,
83 } gpsDynModel_e;
85 typedef enum {
86 GPS_NO_FIX = 0,
87 GPS_FIX_2D,
88 GPS_FIX_3D
89 } gpsFixType_e;
91 #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600
93 typedef struct gpsConfig_s {
94 gpsProvider_e provider;
95 sbasMode_e sbasMode;
96 gpsAutoConfig_e autoConfig;
97 gpsAutoBaud_e autoBaud;
98 gpsDynModel_e dynModel;
99 bool ubloxUseGalileo;
100 bool ubloxUseBeidou;
101 bool ubloxUseGlonass;
102 uint8_t gpsMinSats;
103 uint8_t ubloxNavHz;
104 gpsBaudRate_e autoBaudMax;
105 } gpsConfig_t;
107 PG_DECLARE(gpsConfig_t, gpsConfig);
109 typedef struct gpsCoordinateDDDMMmmmm_s {
110 int16_t dddmm;
111 int16_t mmmm;
112 } gpsCoordinateDDDMMmmmm_t;
114 /* LLH Location in NEU axis system */
115 typedef struct gpsLocation_s {
116 int32_t lat; // Latitude * 1e+7
117 int32_t lon; // Longitude * 1e+7
118 int32_t alt; // Altitude in centimeters (meters * 100)
119 } gpsLocation_t;
121 #define HDOP_SCALE (100)
123 typedef struct gpsSolutionData_s {
124 struct {
125 bool hasNewData;
126 bool gpsHeartbeat; // Toggle each update
127 bool validVelNE;
128 bool validVelD;
129 bool validMag;
130 bool validEPE; // EPH/EPV values are valid - actual accuracy
131 bool validTime;
132 } flags;
134 gpsFixType_e fixType;
135 uint8_t numSat;
137 gpsLocation_t llh;
138 int16_t magData[3];
139 int16_t velNED[3];
141 int16_t groundSpeed;
142 int16_t groundCourse;
144 uint16_t eph; // horizontal accuracy (cm)
145 uint16_t epv; // vertical accuracy (cm)
147 uint16_t hdop; // generic HDOP value (*HDOP_SCALE)
149 dateTime_t time; // GPS time in UTC
151 } gpsSolutionData_t;
153 typedef struct {
154 uint16_t lastMessageDt;
155 uint32_t errors; // gps error counter - crc error/lost of data/sync etc..
156 uint32_t timeouts;
157 uint32_t packetCount;
158 } gpsStatistics_t;
160 extern gpsSolutionData_t gpsSol;
161 extern gpsStatistics_t gpsStats;
163 struct magDev_s;
164 void gpsPreInit(void);
165 void gpsInit(void);
166 // Called periodically from GPS task. Returns true iff the GPS
167 // information was updated.
168 bool gpsUpdate(void);
169 void updateGpsIndicator(timeUs_t currentTimeUs);
170 bool isGPSHealthy(void);
171 bool isGPSHeadingValid(void);
172 struct serialPort_s;
173 void gpsEnablePassthrough(struct serialPort_s *gpsPassthroughPort);
174 void mspGPSReceiveNewData(const uint8_t * bufferPtr);
176 const char *getGpsHwVersion(void);
177 uint8_t getGpsProtoMajorVersion(void);
178 uint8_t getGpsProtoMinorVersion(void);
180 int getGpsBaudrate(void);
181 int gpsBaudRateToInt(gpsBaudRate_e baudrate);
183 #if defined(USE_GPS_FAKE)
184 void gpsFakeSet(
185 gpsFixType_e fixType,
186 uint8_t numSat,
187 int32_t lat,
188 int32_t lon,
189 int32_t alt,
190 int16_t groundSpeed,
191 int16_t groundCourse,
192 int16_t velNED_X,
193 int16_t velNED_Y,
194 int16_t velNED_Z,
195 time_t time);
196 #endif