node-mavlink 2.1.0 → 2.2.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/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export * from './lib/utils';
4
4
  export * from './lib/logger';
5
5
  export * from './lib/mavlink';
6
6
  export * from './lib/mavesp';
7
+ export * from './lib/mavsitl';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA"}
package/dist/index.js CHANGED
@@ -20,3 +20,4 @@ __exportStar(require("./lib/utils"), exports);
20
20
  __exportStar(require("./lib/logger"), exports);
21
21
  __exportStar(require("./lib/mavlink"), exports);
22
22
  __exportStar(require("./lib/mavesp"), exports);
23
+ __exportStar(require("./lib/mavsitl"), exports);
@@ -3,7 +3,7 @@
3
3
  import { EventEmitter } from 'events';
4
4
  import { MavLinkPacketSplitter, MavLinkPacketParser } from './mavlink';
5
5
  import { uint8_t, MavLinkData } from 'mavlink-mappings';
6
- export interface ConnectionInfo {
6
+ export interface EspConnectionInfo {
7
7
  ip: string;
8
8
  sendPort: number;
9
9
  receivePort: number;
@@ -32,7 +32,7 @@ export declare class MavEsp8266 extends EventEmitter {
32
32
  * @param sendPort port to send messages to (default: 14555)
33
33
  * @param ip IP address to send to in case there is no broadcast (default: empty string)
34
34
  */
35
- start(receivePort?: number, sendPort?: number, ip?: string): Promise<ConnectionInfo>;
35
+ start(receivePort?: number, sendPort?: number, ip?: string): Promise<EspConnectionInfo>;
36
36
  /**
37
37
  * Closes the client stopping any message handlers
38
38
  */
@@ -1 +1 @@
1
- {"version":3,"file":"mavesp.d.ts","sourceRoot":"","sources":["../../lib/mavesp.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAIrC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAA0B,MAAM,WAAW,CAAA;AAG9F,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEvD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,MAAM,CAAC,CAAQ;IACvB,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,GAAG,CAAY;IAEvB;;;OAGG;gBACS,EACV,QAAsC,EACtC,MAAkC,GACnC;;;KAAK;IAiBN;;;;;;OAMG;IACG,KAAK,CAAC,WAAW,GAAE,MAAc,EAAE,QAAQ,GAAE,MAAc,EAAE,EAAE,GAAE,MAAW,GAAG,OAAO,CAAC,cAAc,CAAC;IAoB5G;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B;;;;;;OAMG;IACG,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,GAAE,OAAgC,EAAE,MAAM,GAAE,OAAiC,GAAG,OAAO,CAAC,MAAM,CAAC;IAOjI;;;;;;;OAOG;IACG,UAAU,CAAC,GAAG,EAAE,WAAW,EA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,MAAM,CAAC;IAOjI;;;;;;;OAOG;IACG,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAW,EAAE,KAAK,GAAE,OAAgC,EAAE,MAAM,GAAE,OAAiC,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzK;;;;OAIG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASjD,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,qBAAqB;CAI9B"}
@@ -0,0 +1,65 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { EventEmitter } from 'events';
4
+ import { MavLinkPacketSplitter, MavLinkPacketParser } from './mavlink';
5
+ import { uint8_t, MavLinkData } from 'mavlink-mappings';
6
+ export interface SitlConnectionInfo {
7
+ ip: string;
8
+ port: number;
9
+ }
10
+ /**
11
+ * Encapsulation of communication with MavEsp8266
12
+ */
13
+ export declare class MavSitl extends EventEmitter {
14
+ private input;
15
+ private socket?;
16
+ private ip;
17
+ private port;
18
+ private seq;
19
+ /**
20
+ * @param splitter packet splitter instance
21
+ * @param parser packet parser instance
22
+ */
23
+ constructor({ splitter, parser, }?: {
24
+ splitter?: MavLinkPacketSplitter | undefined;
25
+ parser?: MavLinkPacketParser | undefined;
26
+ });
27
+ /**
28
+ * Start communication with the controller via MAVESP8266
29
+ *
30
+ * @param receivePort port to receive messages on (default: 14550)
31
+ * @param sendPort port to send messages to (default: 14555)
32
+ * @param ip IP address to send to in case there is no broadcast (default: empty string)
33
+ */
34
+ start(host?: string, port?: number): Promise<SitlConnectionInfo>;
35
+ /**
36
+ * Closes the client stopping any message handlers
37
+ */
38
+ close(): Promise<void>;
39
+ /**
40
+ * Send a packet
41
+ *
42
+ * @param msg message to send
43
+ * @param sysid system id
44
+ * @param compid component id
45
+ */
46
+ send(msg: MavLinkData, sysid?: uint8_t, compid?: uint8_t): Promise<number>;
47
+ /**
48
+ * Send a signed packet
49
+ *
50
+ * @param msg message to send
51
+ * @param sysid system id
52
+ * @param compid component id
53
+ * @param linkId link id for the signature
54
+ */
55
+ sendSigned(msg: MavLinkData, key: Buffer, linkId?: uint8_t, sysid?: uint8_t, compid?: uint8_t): Promise<number>;
56
+ /**
57
+ * Send raw data over the socket. Useful for custom implementation of data sending
58
+ *
59
+ * @param buffer buffer to send
60
+ */
61
+ sendBuffer(buffer: Buffer): Promise<number>;
62
+ private processIncomingTCPData;
63
+ private processIncomingPacket;
64
+ }
65
+ //# sourceMappingURL=mavsitl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mavsitl.d.ts","sourceRoot":"","sources":["../../lib/mavsitl.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAIrC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAA0B,MAAM,WAAW,CAAA;AAG9F,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEvD,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;CACb;AAED;;GAEG;AACH,qBAAa,OAAQ,SAAQ,YAAY;IACvC,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,MAAM,CAAC,CAAQ;IACvB,OAAO,CAAC,EAAE,CAAsB;IAChC,OAAO,CAAC,IAAI,CAAe;IAC3B,OAAO,CAAC,GAAG,CAAY;IAEvB;;;OAGG;gBACS,EACV,QAAsC,EACtC,MAAkC,GACnC;;;KAAK;IAiBN;;;;;;OAMG;IACG,KAAK,CAAC,IAAI,GAAE,MAAoB,EAAE,IAAI,GAAE,MAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAmBzF;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAa5B;;;;;;OAMG;IACG,IAAI,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,GAAE,OAAgC,EAAE,MAAM,GAAE,OAAiC,GAAG,OAAO,CAAC,MAAM,CAAC;IAOjI;;;;;;;OAOG;IACG,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAW,EAAE,KAAK,GAAE,OAAgC,EAAE,MAAM,GAAE,OAAiC,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzK;;;;OAIG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASjD,OAAO,CAAC,sBAAsB;IAK9B,OAAO,CAAC,qBAAqB;CAI9B"}
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MavSitl = void 0;
4
+ const events_1 = require("events");
5
+ const net_1 = require("net");
6
+ const stream_1 = require("stream");
7
+ const mavlink_1 = require("./mavlink");
8
+ const mavlink_2 = require("./mavlink");
9
+ /**
10
+ * Encapsulation of communication with MavEsp8266
11
+ */
12
+ class MavSitl extends events_1.EventEmitter {
13
+ input;
14
+ socket;
15
+ ip = '127.0.0.1';
16
+ port = 5760;
17
+ seq = 0;
18
+ /**
19
+ * @param splitter packet splitter instance
20
+ * @param parser packet parser instance
21
+ */
22
+ constructor({ splitter = new mavlink_1.MavLinkPacketSplitter(), parser = new mavlink_1.MavLinkPacketParser(), } = {}) {
23
+ super();
24
+ this.input = new stream_1.PassThrough();
25
+ this.processIncomingTCPData = this.processIncomingTCPData.bind(this);
26
+ this.processIncomingPacket = this.processIncomingPacket.bind(this);
27
+ // Create the reader as usual by piping the source stream through the splitter
28
+ // and packet parser
29
+ const reader = this.input
30
+ .pipe(splitter)
31
+ .pipe(parser);
32
+ reader.on('data', this.processIncomingPacket);
33
+ }
34
+ /**
35
+ * Start communication with the controller via MAVESP8266
36
+ *
37
+ * @param receivePort port to receive messages on (default: 14550)
38
+ * @param sendPort port to send messages to (default: 14555)
39
+ * @param ip IP address to send to in case there is no broadcast (default: empty string)
40
+ */
41
+ async start(host = '127.0.0.1', port = 5760) {
42
+ if (this.socket)
43
+ throw new Error('Already connected');
44
+ this.ip = host;
45
+ this.port = port;
46
+ // Create a TCP socket to connect to SITL
47
+ this.socket = new net_1.Socket();
48
+ this.socket.on('data', this.processIncomingTCPData);
49
+ this.socket.once('close', () => this.emit('close'));
50
+ // Start listening on the socket
51
+ return new Promise((resolve, reject) => {
52
+ this.socket?.connect(5760, host, () => {
53
+ resolve({ ip: this.ip, port: this.port });
54
+ });
55
+ });
56
+ }
57
+ /**
58
+ * Closes the client stopping any message handlers
59
+ */
60
+ async close() {
61
+ if (!this.socket)
62
+ throw new Error('Not connected');
63
+ // Unregister event handlers
64
+ this.socket.off('data', this.processIncomingTCPData);
65
+ // Close the socket
66
+ return new Promise(resolve => {
67
+ this.socket?.end(resolve);
68
+ this.socket = undefined;
69
+ });
70
+ }
71
+ /**
72
+ * Send a packet
73
+ *
74
+ * @param msg message to send
75
+ * @param sysid system id
76
+ * @param compid component id
77
+ */
78
+ async send(msg, sysid = mavlink_2.MavLinkProtocol.SYS_ID, compid = mavlink_2.MavLinkProtocol.COMP_ID) {
79
+ const protocol = new mavlink_2.MavLinkProtocolV2(sysid, compid);
80
+ const buffer = protocol.serialize(msg, this.seq++);
81
+ this.seq &= 255;
82
+ return this.sendBuffer(buffer);
83
+ }
84
+ /**
85
+ * Send a signed packet
86
+ *
87
+ * @param msg message to send
88
+ * @param sysid system id
89
+ * @param compid component id
90
+ * @param linkId link id for the signature
91
+ */
92
+ async sendSigned(msg, key, linkId = 1, sysid = mavlink_2.MavLinkProtocol.SYS_ID, compid = mavlink_2.MavLinkProtocol.COMP_ID) {
93
+ const protocol = new mavlink_2.MavLinkProtocolV2(sysid, compid, mavlink_2.MavLinkProtocolV2.IFLAG_SIGNED);
94
+ const b1 = protocol.serialize(msg, this.seq++);
95
+ this.seq &= 255;
96
+ const b2 = protocol.sign(b1, linkId, key);
97
+ return this.sendBuffer(b2);
98
+ }
99
+ /**
100
+ * Send raw data over the socket. Useful for custom implementation of data sending
101
+ *
102
+ * @param buffer buffer to send
103
+ */
104
+ async sendBuffer(buffer) {
105
+ return new Promise((resolve, reject) => {
106
+ this.socket?.write(buffer, (err) => {
107
+ if (err)
108
+ reject(err);
109
+ else
110
+ resolve(buffer.length);
111
+ });
112
+ });
113
+ }
114
+ processIncomingTCPData(buffer) {
115
+ // pass on the data to the input stream
116
+ this.input.write(buffer);
117
+ }
118
+ processIncomingPacket(packet) {
119
+ // let the user know we received the packet
120
+ this.emit('data', packet);
121
+ }
122
+ }
123
+ exports.MavSitl = MavSitl;
@@ -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,52 @@
1
+ #!/usr/bin/env -S npx ts-node
2
+
3
+ import { MavSitl, minimal, common, ardupilotmega } from '..'
4
+ import { MavLinkPacket, MavLinkPacketRegistry } from '..'
5
+
6
+ // start the simulator as follows:
7
+ //
8
+ // ./sim_vehicle.py -v ArduCopter -f quad --no-mavproxy
9
+
10
+ const REGISTRY: MavLinkPacketRegistry = {
11
+ ...minimal.REGISTRY,
12
+ ...common.REGISTRY,
13
+ ...ardupilotmega.REGISTRY,
14
+ }
15
+
16
+ async function main() {
17
+ const port = new MavSitl()
18
+
19
+ // start the communication
20
+ const { ip } = await port.start()
21
+ console.log(`Connected to: ${ip}`)
22
+
23
+ // log incoming messages
24
+ port.on('data', (packet: MavLinkPacket) => {
25
+ const clazz = REGISTRY[packet.header.msgid]
26
+ if (clazz) {
27
+ if (packet.header.msgid === common.ParamValue.MSG_ID) {
28
+ const data = packet.protocol.data(packet.payload, clazz)
29
+ console.log('>', data)
30
+ }
31
+ } else {
32
+ console.log('!', packet.debug())
33
+ }
34
+ })
35
+
36
+ // Create an instance of of the `RequestProtocolVersionCommand`
37
+ // class that will be the vessel for containing the command data.
38
+ // Underneath the cover it uses CommandLong to convert the data.
39
+ //
40
+ // By convention the intermediate fields that are then serialized
41
+ // are named with `_` (underscore) prefix and should not be used
42
+ // directly. That doesn't mean you can't use them, but if there
43
+ // is an equivalent Command class it is just a lot easier and every
44
+ // parameter not only has a more descriptive names but also in-line
45
+ // documentation.
46
+ const command = new common.RequestProtocolVersionCommand()
47
+ command.confirmation = 1
48
+
49
+ await port.send(command)
50
+ }
51
+
52
+ main()
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-mavlink",
3
- "version": "2.1.0",
3
+ "version": "2.2.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",