NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gps.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight 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.
8  *
9  * Ninjaflight 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #include "../config/gps.h"
21 #include "../system_calls.h"
22 #include "../drivers/serial.h"
23 
24 #define LAT 0
25 #define LON 1
26 
27 #define GPS_DEGREES_DIVIDER 10000000L
28 #define SBAS_MODE_MAX SBAS_GAGAN
29 
30 typedef enum {
37 
38 #define GPS_BAUDRATE_MAX GPS_BAUDRATE_9600
39 typedef struct gpsCoordinateDDDMMmmmm_s {
40  int16_t dddmm;
41  int16_t mmmm;
43 
44 
45 typedef enum {
51 
52 #define GPS_MESSAGE_STATE_ENTRY_COUNT (GPS_MESSAGE_STATE_MAX + 1)
53 
54 typedef struct gpsData_s {
55  uint8_t state; // GPS thread state. Used for detecting cable disconnects and configuring attached devices
56  uint8_t baudrateIndex; // index into auto-detecting or current baudrate
57  uint32_t errors; // gps error counter - crc error/lost of data/sync etc..
58  uint32_t timeouts;
59  uint32_t lastMessage; // last time valid GPS data was received (millis)
60  uint32_t lastLastMessage; // last-last valid GPS message. Used to calculate delta.
61 
62  uint32_t state_position; // incremental variable for loops
63  sys_millis_t state_ts; // timestamp for last state_position increment
65 } gpsData_t;
66 
67 #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.
68 
69 struct gps {
72 
74  int32_t GPS_coord[2]; // LAT/LON
75 
76  uint8_t GPS_numSat;
77  uint16_t GPS_hdop; // GPS signal quality
78  uint8_t GPS_update; // it's a binary toogle to distinct a GPS position update
79  uint32_t GPS_packetCount;
81  uint16_t GPS_altitude; // altitude in 0.1m
82  uint16_t GPS_speed; // speed in 0.1m/s
83  uint16_t GPS_ground_course; // degrees * 10
84  uint8_t GPS_numCh; // Number of channels
85  uint8_t GPS_svinfo_chn[16]; // Channel number
86  uint8_t GPS_svinfo_svid[16]; // Satellite ID
87  uint8_t GPS_svinfo_quality[16]; // Bitfield Qualtity
88  uint8_t GPS_svinfo_cno[16]; // Carrier to Noise Ratio (Signal Strength)
89 
91 
93  const struct system_calls *system;
94  const struct config *config;
95 };
96 
97 #define GPS_DBHZ_MIN 0
98 #define GPS_DBHZ_MAX 55
99 
100 int gps_init(struct gps *self, const struct system_calls *system, const struct config *config);
101 
102 void gps_enable_passthrough(struct gps *self, struct serialPort_s *gpsPassthroughPort);
103 void gps_update(struct gps *self);
104 bool gps_process_char(struct gps *self, uint8_t c);
gpsData_t gpsData
Definition: gps.h:73
uint32_t timeouts
Definition: gps.h:58
uint8_t GPS_svinfo_quality[16]
Definition: gps.h:87
Definition: config.h:81
uint32_t GPS_garbageByteCount
Definition: gps.h:90
gpsBaudRate_e
Definition: gps.h:30
serialPort_t * gpsPort
Definition: gps.h:92
uint16_t GPS_hdop
Definition: gps.h:77
void gps_enable_passthrough(struct gps *self, struct serialPort_s *gpsPassthroughPort)
Definition: gps.c:1021
Definition: gps.h:47
Definition: gps.h:69
struct gpsData_s gpsData_t
struct gpsCoordinateDDDMMmmmm_s gpsCoordinateDDDMMmmmm_t
Definition: gps.h:48
Definition: gps.h:46
uint32_t GPS_svInfoReceivedCount
Definition: gps.h:80
uint32_t GPS_packetCount
Definition: gps.h:79
uint8_t GPS_svinfo_cno[16]
Definition: gps.h:88
sys_millis_t state_ts
Definition: gps.h:63
const struct system_calls * system
Definition: gps.h:93
uint32_t lastLastMessage
Definition: gps.h:60
Definition: gps.h:49
const struct config * config
Definition: gps.h:94
Definition: gps.h:31
Definition: gps.h:34
int32_t GPS_coord[2]
Definition: gps.h:74
struct system_config system
Definition: config.h:99
int16_t dddmm
Definition: gps.h:40
int32_t sys_millis_t
Definition: system_calls.h:6
Definition: gps.h:33
gpsMessageState_e
Definition: gps.h:45
Definition: gps.h:35
uint32_t lastMessage
Definition: gps.h:59
uint16_t GPS_altitude
Definition: gps.h:81
uint8_t GPS_numSat
Definition: gps.h:76
Definition: gps.h:39
uint32_t errors
Definition: gps.h:57
Definition: gps.h:54
int16_t mmmm
Definition: gps.h:41
uint8_t GPS_update
Definition: gps.h:78
Definition: gps.h:32
gpsMessageState_e messageState
Definition: gps.h:64
uint8_t state
Definition: gps.h:55
void gps_update(struct gps *self)
Definition: gps.c:325
bool gps_process_char(struct gps *self, uint8_t c)
uint16_t GPS_speed
Definition: gps.h:82
uint8_t GPS_svinfo_chn[16]
Definition: gps.h:85
Definition: system_calls.h:200
int gps_init(struct gps *self, const struct system_calls *system, const struct config *config)
Definition: gps.c:169
uint32_t state_position
Definition: gps.h:62
char * gpsPacketLogChar
Definition: gps.h:71
uint8_t baudrateIndex
Definition: gps.h:56
uint16_t GPS_ground_course
Definition: gps.h:83
char gpsPacketLog[GPS_PACKET_LOG_ENTRY_COUNT]
Definition: gps.h:70
uint8_t GPS_numCh
Definition: gps.h:84
uint8_t GPS_svinfo_svid[16]
Definition: gps.h:86
#define GPS_PACKET_LOG_ENTRY_COUNT
Definition: gps.h:67
Definition: serial.h:43