[FLYWOOF411] add board documentation
[inav/snaewe.git] / src / main / io / gps.h
bloba7074997359b6da9efc29d3771a0fbe77e8d8a77
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>
22 #include "config/parameter_group.h"
24 #include "common/time.h"
26 #define GPS_DBHZ_MIN 0
27 #define GPS_DBHZ_MAX 55
29 #define LAT 0
30 #define LON 1
32 #define GPS_DEGREES_DIVIDER 10000000L
34 typedef enum {
35 GPS_NMEA = 0,
36 GPS_UBLOX,
37 GPS_I2CNAV,
38 GPS_NAZA,
39 GPS_UBLOX7PLUS,
40 GPS_MTK,
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_COUNT
62 } gpsBaudRate_e;
64 typedef enum {
65 GPS_AUTOCONFIG_OFF = 0,
66 GPS_AUTOCONFIG_ON,
67 } gpsAutoConfig_e;
69 typedef enum {
70 GPS_AUTOBAUD_OFF = 0,
71 GPS_AUTOBAUD_ON
72 } gpsAutoBaud_e;
74 typedef enum {
75 GPS_DYNMODEL_PEDESTRIAN = 0,
76 GPS_DYNMODEL_AIR_1G,
77 GPS_DYNMODEL_AIR_4G,
78 } gpsDynModel_e;
80 typedef enum {
81 GPS_NO_FIX = 0,
82 GPS_FIX_2D,
83 GPS_FIX_3D
84 } gpsFixType_e;
86 #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600
88 typedef struct gpsConfig_s {
89 gpsProvider_e provider;
90 sbasMode_e sbasMode;
91 gpsAutoConfig_e autoConfig;
92 gpsAutoBaud_e autoBaud;
93 gpsDynModel_e dynModel;
94 bool ubloxUseGalileo;
95 uint8_t gpsMinSats;
96 } gpsConfig_t;
98 PG_DECLARE(gpsConfig_t, gpsConfig);
100 typedef struct gpsCoordinateDDDMMmmmm_s {
101 int16_t dddmm;
102 int16_t mmmm;
103 } gpsCoordinateDDDMMmmmm_t;
105 /* LLH Location in NEU axis system */
106 typedef struct gpsLocation_s {
107 int32_t lat; // Latitude * 1e+7
108 int32_t lon; // Longitude * 1e+7
109 int32_t alt; // Altitude in centimeters (meters * 100)
110 } gpsLocation_t;
112 #define HDOP_SCALE (100)
114 typedef struct gpsSolutionData_s {
115 struct {
116 bool hasNewData;
117 bool gpsHeartbeat; // Toggle each update
118 bool validVelNE;
119 bool validVelD;
120 bool validMag;
121 bool validEPE; // EPH/EPV values are valid - actual accuracy
122 bool validTime;
123 } flags;
125 gpsFixType_e fixType;
126 uint8_t numSat;
128 gpsLocation_t llh;
129 int16_t magData[3];
130 int16_t velNED[3];
132 int16_t groundSpeed;
133 int16_t groundCourse;
135 uint16_t eph; // horizontal accuracy (cm)
136 uint16_t epv; // vertical accuracy (cm)
138 uint16_t hdop; // generic HDOP value (*HDOP_SCALE)
140 dateTime_t time; // GPS time in UTC
142 } gpsSolutionData_t;
144 typedef struct {
145 uint16_t lastMessageDt;
146 uint32_t errors; // gps error counter - crc error/lost of data/sync etc..
147 uint32_t timeouts;
148 uint32_t packetCount;
149 } gpsStatistics_t;
151 extern gpsSolutionData_t gpsSol;
152 extern gpsStatistics_t gpsStats;
154 struct magDev_s;
155 bool gpsMagDetect(struct magDev_s *mag);
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);