如何解码Canbus的DBC定义?
我编写了一个.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像这样,看起来很好,看起来不错 :
信号 | 解码值 |
---|---|
0 | SLOT3_ERROR_ID |
3 | SLOT4_ERROR_STATE |
0 | SLOT3_ERROR_RESEVER |
0 | SLOT2_ERROR_STATE |
0 | SLOT4_ERROR_ID |
4 | SLOT4_ERROR_ERROR_REVERD |
0 | SLOT2_ERROR_RESEVER |
slot1_error_state |
|
ME | 1 |
于 | 我们 |
专注 | 的 |
|
定义 - 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:
Signal | Decoded value |
---|---|
Slot2_Error_Reserved | 0 |
Slot3_Error_Id | 3 |
Slot4_Error_State | 0 |
Slot3_Error_Reserved | 0 |
Slot2_Error_State | 0 |
Slot4_Error_Id | 4 |
Slot4_Error_Reserved | 0 |
Slot2_Error_Id | 2 |
Slot1_Error_Reserved | 0 |
Slot3_Error_State | 2 |
Slot1_Error_Id | 1 |
Slot1_Error_State | 0 |
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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
造成混乱的原因是您的信号被定义为大端字节序。
当大端和小端混合时,我自己经常感到困惑。
如果您尝试可视化
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: