-
Notifications
You must be signed in to change notification settings - Fork 61
/
gps.d.ts
232 lines (206 loc) · 5.31 KB
/
gps.d.ts
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
export as namespace gps;
export = GPS;
declare class GPS {
state: GPS.GPSState;
/**
* The update method is the most important export function, it parses a NMEA sentence and forces the callbacks to trigger
* @param line NMEA string
* @returns is valid
*/
update(line: string): boolean;
/**
* Will call update() when a full NMEA sentence has been arrived
* @param chunk Partial NMEA string
*/
updatePartial(chunk: string): void;
/**
* Adds an event listener for a protocol to occur (see implemented protocols, simply use the name - upper case) or for all sentences with data.
* Because GPS.js should be more general, it doesn't inherit EventEmitter, but simply invokes the callback.
* @param event Event type
* @param callback Callback with data
* @returns GPS instance
*/
on(event: string, callback: (data: any) => void): GPS;
/**
* Removes an event listener
* @param event Event type
* @returns GPS instance
*/
off(event: string): GPS;
/**
* Parses a single line and returns the resulting object, in case the callback system isn't needed/wanted
* @param line NMEA string
* @returns NMEA object or False
*/
static Parse<T = any>(line: string): false | T;
/**
* Calculates the distance between two geo-coordinates using Haversine formula
* @param latFrom
* @param lonFrom
* @param latTo
* @param lonTo
* @returns Distance in km
*/
static Distance(
latFrom: number,
lonFrom: number,
latTo: number,
lonTo: number
): number;
/**
* Calculates the length of a traveled route, given as an array of {lat: x, lon: y} point objects
* @param points Array of {lat: x, lon: y}
* @returns Distance in km
*/
static TotalDistance(points: GPS.LatLon[]): number;
/**
* Calculates the angle from one coordinate to another. Heading is represented as windrose coordinates (N=0, E=90, S=189, W=270)
* @param latFrom
* @param lonFrom
* @param latTo
* @param lonTo
* @returns Heading in degrees
*/
static Heading(
latFrom: number,
lonFrom: number,
latTo: number,
lonTo: number
): number;
}
declare namespace GPS {
export interface LatLon {
lat: number;
lon: number;
}
export interface GPSState {
[key: string]: any;
processed: number;
errors: number;
time?: Date;
lat?: number;
lon?: number;
alt?: number;
speed?: number;
track?: number;
satsActive?: number[];
satsVisible?: Satellite[];
}
export interface GGA {
time: Date;
lat: number;
lon: number;
alt: number;
quality?: GGAQuality;
satellites: number;
hdop: number;
geoidal: number;
age: number;
stationID: number;
raw: string;
valid: boolean;
type: 'GGA';
}
export enum GGAQuality {
'fix' = 1,
'dgps-fix' = 2,
'pps-fix' = 3,
'rtk' = 4,
'rtk-float' = 5,
'estimated' = 6,
'manual' = 7,
'simulated' = 8
}
export interface GSA {
mode?: 'manual'|'automatic';
fix?: '2D'|'3D';
satellites: number[];
pdop: number;
hdop: number;
vdop: number;
raw: string;
valid: boolean;
type: 'GSA';
}
export interface RMC {
time: Date;
status?: 'active'|'void';
lat: number;
lon: number;
speed: number;
track: number;
variation: number;
faa: FAA;
raw: string;
valid: boolean;
type: 'RMC';
}
export interface VTG {
track: number;
trackMagnetic: number;
speed: number;
faa: FAA;
raw: string;
valid: boolean;
type: 'VTG';
}
export enum FAA {
'autonomous' = 'A',
'differential' = 'D',
'estimated' = 'E',
'manual input' = 'M',
'simulated' = 'S',
'not valid' = 'N',
'precise' = 'P'
}
export interface GSV {
msgNumber: number;
msgsTotal: number;
satellites: Satellite[];
raw: string;
valid: boolean;
type: 'GSV';
}
export interface Satellite {
prn: number;
elevation: number;
azimuth: number;
snr: number;
status: string;
}
export interface GLL {
time: Date;
status?: 'active'|'void';
lat: number;
lon: number;
raw: string;
valid: boolean;
type: 'GLL';
}
export interface ZDA {
time: Date;
raw: string;
valid: boolean;
type: 'ZDA';
}
export interface GST {
time: Date;
rms: number;
ellipseMajor: number;
ellipseMinor: number;
ellipseOrientation: number;
latitudeError: number;
longitudeError: number;
heightError: number;
raw: string;
valid: boolean;
type: 'GST';
}
export interface HDT {
heading: number;
trueNorth: boolean;
raw: string;
valid: boolean;
type: 'HDT';
}
}