Dart MAVLink Library
Overview
dart_mavlink is a MAVLink message processing package written in dart, making it easy to parse and serialize MAVLink v1 and v2 packets. The package supports several MAVLink dialects.
https://github.com/nus/dart_mavlink
Installation
Installing the package requires adding dart_mavlink as a Git submodule, as dart_mavlink is not on the official package repository for Dart and Flutter: https://pub.dev/
Create a Dart application to use the package in:
a. Install Git and Dart if you haven’t already: https://dart.dev/get-dart
b. Create a new Dart application and navigate to directory:dart create project_name
cd project_name
Setup dart_mavlink as a Git submodule:
a. Initialize a new Git repository in the application folder:git init
b. Add dart_mavlink as a submodule:git submodule add https://github.com/nus/dart_mavlink.git
c. Initialize and update submodules recursively:git submodule update --init --recursive
Add dart_mavlink to Dart dependencies:
a. Add the path as a dependency in the pubspec.yaml file under dependencies:# Add regular dependencies here. dependencies: dart_mavlink: path: ./dart_mavlink
b. Mark package as not for publishing in the pubspec.yaml file:
c. Get dependencies by running:dart pub get
At this point, you may create a GitHub repository at any time and follow the instructions for pushing an existing repository.
Usage
Creating and serializing messages
The dart_mavlink library contains dart files within the dialects folder which implement various MAVLink message sets as classes in Dart. This is done in PascalCase. For example, to create a SYSTEM_TIME message, one can use the SystemTime class, with messages parameters passed as arguments to the class.
These files also contain MAVLink type enums for use in setting the parameters of messages, which is done in camelCase. For example, in the HEARTBEAT message, the system_status argument of the Heartbeat class is a value of type enum MAV_STATE. For a system in state MAV_STATE_ACTIVE, mavStateActive can be passed as a argument to the Heartbeat class.
Here is an example of creating and serializing a Heartbeat message.
import 'package:dart_mavlink/mavlink.dart';
import 'package:dart_mavlink/dialects/common.dart';
var dialect = MavlinkDialectCommon();
var sequence = 0;
var systemId = 255;
var componentId = 1;
var heartbeat = Heartbeat(
customMode: mavTypeGeneric,
type: mavTypeGeneric,
autopilot: mavAutopilotInvalid,
baseMode: mavModeFlagManualInputEnabled,
systemStatus: mavStateActive,
mavlinkVersion: MavlinkDialectCommon.mavlinkVersion);
var frm = MavlinkFrame.v2(sequence, systemId, componentId, heartbeat);
var serialized = frm.serialize();
Parsing messages
Â