mavlink协议移植问题

mavlink源代码是一个代码库,使用的时候只需要将mavlink.h头文件包含到工程项目中即可。

mavlink通信协议是无状态的连接,一般采用心跳消息跟踪系统是否存在。请确保每60、30、10或1秒发送心跳(建议使用1HZ),一旦心跳到达则视为系统已经连接。

快速整合方法: 发送数据例程(这个例子需要的代码比较多)

/* The default UART header for your MCU */
#include "uart.h"
#include <mavlink/v1./common/mavlink.h> mavlink_system_t mavlink_system; mavlink_system.sysid = ; ///< ID 20 for this airplane
mavlink_system.compid = MAV_COMP_ID_IMU; ///< The component sending the message is the IMU, it could be also a Linux process // Define the system type, in this case an airplane
uint8_t system_type = MAV_TYPE_FIXED_WING;
uint8_t autopilot_type = MAV_AUTOPILOT_GENERIC; uint8_t system_mode = MAV_MODE_PREFLIGHT; ///< Booting up
uint32_t custom_mode = 0; ///< Custom mode, can be defined by user/adopter
uint8_t system_state = MAV_STATE_STANDBY; ///< System ready for flight // Initialize the required buffers
mavlink_message_t msg;
uint8_t buf[MAVLINK_MAX_PACKET_LEN]; // Pack the message
mavlink_msg_heartbeat_pack(mavlink_system.sysid, mavlink_system.compid, &msg, system_type, autopilot_type, system_mode, custom_mode, system_state); // Copy the message to the send buffer
uint16_t len = mavlink_msg_to_send_buffer(buf, &msg); // Send the message with the standard UART send function
// uart0_send might be named differently depending on
// the individual microcontroller / library in use.
uart0_send(buf, len);

接收数据例程:此段代码运行效率比较低,所以建议在主循环中运行该函数,并且尽快清空USART缓冲区。

#include <mavlink/v1./common/mavlink.h>

// Example variable, by declaring them static they're persistent
// and will thus track the system state
static int packet_drops = ;
static int mode = MAV_MODE_UNINIT; /* Defined in mavlink_types.h, which is included by mavlink.h */ /**
* @brief Receive communication packets and handle them
*
* This function decodes packets on the protocol level and also handles
* their value by calling the appropriate functions.
*/
static void communication_receive(void)
{
mavlink_message_t msg;
mavlink_status_t status; // COMMUNICATION THROUGH EXTERNAL UART PORT (XBee serial) while(uart0_char_available())
{
uint8_t c = uart0_get_char();
// Try to get a new message
if(mavlink_parse_char(MAVLINK_COMM_0, c, &msg, &status)) {
// Handle message switch(msg.msgid)
{
case MAVLINK_MSG_ID_HEARTBEAT:
{
// E.g. read GCS heartbeat and go into
// comm lost mode if timer times out
}
break;
case MAVLINK_MSG_ID_COMMAND_LONG:
// EXECUTE ACTION
break;
default:
//Do nothing
break;
}
} // And get the next one
} // Update global packet drops counter
packet_drops += status.packet_rx_drop_count;
} 利用适配器函数减少代码 #include "your_mavlink_bridge_header.h"
/* You have to #define MAVLINK_USE_CONVENIENCE_FUNCTIONS in your_mavlink_bridge_header,
and you have to declare: mavlink_system_t mavlink_system;
these two variables will be used internally by the mavlink_msg_xx_send() functions.
Please see the section below for an example of such a bridge header. */
#include <mavlink.h> // Define the system type, in this case an airplane
int system_type = MAV_FIXED_WING;
// Send a heartbeat over UART0 including the system type
mavlink_msg_heartbeat_send(MAVLINK_COMM_0, system_type, MAV_AUTOPILOT_GENERIC, MAV_MODE_MANUAL_DISARMED, MAV_STATE_STANDBY); your_mavlink_bridge_header.h
/* MAVLink adapter header */
#ifndef YOUR_MAVLINK_BRIDGE_HEADER_H
#define YOUR_MAVLINK_BRIDGE_HEADER_H #define MAVLINK_USE_CONVENIENCE_FUNCTIONS #include <mavlink/v1./mavlink_types.h> /* Struct that stores the communication settings of this system.
you can also define / alter these settings elsewhere, as long
as they're included BEFORE mavlink.h.
So you can set the mavlink_system.sysid = 100; // System ID, 1-255
mavlink_system.compid = 50; // Component/Subsystem ID, 1-255 Lines also in your main.c, e.g. by reading these parameter from EEPROM.
*/
mavlink_system_t mavlink_system;
mavlink_system.sysid = ; // System ID, 1-255
mavlink_system.compid = ; // Component/Subsystem ID, 1-255 /**
* @brief Send one char (uint8_t) over a comm channel
*
* @param chan MAVLink channel to use, usually MAVLINK_COMM_0 = UART0
* @param ch Character to send
*/
static inline void comm_send_ch(mavlink_channel_t chan, uint8_t ch)
{
if (chan == MAVLINK_COMM_0)
{
uart0_transmit(ch);
}
if (chan == MAVLINK_COMM_1)
{
uart1_transmit(ch);
}
} #endif /* YOUR_MAVLINK_BRIDGE_HEADER_H */

mavlink协议移植问题的更多相关文章

  1. Mavlink协议理解

    来源:blog.csdn.net/super_mice/article/details/44836585 之前看了mavlink协议,网上关于mavlink的资料不多.本文大概总结了下对mavlink ...

  2. Mavlink 协议 理解

    来源:blog.csdn.net/super_mice/article/details/44836585 之前看了mavlink协议,网上关于mavlink的资料不多.本文大概总结了下对mavlink ...

  3. 移植mavlink协议到STM32详细教程

    1准备材料, 首先准备一个带串口的stm32程序(这里选用整点原子的官方串口例程这里自己去找不讲)作者:恒久力行 QQ:624668529,然后去mavlink官网下载mavlink源码,这里重点讲解 ...

  4. MAVLINK协议

    参考https://cloud.tencent.com/developer/news/48344 https://www.cnblogs.com/lovechen/p/5801679.html htt ...

  5. GPSR协议移植

    修改的文件有packet.h.cmu-trace.cc.priqueue.cc.ns-packet.tcl.Makefile 1.在 $HOME/ns-allinone-2.29/ns-2.29下新建 ...

  6. Python脚本通过ftp协议移植文件

    需求 项目需要定时移植多个客户服务器的文件到公司服务器上,确保文件定时同步和生成监控日志 机制原理 1.客户和公司服务器同时安装vpn,绕过复杂的网关,linux下使用的OpenVPN 2.服务器定时 ...

  7. MAVLink功能开发,移植教程。

    MAVLink功能开发 -----------------本文由"智御电子"提供,同时提供视频移植教程,以便电子爱好者交流学习.---------------- 1.MAVLink ...

  8. Mavlink - 无人机通讯协议

    http://qgroundcontrol.org/mavlink/start mavlink协议介绍https://pixhawk.ethz.ch/mavlink/ 消息简介 MAVLink简介 M ...

  9. Mavlink地面站编写之二--Mission Planner编译

    软件下载:        本文使用VS2013进行编译和改动Mission Planner,其它版本号没有尝试过. 首先下载Mission Planner源码. https://github.com/ ...

随机推荐

  1. APM监控工具Pinpoint搭建

    一:Pinpoint简介与架构图示 Pinpoint是什么Pinpoint是开源在github上的一款使用JAVA语言编写的APM监控工具,用于大规模分布式系统监控.它对性能的影响较小,只增加约3%的 ...

  2. 移动端overflow失效问题

    在项目开发中,我们有时候需要实现元素从屏幕外移动到屏幕内的效果. 我们一般会有这样的方案:先通过position: absolution或transform: translate() 使得元素移动到屏 ...

  3. SPA中前端路由基本原理与实现方式

    SPA 前端路由原理与实现方式 通常 SPA 中前端路由有2中实现方式,本文会简单快速总结这两种方法及其实现: 修改 url 中 Hash 利用 H5 中的 history Hash 我们都知道 ur ...

  4. Python正则表达式语法

    单个字符匹配 字符 匹配 . 匹配任意字符(除了\n) [...] 匹配字符集 \d/\D 匹配数字/非数字 \s/\S 匹配空白/非空白字符 \w/\W 匹配单词字符[a-zA-A0-9] In [ ...

  5. 讨论一下.NET里,对cookie身份验证的超时的处理

    引言 在.NET里提供了FormsAuthentication类用来对用户身份进行验证和授权.不过,对于cookie的超时处理,一直是一个头疼的问题.这里介绍一下微软对.NET 身份验证超时的处理机制 ...

  6. day06可变与不可变类型,if判断,运算符

    1:可变不可变类型 2.什么是条件?什么可以当做条件?为何要要用条件? 显式布尔值:True.False 隐式布尔值:所有数据类型,其中0.None.空为假 3:逻辑运算符:用来 # not. and ...

  7. arm 添加 samb 文件共享

    编译环境: ubunto 12 arm-linux-gcc 4.3.2 arm linux 4.1.36 开发板 2440 测试上传速度,大文件 github源码 https://github.com ...

  8. 你会无聊到把Administrator用户禁用,并且自己创建的用户搞到消失掉还有Administrator用户被禁吗。。。。。

    2020年3月17日20:07:00 如文章标题哈,就是这么任性,无奈 事件起因:因为要部署项目,并且需要将线上的Oracle数据库导入到本地Oracle数据库中突然发现使用 sqlplus 连接数据 ...

  9. 深入理解“骑士”漏洞 VoltJockey

    先理解一下题目:VoltJockey: Breaching TrustZone by Software-Controlled Voltage Manipulation over Multi-core ...

  10. Java对接百度智能云人脸识别

    ------------------------->这篇文章就是自己做个笔记<------------------------- 首先登录or注册自己的百度智能云管理中心:https:// ...