nmea-web-serial 1.1.1 → 1.1.2

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.
@@ -12,7 +12,6 @@ import { EventObject } from 'xstate';
12
12
  import { GGAPacket } from 'nmea-simple';
13
13
  import { GLLPacket } from 'nmea-simple';
14
14
  import { HDGPacket } from 'nmea-simple';
15
- import { HDMPacket } from 'nmea-simple';
16
15
  import { HDTPacket } from 'nmea-simple';
17
16
  import { MachineSnapshot } from 'xstate';
18
17
  import { MetaObject } from 'xstate';
@@ -29,60 +28,38 @@ import { VTGPacket } from 'nmea-simple';
29
28
  import { ZDAPacket } from 'nmea-simple';
30
29
 
31
30
  /**
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.
31
+ * Simple client for navigation NMEA data.
32
+ * Creates a machine and manages connection state automatically.
51
33
  *
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.
34
+ * @param options - Configuration options.
35
+ * @returns A client instance for managing the NMEA connection.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const client = createNavigationNmeaClient({
40
+ * enableLogging: true,
41
+ * onData: (navigation) => {
42
+ * console.log('Position:', navigation.position);
43
+ * },
44
+ * });
45
+ *
46
+ * client.connect();
47
+ * ```
60
48
  */
61
- export declare function createNavigationNmeaConfig(options?: {
62
- allowedSentenceIds?: readonly string[];
63
- externalVariation?: number;
64
- }): NmeaMachineConfig<NavigationData, StoredPackets>;
49
+ export declare function createNavigationNmeaClient(options?: NmeaClientOptions<NavigationData>): NmeaClient<NavigationData, StoredPackets>;
65
50
 
66
51
  /**
67
52
  * Convenience function to create a navigation-focused NMEA machine.
68
53
  * This is a pre-configured machine that computes navigation data from NMEA packets.
69
54
  *
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
55
  * @returns An NMEA machine configured for navigation data computation.
74
56
  *
75
57
  * @example
76
58
  * ```typescript
77
- * const machine = createNavigationNmeaMachine({
78
- * externalVariation: 5.5,
79
- * });
59
+ * const machine = createNavigationNmeaMachine();
80
60
  * ```
81
61
  */
82
- export declare function createNavigationNmeaMachine(options?: {
83
- allowedSentenceIds?: readonly string[];
84
- externalVariation?: number;
85
- }): StateMachine<NmeaContext<NavigationData, StoredPackets>, {
62
+ export declare function createNavigationNmeaMachine(): StateMachine<NmeaContext<NavigationData, StoredPackets>, {
86
63
  type: "CONNECT";
87
64
  } | {
88
65
  type: "DISCONNECT";
@@ -608,11 +585,6 @@ readonly CONNECT: "connecting";
608
585
  };
609
586
  }>;
610
587
 
611
- /**
612
- * Generate the correct trailing "*xx" footer for an NMEA sentence.
613
- */
614
- export declare function createNmeaChecksumFooter(sentenceWithoutChecksum: string): string;
615
-
616
588
  /**
617
589
  * Factory function to create an NMEA state machine with a generic adapter pattern.
618
590
  *
@@ -1177,56 +1149,8 @@ export declare interface DPTPacket extends PacketStub<typeof sentenceId> {
1177
1149
  maximumRangeScale: number;
1178
1150
  }
1179
1151
 
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
1152
  declare type ExtendedNmeaPacket = Packet | CustomPackets;
1213
1153
 
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
1154
  /**
1231
1155
  * Types for navigation data.
1232
1156
  */
@@ -1252,7 +1176,7 @@ export declare interface NavigationData {
1252
1176
  } | null;
1253
1177
  heading: {
1254
1178
  degreesTrue: number;
1255
- source: 'HDT' | 'HDG' | 'HDM' | 'COG' | null;
1179
+ source: 'HDT' | 'HDG' | 'COG' | null;
1256
1180
  isDerived: boolean;
1257
1181
  } | null;
1258
1182
  depth: {
@@ -1261,6 +1185,81 @@ export declare interface NavigationData {
1261
1185
  } | null;
1262
1186
  }
1263
1187
 
1188
+ /**
1189
+ * Simple client for managing NMEA connections.
1190
+ * Abstracts away XState details while still exposing the machine for advanced use.
1191
+ */
1192
+ export declare class NmeaClient<TData, TPackets extends Record<string, unknown>> {
1193
+ private actor;
1194
+ private subscription;
1195
+ private options?;
1196
+ /**
1197
+ * Creates a new NMEA client.
1198
+ *
1199
+ * @param machine - The NMEA machine instance (created with createNmeaMachine).
1200
+ * @param options - Optional configuration and callbacks.
1201
+ */
1202
+ constructor(machine: ReturnType<typeof createNmeaMachine<TData, TPackets>>, options?: NmeaClientOptions<TData>);
1203
+ private setupSubscriptions;
1204
+ /**
1205
+ * Gets the current data.
1206
+ */
1207
+ get data(): TData;
1208
+ /**
1209
+ * Gets whether the connection is currently active.
1210
+ */
1211
+ get isConnected(): boolean;
1212
+ /**
1213
+ * Gets whether the connection is in progress.
1214
+ */
1215
+ get isConnecting(): boolean;
1216
+ /**
1217
+ * Gets the current error message, if any.
1218
+ */
1219
+ get error(): string | null;
1220
+ /**
1221
+ * Connects to the serial port.
1222
+ */
1223
+ connect(): void;
1224
+ /**
1225
+ * Disconnects from the serial port.
1226
+ */
1227
+ disconnect(): void;
1228
+ /**
1229
+ * Sets logging enabled/disabled.
1230
+ */
1231
+ setLogging(enabled: boolean): void;
1232
+ /**
1233
+ * Sets the baud rate (requires reconnection to take effect).
1234
+ */
1235
+ setBaudRate(baudRate: number): void;
1236
+ /**
1237
+ * Gets the underlying XState actor (for advanced users).
1238
+ * Allows access to full XState functionality.
1239
+ */
1240
+ get machine(): NmeaMachineActor<TData, TPackets>;
1241
+ /**
1242
+ * Disposes of the client and cleans up resources.
1243
+ */
1244
+ dispose(): void;
1245
+ }
1246
+
1247
+ /**
1248
+ * Configuration for the NMEA client.
1249
+ */
1250
+ export declare interface NmeaClientOptions<TData = unknown> {
1251
+ /** Whether to enable logging of parsed packets. */
1252
+ enableLogging?: boolean;
1253
+ /** Baud rate for serial communication. Default is 4800. */
1254
+ baudRate?: number;
1255
+ /** Callback function called when data is updated. */
1256
+ onData?: (data: TData) => void;
1257
+ /** Callback function called when connection state changes. */
1258
+ onStateChange?: (isConnected: boolean) => void;
1259
+ /** Callback function called when an error occurs. */
1260
+ onError?: (error: string) => void;
1261
+ }
1262
+
1264
1263
  /**
1265
1264
  * Generic context for the NMEA state machine.
1266
1265
  * @template TData - The type of computed/translated data.
@@ -1332,54 +1331,10 @@ export declare interface NmeaMachineConfig<TData, TPackets extends Record<string
1332
1331
  initialPackets: TPackets;
1333
1332
  }
1334
1333
 
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;
1334
+ export { Packet }
1365
1335
 
1366
1336
  export declare function parseNmeaSentence(sentence: string): ExtendedNmeaPacket;
1367
1337
 
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
1338
  export declare function parseUnsafeNmeaSentence(sentence: string): ExtendedNmeaPacket | UnknownPacket;
1384
1339
 
1385
1340
  declare const sentenceId: "DPT";
@@ -1398,7 +1353,6 @@ export declare interface StoredPackets extends Record<string, unknown> {
1398
1353
  VTG?: VTGPacket;
1399
1354
  HDT?: HDTPacket;
1400
1355
  HDG?: HDGPacket;
1401
- HDM?: HDMPacket;
1402
1356
  DPT?: DPTPacket;
1403
1357
  DBT?: DBTPacket;
1404
1358
  DBS?: DBSPacket;
@@ -1406,16 +1360,6 @@ export declare interface StoredPackets extends Record<string, unknown> {
1406
1360
  ZDA?: ZDAPacket;
1407
1361
  }
1408
1362
 
1409
- /**
1410
- * Utility functions for NMEA encoding, decoding, and validation.
1411
- */
1412
- export declare function toHexString(v: number): string;
1413
-
1414
1363
  export declare type UnsafeAndCustomPackets = CustomPackets | UnknownPacket;
1415
1364
 
1416
- /**
1417
- * Checks that the given NMEA sentence has a valid checksum.
1418
- */
1419
- export declare function validNmeaChecksum(nmeaSentence: string): boolean;
1420
-
1421
1365
  export { }