nmea-web-serial 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +0 -0
- package/dist/nmea-web-serial.cjs +4 -0
- package/dist/nmea-web-serial.d.ts +1421 -0
- package/dist/nmea-web-serial.iife.js +4 -0
- package/dist/nmea-web-serial.js +3858 -0
- package/dist/nmea-web-serial.umd.cjs +4 -0
- package/package.json +72 -0
|
@@ -0,0 +1,1421 @@
|
|
|
1
|
+
import { ActionFunction } from 'xstate';
|
|
2
|
+
import { ActorRef } from 'xstate';
|
|
3
|
+
import { ActorRefFrom } from 'xstate';
|
|
4
|
+
import { ActorRefFromLogic } from 'xstate';
|
|
5
|
+
import { AnyActorRef } from 'xstate';
|
|
6
|
+
import { AnyEventObject } from 'xstate';
|
|
7
|
+
import { CallbackActorLogic } from 'xstate';
|
|
8
|
+
import { DBTPacket } from 'nmea-simple';
|
|
9
|
+
import { DoneActorEvent } from 'xstate';
|
|
10
|
+
import { ErrorActorEvent } from 'xstate';
|
|
11
|
+
import { EventObject } from 'xstate';
|
|
12
|
+
import { GGAPacket } from 'nmea-simple';
|
|
13
|
+
import { GLLPacket } from 'nmea-simple';
|
|
14
|
+
import { HDGPacket } from 'nmea-simple';
|
|
15
|
+
import { HDMPacket } from 'nmea-simple';
|
|
16
|
+
import { HDTPacket } from 'nmea-simple';
|
|
17
|
+
import { MachineSnapshot } from 'xstate';
|
|
18
|
+
import { MetaObject } from 'xstate';
|
|
19
|
+
import { NonReducibleUnknown } from 'xstate';
|
|
20
|
+
import { Packet } from 'nmea-simple';
|
|
21
|
+
import { PacketStub } from 'nmea-simple/dist/codecs/PacketStub';
|
|
22
|
+
import { PromiseActorLogic } from 'xstate';
|
|
23
|
+
import { RMCPacket } from 'nmea-simple';
|
|
24
|
+
import { StateMachine } from 'xstate';
|
|
25
|
+
import { StateValue } from 'xstate';
|
|
26
|
+
import { UnknownPacket } from 'nmea-simple/dist/codecs/UnknownPacket';
|
|
27
|
+
import { Values } from 'xstate';
|
|
28
|
+
import { VTGPacket } from 'nmea-simple';
|
|
29
|
+
import { ZDAPacket } from 'nmea-simple';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Append the correct trailing "*xx" footer for an NMEA string and return the result.
|
|
33
|
+
*/
|
|
34
|
+
export declare function appendChecksumFooter(sentenceWithoutChecksum: string): string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Computes navigation data from stored packets using a fallback strategy.
|
|
38
|
+
* Each navigation property (time, position, speed, heading, depth) is computed
|
|
39
|
+
* with priority-based fallback to the best available data source.
|
|
40
|
+
*/
|
|
41
|
+
export declare function computeNavigationData(packets: StoredPackets, externalVariation?: number): NavigationData;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generate a checksum for an NMEA sentence without the trailing "*xx".
|
|
45
|
+
*/
|
|
46
|
+
export declare function computeNmeaChecksum(sentenceWithoutChecksum: string): number;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates a navigation adapter function with the specified magnetic variation.
|
|
50
|
+
* The adapter is a closure that captures the variation value.
|
|
51
|
+
*
|
|
52
|
+
* @param externalVariation - Optional magnetic variation for heading calculations.
|
|
53
|
+
* @returns An adapter function that transforms packets into navigation data.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createNavigationAdapter(externalVariation?: number): (packets: StoredPackets) => NavigationData;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Configuration for creating a navigation-focused NMEA machine.
|
|
59
|
+
* This is a convenience configuration that uses the navigation adapter.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createNavigationNmeaConfig(options?: {
|
|
62
|
+
allowedSentenceIds?: readonly string[];
|
|
63
|
+
externalVariation?: number;
|
|
64
|
+
}): NmeaMachineConfig<NavigationData, StoredPackets>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Convenience function to create a navigation-focused NMEA machine.
|
|
68
|
+
* This is a pre-configured machine that computes navigation data from NMEA packets.
|
|
69
|
+
*
|
|
70
|
+
* @param options - Optional configuration for the navigation machine.
|
|
71
|
+
* @param options.allowedSentenceIds - Optional array of allowed sentence IDs.
|
|
72
|
+
* @param options.externalVariation - Optional magnetic variation for heading calculations.
|
|
73
|
+
* @returns An NMEA machine configured for navigation data computation.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const machine = createNavigationNmeaMachine({
|
|
78
|
+
* externalVariation: 5.5,
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function createNavigationNmeaMachine(options?: {
|
|
83
|
+
allowedSentenceIds?: readonly string[];
|
|
84
|
+
externalVariation?: number;
|
|
85
|
+
}): StateMachine<NmeaContext<NavigationData, StoredPackets>, {
|
|
86
|
+
type: "CONNECT";
|
|
87
|
+
} | {
|
|
88
|
+
type: "DISCONNECT";
|
|
89
|
+
} | {
|
|
90
|
+
type: "SERIAL.DATA";
|
|
91
|
+
data: Packet;
|
|
92
|
+
} | {
|
|
93
|
+
type: "SERIAL.ERROR";
|
|
94
|
+
error: string;
|
|
95
|
+
} | {
|
|
96
|
+
type: "FATAL_ERROR";
|
|
97
|
+
error: string;
|
|
98
|
+
} | {
|
|
99
|
+
type: "SERIAL.DISCONNECTED";
|
|
100
|
+
} | {
|
|
101
|
+
type: "STOP";
|
|
102
|
+
} | {
|
|
103
|
+
type: "SET_LOGGING";
|
|
104
|
+
enabled: boolean;
|
|
105
|
+
} | {
|
|
106
|
+
type: "SET_BAUD_RATE";
|
|
107
|
+
baudRate: number;
|
|
108
|
+
}, {
|
|
109
|
+
[x: string]: ActorRefFromLogic<PromiseActorLogic<SerialPort, {
|
|
110
|
+
baudRate: number;
|
|
111
|
+
}, EventObject>> | ActorRefFromLogic<CallbackActorLogic<NmeaEvent, {
|
|
112
|
+
port: SerialPort;
|
|
113
|
+
}, EventObject>> | ActorRefFromLogic<PromiseActorLogic<void, {
|
|
114
|
+
port: SerialPort | null;
|
|
115
|
+
}, EventObject>> | undefined;
|
|
116
|
+
}, Values< {
|
|
117
|
+
connectToSerial: {
|
|
118
|
+
src: "connectToSerial";
|
|
119
|
+
logic: PromiseActorLogic<SerialPort, {
|
|
120
|
+
baudRate: number;
|
|
121
|
+
}, EventObject>;
|
|
122
|
+
id: string | undefined;
|
|
123
|
+
};
|
|
124
|
+
readNmeaStream: {
|
|
125
|
+
src: "readNmeaStream";
|
|
126
|
+
logic: CallbackActorLogic<NmeaEvent, {
|
|
127
|
+
port: SerialPort;
|
|
128
|
+
}, EventObject>;
|
|
129
|
+
id: string | undefined;
|
|
130
|
+
};
|
|
131
|
+
closePort: {
|
|
132
|
+
src: "closePort";
|
|
133
|
+
logic: PromiseActorLogic<void, {
|
|
134
|
+
port: SerialPort | null;
|
|
135
|
+
}, EventObject>;
|
|
136
|
+
id: string | undefined;
|
|
137
|
+
};
|
|
138
|
+
}>, Values< {
|
|
139
|
+
setPort: {
|
|
140
|
+
type: "setPort";
|
|
141
|
+
params: {
|
|
142
|
+
port: SerialPort;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
setError: {
|
|
146
|
+
type: "setError";
|
|
147
|
+
params: {
|
|
148
|
+
error: unknown;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
logParsedData: {
|
|
152
|
+
type: "logParsedData";
|
|
153
|
+
params: {
|
|
154
|
+
packet: Packet;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
storePacket: {
|
|
158
|
+
type: "storePacket";
|
|
159
|
+
params: {
|
|
160
|
+
packet: Packet;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
clearError: {
|
|
164
|
+
type: "clearError";
|
|
165
|
+
params: {
|
|
166
|
+
error: string;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
setFatalError: {
|
|
170
|
+
type: "setFatalError";
|
|
171
|
+
params: {
|
|
172
|
+
error: string;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
disconnect: {
|
|
176
|
+
type: "disconnect";
|
|
177
|
+
params: NonReducibleUnknown;
|
|
178
|
+
};
|
|
179
|
+
setLogging: {
|
|
180
|
+
type: "setLogging";
|
|
181
|
+
params: {
|
|
182
|
+
enabled: boolean;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
setBaudRate: {
|
|
186
|
+
type: "setBaudRate";
|
|
187
|
+
params: {
|
|
188
|
+
baudRate: number;
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
}>, never, never, "error" | "disconnected" | "connecting" | "connected" | "disconnecting", string, NonReducibleUnknown, NonReducibleUnknown, EventObject, MetaObject, {
|
|
192
|
+
readonly id: "nmea";
|
|
193
|
+
readonly initial: "disconnected";
|
|
194
|
+
readonly context: {
|
|
195
|
+
readonly port: null;
|
|
196
|
+
readonly error: null;
|
|
197
|
+
readonly packets: StoredPackets;
|
|
198
|
+
readonly data: NavigationData;
|
|
199
|
+
readonly enableLogging: false;
|
|
200
|
+
readonly baudRate: 4800;
|
|
201
|
+
};
|
|
202
|
+
readonly on: {
|
|
203
|
+
readonly SET_LOGGING: {
|
|
204
|
+
readonly actions: {
|
|
205
|
+
readonly type: "setLogging";
|
|
206
|
+
readonly params: ({ event }: {
|
|
207
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
208
|
+
event: {
|
|
209
|
+
type: "SET_LOGGING";
|
|
210
|
+
enabled: boolean;
|
|
211
|
+
};
|
|
212
|
+
}) => {
|
|
213
|
+
enabled: boolean;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
readonly states: {
|
|
219
|
+
readonly disconnected: {
|
|
220
|
+
readonly on: {
|
|
221
|
+
readonly CONNECT: "connecting";
|
|
222
|
+
readonly SET_BAUD_RATE: {
|
|
223
|
+
readonly actions: {
|
|
224
|
+
readonly type: "setBaudRate";
|
|
225
|
+
readonly params: ({ event }: {
|
|
226
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
227
|
+
event: {
|
|
228
|
+
type: "SET_BAUD_RATE";
|
|
229
|
+
baudRate: number;
|
|
230
|
+
};
|
|
231
|
+
}) => {
|
|
232
|
+
baudRate: number;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
readonly connecting: {
|
|
239
|
+
readonly invoke: {
|
|
240
|
+
readonly id: "connectToSerial";
|
|
241
|
+
readonly src: "connectToSerial";
|
|
242
|
+
readonly input: ({ context }: {
|
|
243
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
244
|
+
event: {
|
|
245
|
+
type: "CONNECT";
|
|
246
|
+
} | {
|
|
247
|
+
type: "DISCONNECT";
|
|
248
|
+
} | {
|
|
249
|
+
type: "SERIAL.DATA";
|
|
250
|
+
data: Packet;
|
|
251
|
+
} | {
|
|
252
|
+
type: "SERIAL.ERROR";
|
|
253
|
+
error: string;
|
|
254
|
+
} | {
|
|
255
|
+
type: "FATAL_ERROR";
|
|
256
|
+
error: string;
|
|
257
|
+
} | {
|
|
258
|
+
type: "SERIAL.DISCONNECTED";
|
|
259
|
+
} | {
|
|
260
|
+
type: "STOP";
|
|
261
|
+
} | {
|
|
262
|
+
type: "SET_LOGGING";
|
|
263
|
+
enabled: boolean;
|
|
264
|
+
} | {
|
|
265
|
+
type: "SET_BAUD_RATE";
|
|
266
|
+
baudRate: number;
|
|
267
|
+
};
|
|
268
|
+
self: ActorRef<MachineSnapshot<NmeaContext<NavigationData, StoredPackets>, {
|
|
269
|
+
type: "CONNECT";
|
|
270
|
+
} | {
|
|
271
|
+
type: "DISCONNECT";
|
|
272
|
+
} | {
|
|
273
|
+
type: "SERIAL.DATA";
|
|
274
|
+
data: Packet;
|
|
275
|
+
} | {
|
|
276
|
+
type: "SERIAL.ERROR";
|
|
277
|
+
error: string;
|
|
278
|
+
} | {
|
|
279
|
+
type: "FATAL_ERROR";
|
|
280
|
+
error: string;
|
|
281
|
+
} | {
|
|
282
|
+
type: "SERIAL.DISCONNECTED";
|
|
283
|
+
} | {
|
|
284
|
+
type: "STOP";
|
|
285
|
+
} | {
|
|
286
|
+
type: "SET_LOGGING";
|
|
287
|
+
enabled: boolean;
|
|
288
|
+
} | {
|
|
289
|
+
type: "SET_BAUD_RATE";
|
|
290
|
+
baudRate: number;
|
|
291
|
+
}, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, {
|
|
292
|
+
type: "CONNECT";
|
|
293
|
+
} | {
|
|
294
|
+
type: "DISCONNECT";
|
|
295
|
+
} | {
|
|
296
|
+
type: "SERIAL.DATA";
|
|
297
|
+
data: Packet;
|
|
298
|
+
} | {
|
|
299
|
+
type: "SERIAL.ERROR";
|
|
300
|
+
error: string;
|
|
301
|
+
} | {
|
|
302
|
+
type: "FATAL_ERROR";
|
|
303
|
+
error: string;
|
|
304
|
+
} | {
|
|
305
|
+
type: "SERIAL.DISCONNECTED";
|
|
306
|
+
} | {
|
|
307
|
+
type: "STOP";
|
|
308
|
+
} | {
|
|
309
|
+
type: "SET_LOGGING";
|
|
310
|
+
enabled: boolean;
|
|
311
|
+
} | {
|
|
312
|
+
type: "SET_BAUD_RATE";
|
|
313
|
+
baudRate: number;
|
|
314
|
+
}, AnyEventObject>;
|
|
315
|
+
}) => {
|
|
316
|
+
baudRate: number;
|
|
317
|
+
};
|
|
318
|
+
readonly onDone: {
|
|
319
|
+
readonly target: "connected";
|
|
320
|
+
readonly actions: {
|
|
321
|
+
readonly type: "setPort";
|
|
322
|
+
readonly params: ({ event }: {
|
|
323
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
324
|
+
event: DoneActorEvent<SerialPort, string>;
|
|
325
|
+
}) => {
|
|
326
|
+
port: SerialPort;
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
readonly onError: {
|
|
331
|
+
readonly target: "error";
|
|
332
|
+
readonly actions: {
|
|
333
|
+
readonly type: "setError";
|
|
334
|
+
readonly params: ({ event }: {
|
|
335
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
336
|
+
event: ErrorActorEvent<unknown, string>;
|
|
337
|
+
}) => {
|
|
338
|
+
error: unknown;
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
readonly connected: {
|
|
345
|
+
readonly on: {
|
|
346
|
+
readonly 'SERIAL.DATA': {
|
|
347
|
+
readonly actions: readonly [{
|
|
348
|
+
readonly type: "logParsedData";
|
|
349
|
+
readonly params: ({ event }: {
|
|
350
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
351
|
+
event: {
|
|
352
|
+
type: "SERIAL.DATA";
|
|
353
|
+
data: Packet;
|
|
354
|
+
};
|
|
355
|
+
}) => {
|
|
356
|
+
packet: Packet;
|
|
357
|
+
};
|
|
358
|
+
}, {
|
|
359
|
+
readonly type: "storePacket";
|
|
360
|
+
readonly params: ({ event }: {
|
|
361
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
362
|
+
event: {
|
|
363
|
+
type: "SERIAL.DATA";
|
|
364
|
+
data: Packet;
|
|
365
|
+
};
|
|
366
|
+
}) => {
|
|
367
|
+
packet: Packet;
|
|
368
|
+
};
|
|
369
|
+
}];
|
|
370
|
+
};
|
|
371
|
+
readonly 'SERIAL.ERROR': {
|
|
372
|
+
readonly actions: {
|
|
373
|
+
readonly type: "clearError";
|
|
374
|
+
readonly params: ({ event }: {
|
|
375
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
376
|
+
event: {
|
|
377
|
+
type: "SERIAL.ERROR";
|
|
378
|
+
error: string;
|
|
379
|
+
};
|
|
380
|
+
}) => {
|
|
381
|
+
error: string;
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
readonly FATAL_ERROR: {
|
|
386
|
+
readonly target: "error";
|
|
387
|
+
readonly actions: {
|
|
388
|
+
readonly type: "setFatalError";
|
|
389
|
+
readonly params: ({ event }: {
|
|
390
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
391
|
+
event: {
|
|
392
|
+
type: "FATAL_ERROR";
|
|
393
|
+
error: string;
|
|
394
|
+
};
|
|
395
|
+
}) => {
|
|
396
|
+
error: string;
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
readonly 'SERIAL.DISCONNECTED': {
|
|
401
|
+
readonly target: "disconnecting";
|
|
402
|
+
};
|
|
403
|
+
readonly DISCONNECT: {
|
|
404
|
+
readonly actions: ActionFunction<NmeaContext<NavigationData, StoredPackets>, {
|
|
405
|
+
type: "DISCONNECT";
|
|
406
|
+
}, {
|
|
407
|
+
type: "CONNECT";
|
|
408
|
+
} | {
|
|
409
|
+
type: "DISCONNECT";
|
|
410
|
+
} | {
|
|
411
|
+
type: "SERIAL.DATA";
|
|
412
|
+
data: Packet;
|
|
413
|
+
} | {
|
|
414
|
+
type: "SERIAL.ERROR";
|
|
415
|
+
error: string;
|
|
416
|
+
} | {
|
|
417
|
+
type: "FATAL_ERROR";
|
|
418
|
+
error: string;
|
|
419
|
+
} | {
|
|
420
|
+
type: "SERIAL.DISCONNECTED";
|
|
421
|
+
} | {
|
|
422
|
+
type: "STOP";
|
|
423
|
+
} | {
|
|
424
|
+
type: "SET_LOGGING";
|
|
425
|
+
enabled: boolean;
|
|
426
|
+
} | {
|
|
427
|
+
type: "SET_BAUD_RATE";
|
|
428
|
+
baudRate: number;
|
|
429
|
+
}, undefined, never, never, never, never, never>;
|
|
430
|
+
};
|
|
431
|
+
};
|
|
432
|
+
readonly invoke: {
|
|
433
|
+
readonly id: "streamReader";
|
|
434
|
+
readonly src: "readNmeaStream";
|
|
435
|
+
readonly input: ({ context }: {
|
|
436
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
437
|
+
event: {
|
|
438
|
+
type: "CONNECT";
|
|
439
|
+
} | {
|
|
440
|
+
type: "DISCONNECT";
|
|
441
|
+
} | {
|
|
442
|
+
type: "SERIAL.DATA";
|
|
443
|
+
data: Packet;
|
|
444
|
+
} | {
|
|
445
|
+
type: "SERIAL.ERROR";
|
|
446
|
+
error: string;
|
|
447
|
+
} | {
|
|
448
|
+
type: "FATAL_ERROR";
|
|
449
|
+
error: string;
|
|
450
|
+
} | {
|
|
451
|
+
type: "SERIAL.DISCONNECTED";
|
|
452
|
+
} | {
|
|
453
|
+
type: "STOP";
|
|
454
|
+
} | {
|
|
455
|
+
type: "SET_LOGGING";
|
|
456
|
+
enabled: boolean;
|
|
457
|
+
} | {
|
|
458
|
+
type: "SET_BAUD_RATE";
|
|
459
|
+
baudRate: number;
|
|
460
|
+
};
|
|
461
|
+
self: ActorRef<MachineSnapshot<NmeaContext<NavigationData, StoredPackets>, {
|
|
462
|
+
type: "CONNECT";
|
|
463
|
+
} | {
|
|
464
|
+
type: "DISCONNECT";
|
|
465
|
+
} | {
|
|
466
|
+
type: "SERIAL.DATA";
|
|
467
|
+
data: Packet;
|
|
468
|
+
} | {
|
|
469
|
+
type: "SERIAL.ERROR";
|
|
470
|
+
error: string;
|
|
471
|
+
} | {
|
|
472
|
+
type: "FATAL_ERROR";
|
|
473
|
+
error: string;
|
|
474
|
+
} | {
|
|
475
|
+
type: "SERIAL.DISCONNECTED";
|
|
476
|
+
} | {
|
|
477
|
+
type: "STOP";
|
|
478
|
+
} | {
|
|
479
|
+
type: "SET_LOGGING";
|
|
480
|
+
enabled: boolean;
|
|
481
|
+
} | {
|
|
482
|
+
type: "SET_BAUD_RATE";
|
|
483
|
+
baudRate: number;
|
|
484
|
+
}, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, {
|
|
485
|
+
type: "CONNECT";
|
|
486
|
+
} | {
|
|
487
|
+
type: "DISCONNECT";
|
|
488
|
+
} | {
|
|
489
|
+
type: "SERIAL.DATA";
|
|
490
|
+
data: Packet;
|
|
491
|
+
} | {
|
|
492
|
+
type: "SERIAL.ERROR";
|
|
493
|
+
error: string;
|
|
494
|
+
} | {
|
|
495
|
+
type: "FATAL_ERROR";
|
|
496
|
+
error: string;
|
|
497
|
+
} | {
|
|
498
|
+
type: "SERIAL.DISCONNECTED";
|
|
499
|
+
} | {
|
|
500
|
+
type: "STOP";
|
|
501
|
+
} | {
|
|
502
|
+
type: "SET_LOGGING";
|
|
503
|
+
enabled: boolean;
|
|
504
|
+
} | {
|
|
505
|
+
type: "SET_BAUD_RATE";
|
|
506
|
+
baudRate: number;
|
|
507
|
+
}, AnyEventObject>;
|
|
508
|
+
}) => {
|
|
509
|
+
port: SerialPort;
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
};
|
|
513
|
+
readonly disconnecting: {
|
|
514
|
+
readonly invoke: {
|
|
515
|
+
readonly id: "closePort";
|
|
516
|
+
readonly src: "closePort";
|
|
517
|
+
readonly input: ({ context }: {
|
|
518
|
+
context: NmeaContext<NavigationData, StoredPackets>;
|
|
519
|
+
event: {
|
|
520
|
+
type: "CONNECT";
|
|
521
|
+
} | {
|
|
522
|
+
type: "DISCONNECT";
|
|
523
|
+
} | {
|
|
524
|
+
type: "SERIAL.DATA";
|
|
525
|
+
data: Packet;
|
|
526
|
+
} | {
|
|
527
|
+
type: "SERIAL.ERROR";
|
|
528
|
+
error: string;
|
|
529
|
+
} | {
|
|
530
|
+
type: "FATAL_ERROR";
|
|
531
|
+
error: string;
|
|
532
|
+
} | {
|
|
533
|
+
type: "SERIAL.DISCONNECTED";
|
|
534
|
+
} | {
|
|
535
|
+
type: "STOP";
|
|
536
|
+
} | {
|
|
537
|
+
type: "SET_LOGGING";
|
|
538
|
+
enabled: boolean;
|
|
539
|
+
} | {
|
|
540
|
+
type: "SET_BAUD_RATE";
|
|
541
|
+
baudRate: number;
|
|
542
|
+
};
|
|
543
|
+
self: ActorRef<MachineSnapshot<NmeaContext<NavigationData, StoredPackets>, {
|
|
544
|
+
type: "CONNECT";
|
|
545
|
+
} | {
|
|
546
|
+
type: "DISCONNECT";
|
|
547
|
+
} | {
|
|
548
|
+
type: "SERIAL.DATA";
|
|
549
|
+
data: Packet;
|
|
550
|
+
} | {
|
|
551
|
+
type: "SERIAL.ERROR";
|
|
552
|
+
error: string;
|
|
553
|
+
} | {
|
|
554
|
+
type: "FATAL_ERROR";
|
|
555
|
+
error: string;
|
|
556
|
+
} | {
|
|
557
|
+
type: "SERIAL.DISCONNECTED";
|
|
558
|
+
} | {
|
|
559
|
+
type: "STOP";
|
|
560
|
+
} | {
|
|
561
|
+
type: "SET_LOGGING";
|
|
562
|
+
enabled: boolean;
|
|
563
|
+
} | {
|
|
564
|
+
type: "SET_BAUD_RATE";
|
|
565
|
+
baudRate: number;
|
|
566
|
+
}, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, {
|
|
567
|
+
type: "CONNECT";
|
|
568
|
+
} | {
|
|
569
|
+
type: "DISCONNECT";
|
|
570
|
+
} | {
|
|
571
|
+
type: "SERIAL.DATA";
|
|
572
|
+
data: Packet;
|
|
573
|
+
} | {
|
|
574
|
+
type: "SERIAL.ERROR";
|
|
575
|
+
error: string;
|
|
576
|
+
} | {
|
|
577
|
+
type: "FATAL_ERROR";
|
|
578
|
+
error: string;
|
|
579
|
+
} | {
|
|
580
|
+
type: "SERIAL.DISCONNECTED";
|
|
581
|
+
} | {
|
|
582
|
+
type: "STOP";
|
|
583
|
+
} | {
|
|
584
|
+
type: "SET_LOGGING";
|
|
585
|
+
enabled: boolean;
|
|
586
|
+
} | {
|
|
587
|
+
type: "SET_BAUD_RATE";
|
|
588
|
+
baudRate: number;
|
|
589
|
+
}, AnyEventObject>;
|
|
590
|
+
}) => {
|
|
591
|
+
port: SerialPort | null;
|
|
592
|
+
};
|
|
593
|
+
readonly onDone: {
|
|
594
|
+
readonly target: "disconnected";
|
|
595
|
+
readonly actions: "disconnect";
|
|
596
|
+
};
|
|
597
|
+
readonly onError: {
|
|
598
|
+
readonly target: "disconnected";
|
|
599
|
+
readonly actions: "disconnect";
|
|
600
|
+
};
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
readonly error: {
|
|
604
|
+
readonly on: {
|
|
605
|
+
readonly CONNECT: "connecting";
|
|
606
|
+
};
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
}>;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Generate the correct trailing "*xx" footer for an NMEA sentence.
|
|
613
|
+
*/
|
|
614
|
+
export declare function createNmeaChecksumFooter(sentenceWithoutChecksum: string): string;
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Factory function to create an NMEA state machine with a generic adapter pattern.
|
|
618
|
+
*
|
|
619
|
+
* @template TData - The type of computed/translated data stored in context.
|
|
620
|
+
* @template TPackets - The type of stored packets (typically a record of sentence ID to packet).
|
|
621
|
+
* @param config - Configuration for the machine including adapter function and initial values.
|
|
622
|
+
* @returns An XState machine configured with the provided adapter and types.
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```typescript
|
|
626
|
+
* const machine = createNmeaMachine({
|
|
627
|
+
* adapter: computeNavigationData,
|
|
628
|
+
* allowedSentenceIds: ['GGA', 'RMC', 'VTG'],
|
|
629
|
+
* initialData: { time: null, position: null },
|
|
630
|
+
* initialPackets: {},
|
|
631
|
+
* });
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
export declare function createNmeaMachine<TData, TPackets extends Record<string, unknown>>(config: NmeaMachineConfig<TData, TPackets>): StateMachine<NmeaContext<TData, TPackets>, {
|
|
635
|
+
type: "CONNECT";
|
|
636
|
+
} | {
|
|
637
|
+
type: "DISCONNECT";
|
|
638
|
+
} | {
|
|
639
|
+
type: "SERIAL.DATA";
|
|
640
|
+
data: Packet;
|
|
641
|
+
} | {
|
|
642
|
+
type: "SERIAL.ERROR";
|
|
643
|
+
error: string;
|
|
644
|
+
} | {
|
|
645
|
+
type: "FATAL_ERROR";
|
|
646
|
+
error: string;
|
|
647
|
+
} | {
|
|
648
|
+
type: "SERIAL.DISCONNECTED";
|
|
649
|
+
} | {
|
|
650
|
+
type: "STOP";
|
|
651
|
+
} | {
|
|
652
|
+
type: "SET_LOGGING";
|
|
653
|
+
enabled: boolean;
|
|
654
|
+
} | {
|
|
655
|
+
type: "SET_BAUD_RATE";
|
|
656
|
+
baudRate: number;
|
|
657
|
+
}, {
|
|
658
|
+
[x: string]: ActorRefFromLogic<PromiseActorLogic<SerialPort, {
|
|
659
|
+
baudRate: number;
|
|
660
|
+
}, EventObject>> | ActorRefFromLogic<CallbackActorLogic<NmeaEvent, {
|
|
661
|
+
port: SerialPort;
|
|
662
|
+
}, EventObject>> | ActorRefFromLogic<PromiseActorLogic<void, {
|
|
663
|
+
port: SerialPort | null;
|
|
664
|
+
}, EventObject>> | undefined;
|
|
665
|
+
}, Values< {
|
|
666
|
+
connectToSerial: {
|
|
667
|
+
src: "connectToSerial";
|
|
668
|
+
logic: PromiseActorLogic<SerialPort, {
|
|
669
|
+
baudRate: number;
|
|
670
|
+
}, EventObject>;
|
|
671
|
+
id: string | undefined;
|
|
672
|
+
};
|
|
673
|
+
readNmeaStream: {
|
|
674
|
+
src: "readNmeaStream";
|
|
675
|
+
logic: CallbackActorLogic<NmeaEvent, {
|
|
676
|
+
port: SerialPort;
|
|
677
|
+
}, EventObject>;
|
|
678
|
+
id: string | undefined;
|
|
679
|
+
};
|
|
680
|
+
closePort: {
|
|
681
|
+
src: "closePort";
|
|
682
|
+
logic: PromiseActorLogic<void, {
|
|
683
|
+
port: SerialPort | null;
|
|
684
|
+
}, EventObject>;
|
|
685
|
+
id: string | undefined;
|
|
686
|
+
};
|
|
687
|
+
}>, Values< {
|
|
688
|
+
setPort: {
|
|
689
|
+
type: "setPort";
|
|
690
|
+
params: {
|
|
691
|
+
port: SerialPort;
|
|
692
|
+
};
|
|
693
|
+
};
|
|
694
|
+
setError: {
|
|
695
|
+
type: "setError";
|
|
696
|
+
params: {
|
|
697
|
+
error: unknown;
|
|
698
|
+
};
|
|
699
|
+
};
|
|
700
|
+
logParsedData: {
|
|
701
|
+
type: "logParsedData";
|
|
702
|
+
params: {
|
|
703
|
+
packet: Packet;
|
|
704
|
+
};
|
|
705
|
+
};
|
|
706
|
+
storePacket: {
|
|
707
|
+
type: "storePacket";
|
|
708
|
+
params: {
|
|
709
|
+
packet: Packet;
|
|
710
|
+
};
|
|
711
|
+
};
|
|
712
|
+
clearError: {
|
|
713
|
+
type: "clearError";
|
|
714
|
+
params: {
|
|
715
|
+
error: string;
|
|
716
|
+
};
|
|
717
|
+
};
|
|
718
|
+
setFatalError: {
|
|
719
|
+
type: "setFatalError";
|
|
720
|
+
params: {
|
|
721
|
+
error: string;
|
|
722
|
+
};
|
|
723
|
+
};
|
|
724
|
+
disconnect: {
|
|
725
|
+
type: "disconnect";
|
|
726
|
+
params: NonReducibleUnknown;
|
|
727
|
+
};
|
|
728
|
+
setLogging: {
|
|
729
|
+
type: "setLogging";
|
|
730
|
+
params: {
|
|
731
|
+
enabled: boolean;
|
|
732
|
+
};
|
|
733
|
+
};
|
|
734
|
+
setBaudRate: {
|
|
735
|
+
type: "setBaudRate";
|
|
736
|
+
params: {
|
|
737
|
+
baudRate: number;
|
|
738
|
+
};
|
|
739
|
+
};
|
|
740
|
+
}>, never, never, "error" | "disconnected" | "connecting" | "connected" | "disconnecting", string, NonReducibleUnknown, NonReducibleUnknown, EventObject, MetaObject, {
|
|
741
|
+
readonly id: "nmea";
|
|
742
|
+
readonly initial: "disconnected";
|
|
743
|
+
readonly context: {
|
|
744
|
+
readonly port: null;
|
|
745
|
+
readonly error: null;
|
|
746
|
+
readonly packets: TPackets;
|
|
747
|
+
readonly data: TData;
|
|
748
|
+
readonly enableLogging: false;
|
|
749
|
+
readonly baudRate: 4800;
|
|
750
|
+
};
|
|
751
|
+
readonly on: {
|
|
752
|
+
readonly SET_LOGGING: {
|
|
753
|
+
readonly actions: {
|
|
754
|
+
readonly type: "setLogging";
|
|
755
|
+
readonly params: ({ event }: {
|
|
756
|
+
context: NmeaContext<TData, TPackets>;
|
|
757
|
+
event: {
|
|
758
|
+
type: "SET_LOGGING";
|
|
759
|
+
enabled: boolean;
|
|
760
|
+
};
|
|
761
|
+
}) => {
|
|
762
|
+
enabled: boolean;
|
|
763
|
+
};
|
|
764
|
+
};
|
|
765
|
+
};
|
|
766
|
+
};
|
|
767
|
+
readonly states: {
|
|
768
|
+
readonly disconnected: {
|
|
769
|
+
readonly on: {
|
|
770
|
+
readonly CONNECT: "connecting";
|
|
771
|
+
readonly SET_BAUD_RATE: {
|
|
772
|
+
readonly actions: {
|
|
773
|
+
readonly type: "setBaudRate";
|
|
774
|
+
readonly params: ({ event }: {
|
|
775
|
+
context: NmeaContext<TData, TPackets>;
|
|
776
|
+
event: {
|
|
777
|
+
type: "SET_BAUD_RATE";
|
|
778
|
+
baudRate: number;
|
|
779
|
+
};
|
|
780
|
+
}) => {
|
|
781
|
+
baudRate: number;
|
|
782
|
+
};
|
|
783
|
+
};
|
|
784
|
+
};
|
|
785
|
+
};
|
|
786
|
+
};
|
|
787
|
+
readonly connecting: {
|
|
788
|
+
readonly invoke: {
|
|
789
|
+
readonly id: "connectToSerial";
|
|
790
|
+
readonly src: "connectToSerial";
|
|
791
|
+
readonly input: ({ context }: {
|
|
792
|
+
context: NmeaContext<TData, TPackets>;
|
|
793
|
+
event: {
|
|
794
|
+
type: "CONNECT";
|
|
795
|
+
} | {
|
|
796
|
+
type: "DISCONNECT";
|
|
797
|
+
} | {
|
|
798
|
+
type: "SERIAL.DATA";
|
|
799
|
+
data: Packet;
|
|
800
|
+
} | {
|
|
801
|
+
type: "SERIAL.ERROR";
|
|
802
|
+
error: string;
|
|
803
|
+
} | {
|
|
804
|
+
type: "FATAL_ERROR";
|
|
805
|
+
error: string;
|
|
806
|
+
} | {
|
|
807
|
+
type: "SERIAL.DISCONNECTED";
|
|
808
|
+
} | {
|
|
809
|
+
type: "STOP";
|
|
810
|
+
} | {
|
|
811
|
+
type: "SET_LOGGING";
|
|
812
|
+
enabled: boolean;
|
|
813
|
+
} | {
|
|
814
|
+
type: "SET_BAUD_RATE";
|
|
815
|
+
baudRate: number;
|
|
816
|
+
};
|
|
817
|
+
self: ActorRef<MachineSnapshot<NmeaContext<TData, TPackets>, {
|
|
818
|
+
type: "CONNECT";
|
|
819
|
+
} | {
|
|
820
|
+
type: "DISCONNECT";
|
|
821
|
+
} | {
|
|
822
|
+
type: "SERIAL.DATA";
|
|
823
|
+
data: Packet;
|
|
824
|
+
} | {
|
|
825
|
+
type: "SERIAL.ERROR";
|
|
826
|
+
error: string;
|
|
827
|
+
} | {
|
|
828
|
+
type: "FATAL_ERROR";
|
|
829
|
+
error: string;
|
|
830
|
+
} | {
|
|
831
|
+
type: "SERIAL.DISCONNECTED";
|
|
832
|
+
} | {
|
|
833
|
+
type: "STOP";
|
|
834
|
+
} | {
|
|
835
|
+
type: "SET_LOGGING";
|
|
836
|
+
enabled: boolean;
|
|
837
|
+
} | {
|
|
838
|
+
type: "SET_BAUD_RATE";
|
|
839
|
+
baudRate: number;
|
|
840
|
+
}, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, {
|
|
841
|
+
type: "CONNECT";
|
|
842
|
+
} | {
|
|
843
|
+
type: "DISCONNECT";
|
|
844
|
+
} | {
|
|
845
|
+
type: "SERIAL.DATA";
|
|
846
|
+
data: Packet;
|
|
847
|
+
} | {
|
|
848
|
+
type: "SERIAL.ERROR";
|
|
849
|
+
error: string;
|
|
850
|
+
} | {
|
|
851
|
+
type: "FATAL_ERROR";
|
|
852
|
+
error: string;
|
|
853
|
+
} | {
|
|
854
|
+
type: "SERIAL.DISCONNECTED";
|
|
855
|
+
} | {
|
|
856
|
+
type: "STOP";
|
|
857
|
+
} | {
|
|
858
|
+
type: "SET_LOGGING";
|
|
859
|
+
enabled: boolean;
|
|
860
|
+
} | {
|
|
861
|
+
type: "SET_BAUD_RATE";
|
|
862
|
+
baudRate: number;
|
|
863
|
+
}, AnyEventObject>;
|
|
864
|
+
}) => {
|
|
865
|
+
baudRate: number;
|
|
866
|
+
};
|
|
867
|
+
readonly onDone: {
|
|
868
|
+
readonly target: "connected";
|
|
869
|
+
readonly actions: {
|
|
870
|
+
readonly type: "setPort";
|
|
871
|
+
readonly params: ({ event }: {
|
|
872
|
+
context: NmeaContext<TData, TPackets>;
|
|
873
|
+
event: DoneActorEvent<SerialPort, string>;
|
|
874
|
+
}) => {
|
|
875
|
+
port: SerialPort;
|
|
876
|
+
};
|
|
877
|
+
};
|
|
878
|
+
};
|
|
879
|
+
readonly onError: {
|
|
880
|
+
readonly target: "error";
|
|
881
|
+
readonly actions: {
|
|
882
|
+
readonly type: "setError";
|
|
883
|
+
readonly params: ({ event }: {
|
|
884
|
+
context: NmeaContext<TData, TPackets>;
|
|
885
|
+
event: ErrorActorEvent<unknown, string>;
|
|
886
|
+
}) => {
|
|
887
|
+
error: unknown;
|
|
888
|
+
};
|
|
889
|
+
};
|
|
890
|
+
};
|
|
891
|
+
};
|
|
892
|
+
};
|
|
893
|
+
readonly connected: {
|
|
894
|
+
readonly on: {
|
|
895
|
+
readonly 'SERIAL.DATA': {
|
|
896
|
+
readonly actions: readonly [{
|
|
897
|
+
readonly type: "logParsedData";
|
|
898
|
+
readonly params: ({ event }: {
|
|
899
|
+
context: NmeaContext<TData, TPackets>;
|
|
900
|
+
event: {
|
|
901
|
+
type: "SERIAL.DATA";
|
|
902
|
+
data: Packet;
|
|
903
|
+
};
|
|
904
|
+
}) => {
|
|
905
|
+
packet: Packet;
|
|
906
|
+
};
|
|
907
|
+
}, {
|
|
908
|
+
readonly type: "storePacket";
|
|
909
|
+
readonly params: ({ event }: {
|
|
910
|
+
context: NmeaContext<TData, TPackets>;
|
|
911
|
+
event: {
|
|
912
|
+
type: "SERIAL.DATA";
|
|
913
|
+
data: Packet;
|
|
914
|
+
};
|
|
915
|
+
}) => {
|
|
916
|
+
packet: Packet;
|
|
917
|
+
};
|
|
918
|
+
}];
|
|
919
|
+
};
|
|
920
|
+
readonly 'SERIAL.ERROR': {
|
|
921
|
+
readonly actions: {
|
|
922
|
+
readonly type: "clearError";
|
|
923
|
+
readonly params: ({ event }: {
|
|
924
|
+
context: NmeaContext<TData, TPackets>;
|
|
925
|
+
event: {
|
|
926
|
+
type: "SERIAL.ERROR";
|
|
927
|
+
error: string;
|
|
928
|
+
};
|
|
929
|
+
}) => {
|
|
930
|
+
error: string;
|
|
931
|
+
};
|
|
932
|
+
};
|
|
933
|
+
};
|
|
934
|
+
readonly FATAL_ERROR: {
|
|
935
|
+
readonly target: "error";
|
|
936
|
+
readonly actions: {
|
|
937
|
+
readonly type: "setFatalError";
|
|
938
|
+
readonly params: ({ event }: {
|
|
939
|
+
context: NmeaContext<TData, TPackets>;
|
|
940
|
+
event: {
|
|
941
|
+
type: "FATAL_ERROR";
|
|
942
|
+
error: string;
|
|
943
|
+
};
|
|
944
|
+
}) => {
|
|
945
|
+
error: string;
|
|
946
|
+
};
|
|
947
|
+
};
|
|
948
|
+
};
|
|
949
|
+
readonly 'SERIAL.DISCONNECTED': {
|
|
950
|
+
readonly target: "disconnecting";
|
|
951
|
+
};
|
|
952
|
+
readonly DISCONNECT: {
|
|
953
|
+
readonly actions: ActionFunction<NmeaContext<TData, TPackets>, {
|
|
954
|
+
type: "DISCONNECT";
|
|
955
|
+
}, {
|
|
956
|
+
type: "CONNECT";
|
|
957
|
+
} | {
|
|
958
|
+
type: "DISCONNECT";
|
|
959
|
+
} | {
|
|
960
|
+
type: "SERIAL.DATA";
|
|
961
|
+
data: Packet;
|
|
962
|
+
} | {
|
|
963
|
+
type: "SERIAL.ERROR";
|
|
964
|
+
error: string;
|
|
965
|
+
} | {
|
|
966
|
+
type: "FATAL_ERROR";
|
|
967
|
+
error: string;
|
|
968
|
+
} | {
|
|
969
|
+
type: "SERIAL.DISCONNECTED";
|
|
970
|
+
} | {
|
|
971
|
+
type: "STOP";
|
|
972
|
+
} | {
|
|
973
|
+
type: "SET_LOGGING";
|
|
974
|
+
enabled: boolean;
|
|
975
|
+
} | {
|
|
976
|
+
type: "SET_BAUD_RATE";
|
|
977
|
+
baudRate: number;
|
|
978
|
+
}, undefined, never, never, never, never, never>;
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
readonly invoke: {
|
|
982
|
+
readonly id: "streamReader";
|
|
983
|
+
readonly src: "readNmeaStream";
|
|
984
|
+
readonly input: ({ context }: {
|
|
985
|
+
context: NmeaContext<TData, TPackets>;
|
|
986
|
+
event: {
|
|
987
|
+
type: "CONNECT";
|
|
988
|
+
} | {
|
|
989
|
+
type: "DISCONNECT";
|
|
990
|
+
} | {
|
|
991
|
+
type: "SERIAL.DATA";
|
|
992
|
+
data: Packet;
|
|
993
|
+
} | {
|
|
994
|
+
type: "SERIAL.ERROR";
|
|
995
|
+
error: string;
|
|
996
|
+
} | {
|
|
997
|
+
type: "FATAL_ERROR";
|
|
998
|
+
error: string;
|
|
999
|
+
} | {
|
|
1000
|
+
type: "SERIAL.DISCONNECTED";
|
|
1001
|
+
} | {
|
|
1002
|
+
type: "STOP";
|
|
1003
|
+
} | {
|
|
1004
|
+
type: "SET_LOGGING";
|
|
1005
|
+
enabled: boolean;
|
|
1006
|
+
} | {
|
|
1007
|
+
type: "SET_BAUD_RATE";
|
|
1008
|
+
baudRate: number;
|
|
1009
|
+
};
|
|
1010
|
+
self: ActorRef<MachineSnapshot<NmeaContext<TData, TPackets>, {
|
|
1011
|
+
type: "CONNECT";
|
|
1012
|
+
} | {
|
|
1013
|
+
type: "DISCONNECT";
|
|
1014
|
+
} | {
|
|
1015
|
+
type: "SERIAL.DATA";
|
|
1016
|
+
data: Packet;
|
|
1017
|
+
} | {
|
|
1018
|
+
type: "SERIAL.ERROR";
|
|
1019
|
+
error: string;
|
|
1020
|
+
} | {
|
|
1021
|
+
type: "FATAL_ERROR";
|
|
1022
|
+
error: string;
|
|
1023
|
+
} | {
|
|
1024
|
+
type: "SERIAL.DISCONNECTED";
|
|
1025
|
+
} | {
|
|
1026
|
+
type: "STOP";
|
|
1027
|
+
} | {
|
|
1028
|
+
type: "SET_LOGGING";
|
|
1029
|
+
enabled: boolean;
|
|
1030
|
+
} | {
|
|
1031
|
+
type: "SET_BAUD_RATE";
|
|
1032
|
+
baudRate: number;
|
|
1033
|
+
}, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, {
|
|
1034
|
+
type: "CONNECT";
|
|
1035
|
+
} | {
|
|
1036
|
+
type: "DISCONNECT";
|
|
1037
|
+
} | {
|
|
1038
|
+
type: "SERIAL.DATA";
|
|
1039
|
+
data: Packet;
|
|
1040
|
+
} | {
|
|
1041
|
+
type: "SERIAL.ERROR";
|
|
1042
|
+
error: string;
|
|
1043
|
+
} | {
|
|
1044
|
+
type: "FATAL_ERROR";
|
|
1045
|
+
error: string;
|
|
1046
|
+
} | {
|
|
1047
|
+
type: "SERIAL.DISCONNECTED";
|
|
1048
|
+
} | {
|
|
1049
|
+
type: "STOP";
|
|
1050
|
+
} | {
|
|
1051
|
+
type: "SET_LOGGING";
|
|
1052
|
+
enabled: boolean;
|
|
1053
|
+
} | {
|
|
1054
|
+
type: "SET_BAUD_RATE";
|
|
1055
|
+
baudRate: number;
|
|
1056
|
+
}, AnyEventObject>;
|
|
1057
|
+
}) => {
|
|
1058
|
+
port: SerialPort;
|
|
1059
|
+
};
|
|
1060
|
+
};
|
|
1061
|
+
};
|
|
1062
|
+
readonly disconnecting: {
|
|
1063
|
+
readonly invoke: {
|
|
1064
|
+
readonly id: "closePort";
|
|
1065
|
+
readonly src: "closePort";
|
|
1066
|
+
readonly input: ({ context }: {
|
|
1067
|
+
context: NmeaContext<TData, TPackets>;
|
|
1068
|
+
event: {
|
|
1069
|
+
type: "CONNECT";
|
|
1070
|
+
} | {
|
|
1071
|
+
type: "DISCONNECT";
|
|
1072
|
+
} | {
|
|
1073
|
+
type: "SERIAL.DATA";
|
|
1074
|
+
data: Packet;
|
|
1075
|
+
} | {
|
|
1076
|
+
type: "SERIAL.ERROR";
|
|
1077
|
+
error: string;
|
|
1078
|
+
} | {
|
|
1079
|
+
type: "FATAL_ERROR";
|
|
1080
|
+
error: string;
|
|
1081
|
+
} | {
|
|
1082
|
+
type: "SERIAL.DISCONNECTED";
|
|
1083
|
+
} | {
|
|
1084
|
+
type: "STOP";
|
|
1085
|
+
} | {
|
|
1086
|
+
type: "SET_LOGGING";
|
|
1087
|
+
enabled: boolean;
|
|
1088
|
+
} | {
|
|
1089
|
+
type: "SET_BAUD_RATE";
|
|
1090
|
+
baudRate: number;
|
|
1091
|
+
};
|
|
1092
|
+
self: ActorRef<MachineSnapshot<NmeaContext<TData, TPackets>, {
|
|
1093
|
+
type: "CONNECT";
|
|
1094
|
+
} | {
|
|
1095
|
+
type: "DISCONNECT";
|
|
1096
|
+
} | {
|
|
1097
|
+
type: "SERIAL.DATA";
|
|
1098
|
+
data: Packet;
|
|
1099
|
+
} | {
|
|
1100
|
+
type: "SERIAL.ERROR";
|
|
1101
|
+
error: string;
|
|
1102
|
+
} | {
|
|
1103
|
+
type: "FATAL_ERROR";
|
|
1104
|
+
error: string;
|
|
1105
|
+
} | {
|
|
1106
|
+
type: "SERIAL.DISCONNECTED";
|
|
1107
|
+
} | {
|
|
1108
|
+
type: "STOP";
|
|
1109
|
+
} | {
|
|
1110
|
+
type: "SET_LOGGING";
|
|
1111
|
+
enabled: boolean;
|
|
1112
|
+
} | {
|
|
1113
|
+
type: "SET_BAUD_RATE";
|
|
1114
|
+
baudRate: number;
|
|
1115
|
+
}, Record<string, AnyActorRef>, StateValue, string, unknown, any, any>, {
|
|
1116
|
+
type: "CONNECT";
|
|
1117
|
+
} | {
|
|
1118
|
+
type: "DISCONNECT";
|
|
1119
|
+
} | {
|
|
1120
|
+
type: "SERIAL.DATA";
|
|
1121
|
+
data: Packet;
|
|
1122
|
+
} | {
|
|
1123
|
+
type: "SERIAL.ERROR";
|
|
1124
|
+
error: string;
|
|
1125
|
+
} | {
|
|
1126
|
+
type: "FATAL_ERROR";
|
|
1127
|
+
error: string;
|
|
1128
|
+
} | {
|
|
1129
|
+
type: "SERIAL.DISCONNECTED";
|
|
1130
|
+
} | {
|
|
1131
|
+
type: "STOP";
|
|
1132
|
+
} | {
|
|
1133
|
+
type: "SET_LOGGING";
|
|
1134
|
+
enabled: boolean;
|
|
1135
|
+
} | {
|
|
1136
|
+
type: "SET_BAUD_RATE";
|
|
1137
|
+
baudRate: number;
|
|
1138
|
+
}, AnyEventObject>;
|
|
1139
|
+
}) => {
|
|
1140
|
+
port: SerialPort | null;
|
|
1141
|
+
};
|
|
1142
|
+
readonly onDone: {
|
|
1143
|
+
readonly target: "disconnected";
|
|
1144
|
+
readonly actions: "disconnect";
|
|
1145
|
+
};
|
|
1146
|
+
readonly onError: {
|
|
1147
|
+
readonly target: "disconnected";
|
|
1148
|
+
readonly actions: "disconnect";
|
|
1149
|
+
};
|
|
1150
|
+
};
|
|
1151
|
+
};
|
|
1152
|
+
readonly error: {
|
|
1153
|
+
readonly on: {
|
|
1154
|
+
readonly CONNECT: "connecting";
|
|
1155
|
+
};
|
|
1156
|
+
};
|
|
1157
|
+
};
|
|
1158
|
+
}>;
|
|
1159
|
+
|
|
1160
|
+
declare type CustomPackets = DBSPacket | DBKPacket | DPTPacket;
|
|
1161
|
+
|
|
1162
|
+
export declare interface DBKPacket extends PacketStub<typeof sentenceId_3> {
|
|
1163
|
+
depthFeet: number;
|
|
1164
|
+
depthMeters: number;
|
|
1165
|
+
depthFathoms: number;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
export declare interface DBSPacket extends PacketStub<typeof sentenceId_2> {
|
|
1169
|
+
depthFeet: number;
|
|
1170
|
+
depthMeters: number;
|
|
1171
|
+
depthFathoms: number;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
export declare interface DPTPacket extends PacketStub<typeof sentenceId> {
|
|
1175
|
+
depthMeters: number;
|
|
1176
|
+
offsetMeters: number;
|
|
1177
|
+
maximumRangeScale: number;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
export declare function encodeAltitude(alt: number): string;
|
|
1181
|
+
|
|
1182
|
+
export declare function encodeAltitudeNoUnits(alt: number): string;
|
|
1183
|
+
|
|
1184
|
+
export declare function encodeDate(date?: Date): string;
|
|
1185
|
+
|
|
1186
|
+
export declare function encodeDegrees(degrees?: number): string;
|
|
1187
|
+
|
|
1188
|
+
export declare function encodeFixed(value: number | undefined, decimalPlaces: number): string;
|
|
1189
|
+
|
|
1190
|
+
export declare function encodeGeoidalSeperation(geoidalSep: number): string;
|
|
1191
|
+
|
|
1192
|
+
export declare function encodeGeoidalSeperationNoUnits(geoidalSep: number): string;
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* Encodes the latitude in the standard NMEA format "ddmm.mmmmmm".
|
|
1196
|
+
*
|
|
1197
|
+
* @param latitude Latitude in decimal degrees.
|
|
1198
|
+
*/
|
|
1199
|
+
export declare function encodeLatitude(latitude?: number): string;
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* Encodes the longitude in the standard NMEA format "dddmm.mmmmmm".
|
|
1203
|
+
*
|
|
1204
|
+
* @param longitude Longitude in decimal degrees.
|
|
1205
|
+
*/
|
|
1206
|
+
export declare function encodeLongitude(longitude?: number): string;
|
|
1207
|
+
|
|
1208
|
+
export declare function encodeTime(date?: Date): string;
|
|
1209
|
+
|
|
1210
|
+
export declare function encodeValue(value?: unknown): string;
|
|
1211
|
+
|
|
1212
|
+
declare type ExtendedNmeaPacket = Packet | CustomPackets;
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Initial navigation data state.
|
|
1216
|
+
*/
|
|
1217
|
+
export declare const initialNavigationData: NavigationData;
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Initial stored packets state.
|
|
1221
|
+
*/
|
|
1222
|
+
export declare const initialNavigationPackets: StoredPackets;
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* Default sentence IDs used for navigation data computation.
|
|
1226
|
+
* Includes standard NMEA sentences and custom depth sentences.
|
|
1227
|
+
*/
|
|
1228
|
+
export declare const NAVIGATION_SENTENCE_IDS: readonly ["GGA", "RMC", "GLL", "VTG", "HDT", "HDG", "HDM", "DPT", "DBT", "DBS", "DBK", "ZDA"];
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* Types for navigation data.
|
|
1232
|
+
*/
|
|
1233
|
+
export declare interface NavigationData {
|
|
1234
|
+
time: {
|
|
1235
|
+
utc: Date;
|
|
1236
|
+
local: Date | null;
|
|
1237
|
+
source: 'ZDA' | 'GGA' | 'RMC' | 'GLL' | null;
|
|
1238
|
+
} | null;
|
|
1239
|
+
position: {
|
|
1240
|
+
latitude: number;
|
|
1241
|
+
longitude: number;
|
|
1242
|
+
source: 'GGA' | 'RMC' | 'GLL' | null;
|
|
1243
|
+
fixType?: 'none' | 'fix' | 'delta' | 'pps' | 'rtk' | 'frtk' | 'estimated' | 'manual' | 'simulation';
|
|
1244
|
+
status?: 'valid' | 'warning' | 'invalid';
|
|
1245
|
+
altitudeMeters?: number;
|
|
1246
|
+
satellitesInView?: number;
|
|
1247
|
+
horizontalDilution?: number;
|
|
1248
|
+
} | null;
|
|
1249
|
+
speed: {
|
|
1250
|
+
knots: number;
|
|
1251
|
+
source: 'VTG' | 'RMC' | null;
|
|
1252
|
+
} | null;
|
|
1253
|
+
heading: {
|
|
1254
|
+
degreesTrue: number;
|
|
1255
|
+
source: 'HDT' | 'HDG' | 'HDM' | 'COG' | null;
|
|
1256
|
+
isDerived: boolean;
|
|
1257
|
+
} | null;
|
|
1258
|
+
depth: {
|
|
1259
|
+
meters: number;
|
|
1260
|
+
source: 'DPT' | 'DBT' | 'DBS' | 'DBK' | null;
|
|
1261
|
+
} | null;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Generic context for the NMEA state machine.
|
|
1266
|
+
* @template TData - The type of computed/translated data.
|
|
1267
|
+
* @template TPackets - The type of stored packets.
|
|
1268
|
+
*/
|
|
1269
|
+
export declare interface NmeaContext<TData, TPackets extends Record<string, unknown>> {
|
|
1270
|
+
/** The active Web Serial port connection, or null if disconnected. */
|
|
1271
|
+
port: SerialPort | null;
|
|
1272
|
+
/** Current error message, or null if no error. */
|
|
1273
|
+
error: string | null;
|
|
1274
|
+
/** Map of stored NMEA packets by sentence ID. */
|
|
1275
|
+
packets: TPackets;
|
|
1276
|
+
/** Computed/translated data derived from stored packets via the adapter. */
|
|
1277
|
+
data: TData;
|
|
1278
|
+
/** Whether to log parsed NMEA packets to the console. */
|
|
1279
|
+
enableLogging: boolean;
|
|
1280
|
+
/** Baud rate for serial port communication. Default is 4800 (standard NMEA rate). */
|
|
1281
|
+
baudRate: number;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Events that the NMEA state machine can handle.
|
|
1286
|
+
*/
|
|
1287
|
+
export declare type NmeaEvent = {
|
|
1288
|
+
type: 'CONNECT';
|
|
1289
|
+
} | {
|
|
1290
|
+
type: 'DISCONNECT';
|
|
1291
|
+
} | {
|
|
1292
|
+
type: 'SERIAL.DATA';
|
|
1293
|
+
data: Packet;
|
|
1294
|
+
} | {
|
|
1295
|
+
type: 'SERIAL.ERROR';
|
|
1296
|
+
error: string;
|
|
1297
|
+
} | {
|
|
1298
|
+
type: 'FATAL_ERROR';
|
|
1299
|
+
error: string;
|
|
1300
|
+
} | {
|
|
1301
|
+
type: 'SERIAL.DISCONNECTED';
|
|
1302
|
+
} | {
|
|
1303
|
+
type: 'STOP';
|
|
1304
|
+
} | {
|
|
1305
|
+
type: 'SET_LOGGING';
|
|
1306
|
+
enabled: boolean;
|
|
1307
|
+
} | {
|
|
1308
|
+
type: 'SET_BAUD_RATE';
|
|
1309
|
+
baudRate: number;
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* Type helper to extract the machine type from the factory function.
|
|
1314
|
+
* @template TData - The type of computed/translated data.
|
|
1315
|
+
* @template TPackets - The type of stored packets.
|
|
1316
|
+
*/
|
|
1317
|
+
export declare type NmeaMachineActor<TData, TPackets extends Record<string, unknown>> = ActorRefFrom<ReturnType<typeof createNmeaMachine<TData, TPackets>>>;
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* Configuration for creating an NMEA machine.
|
|
1321
|
+
* @template TData - The type of computed/translated data stored in context.
|
|
1322
|
+
* @template TPackets - The type of stored packets (typically a record of sentence ID to packet).
|
|
1323
|
+
*/
|
|
1324
|
+
export declare interface NmeaMachineConfig<TData, TPackets extends Record<string, unknown>> {
|
|
1325
|
+
/** Function that transforms stored packets into the computed data type. */
|
|
1326
|
+
adapter: (packets: TPackets) => TData;
|
|
1327
|
+
/** Optional list of sentence IDs to filter and store. If not provided, all parsed sentences are stored. */
|
|
1328
|
+
allowedSentenceIds?: readonly string[];
|
|
1329
|
+
/** Initial computed data value. */
|
|
1330
|
+
initialData: TData;
|
|
1331
|
+
/** Initial stored packets value. */
|
|
1332
|
+
initialPackets: TPackets;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
export declare function padLeft(value: string | number, length: number, paddingCharacter: string): string;
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Parses coordinate given as "dddmm.mm", "ddmm.mm", "dmm.mm" or "mm.mm"
|
|
1339
|
+
*/
|
|
1340
|
+
export declare function parseDmCoordinate(coordinate: string): number;
|
|
1341
|
+
|
|
1342
|
+
/**
|
|
1343
|
+
* Parse the given string to a float, returning 0 for an empty string.
|
|
1344
|
+
*/
|
|
1345
|
+
export declare function parseFloatSafe(str: string): number;
|
|
1346
|
+
|
|
1347
|
+
/**
|
|
1348
|
+
* Parse the given string to a integer, returning 0 for an empty string.
|
|
1349
|
+
*/
|
|
1350
|
+
export declare function parseIntSafe(i: string): number;
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* Parses latitude given as "ddmm.mm", "dmm.mm" or "mm.mm" (assuming zero
|
|
1354
|
+
* degrees) along with a given hemisphere of "N" or "S" into decimal degrees,
|
|
1355
|
+
* where north is positive and south is negative.
|
|
1356
|
+
*/
|
|
1357
|
+
export declare function parseLatitude(lat: string, hemi: string): number;
|
|
1358
|
+
|
|
1359
|
+
/**
|
|
1360
|
+
* Parses latitude given as "dddmm.mm", "ddmm.mm", "dmm.mm" or "mm.mm" (assuming
|
|
1361
|
+
* zero degrees) along with a given hemisphere of "E" or "W" into decimal
|
|
1362
|
+
* degrees, where east is positive and west is negative.
|
|
1363
|
+
*/
|
|
1364
|
+
export declare function parseLongitude(lon: string, hemi: string): number;
|
|
1365
|
+
|
|
1366
|
+
export declare function parseNmeaSentence(sentence: string): ExtendedNmeaPacket;
|
|
1367
|
+
|
|
1368
|
+
/**
|
|
1369
|
+
* Parse the given string to a float if possible, returning 0 for an undefined
|
|
1370
|
+
* value and a string the the given string cannot be parsed.
|
|
1371
|
+
*/
|
|
1372
|
+
export declare function parseNumberOrString(str?: string): number | string;
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* Parses a UTC time and optionally a date and returns a Date
|
|
1376
|
+
* object.
|
|
1377
|
+
* @param {string} time Time the format "hhmmss" or "hhmmss.ss"
|
|
1378
|
+
* @param {string=} date Optional date in format the ddmmyyyy or ddmmyy
|
|
1379
|
+
* @returns {Date}
|
|
1380
|
+
*/
|
|
1381
|
+
export declare function parseTime(time: string, date?: string, rmcCompatible?: boolean): Date;
|
|
1382
|
+
|
|
1383
|
+
export declare function parseUnsafeNmeaSentence(sentence: string): ExtendedNmeaPacket | UnknownPacket;
|
|
1384
|
+
|
|
1385
|
+
declare const sentenceId: "DPT";
|
|
1386
|
+
|
|
1387
|
+
declare const sentenceId_2: "DBS";
|
|
1388
|
+
|
|
1389
|
+
declare const sentenceId_3: "DBK";
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Types for stored packets by sentence type.
|
|
1393
|
+
*/
|
|
1394
|
+
export declare interface StoredPackets extends Record<string, unknown> {
|
|
1395
|
+
GGA?: GGAPacket;
|
|
1396
|
+
RMC?: RMCPacket;
|
|
1397
|
+
GLL?: GLLPacket;
|
|
1398
|
+
VTG?: VTGPacket;
|
|
1399
|
+
HDT?: HDTPacket;
|
|
1400
|
+
HDG?: HDGPacket;
|
|
1401
|
+
HDM?: HDMPacket;
|
|
1402
|
+
DPT?: DPTPacket;
|
|
1403
|
+
DBT?: DBTPacket;
|
|
1404
|
+
DBS?: DBSPacket;
|
|
1405
|
+
DBK?: DBKPacket;
|
|
1406
|
+
ZDA?: ZDAPacket;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* Utility functions for NMEA encoding, decoding, and validation.
|
|
1411
|
+
*/
|
|
1412
|
+
export declare function toHexString(v: number): string;
|
|
1413
|
+
|
|
1414
|
+
export declare type UnsafeAndCustomPackets = CustomPackets | UnknownPacket;
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* Checks that the given NMEA sentence has a valid checksum.
|
|
1418
|
+
*/
|
|
1419
|
+
export declare function validNmeaChecksum(nmeaSentence: string): boolean;
|
|
1420
|
+
|
|
1421
|
+
export { }
|