如何解码Canbus的DBC定义?

发布于 2025-01-19 12:38:33 字数 2261 浏览 0 评论 0原文

我编写了一个.dbc文件解码器,该文件很好地工作。

但是,当我添加一个新的硬件DBC时,对于以下消息,我的代码无法正确解码这些信号。这是DBC部分:

BO_ 2566852816 ERROR_INFO: 8 Vector__XXX
 SG_ Slot4_Error_Reserved : 62|7@0+ (1,0) [0|127] "" Vector__XXX
 SG_ Slot3_Error_Reserved : 46|7@0+ (1,0) [0|127] "" Vector__XXX
 SG_ Slot2_Error_Reserved : 30|7@0+ (1,0) [0|127] "" Vector__XXX
 SG_ Slot1_Error_Reserved : 14|7@0+ (1,0) [0|127] "" Vector__XXX
 SG_ Slot4_Error_State : 49|3@0+ (1,0) [0|7] "#" Vector__XXX
 SG_ Slot3_Error_State : 33|3@0+ (1,0) [0|7] "#" Vector__XXX
 SG_ Slot2_Error_State : 17|3@0+ (1,0) [0|7] "#" Vector__XXX
 SG_ Slot4_Error_Id : 55|6@0+ (1,0) [0|63] "#" Vector__XXX
 SG_ Slot3_Error_Id : 39|6@0+ (1,0) [0|63] "#" Vector__XXX
 SG_ Slot2_Error_Id : 23|6@0+ (1,0) [0|63] "#" Vector__XXX
 SG_ Slot1_Error_State : 1|3@0+ (1,0) [0|7] "#" Vector__XXX
 SG_ Slot1_Error_Id : 7|6@0+ (1,0) [0|63] "#" Vector__XXX

这是error_info框架我接收的字节:

04 00 08 00 0D 00 0D 00 10 00

bms master像这样,看起来很好,看起来不错 :

信号解码值
0SLOT3_ERROR_ID
3SLOT4_ERROR_STATE
0SLOT3_ERROR_RESEVER
0SLOT2_ERROR_STATE
0SLOT4_ERROR_ID
4SLOT4_ERROR_ERROR_REVERD
0SLOT2_ERROR_RESEVER
slot1_error_state
ME1
我们
专注

定义 - aka | 3@0+ - 这意味着:

  • start bit是1,又名第二;
  • 长度是3位;
  • 0表示大恩迪安(1本来意味着小恩迪安);
  • +表示未签名。

根据我对DBC格式的理解,以3位的位1开始是胡说八道。但这证明我错了。

我试图解码这些值,然后做到了,如下所示:

“在此处输入图像说明”

如您在图纸上所看到的,我得到了ID,并且状态与BMSMASTER相同。

但是,我拉头发以了解这是如何依赖DBC所包含的定义的。

任何人都可以逐步解释,如何应用我在问题开头说的两个规则,请问?

I wrote a .DBC file decoder which works very well.

But as I add a new hardware DBC, for the following message, my code does not decode these signals correctly. Here is the DBC portion:

BO_ 2566852816 ERROR_INFO: 8 Vector__XXX
 SG_ Slot4_Error_Reserved : 62|7@0+ (1,0) [0|127] "" Vector__XXX
 SG_ Slot3_Error_Reserved : 46|7@0+ (1,0) [0|127] "" Vector__XXX
 SG_ Slot2_Error_Reserved : 30|7@0+ (1,0) [0|127] "" Vector__XXX
 SG_ Slot1_Error_Reserved : 14|7@0+ (1,0) [0|127] "" Vector__XXX
 SG_ Slot4_Error_State : 49|3@0+ (1,0) [0|7] "#" Vector__XXX
 SG_ Slot3_Error_State : 33|3@0+ (1,0) [0|7] "#" Vector__XXX
 SG_ Slot2_Error_State : 17|3@0+ (1,0) [0|7] "#" Vector__XXX
 SG_ Slot4_Error_Id : 55|6@0+ (1,0) [0|63] "#" Vector__XXX
 SG_ Slot3_Error_Id : 39|6@0+ (1,0) [0|63] "#" Vector__XXX
 SG_ Slot2_Error_Id : 23|6@0+ (1,0) [0|63] "#" Vector__XXX
 SG_ Slot1_Error_State : 1|3@0+ (1,0) [0|7] "#" Vector__XXX
 SG_ Slot1_Error_Id : 7|6@0+ (1,0) [0|63] "#" Vector__XXX

Here is the bytes for the ERROR_INFO frame I receive:

04 00 08 00 0D 00 10 00

BMS master decodes it like so, which looks fine to me:

SignalDecoded value
Slot2_Error_Reserved0
Slot3_Error_Id3
Slot4_Error_State0
Slot3_Error_Reserved0
Slot2_Error_State0
Slot4_Error_Id4
Slot4_Error_Reserved0
Slot2_Error_Id2
Slot1_Error_Reserved0
Slot3_Error_State2
Slot1_Error_Id1
Slot1_Error_State0

If we focus on the definition of Slot1_Error_State — aka 1|3@0+— this means:

  • start bit is 1, aka the second;
  • length is 3 bits;
  • and 0 means big endian (1 would have meant little endian);
  • the+ means unsigned.

As per my understanding of the DBC format, starting at bit 1 for 3 bits is nonsense. But this proves that I am wrong.

I tried to decode the values, and I made it, as follows:

enter image description here

As you can see on my drawing, I got the ID and states identical to what bmsMaster found.

But, I pull my hair to understand how this relies to the definition the DBC contains.

Anyone can explain, step by step, how to apply the two rules I talked about at the beginning of the question, pls?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪我们做朋友吧 2025-01-26 12:38:33

造成混乱的原因是您的信号被定义为大端字节序。
当大端和小端混合时,我自己经常感到困惑。

如果您尝试可视化 Slot1_Error_State,它实际上应该从 Byte0 最低有效位(1,然后 0)开始,并以 Byte1 最高有效位结束:

在此处输入图像描述

The confusion comes from the fact that your signals are defined as big-endian.
I often get confused myself when big and little endian are mixed.

If you try to visualize Slot1_Error_State, it should actually start at Byte0 least significant bits (1, then 0) and end at Byte1 most significant bit:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文