What's This
This repository is an npm module and a JavaScript MAVLink implementation to parse MAVLink messages, generated using Parrot MAVLink repository,
with the multiple dialects, including all
and common
for now, using Mavlink v1.0 and v2.0 protocol.
Import
Using v1.0 protocpl
const { mavlink10: mavlink, MAVLink10Processor: MAVLink } = require('mavlinkjs/mavlink_all_v1');
or
import { mavlink10 as mavlink, MAVLink10Processor as MAVLink } from 'mavlinkjs/mavlink_all_v1';
Using v2.0 protocol
const { mavlink20: mavlink, MAVLink20Processor: MAVLink } = require('mavlinkjs/mavlink_all_v2');
or
import { mavlink20 as mavlink, MAVLink20Processor as MAVLink } from 'mavlinkjs/mavlink_all_v2';
Usage
Suppose you're using serial port to read data from your flight control, you could use Mavlink parser as following:
const SerialPort = require('serialport');
const { mavlink10: mavlink, MAVLink10Processor: MAVLink } = require('mavlinkjs/mavlink_all_v1');
const mavlinkParser = new MAVLink(null, 0, 0);
mavlinkParser.on('message', function(msg) {
console.log(msg);
});
mavlinkParser.on('HEARTBEAT', function(msg) {
console.log(msg.name)
});
const serialport = new SerialPort('/dev/tty.usbserial-1430', {
57600,
autoOpen: true
})
serialport.on('error', function(err) {
logger.warn(`Error in serial port: ${err.message}`)
})
serialport.on('data', function(data) {
mavlinkParser.parseBuffer(data)
});