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)
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/>.
23 #include "common/axis.h"
24 #include "common/time.h"
31 #define GPS_DEGREES_DIVIDER 10000000L
48 #define SBAS_MODE_MAX SBAS_GAGAN
51 GPS_BAUDRATE_115200
= 0,
59 GPS_AUTOCONFIG_OFF
= 0,
68 #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600
70 typedef struct gpsConfig_s
{
71 gpsProvider_e provider
;
73 gpsAutoConfig_e autoConfig
;
74 gpsAutoBaud_e autoBaud
;
77 PG_DECLARE(gpsConfig_t
, gpsConfig
);
79 typedef struct gpsCoordinateDDDMMmmmm_s
{
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
91 typedef struct gpsSolutionData_s
{
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)
101 GPS_MESSAGE_STATE_IDLE
= 0,
102 GPS_MESSAGE_STATE_INIT
,
103 GPS_MESSAGE_STATE_SBAS
,
104 GPS_MESSAGE_STATE_ENTRY_COUNT
107 typedef struct gpsData_s
{
108 uint32_t errors
; // gps error counter - crc error/lost of data/sync etc..
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
;
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
;
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
155 void gpsUpdate(timeUs_t currentTimeUs
);
156 bool gpsNewFrame(uint8_t c
);
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
);