forked from omcaree/node-mavlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·65 lines (53 loc) · 1.57 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var SerialPort = require('serialport').SerialPort;
var mavlink = require('./src/mavlink.js');
//Open serial port
var port = new SerialPort('/dev/ttyO1', {
baudrate: 57600
});
//When port is open, start up mavlink
port.on('open', function() {
console.log("Serial Port is ready");
//listening for system 1 component 1
var m = new mavlink(1,1);
//When mavlink is ready, assign some listeners
m.on('ready', function() {
console.log("Mavlink is ready!");
//Parse any new incoming data
port.on('data', function(data) {
m.parse(data);
});
//Attitude listener
m.on('ATTITUDE', function(message, fields) {
//Do something interesting with Attitude data here
console.log("Roll is " + fields.roll + "\nPitch is " + fields.pitch);
});
//Create a few messages and print them to screen
m.createMessage("ATTITUDE", {
'time_boot_ms': 30,
'roll': 0.1,
'pitch': 0.2,
'yaw': 0.3,
'rollspeed': 0.4,
'pitchspeed': 0.5,
'yawspeed': 0.6
}, echoMessage);
m.createMessage("PARAM_VALUE", {
'param_id': 'MY_PI',
'param_value': 3.14159,
'param_type': 5,
'param_count': 100,
'param_index': 55
}, echoMessage);
m.createMessage("GPS_STATUS", {
'satellites_visible': 5,
'satellite_prn': [1, 2, 3, 4, 5],
'satellite_used': [2, 3, 4, 5, 6],
'satellite_elevation': [3, 4, 5, 6, 7],
'satellite_azimuth': [4, 5, 6, 7, 8],
'satellite_snr': [5, 6, 7, 8, 9]
}, echoMessage);
});
});
var echoMessage = function(message) {
console.log(message);
}