UDS学习笔记(七)——网络地址

目录

物理地址与功能地址

网络层地址


 

在使用Python学习ISO15765的过程中,发现它的网络地址很有意思。因此在此做一个笔记,记录ISOTP的网络地址的定义。这里使用的是python-can-isotp库,文档为:参考文档

在其文档中,我们可以看到它的地址设定有以下:

import isotp

isotp.Address(isotp.AddressingMode.Normal_11bits, rxid=0x123, txid=0x456)
isotp.Address(isotp.AddressingMode.Normal_29bits, rxid=0x123456, txid=0x789ABC)
isotp.Address(isotp.AddressingMode.NormalFixed_29bits, source_address=0x11, target_address=0x22)
isotp.Address(isotp.AddressingMode.Extended_11bits, rxid=0x123, txid=0x456, source_address=0x55, target_address=0xAA)
isotp.Address(isotp.AddressingMode.Extended_29bits, rxid=0x123456, txid=0x789ABC, source_address=0x55, target_address=0xAA)
isotp.Address(isotp.AddressingMode.Mixed_11bits, rxid=0x123, txid=0x456, address_extension=0x99)
isotp.Address(isotp.AddressingMode.Mixed_29bits, source_address=0x11, target_address=0x22, address_extension=0x99)

物理地址与功能地址

首先是物理地址与功能地址。怎么理解物理地址与功能地址的区别呢。物理地址是诊断仪与ECU一对一的通信,而功能地址则是诊断仪与ECU一对多的通信。例如当诊断仪需要关闭总线上所有的ECU发送数据时。可以通过物理地址一个个关闭ECU发送数据功能。也可以通过功能地址一次性关闭所有的ECU发送数据的功能。需要注意的是,功能地址只支持单帧,而物理地址支持完整的功能。

网络层地址

网络层地址包括三种:正常固定地址,扩展地址以及混合地址,如下图所示:

 

正常固定地址如下,其设置方式有两种,一种是直接设置要发送的ID的值(此种方式设置的物理地址与功能地址此时相同),另一种则是通过SA和TA设置ID的值(物理地址以及功能地址是不相同的)。需要备注的是11位的地址是无法设置SA,TA: 

import isotp
addr = isotp.Address(isotp.AddressingMode.Normal_11bits, rxid=0x123, txid=0x456)
print(hex(addr.rx_arbitration_id_physical)) #0x123
print(hex(addr.rx_arbitration_id_functional)) #0x123
print(hex(addr.tx_arbitration_id_physical)) #0x456
print(hex(addr.tx_arbitration_id_functional)) #0x456
addr = isotp.Address(isotp.AddressingMode.Normal_29bits, rxid=0x123456, txid=0x789ABC)
print(hex(addr.rx_arbitration_id_physical)) #0x123456
print(hex(addr.rx_arbitration_id_functional)) #0x123456
print(hex(addr.tx_arbitration_id_physical)) #0x789ABC
print(hex(addr.tx_arbitration_id_functional)) #0x789ABC
addr = isotp.Address(isotp.AddressingMode.NormalFixed_29bits, source_address=0x11, target_address=0x22)
print(hex(addr.rx_arbitration_id_physical)) #0x18da1122
print(hex(addr.rx_arbitration_id_functional)) #0x18db1122
print(hex(addr.tx_arbitration_id_physical)) #0x18da2211
print(hex(addr.tx_arbitration_id_functional)) #0x18db2211

扩展地址如下,可见其SA,TA并没有影响发送ID的值,而是将TA放置到CAN的数据域:

addr = isotp.Address(isotp.AddressingMode.Extended_11bits, rxid=0x123, txid=0x456, source_address=0x55, target_address=0xAA)
print(hex(addr.rx_arbitration_id_physical)) #0x123
print(hex(addr.rx_arbitration_id_functional)) #0x123
print(hex(addr.tx_arbitration_id_physical)) #0x456
print(hex(addr.tx_arbitration_id_functional)) #0x456
addr = isotp.Address(isotp.AddressingMode.Extended_29bits, rxid=0x123456, txid=0x789ABC, source_address=0x55, target_address=0xAA)
print(hex(addr.rx_arbitration_id_physical)) #0x123456
print(hex(addr.rx_arbitration_id_functional)) #0x123456
print(hex(addr.tx_arbitration_id_physical)) #0x789ABC
print(hex(addr.tx_arbitration_id_functional)) #0x789ABC

 

 混合地址将数据域的第一个字节设置位AE(address_extension),同时其dec与正常不同。

addr = isotp.Address(isotp.AddressingMode.Mixed_11bits, rxid=0x123, txid=0x456, address_extension=0x99)
print(hex(addr.rx_arbitration_id_physical)) #0x123
print(hex(addr.rx_arbitration_id_functional)) #0x123
print(hex(addr.tx_arbitration_id_physical)) #0x456
print(hex(addr.tx_arbitration_id_functional)) #0x456
addr = isotp.Address(isotp.AddressingMode.Mixed_29bits, source_address=0x11, target_address=0x22, address_extension=0x99)
print(hex(addr.rx_arbitration_id_physical)) #0x18ce1122
print(hex(addr.rx_arbitration_id_functional)) #0x18cd1122
print(hex(addr.tx_arbitration_id_physical)) #0x18ce2211
print(hex(addr.tx_arbitration_id_functional))#0x18cd2211

 

  • 2
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值