首页 > 其他分享 >mavlink version

mavlink version

时间:2024-03-10 16:25:41浏览次数:17  
标签:xml version system uint8 mavlink type

mavlink本身提供了一种版本号校验的方式,开源的代码生成器对此做了处理的,在xml把字段类型定义成uint8_t_mavlink_version,生成的时候应该就是直接取xml的version,交互双方可以直接根据此字段校验双方版本。

示例

在官方提供的common.xml文件中,对HEARTBEAT消息做了如下定义

<message id="0" name="HEARTBEAT">
  <description>The heartbeat message shows that a system or component is present and responding. The type and autopilot fields (along with the message component id), allow the receiving system to treat further messages from this system appropriately (e.g. by laying out the user interface based on the autopilot). This microservice is documented at https://mavlink.io/en/services/heartbeat.html</description>
  <field type="uint8_t" name="type" enum="MAV_TYPE">Type of the system (quadrotor, helicopter, etc.). Components use the same type as their associated system.</field>
  <field type="uint8_t" name="autopilot" enum="MAV_AUTOPILOT">Autopilot type / class.</field>
  <field type="uint8_t" name="base_mode" enum="MAV_MODE_FLAG" display="bitmask">System mode bitmap.</field>
  <field type="uint32_t" name="custom_mode">A bitfield for use for autopilot-specific flags</field>
  <field type="uint8_t" name="system_status" enum="MAV_STATE">System status flag.</field>
  <field type="uint8_t_mavlink_version" name="mavlink_version">MAVLink version, not writable by user, gets added by protocol because of magic data type: uint8_t_mavlink_version</field>
</message>

最后一个字段mavlink_version的类型为uint8_t_mavlink_version

查看生成的mavlink_msg_heartbeat.h文件,对heartbeat消息的编码函数如下:

static inline uint16_t mavlink_msg_heartbeat_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
                               mavlink_message_t* msg,
                                   uint8_t type,uint8_t autopilot,uint8_t base_mode,uint32_t custom_mode,uint8_t system_status)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_HEARTBEAT_LEN];
    _mav_put_uint32_t(buf, 0, custom_mode);
    _mav_put_uint8_t(buf, 4, type);
    _mav_put_uint8_t(buf, 5, autopilot);
    _mav_put_uint8_t(buf, 6, base_mode);
    _mav_put_uint8_t(buf, 7, system_status);
    _mav_put_uint8_t(buf, 8, 3);

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_HEARTBEAT_LEN);
#else
    mavlink_heartbeat_t packet;
    packet.custom_mode = custom_mode;
    packet.type = type;
    packet.autopilot = autopilot;
    packet.base_mode = base_mode;
    packet.system_status = system_status;
    packet.mavlink_version = 3;

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_HEARTBEAT_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_HEARTBEAT;
    return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_HEARTBEAT_MIN_LEN, MAVLINK_MSG_ID_HEARTBEAT_LEN, MAVLINK_MSG_ID_HEARTBEAT_CRC);
}

其对字段mavlink_version赋值为常量3,而常量3则是common.xml定义的version标签值

<?xml version="1.0"?>
<mavlink>
  <version>3</version>
  <dialect>0</dialect>
  ...
</mavlink>

生成器对此的实现

mavparse.py中定义了类 MAVField

class MAVField(object):
    def __init__(self, name, type, print_format, xml, description='', enum='', display='', units='', instance=False):
        self.name = name
        ...
        self.omit_arg = False
        self.const_value = None
        ...
        lengths = {
        'float'    : 4,
        'double'   : 8,
        'char'     : 1,
        'int8_t'   : 1,
        'uint8_t'  : 1,
        'uint8_t_mavlink_version'  : 1,
        'int16_t'  : 2,
        'uint16_t' : 2,
        'int32_t'  : 4,
        'uint32_t' : 4,
        'int64_t'  : 8,
        'uint64_t' : 8,
        }

        if type=='uint8_t_mavlink_version':
            type = 'uint8_t'
            self.omit_arg = True
            self.const_value = xml.version
		 ...

在mavgen_c.py中,函数generate_one有如下实现:

def generate_one(basename, xml):
    '''generate headers for one XML file'''
	...
	# cope with uint8_t_mavlink_version
    for m in xml.message:
		...
		for f in m.fields:
				if not f.omit_arg:
					m.arg_fields.append(f)
					f.putname = f.name
				else:
					f.putname = f.const_value

可见,uint8_t_mavlink_version类型即为uint8_t,并且,当为此类型时,putname使用的是const_value,也即xml.version,否则即为name(字段名称)

标签:xml,version,system,uint8,mavlink,type
From: https://www.cnblogs.com/hjx168/p/18064301

相关文章

  • CF1264D2 Beautiful Bracket Sequence (hard version) 题解
    括号深度的本质,其实就是删除若干个字符以后使得左边一半全是(,右边一半全是),最终(的个数的最大值。那么就一定存在一个位置使得在这个位置以及之前的字符中(的个数等于这个字符后)的个数。考虑枚举这个位置,记它左边的(的个数为\(a\)、?的个数为\(x\),右边的)的个数......
  • CF1824B1 LuoTianyi and the Floating Islands (Easy Version) 题解
    分析按照\(k\)的奇偶分开考虑。\(k\)为奇数。一个好的节点有且仅有一个在任意两个有人的节点\(i,j\)的路径的交点上的最优位置。若该交点偏移\(1\)步,则必然会使路径长度和\(+1\)。故期望为\(1\)。\(k\)为偶数。任意一个好的节点仍然在任意两个有人的节点\(i,j\)的......
  • Subversion svn 开源的版本控制系统入门介绍 VCS
    拓展阅读Subversion开源的版本控制系统入门介绍VCSGit开源的版本控制系统-01-入门使用介绍Git开源的版本控制系统-02-baseusage基本用法Git开源的版本控制系统-03-时间数据回溯Git开源的版本控制系统-04-branchmanage分支管理Git开源的版本控制系统-05-tags标签......
  • XOR Break — Game Version
    其实做了两道博弈的交互题后可以知道,博弈的交互题一般是需要你找到一种必胜的策略的,而且这种必胜的策略与非交互题还不同,因为对方可能不是按照最优策略走的,所以我们要找的是在任意一种情况下对面怎么走都能胜的条件,而且要对每一种情况都做出对应的策略(非交互题的话,我们是知道对方......
  • CodeForces 1540D Inverse Inversions
    洛谷传送门CF传送门小清新题。首先容易发现每个合法的\(b\)唯一对应一个排列,大概就是每个时刻排列元素的相对顺序,然后插入到相应的位置。但是这样太麻烦了。发现题目只要求求单点的\(p\)值。这应该有更简单的方法。考虑令\(b_i\getsi-b_i\)表示\(p_i\)在前缀\(......
  • XOR Break — Solo Version
    这道题目就是纯纯的题面搞人心态,看到\(63\)次操作真的很容易想到从高位到低位一位位进行操作。然而正解却不是先来看官解首先每次操作只会将\(n\)变小,所以如果\(m>n\),那么肯定无解;如果\(m=n\)那么不用操作;接下来假定\(m<n\)如果\(m\)最高位\(1\)和\(n\)最高位\(1\)一样,那么直接......
  • 关于SAP-APP机器-R3trans -d报错-R3trans: /lib64/libstdc++.so.6: version `GLIBCXX_
    在SAP-应用-APP-机器上执行如下命令报错awpxxx03:prdadm270>R3trans-dR3trans:/lib64/libstdc++.so.6:version`GLIBCXX_3.4.26'notfound(requiredbyR3trans) 其实之前,使用过一种方法解决这个问题,可以参考笔者另一篇文章《关于Redhat-Linux中-compat-sap-c++的说......
  • Maximum And Queries (hard version)
    首先来介绍一下SOSDP看这篇文章解释一下,最开始的初始化for(inti=0;i<(1<<N);i++)f[i]=w[i];就是0/1背包的的初始化,可以模拟一下想一下为啥然后是DP的过程中,注意f[st^(1<<i)]是肯定不会在这一层被更新的(因为(st^(1<<i))&(1<<i)肯定为\(0\)),所以倒序循环还是正序循环是无所谓的......
  • CF1856E1 PermuTree (easy version) 题解
    假定当前在节点\(u\),它拥有两棵子树\(v,w\),此时\(u\)是\(\operatorname{lca}(v,w)\)。我们一定可以构造出一个排列\(a\),使得所有满足\(i\inv\)的节点\(i\)和满足\(j\inw\)的节点\(j\),有\(a_i<a_u<a_j\)。因此此时点\(u\)对于答案的贡献即为\(size_v\times......
  • Codeforces 1446D1 Frequency Problem (Easy Version)
    考虑求出全局的众数\(A\)。那么有一个结论,就是答案区间的众数中绝对有\(A\)。考虑反证法,如果没有\(A\),\(A\)在序列中出现的个数一定\(\ge\)区间内众数的出现个数,所以可以一直往外扩展直到\(A\)出现的个数与区间内非\(A\)众数的个数持平,这样肯定更优。于是可以考虑钦......