https://github.com/roackb2/mavlinkjs
JavaScript implementation of Mavlink protocols
https://github.com/roackb2/mavlinkjs
Last synced: about 1 year ago
JSON representation
JavaScript implementation of Mavlink protocols
- Host: GitHub
- URL: https://github.com/roackb2/mavlinkjs
- Owner: roackb2
- Created: 2020-09-30T14:52:46.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-15T18:25:59.000Z (about 3 years ago)
- Last Synced: 2025-04-22T23:51:30.524Z (about 1 year ago)
- Language: JavaScript
- Size: 312 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# What's This
This repository is an npm module and a JavaScript MAVLink implementation to parse MAVLink messages, generated using [Parrot MAVLink repository](https://github.com/Parrot-Developers/mavlink/tree/master/pymavlink/generator/javascript),
with the multiple dialects, including `all` and `common` for now, using Mavlink v1.0 and v2.0 protocol.
# Import
## Using v1.0 protocpl
```JavaScript
const { mavlink10: mavlink, MAVLink10Processor: MAVLink } = require('mavlinkjs/mavlink_all_v1');
```
or
```JavaScript
import { mavlink10 as mavlink, MAVLink10Processor as MAVLink } from 'mavlinkjs/mavlink_all_v1';
```
## Using v2.0 protocol
```JavaScript
const { mavlink20: mavlink, MAVLink20Processor: MAVLink } = require('mavlinkjs/mavlink_all_v2');
```
or
```JavaScript
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:
```JavaScript
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) {
// the parsed message is here
console.log(msg);
});
mavlinkParser.on('HEARTBEAT', function(msg) {
// you could listen on specific message type
console.log(msg.name)
// outputs 'HEARTBEAT'
});
const serialport = new SerialPort('/dev/tty.usbserial-1430', {
57600,
autoOpen: true
})
serialport.on('error', function(err) {
logger.warn(`Error in serial port: ${err.message}`)
})
// When the connection issues a "got data" event, try and parse it
serialport.on('data', function(data) {
// pass to mavlinkParser to parse the raw data
mavlinkParser.parseBuffer(data)
});
```