-
Notifications
You must be signed in to change notification settings - Fork 6
/
tinygps.h
108 lines (86 loc) · 3.38 KB
/
tinygps.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
TinyGPS - a small GPS library for Arduino providing basic NMEA parsing
Based on work by and "distance_to" and "course_to" courtesy of Maarten Lamers.
Suggestion to add satellites(), course_to(), and cardinal(), by Matt Monson.
Copyright (C) 2008-2012 Mikal Hart
All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef tinygps_h
#define tinygps_h
typedef char bool;
typedef unsigned char byte;
#define false 0
#define true 1
#define PI 3.14159265
#define TWO_PI 2*PI
#define sq(x) ((x)*(x))
#define GPRMC_TERM "GPRMC"
#define GPGGA_TERM "GPGGA"
#define GPS_INVALID_F_ANGLE 1000.0
#define GPS_INVALID_F_ALTITUDE 1000000.0
#define GPS_INVALID_F_SPEED -1.0
#define GPS_VERSION 12 // software version of this library
#define GPS_MPH_PER_KNOT 1.15077945
#define GPS_MPS_PER_KNOT 0.51444444
#define GPS_KMPH_PER_KNOT 1.852
#define GPS_MILES_PER_METER 0.00062137112
#define GPS_KM_PER_METER 0.001
// #define GPS_NO_STATS
enum {
GPS_INVALID_AGE = 0xFFFFFFFF,
GPS_INVALID_ANGLE = 999999999,
GPS_INVALID_ALTITUDE = 999999999,
GPS_INVALID_DATE = 0,
GPS_INVALID_TIME = 0xFFFFFFFF,
GPS_INVALID_SPEED = 999999999,
GPS_INVALID_FIX_TIME = 0xFFFFFFFF,
GPS_INVALID_SATELLITES = 0xFF,
GPS_INVALID_HDOP = 0xFFFFFFFF
};
// process one character received from GPS
bool encode(char c);
// lat/long in hundred thousandths of a degree and age of fix in milliseconds
void gps_get_position(long *latitude, long *longitude, unsigned long *fix_age);
// date as ddmmyy, time as hhmmsscc, and age in milliseconds
void gps_get_datetime(unsigned long *date, unsigned long *time, unsigned long *age);
void gps_f_get_position(float *latitude, float *longitude, unsigned long *fix_age);
void gps_crack_datetime(int *year, byte *month, byte *day,
byte *hour, byte *minute, byte *second, byte *hundredths, unsigned long *fix_age);
float gps_f_altitude();
float gps_f_course();
float gps_f_speed_knots();
float gps_f_speed_mph();
float gps_f_speed_mps();
float gps_f_speed_kmph();
static int library_version() { return GPS_VERSION; }
static float gps_distance_between (float lat1, float long1, float lat2, float long2);
static float gps_course_to (float lat1, float long1, float lat2, float long2);
static const char *gps_cardinal(float course);
#ifndef GPS_NO_STATS
void gps_stats(unsigned long *chars, unsigned short *good_sentences, unsigned short *failed_cs);
#endif
enum {
GPS_SENTENCE_GPGGA,
GPS_SENTENCE_GPRMC,
GPS_SENTENCE_OTHER
};
// internal utilities
int from_hex(char a);
unsigned long gps_parse_decimal();
unsigned long gps_parse_degrees();
bool gps_term_complete();
bool gpsisdigit(char c);
long gpsatol(const char *str);
int gpsstrcmp(const char *str1, const char *str2);
#endif