https://github.com/padcom/node-mavlink-heartbeat
https://github.com/padcom/node-mavlink-heartbeat
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/padcom/node-mavlink-heartbeat
- Owner: padcom
- Created: 2023-04-26T00:29:19.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-26T01:08:24.000Z (about 3 years ago)
- Last Synced: 2025-10-10T23:19:15.436Z (8 months ago)
- Language: TypeScript
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Heartbeat scheduler and receiver for node-mavlink
Sending and receiving heartbeats is really a basic thing. It shouldn't have to be written per project.
This is why the `node-mavlink-heartbeat` package has been created. In a simple and effective way it allows the developer to concentrate on what is important and not what is just noise.
## Installation
To install the package issue the following command:
```bash
$ npm install --save node-mavlink-heartbeat
```
## Usage
There are 2 birds that you'll be able to kill with one stone, so to speak. That's because the same instance of `Heartbeat` can serve as both the receiver, sender and scheduler of sending heartbeat packets.
For a comprehensive example please see `examples/simple.ts`
```typescript
const port = new SerialPort({ path: '/dev/ttyACM0', baudRate: 115200 })
const heartbeat = new Heartbeat(port)
heartbeat.on('heartbeat', ({ packet, heartbeat }: HeartbeatData) => {
// do something with the packet
console.log(packet.debug())
// or with the typed heartbeat packet
console.log(heartbeat.baseMode)
})
port
.pipe(new MavLinkPacketSplitter())
.pipe(new MavLinkPacketParser())
.pipe(heartbeat)
.resume()
// Wait for the drone to give us a sign it's alive
// That way we know for sure the connection is ready.
await heartbeat.waitForOne()
// send a single heartbeat
await heartbeat.send()
// start sending heartbeats
heartbeat.start()
// stop sending heartbeats
heartbeat.stop()
```
Happy coding!