mavlink解码java_mavlink: A Java API for MAVLink communication

2023-05-16

Overview

A Java SDK for communication using the Mavlink1 and Mavlink2 protocols.

Structure

The project is made up of 3 components:

mavlink-protocol

A low-level API which deals with reading and writing packets. It does not have any

knowledge of dialects or about the meaning of messages. It does, however, provide infrastructure

for packet CRC validation as well as packet signing. The required implementation or

session-specific information (such as message CRC extra and signing parameters) have to be

provided, though. If you are after making your own high-level design then this is likely the

choice for you. If you would like to use mavlink-protocol without the rest of the components of

this repository, then you can read mavlink-protocol's README

to learn how.

generator gradle plugin

Used in order to generate dialect-specific sources. The generated sources depend upon the

classes of this root project, and therefore the plugin is unlikely to be of any use as a

stand-alone -- If you are writing your own dialect XML files, then forking this project

is likely what you're after.

mavlink (root project)

A higher level API which provides its users with a complete abstraction from the lower level

protocol. This is likely what you want if you're after making an application that communicates

with Mavlink devices.

Get it

Maven Central coordinates are io.dronefleet.mavlink:mavlink:1.1.8

Examples

Brief

This is a brief example for the minimum required to communicate using Mavlink1 with the

default dialects.

// Reading

MavlinkConnection connection = MavlinkConnection.create(in, out); // InputStream, OutputStream

MavlinkMessage message;

while ((message = connection.next()) != null) {

// ...

}

// Writing

connection.send1(

255, /* systemId */

0, /* componentId */

Heartbeat.builder()

.type(MavType.MAV_TYPE_GCS)

.autopilot(MavAutopilot.MAV_AUTOPILOT_INVALID)

.systemStatus(MavState.MAV_STATE_UNINIT)

.mavlinkVersion(3)

.build()));

Reading & disambiguating messages

This is a detailed example of how to use the API to read and write messages.

// This example uses a TCP socket, however we may also use a UDP socket by injecting

// PipedInputStream/PipedOutputStream to MavlinkConnection, or even USB by using any

// implementation that will eventually yield an InputStream and an OutputStream.

try (Socket socket = new Socket("127.0.0.1", 5760)) {

// After establishing a connection, we proceed to building a MavlinkConnection instance.

MavlinkConnection connection = MavlinkConnection.create(

socket.getInputStream(),

socket.getOutputStream());

// Now we are ready to read and send messages.

MavlinkMessage message;

while ((message = connection.next()) != null) {

// The received message could be either a Mavlink1 message, or a Mavlink2 message.

// To check if the message is a Mavlink2 message, we could do the following:

if (message instanceof Mavlink2Message) {

// This is a Mavlink2 message.

Mavlink2Message message2 = (Mavlink2Message)message;

if (message2.isSigned()) {

// This is a signed message. Let's validate its signature.

if (message2.validateSignature(mySecretKey)) {

// Signature is valid.

} else {

// Signature validation failed. This message is suspicious and

// should not be handled. Perhaps we should log this incident.

}

} else {

// This is an unsigned message.

}

} else {

// This is a Mavlink1 message.

}

// When a message is received, its payload type isn't statically available.

// We can resolve which kind of message it is by its payload, like so:

if (message.getPayload() instanceof Heartbeat) {

// This is a heartbeat message

MavlinkMessage heartbeatMessage = (MavlinkMessage)message;

}

// We are better off by publishing the payload to a pub/sub mechanism such

// as RxJava, JMS or any other favorite instead, though.

}

} catch (EOFException eof) {

// The stream has ended.

}

Writing Mavlink 2 messages

int systemId = 255;

int componentId = 0;

Heartbeat heartbeat = Heartbeat.builder()

.type(MavType.MAV_TYPE_GCS)

.autopilot(MavAutopilot.MAV_AUTOPILOT_INVALID)

.systemStatus(MavState.MAV_STATE_UNINIT)

.mavlinkVersion(3)

.build()

// Write an unsigned heartbeat

connection.send2(systemId, componentId, heartbeat);

// Write a signed heartbeat

int linkId = 1;

long timestamp = /* provide microsecond time */;

byte[] secretKey = MessageDigest.getInstance("SHA-256")

.digest("a secret phrase".getBytes(StandardCharsets.UTF_8))

connection.send2(systemId, componentId, heartbeat, linkId, timestamp, secretKey);

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

mavlink解码java_mavlink: A Java API for MAVLink communication 的相关文章

  • NIO 直接缓冲区何时以及如何被释放?

    我有一个 C 库 需要一个临时缓冲区作为暂存空间 我正在考虑将直接字节缓冲区的地址传递给它 在最终释放缓冲区之前 是否允许虚拟机重新定位缓冲区 JNI 框架消失后 本机库将保留该指针 我的理解是 JNI 本地对象引用无法缓存 因为 VM 可
  • JTree ConvertValueToText 返回在更改时被截断

    我有一个自定义树实现convertValueToText 此实现取决于某些全局状态 如果返回的字符串比先前返回的字符串更长 实际上我认为更宽 因为以像素为单位触发它 则文本将被截断并用 填充 当重绘是由 取消 选择元素或某个元素引起时 情况
  • Eclipse Oxygen - 该项目未构建,因为其构建路径不完整

    我刚刚安装了 Eclipse Oxygen 并尝试在工作台中打开现有项目 但收到此错误 该项目未构建 因为其构建路径不完整 不能 找到 java lang Object 的类文件 修复构建路径然后尝试 建设这个项目 我尝试右键单击该项目 转
  • 合并和颜色样式不适用于 Apache POI excel 2003 格式

    在 Apache POI 中 我为某些单元格应用了一些样式并合并了这些单元格 当我在 2010 年或 2007 年打开时 它工作正常 但在 2003 年 格式样式消失了 每次保存 2003 Excel 文件之前都会弹出兼容性检查对话框 请参
  • 我可以使用 Selenium Webdriver 测试元素的顺序吗?

    有一个表单 其中有 3 个字段 具有 3 个不同的 ID fieldset div div fieldset
  • 如何在 Google 知识图谱中搜索具有特定属性的条目?

    应如何制定搜索查询kgsearch googleapis com查找给定类别中的所有条目 例如 如果我想搜索 Schema org 类别中的内容应用类别 http schema org applicationCategory 我该怎么办呢
  • 如何在 QueryDSL 中选择文字

    我目前正在开发一个使用 queryDSL 和 hibernate 的项目 其中它需要一个选择文字 按照发布的示例here https stackoverflow com questions 18691317 querydsl how to
  • java.lang.ClassNotFoundException: org.jboss.logging.Logger

    我有一个奇怪的问题 我有一个JMS https en wiktionary org wiki JMS客户端应用程序和MDB https en wikipedia org wiki Enterprise JavaBeans Message d
  • 不使用 length() 方法的字符串长度[关闭]

    Closed 这个问题需要细节或清晰度 help closed questions 目前不接受答案 如何在不使用字符串的情况下找到字符串的长度length String类的方法 str toCharArray length应该管用 或者怎么
  • IntelliJ - 无效源版本:17

    我已经在 IntelliJ 中使用 Gradle 创建了一个使用 Java 17 的新 Java 项目 运行我的应用程序时出现错误Cause error invalid source release 17 我的设置 我已经安装了openjd
  • 在 Apache Servicemix 4 中的 OSGi 包之间共享配置文件?

    有人能够在 SMX4 中的两个或多个捆绑包之间成功共享配置吗 我正在寻找的是这样的 有一个文件 SMX HOME etc myconfiguration cfg 使此配置 可用 以便使用 Spring dm 通过 OSGi 配置管理将其注入
  • Java DNSLookup MX 记录列表。类似于 MXToolBox

    我正在构建一个程序来列出域的所有 MX 记录 起初似乎工作正常 但与在线工具进行比较后http mxtoolbox com http mxtoolbox com 有些域程序无法获取 MX 记录 而 MXToolbox 可以 我不确定原因是什
  • gwt 文本框添加更改处理程序

    我有一个从设计师那里收到的文本框 但是我在 GWT 中编写了操作 问题是文本框为空 但是当通过按下按钮用值填充文本框时 将显示警报框 通知值已更改 但没有成功 帮助我 TextBox zip1 null function onModuleL
  • 短 2 个字节

    我正在从串行端口读取一个长度为 133 字节的数据包 最后 2 个字节包含 CRC 值 我使用 Java 将 2 个字节值制成单个 我认为很短 这就是我所做的 short high 48 0x00ff short low 80 short
  • 没有运算符与给定名称和参数类型匹配。您可能需要添加显式类型转换。 -- Netbeans、Postgresql 8.4 和 Glassfish

    我正在尝试使用 EclipseLink 在 Glassfish 中使用 JPA 编辑 Postgresql 中的表 当我插入一个实体时 它运行良好 但是 当我尝试编辑或删除同一实体时 它失败并出现以下错误 任何想法 Caused by Ex
  • 将其元素添加到另一个列表后清除列表

    我正在做一个程序 它获取更多句子作为参数 我制作了 2 个列表 一个称为 propozitie 其中包含每个句子 另一个称为 propozitii 其中包含所有句子 问题是 当我在遇到 后清除 propozitie 列表时 它也会清除 pr
  • Java ByteBuffer 性能问题

    在处理多个千兆字节文件时 我注意到一些奇怪的事情 似乎使用文件通道从文件读取到使用 allocateDirect 分配的重用 ByteBuffer 对象比从 MappedByteBuffer 读取要慢得多 事实上它甚至比读取到字节还要慢使用
  • 如何以最短的等待时间加速 Java Selenium 脚本

    我目前正在开发一个 java selenium 项目 这通常是一个小脚本 我必须在其中检查每个元素是否存在 并基于触发一些操作 但我们主要关心的是完成脚本的持续时间 基本上 我在脚本中使用了下面的每一个并运行了测试 尽管在每种情况下脚本都在
  • Spring Bean 属性“xxx”不可写或具有无效的 setter 方法

    我是一个 Spring 新手 有一个看似简单的 Spring 问题 我为此工作了几个小时 但没有运气 这是例外情况 后面是代码 提前感谢您 Exception in thread main org springframework beans
  • 事件日志解析器的适当设计模式?

    处理一个解析事件日志的项目 然后根据这些事件的属性更新模型 我一直很懒于 完成它 而更关心前期优化 精益代码和正确的设计模式 主要是自学实验 我感兴趣的是更有经验的设计师认为哪些模式是相关的 或者哪种类型的伪代码对象架构是最好的 最容易维护

随机推荐