UDS问题之DLC的长度一定就是8字节吗

文章讨论了UDS服务中DID请求超时的问题,原因是设备应答过滤掉DLC小于8字节的帧。通过查阅ISO标准,发现DLC长度取决于网络层协议,推荐使用8字节填充或优化至实际数据长度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景:
使用$22服务 DID:0xF193或者其他DID请求数据,最后没有应答,导致请求超时。
TX: 0x710 Len: 4 03 22 F1 93.
若是换成
TX: 0x710 Len: 8 03 22 F1 93 00 00 00 00
RX: 0x720 Len: 8 10 0C 62 F1 93 48 57 2D
RX: 0x710 Len: 8 30 00 00 00 00 00 00 00
RX: 0x720 Len: 8 21 31 20 20 20 20 00 00
就有正常的正确的响应。

问题:
查找代码发现是应答设备,uds协议栈做了过滤把DLC小于8字节的都忽律不处理了,导致请求诊断仪请求超时。

解决:
查找网上资料,有的说uds can固定就是8字节长度,有的没有说。只能去查原始文档了。

ISO14229-1作为uds最权威的文档,但是仅仅是对uds应用层的规定,对于链路层还是要去查找ISO15765-2文档。
全文搜索DLC,终于找到关键部分。
在这里插入图片描述
在这里插入图片描述
7.4 CAN frame Data Length Code
7.4 CAN帧数据长度代码

7.4.1 DLC parameter
7.4.1 DLC参数

The DLC parameter specifies the number of data bytes transmitted in a CAN frame. This part of ISO 15765 does not specify any requirements concerning the length of the data field in a CAN frame other than those implied by the size of the network layer protocol data units.
DLC参数指定在CAN帧中传输的数据字节数。ISO 15765的这部分没有规定关于CAN帧中数据字段长度的任何要求,除了网络层协议数据单元的大小所暗示的要求。

An application that implements the network layer as defined in this document might either pad all CAN frames to their full length (see 7.4.2) or optimize the DLC to the applicable length of the network layer protocol data unit (see 7.4.3).
实现本文档中定义的网络层的应用程序可以将所有CAN帧填充到其完整长度(见7.4.2),或将DLC优化到网络层协议数据单元的适用长度(见7.4.3)。

7.4.2 CAN frame data padding
7.4.2 CAN帧数据填充

The DLC is always set to 8. If the N_PDU to be transmitted is shorter than 8 bytes, then the sender has to set the DLC to the maximum value 8 (padding of unused data bytes). In particular this can be the case for an SF, FC frame or last CF of a segmented message.
The DLC parameter of the CAN frame is set by the sender and read by the receiver to determine the number of data bytes per CAN frame to be processed by the network layer. The DLC parameter cannot be used to determine the message length; this information shall be extracted from the N_PCI information in the beginning of a message.
DLC总是设置为8。如果要传输的N_PDU小于8字节,则发送方必须将DLC设置为最大值8(未使用的数据字节填充)。特别是SF、FC帧或分段消息的最后一个CF。CAN帧的DLC参数由发送方设置,并由接收方读取,以确定网络层对每个CAN帧所要处理的数据字节数。DLC参数不能用于确定消息长度;此信息应从消息开头的N_PCI信息中提取。

7.4.3 CAN frame data optimization
7.4.3 CAN帧数据优化

The DLC does not always need to be 8. If the N_PDU to be transmitted is shorter than 8 bytes, then the sender may optimize the CAN bus load by shortening the CAN frame data to only contain the number of bytes occupied by the N_PDU (no padding of unused data bytes). CAN frame data optimization can only be used for a SF, FC frame or last CF of a segmented message.
The DLC parameter of the CAN frame is set by the sender and read by the receiver to determine the number of data bytes per CAN frame to be processed by the network layer. The DLC parameter cannot be used to determine the message length; this information shall be extracted from the N_PCI information in the beginning of a message.
DLC并不总是需要是8。如果要传输的N_PDU小于8字节,那么发送方可以通过缩短CAN帧数据来只包含N_PDU占用的字节数(不添加未占用的数据字节)来优化CAN总线负载。CAN帧数据优化只能用于分段消息的SF、FC帧或分段消息的最后一个CF。CAN帧的DLC参数由发送方设置,并由接收方读取,以确定网络层对每个CAN帧所要处理的数据字节数。DLC参数不能用于确定消息长度;此信息应从消息开头的N_PCI信息中提取。

7.4.4 Data Length Code error handling
7.4.4 数据长度、代码、错误处理

Depending on the N_PCI value, the network layer can calculate the smallest expected value for the CAN DLC parameter in a received CAN frame.
The reception of a CAN frame with a DLC value smaller than expected (less than 8 for applications which pad the CAN frames or smaller than implied by the size of the network protocol data unit for optimized implementations) shall be ignored by the network layer without any further action
根据N_PCI值,网络层可以计算出在接收到的can帧中的CAN DLC参数的最小期望值。接收的DLC值小于预期的CAN帧(对于填充CAN帧的应用程序,小于8,或者对于实现优化小于网络协议数据单元的大小)应当忽略网络层,而且没有任何进一步的处理

结论:
DLC的长度,官方没有明确的规定,建议是:可以是固定8字节或者使用优化的最小字节。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值