原文http://uavcan.org/Specification/3._Data_structure_description_language/

DSDL:Data structure description language

实际上,就是自动生成的C++格式的数据结构。用来定义UAVCAN中的各种类型的消息。个人认为就是看着更清晰,理解起来更容易,也是UAVCAN的设计思想。使用C代码也很容易实现

C代码例子https://github.com/zwx230741/libcanard

结构定义

[default data type ID.]<data type name>.uavcan
+ uavcan                        <-- Root namespace
+ equipment <-- Nested namespace
+ ...
+ protocol <-- Nested namespace
+ 341.NodeStatus.uavcan <-- Definition of data type "uavcan.protocol.NodeStatus" with
default data type ID 341
+ ...
+ Timestamp.uavcan <-- Definition of data type "uavcan.Timestamp", default data
type ID is not assigned

DSDL中定义的都是标准的数据类型,也是默认的数据类型,不需要更改

可用的数据类型ID是有限的

DSDL发布消息

具体源码可以参考UAVCAN源码

DSDL通过Publisher来发布消息,当你需要发送数据到can设备时使用

uavcan::equipment::esc::RawCommand msg;
uavcan::Publisher<uavcan::equipment::esc::RawCommand> _uavcan_pub_raw_cmd;
(void)_uavcan_pub_raw_cmd.broadcast(msg); //广播消息

DSDL订阅消息

DSDL通过Subscriber来订阅消息,当你需要接收can设备数据到时使用

typedef uavcan::MethodBinder<UavcanEscController*,
void (UavcanEscController::*)(const uavcan::ReceivedDataStructure<uavcan::equipment::esc::Status>&)>
StatusCbBinder;
uavcan::Subscriber<uavcan::equipment::esc::Status, StatusCbBinder> _uavcan_sub_status; int res = _uavcan_sub_status.start(StatusCbBinder(this, &UavcanEscController::esc_status_sub_cb));
if (res < 0)
{
warnx("ESC status sub failed %i", res);
return res;
} void UavcanEscController::esc_status_sub_cb(const uavcan::ReceivedDataStructure<uavcan::equipment::esc::Status> &msg)
{
;
}

数据结构举例

#
# Abstract node status information.
#
# Any UAVCAN node is required to publish this message periodically.
# #
# Publication period may vary within these limits.
# It is NOT recommended to change it at run time.
#
uint16 MAX_BROADCASTING_PERIOD_MS = 1000
uint16 MIN_BROADCASTING_PERIOD_MS = 2 #
# If a node fails to publish this message in this amount of time, it should be considered offline.
#
uint16 OFFLINE_TIMEOUT_MS = 3000 #
# Uptime counter should never overflow.
# Other nodes may detect that a remote node has restarted when this value goes backwards.
#
uint32 uptime_sec #
# Abstract node health.
#
uint2 HEALTH_OK = 0 # The node is functioning properly.
uint2 HEALTH_WARNING = 1 # A critical parameter went out of range or the node
encountered a minor failure.
uint2 HEALTH_ERROR = 2 # The node encountered a major failure.
uint2 HEALTH_CRITICAL = 3 # The node suffered a fatal malfunction.
uint2 health #
# Current mode.
#
# Mode OFFLINE can be actually reported by the node to explicitly inform other network
# participants that the sending node is about to shutdown. In this case other nodes will not
# have to wait OFFLINE_TIMEOUT_MS before they detect that the node is no longer available.
#
# Reserved values can be used in future revisions of the specification.
#
uint3 MODE_OPERATIONAL = 0 # Node is performing its main functions.
uint3 MODE_INITIALIZATION = 1 # Node is initializing; this mode is entered
immediately after startup.
uint3 MODE_MAINTENANCE = 2 # Node is under maintenance.
uint3 MODE_SOFTWARE_UPDATE = 3 # Node is in the process of updating its software.
uint3 MODE_OFFLINE = 7 # Node is no longer available.
uint3 mode #
# Not used currently, keep zero when publishing, ignore when receiving.
#
uint3 sub_mode #
# Optional, vendor-specific node status code, e.g. a fault code or a status bitmask.
#
uint16 vendor_specific_status_code

结构体中的属性值:

默认值:不可以修改,也不参与网络交互

变量:可以通过应用程序修改,参与网络收发

uint8[<=64] payload

UAVCAN支持不定长数组,使用起来很方便。但是要注意,DSDL订阅消息的时候,默认第一个字节表示数组的长度

服务响应标记:

该标记由三个减号组成

---

C方式发送消息

等价于DSDL发布消息

/*
封包数据,根据数据类型
void canardEncodeScalar(void *destination,
uint32_t bit_offset,
uint8_t bit_length, //bit长度
const void *value)
*/
canardEncodeScalar(buffer, 0, 28, &uptime_sec); /*
发送消息,加入到发送队列
int canardBroadcast(CanardInstance *ins,
uint64_t data_type_signature,
uint16_t data_type_id,
uint8_t *inout_transfer_id,
uint8_t priority,
const void *payload,
uint16_t payload_len)
*/
canardBroadcast(&canard, UAVCAN_NODE_STATUS_DATA_TYPE_SIGNATURE,
UAVCAN_NODE_STATUS_DATA_TYPE_ID, &transfer_id, CANARD_TRANSFER_PRIORITY_LOW,
buffer, UAVCAN_NODE_STATUS_MESSAGE_SIZE);

C方式接收消息

等价于DSDL订阅消息

/*
从接收到的数据包中,解析出数据
int canardDecodeScalar(const CanardRxTransfer *transfer,
uint32_t bit_offset,
uint8_t bit_length,
bool value_is_signed,
void *out_value)
*/
canardDecodeScalar(transfer, 0, 28, false, &uptime_sec[i]);

UAVCAN DSDL介绍的更多相关文章

  1. uavcan扩展帧格式 zubax

    zubax_gnss_1.0和zubax_gnss_2.0中使用的uavcan的两种不同封装方式.都是采用扩展帧29b帧类型 zubax_gnss_1.0 我的代码:https://github.co ...

  2. CSS3 background-image背景图片相关介绍

    这里将会介绍如何通过background-image设置背景图片,以及背景图片的平铺.拉伸.偏移.设置大小等操作. 1. 背景图片样式分类 CSS中设置元素背景图片及其背景图片样式的属性主要以下几个: ...

  3. MySQL高级知识- MySQL的架构介绍

    [TOC] 1.MySQL 简介 概述 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司. MySQL是一种关联数据库管理系统,将数据保存在不同的表中,而 ...

  4. Windows Server 2012 NIC Teaming介绍及注意事项

    Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...

  5. Linux下服务器端开发流程及相关工具介绍(C++)

    去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ...

  6. JavaScript var关键字、变量的状态、异常处理、命名规范等介绍

    本篇主要介绍var关键字.变量的undefined和null状态.异常处理.命名规范. 目录 1. var 关键字:介绍var关键字的使用. 2. 变量的状态:介绍变量的未定义.已定义未赋值.已定义已 ...

  7. HTML DOM 介绍

    本篇主要介绍DOM内容.DOM 节点.节点属性以及获取HTML元素的方法. 目录 1. 介绍 DOM:介绍DOM,以及对DOM分类和功能的说明. 2. DOM 节点:介绍DOM节点分类和节点层次. 3 ...

  8. HTML 事件(一) 事件的介绍

    本篇主要介绍HTML中的事件知识:事件相关术语.DOM事件规范.事件对象. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三 ...

  9. HTML5 介绍

    本篇主要介绍HTML5规范的内容和页面上的架构变动. 目录 1. HTML5介绍 1.1 介绍 1.2 内容 1.3 浏览器支持情况 2. 创建HTML5页面 2.1 <!DOCTYPE> ...

随机推荐

  1. zz 勵志貼,成功是努力加对的方向

    5-6年工作经验程序员初进大厂,如何适应工作? 李苦李 李苦李 ​ 华为 架构师 318 人赞同了该回答 泻药! 与题主背景非常相似. 本人毕业8年+,普通二本,学历不突出,非计算机专业. 唯一不同的 ...

  2. [转]import xxx from 和 import {xxx} from的区别

    原文地址:https://www.cnblogs.com/Abner5/p/7256043.html 1.vue import FunName from ‘../xxx’ 1.js export de ...

  3. centos7.6使用 supervisor 对filebeat7.3.1进程进行管理

    centos7.6使用 supervisor 对filebeat7.3.1进程进行管理 Supervisor 是一个 Python 开发的 client/server 系统,可以管理和监控类 UNIX ...

  4. 第一节:Python+Selenium环境搭建

    一.selenium工作原理 二.安装python Window系统下,python的安装很简单.访问python.org/download,下载最新版本,安装过程与其他windows软件类似.记得下 ...

  5. ARM 链接脚本分析

    分析连接脚本的语法规则 /* ---------------------------------------------------------------------------- * Memory ...

  6. C++内存管理2-内存泄漏

    1 C++中动态内存分配引发问题的解决方案 假设我们要开发一个String类,它可以方便地处理字符串数据.我们可以在类中声明一个数组,考虑到有时候字符串极长,我们可以把数组大小设为200,但一般的情况 ...

  7. Java之数组类型

    如果我们有一组类型相同的变量.例如,5位同学的成绩,可以这么写 public class Main { public static void main(String[] args) { // 5位同学 ...

  8. SpringBoot小技巧:Jar包换War包

    SpringBoot小技巧:Jar包换War包 情景 我们都知道springBoot中已经内置了tomcat,是不需要我们额外的配置tomcat服务器的,但是有时这也可能是我们的一个瓶颈,因为如果我们 ...

  9. PHP ob_gzhandler的理解

    PHP ob_gzhandler的理解那么对于我们这些没有开启mod_deflate模块的主机来说,就只能采用ob_gzhandler函数来压缩了,它的压缩效果和mod_deflate相比,相差很小, ...

  10. scrollview的优化

    针对一次加载很多格子的scrollview的优化,第一次只加载可视区域的格子,其他的用空物体占位,在每次滑动时检测需要实例化的格子,通过对象池重用第一次的格子.可以根据每行格子的数量只检测每行的第一个 ...