mavlink-browser
v1.5.0
Published
Allows the parsing and generation of mavlink v1 and v2 packets within a browser environment.
Downloads
99
Maintainers
Readme
Allows the parsing and generation of mavlink v1 and v2 packets within a browser environment.
🏠 Homepage
Install
npm i mavlink-browser
Run tests
npm run test
Usage
//initial
import { mavlink20, MAVLink20Processor, Buffer } from 'mavlink-browser';
const mavlinkParser = new MAVLink20Processor(null, 42, 150);
//Establish a connection medium. Ex - WebSerial:
const port = await navigator.serial.requestPort();
await port.open({ baudRate: 57600 });
//Create a message handler to handle incoming mavlink messages
mavlinkParser.on('message',(msg) => {
//Can implement any custom logic to handle incoming messages. Below just logs the message to the console.
console.log(msg)
})
//Can also create a handler for every mavlink message ex:
mavlinkParser.on('HEARTBEAT', (heartbeat) => {
console.log(heartbeat)
})
mavlinkParser.on('MISSION_ACK', (mack) => {
console.log(mack)
})
//Intialize serial port reader
const reader = port.readable.getReader();
while (reader) {
const { value, done } = await reader.read();
if (done) {
reader.releaseLock();
break;
}
// the below line parses the uint8 array and emits a message which is sent to the handler created above
mavlinkParser.parseBuffer(value)
}
//Sending messages:
const writer = port.writable.getWriter();
//Create a command ex arm command:
const armCommand = new mavlink20.messages.command_long(1, 0, mavlink20.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 0, 0, 0, 0, 0, 0);
//Format it accordingly and send it through the webserial port
if (writer) {
writer.write(new Buffer(armCommand.pack(mavlinkParser)))
}
Author
👤 Neel Sani
- Website: neels.dev/
- Github: @neelsani
- Email: [email protected]
🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide. Or just shoot me an email at [email protected]
Show your support
Give a ⭐️ if this project helped you!