Code Monkey home page Code Monkey logo

mavlinkjava's Introduction

MAVLink Java generator and library

This project has been moved from: http://code.google.com/p/mavlinkjava

The goal of this project is to generate a Java Library from [http://www.qgroundcontrol.org/mavlink/ MAVLink] xml files for embedded Java (Android or not) and Java ground stations. It works with MAVLink 0.9 or 1.0 xml files.

It is architectured with 4 Eclipse Java projects:

  • org.mavlink.generator : contains the generator and MAVLink xml files. Generated code is put in org.mavlink.library/generated folder.
  • org.mavlink.library : Helpers for MAVLink and message. Contains generated code from generator.
  • org.mavlink.util : CRC classes uses by generator and library.
  • org.mavlink.maven : parent pom for the project

Generator usage

Put desired mavlink xml files in a directory. Don't forget include files. By example for ardupilotmega generation put ardupilotmega.xml and common.xml in a directory.

Then generate code in directory "generated" in org.mavlink.library Eclipse project.

So build org.mavlink.library and org.mavlink.util Eclipse project and generate jar with each jardesc in projects.

Now you can use the 2 generated jar in your projects!

Command line arguments of MAVLink Java generator are :

  • source : xml file or directory path containing xml files to parse for generation
  • target : directory path for output Java source files
  • isLittleEndian : true if type are exchanged or stored in LittleEndian in buffer, false for BigEndian
  • forEmbeddedJava : true if generated code must use apis for embedded code (CLDC), false else for ground station
  • useExtraByte : if true use extra crc byte to compute CRC : true for MAVLink 1.0, false for 0.9
  • debug : true to generate toString methods in each message class

Example

java org.mavlink.generator.MAVLinkGenerator resources/v1.0 target/ true true true true
java org.mavlink.generator.MAVLinkGenerator resources/v1.0/ardupilotmega.xml target/ true true true true

Generate MAVLink message Java classes for mavlink xml files contains in resources/v1.0 in target diretory for Little Endian data, embedded code with debug code.

Integration in MAVLinl distribution

  • Copy the 4 projects in a directory
  • Go in org.mavlink.generator and run makedistrib.sh (Linux) or makedistrib.bat (Windows)
    • A distrib directory is generated at the same level as the 3 projects
  • Copy the directory distrib/Java in the mavlink distribution : .../mavlink/pymavlink/generator
  • Go in .../mavlink/pymavlink/generator/Java

So users must run gen_java.bat (Windows) or gen_java.sh (Linux) to generate jar files. All lib are generated in lib directory. Users must choose lib/org.mavlink.util-1.00.jar and one of the org.mavlink.library-xxx.jar generated to work.

Library usage :

Use MAVLinkReader to read messages with method MAVLinkMessage getNextMessage(). It's return a message if available else null.

MAVLinkReader reader = new MAVLinkReader(dis, IMAVLinkMessage.MAVPROT_PACKET_START_V10);
MAVLinkMessage msg;
while (true) {
    msg = reader.getNextMessage();
    if (msg != null) {
        // Do your stuff
        ...
    }
}

You can use also getNextMessageWithoutBlocking() : If bytes available, try to read it. Don't wait message is completed, it will be retruned nex time.

Use encode() method on MAVLink message to generate a byte buffer so you can send it in a Data Output Stream.

msg_heartbeat hb = new msg_heartbeat(sysId, componentId);
hb.sequence = sequence++;
hb.autopilot = MAV_AUTOPILOT.MAV_AUTOPILOT_PX4;
hb.base_mode = MAV_MODE_FLAG.MAV_MODE_FLAG_STABILIZE_ENABLED;
hb.custom_mode = custom_mode;
hb.mavlink_version = 3;
hb.system_status = MAV_STATE.MAV_STATE_POWEROFF;
byte[] result = hb.encode();
dos.put(result);

Don't hesitate to send me your issues or requests! :-)

Have fun with that!

Note

Actually 2 projects are using this code for Android :

[http://www.diydrones.com/forum/topics/andropilot-alpha-tester-discussion-for-this-android-application?id=705844 AndroPilot] Thank's to Kevin Hester to his remarks and issues!

[http://www.autoquad.org Autoquad] Thank's to Peter Hafner for his choice! :-)

mavlinkjava's People

Contributors

ghelle avatar tribbloid avatar yuripourre 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.