node-mavlink 2.1.0 → 2.3.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.
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env -S npx ts-node
2
+
3
+ import { MavParamType } from 'mavlink-mappings/dist/lib/common'
4
+ import { MavSitl, minimal, common, ardupilotmega } from '..'
5
+ import { MavLinkPacket, MavLinkPacketRegistry } from '..'
6
+
7
+ // start the simulator as follows:
8
+ //
9
+ // ./sim_vehicle.py -v ArduCopter -f quad --no-mavproxy
10
+
11
+ const REGISTRY: MavLinkPacketRegistry = {
12
+ ...minimal.REGISTRY,
13
+ ...common.REGISTRY,
14
+ ...ardupilotmega.REGISTRY,
15
+ }
16
+
17
+ async function main() {
18
+ const port = new MavSitl()
19
+
20
+ // start the communication
21
+ const { ip } = await port.start()
22
+ console.log(`Connected to: ${ip}`)
23
+
24
+ // log incoming messages
25
+ port.on('data', (packet: MavLinkPacket) => {
26
+ const clazz = REGISTRY[packet.header.msgid]
27
+ if (clazz) {
28
+ if (packet.header.msgid === common.ParamValue.MSG_ID) {
29
+ const data = packet.protocol.data(packet.payload, clazz) as common.ParamValue
30
+ console.log('>', data)
31
+ }
32
+ } else {
33
+ console.log('!', packet.debug())
34
+ }
35
+ })
36
+
37
+ // Create an instance of of the `ParamRequestList`
38
+ // class that will be the vessel for coRequestProtocolVersionCommandntaining the command data.
39
+ // Underneath the cover it uses CommandLong to convert the data.
40
+ //
41
+ // By convention the intermediate fields that are then serialized
42
+ // are named with `_` (underscore) prefix and should not be used
43
+ // directly. That doesn't mean you can't use them, but if there
44
+ // is an equivalent Command class it is just a lot easier and every
45
+ // parameter not only has a more descriptive names but also in-line
46
+ // documentation.
47
+ const command = new common.ParamRequestList()
48
+
49
+ await port.send(command)
50
+ }
51
+
52
+ main()
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env -S npx ts-node
2
+
3
+ // start the simulator as follows:
4
+ //
5
+ // ./sim_vehicle.py -v ArduCopter -f quad --no-mavlink
6
+
7
+ import { MavBool } from 'mavlink-mappings/dist/lib/standard'
8
+ import { MavTCP, minimal, common, ardupilotmega, reserialize, sleep } from '..'
9
+ import { MavLinkPacket, MavLinkPacketRegistry } from '..'
10
+
11
+ const REGISTRY: MavLinkPacketRegistry = {
12
+ ...minimal.REGISTRY,
13
+ ...common.REGISTRY,
14
+ ...ardupilotmega.REGISTRY,
15
+ }
16
+
17
+ async function main() {
18
+ const port = new MavTCP()
19
+
20
+ // start the communication
21
+ const { ip } = await port.start()
22
+ console.log(`Connected to: ${ip}`)
23
+
24
+ // log incoming messages
25
+ port.on('data', (packet: MavLinkPacket) => {
26
+ const clazz = REGISTRY[packet.header.msgid]
27
+ if (clazz) {
28
+ const data = packet.protocol.data(packet.payload, clazz)
29
+ if (packet.header.msgid === common.CommandAck.MSG_ID) {
30
+ console.log(packet.debug())
31
+ console.log('ACKNOWLEDGED>', data)
32
+ port.close()
33
+ process.exit(0)
34
+ } else {
35
+ console.log(packet.debug())
36
+ console.log(data)
37
+ }
38
+ } else {
39
+ console.log('<UNKNOWN>', packet.debug())
40
+ }
41
+ })
42
+
43
+ // Create an instance of of the `RequestProtocolVersionCommand`
44
+ // class that will be the vessel for containing the command data.
45
+ // Underneath the cover it uses CommandLong to convert the data.
46
+ //
47
+ // By convention the intermediate fields that are then serialized
48
+ // are named with `_` (underscore) prefix and should not be used
49
+ // directly. That doesn't mean you can't use them, but if there
50
+ // is an equivalent Command class it is just a lot easier and every
51
+ // parameter not only has a more descriptive names but also in-line
52
+ // documentation.
53
+ const command = new common.RequestProtocolVersionCommand()
54
+ command.protocol = MavBool.FALSE
55
+
56
+ await port.send(command)
57
+
58
+ const { header, data } = reserialize(command)
59
+ console.log(`Packet (proto: MAV_V2, sysid: ${header.sysid}, compid: ${header.compid}, msgid: ${header.msgid}, seq: ${header.seq}, plen: ${header.payloadLength})`)
60
+ console.log('SENT>', data)
61
+
62
+ // Give the system time to process any incoming acknowledges
63
+ await sleep(500)
64
+
65
+ // Close communication
66
+ port.close()
67
+ process.exit(1)
68
+ }
69
+
70
+ main()
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env -S npx ts-node
2
2
 
3
- import { MavEsp8266, minimal, common, ardupilotmega } from '..'
3
+ import { MavEsp8266, minimal, common, ardupilotmega, reserialize, sleep } from '..'
4
4
  import { MavLinkPacket, MavLinkPacketRegistry } from '..'
5
5
 
6
6
  const REGISTRY: MavLinkPacketRegistry = {
@@ -9,12 +9,6 @@ const REGISTRY: MavLinkPacketRegistry = {
9
9
  ...ardupilotmega.REGISTRY,
10
10
  }
11
11
 
12
- // This is how you could build a registry of all commands from different packages
13
- const COMMANDS: common.MavLinkCommandRegistry = {
14
- ...common.COMMANDS,
15
- ...ardupilotmega.COMMANDS,
16
- }
17
-
18
12
  async function main() {
19
13
  const port = new MavEsp8266()
20
14
 
@@ -28,12 +22,18 @@ async function main() {
28
22
  port.on('data', (packet: MavLinkPacket) => {
29
23
  const clazz = REGISTRY[packet.header.msgid]
30
24
  if (clazz) {
25
+ const data = packet.protocol.data(packet.payload, clazz)
31
26
  if (packet.header.msgid === common.CommandAck.MSG_ID) {
32
- const data = packet.protocol.data(packet.payload, clazz)
33
- console.log('>', data)
27
+ console.log(packet.debug())
28
+ console.log('ACKNOWLEDGED>', data)
29
+ port.close()
30
+ process.exit(0)
31
+ } else {
32
+ console.log(packet.debug())
33
+ console.log(data)
34
34
  }
35
35
  } else {
36
- console.log('!', packet.debug())
36
+ console.log('<UNKNOWN>', packet.debug())
37
37
  }
38
38
  })
39
39
 
@@ -48,16 +48,21 @@ async function main() {
48
48
  // parameter not only has a more descriptive names but also in-line
49
49
  // documentation.
50
50
  const command = new common.RequestProtocolVersionCommand()
51
+ command.targetSystem = 1
52
+ command.targetComponent = 1
51
53
  command.confirmation = 1
52
54
 
53
55
  await port.send(command)
54
56
 
55
- // Give the system time to process any incoming acknowledges
56
- const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
57
- await sleep(1000)
57
+ const { header, data } = reserialize(command)
58
+ console.log(`Packet (proto: MAV_V2, sysid: ${header.sysid}, compid: ${header.compid}, msgid: ${header.msgid}, seq: ${header.seq}, plen: ${header.payloadLength})`)
59
+ console.log('SENT>', data)
60
+
61
+ await sleep(5000)
58
62
 
59
63
  // Close communication
60
64
  port.close()
65
+ process.exit(1)
61
66
  }
62
67
 
63
68
  main()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-mavlink",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "author": "Matthias Hryniszak <padcom@gmail.com>",
5
5
  "license": "LGPL",
6
6
  "description": "MavLink definitions and parsing library",
@@ -9,11 +9,11 @@
9
9
  ],
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://github.com/padcom/node-mavlink.git"
12
+ "url": "git+https://github.com/ArduPilot/node-mavlink.git"
13
13
  },
14
14
  "bugs": {
15
15
  "email": "padcom@gmail.com",
16
- "url": "https://github.com/padcom/node-mavlink/issues"
16
+ "url": "https://github.com/ArduPilot/node-mavlink/issues"
17
17
  },
18
18
  "funding": {
19
19
  "type": "patreon",
@@ -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.20-20240131-0"
25
+ "mavlink-mappings": "^1.0.21-20250824-1"
26
26
  },
27
27
  "scripts": {
28
28
  "clean": "rm -rf dist lib/*.js",