node-mavlink 1.0.12 → 1.1.1
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/launch.json +11 -10
- package/.vscode/settings.json +3 -0
- package/README.md +5 -8
- 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/index.js +1 -21
- package/dist/lib/logger.js +1 -118
- package/dist/lib/mavesp.js +1 -110
- package/dist/lib/mavlink.js +1 -689
- package/dist/lib/serialization.js +1 -172
- package/dist/lib/utils.js +1 -88
- package/examples/send-receive-file.ts +3 -8
- package/examples/send-receive-serial.ts +17 -5
- package/examples/send-receive-signed-serial.ts +17 -5
- package/examples/send-receive-signed-udp.ts +15 -4
- package/examples/send-receive-udp.ts +15 -3
- package/lib/serialization.test.ts +46 -0
- package/package.json +8 -7
- package/tests/main.ts +4 -8
- package/tsconfig.json +1 -1
@@ -1,172 +1 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DESERIALIZERS = exports.SERIALIZERS = void 0;
|
4
|
-
/**
|
5
|
-
* A dictionary containing functions that serialize a certain value based on the field type
|
6
|
-
*/
|
7
|
-
exports.SERIALIZERS = {
|
8
|
-
// special types
|
9
|
-
'uint8_t_mavlink_version': (value, buffer, offset) => buffer.writeUInt8(value, offset),
|
10
|
-
// singular types
|
11
|
-
'char': (value, buffer, offset) => buffer.writeUInt8(value, offset),
|
12
|
-
'int8_t': (value, buffer, offset) => buffer.writeInt8(value, offset),
|
13
|
-
'uint8_t': (value, buffer, offset) => buffer.writeUInt8(value, offset),
|
14
|
-
'int16_t': (value, buffer, offset) => buffer.writeInt16LE(value, offset),
|
15
|
-
'uint16_t': (value, buffer, offset) => buffer.writeUInt16LE(value, offset),
|
16
|
-
'int32_t': (value, buffer, offset) => buffer.writeInt32LE(value, offset),
|
17
|
-
'uint32_t': (value, buffer, offset) => buffer.writeUInt32LE(value, offset),
|
18
|
-
'int64_t': (value, buffer, offset) => buffer.writeBigInt64LE(value, offset),
|
19
|
-
'uint64_t': (value, buffer, offset) => buffer.writeBigUInt64LE(value, offset),
|
20
|
-
'float': (value, buffer, offset) => buffer.writeFloatLE(value, offset),
|
21
|
-
'double': (value, buffer, offset) => buffer.writeDoubleLE(value, offset),
|
22
|
-
// array types
|
23
|
-
'char[]': (value, buffer, offset, maxLen) => {
|
24
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
25
|
-
const code = value.charCodeAt(i);
|
26
|
-
buffer.writeUInt8(code, offset + i);
|
27
|
-
}
|
28
|
-
},
|
29
|
-
'int8_t[]': (value, buffer, offset, maxLen) => {
|
30
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
31
|
-
buffer.writeInt8(value[i], offset + i);
|
32
|
-
}
|
33
|
-
},
|
34
|
-
'uint8_t[]': (value, buffer, offset, maxLen) => {
|
35
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
36
|
-
buffer.writeUInt8(value[i], offset + i);
|
37
|
-
}
|
38
|
-
},
|
39
|
-
'int16_t[]': (value, buffer, offset, maxLen) => {
|
40
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
41
|
-
buffer.writeInt16LE(value[i], offset + i * 2);
|
42
|
-
}
|
43
|
-
},
|
44
|
-
'uint16_t[]': (value, buffer, offset, maxLen) => {
|
45
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
46
|
-
buffer.writeUInt16LE(value[i], offset + i * 2);
|
47
|
-
}
|
48
|
-
},
|
49
|
-
'int32_t[]': (value, buffer, offset, maxLen) => {
|
50
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
51
|
-
buffer.writeInt32LE(value[i], offset + i * 4);
|
52
|
-
}
|
53
|
-
},
|
54
|
-
'uint32_t[]': (value, buffer, offset, maxLen) => {
|
55
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
56
|
-
buffer.writeUInt32LE(value[i], offset + i * 4);
|
57
|
-
}
|
58
|
-
},
|
59
|
-
'int64_t[]': (value, buffer, offset, maxLen) => {
|
60
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
61
|
-
buffer.writeBigInt64LE(value[i], offset + i * 8);
|
62
|
-
}
|
63
|
-
},
|
64
|
-
'uint64_t[]': (value, buffer, offset, maxLen) => {
|
65
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
66
|
-
buffer.writeBigUInt64LE(value[i], offset + i * 8);
|
67
|
-
}
|
68
|
-
},
|
69
|
-
'float[]': (value, buffer, offset, maxLen) => {
|
70
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
71
|
-
buffer.writeFloatLE(value[i], offset + i * 4);
|
72
|
-
}
|
73
|
-
},
|
74
|
-
'double[]': (value, buffer, offset, maxLen) => {
|
75
|
-
for (let i = 0; i < value.length && i < maxLen; i++) {
|
76
|
-
buffer.writeDoubleLE(value[i], offset + i * 8);
|
77
|
-
}
|
78
|
-
},
|
79
|
-
};
|
80
|
-
/**
|
81
|
-
* A dictionary containing functions that deserialize a certain value based on the field type
|
82
|
-
*/
|
83
|
-
exports.DESERIALIZERS = {
|
84
|
-
// special types
|
85
|
-
'uint8_t_mavlink_version': (buffer, offset) => buffer.readUInt8(offset),
|
86
|
-
// singular types
|
87
|
-
'char': (buffer, offset) => String.fromCharCode(buffer.readUInt8(offset)),
|
88
|
-
'int8_t': (buffer, offset) => buffer.readInt8(offset),
|
89
|
-
'uint8_t': (buffer, offset) => buffer.readUInt8(offset),
|
90
|
-
'int16_t': (buffer, offset) => buffer.readInt16LE(offset),
|
91
|
-
'uint16_t': (buffer, offset) => buffer.readUInt16LE(offset),
|
92
|
-
'int32_t': (buffer, offset) => buffer.readInt32LE(offset),
|
93
|
-
'uint32_t': (buffer, offset) => buffer.readUInt32LE(offset),
|
94
|
-
'int64_t': (buffer, offset) => buffer.readBigInt64LE(offset),
|
95
|
-
'uint64_t': (buffer, offset) => buffer.readBigUInt64LE(offset),
|
96
|
-
'float': (buffer, offset) => buffer.readFloatLE(offset),
|
97
|
-
'double': (buffer, offset) => buffer.readDoubleLE(offset),
|
98
|
-
// array types
|
99
|
-
'char[]': (buffer, offset, length) => {
|
100
|
-
let result = '';
|
101
|
-
for (let i = 0; i < length; i++) {
|
102
|
-
const charCode = buffer.readUInt8(offset + i);
|
103
|
-
if (charCode !== 0) {
|
104
|
-
result += String.fromCharCode(charCode);
|
105
|
-
}
|
106
|
-
else {
|
107
|
-
break;
|
108
|
-
}
|
109
|
-
}
|
110
|
-
return result;
|
111
|
-
},
|
112
|
-
'int8_t[]': (buffer, offset, length) => {
|
113
|
-
const result = new Array(length);
|
114
|
-
for (let i = 0; i < length; i++)
|
115
|
-
result[i] = buffer.readInt8(offset + i);
|
116
|
-
return result;
|
117
|
-
},
|
118
|
-
'uint8_t[]': (buffer, offset, length) => {
|
119
|
-
const result = new Array(length);
|
120
|
-
for (let i = 0; i < length; i++)
|
121
|
-
result[i] = buffer.readUInt8(offset + i);
|
122
|
-
return result;
|
123
|
-
},
|
124
|
-
'int16_t[]': (buffer, offset, length) => {
|
125
|
-
const result = new Array(length);
|
126
|
-
for (let i = 0; i < length; i++)
|
127
|
-
result[i] = buffer.readInt16LE(offset + i * 2);
|
128
|
-
return result;
|
129
|
-
},
|
130
|
-
'uint16_t[]': (buffer, offset, length) => {
|
131
|
-
const result = new Array(length);
|
132
|
-
for (let i = 0; i < length; i++)
|
133
|
-
result[i] = buffer.readUInt16LE(offset + i * 2);
|
134
|
-
return result;
|
135
|
-
},
|
136
|
-
'int32_t[]': (buffer, offset, length) => {
|
137
|
-
const result = new Array(length);
|
138
|
-
for (let i = 0; i < length; i++)
|
139
|
-
result[i] = buffer.readInt32LE(offset + i * 4);
|
140
|
-
return result;
|
141
|
-
},
|
142
|
-
'uint32_t[]': (buffer, offset, length) => {
|
143
|
-
const result = new Array(length);
|
144
|
-
for (let i = 0; i < length; i++)
|
145
|
-
result[i] = buffer.readUInt32LE(offset + i * 4);
|
146
|
-
return result;
|
147
|
-
},
|
148
|
-
'int64_t[]': (buffer, offset, length) => {
|
149
|
-
const result = new Array(length);
|
150
|
-
for (let i = 0; i < length; i++)
|
151
|
-
result[i] = buffer.readBigInt64LE(offset + i * 8);
|
152
|
-
return result;
|
153
|
-
},
|
154
|
-
'uint64_t[]': (buffer, offset, length) => {
|
155
|
-
const result = new Array(length);
|
156
|
-
for (let i = 0; i < length; i++)
|
157
|
-
result[i] = buffer.readBigUInt64LE(offset + i * 8);
|
158
|
-
return result;
|
159
|
-
},
|
160
|
-
'float[]': (buffer, offset, length) => {
|
161
|
-
const result = new Array(length);
|
162
|
-
for (let i = 0; i < length; i++)
|
163
|
-
result[i] = buffer.readFloatLE(offset + i * 4);
|
164
|
-
return result;
|
165
|
-
},
|
166
|
-
'double[]': (buffer, offset, length) => {
|
167
|
-
const result = new Array(length);
|
168
|
-
for (let i = 0; i < length; i++)
|
169
|
-
result[i] = buffer.readDoubleLE(offset + i * 8);
|
170
|
-
return result;
|
171
|
-
},
|
172
|
-
};
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DESERIALIZERS=exports.SERIALIZERS=void 0,exports.SERIALIZERS={uint8_t_mavlink_version:(r,e,n)=>e.writeUInt8(r,n),char:(r,e,n)=>e.writeUInt8(r,n),int8_t:(r,e,n)=>e.writeInt8(r,n),uint8_t:(r,e,n)=>e.writeUInt8(r,n),int16_t:(r,e,n)=>e.writeInt16LE(r,n),uint16_t:(r,e,n)=>e.writeUInt16LE(r,n),int32_t:(r,e,n)=>e.writeInt32LE(r,n),uint32_t:(r,e,n)=>e.writeUInt32LE(r,n),int64_t:(r,e,n)=>e.writeBigInt64LE(r,n),uint64_t:(r,e,n)=>e.writeBigUInt64LE(r,n),float:(r,e,n)=>e.writeFloatLE(r,n),double:(r,e,n)=>e.writeDoubleLE(r,n),"char[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++){const o=r.charCodeAt(t);e.writeUInt8(o,n+t)}},"int8_t[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeInt8(r[t],n+t)},"uint8_t[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeUInt8(r[t],n+t)},"int16_t[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeInt16LE(r[t],n+t*2)},"uint16_t[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeUInt16LE(r[t],n+t*2)},"int32_t[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeInt32LE(r[t],n+t*4)},"uint32_t[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeUInt32LE(r[t],n+t*4)},"int64_t[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeBigInt64LE(r[t],n+t*8)},"uint64_t[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeBigUInt64LE(r[t],n+t*8)},"float[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeFloatLE(r[t],n+t*4)},"double[]":(r,e,n,i)=>{for(let t=0;t<r.length&&t<i;t++)e.writeDoubleLE(r[t],n+t*8)}},exports.DESERIALIZERS={uint8_t_mavlink_version:(r,e)=>r.readUInt8(e),char:(r,e)=>String.fromCharCode(r.readUInt8(e)),int8_t:(r,e)=>r.readInt8(e),uint8_t:(r,e)=>r.readUInt8(e),int16_t:(r,e)=>r.readInt16LE(e),uint16_t:(r,e)=>r.readUInt16LE(e),int32_t:(r,e)=>r.readInt32LE(e),uint32_t:(r,e)=>r.readUInt32LE(e),int64_t:(r,e)=>r.readBigInt64LE(e),uint64_t:(r,e)=>r.readBigUInt64LE(e),float:(r,e)=>r.readFloatLE(e),double:(r,e)=>r.readDoubleLE(e),"char[]":(r,e,n)=>{let i="";for(let t=0;t<n;t++){const o=r.readUInt8(e+t);if(o!==0)i+=String.fromCharCode(o);else break}return i},"int8_t[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readInt8(e+t);return i},"uint8_t[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readUInt8(e+t);return i},"int16_t[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readInt16LE(e+t*2);return i},"uint16_t[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readUInt16LE(e+t*2);return i},"int32_t[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readInt32LE(e+t*4);return i},"uint32_t[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readUInt32LE(e+t*4);return i},"int64_t[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readBigInt64LE(e+t*8);return i},"uint64_t[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readBigUInt64LE(e+t*8);return i},"float[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readFloatLE(e+t*4);return i},"double[]":(r,e,n)=>{const i=new Array(n);for(let t=0;t<n;t++)i[t]=r.readDoubleLE(e+t*8);return i}};
|
package/dist/lib/utils.js
CHANGED
@@ -1,88 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.waitFor = exports.sleep = exports.dump = exports.hex = void 0;
|
13
|
-
/**
|
14
|
-
* Convert a number to hexadecimal representation with a minumum
|
15
|
-
* number of characters and optional prefix (0x by default)
|
16
|
-
*
|
17
|
-
* @param n value to convert
|
18
|
-
* @param len length of the converted string (without prefix)
|
19
|
-
* @param prefix prefix to prepend the generated string with
|
20
|
-
*/
|
21
|
-
function hex(n, len = 2, prefix = '0x') {
|
22
|
-
return `${prefix}${n.toString(16).padStart(len, '0')}`;
|
23
|
-
}
|
24
|
-
exports.hex = hex;
|
25
|
-
/**
|
26
|
-
* Dump a buffer in a readable form
|
27
|
-
*
|
28
|
-
* @param buffer buffer to dump
|
29
|
-
* @param lineWidth width of the line, in bytes of buffer
|
30
|
-
*/
|
31
|
-
function dump(buffer, lineWidth = 16) {
|
32
|
-
const line = [];
|
33
|
-
let address = 0;
|
34
|
-
for (let i = 0; i < buffer.length; i++) {
|
35
|
-
line.push(hex(buffer[i], 2, '0x'));
|
36
|
-
if (line.length === lineWidth) {
|
37
|
-
console.log(hex(address, 4), '|', line.join(' '));
|
38
|
-
address += lineWidth;
|
39
|
-
line.length = 0;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
if (line.length > 0) {
|
43
|
-
console.log(hex(address, 4), '|', line.join(' '));
|
44
|
-
}
|
45
|
-
}
|
46
|
-
exports.dump = dump;
|
47
|
-
/**
|
48
|
-
* Sleep for a given number of miliseconds
|
49
|
-
*
|
50
|
-
* @param ms number of miliseconds to sleep
|
51
|
-
*/
|
52
|
-
function sleep(ms) {
|
53
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
54
|
-
}
|
55
|
-
exports.sleep = sleep;
|
56
|
-
/**
|
57
|
-
* Execute a callback every <code>interval</code>ms and if it will not return
|
58
|
-
* a truthy value in the <code>timeout<code>ms then throw a Timeout exception.
|
59
|
-
* This is a very useful utility that will allow you to specify how often
|
60
|
-
* a particular expression should be evaluated and how long will it take to end
|
61
|
-
* the execution without success. Great for time-sensitive operations.
|
62
|
-
*
|
63
|
-
* @param cb callback to call every <code>interval</code>ms
|
64
|
-
* @param timeout number of miliseconds that need to pass before the Timeout exception is thrown
|
65
|
-
* @param interval number of miliseconds before re-running the callback
|
66
|
-
*/
|
67
|
-
function waitFor(cb, timeout = 10000, interval = 100) {
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
69
|
-
return new Promise((resolve, reject) => {
|
70
|
-
const timeoutTimer = setTimeout(() => {
|
71
|
-
cleanup();
|
72
|
-
reject('Timeout');
|
73
|
-
}, timeout);
|
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
|
-
};
|
85
|
-
});
|
86
|
-
});
|
87
|
-
}
|
88
|
-
exports.waitFor = waitFor;
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.waitFor=exports.sleep=exports.dump=exports.hex=void 0;function hex(t,o=2,e="0x"){return`${e}${t.toString(16).padStart(o,"0")}`}exports.hex=hex;function dump(t,o=16){const e=[];let r=0;for(let n=0;n<t.length;n++)e.push(hex(t[n],2,"0x")),e.length===o&&(console.log(hex(r,4),"|",e.join(" ")),r+=o,e.length=0);e.length>0&&console.log(hex(r,4),"|",e.join(" "))}exports.dump=dump;function sleep(t){return new Promise(o=>setTimeout(o,t))}exports.sleep=sleep;async function waitFor(t,o=1e4,e=100){return new Promise((r,n)=>{const l=setTimeout(()=>{s(),n("Timeout")},o),u=setInterval(()=>{const i=t();i&&(s(),r(i))}),s=()=>{clearTimeout(l),clearTimeout(u)}})}exports.waitFor=waitFor;
|
@@ -7,14 +7,10 @@ import {
|
|
7
7
|
asluav, development, ualberta,
|
8
8
|
} from '..'
|
9
9
|
|
10
|
-
const file = createReadStream('./GH-5.bin')
|
11
|
-
|
12
10
|
const splitter = new MavLinkPacketSplitter()
|
13
|
-
|
14
|
-
const
|
15
|
-
|
16
|
-
.pipe(new MavLinkPacketParser())
|
17
|
-
|
11
|
+
const parser = new MavLinkPacketParser()
|
12
|
+
const file = createReadStream('./GH-5.bin')
|
13
|
+
const reader = file.pipe(splitter).pipe(parser)
|
18
14
|
|
19
15
|
// create a registry of mappings between a message id and a data class
|
20
16
|
const REGISTRY = {
|
@@ -41,4 +37,3 @@ file.on('close', () => {
|
|
41
37
|
console.log('Number of unknown packages:', splitter.unknownPackagesCount)
|
42
38
|
console.log('\nTotal number of consumed packets:', splitter.validPackages)
|
43
39
|
})
|
44
|
-
|
@@ -1,12 +1,18 @@
|
|
1
1
|
#!/usr/bin/env -S npx ts-node
|
2
2
|
|
3
|
-
import
|
4
|
-
import { MavLinkPacketSplitter, MavLinkPacketParser, MavLinkPacket } from '..'
|
5
|
-
import { common, waitFor, send } from '..'
|
3
|
+
import { SerialPort } from 'serialport'
|
4
|
+
import { MavLinkPacketRegistry, MavLinkPacketSplitter, MavLinkPacketParser, MavLinkPacket } from '..'
|
5
|
+
import { minimal, common, ardupilotmega, waitFor, send } from '..'
|
6
|
+
|
7
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
8
|
+
...minimal.REGISTRY,
|
9
|
+
...common.REGISTRY,
|
10
|
+
...ardupilotmega.REGISTRY,
|
11
|
+
}
|
6
12
|
|
7
13
|
async function main() {
|
8
14
|
// Create an output stream to write data to the controller
|
9
|
-
const port = new SerialPort('/dev/ttyACM0')
|
15
|
+
const port = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
|
10
16
|
|
11
17
|
// Create the reader as usual by piping the source stream through the splitter
|
12
18
|
// and packet parser
|
@@ -21,7 +27,13 @@ async function main() {
|
|
21
27
|
// This is the place where all your application-level logic will exist
|
22
28
|
reader.on('data', (packet: MavLinkPacket) => {
|
23
29
|
online = true
|
24
|
-
|
30
|
+
const clazz = REGISTRY[packet.header.msgid]
|
31
|
+
if (clazz) {
|
32
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
33
|
+
console.log('>', data)
|
34
|
+
} else {
|
35
|
+
console.log('!', packet.debug())
|
36
|
+
}
|
25
37
|
})
|
26
38
|
|
27
39
|
// Wait for the remote system to be available
|
@@ -1,16 +1,22 @@
|
|
1
1
|
#!/usr/bin/env -S npx ts-node
|
2
2
|
|
3
|
-
import
|
3
|
+
import { SerialPort } from 'serialport'
|
4
4
|
import { MavLinkPacketSplitter, MavLinkPacketParser } from '..'
|
5
|
-
import { MavLinkPacket, MavLinkPacketSignature } from '..'
|
6
|
-
import { common, waitFor, sendSigned } from '..'
|
5
|
+
import { MavLinkPacket, MavLinkPacketSignature, MavLinkPacketRegistry } from '..'
|
6
|
+
import { minimal, common, ardupilotmega, waitFor, sendSigned } from '..'
|
7
|
+
|
8
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
9
|
+
...minimal.REGISTRY,
|
10
|
+
...common.REGISTRY,
|
11
|
+
...ardupilotmega.REGISTRY,
|
12
|
+
}
|
7
13
|
|
8
14
|
// Use your own secret passphrase in place of 'qwerty'
|
9
15
|
const key = MavLinkPacketSignature.key('qwerty')
|
10
16
|
|
11
17
|
async function main() {
|
12
18
|
// Create an output stream to write data to the controller
|
13
|
-
const port = new SerialPort('/dev/ttyACM0')
|
19
|
+
const port = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
|
14
20
|
|
15
21
|
// Create the reader as usual by piping the source stream through the splitter
|
16
22
|
// and packet parser
|
@@ -25,7 +31,6 @@ async function main() {
|
|
25
31
|
// This is the place where all your application-level logic will exist
|
26
32
|
reader.on('data', (packet: MavLinkPacket) => {
|
27
33
|
online = true
|
28
|
-
console.log(packet.debug())
|
29
34
|
if (packet.signature) {
|
30
35
|
if (packet.signature.matches(key)) {
|
31
36
|
console.log('Signature check OK')
|
@@ -35,6 +40,13 @@ async function main() {
|
|
35
40
|
} else {
|
36
41
|
console.log('Packet not signed')
|
37
42
|
}
|
43
|
+
const clazz = REGISTRY[packet.header.msgid]
|
44
|
+
if (clazz) {
|
45
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
46
|
+
console.log('>', data)
|
47
|
+
} else {
|
48
|
+
console.log('!', packet.debug())
|
49
|
+
}
|
38
50
|
})
|
39
51
|
|
40
52
|
// Wait for the remote system to be available
|
@@ -1,7 +1,13 @@
|
|
1
1
|
#!/usr/bin/env -S npx ts-node
|
2
2
|
|
3
|
-
import { MavEsp8266, common } from '
|
4
|
-
import { MavLinkPacket,
|
3
|
+
import { MavEsp8266, minimal, common, ardupilotmega } from '..'
|
4
|
+
import { MavLinkPacketSignature, MavLinkPacket, MavLinkPacketRegistry } from '..'
|
5
|
+
|
6
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
7
|
+
...minimal.REGISTRY,
|
8
|
+
...common.REGISTRY,
|
9
|
+
...ardupilotmega.REGISTRY,
|
10
|
+
}
|
5
11
|
|
6
12
|
// Use your own secret passphrase in place of 'qwerty'
|
7
13
|
const key = MavLinkPacketSignature.key('qwerty')
|
@@ -14,8 +20,6 @@ async function main() {
|
|
14
20
|
|
15
21
|
// log incomming messages
|
16
22
|
port.on('data', (packet: MavLinkPacket) => {
|
17
|
-
console.log(packet.debug())
|
18
|
-
console.log(packet.debug())
|
19
23
|
if (packet.signature) {
|
20
24
|
if (packet.signature.matches(key)) {
|
21
25
|
console.log('Signature check OK')
|
@@ -25,6 +29,13 @@ async function main() {
|
|
25
29
|
} else {
|
26
30
|
console.log('Packet not signed')
|
27
31
|
}
|
32
|
+
const clazz = REGISTRY[packet.header.msgid]
|
33
|
+
if (clazz) {
|
34
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
35
|
+
console.log('>', data)
|
36
|
+
} else {
|
37
|
+
console.log('!', packet.debug())
|
38
|
+
}
|
28
39
|
})
|
29
40
|
|
30
41
|
// You're now ready to send messages to the controller using the socket
|
@@ -1,7 +1,13 @@
|
|
1
1
|
#!/usr/bin/env -S npx ts-node
|
2
2
|
|
3
|
-
import { MavEsp8266, common } from '..'
|
4
|
-
import { MavLinkPacket } from '..'
|
3
|
+
import { MavEsp8266, minimal, common, ardupilotmega } from '..'
|
4
|
+
import { MavLinkPacket, MavLinkPacketRegistry } from '..'
|
5
|
+
|
6
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
7
|
+
...minimal.REGISTRY,
|
8
|
+
...common.REGISTRY,
|
9
|
+
...ardupilotmega.REGISTRY,
|
10
|
+
}
|
5
11
|
|
6
12
|
async function main() {
|
7
13
|
const port = new MavEsp8266()
|
@@ -13,7 +19,13 @@ async function main() {
|
|
13
19
|
|
14
20
|
// log incomming messages
|
15
21
|
port.on('data', (packet: MavLinkPacket) => {
|
16
|
-
|
22
|
+
const clazz = REGISTRY[packet.header.msgid]
|
23
|
+
if (clazz) {
|
24
|
+
const data = packet.protocol.data(packet.payload, clazz)
|
25
|
+
console.log('>', data)
|
26
|
+
} else {
|
27
|
+
console.log('!', packet.debug())
|
28
|
+
}
|
17
29
|
})
|
18
30
|
|
19
31
|
// You're now ready to send messages to the controller using the socket
|
@@ -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
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-mavlink",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.1.1",
|
4
4
|
"author": "Matthias Hryniszak <padcom@gmail.com>",
|
5
5
|
"license": "LGPL",
|
6
6
|
"description": "MavLink definitions and parsing library",
|
@@ -22,23 +22,24 @@
|
|
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.9-20220424"
|
26
26
|
},
|
27
27
|
"scripts": {
|
28
|
-
"build": "tsc",
|
29
|
-
"test": "jest",
|
28
|
+
"build": "tsc && minimize-js dist",
|
29
|
+
"test": "jest && npm run test:batch",
|
30
|
+
"test:batch": "npx ts-node tests/main.ts e2e --input tests/data.mavlink",
|
30
31
|
"dev": "jest --watch",
|
31
32
|
"test:e2e": "cd tests && ./main.ts e2e --input data.mavlink",
|
32
|
-
"prepublishOnly": "rm -rf dist && npm install && npm
|
33
|
+
"prepublishOnly": "rm -rf dist && npm install && npm run build && npm test"
|
33
34
|
},
|
34
35
|
"devDependencies": {
|
35
36
|
"@types/jest": "^27.4.1",
|
36
37
|
"@types/node": "^15.14.9",
|
37
|
-
"@types/serialport": "^8.0.1",
|
38
38
|
"@types/xml2js": "^0.4.8",
|
39
39
|
"@types/yargs": "^17.0.8",
|
40
40
|
"jest": "^27.5.1",
|
41
|
-
"
|
41
|
+
"minimize-js": "^1.3.0",
|
42
|
+
"serialport": "^10.0.0",
|
42
43
|
"ts-jest": "^27.1.4",
|
43
44
|
"ts-node": "^9.1.1",
|
44
45
|
"typescript": "^4.4.3",
|
package/tests/main.ts
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
import yargs from 'yargs'
|
4
4
|
import { existsSync, createReadStream } from 'fs'
|
5
5
|
import { minimal, common, ardupilotmega } from 'mavlink-mappings'
|
6
|
-
import { createMavLinkStream, MavLinkPacket, Logger, LogLevel } from '..'
|
7
|
-
import {
|
6
|
+
import { createMavLinkStream, MavLinkPacket, Logger, LogLevel, MavLinkPacketRegistry } from '..'
|
7
|
+
import { dump } from '..'
|
8
8
|
|
9
9
|
Logger.on('log', ({ context, level, message }) => {
|
10
10
|
if (level <= LogLevel.error) {
|
@@ -36,7 +36,7 @@ async function main() {
|
|
36
36
|
|
37
37
|
const command = config._[0]
|
38
38
|
if (command === 'e2e') {
|
39
|
-
const REGISTRY = {
|
39
|
+
const REGISTRY: MavLinkPacketRegistry = {
|
40
40
|
...minimal.REGISTRY,
|
41
41
|
...common.REGISTRY,
|
42
42
|
...ardupilotmega.REGISTRY,
|
@@ -48,11 +48,7 @@ async function main() {
|
|
48
48
|
reader.on('data', (packet: MavLinkPacket) => {
|
49
49
|
const clazz = REGISTRY[packet.header.msgid]
|
50
50
|
if (clazz) {
|
51
|
-
|
52
|
-
console.log('<', packet.debug())
|
53
|
-
clazz.FIELDS.forEach(field => {
|
54
|
-
console.log(clazz.MSG_NAME + '.' + field.source + ' = ' + message[field.name])
|
55
|
-
})
|
51
|
+
packet.protocol.data(packet.payload, clazz)
|
56
52
|
} else {
|
57
53
|
console.log('< (unknown)', packet.debug())
|
58
54
|
}
|