Removed excess trailing spaces before new lines on licenses.
[betaflight.git] / src / main / io / gps.h
blob4b8cf045fb623e66c6f9f24324183b845d3f3a1b
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "common/axis.h"
24 #include "common/time.h"
26 #include "pg/pg.h"
28 #define LAT 0
29 #define LON 1
31 #define GPS_DEGREES_DIVIDER 10000000L
32 #define GPS_X 1
33 #define GPS_Y 0
35 typedef enum {
36 GPS_NMEA = 0,
37 GPS_UBLOX
38 } gpsProvider_e;
40 typedef enum {
41 SBAS_AUTO = 0,
42 SBAS_EGNOS,
43 SBAS_WAAS,
44 SBAS_MSAS,
45 SBAS_GAGAN
46 } sbasMode_e;
48 #define SBAS_MODE_MAX SBAS_GAGAN
50 typedef enum {
51 GPS_BAUDRATE_115200 = 0,
52 GPS_BAUDRATE_57600,
53 GPS_BAUDRATE_38400,
54 GPS_BAUDRATE_19200,
55 GPS_BAUDRATE_9600
56 } gpsBaudRate_e;
58 typedef enum {
59 GPS_AUTOCONFIG_OFF = 0,
60 GPS_AUTOCONFIG_ON
61 } gpsAutoConfig_e;
63 typedef enum {
64 GPS_AUTOBAUD_OFF = 0,
65 GPS_AUTOBAUD_ON
66 } gpsAutoBaud_e;
68 #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600
70 typedef struct gpsConfig_s {
71 gpsProvider_e provider;
72 sbasMode_e sbasMode;
73 gpsAutoConfig_e autoConfig;
74 gpsAutoBaud_e autoBaud;
75 } gpsConfig_t;
77 PG_DECLARE(gpsConfig_t, gpsConfig);
79 typedef struct gpsCoordinateDDDMMmmmm_s {
80 int16_t dddmm;
81 int16_t mmmm;
82 } gpsCoordinateDDDMMmmmm_t;
84 /* LLH Location in NEU axis system */
85 typedef struct gpsLocation_s {
86 int32_t lat; // latitude * 1e+7
87 int32_t lon; // longitude * 1e+7
88 uint16_t alt; // altitude in 0.1m
89 } gpsLocation_t;
91 typedef struct gpsSolutionData_s {
92 gpsLocation_t llh;
93 uint16_t GPS_altitude; // altitude in 0.1m
94 uint16_t groundSpeed; // speed in 0.1m/s
95 uint16_t groundCourse; // degrees * 10
96 uint16_t hdop; // generic HDOP value (*100)
97 uint8_t numSat;
98 } gpsSolutionData_t;
100 typedef enum {
101 GPS_MESSAGE_STATE_IDLE = 0,
102 GPS_MESSAGE_STATE_INIT,
103 GPS_MESSAGE_STATE_SBAS,
104 GPS_MESSAGE_STATE_ENTRY_COUNT
105 } gpsMessageState_e;
107 typedef struct gpsData_s {
108 uint32_t errors; // gps error counter - crc error/lost of data/sync etc..
109 uint32_t timeouts;
110 uint32_t lastMessage; // last time valid GPS data was received (millis)
111 uint32_t lastLastMessage; // last-last valid GPS message. Used to calculate delta.
113 uint32_t state_position; // incremental variable for loops
114 uint32_t state_ts; // timestamp for last state_position increment
115 uint8_t state; // GPS thread state. Used for detecting cable disconnects and configuring attached devices
116 uint8_t baudrateIndex; // index into auto-detecting or current baudrate
117 gpsMessageState_e messageState;
118 } gpsData_t;
120 #define GPS_PACKET_LOG_ENTRY_COUNT 21 // To make this useful we should log as many packets as we can fit characters a single line of a OLED display.
121 extern char gpsPacketLog[GPS_PACKET_LOG_ENTRY_COUNT];
123 extern int32_t GPS_home[2];
124 extern uint16_t GPS_distanceToHome; // distance to home point in meters
125 extern int16_t GPS_directionToHome; // direction to home or hol point in degrees
126 extern int16_t GPS_angle[ANGLE_INDEX_COUNT]; // it's the angles that must be applied for GPS correction
127 extern float dTnav; // Delta Time in milliseconds for navigation computations, updated with every good GPS read
128 extern float GPS_scaleLonDown; // this is used to offset the shrinking longitude as we go towards the poles
129 extern int16_t actual_speed[2];
130 extern int16_t nav_takeoff_bearing;
131 // navigation mode
132 typedef enum {
133 NAV_MODE_NONE = 0,
134 NAV_MODE_POSHOLD,
135 NAV_MODE_WP
136 } navigationMode_e;
137 extern navigationMode_e nav_mode; // Navigation mode
139 extern gpsData_t gpsData;
140 extern gpsSolutionData_t gpsSol;
142 extern uint8_t GPS_update; // it's a binary toogle to distinct a GPS position update
143 extern uint32_t GPS_packetCount;
144 extern uint32_t GPS_svInfoReceivedCount;
145 extern uint8_t GPS_numCh; // Number of channels
146 extern uint8_t GPS_svinfo_chn[16]; // Channel number
147 extern uint8_t GPS_svinfo_svid[16]; // Satellite ID
148 extern uint8_t GPS_svinfo_quality[16]; // Bitfield Qualtity
149 extern uint8_t GPS_svinfo_cno[16]; // Carrier to Noise Ratio (Signal Strength)
151 #define GPS_DBHZ_MIN 0
152 #define GPS_DBHZ_MAX 55
154 void gpsInit(void);
155 void gpsUpdate(timeUs_t currentTimeUs);
156 bool gpsNewFrame(uint8_t c);
157 struct serialPort_s;
158 void gpsEnablePassthrough(struct serialPort_s *gpsPassthroughPort);
159 void onGpsNewData(void);
160 void GPS_reset_home_position(void);
161 void GPS_calc_longitude_scaling(int32_t lat);
162 void navNewGpsData(void);
163 void GPS_distance_cm_bearing(int32_t *currentLat1, int32_t *currentLon1, int32_t *destinationLat2, int32_t *destinationLon2, uint32_t *dist, int32_t *bearing);