Python CAN:Fault Injection_CAN Msg相关故障

问题描述

我将通过提出另一个问题来扩展 Embedded Noob 的帖子。我正在测试 ECU 的故障代码(主要与 Missing 和 Invalid Msg 故障代码有关)。背景:如果被测ECU在一段时间后没有收到特定消息,则设置Missing msg,如果接收到的msg中的一个信号/多个信号不准确,则设置Invalid msg。

由于我正在对 ECU 执行台架级测试,因此我的设置包括以下内容一个模拟 ECU 所需消息的脚本(应该无限期运行),另一个发送诊断消息以读取故障代码信息的脚本(应该能够模拟中设置的停止和重新启动消息)(每个 UDS 的服务 0x19)和 python-can 包中包含的 can.logger 脚本。

我正在使用以下脚本为我的 ECU 模拟环境:

import can
import time


## Define the interface:
bus = can.interface.Bus(bustype='pcan',channel='PCAN_USBBUS1',bitrate=500000)



## Define the messages to transmit (Instantiating):
msg_3B3 = can.message.Message(arbitration_id=0x3B3,data=[0x40,0x84,0xC0,0x0C,0x00,0x00],extended_id=False)
msg_41E = can.message.Message(arbitration_id=0x41E,data=[0xFF,0xFF,0xFF],extended_id=False)
msg_44C = can.message.Message(arbitration_id=0x44C,extended_id=False)
msg_59E = can.message.Message(arbitration_id=0x59E,extended_id=False)


## Periodicty for messages per dbc file:
periodicity_msg_3B3 = 1.0
periodicity_msg_41E = 1.0
periodicity_msg_44C = 1.0
periodicity_msg_59E = 1.0

## List of Tuples (Msg Object & periodicity):
msgs_and_periodicity = [(msg_3B3,periodicity_msg_3B3),(msg_41E,periodicity_msg_41E),(msg_44C,periodicity_msg_44C),(msg_59E,periodicity_msg_59E)]


for msg,period in msgs_and_periodicity:
    bus.send_periodic(msg,period)


print('\nBlock has finished executing. Messages will Now be sent at their respective periodicity indefinitely'
      'until a keyboard interrupt is issued')


## Run indefinitely / unless stopped by user:
while True:
    try:
        time.sleep(1)
    except KeyboardInterrupt:
        print('Stopping')
        break

因为我使用 while 循环无限期地运行模拟,直到我使用 CTRL + C(在 pycharm 上)停止它,所以我不确定如何使用代码合并,停止 msg,说 msg_41E 来设置故障和重新启动它以消除此现有代码中的错误。我不希望任何其他消息停止,但只有我决定要停止/重新启动的消息 (msg_41E)

查看文档后,我只发现以下类提供停止和重新启动消息任务的方法:class can.broadcastmanager.CyclicTask & class can.RestartableCyclicTaskABC

请帮忙:(

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)