Removing TODOs.
[betaflight.git] / src / main / io / gps.h
blob18063ae314b04b3eed670033bd4569858e4b1848
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 #define LAT 0
21 #define LON 1
23 #define GPS_DEGREES_DIVIDER 10000000L
25 typedef enum {
26 GPS_NMEA = 0,
27 GPS_UBLOX
28 } gpsProvider_e;
30 #define GPS_PROVIDER_MAX GPS_UBLOX
32 typedef enum {
33 SBAS_AUTO = 0,
34 SBAS_EGNOS,
35 SBAS_WAAS,
36 SBAS_MSAS,
37 SBAS_GAGAN
38 } sbasMode_e;
40 #define SBAS_MODE_MAX SBAS_GAGAN
42 typedef enum {
43 GPS_BAUDRATE_115200 = 0,
44 GPS_BAUDRATE_57600,
45 GPS_BAUDRATE_38400,
46 GPS_BAUDRATE_19200,
47 GPS_BAUDRATE_9600
48 } gpsBaudRate_e;
50 typedef enum {
51 GPS_AUTOCONFIG_OFF = 0,
52 GPS_AUTOCONFIG_ON,
53 } gpsAutoConfig_e;
55 typedef enum {
56 GPS_AUTOBAUD_OFF = 0,
57 GPS_AUTOBAUD_ON
58 } gpsAutoBaud_e;
60 #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600
62 typedef struct gpsConfig_s {
63 gpsProvider_e provider;
64 sbasMode_e sbasMode;
65 gpsAutoConfig_e autoConfig;
66 gpsAutoBaud_e autoBaud;
67 } gpsConfig_t;
69 typedef enum {
70 GPS_PASSTHROUGH_ENABLED = 1,
71 GPS_PASSTHROUGH_NO_SERIAL_PORT
72 } gpsEnablePassthroughResult_e;
74 typedef struct gpsCoordinateDDDMMmmmm_s {
75 int16_t dddmm;
76 int16_t mmmm;
77 } gpsCoordinateDDDMMmmmm_t;
80 typedef enum {
81 GPS_MESSAGE_STATE_IDLE = 0,
82 GPS_MESSAGE_STATE_INIT,
83 GPS_MESSAGE_STATE_SBAS,
84 GPS_MESSAGE_STATE_MAX = GPS_MESSAGE_STATE_SBAS
85 } gpsMessageState_e;
87 #define GPS_MESSAGE_STATE_ENTRY_COUNT (GPS_MESSAGE_STATE_MAX + 1)
89 typedef struct gpsData_t {
90 uint8_t state; // GPS thread state. Used for detecting cable disconnects and configuring attached devices
91 uint8_t baudrateIndex; // index into auto-detecting or current baudrate
92 uint32_t errors; // gps error counter - crc error/lost of data/sync etc..
93 uint32_t timeouts;
94 uint32_t lastMessage; // last time valid GPS data was received (millis)
95 uint32_t lastLastMessage; // last-last valid GPS message. Used to calculate delta.
97 uint32_t state_position; // incremental variable for loops
98 uint32_t state_ts; // timestamp for last state_position increment
99 gpsMessageState_e messageState;
100 } gpsData_t;
102 #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.
103 extern char gpsPacketLog[GPS_PACKET_LOG_ENTRY_COUNT];
105 extern gpsData_t gpsData;
106 extern int32_t GPS_coord[2]; // LAT/LON
108 extern uint8_t GPS_numSat;
109 extern uint16_t GPS_hdop; // GPS signal quality
110 extern uint8_t GPS_update; // it's a binary toogle to distinct a GPS position update
111 extern uint32_t GPS_packetCount;
112 extern uint16_t GPS_altitude; // altitude in 0.1m
113 extern uint16_t GPS_speed; // speed in 0.1m/s
114 extern uint16_t GPS_ground_course; // degrees * 10
115 extern uint8_t GPS_numCh; // Number of channels
116 extern uint8_t GPS_svinfo_chn[16]; // Channel number
117 extern uint8_t GPS_svinfo_svid[16]; // Satellite ID
118 extern uint8_t GPS_svinfo_quality[16]; // Bitfield Qualtity
119 extern uint8_t GPS_svinfo_cno[16]; // Carrier to Noise Ratio (Signal Strength)
121 #define GPS_DBHZ_MIN 0
122 #define GPS_DBHZ_MAX 55
125 void gpsThread(void);
126 bool gpsNewFrame(uint8_t c);
127 gpsEnablePassthroughResult_e gpsEnablePassthrough(void);
128 void updateGpsIndicator(uint32_t currentTime);