Giter Club home page Giter Club logo

go-mavlink's Introduction

go-mavlink

a Go package for reading/writing mavlink messages.

Build Status GoDoc

still under development, not necessarily ready for production use

installation

  • grab the files: go get github.com/liamstask/go-mavlink
  • generate classes from mavlink xml definitions: go generate

xml definitions can be updated from https://github.com/mavlink/mavlink

usage

package go-mavlink/mavgen is used only for generating classes from mavlink xml definitions, it is not generally intended to be used by anything other than the go generate command.

package go-mavlink/mavlink is the main package used for encoding/decoding mavlink messages.

mavlink.Packet is the struct that gets sent over the wire, and mavlink.Message is an interface implemented by all mavlink classes generated by mavgen.

dialects

Several mavlink dialects define messages for overlapping msg ids, so it is required to specify which dialects you'd like to use. DialectCommon is included by most of the available dialects, so is included by default.

dec := mavlink.NewDecoder(rdr)
dec.Dialects.Add(DialectArdupilotmega)

Existing dialects are:

  • DialectArdupilotmega
  • DialectAsluav
  • DialectCommon (added to Encoders/Decoders by default, can be removed if desired)
  • DialectMatrixpilot
  • DialectPixhawk
  • DialectUalberta

decode

a typical decode loop might look like:

rdr := SomeIoReader() // any io.Reader: UDP, serial port, bytes.Buffer, etc
dec := mavlink.NewDecoder(rdr)

for {
    pkt, err := dec.Decode()
    if err != nil {
        log.Fatal("Decode fail:", err)
    }

    // handle packet types you're interested in...
    switch pkt.MsgID {
    case mavlink.MSG_ID_PARAM_VALUE:
        var pv mavlink.ParamValue
        if err := pv.Unpack(pkt); err == nil {
            // handle param value
        }
    }
}

encode

the most convenient way to encode is to use Encoder.Encode():

w := SomeIoWriter() // any io.Writer: UDP, serial port, bytes.Buffer, etc
enc := mavlink.NewEncoder(w)

p := mavlink.Ping{
    Seq: 12345,
}

if err := enc.Encode(0x1, 0x1, &p); err != nil {
    log.Fatal("Encode fail:", err)
}

if for some reason you need to pass a Packet directly, use Encoder.EncodePacket():

p := mavlink.Ping{
    Seq: c.seq,
}

var pkt Packet
if err := p.Pack(&pkt); err != nil {
    log.Fatal("Pack fail:", err)
}

if err := enc.EncodePacket(&pkt); err != nil {
    log.Fatal("Encode fail:", err)
}

go-mavlink's People

Contributors

liamstask avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.