node-mavlink 1.0.12 → 1.0.13
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/.vscode/settings.json +3 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/serialization.ts.html +613 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +0 -0
- package/dist/lib/mavesp.js +13 -24
- package/dist/lib/mavlink.js +21 -34
- package/dist/lib/utils.js +15 -26
- package/lib/serialization.test.ts +46 -0
- package/package.json +1 -1
- package/tsconfig.json +1 -1
@@ -0,0 +1,196 @@
|
|
1
|
+
/* eslint-disable */
|
2
|
+
var addSorting = (function() {
|
3
|
+
'use strict';
|
4
|
+
var cols,
|
5
|
+
currentSort = {
|
6
|
+
index: 0,
|
7
|
+
desc: false
|
8
|
+
};
|
9
|
+
|
10
|
+
// returns the summary table element
|
11
|
+
function getTable() {
|
12
|
+
return document.querySelector('.coverage-summary');
|
13
|
+
}
|
14
|
+
// returns the thead element of the summary table
|
15
|
+
function getTableHeader() {
|
16
|
+
return getTable().querySelector('thead tr');
|
17
|
+
}
|
18
|
+
// returns the tbody element of the summary table
|
19
|
+
function getTableBody() {
|
20
|
+
return getTable().querySelector('tbody');
|
21
|
+
}
|
22
|
+
// returns the th element for nth column
|
23
|
+
function getNthColumn(n) {
|
24
|
+
return getTableHeader().querySelectorAll('th')[n];
|
25
|
+
}
|
26
|
+
|
27
|
+
function onFilterInput() {
|
28
|
+
const searchValue = document.getElementById('fileSearch').value;
|
29
|
+
const rows = document.getElementsByTagName('tbody')[0].children;
|
30
|
+
for (let i = 0; i < rows.length; i++) {
|
31
|
+
const row = rows[i];
|
32
|
+
if (
|
33
|
+
row.textContent
|
34
|
+
.toLowerCase()
|
35
|
+
.includes(searchValue.toLowerCase())
|
36
|
+
) {
|
37
|
+
row.style.display = '';
|
38
|
+
} else {
|
39
|
+
row.style.display = 'none';
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
// loads the search box
|
45
|
+
function addSearchBox() {
|
46
|
+
var template = document.getElementById('filterTemplate');
|
47
|
+
var templateClone = template.content.cloneNode(true);
|
48
|
+
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
49
|
+
template.parentElement.appendChild(templateClone);
|
50
|
+
}
|
51
|
+
|
52
|
+
// loads all columns
|
53
|
+
function loadColumns() {
|
54
|
+
var colNodes = getTableHeader().querySelectorAll('th'),
|
55
|
+
colNode,
|
56
|
+
cols = [],
|
57
|
+
col,
|
58
|
+
i;
|
59
|
+
|
60
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
61
|
+
colNode = colNodes[i];
|
62
|
+
col = {
|
63
|
+
key: colNode.getAttribute('data-col'),
|
64
|
+
sortable: !colNode.getAttribute('data-nosort'),
|
65
|
+
type: colNode.getAttribute('data-type') || 'string'
|
66
|
+
};
|
67
|
+
cols.push(col);
|
68
|
+
if (col.sortable) {
|
69
|
+
col.defaultDescSort = col.type === 'number';
|
70
|
+
colNode.innerHTML =
|
71
|
+
colNode.innerHTML + '<span class="sorter"></span>';
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return cols;
|
75
|
+
}
|
76
|
+
// attaches a data attribute to every tr element with an object
|
77
|
+
// of data values keyed by column name
|
78
|
+
function loadRowData(tableRow) {
|
79
|
+
var tableCols = tableRow.querySelectorAll('td'),
|
80
|
+
colNode,
|
81
|
+
col,
|
82
|
+
data = {},
|
83
|
+
i,
|
84
|
+
val;
|
85
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
86
|
+
colNode = tableCols[i];
|
87
|
+
col = cols[i];
|
88
|
+
val = colNode.getAttribute('data-value');
|
89
|
+
if (col.type === 'number') {
|
90
|
+
val = Number(val);
|
91
|
+
}
|
92
|
+
data[col.key] = val;
|
93
|
+
}
|
94
|
+
return data;
|
95
|
+
}
|
96
|
+
// loads all row data
|
97
|
+
function loadData() {
|
98
|
+
var rows = getTableBody().querySelectorAll('tr'),
|
99
|
+
i;
|
100
|
+
|
101
|
+
for (i = 0; i < rows.length; i += 1) {
|
102
|
+
rows[i].data = loadRowData(rows[i]);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
// sorts the table using the data for the ith column
|
106
|
+
function sortByIndex(index, desc) {
|
107
|
+
var key = cols[index].key,
|
108
|
+
sorter = function(a, b) {
|
109
|
+
a = a.data[key];
|
110
|
+
b = b.data[key];
|
111
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
112
|
+
},
|
113
|
+
finalSorter = sorter,
|
114
|
+
tableBody = document.querySelector('.coverage-summary tbody'),
|
115
|
+
rowNodes = tableBody.querySelectorAll('tr'),
|
116
|
+
rows = [],
|
117
|
+
i;
|
118
|
+
|
119
|
+
if (desc) {
|
120
|
+
finalSorter = function(a, b) {
|
121
|
+
return -1 * sorter(a, b);
|
122
|
+
};
|
123
|
+
}
|
124
|
+
|
125
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
126
|
+
rows.push(rowNodes[i]);
|
127
|
+
tableBody.removeChild(rowNodes[i]);
|
128
|
+
}
|
129
|
+
|
130
|
+
rows.sort(finalSorter);
|
131
|
+
|
132
|
+
for (i = 0; i < rows.length; i += 1) {
|
133
|
+
tableBody.appendChild(rows[i]);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
// removes sort indicators for current column being sorted
|
137
|
+
function removeSortIndicators() {
|
138
|
+
var col = getNthColumn(currentSort.index),
|
139
|
+
cls = col.className;
|
140
|
+
|
141
|
+
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
142
|
+
col.className = cls;
|
143
|
+
}
|
144
|
+
// adds sort indicators for current column being sorted
|
145
|
+
function addSortIndicators() {
|
146
|
+
getNthColumn(currentSort.index).className += currentSort.desc
|
147
|
+
? ' sorted-desc'
|
148
|
+
: ' sorted';
|
149
|
+
}
|
150
|
+
// adds event listeners for all sorter widgets
|
151
|
+
function enableUI() {
|
152
|
+
var i,
|
153
|
+
el,
|
154
|
+
ithSorter = function ithSorter(i) {
|
155
|
+
var col = cols[i];
|
156
|
+
|
157
|
+
return function() {
|
158
|
+
var desc = col.defaultDescSort;
|
159
|
+
|
160
|
+
if (currentSort.index === i) {
|
161
|
+
desc = !currentSort.desc;
|
162
|
+
}
|
163
|
+
sortByIndex(i, desc);
|
164
|
+
removeSortIndicators();
|
165
|
+
currentSort.index = i;
|
166
|
+
currentSort.desc = desc;
|
167
|
+
addSortIndicators();
|
168
|
+
};
|
169
|
+
};
|
170
|
+
for (i = 0; i < cols.length; i += 1) {
|
171
|
+
if (cols[i].sortable) {
|
172
|
+
// add the click event handler on the th so users
|
173
|
+
// dont have to click on those tiny arrows
|
174
|
+
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
175
|
+
if (el.addEventListener) {
|
176
|
+
el.addEventListener('click', ithSorter(i));
|
177
|
+
} else {
|
178
|
+
el.attachEvent('onclick', ithSorter(i));
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
}
|
183
|
+
// adds sorting functionality to the UI
|
184
|
+
return function() {
|
185
|
+
if (!getTable()) {
|
186
|
+
return;
|
187
|
+
}
|
188
|
+
cols = loadColumns();
|
189
|
+
loadData();
|
190
|
+
addSearchBox();
|
191
|
+
addSortIndicators();
|
192
|
+
enableUI();
|
193
|
+
};
|
194
|
+
})();
|
195
|
+
|
196
|
+
window.addEventListener('load', addSorting);
|
File without changes
|
package/dist/lib/mavesp.js
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
3
|
exports.MavEsp8266 = void 0;
|
13
4
|
const events_1 = require("events");
|
@@ -41,21 +32,19 @@ class MavEsp8266 extends events_1.EventEmitter {
|
|
41
32
|
* @param receivePort port to receive messages on (default: 14550)
|
42
33
|
* @param sendPort port to send messages to (default: 14555)
|
43
34
|
*/
|
44
|
-
start(receivePort = 14550, sendPort = 14555) {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
.catch(e => { reject(e); });
|
58
|
-
});
|
35
|
+
async start(receivePort = 14550, sendPort = 14555) {
|
36
|
+
this.sendPort = sendPort;
|
37
|
+
// Create a UDP socket
|
38
|
+
this.socket = (0, dgram_1.createSocket)({ type: 'udp4', reuseAddr: true });
|
39
|
+
this.socket.on('message', this.processIncommingUDPData);
|
40
|
+
// Start listening on the socket
|
41
|
+
return new Promise((resolve, reject) => {
|
42
|
+
this.socket.bind(receivePort, () => {
|
43
|
+
// Wait for the first package to be returned to read the ip address
|
44
|
+
// of the controller
|
45
|
+
(0, utils_1.waitFor)(() => this.ip !== '')
|
46
|
+
.then(() => { resolve(this.ip); })
|
47
|
+
.catch(e => { reject(e); });
|
59
48
|
});
|
60
49
|
});
|
61
50
|
}
|
package/dist/lib/mavlink.js
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
3
|
exports.sendSigned = exports.send = exports.createMavLinkStream = exports.MavLinkPacketParser = exports.MavLinkPacketSplitter = exports.MavLinkPacket = exports.MavLinkPacketSignature = exports.MavLinkProtocolV2 = exports.MavLinkProtocolV1 = exports.MavLinkProtocol = exports.MavLinkPacketHeader = void 0;
|
13
4
|
const stream_1 = require("stream");
|
@@ -596,7 +587,7 @@ exports.MavLinkPacketSplitter = MavLinkPacketSplitter;
|
|
596
587
|
*/
|
597
588
|
class MavLinkPacketParser extends stream_1.Transform {
|
598
589
|
constructor(opts = {}) {
|
599
|
-
super(
|
590
|
+
super({ ...opts, objectMode: true });
|
600
591
|
this.log = logger_1.Logger.getLogger(this);
|
601
592
|
}
|
602
593
|
getProtocol(buffer) {
|
@@ -643,17 +634,15 @@ let seq = 0;
|
|
643
634
|
* @param protocol protocol to use (default: MavLinkProtocolV1)
|
644
635
|
* @returns number of bytes sent
|
645
636
|
*/
|
646
|
-
function send(stream, msg, protocol = new MavLinkProtocolV1()) {
|
647
|
-
return
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
resolve(buffer.length);
|
656
|
-
});
|
637
|
+
async function send(stream, msg, protocol = new MavLinkProtocolV1()) {
|
638
|
+
return new Promise((resolve, reject) => {
|
639
|
+
const buffer = protocol.serialize(msg, seq++);
|
640
|
+
seq &= 255;
|
641
|
+
stream.write(buffer, err => {
|
642
|
+
if (err)
|
643
|
+
reject(err);
|
644
|
+
else
|
645
|
+
resolve(buffer.length);
|
657
646
|
});
|
658
647
|
});
|
659
648
|
}
|
@@ -670,19 +659,17 @@ exports.send = send;
|
|
670
659
|
* @param timestamp optional timestamp for packet signing (default: Date.now())
|
671
660
|
* @returns number of bytes sent
|
672
661
|
*/
|
673
|
-
function sendSigned(stream, msg, key, linkId = 1, sysid = MavLinkProtocol.SYS_ID, compid = MavLinkProtocol.COMP_ID, timestamp = Date.now()) {
|
674
|
-
return
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
resolve(b2.length);
|
685
|
-
});
|
662
|
+
async function sendSigned(stream, msg, key, linkId = 1, sysid = MavLinkProtocol.SYS_ID, compid = MavLinkProtocol.COMP_ID, timestamp = Date.now()) {
|
663
|
+
return new Promise((resolve, reject) => {
|
664
|
+
const protocol = new MavLinkProtocolV2(sysid, compid, MavLinkProtocolV2.IFLAG_SIGNED);
|
665
|
+
const b1 = protocol.serialize(msg, seq++);
|
666
|
+
seq &= 255;
|
667
|
+
const b2 = protocol.sign(b1, linkId, key, timestamp);
|
668
|
+
stream.write(b2, err => {
|
669
|
+
if (err)
|
670
|
+
reject(err);
|
671
|
+
else
|
672
|
+
resolve(b2.length);
|
686
673
|
});
|
687
674
|
});
|
688
675
|
}
|
package/dist/lib/utils.js
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
3
|
exports.waitFor = exports.sleep = exports.dump = exports.hex = void 0;
|
13
4
|
/**
|
@@ -64,25 +55,23 @@ exports.sleep = sleep;
|
|
64
55
|
* @param timeout number of miliseconds that need to pass before the Timeout exception is thrown
|
65
56
|
* @param interval number of miliseconds before re-running the callback
|
66
57
|
*/
|
67
|
-
function waitFor(cb, timeout = 10000, interval = 100) {
|
68
|
-
return
|
69
|
-
|
70
|
-
|
58
|
+
async function waitFor(cb, timeout = 10000, interval = 100) {
|
59
|
+
return new Promise((resolve, reject) => {
|
60
|
+
const timeoutTimer = setTimeout(() => {
|
61
|
+
cleanup();
|
62
|
+
reject('Timeout');
|
63
|
+
}, timeout);
|
64
|
+
const intervalTimer = setInterval(() => {
|
65
|
+
const result = cb();
|
66
|
+
if (result) {
|
71
67
|
cleanup();
|
72
|
-
|
73
|
-
}
|
74
|
-
const intervalTimer = setInterval(() => {
|
75
|
-
const result = cb();
|
76
|
-
if (result) {
|
77
|
-
cleanup();
|
78
|
-
resolve(result);
|
79
|
-
}
|
80
|
-
});
|
81
|
-
const cleanup = () => {
|
82
|
-
clearTimeout(timeoutTimer);
|
83
|
-
clearTimeout(intervalTimer);
|
84
|
-
};
|
68
|
+
resolve(result);
|
69
|
+
}
|
85
70
|
});
|
71
|
+
const cleanup = () => {
|
72
|
+
clearTimeout(timeoutTimer);
|
73
|
+
clearTimeout(intervalTimer);
|
74
|
+
};
|
86
75
|
});
|
87
76
|
}
|
88
77
|
exports.waitFor = waitFor;
|
@@ -162,6 +162,52 @@ describe('serialization', () => {
|
|
162
162
|
})
|
163
163
|
})
|
164
164
|
|
165
|
+
describe('uint64_t', () => {
|
166
|
+
it('will serialize 64-bit unsigned int', () => {
|
167
|
+
const b = Buffer.from([0, -1, -2, -3, -4, -5, -6, -7])
|
168
|
+
SERIALIZERS['uint64_t'](2n, b, 0)
|
169
|
+
expect(b).toStrictEqual(Buffer.from([2, 0, 0, 0, 0, 0, 0, 0]))
|
170
|
+
})
|
171
|
+
it('will deserialize 64-bit unsigned int', () => {
|
172
|
+
const b = Buffer.from([2, 0, 0, 0, 0, 0, 0, 0])
|
173
|
+
const result = DESERIALIZERS['uint64_t'](b, 0)
|
174
|
+
expect(result).toBe(2n)
|
175
|
+
})
|
176
|
+
it('will serialize array of 64-bit unsigned int', () => {
|
177
|
+
const b = Buffer.from(new Array(24))
|
178
|
+
SERIALIZERS['uint64_t[]']([ 1n, 2n, 4n ], b, 0, 3)
|
179
|
+
expect(b).toStrictEqual(Buffer.from([1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0]))
|
180
|
+
})
|
181
|
+
it('will deserialize array of 64-bit unsigned int', () => {
|
182
|
+
const b = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0])
|
183
|
+
const result = DESERIALIZERS['uint64_t[]'](b, 0, 3)
|
184
|
+
expect(result).toEqual([1n, 2n, 5n])
|
185
|
+
})
|
186
|
+
})
|
187
|
+
|
188
|
+
describe('int64_t', () => {
|
189
|
+
it('will serialize 64-bit signed int', () => {
|
190
|
+
const b = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0])
|
191
|
+
SERIALIZERS['int64_t'](-2n, b, 0)
|
192
|
+
expect(b).toStrictEqual(Buffer.from([254, 255, 255, 255, 255, 255, 255, 255]))
|
193
|
+
})
|
194
|
+
it('will deserialize 64-bit signed int', () => {
|
195
|
+
const b = Buffer.from([254, 255, 255, 255, 255, 255, 255, 255])
|
196
|
+
const result = DESERIALIZERS['int64_t'](b, 0)
|
197
|
+
expect(result).toBe(-2n)
|
198
|
+
})
|
199
|
+
it('will serialize array of 64-bit signed int', () => {
|
200
|
+
const b = Buffer.from(new Array(24))
|
201
|
+
SERIALIZERS['int64_t[]']([ 1n, -2n, -5n ], b, 0, 3)
|
202
|
+
expect(b).toStrictEqual(Buffer.from([1, 0, 0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255, 251, 255, 255, 255, 255, 255, 255, 255]))
|
203
|
+
})
|
204
|
+
it('will deserialize array of 64-bit signed int', () => {
|
205
|
+
const b = Buffer.from([1, 0, 0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255, 250, 255, 255, 255, 255, 255, 255, 255])
|
206
|
+
const result = DESERIALIZERS['int64_t[]'](b, 0, 3)
|
207
|
+
expect(result).toEqual([1n, -2n, -6n])
|
208
|
+
})
|
209
|
+
})
|
210
|
+
|
165
211
|
describe('float', () => {
|
166
212
|
it('will serialize float', () => {
|
167
213
|
const b = Buffer.from([0, -1, -2, -3])
|
package/package.json
CHANGED