winIDEA SDK
CANLIN_use_case.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# This Python example demonstrates different use cases for CAN/LIN Add-on
4# module, as described in winIDEA Help: Network traffic sniffing,
5# Timing Analysis, System delay, and Message injection.
6#
7# (c) TASKING Germany GmbH, 2023
8
9"""
10This script demonstrates different use cases for CAN/LIN Add-on module.
11More information can be found in the winIDEA Help.
12"""
13
14import time
15import isystem.connect as ic
16
17# Connect to the last used winIDEA instance
18conn_mgr = ic.ConnectionMgr()
19conn_mgr.connect(ic.CConnectionConfig())
20
21# CAN1 bus configuration:
22# Add the description file
23# Set mode to CAN
24# Allow message injection
25# Set the arbitration phase:
26# Baudrate - 500 kbps
27# Bit sampling point - 70 %
28FNet_ctrl = ic.CFNetCtrl(conn_mgr)
29CAN1_ctrl = FNet_ctrl.CAN("CAN2LIN2.CAN1")
30CAN1_cfg = CAN1_ctrl.cfg()
31CAN1_cfg.set("Databases[0].Path", "../../common/AOM/CAN.dbc")
32CAN1_cfg.set_mode(ic.ECAN_CAN)
33CAN1_cfg.set_allow_injection(True)
34CAN1_cfg.set_arbitration(nBaudrate_kbps=500, nBitSamplingPoint=70)
35
36# End and begin new debug session so the configuration takes effect
37session_ctrl = ic.CSessionCtrl(conn_mgr)
38session_ctrl.end()
39session_ctrl.begin_reset()
40
41# CAN1 FNet operation configuration:
42# Enable recording of all messages
43# Enable recording of injected messages
44CAN1_op = CAN1_ctrl.op()
45CAN1_op.set_record_all_received(True)
46CAN1_op.set_record_all_injected(True)
47
48# Use comparator 0 to trigger TC4 on the reception of a message with ID=0x555
49CAN1_op.set_comparator(nComparator=0, bRecord=True, nFTrig=4, eLength=ic.ECAN_Standard,
50 nID=0x555, nMask=0xFFFFFFFF, eType=ic.ECAN_Both)
51
52# Use action trigger slot 0 to inject message with ID=0x123 when TC4 is triggered
53CAN1_op.set_action(nAction=0, nFTrig=4, eLength=ic.ECAN_Standard, nID=0x123,
54 bFD=False, bBRS=False, bESI=False, bRequest=False, rstrData="00000000")
55
56# Begin New Session - start trace recording
57profiler = ic.CProfilerController2(conn_mgr, fileName='CANLIN_use_case.trd', mode='w')
58profiler.start()
59
60# Run the target
61exec_ctrl = ic.CExecutionController(conn_mgr)
62exec_ctrl.run()
63
64# Wait for a while (target is running) before injecting a message
65time.sleep(3)
66
67# Manually inject a message with ID=0x45 and data=0x0
68CAN1_ctrl.ctrl_inject(eLength=ic.ECAN_Standard, nID=0x45, bFD=False,
69 bBRS=False, bESI=False, bRequest=False, rstrData="00000000")
70
71# Wait for a while before a new manual message is injected
72time.sleep(3)
73
74# Set a breakpoint at a function, run the target until BP is hit and inject a CAN message with ID=0xBB after it
75bc_ctrl = ic.CBreakpointController(conn_mgr)
76bc_ctrl.setBP("Runnable_Core0_1000ms")
77exec_ctrl.run(ic.CExecutionController.TOUT_INF)
78CAN1_ctrl.ctrl_inject(eLength=ic.ECAN_Standard, nID=0xBB, bFD=False,
79 bBRS=False, bESI=False, bRequest=False, rstrData="00000000")
80
81
82# Export the collected data
83export_cfg = ic.CProfilerExportConfig()
84export_cfg.setFileName('CANLIN_use_case.xml') \
85 .setSaveTimeline(True)
86profiler.exportData(export_cfg)
87
88# Load profiler results
89profiler_export_file = export_cfg.getFileName()
90profiler_data = ic.CProfilerData2.createInstance(export_cfg.getFileName(), False)
91
92# Always check for parser warnings
93warnings = profiler_data.getParserWarnings()
94if warnings:
95 print(f"WARNING(S): {warnings}")
96
97# Print events for the 'Signal_Rx8bit_Cyclic'
98if profiler_data.hasArea(ic.CProfilerArea2.EAUX, 'Signal_Rx8bit_Cyclic'):
99 signal_area = profiler_data.getArea(ic.CProfilerArea2.EAUX, 'Signal_Rx8bit_Cyclic')
100 timelineIterator = profiler_data.getTimelineIterator(ic.CProfilerTimeEvent.EEvAny,
101 signal_area.getHandle())
102
103 while timelineIterator.hasNext():
104 timeEvent = timelineIterator.next()
105 print(timeEvent.toString())
106
107# --------------------------------------------------------------------------------------
108# Output example for one of the timeEvents
109# CProfilerTimeEvent:
110# handle: 1073741836
111# eventType: 1
112# value: 37
113# valueUnit:
114# floatValue: 37
115# time: 3667651152
116# eventSource: -1