node-mavlink 1.5.1 → 2.0.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +8 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/magic-numbers.d.ts +3 -0
- package/dist/lib/magic-numbers.d.ts.map +1 -0
- package/dist/lib/magic-numbers.js +24 -0
- package/dist/lib/mavesp.d.ts +12 -4
- package/dist/lib/mavesp.d.ts.map +1 -1
- package/dist/lib/mavesp.js +15 -11
- package/dist/lib/mavlink.d.ts +10 -3
- package/dist/lib/mavlink.d.ts.map +1 -1
- package/dist/lib/mavlink.js +8 -7
- package/dist/lib/utils.d.ts +5 -5
- package/dist/lib/utils.js +5 -5
- package/examples/pool-param-udp.ts +3 -2
- package/examples/send-receive-file.ts +5 -0
- package/examples/send-receive-signed-udp.ts +1 -1
- package/examples/send-receive-udp.ts +3 -3
- package/package.json +3 -3
package/README.md
CHANGED
@@ -75,7 +75,7 @@ import { MavLinkProtocolV2, send } from 'node-mavlink'
|
|
75
75
|
// By convention the intermediate fields that are then serialized
|
76
76
|
// are named with `_` (underscore) prefix and should not be used
|
77
77
|
// directly. That doesn't mean you can't use them, but if there
|
78
|
-
// is
|
78
|
+
// is an equivalent Command class it is just a lot easier and every
|
79
79
|
// parameter not only has a more descriptive names but also in-line
|
80
80
|
// documentation.
|
81
81
|
const command = new common.RequestProtocolVersionCommand()
|
@@ -128,7 +128,7 @@ async function main() {
|
|
128
128
|
// start the communication
|
129
129
|
await port.start()
|
130
130
|
|
131
|
-
// log
|
131
|
+
// log incoming packets
|
132
132
|
port.on('data', packet => {
|
133
133
|
console.log(packet.debug())
|
134
134
|
})
|
@@ -151,7 +151,7 @@ That's it! Easy as a lion :)
|
|
151
151
|
|
152
152
|
## Signed packages
|
153
153
|
|
154
|
-
MavLink v2 introduces package signing. The way it currently works with Mission planner is you give it a pass phrase, Mission Planner encodes it using sha256 hashing algorithm and uses it as part of the signature calculation. Therefore if someone does not know the secret passphrase they won't be able to create packets that would seem to be
|
154
|
+
MavLink v2 introduces package signing. The way it currently works with Mission planner is you give it a pass phrase, Mission Planner encodes it using sha256 hashing algorithm and uses it as part of the signature calculation. Therefore if someone does not know the secret passphrase they won't be able to create packets that would seem to be coming from a source. It's a kind of security thing.
|
155
155
|
|
156
156
|
### Reading signature
|
157
157
|
|
@@ -163,7 +163,7 @@ import { MavLinkPacketSignature } from 'node-mavlink'
|
|
163
163
|
// calculate secret key (change 'qwerty' to your secret phrase)
|
164
164
|
const key = MavLinkPacketSignature.key('qwerty')
|
165
165
|
|
166
|
-
// log
|
166
|
+
// log incoming messages
|
167
167
|
port.on('data', packet => {
|
168
168
|
console.log(packet.debug())
|
169
169
|
if (packet.signature) {
|
@@ -218,7 +218,7 @@ This function calls the `cb` callback periodically at the `interval` (default: 1
|
|
218
218
|
|
219
219
|
#### `async send(stream: Writable, msg: MavLinkData, protocol: MavLinkProtocol)`
|
220
220
|
|
221
|
-
This function serializes the `msg` message using the provided `protocol` (default: `MavLinkProtocolV1`) and sends it to the `stream`. If the process is successful the method returns with the length of written data denoting that no error
|
221
|
+
This function serializes the `msg` message using the provided `protocol` (default: `MavLinkProtocolV1`) and sends it to the `stream`. If the process is successful the method returns with the length of written data denoting that no error occurred. However, if the process was not successful it will error out with the underlying error object returned on by the stream.
|
222
222
|
|
223
223
|
#### `async sendSigned(stream: Writable, msg: MavLinkData, key: Buffer, linkId: uint8_t, sysid: uint8_t, compid: uint8_t)`
|
224
224
|
|
@@ -235,7 +235,7 @@ This is a very handy utility function that asynchronously pauses for a given tim
|
|
235
235
|
|
236
236
|
## Running sim_vehicle.py
|
237
237
|
|
238
|
-
The easiest way to start playing around with this package is to use `sim_vehicle.py`. You can use the default parameters
|
238
|
+
The easiest way to start playing around with this package is to use `sim_vehicle.py`. You can use the default parameters for the MavEsp8266 if you'll make the simulator compatible with it:
|
239
239
|
|
240
240
|
```
|
241
241
|
$ Tools/autotest/sim_vehicle.py -v ArduCopter -f quad --console --map --out udpin:127.0.0.1:14555
|
@@ -249,7 +249,7 @@ The original generated sources lack one very important aspect of a reusable libr
|
|
249
249
|
|
250
250
|
When generating sources for data classes a number of things happen:
|
251
251
|
|
252
|
-
- `enum` values are trimmed from common prefix; duplicating enum name in its value when its value cannot be spelled without the enum name is pointless and leads to
|
252
|
+
- `enum` values are trimmed from common prefix; duplicating enum name in its value when its value cannot be spelled without the enum name is pointless and leads to unnecessarily verbose code
|
253
253
|
- enum values, whenever available, contain JSDoc describing their purpose
|
254
254
|
- data classes are properly named (PascalCase)
|
255
255
|
- data classes fields are properly named (camelCase)
|
@@ -259,6 +259,6 @@ When generating sources for data classes a number of things happen:
|
|
259
259
|
|
260
260
|
This leads to generated code that contains not only raw types but also documentation where it is mostly useful: right at your fingertips.
|
261
261
|
|
262
|
-
I hope you'll enjoy using this library! If you have any comments, find a bug or just generally want to share your thoughts you can reach me via
|
262
|
+
I hope you'll enjoy using this library! If you have any comments, find a bug or just generally want to share your thoughts you can reach me via email: padcom@gmail.com
|
263
263
|
|
264
264
|
Peace!
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,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"}
|
package/dist/index.js
CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("mavlink-mappings"), exports);
|
18
|
+
__exportStar(require("./lib/magic-numbers"), exports);
|
18
19
|
__exportStar(require("./lib/utils"), exports);
|
19
20
|
__exportStar(require("./lib/logger"), exports);
|
20
21
|
__exportStar(require("./lib/mavlink"), exports);
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"magic-numbers.d.ts","sourceRoot":"","sources":["../../lib/magic-numbers.ts"],"names":[],"mappings":"AAEA,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAO5E;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAOtE"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.overrideMessageMagicNumber = exports.registerCustomMessageMagicNumber = void 0;
|
4
|
+
const mavlink_mappings_1 = require("mavlink-mappings");
|
5
|
+
function registerCustomMessageMagicNumber(msgid, magic) {
|
6
|
+
const numbers = mavlink_mappings_1.MSG_ID_MAGIC_NUMBER;
|
7
|
+
if (numbers[msgid] !== undefined) {
|
8
|
+
throw new Error(`Magic number for message "${msgid}" already registered`);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
numbers[msgid] = magic;
|
12
|
+
}
|
13
|
+
}
|
14
|
+
exports.registerCustomMessageMagicNumber = registerCustomMessageMagicNumber;
|
15
|
+
function overrideMessageMagicNumber(msgid, magic) {
|
16
|
+
const numbers = mavlink_mappings_1.MSG_ID_MAGIC_NUMBER;
|
17
|
+
if (numbers[msgid] === undefined) {
|
18
|
+
throw new Error(`Magic number for message "${msgid}" not registered`);
|
19
|
+
}
|
20
|
+
else {
|
21
|
+
numbers[msgid] = magic;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
exports.overrideMessageMagicNumber = overrideMessageMagicNumber;
|
package/dist/lib/mavesp.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/// <reference types="node" />
|
3
3
|
import { EventEmitter } from 'events';
|
4
|
+
import { MavLinkPacketSplitter, MavLinkPacketParser } from './mavlink';
|
4
5
|
import { uint8_t, MavLinkData } from 'mavlink-mappings';
|
5
6
|
export interface ConnectionInfo {
|
6
7
|
ip: string;
|
@@ -16,9 +17,16 @@ export declare class MavEsp8266 extends EventEmitter {
|
|
16
17
|
private ip;
|
17
18
|
private sendPort;
|
18
19
|
private seq;
|
19
|
-
constructor();
|
20
20
|
/**
|
21
|
-
*
|
21
|
+
* @param splitter packet splitter instance
|
22
|
+
* @param parser packet parser instance
|
23
|
+
*/
|
24
|
+
constructor({ splitter, parser, }?: {
|
25
|
+
splitter?: MavLinkPacketSplitter | undefined;
|
26
|
+
parser?: MavLinkPacketParser | undefined;
|
27
|
+
});
|
28
|
+
/**
|
29
|
+
* Start communication with the controller via MAVESP8266
|
22
30
|
*
|
23
31
|
* @param receivePort port to receive messages on (default: 14550)
|
24
32
|
* @param sendPort port to send messages to (default: 14555)
|
@@ -51,7 +59,7 @@ export declare class MavEsp8266 extends EventEmitter {
|
|
51
59
|
* @param buffer buffer to send
|
52
60
|
*/
|
53
61
|
sendBuffer(buffer: Buffer): Promise<number>;
|
54
|
-
private
|
55
|
-
private
|
62
|
+
private processIncomingUDPData;
|
63
|
+
private processIncomingPacket;
|
56
64
|
}
|
57
65
|
//# sourceMappingURL=mavesp.d.ts.map
|
package/dist/lib/mavesp.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mavesp.d.ts","sourceRoot":"","sources":["../../lib/mavesp.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;
|
1
|
+
{"version":3,"file":"mavesp.d.ts","sourceRoot":"","sources":["../../lib/mavesp.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,YAAY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 extends events_1.EventEmitter {
|
|
16
16
|
ip = '';
|
17
17
|
sendPort = 14555;
|
18
18
|
seq = 0;
|
19
|
-
|
19
|
+
/**
|
20
|
+
* @param splitter packet splitter instance
|
21
|
+
* @param parser packet parser instance
|
22
|
+
*/
|
23
|
+
constructor({ splitter = new mavlink_1.MavLinkPacketSplitter(), parser = new mavlink_1.MavLinkPacketParser(), } = {}) {
|
20
24
|
super();
|
21
25
|
this.input = new stream_1.PassThrough();
|
22
|
-
this.
|
23
|
-
this.
|
26
|
+
this.processIncomingUDPData = this.processIncomingUDPData.bind(this);
|
27
|
+
this.processIncomingPacket = this.processIncomingPacket.bind(this);
|
24
28
|
// Create the reader as usual by piping the source stream through the splitter
|
25
29
|
// and packet parser
|
26
30
|
const reader = this.input
|
27
|
-
.pipe(
|
28
|
-
.pipe(
|
29
|
-
reader.on('data', this.
|
31
|
+
.pipe(splitter)
|
32
|
+
.pipe(parser);
|
33
|
+
reader.on('data', this.processIncomingPacket);
|
30
34
|
}
|
31
35
|
/**
|
32
|
-
* Start communication with the controller via
|
36
|
+
* Start communication with the controller via MAVESP8266
|
33
37
|
*
|
34
38
|
* @param receivePort port to receive messages on (default: 14550)
|
35
39
|
* @param sendPort port to send messages to (default: 14555)
|
@@ -38,7 +42,7 @@ class MavEsp8266 extends events_1.EventEmitter {
|
|
38
42
|
this.sendPort = sendPort;
|
39
43
|
// Create a UDP socket
|
40
44
|
this.socket = (0, dgram_1.createSocket)({ type: 'udp4', reuseAddr: true });
|
41
|
-
this.socket.on('message', this.
|
45
|
+
this.socket.on('message', this.processIncomingUDPData);
|
42
46
|
// Start listening on the socket
|
43
47
|
return new Promise((resolve, reject) => {
|
44
48
|
this.socket?.bind(receivePort, () => {
|
@@ -57,7 +61,7 @@ class MavEsp8266 extends events_1.EventEmitter {
|
|
57
61
|
if (!this.socket)
|
58
62
|
throw new Error('Not connected');
|
59
63
|
// Unregister event handlers
|
60
|
-
this.socket.off('message', this.
|
64
|
+
this.socket.off('message', this.processIncomingUDPData);
|
61
65
|
// Close the socket
|
62
66
|
return new Promise(resolve => {
|
63
67
|
this.socket?.close(resolve);
|
@@ -106,14 +110,14 @@ class MavEsp8266 extends events_1.EventEmitter {
|
|
106
110
|
});
|
107
111
|
});
|
108
112
|
}
|
109
|
-
|
113
|
+
processIncomingUDPData(buffer, metadata) {
|
110
114
|
// store the remote ip address
|
111
115
|
if (this.ip === '')
|
112
116
|
this.ip = metadata.address;
|
113
117
|
// pass on the data to the input stream
|
114
118
|
this.input.write(buffer);
|
115
119
|
}
|
116
|
-
|
120
|
+
processIncomingPacket(packet) {
|
117
121
|
// let the user know we received the packet
|
118
122
|
this.emit('data', packet);
|
119
123
|
}
|
package/dist/lib/mavlink.d.ts
CHANGED
@@ -190,12 +190,13 @@ export declare class MavLinkPacket {
|
|
190
190
|
}
|
191
191
|
declare type BufferCallback = (buffer: Buffer) => void;
|
192
192
|
/**
|
193
|
-
* A transform stream that splits the
|
193
|
+
* A transform stream that splits the incoming data stream into chunks containing full MavLink messages
|
194
194
|
*/
|
195
195
|
export declare class MavLinkPacketSplitter extends Transform {
|
196
196
|
protected readonly log: Logger;
|
197
197
|
private buffer;
|
198
198
|
private onCrcError;
|
199
|
+
private readonly magicNumbers;
|
199
200
|
private timestamp;
|
200
201
|
private _validPackagesCount;
|
201
202
|
private _unknownPackagesCount;
|
@@ -205,7 +206,10 @@ export declare class MavLinkPacketSplitter extends Transform {
|
|
205
206
|
* @param verbose print diagnostic information
|
206
207
|
* @param onCrcError callback executed if there is a CRC error (mostly for debugging)
|
207
208
|
*/
|
208
|
-
constructor(opts?: {}, onCrcError?:
|
209
|
+
constructor(opts?: {}, { onCrcError, magicNumbers }?: {
|
210
|
+
onCrcError?: BufferCallback;
|
211
|
+
magicNumbers?: Record<string, number>;
|
212
|
+
});
|
209
213
|
_transform(chunk: Buffer, encoding: string, callback: TransformCallback): void;
|
210
214
|
protected findStartOfPacket(buffer: Buffer, offset?: number): number | null;
|
211
215
|
private getPacketProtocol;
|
@@ -263,7 +267,10 @@ export declare class MavLinkPacketParser extends Transform {
|
|
263
267
|
*
|
264
268
|
* @param input input stream to read from
|
265
269
|
*/
|
266
|
-
export declare function createMavLinkStream(input: Readable, onCrcError
|
270
|
+
export declare function createMavLinkStream(input: Readable, { onCrcError, magicNumbers }?: {
|
271
|
+
onCrcError?: BufferCallback;
|
272
|
+
magicNumbers?: Record<string, number>;
|
273
|
+
}): MavLinkPacketParser;
|
267
274
|
/**
|
268
275
|
* Send a packet to the stream
|
269
276
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mavlink.d.ts","sourceRoot":"","sources":["../../lib/mavlink.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEzE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAU,MAAM,kBAAkB,CAAA;AAE5D,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAGtE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGjC;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAO;IAC/B,KAAK,EAAE,MAAM,CAAI;IACjB,aAAa,EAAE,OAAO,CAAI;IAC1B,oBAAoB,EAAE,OAAO,CAAI;IACjC,kBAAkB,EAAE,OAAO,CAAI;IAC/B,GAAG,EAAE,OAAO,CAAI;IAChB,KAAK,EAAE,OAAO,CAAI;IAClB,MAAM,EAAE,OAAO,CAAI;IACnB,KAAK,EAAE,OAAO,CAAI;CACnB;AAED;;;;;GAKG;AACH,8BAAsB,eAAe;IACnC,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAyB;IAE/C,MAAM,CAAC,IAAI,SAAY;IACvB,MAAM,CAAC,UAAU,SAAI;IACrB,MAAM,CAAC,cAAc,SAAI;IACzB,MAAM,CAAC,eAAe,SAAI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AAE,OAAgC,EAAE,MAAM,GAAE,OAAiC,EACvG,SAAS,SAAa,oBAYvB"}
|
package/dist/lib/mavlink.js
CHANGED
@@ -402,12 +402,13 @@ var PacketValidationResult;
|
|
402
402
|
PacketValidationResult[PacketValidationResult["UNKNOWN"] = 2] = "UNKNOWN";
|
403
403
|
})(PacketValidationResult || (PacketValidationResult = {}));
|
404
404
|
/**
|
405
|
-
* A transform stream that splits the
|
405
|
+
* A transform stream that splits the incoming data stream into chunks containing full MavLink messages
|
406
406
|
*/
|
407
407
|
class MavLinkPacketSplitter extends stream_1.Transform {
|
408
408
|
log = logger_1.Logger.getLogger(this);
|
409
409
|
buffer = Buffer.from([]);
|
410
410
|
onCrcError = null;
|
411
|
+
magicNumbers;
|
411
412
|
timestamp = null;
|
412
413
|
_validPackagesCount = 0;
|
413
414
|
_unknownPackagesCount = 0;
|
@@ -417,9 +418,10 @@ class MavLinkPacketSplitter extends stream_1.Transform {
|
|
417
418
|
* @param verbose print diagnostic information
|
418
419
|
* @param onCrcError callback executed if there is a CRC error (mostly for debugging)
|
419
420
|
*/
|
420
|
-
constructor(opts = {}, onCrcError = () => { }) {
|
421
|
+
constructor(opts = {}, { onCrcError = () => { }, magicNumbers = mavlink_mappings_2.MSG_ID_MAGIC_NUMBER } = {}) {
|
421
422
|
super({ ...opts, objectMode: true });
|
422
423
|
this.onCrcError = onCrcError;
|
424
|
+
this.magicNumbers = magicNumbers;
|
423
425
|
}
|
424
426
|
_transform(chunk, encoding, callback) {
|
425
427
|
this.buffer = Buffer.concat([this.buffer, chunk]);
|
@@ -444,7 +446,7 @@ class MavLinkPacketSplitter extends stream_1.Transform {
|
|
444
446
|
// get protocol this buffer is encoded with
|
445
447
|
const Protocol = this.getPacketProtocol(this.buffer);
|
446
448
|
this.log.debug('Packet protocol is', Protocol.NAME);
|
447
|
-
// check if the buffer contains at least the
|
449
|
+
// check if the buffer contains at least the minimum size of data
|
448
450
|
if (this.buffer.length < Protocol.PAYLOAD_OFFSET + MavLinkProtocol.CHECKSUM_LENGTH) {
|
449
451
|
// current buffer shorter than the shortest message - skipping
|
450
452
|
this.log.debug('Current buffer shorter than the shortest message - skipping');
|
@@ -527,8 +529,7 @@ class MavLinkPacketSplitter extends stream_1.Transform {
|
|
527
529
|
validatePacket(buffer, Protocol) {
|
528
530
|
const protocol = new Protocol();
|
529
531
|
const header = protocol.header(buffer);
|
530
|
-
|
531
|
-
const magic = mavlink_mappings_2.MSG_ID_MAGIC_NUMBER[header.msgid];
|
532
|
+
const magic = this.magicNumbers[header.msgid];
|
532
533
|
if (magic) {
|
533
534
|
const crc = protocol.crc(buffer);
|
534
535
|
const trim = this.isV2Signed(buffer)
|
@@ -669,9 +670,9 @@ exports.MavLinkPacketParser = MavLinkPacketParser;
|
|
669
670
|
*
|
670
671
|
* @param input input stream to read from
|
671
672
|
*/
|
672
|
-
function createMavLinkStream(input, onCrcError) {
|
673
|
+
function createMavLinkStream(input, { onCrcError, magicNumbers } = {}) {
|
673
674
|
return input
|
674
|
-
.pipe(new MavLinkPacketSplitter({}, onCrcError))
|
675
|
+
.pipe(new MavLinkPacketSplitter({}, { onCrcError, magicNumbers }))
|
675
676
|
.pipe(new MavLinkPacketParser());
|
676
677
|
}
|
677
678
|
exports.createMavLinkStream = createMavLinkStream;
|
package/dist/lib/utils.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
/**
|
3
|
-
* Convert a number to hexadecimal representation with a
|
3
|
+
* Convert a number to hexadecimal representation with a minimum
|
4
4
|
* number of characters and optional prefix (0x by default)
|
5
5
|
*
|
6
6
|
* @param n value to convert
|
@@ -16,9 +16,9 @@ export declare function hex(n: number, len?: number, prefix?: string): string;
|
|
16
16
|
*/
|
17
17
|
export declare function dump(buffer: Buffer, lineWidth?: number): void;
|
18
18
|
/**
|
19
|
-
* Sleep for a given number of
|
19
|
+
* Sleep for a given number of milliseconds
|
20
20
|
*
|
21
|
-
* @param {number} ms of
|
21
|
+
* @param {number} ms of milliseconds to sleep
|
22
22
|
*/
|
23
23
|
export declare function sleep(ms: number): Promise<unknown>;
|
24
24
|
/**
|
@@ -29,8 +29,8 @@ export declare function sleep(ms: number): Promise<unknown>;
|
|
29
29
|
* the execution without success. Great for time-sensitive operations.
|
30
30
|
*
|
31
31
|
* @param cb callback to call every <code>interval</code>ms. Waiting stops if the callback returns a truthy value.
|
32
|
-
* @param timeout number of
|
33
|
-
* @param interval number of
|
32
|
+
* @param timeout number of milliseconds that need to pass before the Timeout exception is thrown
|
33
|
+
* @param interval number of milliseconds before re-running the callback
|
34
34
|
*/
|
35
35
|
export declare function waitFor<T>(cb: () => T, timeout?: number, interval?: number): Promise<T>;
|
36
36
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/lib/utils.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.waitFor = exports.sleep = exports.dump = exports.hex = void 0;
|
4
4
|
/**
|
5
|
-
* Convert a number to hexadecimal representation with a
|
5
|
+
* Convert a number to hexadecimal representation with a minimum
|
6
6
|
* number of characters and optional prefix (0x by default)
|
7
7
|
*
|
8
8
|
* @param n value to convert
|
@@ -36,9 +36,9 @@ function dump(buffer, lineWidth = 16) {
|
|
36
36
|
}
|
37
37
|
exports.dump = dump;
|
38
38
|
/**
|
39
|
-
* Sleep for a given number of
|
39
|
+
* Sleep for a given number of milliseconds
|
40
40
|
*
|
41
|
-
* @param {number} ms of
|
41
|
+
* @param {number} ms of milliseconds to sleep
|
42
42
|
*/
|
43
43
|
function sleep(ms) {
|
44
44
|
return new Promise(resolve => setTimeout(resolve, ms));
|
@@ -52,8 +52,8 @@ exports.sleep = sleep;
|
|
52
52
|
* the execution without success. Great for time-sensitive operations.
|
53
53
|
*
|
54
54
|
* @param cb callback to call every <code>interval</code>ms. Waiting stops if the callback returns a truthy value.
|
55
|
-
* @param timeout number of
|
56
|
-
* @param interval number of
|
55
|
+
* @param timeout number of milliseconds that need to pass before the Timeout exception is thrown
|
56
|
+
* @param interval number of milliseconds before re-running the callback
|
57
57
|
*/
|
58
58
|
async function waitFor(cb, timeout = 10000, interval = 100) {
|
59
59
|
return new Promise((resolve, reject) => {
|
@@ -9,9 +9,10 @@ async function main() {
|
|
9
9
|
// start the communication
|
10
10
|
// After this line we have received at least one heartbeat message so we
|
11
11
|
// know what is the remote IP address to send the messages to
|
12
|
-
await port.start()
|
12
|
+
const { ip, sendPort, receivePort } = await port.start()
|
13
|
+
console.log(`Connected to: ${ip}, send port: ${sendPort}, receive port ${receivePort}`)
|
13
14
|
|
14
|
-
// log
|
15
|
+
// log incoming messages
|
15
16
|
port.on('data', (packet: MavLinkPacket) => {
|
16
17
|
if (packet.header.msgid === common.ParamValue.MSG_ID) {
|
17
18
|
const value = packet.protocol.data(packet.payload, common.ParamValue)
|
@@ -7,6 +7,11 @@ import {
|
|
7
7
|
asluav, development, ualberta,
|
8
8
|
} from '..'
|
9
9
|
|
10
|
+
//
|
11
|
+
// Example how to register your own magic numbers:
|
12
|
+
//
|
13
|
+
// const splitter = new MavLinkPacketSplitter({}, { magicNumbers: { '0': 50 } })
|
14
|
+
//
|
10
15
|
const splitter = new MavLinkPacketSplitter()
|
11
16
|
const parser = new MavLinkPacketParser()
|
12
17
|
const file = createReadStream(__dirname + '/GH-5.bin')
|
@@ -19,7 +19,7 @@ async function main() {
|
|
19
19
|
const { ip, sendPort, receivePort } = await port.start()
|
20
20
|
console.log(`Connected to: ${ip}, send port: ${sendPort}, receive port ${receivePort}`)
|
21
21
|
|
22
|
-
// log
|
22
|
+
// log incoming messages
|
23
23
|
port.on('data', (packet: MavLinkPacket) => {
|
24
24
|
if (packet.signature) {
|
25
25
|
if (packet.signature.matches(key)) {
|
@@ -21,10 +21,10 @@ async function main() {
|
|
21
21
|
// start the communication
|
22
22
|
// After this line we have received at least one heartbeat message so we
|
23
23
|
// know what is the remote IP address to send the messages to
|
24
|
-
const { ip, sendPort, receivePort } = await port.start(
|
24
|
+
const { ip, sendPort, receivePort } = await port.start()
|
25
25
|
console.log(`Connected to: ${ip}, send port: ${sendPort}, receive port ${receivePort}`)
|
26
26
|
|
27
|
-
// log
|
27
|
+
// log incoming messages
|
28
28
|
port.on('data', (packet: MavLinkPacket) => {
|
29
29
|
const clazz = REGISTRY[packet.header.msgid]
|
30
30
|
if (clazz) {
|
@@ -44,7 +44,7 @@ async function main() {
|
|
44
44
|
// By convention the intermediate fields that are then serialized
|
45
45
|
// are named with `_` (underscore) prefix and should not be used
|
46
46
|
// directly. That doesn't mean you can't use them, but if there
|
47
|
-
// is
|
47
|
+
// is an equivalent Command class it is just a lot easier and every
|
48
48
|
// parameter not only has a more descriptive names but also in-line
|
49
49
|
// documentation.
|
50
50
|
const command = new common.RequestProtocolVersionCommand()
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-mavlink",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0-alpha.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.15-20230328-0"
|
26
26
|
},
|
27
27
|
"scripts": {
|
28
28
|
"clean": "rm -rf dist lib/*.js",
|
@@ -49,4 +49,4 @@
|
|
49
49
|
"xml2js": "^0.4.23",
|
50
50
|
"yargs": "^17.3.1"
|
51
51
|
}
|
52
|
-
}
|
52
|
+
}
|