node-mavlink 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
package/dist/lib/mavesp.d.ts
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
/// <reference types="node" />
|
3
3
|
import { EventEmitter } from 'events';
|
4
4
|
import { uint8_t, MavLinkData } from 'mavlink-mappings';
|
5
|
+
export interface ConnectionInfo {
|
6
|
+
ip: string;
|
7
|
+
sendPort: number;
|
8
|
+
receivePort: number;
|
9
|
+
}
|
5
10
|
/**
|
6
11
|
* Encapsulation of communication with MavEsp8266
|
7
12
|
*/
|
@@ -18,7 +23,11 @@ export declare class MavEsp8266 extends EventEmitter {
|
|
18
23
|
* @param receivePort port to receive messages on (default: 14550)
|
19
24
|
* @param sendPort port to send messages to (default: 14555)
|
20
25
|
*/
|
21
|
-
start(receivePort?: number, sendPort?: number): Promise<
|
26
|
+
start(receivePort?: number, sendPort?: number): Promise<ConnectionInfo>;
|
27
|
+
/**
|
28
|
+
* Closes the client stopping any message handlers
|
29
|
+
*/
|
30
|
+
close(): Promise<void>;
|
22
31
|
/**
|
23
32
|
* Send a packet
|
24
33
|
*
|
@@ -26,7 +35,7 @@ export declare class MavEsp8266 extends EventEmitter {
|
|
26
35
|
* @param sysid system id
|
27
36
|
* @param compid component id
|
28
37
|
*/
|
29
|
-
send(msg: MavLinkData, sysid?: uint8_t, compid?: uint8_t):
|
38
|
+
send(msg: MavLinkData, sysid?: uint8_t, compid?: uint8_t): Promise<number>;
|
30
39
|
/**
|
31
40
|
* Send a signed packet
|
32
41
|
*
|
@@ -35,13 +44,13 @@ export declare class MavEsp8266 extends EventEmitter {
|
|
35
44
|
* @param compid component id
|
36
45
|
* @param linkId link id for the signature
|
37
46
|
*/
|
38
|
-
sendSigned(msg: MavLinkData, key: Buffer, linkId?: uint8_t, sysid?: uint8_t, compid?: uint8_t):
|
47
|
+
sendSigned(msg: MavLinkData, key: Buffer, linkId?: uint8_t, sysid?: uint8_t, compid?: uint8_t): Promise<number>;
|
39
48
|
/**
|
40
49
|
* Send raw data over the socket. Useful for custom implementation of data sending
|
41
50
|
*
|
42
51
|
* @param buffer buffer to send
|
43
52
|
*/
|
44
|
-
sendBuffer(buffer: Buffer):
|
53
|
+
sendBuffer(buffer: Buffer): Promise<number>;
|
45
54
|
private processIncommingUDPData;
|
46
55
|
private processIncommingPacket;
|
47
56
|
}
|
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;AAOrC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEvD;;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;;IAmBvB;;;;;OAKG;IACG,KAAK,CAAC,WAAW,GAAE,MAAc,EAAE,QAAQ,GAAE,MAAc;
|
1
|
+
{"version":3,"file":"mavesp.d.ts","sourceRoot":"","sources":["../../lib/mavesp.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAOrC,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;;IAmBvB;;;;;OAKG;IACG,KAAK,CAAC,WAAW,GAAE,MAAc,EAAE,QAAQ,GAAE,MAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAmB3F;;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,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,uBAAuB;IAO/B,OAAO,CAAC,sBAAsB;CAI/B"}
|
package/dist/lib/mavesp.js
CHANGED
@@ -45,11 +45,24 @@ class MavEsp8266 extends events_1.EventEmitter {
|
|
45
45
|
// Wait for the first package to be returned to read the ip address
|
46
46
|
// of the controller
|
47
47
|
(0, utils_1.waitFor)(() => this.ip !== '')
|
48
|
-
.then(() => { resolve(this.ip); })
|
48
|
+
.then(() => { resolve({ ip: this.ip, sendPort, receivePort }); })
|
49
49
|
.catch(e => { reject(e); });
|
50
50
|
});
|
51
51
|
});
|
52
52
|
}
|
53
|
+
/**
|
54
|
+
* Closes the client stopping any message handlers
|
55
|
+
*/
|
56
|
+
async close() {
|
57
|
+
if (!this.socket)
|
58
|
+
throw new Error('Not connected');
|
59
|
+
// Unregister event handlers
|
60
|
+
this.socket.off('message', this.processIncommingUDPData);
|
61
|
+
// Close the socket
|
62
|
+
return new Promise(resolve => {
|
63
|
+
this.socket?.close(resolve);
|
64
|
+
});
|
65
|
+
}
|
53
66
|
/**
|
54
67
|
* Send a packet
|
55
68
|
*
|
@@ -57,11 +70,11 @@ class MavEsp8266 extends events_1.EventEmitter {
|
|
57
70
|
* @param sysid system id
|
58
71
|
* @param compid component id
|
59
72
|
*/
|
60
|
-
send(msg, sysid = mavlink_2.MavLinkProtocol.SYS_ID, compid = mavlink_2.MavLinkProtocol.COMP_ID) {
|
73
|
+
async send(msg, sysid = mavlink_2.MavLinkProtocol.SYS_ID, compid = mavlink_2.MavLinkProtocol.COMP_ID) {
|
61
74
|
const protocol = new mavlink_2.MavLinkProtocolV2(sysid, compid);
|
62
75
|
const buffer = protocol.serialize(msg, this.seq++);
|
63
76
|
this.seq &= 255;
|
64
|
-
this.sendBuffer(buffer);
|
77
|
+
return this.sendBuffer(buffer);
|
65
78
|
}
|
66
79
|
/**
|
67
80
|
* Send a signed packet
|
@@ -71,20 +84,27 @@ class MavEsp8266 extends events_1.EventEmitter {
|
|
71
84
|
* @param compid component id
|
72
85
|
* @param linkId link id for the signature
|
73
86
|
*/
|
74
|
-
sendSigned(msg, key, linkId = 1, sysid = mavlink_2.MavLinkProtocol.SYS_ID, compid = mavlink_2.MavLinkProtocol.COMP_ID) {
|
87
|
+
async sendSigned(msg, key, linkId = 1, sysid = mavlink_2.MavLinkProtocol.SYS_ID, compid = mavlink_2.MavLinkProtocol.COMP_ID) {
|
75
88
|
const protocol = new mavlink_2.MavLinkProtocolV2(sysid, compid, mavlink_2.MavLinkProtocolV2.IFLAG_SIGNED);
|
76
89
|
const b1 = protocol.serialize(msg, this.seq++);
|
77
90
|
this.seq &= 255;
|
78
91
|
const b2 = protocol.sign(b1, linkId, key);
|
79
|
-
this.sendBuffer(b2);
|
92
|
+
return this.sendBuffer(b2);
|
80
93
|
}
|
81
94
|
/**
|
82
95
|
* Send raw data over the socket. Useful for custom implementation of data sending
|
83
96
|
*
|
84
97
|
* @param buffer buffer to send
|
85
98
|
*/
|
86
|
-
sendBuffer(buffer) {
|
87
|
-
|
99
|
+
async sendBuffer(buffer) {
|
100
|
+
return new Promise((resolve, reject) => {
|
101
|
+
this.socket?.send(buffer, this.sendPort, this.ip, (err, bytes) => {
|
102
|
+
if (err)
|
103
|
+
reject(err);
|
104
|
+
else
|
105
|
+
resolve(bytes);
|
106
|
+
});
|
107
|
+
});
|
88
108
|
}
|
89
109
|
processIncommingUDPData(buffer, metadata) {
|
90
110
|
// store the remote ip address
|
@@ -16,7 +16,8 @@ async function main() {
|
|
16
16
|
const port = new MavEsp8266()
|
17
17
|
|
18
18
|
// start the communication
|
19
|
-
await port.start()
|
19
|
+
const { ip, sendPort, receivePort } = await port.start()
|
20
|
+
console.log(`Connected to: ${ip}, send port: ${sendPort}, receive port ${receivePort}`)
|
20
21
|
|
21
22
|
// log incomming messages
|
22
23
|
port.on('data', (packet: MavLinkPacket) => {
|
@@ -15,14 +15,17 @@ async function main() {
|
|
15
15
|
// start the communication
|
16
16
|
// After this line we have received at least one heartbeat message so we
|
17
17
|
// know what is the remote IP address to send the messages to
|
18
|
-
await port.start()
|
18
|
+
const { ip, sendPort, receivePort } = await port.start()
|
19
|
+
console.log(`Connected to: ${ip}, send port: ${sendPort}, receive port ${receivePort}`)
|
19
20
|
|
20
21
|
// log incomming messages
|
21
22
|
port.on('data', (packet: MavLinkPacket) => {
|
22
23
|
const clazz = REGISTRY[packet.header.msgid]
|
23
24
|
if (clazz) {
|
24
|
-
|
25
|
-
|
25
|
+
if (packet.header.msgid === common.CommandAck.MSG_ID) {
|
26
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
27
|
+
console.log('>', data)
|
28
|
+
}
|
26
29
|
} else {
|
27
30
|
console.log('!', packet.debug())
|
28
31
|
}
|
@@ -30,13 +33,21 @@ async function main() {
|
|
30
33
|
|
31
34
|
// You're now ready to send messages to the controller using the socket
|
32
35
|
// let's request the list of parameters
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
|
37
|
+
const cmdParamList = new common.ParamRequestList()
|
38
|
+
cmdParamList.targetSystem = 1
|
39
|
+
cmdParamList.targetComponent = 1
|
36
40
|
|
37
41
|
// The send method is another utility method, very handy to have it provided
|
38
42
|
// by the library. It takes care of the sequence number and data serialization.
|
39
|
-
await port.send(
|
43
|
+
await port.send(cmdParamList)
|
44
|
+
|
45
|
+
// Here's another example of sending commands
|
46
|
+
const cmdSetRelay = new common.DoSetRelayCommand()
|
47
|
+
cmdSetRelay.instance = 0
|
48
|
+
cmdSetRelay.setting = 1
|
49
|
+
|
50
|
+
await port.send(cmdSetRelay)
|
40
51
|
}
|
41
52
|
|
42
53
|
main()
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-mavlink",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.4.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.13-20230115"
|
26
26
|
},
|
27
27
|
"scripts": {
|
28
28
|
"clean": "rm -rf dist lib/*.js",
|