Created
February 26, 2023 01:04
-
-
Save dbaldwin/65cc10ea67c92a276ba828637b8c6db9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } from 'net' | |
import { MavLinkPacketSplitter, MavLinkPacketParser, common, minimal, send, MavLinkProtocolV2 } from 'node-mavlink' | |
const REGISTRY = { | |
...minimal.REGISTRY, | |
...common.REGISTRY, | |
}; | |
let port; | |
async function main() { | |
port = connect({ host: ip, port: 31516 }) | |
const reader = port | |
.pipe(new MavLinkPacketSplitter()) | |
.pipe(new MavLinkPacketParser()) | |
//const command = new common.RequestProtocolVersionCommand(); | |
const takeoffCommand = new common.NavTakeoffCommand(1, 1); | |
takeoffCommand.altitude = 20; | |
const armCommand = new common.ComponentArmDisarmCommand(1, 1); | |
armCommand.arm = 1; | |
// command.confirmation = 1; | |
port.on('connect', () => { | |
console.log('Connected!') | |
// console.log(command); | |
// send(port, command, new MavLinkProtocolV2()); | |
send(port, armCommand, new MavLinkProtocolV2()); | |
}); | |
reader.on('data', (packet) => { | |
const clazz = REGISTRY[packet.header.msgid] | |
if (clazz) { | |
const data = packet.protocol.data(packet.payload, clazz) | |
//console.log('>', data) | |
} else { | |
//console.log('!', packet.debug()) | |
} | |
}); | |
} | |
async function getParams() { | |
const message = new common.ParamRequestList() | |
message.targetSystem = 1 | |
message.targetComponent = 1 | |
await send(port, message, new MavLinkProtocolV1()); | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment