node-mavlink 1.0.13 → 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/README.md
CHANGED
@@ -19,11 +19,11 @@ $ npm install --save node-mavlink serialport
|
|
19
19
|
Once you've done it you can start using it. First you'll need a serial port that can parse messages one by one. Please note that since we're using ECMAScript modules the file name should end with `.mjs` extension (e.g. `test.mjs`)
|
20
20
|
|
21
21
|
```javascript
|
22
|
-
import SerialPort from 'serialport'
|
22
|
+
import { SerialPort } from 'serialport'
|
23
23
|
import { MavLinkPacketSplitter, MavLinkPacketParser } from 'node-mavlink'
|
24
24
|
|
25
25
|
// substitute /dev/ttyACM0 with your serial port!
|
26
|
-
const port = new SerialPort('/dev/ttyACM0')
|
26
|
+
const port = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
|
27
27
|
|
28
28
|
// constructing a reader that will emit each packet separately
|
29
29
|
const reader = port
|
@@ -41,18 +41,15 @@ Each message consists of multiple fields that contain specific data. Parsing the
|
|
41
41
|
|
42
42
|
```javascript
|
43
43
|
import {
|
44
|
-
|
44
|
+
MavLinkPacketRegistry,
|
45
|
+
minimal, common, ardupilotmega
|
45
46
|
} from 'node-mavlink'
|
46
47
|
|
47
48
|
// create a registry of mappings between a message id and a data class
|
48
|
-
const REGISTRY = {
|
49
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
49
50
|
...minimal.REGISTRY,
|
50
51
|
...common.REGISTRY,
|
51
52
|
...ardupilotmega.REGISTRY,
|
52
|
-
...uavionix.REGISTRY,
|
53
|
-
...icarous.REGISTRY,
|
54
|
-
...asluav.REGISTRY,
|
55
|
-
...ualberta.REGISTRY,
|
56
53
|
}
|
57
54
|
|
58
55
|
reader.on('data', packet => {
|
@@ -7,14 +7,10 @@ import {
|
|
7
7
|
asluav, development, ualberta,
|
8
8
|
} from '..'
|
9
9
|
|
10
|
-
const file = createReadStream('./GH-5.bin')
|
11
|
-
|
12
10
|
const splitter = new MavLinkPacketSplitter()
|
13
|
-
|
14
|
-
const
|
15
|
-
|
16
|
-
.pipe(new MavLinkPacketParser())
|
17
|
-
|
11
|
+
const parser = new MavLinkPacketParser()
|
12
|
+
const file = createReadStream('./GH-5.bin')
|
13
|
+
const reader = file.pipe(splitter).pipe(parser)
|
18
14
|
|
19
15
|
// create a registry of mappings between a message id and a data class
|
20
16
|
const REGISTRY = {
|
@@ -41,4 +37,3 @@ file.on('close', () => {
|
|
41
37
|
console.log('Number of unknown packages:', splitter.unknownPackagesCount)
|
42
38
|
console.log('\nTotal number of consumed packets:', splitter.validPackages)
|
43
39
|
})
|
44
|
-
|
@@ -1,12 +1,18 @@
|
|
1
1
|
#!/usr/bin/env -S npx ts-node
|
2
2
|
|
3
|
-
import
|
4
|
-
import { MavLinkPacketSplitter, MavLinkPacketParser, MavLinkPacket } from '..'
|
5
|
-
import { common, waitFor, send } from '..'
|
3
|
+
import { SerialPort } from 'serialport'
|
4
|
+
import { MavLinkPacketRegistry, MavLinkPacketSplitter, MavLinkPacketParser, MavLinkPacket } from '..'
|
5
|
+
import { minimal, common, ardupilotmega, waitFor, send } from '..'
|
6
|
+
|
7
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
8
|
+
...minimal.REGISTRY,
|
9
|
+
...common.REGISTRY,
|
10
|
+
...ardupilotmega.REGISTRY,
|
11
|
+
}
|
6
12
|
|
7
13
|
async function main() {
|
8
14
|
// Create an output stream to write data to the controller
|
9
|
-
const port = new SerialPort('/dev/ttyACM0')
|
15
|
+
const port = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
|
10
16
|
|
11
17
|
// Create the reader as usual by piping the source stream through the splitter
|
12
18
|
// and packet parser
|
@@ -21,7 +27,13 @@ async function main() {
|
|
21
27
|
// This is the place where all your application-level logic will exist
|
22
28
|
reader.on('data', (packet: MavLinkPacket) => {
|
23
29
|
online = true
|
24
|
-
|
30
|
+
const clazz = REGISTRY[packet.header.msgid]
|
31
|
+
if (clazz) {
|
32
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
33
|
+
console.log('>', data)
|
34
|
+
} else {
|
35
|
+
console.log('!', packet.debug())
|
36
|
+
}
|
25
37
|
})
|
26
38
|
|
27
39
|
// Wait for the remote system to be available
|
@@ -1,16 +1,22 @@
|
|
1
1
|
#!/usr/bin/env -S npx ts-node
|
2
2
|
|
3
|
-
import
|
3
|
+
import { SerialPort } from 'serialport'
|
4
4
|
import { MavLinkPacketSplitter, MavLinkPacketParser } from '..'
|
5
|
-
import { MavLinkPacket, MavLinkPacketSignature } from '..'
|
6
|
-
import { common, waitFor, sendSigned } from '..'
|
5
|
+
import { MavLinkPacket, MavLinkPacketSignature, MavLinkPacketRegistry } from '..'
|
6
|
+
import { minimal, common, ardupilotmega, waitFor, sendSigned } from '..'
|
7
|
+
|
8
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
9
|
+
...minimal.REGISTRY,
|
10
|
+
...common.REGISTRY,
|
11
|
+
...ardupilotmega.REGISTRY,
|
12
|
+
}
|
7
13
|
|
8
14
|
// Use your own secret passphrase in place of 'qwerty'
|
9
15
|
const key = MavLinkPacketSignature.key('qwerty')
|
10
16
|
|
11
17
|
async function main() {
|
12
18
|
// Create an output stream to write data to the controller
|
13
|
-
const port = new SerialPort('/dev/ttyACM0')
|
19
|
+
const port = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
|
14
20
|
|
15
21
|
// Create the reader as usual by piping the source stream through the splitter
|
16
22
|
// and packet parser
|
@@ -25,7 +31,6 @@ async function main() {
|
|
25
31
|
// This is the place where all your application-level logic will exist
|
26
32
|
reader.on('data', (packet: MavLinkPacket) => {
|
27
33
|
online = true
|
28
|
-
console.log(packet.debug())
|
29
34
|
if (packet.signature) {
|
30
35
|
if (packet.signature.matches(key)) {
|
31
36
|
console.log('Signature check OK')
|
@@ -35,6 +40,13 @@ async function main() {
|
|
35
40
|
} else {
|
36
41
|
console.log('Packet not signed')
|
37
42
|
}
|
43
|
+
const clazz = REGISTRY[packet.header.msgid]
|
44
|
+
if (clazz) {
|
45
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
46
|
+
console.log('>', data)
|
47
|
+
} else {
|
48
|
+
console.log('!', packet.debug())
|
49
|
+
}
|
38
50
|
})
|
39
51
|
|
40
52
|
// Wait for the remote system to be available
|
@@ -1,7 +1,13 @@
|
|
1
1
|
#!/usr/bin/env -S npx ts-node
|
2
2
|
|
3
|
-
import { MavEsp8266, common } from '
|
4
|
-
import { MavLinkPacket,
|
3
|
+
import { MavEsp8266, minimal, common, ardupilotmega } from '..'
|
4
|
+
import { MavLinkPacketSignature, MavLinkPacket, MavLinkPacketRegistry } from '..'
|
5
|
+
|
6
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
7
|
+
...minimal.REGISTRY,
|
8
|
+
...common.REGISTRY,
|
9
|
+
...ardupilotmega.REGISTRY,
|
10
|
+
}
|
5
11
|
|
6
12
|
// Use your own secret passphrase in place of 'qwerty'
|
7
13
|
const key = MavLinkPacketSignature.key('qwerty')
|
@@ -14,8 +20,6 @@ async function main() {
|
|
14
20
|
|
15
21
|
// log incomming messages
|
16
22
|
port.on('data', (packet: MavLinkPacket) => {
|
17
|
-
console.log(packet.debug())
|
18
|
-
console.log(packet.debug())
|
19
23
|
if (packet.signature) {
|
20
24
|
if (packet.signature.matches(key)) {
|
21
25
|
console.log('Signature check OK')
|
@@ -25,6 +29,13 @@ async function main() {
|
|
25
29
|
} else {
|
26
30
|
console.log('Packet not signed')
|
27
31
|
}
|
32
|
+
const clazz = REGISTRY[packet.header.msgid]
|
33
|
+
if (clazz) {
|
34
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
35
|
+
console.log('>', data)
|
36
|
+
} else {
|
37
|
+
console.log('!', packet.debug())
|
38
|
+
}
|
28
39
|
})
|
29
40
|
|
30
41
|
// You're now ready to send messages to the controller using the socket
|
@@ -1,7 +1,13 @@
|
|
1
1
|
#!/usr/bin/env -S npx ts-node
|
2
2
|
|
3
|
-
import { MavEsp8266, common } from '..'
|
4
|
-
import { MavLinkPacket } from '..'
|
3
|
+
import { MavEsp8266, minimal, common, ardupilotmega } from '..'
|
4
|
+
import { MavLinkPacket, MavLinkPacketRegistry } from '..'
|
5
|
+
|
6
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
7
|
+
...minimal.REGISTRY,
|
8
|
+
...common.REGISTRY,
|
9
|
+
...ardupilotmega.REGISTRY,
|
10
|
+
}
|
5
11
|
|
6
12
|
async function main() {
|
7
13
|
const port = new MavEsp8266()
|
@@ -13,7 +19,13 @@ async function main() {
|
|
13
19
|
|
14
20
|
// log incomming messages
|
15
21
|
port.on('data', (packet: MavLinkPacket) => {
|
16
|
-
|
22
|
+
const clazz = REGISTRY[packet.header.msgid]
|
23
|
+
if (clazz) {
|
24
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
25
|
+
console.log('>', data)
|
26
|
+
} else {
|
27
|
+
console.log('!', packet.debug())
|
28
|
+
}
|
17
29
|
})
|
18
30
|
|
19
31
|
// You're now ready to send messages to the controller using the socket
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-mavlink",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.1.0",
|
4
4
|
"author": "Matthias Hryniszak <padcom@gmail.com>",
|
5
5
|
"license": "LGPL",
|
6
6
|
"description": "MavLink definitions and parsing library",
|
@@ -22,7 +22,7 @@
|
|
22
22
|
"main": "dist/index.js",
|
23
23
|
"types": "dist/index.d.ts",
|
24
24
|
"dependencies": {
|
25
|
-
"mavlink-mappings": "^1.0.
|
25
|
+
"mavlink-mappings": "^1.0.9-20220424"
|
26
26
|
},
|
27
27
|
"scripts": {
|
28
28
|
"build": "tsc",
|
@@ -34,11 +34,10 @@
|
|
34
34
|
"devDependencies": {
|
35
35
|
"@types/jest": "^27.4.1",
|
36
36
|
"@types/node": "^15.14.9",
|
37
|
-
"@types/serialport": "^8.0.1",
|
38
37
|
"@types/xml2js": "^0.4.8",
|
39
38
|
"@types/yargs": "^17.0.8",
|
40
39
|
"jest": "^27.5.1",
|
41
|
-
"serialport": "^
|
40
|
+
"serialport": "^10.0.0",
|
42
41
|
"ts-jest": "^27.1.4",
|
43
42
|
"ts-node": "^9.1.1",
|
44
43
|
"typescript": "^4.4.3",
|