nmea-web-serial 1.0.0 → 1.1.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 +2 -0
- package/README.md +128 -0
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
+
Copyright (c) 2025 British Antarctic Survey
|
|
4
|
+
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
5
7
|
in the Software without restriction, including without limitation the rights
|
package/README.md
CHANGED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# NMEA 0183 sentence parser for the Web Serial API
|
|
2
|
+
|
|
3
|
+
This library provides a state machine-based solution for parsing NMEA 0183 sentences from serial ports using the Web Serial API. It builds on top of [nmea-simple](https://www.npmjs.com/package/nmea-simple) and extends it with custom depth sentence codecs (DPT, DBS, DBK) and a navigation data adapter that computes position, time, speed, heading, and depth from multiple NMEA sentences.
|
|
4
|
+
|
|
5
|
+
The library uses [XState](https://xstate.js.org/) to manage serial port connection state and provides a convenient navigation adapter that automatically computes navigation data from various NMEA sentence types.
|
|
6
|
+
|
|
7
|
+
The official NMEA 0183 standard can be found [here](http://www.nmea.org/content/nmea_standards/nmea_0183_v_410.asp) and is described in clear terms [here](https://gpsd.gitlab.io/gpsd/NMEA.html).
|
|
8
|
+
|
|
9
|
+
## Example
|
|
10
|
+
|
|
11
|
+
Typically, you will get NMEA sentences via the Web Serial API from a GPS module or other NMEA device. The library provides a state machine that handles connection, reading, parsing, and data computation.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createNavigationNmeaMachine } from 'nmea-web-serial'
|
|
15
|
+
import { createActor } from 'xstate'
|
|
16
|
+
|
|
17
|
+
// Create the machine
|
|
18
|
+
const machine = createNavigationNmeaMachine()
|
|
19
|
+
|
|
20
|
+
// Create the actor
|
|
21
|
+
const actor = createActor(machine)
|
|
22
|
+
actor.start()
|
|
23
|
+
|
|
24
|
+
// Subscribe to state changes
|
|
25
|
+
actor.subscribe((state) => {
|
|
26
|
+
if (state.value === 'connected') {
|
|
27
|
+
const navigationData = state.context.data
|
|
28
|
+
|
|
29
|
+
if (navigationData.position) {
|
|
30
|
+
console.log('Position:', navigationData.position.latitude, navigationData.position.longitude)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (navigationData.speed) {
|
|
34
|
+
console.log('Speed:', navigationData.speed.knots, 'knots')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (navigationData.heading) {
|
|
38
|
+
console.log('Heading:', navigationData.heading.degreesTrue, '°')
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// Connect to a serial port
|
|
44
|
+
actor.send({ type: 'CONNECT' })
|
|
45
|
+
|
|
46
|
+
// Disconnect when done
|
|
47
|
+
actor.send({ type: 'DISCONNECT' })
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## TypeScript
|
|
51
|
+
|
|
52
|
+
This project is written in [TypeScript](http://www.typescriptlang.org/). The library can be used by plain JavaScript as shown above, and the typing information is included with the library so that anyone wishing to use TypeScript will gain the benefits of the type information.
|
|
53
|
+
|
|
54
|
+
## Packet types supported
|
|
55
|
+
|
|
56
|
+
The library supports all packet types from [nmea-simple](https://www.npmjs.com/package/nmea-simple), plus the following custom depth sentences:
|
|
57
|
+
|
|
58
|
+
- `DPT` - Depth
|
|
59
|
+
- `DBS` - Depth Below Surface
|
|
60
|
+
- `DBK` - Depth Below Keel
|
|
61
|
+
|
|
62
|
+
The navigation adapter uses the following sentence types to compute navigation data:
|
|
63
|
+
|
|
64
|
+
- `GGA` - GPS Fix Data
|
|
65
|
+
- `RMC` - Recommended Minimum Specific GNSS Data
|
|
66
|
+
- `GLL` - Geographic Position: Latitude/Longitude
|
|
67
|
+
- `VTG` - Course Over Ground and Ground Speed
|
|
68
|
+
- `HDT` - Heading, True
|
|
69
|
+
- `HDG` - Heading, Deviation & Variation
|
|
70
|
+
- `HDM` - Heading, Magnetic
|
|
71
|
+
- `DPT` - Depth
|
|
72
|
+
- `DBT` - Depth Below Transducer
|
|
73
|
+
- `DBS` - Depth Below Surface
|
|
74
|
+
- `DBK` - Depth Below Keel
|
|
75
|
+
- `ZDA` - Time & Date
|
|
76
|
+
|
|
77
|
+
## Navigation Data Adapter
|
|
78
|
+
|
|
79
|
+
The navigation adapter automatically computes navigation data from multiple NMEA sentences using priority-based fallback:
|
|
80
|
+
|
|
81
|
+
- **Position**: GGA (with fix) → RMC (valid) → GLL (valid)
|
|
82
|
+
- **Time**: ZDA → GGA → RMC → GLL (ZDA includes timezone for local time)
|
|
83
|
+
- **Speed**: VTG → RMC
|
|
84
|
+
- **Heading**: HDT → HDG → HDM (with external variation) → COG (from RMC/VTG)
|
|
85
|
+
- **Depth**: DPT → DBT → DBS → DBK
|
|
86
|
+
|
|
87
|
+
## Custom Machines
|
|
88
|
+
|
|
89
|
+
You can create custom machines with your own adapter functions:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { createNmeaMachine } from 'nmea-web-serial'
|
|
93
|
+
|
|
94
|
+
interface MyData {
|
|
95
|
+
customField: string | null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface MyPackets extends Record<string, unknown> {
|
|
99
|
+
GGA?: GGAPacket
|
|
100
|
+
// ... other packet types
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function myAdapter(packets: MyPackets): MyData {
|
|
104
|
+
return {
|
|
105
|
+
customField: packets.GGA ? 'has position' : null
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const machine = createNmeaMachine({
|
|
110
|
+
adapter: myAdapter,
|
|
111
|
+
allowedSentenceIds: ['GGA', 'RMC'],
|
|
112
|
+
initialData: { customField: null },
|
|
113
|
+
initialPackets: {},
|
|
114
|
+
})
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Browser Support
|
|
118
|
+
|
|
119
|
+
The Web Serial API is supported in:
|
|
120
|
+
- Chrome 89+
|
|
121
|
+
- Edge 89+
|
|
122
|
+
- Opera 75+
|
|
123
|
+
|
|
124
|
+
Firefox and Safari do not currently support the Web Serial API.
|
|
125
|
+
|
|
126
|
+
## Acknowledgements
|
|
127
|
+
|
|
128
|
+
This module is built on top of [nmea-simple](https://www.npmjs.com/package/nmea-simple) and uses [XState](https://xstate.js.org/) for state management. The documentation was expanded based on the excellent [analysis and descriptions](http://catb.org/gpsd/NMEA.html) by Eric S. Raymond.
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nmea-web-serial",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"packageManager": "npm@10.8.2",
|
|
6
6
|
"description": "NMEA 0183 sentence parser for the Web Serial API",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Jonathan Dawe",
|
|
9
9
|
"email": "jonwe@bas.ac.uk"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://github.com/
|
|
11
|
+
"homepage": "https://github.com/antarctica/nmea-web-serial#readme",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/
|
|
14
|
+
"url": "git+https://github.com/antarctica/nmea-web-serial.git"
|
|
15
15
|
},
|
|
16
16
|
"bugs": {
|
|
17
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "https://github.com/antarctica/nmea-web-serial/issues"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"dev": "vite",
|
|
33
33
|
"build": "tsc && vite build",
|
|
34
|
-
"build:all": "
|
|
34
|
+
"build:all": "turbo run build",
|
|
35
35
|
"lint": "eslint . --fix",
|
|
36
36
|
"lint:all": "turbo run lint",
|
|
37
37
|
"test": "vitest --run",
|