├── .gitignore
├── LICENSE
├── README.md
├── canoe-automation
├── .project
├── .pydevproject
├── .settings
│ └── org.eclipse.core.resources.prefs
├── CANoe.automation
│ ├── CANOEAutomation.py
│ ├── CANOeConfigurationAutomation.py
│ ├── CanoeLaunchWithTSE.py
│ ├── CanoeLaunchWithoutTSE.py
│ ├── __init__.py
│ ├── usecase01_configuration.properties
│ ├── usecase02_configuration.properties
│ └── usecase03_configuration.properties
├── CANoe
│ ├── Python_CANoe.py
│ └── __init__.py
├── resources
│ ├── TestSetup.tse
│ └── TestSetup_WithoutImmediate.tse
└── robot-framework
│ ├── CANoe
│ └── base
│ │ ├── CANoe.py
│ │ ├── canoe_keyword.robot
│ │ └── canoe_usecase.robot
│ ├── LICENSE-2.0.txt
│ ├── README.md
│ └── __init__.py
├── python-can-examples
├── .project
├── .pydevproject
├── basic-ecu-simulation
│ ├── .~lock.usecasediagram.odp#
│ ├── BasicEngineECU.py
│ ├── EngineControlTesterNode.py
│ ├── __init__.py
│ ├── readme.md
│ ├── system.kcd
│ ├── system_MainBus.dbc
│ └── usecasediagram.odp
├── output.xml
├── python-can-dbcmessages
│ ├── LoadDBC.py
│ ├── ReceiveCANDBCMessage.py
│ ├── SendCANDBCMessage.py
│ └── __init__.py
├── python-can-newdbc-handling
│ ├── Basic_DBCinExcel.dbc
│ ├── Basic_DBCinExcel.xlsx
│ ├── LoadDBC.py
│ ├── ReceiveCANDBCMessage.py
│ └── SendCANDBCMessage.py
├── python-can-rawmessages
│ ├── ReceiveCANRawMessage.py
│ ├── SendCANRawMessage.py
│ ├── SendMessageOnKeyPress.py
│ ├── SendMessageOnKeyPressAndReceive.py
│ ├── SendMessagePeriodic.py
│ ├── TesterNode.py
│ ├── __init__.py
│ ├── images
│ │ ├── candump.png
│ │ └── vcansetup.png
│ └── readme.md
├── readme.md
├── resources
│ ├── Antitheft.dbc
│ ├── comfort.dbc
│ └── motohawk.dbc
├── robot-framework
│ ├── CURF
│ │ ├── base
│ │ │ ├── Curf.py
│ │ │ └── averagetime.py
│ │ ├── dbc
│ │ │ └── Example.dbc
│ │ ├── keywords
│ │ │ └── curf.robot
│ │ ├── outputs
│ │ │ └── .gitignore
│ │ └── testsuite
│ │ │ ├── canIsoTP.robot
│ │ │ ├── canRaw.robot
│ │ │ ├── canUDS.robot
│ │ │ ├── log.html
│ │ │ ├── output.xml
│ │ │ ├── outputs
│ │ │ └── .gitignore
│ │ │ ├── report.html
│ │ │ └── tester_motor_usecase.robot
│ ├── LICENSE-2.0.txt
│ ├── README.md
│ └── __init__.py
└── toc.md
└── python-can-usecases
├── .project
├── .pydevproject
├── 01_EngineControlECU
├── Basic_DBC.dbc
├── Engine_ECU_DBC.py
├── Engine_ECU_RAW.py
├── Engine_Tester_DBC.py
├── Engine_Tester_RAW.py
├── GUI_Based
│ ├── Basic_DBC.dbc
│ ├── Engine_ECU_DBC.py
│ ├── Engine_GUITester.py
│ └── speedMeter.qml
├── Tester node ecu.py
├── __init__.py
├── engine ecu.py
├── engine.can
├── readme.md
└── testernode.can
├── 02_CentralLockingSystemECU
├── .dbc & .can
│ ├── DE.can
│ ├── ED.can
│ └── comfort.dbc
├── CLS.ecux
├── CLS.py
├── DE.can
├── ED.can
├── ReadMe
├── ReferralDiagram.pdf
├── __init__.py
└── comfort.dbc
├── 03_SeatBeltControlECU
├── Basic_DBC.dbc
├── SeatbeltECU_Testernode.py
├── Seatbelt_ECU_DBC.py
├── Seatbelt_Tester_DBC.py
├── Seatbelt_ecu_raw.py
├── __init__.py
├── precrash seatbelt test case.pdf
└── seatbeltECU.py
├── 04_CruiseControlECU
└── __init__.py
├── 05_ClimateControlECU
├── ClimateECU_TestNode.py
├── __init__.py
├── climate_control.can
├── climate_ecu.dbc
├── dbc_compare.py
└── readme.md
├── 06_AirBagControlECU
├── AirbagTestNode.py
├── DBC
│ ├── Basic_DBC.dbc
│ └── Basic_DBCinExcel.xlsx
├── RAW_Message
│ ├── AirbagTestNode_RAW.py
│ └── airbagECUSimulation_RAW.py
├── Robot_Tester
│ ├── base
│ │ ├── Curf.py
│ │ └── averagetime.py
│ ├── dbc
│ │ ├── airbag_MainBus.dbc
│ │ └── system_MainBus.dbc
│ ├── keywords
│ │ └── curf.robot
│ ├── outputs
│ │ └── .gitignore
│ └── testsuite
│ │ ├── canRaw.robot
│ │ ├── log.html
│ │ ├── output.xml
│ │ ├── outputs
│ │ └── 20200427
│ │ │ ├── Check the reception of Airbag Active Status_20200427_112844
│ │ │ ├── Check the reception of Airbag Active Status_20200427_113018
│ │ │ ├── Check the reception of Airbag Active Status_20200427_113200
│ │ │ ├── Check the reception of Airbag Active Status_20200427_113315
│ │ │ ├── Check the reception of Airbag Active Status_20200427_113459
│ │ │ ├── Check the reception of Airbag Active Status_20200427_113627
│ │ │ ├── Check the reception of Airbag Active Status_20200427_113716
│ │ │ ├── Check the reception of Airbag Active Status_20200427_114513
│ │ │ ├── Check the reception of Airbag Active Status_20200427_114640
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_112843
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_113017
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_113159
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_113314
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_113458
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_113626
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_113715
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_114512
│ │ │ ├── Check the reception of Airbag Idle Status_20200427_114639
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_112842
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_113016
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_113159
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_113313
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_113458
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_113626
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_113715
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_114512
│ │ │ ├── Check the reception of Airbag Inactive Status_20200427_114639
│ │ │ ├── Send Message VehicleMotion_20200427_112844
│ │ │ ├── Send Message VehicleMotion_20200427_113018
│ │ │ ├── Send Message VehicleMotion_20200427_113200
│ │ │ ├── Send Message VehicleMotion_20200427_113315
│ │ │ ├── Send Message VehicleMotion_20200427_113459
│ │ │ ├── Send Message VehicleMotion_20200427_113627
│ │ │ ├── Send Message VehicleMotion_20200427_113716
│ │ │ ├── Send a Crash Detected CAN frame_20200427_113018
│ │ │ ├── Send a Crash Detected CAN frame_20200427_113200
│ │ │ ├── Send a Crash Detected CAN frame_20200427_113315
│ │ │ ├── Send a Crash Detected Signal_20200427_113459
│ │ │ ├── Send a Crash Detected with Engine Run CAN frame_20200427_114513
│ │ │ ├── Send a Crash Detected with Engine Run CAN frame_20200427_114640
│ │ │ ├── Send a Engine Run Signal_20200427_112843
│ │ │ ├── Send a Engine Run Signal_20200427_113017
│ │ │ ├── Send a Engine Run Signal_20200427_113159
│ │ │ ├── Send a Engine Run Signal_20200427_113314
│ │ │ ├── Send a Engine Run Signal_20200427_113458
│ │ │ ├── Send a Engine Run Signal_20200427_113626
│ │ │ ├── Send a Engine Run Signal_20200427_113715
│ │ │ ├── Send a Engine Run Signal_20200427_114512
│ │ │ ├── Send a Engine Run Signal_20200427_114639
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_112843
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_113017
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_113159
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_113314
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_113458
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_113626
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_113715
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_114512
│ │ │ ├── Send a Seatbelt Lock Signal_20200427_114639
│ │ │ ├── Send a Seatbelt Un-lock Signal_20200427_112842
│ │ │ ├── Send a Seatbelt Un-lock Signal_20200427_113016
│ │ │ ├── Send a Seatbelt Un-lock Signal_20200427_113159
│ │ │ ├── Send a Seatbelt Un-lock Signal_20200427_113313
│ │ │ ├── Send a Seatbelt Un-lock Signal_20200427_113458
│ │ │ ├── Send a Seatbelt Un-lock Signal_20200427_113626
│ │ │ ├── Send a Seatbelt Un-lock Signal_20200427_113715
│ │ │ ├── Send a Seatbelt Un-lock Signal_20200427_114512
│ │ │ └── Send a Seatbelt Un-lock Signal_20200427_114639
│ │ ├── report.html
│ │ └── tester_Airbag_usecase.robot
├── __init__.py
├── airbagECUSimulation.py.py
├── airbag_MainBus.dbc
└── readme.md
├── Documents
└── System Test Engineer.odp
├── Tools
└── can_logFile.py
└── output.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This repository contains
2 | 1. Usage of CAN Libraries available Python
3 | * can-utils
4 | * cantools
5 | * can-matrix
6 | * robot-framework
7 |
8 | 2. Automotive Use Cases developed using CAN Libraries available Python
9 |
10 | # About US
11 | ANCIT is an Engineering Tools and Services company based out of US, Germany and Bangalore - INDIA catering prominent enterprises to startup ventures committed in Industrial,Semiconductor, Automotive, IoT , Defence and Aerospace. We are specialized in Development and Customization of Tools, IDEs and Automation of Testing Processes in these industries.
12 |
13 | # Contact US
14 | Please write to bk@ancitconsulting.com or beeshma@ancitconsulting.com if you need more information or wish to contribute to our repository.
15 |
--------------------------------------------------------------------------------
/canoe-automation/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | canoe-automation
4 |
5 |
6 |
7 |
8 |
9 | org.python.pydev.PyDevBuilder
10 |
11 |
12 |
13 |
14 |
15 | org.python.pydev.pythonNature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/canoe-automation/.pydevproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | /${PROJECT_DIR_NAME}
5 |
6 | python interpreter
7 | Default
8 |
9 |
--------------------------------------------------------------------------------
/canoe-automation/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//CANoe.automation/CANOeConfigurationAutomation.py=UTF-8
3 | encoding//CANoe/Python_CANoe.py=utf-8
4 | encoding//CANoe/__init__.py=UTF-8
5 | encoding//robot-framework/CANoe/base/CANoe.py=utf-8
6 |
--------------------------------------------------------------------------------
/canoe-automation/CANoe.automation/CANOEAutomation.py:
--------------------------------------------------------------------------------
1 | from time import sleep
2 | import win32com.client as win32
3 | import configparser
4 | import time
5 | import pythoncom
6 |
7 | testComplete = False
8 |
9 | class TestModuleEvents(object):
10 | def OnReportGenerated(self,Success, SourceFullName, GeneratedFullName):
11 | print("Report Generated")
12 | global testComplete
13 | testComplete = True
14 |
15 | def OnStop(self, value):
16 | global testComplete
17 | testComplete = True
18 | print("Test Module Stopped")
19 |
20 | def OnStart(self):
21 | print("Test Module Started")
22 | global testComplete
23 | testComplete = False
24 |
25 | class TestConfigurationEvents(object):
26 | def OnStart(self):
27 | print("Measurement Started")
28 | global testComplete
29 | testComplete = False
30 |
31 | def OnStop(self):
32 | print("Measurement Stopped")
33 | global testComplete
34 | testComplete = False
35 |
36 | class CANOEAutomation:
37 |
38 | def __init__(self):
39 | global testComplete
40 | testComplete = False
41 |
42 | def getVerdict(self,argument):
43 | switcher = {
44 | 0: "zero",
45 | 1: "Passed",
46 | 2: "Failed",
47 | 3: "None",
48 | 4: "Inconclusive",
49 | 5: "Error in testsystem"
50 | }
51 |
52 | # get() method of dictionary data type returns
53 | # value of passed argument if it is present
54 | # in dictionary otherwise second argument will
55 | # be assigned as default value of passed argument
56 | return switcher.get(argument, "Not Available")
57 |
58 |
59 | def executeTestModule(self, win32, test_module):
60 | print(test_module)
61 | seq = test_module.Sequence
62 | for i in range(1, seq.Count + 1):
63 | tc = win32.CastTo(seq.Item(i), "ITestCase")
64 | print(tc)
65 |
66 | #
67 | win32.WithEvents(test_module, TestModuleEvents)
68 | test_module.Start()
69 | global testComplete
70 | while not testComplete:
71 | pythoncom.PumpWaitingMessages()
72 | time.sleep(1)
73 |
74 | print(self.getVerdict(test_module.Verdict))
75 |
76 | def startCanoe(self):
77 | #parse the Configuration File to pick the configuration path and tse path
78 | config = configparser.RawConfigParser()
79 | config.read('usecase02_configuration.properties')
80 | configurationPath = config.get('TESTCONFIGURATION', 'configurationpath')
81 | testspec = config.get('TESTCONFIGURATION', 'testspecification')
82 |
83 | CANoe = win32.DispatchEx("CANoe.Application")
84 | CANoe.Open(configurationPath)
85 |
86 |
87 |
88 | testSetup = CANoe.Configuration.TestSetup
89 | testSetup.TestEnvironments.Add(testspec)
90 | test_env = testSetup.TestEnvironments.Item(1)
91 | test_env = win32.CastTo(test_env, "ITestEnvironment2")
92 |
93 | CANoe.Measurement.Start()
94 | sleep(5) # Sleep because measurement start is not instantaneous
95 |
96 | testModules = test_env.TestModules
97 | for i in range(1, testModules.Count+1):
98 | test_module = test_env.TestModules.Item(i)
99 | self.executeTestModule(win32, test_module)
100 |
101 | exit()
102 |
103 |
104 |
105 | # seq = test_module.Sequence
106 | # for i in range(1, seq.Count+1):
107 | # # Cast from to to access {.Verdict}
108 | # # and the {.Enabled} property
109 | # tc = win32.CastTo(seq.Item(i), "ITestCase")
110 | # print(tc)
111 | # if tc.Verdict != 1: # Verdict 1 is pass
112 | # tc.Enabled = True
113 | # print(f"Enabling Test Case {tc.Ident} with verdict {tc.Verdict}")
114 | # else:
115 | # tc.Enabled = False
116 | # print(f"Disabling Test Case {tc.Ident} since it has already passed")
117 |
118 | if __name__ == '__main__':
119 | canoeAutomation = CANOEAutomation()
120 | canoeAutomation.startCanoe()
121 |
--------------------------------------------------------------------------------
/canoe-automation/CANoe.automation/CANOeConfigurationAutomation.py:
--------------------------------------------------------------------------------
1 | # -*- coding: UTF-8 -*-
2 | #.Data:2018/5/19
3 |
4 | import CANoe
5 | import time
6 | import configparser
7 | import os
8 |
9 | #Read User Configuration
10 | config = configparser.RawConfigParser()
11 | config.read('usecase02_configuration.properties')
12 | configurationPath = config.get('TESTCONFIGURATION', 'configurationpath')
13 | print(configurationPath)
14 | testspec = config.get('TESTCONFIGURATION', 'testspecification')
15 | print(testspec)
16 | # if len(testspec) != 0:
17 | # updateTestSpecification(configurationPath, testspec)
18 |
19 | app = CANoe.CANoe() #定义CANoe为app
20 |
21 | app.open_simulation(configurationPath) #导入某个CANoe congif
22 |
23 | if len(testspec) != 0:
24 | app.load_testsetup(testspec)
25 |
26 |
27 | app.start_Measurement() #启动CANoe
28 | app.start_testmodule()
29 | time.sleep(120)
30 | app.stop_Measurement() #停止CANoe
31 |
--------------------------------------------------------------------------------
/canoe-automation/CANoe.automation/CanoeLaunchWithTSE.py:
--------------------------------------------------------------------------------
1 | """Execute XML Test Cases without a pass verdict"""
2 | import sys
3 | from time import sleep
4 | import win32com.client as win32
5 |
6 | CANoe = win32.DispatchEx("CANoe.Application")
7 | CANoe.Open("E:/ancit-projects/canoe-autoit/CentralLockingSystem/CentralLockingSystem.cfg")
8 |
9 | test_env = CANoe.Configuration.TestSetup.TestEnvironments.Item('Test Environment')
10 | test_env = win32.CastTo(test_env, "ITestEnvironment2")
11 |
12 | # Get the XML TestModule (type ) in the test setup
13 | test_module = test_env.TestModules.Item('Tester')
14 |
15 | # {.Sequence} property returns a collection of or
16 | # or which is more generic
17 | seq = test_module.Sequence
18 | for i in range(1, seq.Count+1):
19 | # Cast from to to access {.Verdict}
20 | # and the {.Enabled} property
21 | tc = win32.CastTo(seq.Item(i), "ITestCase")
22 | print(tc)
23 | # if tc.Verdict != 1: # Verdict 1 is pass
24 | # tc.Enabled = True
25 | # print(f"Enabling Test Case {tc.Ident} with verdict {tc.Verdict}")
26 | # else:
27 | # tc.Enabled = False
28 | # print(f"Disabling Test Case {tc.Ident} since it has already passed")
29 |
30 |
31 | CANoe.Measurement.Start()
32 | sleep(5) # Sleep because measurement start is not instantaneous
33 | test_module.Start()
34 | sleep(1)
--------------------------------------------------------------------------------
/canoe-automation/CANoe.automation/CanoeLaunchWithoutTSE.py:
--------------------------------------------------------------------------------
1 | """Execute XML Test Cases without a pass verdict"""
2 | from time import sleep
3 | import win32com.client as win32
4 | import configparser
5 |
6 | config = configparser.RawConfigParser()
7 | config.read('usecase02_configuration.properties')
8 | configurationPath = config.get('TESTCONFIGURATION', 'configurationpath')
9 | testspec = config.get('TESTCONFIGURATION', 'testspecification')
10 |
11 | CANoe = win32.DispatchEx("CANoe.Application")
12 | CANoe.Open(configurationPath)
13 |
14 | testSetup = CANoe.Configuration.TestSetup
15 | testSetup.TestEnvironments.Add(testspec)
16 | test_env = testSetup.TestEnvironments.Item('Test Environment')
17 | report = test_env.Report
18 | report = win32.CastTo(test_env, "ITestReport5")
19 | test_env = win32.CastTo(test_env, "ITestEnvironment2")
20 |
21 |
22 | print(report.FullName)
23 |
24 | # Get the XML TestModule (type ) in the test setup
25 | test_module = test_env.TestModules.Item('Tester')
26 | print(test_module.Path)
27 | report = win32.CastTo(test_module.Report, "ITestReport5")
28 | print(report.FullName)
29 |
30 | # {.Sequence} property returns a collection of or
31 | # or which is more generic
32 | seq = test_module.Sequence
33 | for i in range(1, seq.Count+1):
34 | # Cast from to to access {.Verdict}
35 | # and the {.Enabled} property
36 | tc = win32.CastTo(seq.Item(i), "ITestCase")
37 | print(tc)
38 | # if tc.Verdict != 1: # Verdict 1 is pass
39 | # tc.Enabled = True
40 | # print(f"Enabling Test Case {tc.Ident} with verdict {tc.Verdict}")
41 | # else:
42 | # tc.Enabled = False
43 | # print(f"Disabling Test Case {tc.Ident} since it has already passed")
44 |
45 |
46 | CANoe.Measurement.Start()
47 | sleep(5) # Sleep because measurement start is not instantaneous
48 | test_module.Start()
49 | sleep(1)
--------------------------------------------------------------------------------
/canoe-automation/CANoe.automation/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/canoe-automation/CANoe.automation/__init__.py
--------------------------------------------------------------------------------
/canoe-automation/CANoe.automation/usecase01_configuration.properties:
--------------------------------------------------------------------------------
1 | [TESTCONFIGURATION]
2 | configurationpath=E:/ancit-projects/canoe-autoit/CentralLockingSystem/CentralLockingSystem.cfg
3 | testspecification=
--------------------------------------------------------------------------------
/canoe-automation/CANoe.automation/usecase02_configuration.properties:
--------------------------------------------------------------------------------
1 | [TESTCONFIGURATION]
2 | configurationpath=E:/ancit-projects/canoe-autoit/CentralLockingSystem/CentralLockingSystem.cfg
3 | testspecification = E:/ancit-projects/canoe-autoit/CentralLockingSystem/TestSetup.tse
--------------------------------------------------------------------------------
/canoe-automation/CANoe.automation/usecase03_configuration.properties:
--------------------------------------------------------------------------------
1 | [CANOECONFIGURATION]
2 | configurationpath=C:/Users/Public/Documents/Vector/CANoe/10.0 (x64)/CANoe Sample Configurations/CAN/TestFeatureSet/CentralLockingSystem/CentralLockingSystem.cfg
3 | [TESTCONFIGURATION]
4 | testspecification = C:/Users/Public/Documents/Vector/CANoe/10.0 (x64)/CANoe Sample Configurations/CAN/TestFeatureSet/CentralLockingSystem/TestSetup.tse, C:/Users/Public/Documents/Vector/CANoe/10.0 (x64)/CANoe Sample Configurations/CAN/TestFeatureSet/CentralLockingSystem/TestSetupNET.tse
--------------------------------------------------------------------------------
/canoe-automation/CANoe/__init__.py:
--------------------------------------------------------------------------------
1 | # -*- coding: UTF-8 -*-
2 | #.Data:2018/5/19
3 |
4 | from .Python_CANoe import CANoe # hz
--------------------------------------------------------------------------------
/canoe-automation/resources/TestSetup.tse:
--------------------------------------------------------------------------------
1 | ;CANoe Version |4|10|0|62624 TestSetup
2 | Version: 10.0.127 Build 127
3 | 32 PRO
4 | 5
5 | APPDIR Vector.CANoe.SignalGenerators.DLL
6 | Vector.CANoe.SignalGenerators, Version=10.0.127.0, Culture=neutral, PublicKeyToken=null
7 | Vector.CANoe.SignalGenerators.ComponentWrapper
8 | 1
9 | 1.0.1
10 | VTSPersistentRoot 1 Begin_Of_Object
11 | 1
12 | 1
13 | TS_PERSISTENT_ROOT_ID_STRING_0x792341fe
14 | 1
15 | 2
16 | VTSProgrammedNode 2 Begin_Of_Object
17 | 1
18 | VTSWrapper 3 Begin_Of_Object
19 | 2
20 | VTSItem 4 Begin_Of_Object
21 | 1
22 | 3 2589847316 0
23 | 1
24 | END_OF_ITEM_DATA
25 | End_Of_Object VTSItem 4
26 | 2
27 | VXmlTestNode 4 Begin_Of_Object
28 | 4
29 | VTestNode 5 Begin_Of_Object
30 | 8
31 | VProgrammedNode 6 Begin_Of_Object
32 | 5
33 | VConfigurationRoot 7 Begin_Of_Object
34 | 1
35 | End_Of_Object VConfigurationRoot 7
36 | 1 "Testmodules\LockingSystemTester.vxt"
37 | 1
38 | E:\ancit-projects\canoe-autoit\CentralLockingSystem\Testmodules\LockingSystemTester.vxt
39 |
40 |
41 | 5
42 | Tester
43 | Test 3
44 | EOF_TITLE_INFO
45 |
46 | 1
47 | 1
48 | VConfigurationBox 7 Begin_Of_Object
49 | 1
50 | VUniqueBox 8 Begin_Of_Object
51 | 1
52 | VBoxRoot 9 Begin_Of_Object
53 | 1
54 | 3
55 | 0 1 0 1 -1 -1 -1 -1 476 0 1106 548
56 |
57 | 1
58 |
59 | MDI_DOCK_INFO_END
60 | 5
61 | 1
62 | 6
63 | 0 1 -1 -1 -1 -1 476 0 1106 548
64 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
65 | END_OF_DOCK_INFO
66 | 1
67 | 2
68 | 1
69 | 0 1 -1 -1 -1 -1 400 292 1200 878
70 | 0
71 | 1
72 | 1272 560
73 | END_OF_DESKTOP_DATA
74 | 6
75 | 0 1 0 0 -1 -1 240 280 590 530
76 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
77 | END_OF_DOCK_INFO
78 | 0
79 | 2
80 | 1
81 | 0 1 -1 -1 -1 -1 400 292 1200 878
82 | 0
83 | 0
84 | 999 589
85 | END_OF_DESKTOP_DATA
86 | END_OF_DESKTOP_DATA_COLLECTION
87 | 0
88 | 0 1
89 | 1
90 | 6
91 | 0 1 0 0 -1 -1 240 280 590 530
92 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
93 | END_OF_DOCK_INFO
94 | 0
95 | -1
96 | 1
97 | 0 1 -1 -1 -1 -1 400 292 1200 878
98 | 0
99 | 0
100 | 0 0
101 | END_OF_DESKTOP_DATA
102 | 6
103 | 0 1 0 0 -1 -1 240 280 590 530
104 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
105 | END_OF_DOCK_INFO
106 | 0
107 | -1
108 | 1
109 | 0 1 -1 -1 -1 -1 400 292 1200 878
110 | 0
111 | 0
112 | 0 0
113 | END_OF_DESKTOP_DATA
114 | END_OF_DESKTOP_DATA_COLLECTION
115 | 0
116 | END_OF_DESKTOP_MEMBER
117 | {6D8549FC-F858-4342-9140-60D0EC53BD1E}
118 | 0
119 | End_Of_Object VBoxRoot 9
120 | 1 -1 0 0 0 0 0 0 0 0 0 0
121 | End_Of_Object VUniqueBox 8
122 | 1
123 | End_Of_Object VConfigurationBox 7
124 | 1
125 | 1
126 | 0
127 | 1
128 | 0
129 |
130 | EOF_MBSSDATA
131 | 1
132 | 0 1
133 | 0
134 | EOF_NLDATA
135 | 0
136 | EOF_ASSEMBLYDATA
137 | 1 "Testmodules\LockingSystemTester.vxt"
138 | VIPBStackSetting 7 Begin_Of_Object
139 | 4
140 | 2
141 | 0
142 | 0
143 | 1
144 | 0
145 | 1
146 | End_Of_Object VIPBStackSetting 7
147 | 6
148 | NULL
149 | End_Of_Serialized_Data 6
150 | 0
151 | 0 ""
152 | 1
153 | End_Of_Object VProgrammedNode 6
154 | 0
155 | 2
156 | IDS_REPORTFILTER_ITEM_DESCRIPTION=1
157 | IDS_REPORTFILTER_ITEM_COMMENTS=1
158 | IDS_REPORTFILTER_ITEM_VARIABLE=1
159 | IDS_REPORTFILTER_ITEM_RESUME_SIMPLETIMEOUT=0
160 | IDS_REPORTFILTER_ITEM_RESUME=1
161 | IDS_REPORTFILTER_ITEM_FIRSTVIOLATION=1
162 | IDS_REPORTFILTER_ITEM_STATISTICS=1
163 | IDS_REPORTFILTER_ITEM_HARDWARE=1
164 | IDS_REPORTFILTER_ITEM_CHECKEVENTS=0
165 | IDS_REPORTFITLER_ITEM_GENINFO=1
166 | IDS_REPORTFITLER_ITEM_SUTINFO=1
167 | IDS_REPORTFITLER_ITEM_ENGINFO=1
168 | IDS_REPORTFITLER_ITEM_ELMINFO=1
169 | End_Of_ReportFilter_Items
170 | 1
171 | NULL
172 | NULL
173 | 1
174 | 1 "Testmodules\TestCaseLibrary.can"
175 | EOF_CAPLLIBS
176 | 1 "reportLockingSystemTester.vtestreport"
177 | 1 0 1
178 | 0
179 | 1 base=cfg ""
180 | 3
181 | VSimulinkModelViewerConfiguration 6 Begin_Of_Object
182 | 2
183 | 0 ""
184 | 0 ""
185 | 0 ""
186 | 150
187 | 0
188 | End_Of_Object VSimulinkModelViewerConfiguration 6
189 | 1
190 | 0
191 | 1
192 | 1
193 | VConfigurationBox 6 Begin_Of_Object
194 | 1
195 | VUniqueBox 7 Begin_Of_Object
196 | 1
197 | VBoxRoot 8 Begin_Of_Object
198 | 1
199 | 3
200 | 0 1 0 1 -1 -1 -1 -1 476 0 1106 548
201 |
202 | 1
203 |
204 | MDI_DOCK_INFO_END
205 | 5
206 | 1
207 | 6
208 | 0 1 -1 -1 -1 -1 476 0 1106 548
209 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
210 | END_OF_DOCK_INFO
211 | 1
212 | 2
213 | 1
214 | 0 1 -1 -1 -1 -1 400 292 1200 878
215 | 0
216 | 1
217 | 1272 560
218 | END_OF_DESKTOP_DATA
219 | 6
220 | 0 1 0 0 -1 -1 240 280 590 530
221 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
222 | END_OF_DOCK_INFO
223 | 0
224 | 2
225 | 1
226 | 0 1 -1 -1 -1 -1 400 292 1200 878
227 | 0
228 | 0
229 | 999 589
230 | END_OF_DESKTOP_DATA
231 | END_OF_DESKTOP_DATA_COLLECTION
232 | 0
233 | 0 1
234 | 1
235 | 6
236 | 0 1 0 0 -1 -1 240 280 590 530
237 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
238 | END_OF_DOCK_INFO
239 | 0
240 | -1
241 | 1
242 | 0 1 -1 -1 -1 -1 400 292 1200 878
243 | 0
244 | 0
245 | 0 0
246 | END_OF_DESKTOP_DATA
247 | 6
248 | 0 1 0 0 -1 -1 240 280 590 530
249 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
250 | END_OF_DOCK_INFO
251 | 0
252 | -1
253 | 1
254 | 0 1 -1 -1 -1 -1 400 292 1200 878
255 | 0
256 | 0
257 | 0 0
258 | END_OF_DESKTOP_DATA
259 | END_OF_DESKTOP_DATA_COLLECTION
260 | 0
261 | END_OF_DESKTOP_MEMBER
262 | {6D8549FC-F858-4342-9140-60D0EC53BD1E}
263 | 0
264 | End_Of_Object VBoxRoot 8
265 | 1 -1 0 0 0 0 0 0 0 0 0 0
266 | End_Of_Object VUniqueBox 7
267 | 1
268 | End_Of_Object VConfigurationBox 6
269 | 1 "Testmodules\TestCaseLibrary2.cbf"
270 | NULL
271 | 0
272 | 0
273 | End_Of_Object VTestNode 5
274 | VTestModuleControllerXML 5 Begin_Of_Object
275 | 1
276 | VTestModuleController 6 Begin_Of_Object
277 | 3
278 | 1
279 | 0
280 | 0
281 | 0
282 | 0
283 | 0
284 | 1
285 | 0
286 | 0
287 | 0
288 | 0
289 | 0
290 | End_Of_Object VTestModuleController 6
291 | End_Of_Object VTestModuleControllerXML 5
292 | End_Of_Testcase_Exec_Flags
293 | Variant: A VariantEnd
294 | 1 base=cfg ""
295 | End_Of_Testcase_Exec_Flags_W
296 | Variant: A VariantEnd
297 | End_Of_Object VXmlTestNode 4
298 | TS_WRP_DATA_END
299 | End_Of_Object VTSWrapper 3
300 | 4
301 | 0
302 | 1
303 | TS_BUS_INFO_COLLECTION_END
304 | TS_CAPL_BLOCK_END
305 | End_Of_Object VTSProgrammedNode 2
306 | VTSFolder 2 Begin_Of_Object
307 | 1
308 | VTSItem 3 Begin_Of_Object
309 | 1
310 | 3 2595646244 0
311 | 1
312 | END_OF_ITEM_DATA
313 | End_Of_Object VTSItem 3
314 | 4
315 | Test Environment
316 | 1
317 | 2589847316
318 | 1 "sumreport.xml"
319 | END_OF_FILE_NAME
320 | 1 ""
321 | END_OF_FILE_NAME
322 | 3
323 | 1
324 | END_OF_FOLDER_DATA
325 | End_Of_Object VTSFolder 2
326 | 1
327 | 2595646244
328 | 2
329 | 1
330 | 2589847316
331 | 0
332 | 1
333 | 2595646244
334 | 1
335 | 2589847316
336 | End_Of_Object VTSPersistentRoot 1
337 |
--------------------------------------------------------------------------------
/canoe-automation/resources/TestSetup_WithoutImmediate.tse:
--------------------------------------------------------------------------------
1 | ;CANoe Version |4|10|0|62641 TestSetup
2 | Version: 10.0.127 Build 127
3 | 32 PRO
4 | 5
5 | APPDIR Vector.CANoe.SignalGenerators.DLL
6 | Vector.CANoe.SignalGenerators, Version=10.0.127.0, Culture=neutral, PublicKeyToken=null
7 | Vector.CANoe.SignalGenerators.ComponentWrapper
8 | 1
9 | 1.0.1
10 | VTSPersistentRoot 1 Begin_Of_Object
11 | 1
12 | 1
13 | TS_PERSISTENT_ROOT_ID_STRING_0x792341fe
14 | 1
15 | 2
16 | VTSProgrammedNode 2 Begin_Of_Object
17 | 1
18 | VTSWrapper 3 Begin_Of_Object
19 | 2
20 | VTSItem 4 Begin_Of_Object
21 | 1
22 | 3 4239567674 0
23 | 1
24 | END_OF_ITEM_DATA
25 | End_Of_Object VTSItem 4
26 | 2
27 | VXmlTestNode 4 Begin_Of_Object
28 | 4
29 | VTestNode 5 Begin_Of_Object
30 | 8
31 | VProgrammedNode 6 Begin_Of_Object
32 | 5
33 | VConfigurationRoot 7 Begin_Of_Object
34 | 1
35 | End_Of_Object VConfigurationRoot 7
36 | 1 "Testmodules\LockingSystemTester.vxt"
37 | 1
38 | E:\ancit-projects\canoe-autoit\CentralLockingSystem\Testmodules\LockingSystemTester.vxt
39 |
40 |
41 | 5
42 | Tester
43 | Test 3
44 | EOF_TITLE_INFO
45 |
46 | 1
47 | 1
48 | VConfigurationBox 7 Begin_Of_Object
49 | 1
50 | VUniqueBox 8 Begin_Of_Object
51 | 1
52 | VBoxRoot 9 Begin_Of_Object
53 | 1
54 | 3
55 | 0 1 0 1 -1 -1 -1 -1 476 0 1106 548
56 |
57 | 1
58 |
59 | MDI_DOCK_INFO_END
60 | 5
61 | 1
62 | 6
63 | 0 1 -1 -1 -1 -1 476 0 1106 548
64 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
65 | END_OF_DOCK_INFO
66 | 1
67 | 2
68 | 1
69 | 0 1 -1 -1 -1 -1 400 292 1200 878
70 | 0
71 | 1
72 | 1272 560
73 | END_OF_DESKTOP_DATA
74 | 6
75 | 0 1 0 0 -1 -1 240 280 590 530
76 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
77 | END_OF_DOCK_INFO
78 | 0
79 | 2
80 | 1
81 | 0 1 -1 -1 -1 -1 400 292 1200 878
82 | 0
83 | 0
84 | 999 589
85 | END_OF_DESKTOP_DATA
86 | END_OF_DESKTOP_DATA_COLLECTION
87 | 0
88 | 0 1
89 | 1
90 | 6
91 | 0 1 0 0 -1 -1 240 280 590 530
92 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
93 | END_OF_DOCK_INFO
94 | 0
95 | -1
96 | 1
97 | 0 1 -1 -1 -1 -1 400 292 1200 878
98 | 0
99 | 0
100 | 0 0
101 | END_OF_DESKTOP_DATA
102 | 6
103 | 0 1 0 0 -1 -1 240 280 590 530
104 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
105 | END_OF_DOCK_INFO
106 | 0
107 | -1
108 | 1
109 | 0 1 -1 -1 -1 -1 400 292 1200 878
110 | 0
111 | 0
112 | 0 0
113 | END_OF_DESKTOP_DATA
114 | END_OF_DESKTOP_DATA_COLLECTION
115 | 0
116 | END_OF_DESKTOP_MEMBER
117 | {330B2167-21A2-4518-9AC0-47E4AEA3CDD5}
118 | 0
119 | End_Of_Object VBoxRoot 9
120 | 1 -1 0 0 0 0 0 0 0 0 0 0
121 | End_Of_Object VUniqueBox 8
122 | 1
123 | End_Of_Object VConfigurationBox 7
124 | 1
125 | 1
126 | 0
127 | 1
128 | 0
129 |
130 | EOF_MBSSDATA
131 | 1
132 | 0 1
133 | 0
134 | EOF_NLDATA
135 | 0
136 | EOF_ASSEMBLYDATA
137 | 1 "Testmodules\LockingSystemTester.vxt"
138 | VIPBStackSetting 7 Begin_Of_Object
139 | 4
140 | 2
141 | 0
142 | 0
143 | 1
144 | 0
145 | 1
146 | End_Of_Object VIPBStackSetting 7
147 | 6
148 | NULL
149 | End_Of_Serialized_Data 6
150 | 0
151 | 0 ""
152 | 1
153 | End_Of_Object VProgrammedNode 6
154 | 0
155 | 2
156 | IDS_REPORTFILTER_ITEM_DESCRIPTION=1
157 | IDS_REPORTFILTER_ITEM_COMMENTS=1
158 | IDS_REPORTFILTER_ITEM_VARIABLE=1
159 | IDS_REPORTFILTER_ITEM_RESUME_SIMPLETIMEOUT=0
160 | IDS_REPORTFILTER_ITEM_RESUME=1
161 | IDS_REPORTFILTER_ITEM_FIRSTVIOLATION=1
162 | IDS_REPORTFILTER_ITEM_STATISTICS=1
163 | IDS_REPORTFILTER_ITEM_HARDWARE=1
164 | IDS_REPORTFILTER_ITEM_CHECKEVENTS=0
165 | IDS_REPORTFITLER_ITEM_GENINFO=1
166 | IDS_REPORTFITLER_ITEM_SUTINFO=1
167 | IDS_REPORTFITLER_ITEM_ENGINFO=1
168 | IDS_REPORTFITLER_ITEM_ELMINFO=1
169 | End_Of_ReportFilter_Items
170 | 1
171 | NULL
172 | NULL
173 | 1
174 | 1 "Testmodules\TestCaseLibrary.can"
175 | EOF_CAPLLIBS
176 | 1 "reportLockingSystemTester.vtestreport"
177 | 1 0 1
178 | 0
179 | 1 base=cfg ""
180 | 3
181 | VSimulinkModelViewerConfiguration 6 Begin_Of_Object
182 | 2
183 | 0 ""
184 | 0 ""
185 | 0 ""
186 | 150
187 | 0
188 | End_Of_Object VSimulinkModelViewerConfiguration 6
189 | 1
190 | 0
191 | 1
192 | 1
193 | VConfigurationBox 6 Begin_Of_Object
194 | 1
195 | VUniqueBox 7 Begin_Of_Object
196 | 1
197 | VBoxRoot 8 Begin_Of_Object
198 | 1
199 | 3
200 | 0 1 0 1 -1 -1 -1 -1 476 0 1106 548
201 |
202 | 1
203 |
204 | MDI_DOCK_INFO_END
205 | 5
206 | 1
207 | 6
208 | 0 1 -1 -1 -1 -1 476 0 1106 548
209 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
210 | END_OF_DOCK_INFO
211 | 1
212 | 2
213 | 1
214 | 0 1 -1 -1 -1 -1 400 292 1200 878
215 | 0
216 | 1
217 | 1272 560
218 | END_OF_DESKTOP_DATA
219 | 6
220 | 0 1 0 0 -1 -1 240 280 590 530
221 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
222 | END_OF_DOCK_INFO
223 | 0
224 | 2
225 | 1
226 | 0 1 -1 -1 -1 -1 400 292 1200 878
227 | 0
228 | 0
229 | 999 589
230 | END_OF_DESKTOP_DATA
231 | END_OF_DESKTOP_DATA_COLLECTION
232 | 0
233 | 0 1
234 | 1
235 | 6
236 | 0 1 0 0 -1 -1 240 280 590 530
237 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
238 | END_OF_DOCK_INFO
239 | 0
240 | -1
241 | 1
242 | 0 1 -1 -1 -1 -1 400 292 1200 878
243 | 0
244 | 0
245 | 0 0
246 | END_OF_DESKTOP_DATA
247 | 6
248 | 0 1 0 0 -1 -1 240 280 590 530
249 | 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -1 32767 0 0 0 0 0 0 0 0 0 0 -1 -1 0 0 0 0 0 0
250 | END_OF_DOCK_INFO
251 | 0
252 | -1
253 | 1
254 | 0 1 -1 -1 -1 -1 400 292 1200 878
255 | 0
256 | 0
257 | 0 0
258 | END_OF_DESKTOP_DATA
259 | END_OF_DESKTOP_DATA_COLLECTION
260 | 0
261 | END_OF_DESKTOP_MEMBER
262 | {330B2167-21A2-4518-9AC0-47E4AEA3CDD5}
263 | 0
264 | End_Of_Object VBoxRoot 8
265 | 1 -1 0 0 0 0 0 0 0 0 0 0
266 | End_Of_Object VUniqueBox 7
267 | 1
268 | End_Of_Object VConfigurationBox 6
269 | 1 "Testmodules\TestCaseLibrary2.cbf"
270 | NULL
271 | 0
272 | 0
273 | End_Of_Object VTestNode 5
274 | VTestModuleControllerXML 5 Begin_Of_Object
275 | 1
276 | VTestModuleController 6 Begin_Of_Object
277 | 3
278 | 1
279 | 0
280 | 0
281 | 0
282 | 0
283 | 0
284 | 1
285 | 0
286 | 0
287 | 0
288 | 0
289 | 0
290 | End_Of_Object VTestModuleController 6
291 | End_Of_Object VTestModuleControllerXML 5
292 | End_Of_Testcase_Exec_Flags
293 | Variant: A VariantEnd
294 | 1 base=cfg ""
295 | End_Of_Testcase_Exec_Flags_W
296 | Variant: A VariantEnd
297 | End_Of_Object VXmlTestNode 4
298 | TS_WRP_DATA_END
299 | End_Of_Object VTSWrapper 3
300 | 4
301 | 0
302 | 1
303 | TS_BUS_INFO_COLLECTION_END
304 | TS_CAPL_BLOCK_END
305 | End_Of_Object VTSProgrammedNode 2
306 | VTSFolder 2 Begin_Of_Object
307 | 1
308 | VTSItem 3 Begin_Of_Object
309 | 1
310 | 3 4244474890 0
311 | 1
312 | END_OF_ITEM_DATA
313 | End_Of_Object VTSItem 3
314 | 4
315 | Test Environment
316 | 1
317 | 4239567674
318 | 1 "sumreport.xml"
319 | END_OF_FILE_NAME
320 | 1 ""
321 | END_OF_FILE_NAME
322 | 3
323 | 1
324 | END_OF_FOLDER_DATA
325 | End_Of_Object VTSFolder 2
326 | 1
327 | 4244474890
328 | 2
329 | 1
330 | 4239567674
331 | 0
332 | 1
333 | 4244474890
334 | 1
335 | 4239567674
336 | End_Of_Object VTSPersistentRoot 1
337 |
--------------------------------------------------------------------------------
/canoe-automation/robot-framework/CANoe/base/canoe_keyword.robot:
--------------------------------------------------------------------------------
1 | *** Settings ***
2 | Library CANoe.py WITH NAME canoe
3 | *** Keywords ***
4 | Open Simulation
5 | [Arguments] ${CONFIGURATIONPATH}
6 | canoe.OPEN SIMULATION ${CONFIGURATIONPATH}
7 | Load TestSetup
8 | [Arguments] ${TESTSPECIFICATION}
9 | canoe.LOAD TESTSETUP ${TESTSPECIFICATION}
10 | Start Measurement
11 | canoe.START MEASUREMENT
12 | Start TestModule
13 | canoe.START TESTMODULE
14 | Stop Measurement
15 | canoe.STOP MEASUREMENT
16 | Waiting
17 | [Arguments] ${WAIT TIME}
18 | canoe.WAITING
--------------------------------------------------------------------------------
/canoe-automation/robot-framework/CANoe/base/canoe_usecase.robot:
--------------------------------------------------------------------------------
1 | *** Settings ***
2 | Resource canoe_keyword.robot
3 | Library DateTime
4 |
5 | *** Variables ***
6 | ${CONFIGURATIONPATH} E:/ancit-projects/canoe-autoit/CentralLockingSystem/CentralLockingSystem.cfg
7 | ${TESTSPECIFICATION} E:/ancit-projects/canoe-autoit/CentralLockingSystem/TestSetup.tse
8 |
9 |
10 | *** Test Cases ***
11 | Load Simulation and Run TestSetup
12 | Open Simulation ${CONFIGURATIONPATH}
13 | Load TestSetup ${TESTSPECIFICATION}
14 | # Load TestSetup ${TESTSPEC2}
15 | Start Measurement
16 | Start TestModule
17 | # Waiting 90
18 | # Stop Measurement
19 |
20 | # Run TestSetup
21 | # Start Measurement
22 | # Start TestModule
23 |
24 |
25 | # Load and Run TestSetup
26 | # Load TestSetup ${TESTSPEC2}
27 | # Start Measurement
28 | # Start TestModule
29 |
--------------------------------------------------------------------------------
/canoe-automation/robot-framework/README.md:
--------------------------------------------------------------------------------
1 | # CURF
2 |
3 | ## CAN UDS for Robot Framework
4 |
5 | ### CAN BUS with ISO-14229 implementation RobotFramework Library
6 |
7 | The goal of this Robotframework Library is testing CAN BUS with RobotFramework
8 |
9 | ## CAN, UDS and ISO-TP Reminder
10 |
11 | They are a lot of CAN protocols and it can be confusing.
12 |
13 | CAN (ISO-11898) was released in 1991 and the main limit is the size of payload (8 Bytes) by frame.
14 |
15 | ISO-TP (ISO 15765-2) TP means 'Transport Layer' was introducted in 2016. The main goal is the transfer of longer messages over CAN into multiples frames, adding metadata that allows the interpretation of individual frames and reassembly into a complete message packet by the recipient. It can carry up to 4095 bytes of payload per message packet.
16 |
17 | UDS (ISO 14229-1) Unified Diagnostic Services is a communication protocol, Unified means that is an international and not company specific standard. This standard use ISO-TP.
18 |
19 | ## Compatibility
20 |
21 | This RobotFramework library is cross-platform (tested under Debian9, and Windows 10)
22 |
23 | The library use [python-can](https://python-can.readthedocs.io/en/master/index.html) to support CAN interface the interfaces [linked here](https://python-can.readthedocs.io/en/master/interfaces.html) must be compatibles.
24 |
25 | The library use [isotp](https://can-isotp.readthedocs.io/en/latest/index.html) to handle ISO-15765 protocol
26 |
27 | The library use [cantools](https://cantools.readthedocs.io/en/latest/) to encoding/decoding CAN Database, see [here](https://cantools.readthedocs.io/en/latest/#functions-and-classes) to find compatible format
28 |
29 | ## Requirements
30 |
31 | They are a few dependencies, the library must work in Linux and Windows
32 |
33 | ```shell
34 | pip install robotframework
35 | pip install python-can
36 | pip install cantools
37 | pip install can-isotp
38 | ```
39 |
40 | ## Use
41 |
42 | See testsuite/test.robot
43 |
44 | All test must start with
45 |
46 | ```shell
47 | Set CAN Bus ${INTERFACE} ${CHANNEL} ${BITRATE} ${DB FILE}
48 | ```
49 |
50 | So the best can be to instanciate it with 'Test Setup'
51 |
52 | Before using ISO-TP/UDS specific keywords you must instanciate it as follow:
53 |
54 | ```shell
55 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
56 | ```
57 |
58 |
--------------------------------------------------------------------------------
/canoe-automation/robot-framework/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/canoe-automation/robot-framework/__init__.py
--------------------------------------------------------------------------------
/python-can-examples/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | python-can-examples
4 |
5 |
6 |
7 |
8 |
9 | org.python.pydev.PyDevBuilder
10 |
11 |
12 |
13 |
14 |
15 | org.python.pydev.pythonNature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/python-can-examples/.pydevproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | /${PROJECT_DIR_NAME}
7 | /${PROJECT_DIR_NAME}/python-can-newdbc-handling
8 |
9 |
10 |
11 | python interpreter
12 |
13 |
14 | python3
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/python-can-examples/basic-ecu-simulation/.~lock.usecasediagram.odp#:
--------------------------------------------------------------------------------
1 | ,ancit,ancit-ThinkPad-L450,25.03.2020 13:32,file:///home/ancit/.config/libreoffice/4;
--------------------------------------------------------------------------------
/python-can-examples/basic-ecu-simulation/BasicEngineECU.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | #
3 | # The "real" Motor node, transmitting the MotorStatus message
4 | # periodically.
5 | #
6 |
7 | import struct
8 | import can
9 |
10 | def create_message(speed, load):
11 | return can.Message(arbitration_id=0x010,
12 | extended_id=False,
13 | data=struct.pack('
2 |
3 |
4 | A washing machine.
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/python-can-examples/basic-ecu-simulation/system_MainBus.dbc:
--------------------------------------------------------------------------------
1 | VERSION "created by canmatrix"
2 |
3 |
4 | NS_ :
5 |
6 | BS_:
7 |
8 | BU_: Motor Controller
9 |
10 |
11 | BO_ 16 MotorStatus: 3 Motor
12 | SG_ MSSpeed : 0|16@1+ (1,0) [0|65535] "" Controller
13 | SG_ Load : 16|8@1+ (1,0) [0|255] "" Controller
14 |
15 | BO_ 17 MotorControl: 2 Controller
16 | SG_ MCSpeed : 0|16@1+ (1,0) [0|65535] "" Motor
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/python-can-examples/basic-ecu-simulation/usecasediagram.odp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-examples/basic-ecu-simulation/usecasediagram.odp
--------------------------------------------------------------------------------
/python-can-examples/output.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-examples/output.xml
--------------------------------------------------------------------------------
/python-can-examples/python-can-dbcmessages/LoadDBC.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import cantools
7 | from can.message import Message
8 | db = cantools.db.load_file('/home/bk/git/pythoncan-examples/python-can-examples/resources/motohawk.dbc')
9 | # print the content of the dbc
10 | print(db)
11 |
12 | # print a particular message in the dbc
13 | msg = db.get_message_by_name('ExampleMessage')
14 | print(msg)
15 | print(msg.cycle_time)
16 | print(msg.signal_tree)
17 | temperature_signal = msg.signals[2]
18 | print(temperature_signal)
19 | print(temperature_signal.scale)
20 | print(temperature_signal.offset)
--------------------------------------------------------------------------------
/python-can-examples/python-can-dbcmessages/ReceiveCANDBCMessage.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import cantools
7 | from can.message import Message
8 | db = cantools.db.load_file('/home/ancit/Documents/malai/python-workspace/python-can-examples/comfort.dbc')
9 |
10 | import can
11 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
12 | while True:
13 | message = bus.recv()
14 | print(db.decode_message(message.arbitration_id, message.data))
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-dbcmessages/SendCANDBCMessage.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import cantools
7 | from can.message import Message
8 | db = cantools.db.load_file('/home/bk/git/pythoncan-examples/python-can-examples/resources/motohawk.dbc')
9 |
10 | # print a particular message in the dbc
11 | msg = db.get_message_by_name('VehicleMotion')
12 | msg_data = msg.encode({'Velocity':4,'CrashDetected':1,'EngineRunning':1})
13 |
14 | import can
15 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
16 | msg = can.Message(arbitration_id=msg.frame_id,data=msg_data,is_extended_id=False)
17 | try:
18 | bus.send(msg)
19 | print("Message sent on {}".format(bus.channel_info))
20 | except can.CanError:
21 | print("Message NOT sent")
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-dbcmessages/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-examples/python-can-dbcmessages/__init__.py
--------------------------------------------------------------------------------
/python-can-examples/python-can-newdbc-handling/Basic_DBCinExcel.dbc:
--------------------------------------------------------------------------------
1 | VERSION "created by canmatrix"
2 |
3 |
4 | NS_ :
5 |
6 | BS_:
7 |
8 | BU_:
9 |
10 |
11 | BO_ 257 SeatbeltMsg: 8 Vector__XXX
12 | SG_ SeatbeltStatus : 7|1@0+ (1,0) [0|1] "" Vector__XXX
13 |
14 | BO_ 258 AirbagMsg: 8 Vector__XXX
15 | SG_ AirbagStatus : 6|2@0+ (1,0) [0|3] "" Vector__XXX
16 | SG_ AirbagCondition : 4|1@0+ (1,0) [0|1] "" Vector__XXX
17 |
18 | BO_ 260 VehicleMotion: 8 Vector__XXX
19 | SG_ CrashDetected : 3|1@0+ (1,0) [0|1] "" Vector__XXX
20 | SG_ EngineRunning : 2|1@0+ (1,0) [0|1] "" Vector__XXX
21 | SG_ Velocity : 15|16@0+ (0.1,0) [0|65535] "km/h" Vector__XXX
22 |
23 | BO_ 261 BrakeMsg: 8 Vector__XXX
24 | SG_ BrakeStatus : 1|1@0+ (1,0) [0|1] "" Vector__XXX
25 |
26 | BO_ 262 AccelarationMsg: 8 Vector__XXX
27 | SG_ Acceleration : 31|16@0+ (0.1,0) [0|65535] "m/s2" Vector__XXX
28 |
29 |
30 |
31 | CM_ SG_ 257 SeatbeltStatus "Status of wether Seatbelt is worn or not";
32 | CM_ SG_ 258 AirbagStatus "Echos the state of the Airbag Condition";
33 | CM_ SG_ 258 AirbagCondition "state of the Airbag Health";
34 | CM_ SG_ 260 CrashDetected "Status of wether crash is detected or not";
35 | CM_ SG_ 260 EngineRunning "Echos Engine Running Status";
36 | CM_ SG_ 260 Velocity "Value of the Vehicles Velocity";
37 | CM_ SG_ 261 BrakeStatus "Status of wether Brake is applied or not";
38 | CM_ SG_ 262 Acceleration "Value of the Acceleration Applaid";
39 |
40 |
41 | BA_DEF_ BO_ "GenMsgCycleTimeActive" INT 0 65535;
42 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 65535;
43 | BA_DEF_ BO_ "GenMsgNrOfRepetitions" INT 0 65535;
44 | BA_DEF_ BO_ "GenMsgSendType" ENUM;
45 | BA_DEF_ SG_ "GenSigSNA" STRING;
46 |
47 |
48 |
49 |
50 | VAL_ 257 SeatbeltStatus 0 "Worn" 1 "NotWorn";
51 | VAL_ 258 AirbagStatus 0 "Ready" 1 "NotReady" 2 "Released";
52 | VAL_ 258 AirbagCondition 0 "Healthy" 1 "Damage";
53 | VAL_ 260 CrashDetected 0 "Crash" 1 "CrashFree";
54 | VAL_ 260 EngineRunning 0 "NotRunning" 1 "Running";
55 | VAL_ 261 BrakeStatus 0 "BrakeApplied" 1 "NotWorn";
56 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-newdbc-handling/Basic_DBCinExcel.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-examples/python-can-newdbc-handling/Basic_DBCinExcel.xlsx
--------------------------------------------------------------------------------
/python-can-examples/python-can-newdbc-handling/LoadDBC.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import cantools
7 | from can.message import Message
8 | db = cantools.db.load_file('/home/bk/git/pythoncan-examples/python-can-examples/python-can-newdbc-handling/Basic_DBCinExcel.dbc')
9 | # print the content of the dbc
10 | #print(db)
11 |
12 | #print a particular message in the dbc
13 | msg = db.get_message_by_name('BrakeMsg')
14 | print(msg)
15 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-newdbc-handling/ReceiveCANDBCMessage.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import cantools
7 | from can.message import Message
8 | db = cantools.db.load_file('/home/bk/git/pythoncan-examples/python-can-examples/python-can-newdbc-handling/Basic_DBCinExcel.dbc')
9 |
10 | import can
11 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
12 | while True:
13 | message = bus.recv()
14 | print(db.decode_message(message.arbitration_id, message.data))
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-newdbc-handling/SendCANDBCMessage.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import cantools
7 | from can.message import Message
8 | db = cantools.db.load_file('/home/bk/git/pythoncan-examples/python-can-examples/python-can-newdbc-handling/Basic_DBCinExcel.dbc')
9 |
10 | # print a particular message in the dbc
11 | msg = db.get_message_by_name('SeatbeltMsg')
12 | msg_data = msg.encode({'SeatbeltStatus':0})
13 |
14 | import can
15 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
16 | msg = can.Message(arbitration_id=msg.frame_id,data=msg_data,is_extended_id=False)
17 | try:
18 | bus.send(msg)
19 | print("Message sent on {}".format(bus.channel_info))
20 | except can.CanError:
21 | print("Message NOT sent")
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/ReceiveCANRawMessage.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import can
7 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
8 | while True:
9 | message = bus.recv()
10 | print(message)
11 |
12 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/SendCANRawMessage.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import can
7 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
8 | msg = can.Message(arbitration_id=0x021,data=[0, 25, 0, 1, 3, 1, 4, 1],is_extended_id=False)
9 | try:
10 | bus.send(msg)
11 | print("Message sent on {}".format(bus.channel_info))
12 | except can.CanError:
13 | print("Message NOT sent")
14 |
15 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/SendMessageOnKeyPress.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import time
3 |
4 | import can
5 | from pynput import keyboard
6 |
7 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
8 |
9 | def on_press(key):
10 | if key.char == 'a': # handles if key press is shift
11 | msg = can.Message(arbitration_id=0xffee,data=[0, 25, 0, 1, 3, 1, 4, 1],is_extended_id=False)
12 | try:
13 | bus.send(msg)
14 | print("Message sent on {}".format(bus.channel_info))
15 | except can.CanError:
16 | print("Message NOT sent")
17 |
18 | if key.char == 'b': # handles if key press is shift
19 | msg = can.Message(arbitration_id=0xc0ffee,data=[0, 0, 0, 1, 3, 1, 4, 1],is_extended_id=False)
20 | task.modify_data(msg)
21 |
22 | def get_current_key_input():
23 | with keyboard.Listener(on_press=on_press) as listener:
24 | listener.join()
25 |
26 |
27 | msg = can.Message(arbitration_id=0xc0ffee,data=[0, 25, 0, 0, 0, 0, 0, 0],is_extended_id=False)
28 | try:
29 | task = bus.send_periodic(msg,0.2)
30 | print("Message sent on {}".format(bus.channel_info))
31 | except can.CanError:
32 | print("Message NOT sent")
33 |
34 | get_current_key_input()
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/SendMessageOnKeyPressAndReceive.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import time
3 | import threading
4 | import can
5 | from pynput import keyboard
6 |
7 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
8 |
9 | def on_press(key):
10 | if key.char == 'a': # handles if key press is shift
11 | msg = can.Message(arbitration_id=0xffee,data=[0, 25, 0, 1, 3, 1, 4, 1],is_extended_id=False)
12 | try:
13 | bus.send(msg)
14 | print("Message sent on {}".format(bus.channel_info))
15 | except can.CanError:
16 | print("Message NOT sent")
17 |
18 | if key.char == 'b': # handles if key press is shift
19 | msg = can.Message(arbitration_id=0xc0ffee,data=[0, 0, 0, 1, 3, 1, 4, 1],is_extended_id=False)
20 | task.modify_data(msg)
21 |
22 | def get_current_key_input():
23 | keyboard.Listener(on_press=on_press).start()
24 |
25 |
26 | def thread_function(name):
27 | while True:
28 | message = bus.recv()
29 | print(message)
30 |
31 |
32 | msg = can.Message(arbitration_id=0xc0ffee,data=[0, 25, 0, 0, 0, 0, 0, 0],is_extended_id=False)
33 | try:
34 | task = bus.send_periodic(msg,0.2)
35 | print("Message sent on {}".format(bus.channel_info))
36 | except can.CanError:
37 | print("Message NOT sent")
38 |
39 | get_current_key_input()
40 |
41 | x = threading.Thread(target=thread_function, args=(1,))
42 | print("Main : before running thread")
43 | x.start()
44 |
45 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/SendMessagePeriodic.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 24-Mar-2020
3 |
4 | @author: ancit
5 | '''
6 | import can
7 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
8 | msg = can.Message(arbitration_id=0xc0ffee,data=[0, 25, 0, 1, 3, 1, 4, 1],is_extended_id=False)
9 | try:
10 | bus.send_periodic(msg,0.2)
11 | print("Message sent on {}".format(bus.channel_info))
12 | except can.CanError:
13 | print("Message NOT sent")
14 |
15 |
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/TesterNode.py:
--------------------------------------------------------------------------------
1 | import can
2 | import cantools
3 |
4 | dbc = cantools.database.load_file('/home/ancit/Documents/malai/Antitheft.dbc')
5 | can_bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=1000000)
6 | tester = cantools.tester.Tester('TransmitNode', dbc, can_bus, None)
7 |
8 | tester.start()
9 | status = tester.expect('Ant_VehicleMotion', signals=['Ant_EngineRunning'], timeout=None, discard_other_messages=False)
10 | print(status)
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-examples/python-can-rawmessages/__init__.py
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/images/candump.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-examples/python-can-rawmessages/images/candump.png
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/images/vcansetup.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-examples/python-can-rawmessages/images/vcansetup.png
--------------------------------------------------------------------------------
/python-can-examples/python-can-rawmessages/readme.md:
--------------------------------------------------------------------------------
1 |
2 | # Configuring VCAN [Virtual CAN] in Linux
3 |
4 |
5 | * $ sudo modprobe vcan
6 | * $ sudo ip link add dev vcan0 type vcan
7 | * $ sudo ip link set up vcan0
8 |
9 |
10 | ## SendCANRawMessage.py
11 | This Python Module would send 1 CAN Message on vcan0
12 |
13 |
14 | ## SendMessagePeriodic.py
15 |
16 | This Python Module would send CAN Message on vcan0 in a cyclic mode
17 |
18 | * How to run Periodic Messages
19 | Go to Python Shell and execute exec(open('filepath').read())
20 |
21 |
22 | ## ReceiveCANRawMessage.py
23 |
24 | This is a Python Module for receiving all the messages on the Bus
25 |
26 | ## LoadDBC.py
27 | * Load the DBC
28 | * Print the DBC Content
29 | * Select a particular message in the DBC
30 | * Print the Message Content
31 |
32 |
33 | ## SendCANDBCMessage.py
34 | This module is used to Send Message thru DBC Encoding
35 | * Load the DBC
36 | * Get the desired Message [db.get_message_by_name('VehicleMotion')]
37 | * encode the message with data [msg.encode({'Velocity':4,'CrashDetected':1,'EngineRunning':1})]
38 | * send on the can bus
39 |
40 |
41 | ## Receive Message thru CANDUMP using DBC Decoding
42 | candump vcan0 | cantools decode /home/ancit/Documents/malai/python-workspace/python-can-examples/comfort.dbc
43 |
44 | ## Text based UI for CANDUMP
45 | $ cantools monitor tests/files/dbc/motohawk.dbc
46 |
47 | Has options to filter, play, pause, reset whereas candump doesnt have these options
48 |
49 | ## ReceiveCANDBCMessage.py
50 | This module is used to Receive Message thru DBC Decoding
51 |
--------------------------------------------------------------------------------
/python-can-examples/readme.md:
--------------------------------------------------------------------------------
1 | ## Installation
2 |
3 | By default all Ubuntu installation come with Python2.6.2
4 | Python3 needs to be installed
5 |
6 | ```shell
7 | sudo apt-get update
8 | sudo apt-get install python3.8
9 | ```
10 |
11 | Pip3 needs to be installed
12 |
13 | ```shell
14 | sudo apt-get install python3-pip
15 | ```
16 |
17 | If you have more than 1 version of Python3 installed in Linux
18 | We need to point Python3 to Python3.8 installation
19 |
20 | ```shell
21 | sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
22 | sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
23 | ```
24 |
25 | ```shell
26 | sudo update-alternatives --config python3
27 | ```
28 |
29 | Running the above command should bring up the list of Python3 installed and show you the automode. Press 2
30 |
31 | Few python dependencies that you need to install to continue further. These libraries work in Linux and Windows
32 | Python3 installation would be preferred.
33 |
34 | ```shell
35 | pip3 install robotframework
36 | pip3 install python-can
37 | pip3 install cantools
38 | pip3 install can-isotp
39 | pip3 install canmatrix
40 | ```
41 | # Configuring VCAN [Virtual CAN] in Linux
42 |
43 | * $ sudo modprobe vcan
44 | * $ sudo ip link add dev vcan0 type vcan
45 | * $ sudo ip link set up vcan0
46 |
47 | Contains Python examples for CAN protocol
48 |
49 | can-utils
50 |
51 | candump [Listens to CANBUS]
52 | cansend [Sends CAN Message on CANBUS]
53 | cangen [Sends Random CAN Messages on CANBUS]
54 | cansniffer [Similar to candump]
55 | canmonitor [Textual UI for candump >> Filter, Clear]
56 |
57 | Python >> CAN Raw Message Send and Receive CAN Raw Message Periodic Send
58 |
59 | cantools
60 |
61 | It works on DBC / ARXML / KCD
62 | Load DBC -> Message and Signal
63 | Send CAN Message using DBC Encoding and Receive thru DBC Decoding thru Python
64 | candump | cantools
65 | tester node : Unit Testing : HTML Report
66 |
67 | robot framework
68 |
69 | canisotp, cantools, uds
70 | python : libraries functions
71 | keyword robot : Language : keyword robot will inturn invoke the python libraries
72 | test robot : Should follow the syntax of the keyword robot
73 |
--------------------------------------------------------------------------------
/python-can-examples/resources/comfort.dbc:
--------------------------------------------------------------------------------
1 | VERSION ""
2 |
3 |
4 | NS_ :
5 | NS_DESC_
6 | CM_
7 | BA_DEF_
8 | BA_
9 | VAL_
10 | CAT_DEF_
11 | CAT_
12 | FILTER
13 | BA_DEF_DEF_
14 | EV_DATA_
15 | ENVVAR_DATA_
16 | SGTYPE_
17 | SGTYPE_VAL_
18 | BA_DEF_SGTYPE_
19 | BA_SGTYPE_
20 | SIG_TYPE_REF_
21 | VAL_TABLE_
22 | SIG_GROUP_
23 | SIG_VALTYPE_
24 | SIGTYPE_VALTYPE_
25 | BO_TX_BU_
26 | BA_DEF_REL_
27 | BA_REL_
28 | BA_DEF_DEF_REL_
29 | BU_SG_REL_
30 | BU_EV_REL_
31 | BU_BO_REL_
32 | SG_MUL_VAL_
33 |
34 | BS_:
35 |
36 | BU_: SUT_Driver SUT
37 |
38 |
39 | BO_ 1536 DiagResponse: 8 Vector__XXX
40 |
41 | BO_ 1792 DiagRequest: 8 Vector__XXX
42 |
43 | BO_ 1 LockingRemoteControlRequest: 1 SUT_Driver
44 | SG_ LockRequest : 0|2@1+ (1,0) [0|0] "" SUT
45 |
46 | BO_ 0 CentralLockingSystemState: 1 SUT
47 | SG_ AntiTheftSystemActive : 1|1@1+ (1,2) [2|10] "" Vector__XXX
48 | SG_ LockState : 0|1@1+ (2,3) [3|5] "" Vector__XXX
49 |
50 | BO_ 50 VehicleMotion: 3 SUT_Driver
51 | SG_ EngineRunning : 17|1@1+ (3,0) [1|3] "" Vector__XXX
52 | SG_ CrashDetected : 16|1@1+ (1,0) [0|0] "" SUT
53 | SG_ Velocity : 0|16@1- (3,0) [1|4] "" SUT
54 |
55 | BO_ 100 WindowState: 2 SUT
56 | SG_ WindowPosition : 0|8@1+ (1,0) [0|255] "" Vector__XXX
57 | SG_ WindowMotion : 14|2@1+ (1,0) [0|0] "" Vector__XXX
58 |
59 | BO_ 101 WindowControl: 1 SUT_Driver
60 | SG_ KeyDown : 1|1@1+ (1,0) [0|0] "" SUT
61 | SG_ KeyUp : 0|1@1+ (1,0) [0|1] "" SUT
62 |
63 |
64 |
65 | EV_ DoorClosed: 0 [0|1] "" 0 1 DUMMY_NODE_VECTOR0 Vector__XXX;
66 |
67 | EV_ rbbpPowermode: 0 [0|5] "" 0 2 DUMMY_NODE_VECTOR0 Vector__XXX;
68 |
69 | BA_DEF_ "NmMessageCount" INT 0 0;
70 | BA_DEF_ BO_ "DiagResponse" ENUM "No","Yes";
71 | BA_DEF_ BO_ "DiagRequest" ENUM "No","Yes";
72 | BA_DEF_ BO_ "GenMsgFastOnStart" INT 0 0;
73 | BA_DEF_ BO_ "GenMsgStartDelayTime" INT 0 0;
74 | BA_DEF_ SG_ "NWM-WakeupAllowed" ENUM "No","Yes";
75 | BA_DEF_ BO_ "NmMessage" ENUM "no","yes";
76 | BA_DEF_ BO_ "GenMsgILSupport" ENUM "No","Yes";
77 | BA_DEF_ BU_ "NmNode" ENUM "no","yes";
78 | BA_DEF_ BU_ "NmStationAddress" INT 0 63;
79 | BA_DEF_ "NmBaseAddress" HEX 1024 1087;
80 | BA_DEF_ BO_ "GenMsgCycleTimeFast" INT 0 50000;
81 | BA_DEF_ "BusType" STRING ;
82 | BA_DEF_ BO_ "GenMsgCycleTime" INT 0 50000;
83 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 1000;
84 | BA_DEF_ BO_ "GenMsgNrOfRepetition" INT 0 999999;
85 | BA_DEF_ BO_ "GenMsgSendType" ENUM "Cyclic","NotUsed","NotUsed","NotUsed","NotUsed","Cyclic","NotUsed","IfActive","NoMsgSendType","NotUsed","vector_leerstring";
86 | BA_DEF_ SG_ "GenSigInactiveValue" INT 0 100000;
87 | BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType","NotUsed","NotUsed","NotUsed","NotUsed","NotUsed";
88 | BA_DEF_ SG_ "GenSigStartValue" FLOAT 0 100000000000;
89 | BA_DEF_DEF_ "NmMessageCount" 64;
90 | BA_DEF_DEF_ "DiagResponse" "No";
91 | BA_DEF_DEF_ "DiagRequest" "No";
92 | BA_DEF_DEF_ "GenMsgFastOnStart" 0;
93 | BA_DEF_DEF_ "GenMsgStartDelayTime" 0;
94 | BA_DEF_DEF_ "NWM-WakeupAllowed" "";
95 | BA_DEF_DEF_ "NmMessage" "no";
96 | BA_DEF_DEF_ "GenMsgILSupport" "Yes";
97 | BA_DEF_DEF_ "NmNode" "no";
98 | BA_DEF_DEF_ "NmStationAddress" 0;
99 | BA_DEF_DEF_ "NmBaseAddress" 1024;
100 | BA_DEF_DEF_ "GenMsgCycleTimeFast" 0;
101 | BA_DEF_DEF_ "BusType" "CAN";
102 | BA_DEF_DEF_ "GenMsgCycleTime" 100;
103 | BA_DEF_DEF_ "GenMsgDelayTime" 0;
104 | BA_DEF_DEF_ "GenMsgNrOfRepetition" 0;
105 | BA_DEF_DEF_ "GenMsgSendType" "NoMsgSendType";
106 | BA_DEF_DEF_ "GenSigInactiveValue" 0;
107 | BA_DEF_DEF_ "GenSigSendType" "Cyclic";
108 | BA_DEF_DEF_ "GenSigStartValue" 0;
109 | BA_ "DiagResponse" BO_ 1536 1;
110 | BA_ "DiagRequest" BO_ 1792 1;
111 | BA_ "GenMsgDelayTime" BO_ 101 18;
112 | BA_ "GenMsgNrOfRepetition" BO_ 101 2;
113 | BA_ "GenMsgCycleTimeFast" BO_ 101 20;
114 | BA_ "GenMsgCycleTime" BO_ 101 500;
115 | BA_ "GenMsgSendType" BO_ 101 0;
116 | BA_ "GenSigSendType" SG_ 1 LockRequest 1;
117 | BA_ "GenSigStartValue" SG_ 0 AntiTheftSystemActive 6;
118 | BA_ "GenSigStartValue" SG_ 0 LockState 0.5;
119 | BA_ "GenSigStartValue" SG_ 50 EngineRunning 0.666666666666667;
120 | BA_ "GenSigSendType" SG_ 50 CrashDetected 1;
121 | BA_ "GenSigStartValue" SG_ 50 Velocity 1;
122 | BA_ "GenSigStartValue" SG_ 100 WindowPosition 3;
123 | BA_ "GenSigSendType" SG_ 100 WindowMotion 1;
124 | BA_ "GenSigSendType" SG_ 101 KeyDown 6;
125 | BA_ "GenSigSendType" SG_ 101 KeyUp 6;
126 | BA_ "GenSigStartValue" SG_ 101 KeyUp 1;
127 | VAL_ 1 LockRequest 3 "Comfort_lock" 2 "Request_unlock" 1 "Request_lock" 0 "idle" ;
128 | VAL_ 0 AntiTheftSystemActive 2 "currently_opening" 1 "currently_closing" 0 "not_moving" ;
129 | VAL_ 0 LockState 2 "currently_opening" 1 "currently_closing" 0 "not_moving" ;
130 | VAL_ 100 WindowMotion 2 "currently_opening" 1 "currently_closing" 0 "not_moving" ;
131 |
132 |
--------------------------------------------------------------------------------
/python-can-examples/resources/motohawk.dbc:
--------------------------------------------------------------------------------
1 | VERSION "1.0"
2 |
3 |
4 | NS_ :
5 | NS_DESC_
6 | CM_
7 | BA_DEF_
8 | BA_
9 | VAL_
10 | CAT_DEF_
11 | CAT_
12 | FILTER
13 | BA_DEF_DEF_
14 | EV_DATA_
15 | ENVVAR_DATA_
16 | SGTYPE_
17 | SGTYPE_VAL_
18 | BA_DEF_SGTYPE_
19 | BA_SGTYPE_
20 | SIG_TYPE_REF_
21 | VAL_TABLE_
22 | SIG_GROUP_
23 | SIG_VALTYPE_
24 | SIGTYPE_VALTYPE_
25 | BO_TX_BU_
26 | BA_DEF_REL_
27 | BA_REL_
28 | BA_DEF_DEF_REL_
29 | BU_SG_REL_
30 | BU_EV_REL_
31 | BU_BO_REL_
32 | SG_MUL_VAL_
33 |
34 | BS_:
35 |
36 | BU_: PCM1 FOO
37 |
38 |
39 | BO_ 496 ExampleMessage: 8 PCM1
40 | SG_ Temperature : 0|12@0- (0.01,250) [229.52|270.47] "degK" PCM1,FOO
41 | SG_ AverageRadius : 6|6@0+ (0.1,0) [0|5] "m" Vector__XXX
42 | SG_ Enable : 7|1@0+ (1,0) [0|0] "-" Vector__XXX
43 |
44 |
45 |
46 |
47 | CM_ BO_ 496 "Example message used as template in MotoHawk models.";
48 |
49 |
50 |
51 | VAL_ 496 Enable 0 "Disabled" 1 "Enabled" ;
52 |
53 |
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/CURF/base/averagetime.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import time
3 |
4 |
5 | class AverageTime:
6 | """ AverageTime calculate the average time between given ticks
7 | The precision can go to 100µs between two ticks, faster it
8 | will be unprecise
9 | """
10 |
11 | def __init__(self):
12 | """Instanciate a AverageTime object
13 | """
14 | self.tick = time.time()
15 | self.last_tick = time.time()
16 | self.time_array = []
17 | self.average = 0
18 | self.isnew = 1
19 |
20 | def put_tick(self):
21 | """ Add a tick
22 | """
23 | if self.isnew == 1:
24 | self.tick = time.time()
25 | self.isnew = 0
26 | else:
27 | self.last_tick = time.time()
28 | time_elapsed = self.last_tick - self.tick
29 | self.time_array.append(time_elapsed)
30 | self.tick = time.time()
31 |
32 | def get_average(self):
33 | """ Return average time between ticks
34 | """
35 | self.average = sum(self.time_array)/float(len(self.time_array))
36 | return self.average
37 |
38 | def get_list(self):
39 | """ Return list of elapsed times
40 | """
41 | return self.time_array
42 |
43 | def clean_list(self):
44 | """ Clean the list
45 | """
46 | self.time_array = []
47 |
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/CURF/dbc/Example.dbc:
--------------------------------------------------------------------------------
1 | VERSION ""
2 |
3 | NS_ :
4 | BA_
5 | BA_DEF_
6 | BA_DEF_DEF_
7 | BA_DEF_DEF_REL_
8 | BA_DEF_REL_
9 | BA_DEF_SGTYPE_
10 | BA_REL_
11 | BA_SGTYPE_
12 | BO_TX_BU_
13 | BU_BO_REL_
14 | BU_EV_REL_
15 | BU_SG_REL_
16 | CAT_
17 | CAT_DEF_
18 | CM_
19 | ENVVAR_DATA_
20 | EV_DATA_
21 | FILTER
22 | NS_DESC_
23 | SGTYPE_
24 | SGTYPE_VAL_
25 | SG_MUL_VAL_
26 | SIGTYPE_VALTYPE_
27 | SIG_GROUP_
28 | SIG_TYPE_REF_
29 | SIG_VALTYPE_
30 | VAL_
31 | VAL_TABLE_
32 |
33 | BS_:
34 |
35 | BU_: DBG DRIVER IO MOTOR SENSOR
36 |
37 |
38 | BO_ 100 DRIVER_HEARTBEAT: 1 DRIVER
39 | SG_ DRIVER_HEARTBEAT_cmd : 0|8@1+ (1,0) [0|0] "" SENSOR,MOTOR
40 |
41 | BO_ 500 IO_DEBUG: 4 IO
42 | SG_ IO_DEBUG_test_unsigned : 0|8@1+ (1,0) [0|0] "" DBG
43 | SG_ IO_DEBUG_test_enum : 8|8@1+ (1,0) [0|0] "" DBG
44 | SG_ IO_DEBUG_test_signed : 16|8@1- (1,0) [0|0] "" DBG
45 | SG_ IO_DEBUG_test_float : 24|8@1+ (0.5,0) [0|0] "" DBG
46 |
47 | BO_ 101 MOTOR_CMD: 1 DRIVER
48 | SG_ MOTOR_CMD_steer : 0|4@1- (1,-5) [-5|5] "" MOTOR
49 | SG_ MOTOR_CMD_drive : 4|4@1+ (1,0) [0|9] "" MOTOR
50 |
51 | BO_ 400 MOTOR_STATUS: 3 MOTOR
52 | SG_ MOTOR_STATUS_wheel_error : 0|1@1+ (1,0) [0|0] "" DRIVER,IO
53 | SG_ MOTOR_STATUS_speed_kph : 8|16@1+ (0.001,0) [0|0] "kph" DRIVER,IO
54 |
55 | BO_ 200 SENSOR_SONARS: 8 SENSOR
56 | SG_ SENSOR_SONARS_mux M : 0|4@1+ (1,0) [0|0] "" DRIVER,IO
57 | SG_ SENSOR_SONARS_err_count : 4|12@1+ (1,0) [0|0] "" DRIVER,IO
58 | SG_ SENSOR_SONARS_left m0 : 16|12@1+ (0.1,0) [0|0] "" DRIVER,IO
59 | SG_ SENSOR_SONARS_middle m0 : 28|12@1+ (0.1,0) [0|0] "" DRIVER,IO
60 | SG_ SENSOR_SONARS_right m0 : 40|12@1+ (0.1,0) [0|0] "" DRIVER,IO
61 | SG_ SENSOR_SONARS_rear m0 : 52|12@1+ (0.1,0) [0|0] "" DRIVER,IO
62 | SG_ SENSOR_SONARS_no_filt_left m1 : 16|12@1+ (0.1,0) [0|0] "" DBG
63 | SG_ SENSOR_SONARS_no_filt_middle m1 : 28|12@1+ (0.1,0) [0|0] "" DBG
64 | SG_ SENSOR_SONARS_no_filt_right m1 : 40|12@1+ (0.1,0) [0|0] "" DBG
65 | SG_ SENSOR_SONARS_no_filt_rear m1 : 52|12@1+ (0.1,0) [0|0] "" DBG
66 |
67 |
68 |
69 |
70 | CM_ BU_ DRIVER "The driver controller driving the car";
71 | CM_ BU_ MOTOR "The motor controller of the car";
72 | CM_ BU_ SENSOR "The sensor controller of the car";
73 | CM_ BO_ 100 "Sync message used to synchronize the controllers";
74 |
75 | BA_DEF_ "BusType" STRING ;
76 | BA_DEF_ BO_ "GenMsgCycleTime" INT 0 0;
77 | BA_DEF_ SG_ "FieldType" STRING ;
78 |
79 | BA_DEF_DEF_ "BusType" "CAN";
80 | BA_DEF_DEF_ "FieldType" "";
81 | BA_DEF_DEF_ "GenMsgCycleTime" 0;
82 |
83 | BA_ "GenMsgCycleTime" BO_ 100 1000;
84 | BA_ "GenMsgCycleTime" BO_ 500 100;
85 | BA_ "GenMsgCycleTime" BO_ 101 100;
86 | BA_ "GenMsgCycleTime" BO_ 400 100;
87 | BA_ "GenMsgCycleTime" BO_ 200 100;
88 | BA_ "FieldType" SG_ 100 DRIVER_HEARTBEAT_cmd "DRIVER_HEARTBEAT_cmd";
89 | BA_ "FieldType" SG_ 500 IO_DEBUG_test_enum "IO_DEBUG_test_enum";
90 |
91 |
92 | VAL_ 100 DRIVER_HEARTBEAT_cmd 2 "DRIVER_HEARTBEAT_cmd_REBOOT" 1 "DRIVER_HEARTBEAT_cmd_SYNC" 0 "DRIVER_HEARTBEAT_cmd_NOOP" ;
93 | VAL_ 500 IO_DEBUG_test_enum 2 "IO_DEBUG_test2_enum_two" 1 "IO_DEBUG_test2_enum_one" ;
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/CURF/outputs/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/CURF/testsuite/canIsoTP.robot:
--------------------------------------------------------------------------------
1 | *** Settings ***
2 | Resource ../keywords/curf.robot
3 | Test Setup Set CAN Bus ${INTERFACE} ${CHANNEL} ${BITRATE} ${DB FILE}
4 | Test Teardown End Log Can
5 | Library DateTime
6 |
7 | *** Variables ***
8 | ${DB FILE} dbc/Example.dbc
9 | ${INTERFACE} socketcan
10 | ${CHANNEL} can0
11 | ${BITRATE} 500000
12 | ${DEFAULT TIMEOUT} 3
13 | ${DEFAULT NODE} DRIVER
14 | ${SOURCE} F1
15 | ${DESTINATION} 04
16 | ${ADDRESSING MODE} NormalFixed_29bits
17 |
18 | *** Test Cases ***
19 |
20 | Test session change
21 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
22 | Send DIAG Request 1002
23 | Diag Response Must Start With 5002
24 |
25 | Disable DTC records
26 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
27 | Send DIAG Request 8502
28 | Diag Response Must Be C502
29 |
30 | Log the next ISO-TP frame
31 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
32 | ${RES} = Get Next DIAG Frame
33 | Log ${RES}
34 |
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/CURF/testsuite/canRaw.robot:
--------------------------------------------------------------------------------
1 | *** Settings ***
2 | Resource ../keywords/curf.robot
3 | Test Setup Set CAN Bus ${INTERFACE} ${CHANNEL} ${BITRATE} ${DB FILE}
4 | Test Teardown End Log Can
5 | Library DateTime
6 |
7 | *** Variables ***
8 | ${DB FILE} /home/ancit/Documents/malai/robotframework-can-uds-library-master/CURF/dbc/Example.dbc
9 | ${INTERFACE} socketcan
10 | ${CHANNEL} vcan0
11 | ${BITRATE} 500000
12 | ${DEFAULT TIMEOUT} 3
13 | ${DEFAULT NODE} DRIVER
14 |
15 |
16 | *** Test Cases ***
17 | Log Next Raw Frame
18 | ${Next_Frame} = Get Next Raw Can Frame
19 | Log ${Next_Frame}
20 |
21 | Check reception of message
22 | Check The Reception Of SENSOR_SONARS TimeOut ${DEFAULT TIMEOUT} Seconds
23 |
24 | Check non reception of message
25 | Check Message MOTOR_CMD TimeOut ${DEFAULT TIMEOUT} Seconds Is Not Received
26 |
27 | Check reception of message in a given node
28 | Check The Reception Of SENSOR_SONARS TimeOut ${DEFAULT TIMEOUT} Seconds In Node ${DEFAULT NODE}
29 |
30 | Check non reception of message in a given node
31 | Check Message SENSOR_SONARS TimeOut ${DEFAULT TIMEOUT} Seconds Is Not Received In Node ${DEFAULT NODE}
32 |
33 | Send a CAN frame
34 | Send Frame With ID 0x5D3 And DEADBEEF As Data
35 |
36 | Send a given signal
37 | Send Signal SENSOR_SONARS_err_count With Value 0
38 |
39 | Check reception of a frame
40 | Check The Frame Reception With ID 5D3 And 0x0 As Data Timeout ${DEFAULT TIMEOUT} Seconds
41 |
42 | Check reception of a frame with given ID and any data
43 | Check The Frame Reception With ID 5D3 And ANY As Data Timeout ${DEFAULT TIMEOUT} Seconds
44 |
45 | Send periodic message
46 | Start Transmission Of Message SENSOR_SONARS Without Data With 1 Seconds Period
47 | Waiting 5 Seconds
48 | Start Transmission Of Message MOTOR_STATUS And 2 As Data With 1 Seconds Period
49 | Waiting 5 Seconds
50 | Stop Transmission Of Messages
51 |
52 | Send periodic signal
53 | Start Transmission Of Signal SENSOR_SONARS_middle And 0 As Value With 1 Seconds Period
54 | Waiting 5 Seconds
55 | Stop Transmission Of Messages
56 |
57 | Check the reception of a CAN signal
58 | Check CAN Signal SENSOR_SONARS_middle Equals To 0 TimeOut ${DEFAULT TIMEOUT} Seconds
59 |
60 | Check the non reception of a CAN signal
61 | Check CAN Signal SENSOR_SONARS_err_count Is Not Received In Timeout ${DEFAULT TIMEOUT} Seconds
62 |
63 | Check the periodicity of a frame with a given ID
64 | Check Frame ID 0x5D3 For 10 Times Expect Period 1 Seconds
65 |
66 |
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/CURF/testsuite/canUDS.robot:
--------------------------------------------------------------------------------
1 | *** Settings ***
2 | Resource ../keywords/curf.robot
3 | Test Setup Set CAN Bus ${INTERFACE} ${CHANNEL} ${BITRATE} ${DB FILE}
4 | Test Teardown End Log Can
5 | Library DateTime
6 |
7 | *** Variables ***
8 | ${DB FILE} dbc/Example.dbc
9 | ${INTERFACE} socketcan
10 | ${CHANNEL} can0
11 | ${BITRATE} 500000
12 | ${DEFAULT TIMEOUT} 3
13 | ${DEFAULT NODE} DRIVER
14 | ${SOURCE} F1
15 | ${DESTINATION} 04
16 | ${ADDRESSING MODE} NormalFixed_29bits
17 | ${CONST1} 0x9735A267
18 | ${CONST2} 0x1F5C2C27
19 | *** Test Cases ***
20 | Clear diagnostic information
21 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
22 | Clear All Diagnostic Information
23 |
24 | Reset the ECU
25 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
26 | Reset ECU
27 |
28 | Log a VehicleManufacturerSparePartNumber
29 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
30 | ${RES} = Report DID F187
31 | Log ${RES}
32 |
33 | Check the bit TestFailed
34 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
35 | Clear All Diagnostic Information
36 | &{DTCMaskRecords}= Get DTCMaskRecords
37 |
38 | :FOR ${key} IN @{DTCMaskRecords.keys()}
39 | \ The Bit testFailed Of statusOfDTC Must Be 0 For DTCMaskRecord ${DTCMaskRecords["${key}"]}
40 |
41 | Check Security handshake
42 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
43 | Send DIAG Request 2761
44 | ${Seed1} = Get Next DIAG Frame
45 | ${Seed1} = Remove The First 4 Char From ${Seed1}
46 | ${Seed1} Catenate SEPARATOR= 0x ${Seed1}
47 | ${SeedKey} = Get Key From Seed ${Seed1} With ${CONST1} As Const1 and ${CONST2} As Const2
48 |
49 | ${Key1} Catenate SEPARATOR= 2762 ${SeedKey}
50 | ${Key1}= Set Variable ${Key1}
51 | Send DIAG Request ${Key1}
52 | Diag Response Must Start With 6762
53 |
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/CURF/testsuite/outputs/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/CURF/testsuite/tester_motor_usecase.robot:
--------------------------------------------------------------------------------
1 | *** Settings ***
2 | Resource ../keywords/curf.robot
3 | Test Setup Set CAN Bus ${INTERFACE} ${CHANNEL} ${BITRATE} ${DB FILE}
4 | Test Teardown End Log Can
5 | Library DateTime
6 |
7 | *** Variables ***
8 | ${DB FILE} /home/ancit/git/pythoncan-examples/python-can-examples/can-examples/system_MainBus.dbc
9 | ${INTERFACE} socketcan
10 | ${CHANNEL} vcan0
11 | ${BITRATE} 500000
12 | ${DEFAULT TIMEOUT} 3
13 | ${DEFAULT NODE} DRIVER
14 |
15 |
16 | *** Test Cases ***
17 | Check the reception of a CAN signal 01
18 | Check CAN Signal MSSpeed Equals To 0 TimeOut ${DEFAULT TIMEOUT} Seconds
19 |
20 | Send a given signal 01
21 | Send Signal MCSpeed With Value 50
22 |
23 | Check the reception of a CAN signal 02
24 | Check CAN Signal MSSpeed Equals To 50 TimeOut ${DEFAULT TIMEOUT} Seconds
25 |
26 | Send a given signal 02
27 | Send Signal MCSpeed With Value 0
28 |
29 | Check the reception of a CAN signal 03
30 | Check CAN Signal MSSpeed Equals To 0 TimeOut ${DEFAULT TIMEOUT} Seconds
31 |
32 | Send a given signal 04
33 | Send Message MotorControl Signal MCSpeed With Value 45
34 |
35 | Send a given signal 03
36 | Send Signal MCSpeed With Value 65535
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/README.md:
--------------------------------------------------------------------------------
1 | # CURF
2 |
3 | ## CAN UDS for Robot Framework
4 |
5 | ### CAN BUS with ISO-14229 implementation RobotFramework Library
6 |
7 | The goal of this Robotframework Library is testing CAN BUS with RobotFramework
8 |
9 | ## CAN, UDS and ISO-TP Reminder
10 |
11 | They are a lot of CAN protocols and it can be confusing.
12 |
13 | CAN (ISO-11898) was released in 1991 and the main limit is the size of payload (8 Bytes) by frame.
14 |
15 | ISO-TP (ISO 15765-2) TP means 'Transport Layer' was introducted in 2016. The main goal is the transfer of longer messages over CAN into multiples frames, adding metadata that allows the interpretation of individual frames and reassembly into a complete message packet by the recipient. It can carry up to 4095 bytes of payload per message packet.
16 |
17 | UDS (ISO 14229-1) Unified Diagnostic Services is a communication protocol, Unified means that is an international and not company specific standard. This standard use ISO-TP.
18 |
19 | ## Compatibility
20 |
21 | This RobotFramework library is cross-platform (tested under Debian9, and Windows 10)
22 |
23 | The library use [python-can](https://python-can.readthedocs.io/en/master/index.html) to support CAN interface the interfaces [linked here](https://python-can.readthedocs.io/en/master/interfaces.html) must be compatibles.
24 |
25 | The library use [isotp](https://can-isotp.readthedocs.io/en/latest/index.html) to handle ISO-15765 protocol
26 |
27 | The library use [cantools](https://cantools.readthedocs.io/en/latest/) to encoding/decoding CAN Database, see [here](https://cantools.readthedocs.io/en/latest/#functions-and-classes) to find compatible format
28 |
29 | ## Requirements
30 |
31 | They are a few dependencies, the library must work in Linux and Windows
32 |
33 | ```shell
34 | pip install robotframework
35 | pip install python-can
36 | pip install cantools
37 | pip install can-isotp
38 | ```
39 |
40 | ## Use
41 |
42 | See testsuite/test.robot
43 |
44 | All test must start with
45 |
46 | ```shell
47 | Set CAN Bus ${INTERFACE} ${CHANNEL} ${BITRATE} ${DB FILE}
48 | ```
49 |
50 | So the best can be to instanciate it with 'Test Setup'
51 |
52 | Before using ISO-TP/UDS specific keywords you must instanciate it as follow:
53 |
54 | ```shell
55 | Set ISOTP Protocol ${SOURCE} ${DESTINATION} ${ADDRESSING MODE}
56 | ```
57 |
58 |
--------------------------------------------------------------------------------
/python-can-examples/robot-framework/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-examples/robot-framework/__init__.py
--------------------------------------------------------------------------------
/python-can-examples/toc.md:
--------------------------------------------------------------------------------
1 | # Introduction to Automotive Electronics
2 | 1. What is a CAR ?
3 | 2. Example Functionalities of a CAR ?
4 | 3. What is a ECU ?
5 | 4. Different Communication Protocols used in a CAR
6 | 5. Introduction to V-Model
7 | 6. Importance of Software Testing in Automotive Electronics
8 |
9 | # Introduction to CAN
10 | 1. Need for Network Arbitration
11 | 2. Introduction to CAN
12 | 3. Format of CAN Data Frame
13 | 4. Setting up Virtual CAN Bus on Linux
14 | 5. Configure CAN Data Frame and Sending on CAN Bus
15 | 6. Receiving and Monitoring CAN Bus
16 |
17 |
18 | # Introduction to Python
19 | 1. Set up Eclipse + PyDev
20 | 2. HelloWorld using Python
21 | 3. Data Types in Python : Number System, String etc
22 | 4. Data Structures in Python : List, Tuple, Dictionary
23 | 5. Programming Basics : Loops, Functions & Threads
24 |
25 | # Using Python to Simulate CAN Network
26 | 1. Sending RAW CAN Data Frames
27 | 2. Receiving RAW CAN Data Frames
28 | 3. Responding to RAW CAN Data Frames
29 | 4. Sending CAN Data Frames Periodically
30 | 5. Sending CAN Data Frames on Event
31 | 6. Simulating an ECU Network
32 |
33 | # Introduction to CAN Database Files
34 | 1. Explaining the Importance of CAN Database Files
35 | 2. Introduction to Messages and Signals
36 | 3. Encoding and Decoding of Messages and Signals
37 | 4. Introduction to different Formats of CAN Database File [dbc, dbf, kcd, arxml]
38 | 5. Creating a DBC File
39 | 6. Using can-matrix Python library to manage DBC Files
40 |
41 | # Using Python & DBC to Simulate a CAN Network
42 | 1. Using Python to read a DBC File and Extract required Information
43 | 2. Encoding and Decoding a Message using DBC
44 | 3. Sending Encoded Message over CAN Bus
45 | 4. Receiving and Decoding Message using DBS over CAN BUS
46 | 5. Simulating a ECU Network using DBC
47 |
48 | # Using Python to Test a CAN Network
49 | 1. Creating a Tester Node
50 | 2. Validating the CAN Bus for Signal Values
51 | 3. Introduction to Unit Testing in Python
52 | 4. Using Unit Testing for CAN Signal Testing
53 | 5. Generation of HTML Test Report
54 |
55 | # Using Robot Framework to Test a CAN Network
56 | 1. Setting Up Robot Framework
57 | 2. Using Robot Framework for Send CAN Frame
58 | 3. Using Robot Framework for Validaing CAN Frame
59 | 4. Publishing HTML Test Report
60 |
61 | # Introduction to UDS
62 | 1. UDS as a Transport Protocol
63 | 2. Reading the Diagnostic Trouble Codes known as DTCs : Read DTC Information
64 | 3. Setting vehicle-specific configuration : Write Data by Identifier
65 | 4. Overriding IO : Input Output Control by Identifier
66 | 5. Requesting a Reset : ECU Reset
67 | 6. Sessions and Security Control
68 | 7. Fault Management using UDS Protocol
69 | 8. Preparing Test Scripts for UDS in Python and Robot Framework
70 |
71 | # Introduction to Vector Tools - CANOE/Canalyzer
72 | 1. Using CANOE for Simulating an ECU Network
73 | 2. Introduction to IG Block, Trace Window etc
74 | 3. Introduction to CAPL Programming for Simulating a CAN Network
75 | 4. Introduction to Test Specification Environment in CANOE
76 | 5. Using CAPL for Testing a CAN Network
--------------------------------------------------------------------------------
/python-can-usecases/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | python-can-usecases
4 |
5 |
6 |
7 |
8 |
9 | org.python.pydev.PyDevBuilder
10 |
11 |
12 |
13 |
14 |
15 | org.python.pydev.pythonNature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/python-can-usecases/.pydevproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | python3
5 |
6 |
7 |
8 | /${PROJECT_DIR_NAME}
9 |
10 |
11 |
12 | python interpreter
13 |
14 |
15 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/Basic_DBC.dbc:
--------------------------------------------------------------------------------
1 | VERSION "created by canmatrix"
2 |
3 |
4 | NS_ :
5 |
6 | BS_:
7 |
8 | BU_:
9 |
10 |
11 | BO_ 257 SeatbeltMsg: 8 Vector__XXX
12 | SG_ SeatbeltStatus : 0|1@1+ (1,0) [0|1] "" Vector__XXX
13 | SG_ SeatbeltLock : 1|1@1+ (1,0) [0|1] "" Vector__XXX
14 |
15 | BO_ 258 AirbagMsg: 8 Vector__XXX
16 | SG_ AirbagStatus : 0|2@1+ (1,0) [0|3] "" Vector__XXX
17 | SG_ AirbagCondition : 2|1@1+ (1,0) [0|1] "" Vector__XXX
18 |
19 | BO_ 260 VehicleMotion: 8 Vector__XXX
20 | SG_ CrashDetected : 0|1@1+ (1,0) [0|1] "" Vector__XXX
21 | SG_ EngineRunning : 1|1@1+ (1,0) [0|1] "" Vector__XXX
22 | SG_ Velocity : 8|16@1+ (0.1,0) [0|65535] "km/h" Vector__XXX
23 |
24 | BO_ 261 BrakeMsg: 8 Vector__XXX
25 | SG_ BrakeStatus : 0|1@1+ (1,0) [0|1] "" Vector__XXX
26 |
27 | BO_ 262 AccelarationMsg: 8 Vector__XXX
28 | SG_ Acceleration : 0|16@1+ (0.1,0) [0|65535] "m/s2" Vector__XXX
29 |
30 |
31 |
32 | CM_ SG_ 257 SeatbeltStatus "Status of wether Seatbelt is worn or not";
33 | CM_ SG_ 257 SeatbeltLock "Status of wether Seatbelt is Locked";
34 | CM_ SG_ 258 AirbagStatus "Echos the state of the Airbag Condition";
35 | CM_ SG_ 258 AirbagCondition "state of the Airbag Health";
36 | CM_ SG_ 260 CrashDetected "Status of wether crash is detected or not";
37 | CM_ SG_ 260 EngineRunning "Echos Engine Running Status";
38 | CM_ SG_ 260 Velocity "Value of the Vehicles Velocity";
39 | CM_ SG_ 261 BrakeStatus "Status of wether Brake is applied or not";
40 | CM_ SG_ 262 Acceleration "Value of the Acceleration Applaid";
41 |
42 |
43 | BA_DEF_ BO_ "GenMsgCycleTimeActive" INT 0 65535;
44 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 65535;
45 | BA_DEF_ BO_ "GenMsgNrOfRepetitions" INT 0 65535;
46 | BA_DEF_ BO_ "GenMsgSendType" ENUM;
47 | BA_DEF_ SG_ "GenSigSNA" STRING;
48 |
49 |
50 |
51 |
52 | VAL_ 257 SeatbeltStatus 0 "NotWorn" 1 "Worn";
53 | VAL_ 257 SeatbeltLock 0 "UnLock" 1 "Lock";
54 | VAL_ 258 AirbagStatus 0 "Ready" 1 "NotReady" 2 "Released";
55 | VAL_ 258 AirbagCondition 0 "Damage" 1 "Healthy";
56 | VAL_ 260 CrashDetected 0 "CrashFree" 1 "Crash";
57 | VAL_ 260 EngineRunning 0 "NotRunning" 1 "Running";
58 | VAL_ 261 BrakeStatus 0 "BrakeNotApplied" 1 "BrakeApplied";
59 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/Engine_ECU_DBC.py:
--------------------------------------------------------------------------------
1 | import can
2 | import cantools
3 | import threading
4 |
5 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
6 | db = cantools.db.load_file('Basic_DBC.dbc')
7 |
8 | brakeMsg = db.get_message_by_name('BrakeMsg')
9 | accelerationMsg = db.get_message_by_name('AccelarationMsg')
10 | EngineMsg = db.get_message_by_name('VehicleMotion')
11 |
12 | def apply_break():
13 | data = EngineMsg.encode({'Velocity':0,'CrashDetected':0,'EngineRunning':1})
14 | message = can.Message(arbitration_id=EngineMsg.frame_id, data=data, is_extended_id=False)
15 | try:
16 | periodicTask.modify_data(message)
17 | print("Break Applied")
18 | except can.CanError:
19 | print("Message not sent")
20 |
21 | def apply_accelerate(AcclVal):
22 | data = EngineMsg.encode({'Velocity': (AcclVal),'CrashDetected':0,'EngineRunning':1})
23 | message = can.Message(arbitration_id=EngineMsg.frame_id, data=data, is_extended_id=False)
24 | try:
25 | periodicTask.modify_data(message)
26 | print("Acceleration : " + str(AcclVal))
27 | except can.CanError:
28 | print("Message NOT sent")
29 |
30 | def on_Message():
31 | while True:
32 | message = bus.recv()
33 | msgData = db.decode_message(message.arbitration_id, message.data)
34 | if message.arbitration_id == accelerationMsg.frame_id:
35 | acclrValue = (msgData['Acceleration'])
36 | apply_accelerate(acclrValue)
37 |
38 | if message.arbitration_id == brakeMsg.frame_id:
39 | apply_break()
40 |
41 | def intiateVehicle():
42 | data = EngineMsg.encode({'Velocity':5,'CrashDetected':0,'EngineRunning':1})
43 | message = can.Message(arbitration_id=EngineMsg.frame_id, data=data, is_extended_id=False)
44 | try:
45 | task = bus.send_periodic(message, 1.0)
46 | print("Cranking engine & Vehicle Initiated")
47 | return task
48 | except can.CanError:
49 | print("Message NOT sent")
50 |
51 | if __name__ == '__main__':
52 | periodicTask = intiateVehicle()
53 | threading.Thread(on_Message()).start()
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/Engine_ECU_RAW.py:
--------------------------------------------------------------------------------
1 | import can
2 | import threading
3 |
4 | can_bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=250000)
5 |
6 | brakeMsgID = 0x105
7 | accelerationMsgID = 0x106
8 | EngineMsgID = 0x104
9 |
10 | def apply_break():
11 | message = can.Message(arbitration_id=EngineMsgID, data=[2,0,0,0], is_extended_id=False)
12 | try:
13 | periodicTask.modify_data(message)
14 | print("Break Applied")
15 | except can.CanError:
16 | print("Message not sent")
17 |
18 | def apply_accelerate(AcclrVal):
19 | message = can.Message(arbitration_id=EngineMsgID, data=[2,AcclrVal,0,0], is_extended_id=False)
20 | try:
21 | periodicTask.modify_data(message)
22 | print("Acceleration : " + str(AcclrVal))
23 | except can.CanError:
24 | print("Message NOT sent")
25 |
26 | def on_Message():
27 | #Initiating Vehicle Condition to Default
28 | while True:
29 | message = can_bus.recv()
30 | msgData = message.data
31 | if message.arbitration_id == accelerationMsgID:
32 | AcclrVal = msgData[0]
33 | apply_accelerate(AcclrVal)
34 |
35 | if message.arbitration_id == brakeMsgID:
36 | apply_break()
37 |
38 | def intiateVehicle():
39 | message = can.Message(arbitration_id=EngineMsgID, data=[2,5,0,0], is_extended_id=False)
40 | try:
41 | task = can_bus.send_periodic(message, 1.0)
42 | print("Cranking engine & Vehicle Initiated")
43 | return task
44 | except can.CanError:
45 | print("Message NOT sent")
46 |
47 | if __name__ == '__main__':
48 | periodicTask = intiateVehicle()
49 | threading.Thread(on_Message()).start()
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/Engine_Tester_DBC.py:
--------------------------------------------------------------------------------
1 | import can
2 | import cantools
3 | import threading
4 | from pynput import keyboard
5 |
6 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
7 | db = cantools.db.load_file('Basic_DBC.dbc')
8 |
9 | brakeMsg = db.get_message_by_name('BrakeMsg')
10 | accelerationMsg = db.get_message_by_name('AccelarationMsg')
11 | EngineMsg = db.get_message_by_name('VehicleMotion')
12 |
13 | AcclrVal = 0
14 |
15 | def _accelerate():
16 | global AcclrVal
17 | AcclrVal = AcclrVal+10
18 |
19 | data = accelerationMsg.encode({'Acceleration':AcclrVal})
20 | message = can.Message(arbitration_id=accelerationMsg.frame_id, data=data, is_extended_id=False)
21 | try:
22 | bus.send(message)
23 | print("\tAccelerated to: "+ str(AcclrVal))
24 | except can.CanError:
25 | print("Message not sent")
26 |
27 | def _decelerate():
28 | global AcclrVal
29 | AcclrVal = AcclrVal-10
30 |
31 | data = accelerationMsg.encode({'Acceleration':AcclrVal})
32 | message = can.Message(arbitration_id=accelerationMsg.frame_id, data=data, is_extended_id=False)
33 | try:
34 | bus.send(message)
35 | print("\tDecelerated to "+ str(AcclrVal))
36 | except can.CanError:
37 | print("Message not sent")
38 |
39 | def _break():
40 | global AcclrVal
41 | data = brakeMsg.encode({'BrakeStatus':1})
42 | message = can.Message(arbitration_id=brakeMsg.frame_id, data=data, is_extended_id=False)
43 | try:
44 | bus.send(message)
45 | print("\tBreak Applied")
46 | AcclrVal = 0
47 | except can.CanError:
48 | print("Message not sent")
49 |
50 |
51 | def on_press(key):
52 | try:
53 | if key.char == 'a':
54 | _accelerate()
55 | if key.char == 'd':
56 | _decelerate()
57 | if key.char == 'b':
58 | _break()
59 | except AttributeError:
60 | print(" Unknown Key Event")
61 |
62 | def on_Message():
63 | buffer = 0
64 | while True:
65 | message = bus.recv()
66 | msgData = db.decode_message(message.arbitration_id, message.data)
67 | if message.arbitration_id == EngineMsg.frame_id:
68 | EngineVelocity = (msgData['Velocity'])
69 | if(buffer != EngineVelocity):
70 | print("Engine Speed Updated: " + str(EngineVelocity))
71 | buffer = EngineVelocity
72 |
73 | def on_Key():
74 | keyboard.Listener(on_press=on_press).start()
75 |
76 | if __name__ == '__main__':
77 | print("Press below Keys to Test\n\t'a' to Accelerate\n\t'd' to Decelerate\n\t'b' to Brake\n")
78 | on_Key()
79 | threading.Thread(on_Message()).start()
80 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/Engine_Tester_RAW.py:
--------------------------------------------------------------------------------
1 | import can
2 | import threading
3 | from pynput import keyboard
4 |
5 | bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=250000)
6 |
7 | brakeMsgID = 0x105
8 | accelerationMsgID = 0x106
9 | EngineMsgID = 0x104
10 |
11 | AcclrVal = 0
12 |
13 | def _accelerate():
14 | global AcclrVal
15 | AcclrVal = AcclrVal+10
16 |
17 | message = can.Message(arbitration_id=accelerationMsgID,data=[AcclrVal, 0],is_extended_id=False)
18 | try:
19 | bus.send(message)
20 | print("\tAccelerated to: "+ str(AcclrVal))
21 | except can.CanError:
22 | print("Message not sent")
23 |
24 | def _decelerate():
25 | global AcclrVal
26 | AcclrVal = AcclrVal-10
27 |
28 | message = can.Message(arbitration_id=accelerationMsgID,data=[AcclrVal, 0],is_extended_id=False)
29 | try:
30 | bus.send(message)
31 | print("\tAccelerated to: "+ str(AcclrVal))
32 | except can.CanError:
33 | print("Message not sent")
34 |
35 | def _break():
36 | global AcclrVal
37 | message = can.Message(arbitration_id=brakeMsgID, data=[0,0], is_extended_id=False)
38 | try:
39 | bus.send(message)
40 | print("\tBreak Applied")
41 | AcclrVal = 0
42 | except can.CanError:
43 | print("Message not sent")
44 |
45 | def on_press(key):
46 | try:
47 | if key.char == 'a':
48 | _accelerate()
49 | if key.char == 'd':
50 | _decelerate()
51 | if key.char == 'b':
52 | _break()
53 | except AttributeError:
54 | print(" Unknown Key Event")
55 |
56 | def on_Message():
57 | buffer = 0
58 | while True:
59 | message = bus.recv()
60 | msgData = message.data
61 | if message.arbitration_id == EngineMsgID:
62 | EngineVelocity = msgData[1]
63 | if(buffer != EngineVelocity):
64 | print("Engine Speed Updated: " + str(EngineVelocity))
65 | buffer = EngineVelocity
66 |
67 | def on_Key():
68 | keyboard.Listener(on_press=on_press).start()
69 |
70 | if __name__ == '__main__':
71 | print("Press below Keys to Test\n\t'a' to Accelerate\n\t'd' to Decelerate\n\t'b' to Brake\n")
72 | on_Key()
73 | threading.Thread(on_Message()).start()
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/GUI_Based/Basic_DBC.dbc:
--------------------------------------------------------------------------------
1 | VERSION "created by canmatrix"
2 |
3 |
4 | NS_ :
5 |
6 | BS_:
7 |
8 | BU_:
9 |
10 |
11 | BO_ 257 SeatbeltMsg: 8 Vector__XXX
12 | SG_ SeatbeltStatus : 0|1@1+ (1,0) [0|1] "" Vector__XXX
13 | SG_ SeatbeltLock : 1|1@1+ (1,0) [0|1] "" Vector__XXX
14 |
15 | BO_ 258 AirbagMsg: 8 Vector__XXX
16 | SG_ AirbagStatus : 0|2@1+ (1,0) [0|3] "" Vector__XXX
17 | SG_ AirbagCondition : 2|1@1+ (1,0) [0|1] "" Vector__XXX
18 |
19 | BO_ 260 VehicleMotion: 8 Vector__XXX
20 | SG_ CrashDetected : 0|1@1+ (1,0) [0|1] "" Vector__XXX
21 | SG_ EngineRunning : 1|1@1+ (1,0) [0|1] "" Vector__XXX
22 | SG_ Velocity : 8|16@1+ (0.1,0) [0|65535] "km/h" Vector__XXX
23 |
24 | BO_ 261 BrakeMsg: 8 Vector__XXX
25 | SG_ BrakeStatus : 0|1@1+ (1,0) [0|1] "" Vector__XXX
26 |
27 | BO_ 262 AccelarationMsg: 8 Vector__XXX
28 | SG_ Acceleration : 0|16@1+ (0.1,0) [0|65535] "m/s2" Vector__XXX
29 |
30 |
31 |
32 | CM_ SG_ 257 SeatbeltStatus "Status of wether Seatbelt is worn or not";
33 | CM_ SG_ 257 SeatbeltLock "Status of wether Seatbelt is Locked";
34 | CM_ SG_ 258 AirbagStatus "Echos the state of the Airbag Condition";
35 | CM_ SG_ 258 AirbagCondition "state of the Airbag Health";
36 | CM_ SG_ 260 CrashDetected "Status of wether crash is detected or not";
37 | CM_ SG_ 260 EngineRunning "Echos Engine Running Status";
38 | CM_ SG_ 260 Velocity "Value of the Vehicles Velocity";
39 | CM_ SG_ 261 BrakeStatus "Status of wether Brake is applied or not";
40 | CM_ SG_ 262 Acceleration "Value of the Acceleration Applaid";
41 |
42 |
43 | BA_DEF_ BO_ "GenMsgCycleTimeActive" INT 0 65535;
44 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 65535;
45 | BA_DEF_ BO_ "GenMsgNrOfRepetitions" INT 0 65535;
46 | BA_DEF_ BO_ "GenMsgSendType" ENUM;
47 | BA_DEF_ SG_ "GenSigSNA" STRING;
48 |
49 |
50 |
51 |
52 | VAL_ 257 SeatbeltStatus 0 "NotWorn" 1 "Worn";
53 | VAL_ 257 SeatbeltLock 0 "UnLock" 1 "Lock";
54 | VAL_ 258 AirbagStatus 0 "Ready" 1 "NotReady" 2 "Released";
55 | VAL_ 258 AirbagCondition 0 "Damage" 1 "Healthy";
56 | VAL_ 260 CrashDetected 0 "CrashFree" 1 "Crash";
57 | VAL_ 260 EngineRunning 0 "NotRunning" 1 "Running";
58 | VAL_ 261 BrakeStatus 0 "BrakeNotApplied" 1 "BrakeApplied";
59 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/GUI_Based/Engine_ECU_DBC.py:
--------------------------------------------------------------------------------
1 | import can
2 | import cantools
3 | import threading
4 |
5 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
6 | db = cantools.db.load_file('Basic_DBC.dbc')
7 |
8 | brakeMsg = db.get_message_by_name('BrakeMsg')
9 | accelerationMsg = db.get_message_by_name('AccelarationMsg')
10 | EngineMsg = db.get_message_by_name('VehicleMotion')
11 |
12 | def apply_break():
13 | data = EngineMsg.encode({'Velocity':0,'CrashDetected':0,'EngineRunning':1})
14 | message = can.Message(arbitration_id=EngineMsg.frame_id, data=data, is_extended_id=False)
15 | try:
16 | periodicTask.modify_data(message)
17 | print("Break Applied")
18 | except can.CanError:
19 | print("Message not sent")
20 |
21 | def apply_accelerate(AcclVal):
22 | data = EngineMsg.encode({'Velocity': (AcclVal),'CrashDetected':0,'EngineRunning':1})
23 | message = can.Message(arbitration_id=EngineMsg.frame_id, data=data, is_extended_id=False)
24 | try:
25 | periodicTask.modify_data(message)
26 | print("Acceleration : " + str(AcclVal))
27 | except can.CanError:
28 | print("Message NOT sent")
29 |
30 | def on_Message():
31 | while True:
32 | message = bus.recv()
33 | msgData = db.decode_message(message.arbitration_id, message.data)
34 | if message.arbitration_id == accelerationMsg.frame_id:
35 | acclrValue = (msgData['Acceleration'])
36 | apply_accelerate(acclrValue)
37 |
38 | if message.arbitration_id == brakeMsg.frame_id:
39 | apply_break()
40 |
41 | def intiateVehicle():
42 | data = EngineMsg.encode({'Velocity':0,'CrashDetected':0,'EngineRunning':1})
43 | message = can.Message(arbitration_id=EngineMsg.frame_id, data=data, is_extended_id=False)
44 | try:
45 | task = bus.send_periodic(message, 1.0)
46 | print("Cranking engine & Vehicle Initiated")
47 | return task
48 | except can.CanError:
49 | print("Message NOT sent")
50 |
51 | if __name__ == '__main__':
52 | periodicTask = intiateVehicle()
53 | threading.Thread(on_Message()).start()
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/GUI_Based/Engine_GUITester.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 | import can
4 | import cantools
5 | from threading import Thread
6 | from pynput import keyboard
7 |
8 | from PyQt5 import QtCore, QtGui, QtQml
9 | from PyQt5.QtCore import QObject
10 | from functools import partial
11 |
12 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
13 | db = cantools.db.load_file('Basic_DBC.dbc')
14 |
15 | brakeMsg = db.get_message_by_name('BrakeMsg')
16 | accelerationMsg = db.get_message_by_name('AccelarationMsg')
17 | EngineMsg = db.get_message_by_name('VehicleMotion')
18 |
19 | AcclrVal = 0
20 | VhclSpeed = 0
21 |
22 | def _accelerate(AcclrVal):
23 | data = accelerationMsg.encode({'Acceleration':AcclrVal})
24 | message = can.Message(arbitration_id=accelerationMsg.frame_id, data=data, is_extended_id=False)
25 | try:
26 | bus.send(message)
27 | print("\tAccelerated to: "+ str(AcclrVal))
28 | except can.CanError:
29 | print("Message not sent")
30 |
31 | def _break():
32 | global AcclrVal
33 | data = brakeMsg.encode({'BrakeStatus':1})
34 | message = can.Message(arbitration_id=brakeMsg.frame_id, data=data, is_extended_id=False)
35 | try:
36 | bus.send(message)
37 | print("\tBreak Applied")
38 | AcclrVal = 0
39 | except can.CanError:
40 | print("Message not sent")
41 |
42 |
43 | def on_press(key):
44 | try:
45 | if key.char == 'a':
46 | _accelerate(10)
47 | if key.char == 'b':
48 | _break()
49 | except AttributeError:
50 | print(" Unknown Key Event")
51 |
52 | class on_Message(Thread):
53 | def __init__(self):
54 | Thread.__init__(self)
55 |
56 | def run(self):
57 | buffer = 0
58 | global VhclSpeed
59 | while True:
60 | message = bus.recv()
61 | msgData = db.decode_message(message.arbitration_id, message.data)
62 | if message.arbitration_id == EngineMsg.frame_id:
63 | EngineVelocity = (msgData['Velocity'])
64 | engineStat = bool(msgData['EngineRunning'])
65 | if(buffer != EngineVelocity):
66 | print("Engine Speed Updated: " + str(EngineVelocity))
67 | buffer = EngineVelocity
68 | guiAppThread.updateSpeed(int(EngineVelocity))
69 | guiAppThread.updateEngStat(engineStat)
70 |
71 |
72 | class on_Key(Thread):
73 | def __init__(self):
74 | Thread.__init__(self)
75 |
76 | def run(self):
77 | keyboard.Listener(on_press=on_press).start()
78 |
79 | class SpeedMeterManager(QtCore.QObject):
80 | # Instance
81 | speedChanged = QtCore.pyqtSignal(int)
82 | engStatChanged = QtCore.pyqtSignal(bool)
83 | brakeStatChanged = QtCore.pyqtSignal(bool)
84 | acclrtnChanged = QtCore.pyqtSignal(int)
85 |
86 | def __init__(self, parent=None):
87 | super(SpeedMeterManager, self).__init__(parent)
88 | self._speedVal = 0
89 | self._engStat = False
90 | self._brakeStat = False
91 |
92 | @QtCore.pyqtProperty(int, notify=speedChanged)
93 | def speedVal(self):
94 | return self._speedVal
95 |
96 | # Define the setter of the 'Speed' property.
97 | @speedVal.setter
98 | def speedVal(self, s):
99 | if self._speedVal != s:
100 | self._speedVal = s
101 | self.speedChanged.emit(s)
102 |
103 | @QtCore.pyqtProperty(bool, notify=brakeStatChanged)
104 | def brakeStat(self):
105 | return self._brakeStat
106 |
107 | # Define the setter of the 'Brake' property.
108 | @brakeStat.setter
109 | def brakeStat(self, b):
110 | self._brakeStat = b
111 | self.brakeStatChanged.emit(b)
112 |
113 | @QtCore.pyqtProperty(bool, notify=engStatChanged)
114 | def engStat(self):
115 | return self._engStat
116 |
117 | # Define the setter of the 'Engine' property.
118 | @engStat.setter
119 | def engStat(self, c):
120 | self._engStat = c
121 | self.engStatChanged.emit(c)
122 |
123 | # Python type of the property is int.
124 | @QtCore.pyqtProperty(int, notify=acclrtnChanged)
125 | def acclVal(self):
126 | return self._acclVal
127 |
128 | # Define the setter of the 'Acceleration' property.
129 | # @acclVal.setter
130 | # def acclVal(self, a):
131 | # self._acclVal = a
132 | # self.acclrtnChanged.emit(a)
133 |
134 | class gui_App (Thread):
135 | def __init__(self):
136 | Thread.__init__(self)
137 | self.tempAccl = 0
138 |
139 | def launch(self):
140 | global VhclSpeed
141 | myApp = QtGui.QGuiApplication(sys.argv)
142 | myEngine = QtQml.QQmlApplicationEngine()
143 | self.manager = SpeedMeterManager()
144 | myEngine.rootContext().setContextProperty("smManager", self.manager)
145 | directory = os.path.dirname(os.path.abspath(__file__))
146 | myEngine.load(QtCore.QUrl.fromLocalFile(os.path.join(directory, 'speedMeter.qml')))
147 |
148 | if not myEngine.rootObjects():
149 | return -1
150 | self.dashB = myEngine.rootObjects()[0]
151 | timer = QtCore.QTimer(interval=500)
152 | # timer.timeout.connect(partial(self.updateSpeed, VhclSpeed))
153 | timer.timeout.connect(self.fetchBrake)
154 | timer.timeout.connect(self.fetchAccl)
155 | timer.start()
156 | return myApp.exec_()
157 |
158 | def updateSpeed(self, cGuageVal):
159 | self.manager.speedVal = cGuageVal
160 |
161 | def updateEngStat(self, engSt):
162 | self.manager.engStat = engSt
163 |
164 | def fetchBrake(self):
165 | brake = self.dashB.findChild(QObject, "brakBtn")
166 | brake_state = int(brake.property("checked"))
167 | if brake_state == True :
168 | _break()
169 |
170 | def fetchAccl(self):
171 | accl = self.dashB.findChild(QObject, "AcclSlider")
172 | C_acclVal = int(accl.property("value"))
173 | if C_acclVal != self.tempAccl:
174 | self.tempAccl = C_acclVal
175 | _accelerate(C_acclVal)
176 |
177 | if __name__ == '__main__':
178 | #Threads
179 | onKeyThread = on_Key()
180 | MsgRcvThread = on_Message()
181 | guiAppThread = gui_App()
182 |
183 | onKeyThread.start()
184 | guiAppThread.start()
185 | MsgRcvThread.start()
186 | # PrintInstructions
187 | print("Press below Keys to Test\n\t'a' to Accelerate\n\t'b' to Brake\n")
188 | #Launch GUI
189 | sys.exit(guiAppThread.launch())
190 |
191 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/GUI_Based/speedMeter.qml:
--------------------------------------------------------------------------------
1 | import QtQuick 2.9
2 | import QtQuick.Window 2.2
3 | import QtQuick.Extras 1.4
4 | import QtQuick.Controls 1.5
5 |
6 | Window {
7 | id: window
8 | visible: true
9 | width: 350
10 | height: 480
11 | color: "#353333"
12 | title: qsTr("DashBoard")
13 |
14 | CircularGauge {
15 | id: circularGauge
16 | x: 37
17 | y: 61
18 | value: smManager.speedVal
19 | maximumValue: 150
20 | }
21 |
22 | ToggleButton {
23 | objectName: "brakBtn"
24 | id: toggleButton
25 | x: 62
26 | y: 406
27 | width: 65
28 | height: 55
29 | text: qsTr("Brake")
30 | checked: false
31 | }
32 |
33 | StatusIndicator {
34 | id: statusIndicator
35 | x: 227
36 | y: 407
37 | active: smManager.engStat
38 | }
39 |
40 | Slider {
41 | objectName: "AcclSlider"
42 | id: sliderHorizontal
43 | x: 37
44 | y: 356
45 | width: 272
46 | height: 22
47 | clip: false
48 | maximumValue: 150
49 | updateValueWhileDragging: true
50 | stepSize: 1
51 | activeFocusOnPress: true
52 | orientation: Qt.Horizontal
53 | tickmarksEnabled: false
54 | value: 0
55 | }
56 |
57 | Label {
58 | id: label
59 | x: 220
60 | y: 447
61 | color: "#d5d3d3"
62 | text: qsTr("Engine")
63 | }
64 |
65 | Label {
66 | id: label1
67 | x: 109
68 | y: 376
69 | color: "#d5d3d3"
70 | text: qsTr("Acceleration Pedel")
71 | }
72 |
73 | Label {
74 | id: label2
75 | x: 127
76 | y: 316
77 | color: "#d5d3d3"
78 | text: qsTr("Vehicle Speed")
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/Tester node ecu.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import can
3 | import cantools
4 | import threading
5 | from pynput import keyboard
6 |
7 | can_bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=250000)
8 |
9 | def _accelerate():
10 |
11 | message = can.Message(arbitration_id= 0x20, data=[10], is_extended_id=False)
12 | print("Accelerated to 10kmph")
13 | try:
14 | can_bus.send(message)
15 | #print(" 0x20 Message sent on {}".format(can_bus.channel_info))
16 | except can.CanError:
17 | print("Message not sent")
18 |
19 | def _accelerate2():
20 |
21 | message = can.Message(arbitration_id= 0x20, data=[20], is_extended_id=False)
22 | print("Accelerated to 20kmph")
23 | try:
24 | can_bus.send(message)
25 | #print(" 0x20 Message sent on {}".format(can_bus.channel_info))
26 | except can.CanError:
27 | print("Message NOT sent")
28 |
29 | def _break():
30 |
31 | message = can.Message(arbitration_id= 0x30, data=[0], is_extended_id=False)
32 | print("Break Applied")
33 | try:
34 | can_bus.send(message)
35 | #print(" 0x30 Message sent on {}".format(can_bus.channel_info))
36 | except can.CanError:
37 | print("Message not sent")
38 |
39 |
40 | def on_press(key):
41 | try:
42 | if key.char == 'b':
43 | _accelerate()
44 | if key.char == 'c':
45 | _accelerate2()
46 | if key.char == 'd':
47 | _break()
48 | if key == keyboard.Key.esc:
49 | return False
50 | except AttributeError:
51 | print(" Unknown Key Event")
52 |
53 | def on_Message():
54 | #Initiating Vehicle Condition to Default
55 | flagAcc1 = True
56 | flagAcc2 = True
57 | flagBrk = True
58 |
59 | while True:
60 | response = can_bus.recv()
61 | data = response.data
62 | if response.arbitration_id == 0x010:
63 | if (response.data == bytearray(b'\n\x01\x00\x00')) and flagAcc1:
64 | print("Engine Speed Updated: 10")
65 | flagAcc1 = False
66 | flagAcc2 = True
67 | flagBrk = True
68 | if (response.data == bytearray(b'\x14\x01\x00\x00')) and flagAcc2:
69 | print("Engine Speed Updated: 20")
70 | flagAcc1 = True
71 | flagAcc2 = False
72 | flagBrk = True
73 | if (response.data == bytearray(b'\x00\x01\x00\x00')) and flagBrk:
74 | print("Engine Speed Updated: 0")
75 | flagAcc1 = True
76 | flagAcc2 = True
77 | flagBrk = False
78 |
79 | def on_Key():
80 | # with keyboard.Listener(on_press=on_press) as listener:
81 | # listener.join()
82 | keyboard.Listener(on_press=on_press).start()
83 |
84 | if __name__ == '__main__':
85 | #instruction()
86 | on_Key()
87 | threading.Thread(on_Message()).start()
88 |
89 |
90 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/01_EngineControlECU/__init__.py
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/engine ecu.py:
--------------------------------------------------------------------------------
1 | from __future__ import print_function
2 | import can
3 | import time
4 | import cantools
5 | from pynput import keyboard
6 | import threading
7 |
8 | can_bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=1000000)
9 |
10 | def engine_on():
11 |
12 | message = can.Message(arbitration_id=0x10, data=[0,1,0,0], is_extended_id=False)
13 | try:
14 | periodicTask.modify_data(message)
15 | print("Engine is ON")
16 | except can.CanError:
17 | print("Message NOT sent")
18 |
19 | def apply_break():
20 | message = can.Message(arbitration_id=0x10, data=[0,1,0,0], is_extended_id=False)
21 | try:
22 | #can_bus.send(message)
23 | periodicTask.modify_data(message)
24 | print("Break Applied")
25 | #print(" 0x10 Message sent on {}".format(can_bus.channel_info))
26 | except can.CanError:
27 | print("Message not sent")
28 |
29 | def apply_accelerate1():
30 | message = can.Message(arbitration_id=0x10, data=[10,1,0,0], is_extended_id=False)
31 | try:
32 | #can_bus.send(message)
33 | periodicTask.modify_data(message)
34 | print("Acceleration : 10")
35 | #print(" 0x10 Message sent on {}".format(can_bus.channel_info))
36 | except can.CanError:
37 | print("Message NOT sent")
38 |
39 | def apply_accelerate2():
40 | message = can.Message(arbitration_id=0x10, data=[20,1,0,0], is_extended_id=False)
41 | try:
42 | #can_bus.send(message)
43 | periodicTask.modify_data(message)
44 | print("Acceleration : 20")
45 | #print(" 0x10 Message sent on {}".format(can_bus.channel_info))
46 | except can.CanError:
47 | print("Message NOT sent")
48 |
49 | def on_Message():
50 | #Initiating Vehicle Condition to Default
51 | while True:
52 | response = can_bus.recv()
53 | data = response.data
54 | if response.arbitration_id == 0x020:
55 | if response.data == bytearray(b'\n'):
56 | apply_accelerate1()
57 | if response.data == bytearray(b'\x14'):
58 | apply_accelerate2()
59 |
60 | if response.arbitration_id == 0x030:
61 | apply_break()
62 |
63 | def intiateVehicle():
64 | message = can.Message(arbitration_id=0x10, data=[0,0,0,0], is_extended_id=False)
65 | try:
66 | task = can_bus.send_periodic(message, 1.0)
67 | print("Cranking engine & Vehicle Initiated")
68 | return task
69 | #print(" 0x10 Message sent on {}".format(can_bus.channel_info))
70 | except can.CanError:
71 | print("Message NOT sent")
72 |
73 | if __name__ == '__main__':
74 |
75 | periodicTask = intiateVehicle()
76 | engine_on()
77 | threading.Thread(on_Message()).start()
78 |
79 | #threading.Thread(on_Message()).start()
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/engine.can:
--------------------------------------------------------------------------------
1 | /*@!Encoding:1252*/
2 | includes
3 | {
4 |
5 | }
6 | variables
7 | {
8 | message 0x10 m1 ;
9 | message 0x20 m2;
10 | message 0x30 m3;
11 | msTimer ms1;
12 | }
13 | on message 0x20
14 | {
15 | if(m2.byte(0)==0x10)
16 | {
17 | m1.dlc=4;
18 | m1.byte(0)=0x10;
19 | m1.byte(1)=0x01;
20 | output(m1);
21 | }
22 | if(m2.byte(0)==0x20)
23 | {
24 | m1.dlc=4;
25 | m1.byte(0)=0x20;
26 | m1.byte(1)=0x01;
27 | output(m1);
28 | }
29 | }
30 | on message 0x30
31 | {
32 | if(m3.byte(0)==0x00)
33 | {
34 | m1.dlc=4;
35 | m1.byte(0)=0x00;
36 | m1.byte(1)=0x01;
37 | output(m1);
38 | }
39 | }
40 | on start
41 | {
42 | setTimer(ms1,100);// initialize timer to 100 msec
43 | m1.dlc=4;
44 | m1.byte(0)=0;
45 | m1.byte(1)=0;
46 | m1.byte(2)=0;
47 | m1.byte(3)=0;
48 | output(m1);
49 | }
50 | on timer ms1
51 | {
52 | setTimer(ms1,100);
53 | m1.dlc=4;
54 | m1.byte(0)=0;
55 | m1.byte(1)=1;
56 | m1.byte(2)=0;
57 | m1.byte(3)=0;
58 | output(m1);
59 | }
60 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/readme.md:
--------------------------------------------------------------------------------
1 |
2 | # Use Case 1 - Basic Engine Control System
3 |
4 | ## Expectation
5 | To check the speed status of the engine by accelerator and brake according to the surrounding environment
6 | ## Functionality
7 | The Engine Control system used here is to check the speed status of the engine according to the surrounding environment depending on the signals received. Accelerator and break will be sending messages to engine, where the former will increase the speed of the engine and the latter will reduce the speed of the engine.
8 |
9 | ## Test Case
10 | 1.Initially engine will be off and it is turned on by cranking the engine. By turning on, it will be able to receive signals from accelerator and break.
11 |
12 | 2.By pressing key 'b' ,engine will be accelerated to 10kmph.
13 |
14 | 3.By pressing key 'c' ,engine will be accelerated to 20kmph.
15 |
16 | 4.By pressing key 'd' ,break is applied and engine speed will be 0kmph.
17 |
18 |
19 |
--------------------------------------------------------------------------------
/python-can-usecases/01_EngineControlECU/testernode.can:
--------------------------------------------------------------------------------
1 | /*@!Encoding:1252*/
2 |
3 | includes
4 | {
5 |
6 | }
7 | variables
8 | {
9 | message 0x20 m2;
10 | message 0x30 m3;
11 | }
12 | on key 'b'
13 | {
14 | m2.dlc=4;
15 | m2.byte(0)=0x10;
16 | m2.byte(1)=0x01;
17 | m2.byte(2)=0x00;
18 | m2.byte(3)=0x00;
19 | output(m2);
20 | }
21 | on key 'c'
22 | {
23 | m2.dlc=4;
24 | m2.byte(0)=0x20;
25 | m2.byte(1)=0x01;
26 | m2.byte(2)=0x00;
27 | m2.byte(3)=0x00;
28 | output(m2);
29 | }
30 | on key 'd'
31 | {
32 | m3.dlc=4;
33 | m3.byte(0)=0x00;
34 | m3.byte(1)=0x01;
35 | m3.byte(2)=0x00;
36 | m3.byte(3)=0x00;
37 | output(m3);
38 | }
39 |
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/.dbc & .can/DE.can:
--------------------------------------------------------------------------------
1 | /*@!Encoding:1252*/
2 | includes
3 | {
4 |
5 | }
6 |
7 | variables
8 | {
9 | message CentralLockingSystemState LState;
10 | message LockingRemoteControlRequest LReq;
11 | message VehicleMotion VCE;
12 | message WindowControl KE;
13 | message WindowState WM;
14 | }
15 |
16 | on message LockingRemoteControlRequest
17 | {
18 | write("CASE Response : Door Unlocked on UnlockDoor Request");
19 | LState.LockState=0x0; // LockState=Unlocked 0x0
20 | output(LState);
21 | }
22 |
23 | on message WindowControl
24 | {
25 | write("CASE Response : Window Closed with Engine Velocity 20 on Door Locked");
26 | WM.WindowPosition=1;
27 | WM.WindowMotion=0x1; //Window Motion=Closed 0x1
28 | output(WM);
29 | }
30 |
31 | on message CentralLockingSystemState
32 | {
33 | write("CASE Response : Comfort Lock Mode");
34 | VCE.EngineRunning=1;
35 | VCE.CrashDetected=0;
36 | output(VCE); //No Crash
37 | }
38 |
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/.dbc & .can/ED.can:
--------------------------------------------------------------------------------
1 | /*@!Encoding:1252*//*@!Encoding:1252*/
2 | /*@!Encoding:1252*/
3 | includes
4 | {
5 |
6 | }
7 |
8 | variables
9 | {
10 | message CentralLockingSystemState LState;
11 | message LockingRemoteControlRequest LReq;
12 | message VehicleMotion VCE;
13 | message WindowControl KE;
14 | message WindowState WM;
15 | msTimer T1;
16 | }
17 |
18 | on start
19 | {
20 | setTimer(T1,1000); //Initilize Timer
21 | }
22 |
23 | on timer T1
24 | {
25 | LState.AntiTheftSystemActive=1; //Periodic Message Sample
26 | output(LState);
27 | setTimer(T1,1000);
28 |
29 | }
30 |
31 | on key 'x' //CRASH DETECTED
32 | {
33 | write("CASE 1 : Crash Detected ==> with EngineOn and RequestToUnlock Door");
34 | VCE.EngineRunning=1;
35 | VCE.CrashDetected=1;
36 | VCE.Velocity=100;
37 | output(VCE);
38 | LReq.LockRequest=0x2; //Unlockrequest=0x2
39 | output(LReq);
40 | }
41 |
42 | on key 'u' //UnLock Door
43 | {
44 | write("CASE 2 : Request DoorUnLock ==> RequestToUnlock Door");
45 | LReq.LockRequest=0x2;
46 | output(LReq); //UnlockDoor Request
47 | }
48 |
49 | on key 'l' //Request to close Window
50 | {
51 | write("CASE 3 : Door Locked with Engine Velocity 20 and Request to Windows Closed");
52 | LState.LockState=0x1; //Door Closed = 0x1
53 | VCE.Velocity=20; //Velocity at 20
54 | output(LState);
55 | output(VCE);
56 | KE.KeyUp=1; //Request to close window
57 | output(KE);
58 | }
59 |
60 | on key 'c' //Comfort Lock
61 | {
62 | write("CASE 4 : Comfort Lock");
63 | WM.WindowMotion=0x0; //Window not moving
64 | LReq.LockRequest=0x3; //Comfort Lock
65 | output(WM);
66 | output(LReq);
67 | LState.LockState=0x1;
68 | output(LState); //Door Locked
69 | }
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/.dbc & .can/comfort.dbc:
--------------------------------------------------------------------------------
1 | VERSION ""
2 |
3 |
4 | NS_ :
5 | NS_DESC_
6 | CM_
7 | BA_DEF_
8 | BA_
9 | VAL_
10 | CAT_DEF_
11 | CAT_
12 | FILTER
13 | BA_DEF_DEF_
14 | EV_DATA_
15 | ENVVAR_DATA_
16 | SGTYPE_
17 | SGTYPE_VAL_
18 | BA_DEF_SGTYPE_
19 | BA_SGTYPE_
20 | SIG_TYPE_REF_
21 | VAL_TABLE_
22 | SIG_GROUP_
23 | SIG_VALTYPE_
24 | SIGTYPE_VALTYPE_
25 | BO_TX_BU_
26 | BA_DEF_REL_
27 | BA_REL_
28 | BA_DEF_DEF_REL_
29 | BU_SG_REL_
30 | BU_EV_REL_
31 | BU_BO_REL_
32 | SG_MUL_VAL_
33 |
34 | BS_:
35 |
36 | BU_: SUT_Driver SUT
37 |
38 |
39 | BO_ 1536 DiagResponse: 8 Vector__XXX
40 |
41 | BO_ 1792 DiagRequest: 8 Vector__XXX
42 |
43 | BO_ 1 LockingRemoteControlRequest: 1 SUT_Driver
44 | SG_ LockRequest : 0|2@1+ (1,0) [0|0] "" SUT
45 |
46 | BO_ 0 CentralLockingSystemState: 1 SUT
47 | SG_ AntiTheftSystemActive : 1|1@1+ (1,0) [0|1] "" Vector__XXX
48 | SG_ LockState : 0|1@1+ (1,0) [0|0] "" Vector__XXX
49 |
50 | BO_ 50 VehicleMotion: 3 SUT_Driver
51 | SG_ EngineRunning : 17|1@1+ (1,0) [0|1] "" Vector__XXX
52 | SG_ CrashDetected : 16|1@1+ (1,0) [0|0] "" SUT
53 | SG_ Velocity : 0|16@1- (0.1,0) [-100|350] "km/h" SUT
54 |
55 | BO_ 100 WindowState: 2 SUT
56 | SG_ WindowPosition : 0|8@1+ (1,0) [0|0] "" Vector__XXX
57 | SG_ WindowMotion : 14|2@1+ (1,0) [0|0] "" Vector__XXX
58 |
59 | BO_ 101 WindowControl: 1 SUT_Driver
60 | SG_ KeyDown : 1|1@1+ (1,0) [0|0] "" SUT
61 | SG_ KeyUp : 0|1@1+ (1,0) [0|0] "" SUT
62 |
63 |
64 |
65 | BA_DEF_ "NmMessageCount" INT 0 0;
66 | BA_DEF_ BO_ "DiagResponse" ENUM "No","Yes";
67 | BA_DEF_ BO_ "DiagRequest" ENUM "No","Yes";
68 | BA_DEF_ BO_ "GenMsgFastOnStart" INT 0 0;
69 | BA_DEF_ BO_ "GenMsgStartDelayTime" INT 0 0;
70 | BA_DEF_ SG_ "NWM-WakeupAllowed" ENUM "No","Yes";
71 | BA_DEF_ BO_ "NmMessage" ENUM "no","yes";
72 | BA_DEF_ BO_ "GenMsgILSupport" ENUM "No","Yes";
73 | BA_DEF_ BU_ "NmNode" ENUM "no","yes";
74 | BA_DEF_ BU_ "NmStationAddress" INT 0 63;
75 | BA_DEF_ "NmBaseAddress" HEX 1024 1087;
76 | BA_DEF_ BO_ "GenMsgCycleTimeFast" INT 0 50000;
77 | BA_DEF_ "BusType" STRING ;
78 | BA_DEF_ BO_ "GenMsgCycleTime" INT 0 50000;
79 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 1000;
80 | BA_DEF_ BO_ "GenMsgNrOfRepetition" INT 0 999999;
81 | BA_DEF_ BO_ "GenMsgSendType" ENUM "Cyclic","NotUsed","NotUsed","NotUsed","NotUsed","Cyclic","NotUsed","IfActive","NoMsgSendType","NotUsed","vector_leerstring";
82 | BA_DEF_ SG_ "GenSigInactiveValue" INT 0 100000;
83 | BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType","NotUsed","NotUsed","NotUsed","NotUsed","NotUsed";
84 | BA_DEF_ SG_ "GenSigStartValue" FLOAT 0 100000000000;
85 | BA_DEF_DEF_ "NmMessageCount" 64;
86 | BA_DEF_DEF_ "DiagResponse" "No";
87 | BA_DEF_DEF_ "DiagRequest" "No";
88 | BA_DEF_DEF_ "GenMsgFastOnStart" 0;
89 | BA_DEF_DEF_ "GenMsgStartDelayTime" 0;
90 | BA_DEF_DEF_ "NWM-WakeupAllowed" "";
91 | BA_DEF_DEF_ "NmMessage" "no";
92 | BA_DEF_DEF_ "GenMsgILSupport" "Yes";
93 | BA_DEF_DEF_ "NmNode" "no";
94 | BA_DEF_DEF_ "NmStationAddress" 0;
95 | BA_DEF_DEF_ "NmBaseAddress" 1024;
96 | BA_DEF_DEF_ "GenMsgCycleTimeFast" 0;
97 | BA_DEF_DEF_ "BusType" "CAN";
98 | BA_DEF_DEF_ "GenMsgCycleTime" 100;
99 | BA_DEF_DEF_ "GenMsgDelayTime" 0;
100 | BA_DEF_DEF_ "GenMsgNrOfRepetition" 0;
101 | BA_DEF_DEF_ "GenMsgSendType" "NoMsgSendType";
102 | BA_DEF_DEF_ "GenSigInactiveValue" 0;
103 | BA_DEF_DEF_ "GenSigSendType" "Cyclic";
104 | BA_DEF_DEF_ "GenSigStartValue" 0;
105 | BA_ "DiagResponse" BO_ 1536 1;
106 | BA_ "DiagRequest" BO_ 1792 1;
107 | BA_ "GenMsgSendType" BO_ 101 0;
108 | BA_ "GenMsgCycleTime" BO_ 101 500;
109 | BA_ "GenMsgCycleTimeFast" BO_ 101 20;
110 | BA_ "GenMsgNrOfRepetition" BO_ 101 2;
111 | BA_ "GenMsgDelayTime" BO_ 101 18;
112 | BA_ "GenSigSendType" SG_ 1 LockRequest 1;
113 | BA_ "GenSigSendType" SG_ 50 CrashDetected 1;
114 | BA_ "GenSigSendType" SG_ 100 WindowMotion 1;
115 | BA_ "GenSigSendType" SG_ 101 KeyDown 6;
116 | BA_ "GenSigSendType" SG_ 101 KeyUp 6;
117 | VAL_ 1 LockRequest 3 "Comfort_lock" 2 "Request_unlock" 1 "Request_lock" 0 "idle" ;
118 | VAL_ 0 LockState 1 "Locked" 0 "Unlocked" ;
119 | VAL_ 100 WindowMotion 2 "currently_opening" 1 "currently_closing" 0 "not_moving" ;
120 |
121 |
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/CLS.ecux:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/02_CentralLockingSystemECU/CLS.ecux
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/DE.can:
--------------------------------------------------------------------------------
1 | /*@!Encoding:1252*/
2 | includes
3 | {
4 |
5 | }
6 |
7 | variables
8 | {
9 | message CentralLockingSystemState LState;
10 | message LockingRemoteControlRequest LReq;
11 | message VehicleMotion VCE;
12 | message WindowControl KE;
13 | message WindowState WM;
14 | }
15 |
16 | on message LockingRemoteControlRequest
17 | {
18 | write("CASE Response : Door Unlocked on UnlockDoor Request");
19 | LState.LockState=0x0; // LockState=Unlocked 0x0
20 | output(LState);
21 | }
22 |
23 | on message WindowControl
24 | {
25 | write("CASE Response : Window Closed with Engine Velocity 20 on Door Locked");
26 | WM.WindowPosition=1;
27 | WM.WindowMotion=0x1; //Window Motion=Closed 0x1
28 | output(WM);
29 | }
30 |
31 | on message CentralLockingSystemState
32 | {
33 | write("CASE Response : Comfort Lock Mode");
34 | VCE.EngineRunning=1;
35 | VCE.CrashDetected=0;
36 | output(VCE); //No Crash
37 | }
38 |
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/ED.can:
--------------------------------------------------------------------------------
1 | /*@!Encoding:1252*//*@!Encoding:1252*/
2 | /*@!Encoding:1252*/
3 | includes
4 | {
5 |
6 | }
7 |
8 | variables
9 | {
10 | message CentralLockingSystemState LState;
11 | message LockingRemoteControlRequest LReq;
12 | message VehicleMotion VCE;
13 | message WindowControl KE;
14 | message WindowState WM;
15 | msTimer T1;
16 | }
17 |
18 | on start
19 | {
20 | setTimer(T1,1000); //Initilize Timer
21 | }
22 |
23 | on timer T1
24 | {
25 | LState.AntiTheftSystemActive=1; //Periodic Message Sample
26 | output(LState);
27 | setTimer(T1,1000);
28 |
29 | }
30 |
31 | on key 'x' //CRASH DETECTED
32 | {
33 | write("CASE 1 : Crash Detected ==> with EngineOn and RequestToUnlock Door");
34 | VCE.EngineRunning=1;
35 | VCE.CrashDetected=1;
36 | VCE.Velocity=100;
37 | output(VCE);
38 | LReq.LockRequest=0x2; //Unlockrequest=0x2
39 | output(LReq);
40 | }
41 |
42 | on key 'u' //UnLock Door
43 | {
44 | write("CASE 2 : Request DoorUnLock ==> RequestToUnlock Door");
45 | LReq.LockRequest=0x2;
46 | output(LReq); //UnlockDoor Request
47 | }
48 |
49 | on key 'l' //Request to close Window
50 | {
51 | write("CASE 3 : Door Locked with Engine Velocity 20 and Request to Windows Closed");
52 | LState.LockState=0x1; //Door Closed = 0x1
53 | VCE.Velocity=20; //Velocity at 20
54 | output(LState);
55 | output(VCE);
56 | KE.KeyUp=1; //Request to close window
57 | output(KE);
58 | }
59 |
60 | on key 'c' //Comfort Lock
61 | {
62 | write("CASE 4 : Comfort Lock");
63 | WM.WindowMotion=0x0; //Window not moving
64 | LReq.LockRequest=0x3; //Comfort Lock
65 | output(WM);
66 | output(LReq);
67 | LState.LockState=0x1;
68 | output(LState); //Door Locked
69 | }
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/ReadMe:
--------------------------------------------------------------------------------
1 |
2 | *****************************************Central Locking System Outline ************************************************
3 |
4 | Central locking system (CLS): Lock, unlock, comfort lock which locks the car and closes the windows.
5 | If a crash occurs then the CLS unlocks the car. The window lift supports opening and closing functions
6 | Functionalities adhere to the comfort.dbc files, consisting of messages and signals that are mapped.
7 |
8 | Use cases have been implemented.
9 | Programs with .can files supports cannoe configuration.
10 | Block diagram attached for precise understanding.
11 |
12 | ************************************* Socketcan Quickstart *******************************************************
13 |
14 | 1: The CAN network driver provides a generic interface to setup, configure and monitor CAN devices.
15 |
16 | 2: The virtual CAN driver (vcan) --> The virtual CAN interfaces allow the transmission and reception
17 | of CAN frames without real CAN controller hardware.
18 |
19 | 3: Virtual CAN network devices are usually named vcan0 vcan1 vcan2.
20 |
21 | 4: To create a virtual can interface using socketcan run the following:
22 |
23 | >>> sudo modprobe vcan
24 |
25 | >>> sudo ip link add dev vcan0 type vcan # Create a vcan network interface with a specific name
26 |
27 | >>> sudo ip link set vcan0 up
28 |
29 | >>> candump vcan0 # Allows you to print all data that is being received by a CAN interface
30 |
31 | >>> candump vcan0 | cantools decode --single-line .dbc file path
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/ReferralDiagram.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/02_CentralLockingSystemECU/ReferralDiagram.pdf
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/02_CentralLockingSystemECU/__init__.py
--------------------------------------------------------------------------------
/python-can-usecases/02_CentralLockingSystemECU/comfort.dbc:
--------------------------------------------------------------------------------
1 | VERSION ""
2 |
3 |
4 | NS_ :
5 | NS_DESC_
6 | CM_
7 | BA_DEF_
8 | BA_
9 | VAL_
10 | CAT_DEF_
11 | CAT_
12 | FILTER
13 | BA_DEF_DEF_
14 | EV_DATA_
15 | ENVVAR_DATA_
16 | SGTYPE_
17 | SGTYPE_VAL_
18 | BA_DEF_SGTYPE_
19 | BA_SGTYPE_
20 | SIG_TYPE_REF_
21 | VAL_TABLE_
22 | SIG_GROUP_
23 | SIG_VALTYPE_
24 | SIGTYPE_VALTYPE_
25 | BO_TX_BU_
26 | BA_DEF_REL_
27 | BA_REL_
28 | BA_DEF_DEF_REL_
29 | BU_SG_REL_
30 | BU_EV_REL_
31 | BU_BO_REL_
32 | SG_MUL_VAL_
33 |
34 | BS_:
35 |
36 | BU_: SUT_Driver SUT
37 |
38 |
39 | BO_ 1536 DiagResponse: 8 Vector__XXX
40 |
41 | BO_ 1792 DiagRequest: 8 Vector__XXX
42 |
43 | BO_ 1 LockingRemoteControlRequest: 1 SUT_Driver
44 | SG_ LockRequest : 0|2@1+ (1,0) [0|0] "" SUT
45 |
46 | BO_ 0 CentralLockingSystemState: 1 SUT
47 | SG_ AntiTheftSystemActive : 1|1@1+ (1,0) [0|1] "" Vector__XXX
48 | SG_ LockState : 0|1@1+ (1,0) [0|0] "" Vector__XXX
49 |
50 | BO_ 50 VehicleMotion: 3 SUT_Driver
51 | SG_ EngineRunning : 17|1@1+ (1,0) [0|1] "" Vector__XXX
52 | SG_ CrashDetected : 16|1@1+ (1,0) [0|0] "" SUT
53 | SG_ Velocity : 0|16@1- (0.1,0) [-100|350] "km/h" SUT
54 |
55 | BO_ 100 WindowState: 2 SUT
56 | SG_ WindowPosition : 0|8@1+ (1,0) [0|0] "" Vector__XXX
57 | SG_ WindowMotion : 14|2@1+ (1,0) [0|0] "" Vector__XXX
58 |
59 | BO_ 101 WindowControl: 1 SUT_Driver
60 | SG_ KeyDown : 1|1@1+ (1,0) [0|0] "" SUT
61 | SG_ KeyUp : 0|1@1+ (1,0) [0|0] "" SUT
62 |
63 |
64 |
65 | BA_DEF_ "NmMessageCount" INT 0 0;
66 | BA_DEF_ BO_ "DiagResponse" ENUM "No","Yes";
67 | BA_DEF_ BO_ "DiagRequest" ENUM "No","Yes";
68 | BA_DEF_ BO_ "GenMsgFastOnStart" INT 0 0;
69 | BA_DEF_ BO_ "GenMsgStartDelayTime" INT 0 0;
70 | BA_DEF_ SG_ "NWM-WakeupAllowed" ENUM "No","Yes";
71 | BA_DEF_ BO_ "NmMessage" ENUM "no","yes";
72 | BA_DEF_ BO_ "GenMsgILSupport" ENUM "No","Yes";
73 | BA_DEF_ BU_ "NmNode" ENUM "no","yes";
74 | BA_DEF_ BU_ "NmStationAddress" INT 0 63;
75 | BA_DEF_ "NmBaseAddress" HEX 1024 1087;
76 | BA_DEF_ BO_ "GenMsgCycleTimeFast" INT 0 50000;
77 | BA_DEF_ "BusType" STRING ;
78 | BA_DEF_ BO_ "GenMsgCycleTime" INT 0 50000;
79 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 1000;
80 | BA_DEF_ BO_ "GenMsgNrOfRepetition" INT 0 999999;
81 | BA_DEF_ BO_ "GenMsgSendType" ENUM "Cyclic","NotUsed","NotUsed","NotUsed","NotUsed","Cyclic","NotUsed","IfActive","NoMsgSendType","NotUsed","vector_leerstring";
82 | BA_DEF_ SG_ "GenSigInactiveValue" INT 0 100000;
83 | BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType","NotUsed","NotUsed","NotUsed","NotUsed","NotUsed";
84 | BA_DEF_ SG_ "GenSigStartValue" FLOAT 0 100000000000;
85 | BA_DEF_DEF_ "NmMessageCount" 64;
86 | BA_DEF_DEF_ "DiagResponse" "No";
87 | BA_DEF_DEF_ "DiagRequest" "No";
88 | BA_DEF_DEF_ "GenMsgFastOnStart" 0;
89 | BA_DEF_DEF_ "GenMsgStartDelayTime" 0;
90 | BA_DEF_DEF_ "NWM-WakeupAllowed" "";
91 | BA_DEF_DEF_ "NmMessage" "no";
92 | BA_DEF_DEF_ "GenMsgILSupport" "Yes";
93 | BA_DEF_DEF_ "NmNode" "no";
94 | BA_DEF_DEF_ "NmStationAddress" 0;
95 | BA_DEF_DEF_ "NmBaseAddress" 1024;
96 | BA_DEF_DEF_ "GenMsgCycleTimeFast" 0;
97 | BA_DEF_DEF_ "BusType" "CAN";
98 | BA_DEF_DEF_ "GenMsgCycleTime" 100;
99 | BA_DEF_DEF_ "GenMsgDelayTime" 0;
100 | BA_DEF_DEF_ "GenMsgNrOfRepetition" 0;
101 | BA_DEF_DEF_ "GenMsgSendType" "NoMsgSendType";
102 | BA_DEF_DEF_ "GenSigInactiveValue" 0;
103 | BA_DEF_DEF_ "GenSigSendType" "Cyclic";
104 | BA_DEF_DEF_ "GenSigStartValue" 0;
105 | BA_ "DiagResponse" BO_ 1536 1;
106 | BA_ "DiagRequest" BO_ 1792 1;
107 | BA_ "GenMsgSendType" BO_ 101 0;
108 | BA_ "GenMsgCycleTime" BO_ 101 500;
109 | BA_ "GenMsgCycleTimeFast" BO_ 101 20;
110 | BA_ "GenMsgNrOfRepetition" BO_ 101 2;
111 | BA_ "GenMsgDelayTime" BO_ 101 18;
112 | BA_ "GenSigSendType" SG_ 1 LockRequest 1;
113 | BA_ "GenSigSendType" SG_ 50 CrashDetected 1;
114 | BA_ "GenSigSendType" SG_ 100 WindowMotion 1;
115 | BA_ "GenSigSendType" SG_ 101 KeyDown 6;
116 | BA_ "GenSigSendType" SG_ 101 KeyUp 6;
117 | VAL_ 1 LockRequest 3 "Comfort_lock" 2 "Request_unlock" 1 "Request_lock" 0 "idle" ;
118 | VAL_ 0 LockState 1 "Locked" 0 "Unlocked" ;
119 | VAL_ 100 WindowMotion 2 "currently_opening" 1 "currently_closing" 0 "not_moving" ;
120 |
121 |
--------------------------------------------------------------------------------
/python-can-usecases/03_SeatBeltControlECU/Basic_DBC.dbc:
--------------------------------------------------------------------------------
1 | VERSION "created by canmatrix"
2 |
3 |
4 | NS_ :
5 |
6 | BS_:
7 |
8 | BU_:
9 |
10 |
11 | BO_ 257 SeatbeltMsg: 8 Vector__XXX
12 | SG_ SeatbeltStatus : 0|1@1+ (1,0) [0|1] "" Vector__XXX
13 | SG_ SeatbeltLock : 1|1@1+ (1,0) [0|1] "" Vector__XXX
14 |
15 | BO_ 258 AirbagMsg: 8 Vector__XXX
16 | SG_ AirbagStatus : 0|2@1+ (1,0) [0|3] "" Vector__XXX
17 | SG_ AirbagCondition : 2|1@1+ (1,0) [0|1] "" Vector__XXX
18 |
19 | BO_ 260 VehicleMotion: 8 Vector__XXX
20 | SG_ CrashDetected : 0|1@1+ (1,0) [0|1] "" Vector__XXX
21 | SG_ EngineRunning : 1|1@1+ (1,0) [0|1] "" Vector__XXX
22 | SG_ Velocity : 8|16@1+ (0.1,0) [0|65535] "km/h" Vector__XXX
23 |
24 | BO_ 261 BrakeMsg: 8 Vector__XXX
25 | SG_ BrakeStatus : 0|1@1+ (1,0) [0|1] "" Vector__XXX
26 |
27 | BO_ 262 AccelarationMsg: 8 Vector__XXX
28 | SG_ Acceleration : 0|16@1+ (0.1,0) [0|65535] "m/s2" Vector__XXX
29 |
30 |
31 |
32 | CM_ SG_ 257 SeatbeltStatus "Status of wether Seatbelt is worn or not";
33 | CM_ SG_ 257 SeatbeltLock "Status of wether Seatbelt is Locked";
34 | CM_ SG_ 258 AirbagStatus "Echos the state of the Airbag Condition";
35 | CM_ SG_ 258 AirbagCondition "state of the Airbag Health";
36 | CM_ SG_ 260 CrashDetected "Status of wether crash is detected or not";
37 | CM_ SG_ 260 EngineRunning "Echos Engine Running Status";
38 | CM_ SG_ 260 Velocity "Value of the Vehicles Velocity";
39 | CM_ SG_ 261 BrakeStatus "Status of wether Brake is applied or not";
40 | CM_ SG_ 262 Acceleration "Value of the Acceleration Applaid";
41 |
42 |
43 | BA_DEF_ BO_ "GenMsgCycleTimeActive" INT 0 65535;
44 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 65535;
45 | BA_DEF_ BO_ "GenMsgNrOfRepetitions" INT 0 65535;
46 | BA_DEF_ BO_ "GenMsgSendType" ENUM;
47 | BA_DEF_ SG_ "GenSigSNA" STRING;
48 |
49 |
50 |
51 |
52 | VAL_ 257 SeatbeltStatus 0 "NotWorn" 1 "Worn";
53 | VAL_ 257 SeatbeltLock 0 "UnLock" 1 "Lock";
54 | VAL_ 258 AirbagStatus 0 "Ready" 1 "NotReady" 2 "Released";
55 | VAL_ 258 AirbagCondition 0 "Damage" 1 "Healthy";
56 | VAL_ 260 CrashDetected 0 "CrashFree" 1 "Crash";
57 | VAL_ 260 EngineRunning 0 "NotRunning" 1 "Running";
58 | VAL_ 261 BrakeStatus 0 "BrakeNotApplied" 1 "BrakeApplied";
59 |
--------------------------------------------------------------------------------
/python-can-usecases/03_SeatBeltControlECU/SeatbeltECU_Testernode.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 15-Apr-2020
3 |
4 | @author: bk
5 | '''
6 |
7 | import can
8 | from pynput import keyboard
9 | import threading
10 |
11 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
12 |
13 | seatbeltMsgID = 0x101
14 | brakeMsgID = 0x105
15 | accelerationMsgID = 0x106
16 |
17 | def on_press(key):
18 | try:
19 | if key.char == 'a': # for acceleration
20 | message = can.Message(arbitration_id=accelerationMsgID,data=[0, 0],is_extended_id=False)
21 | try:
22 | bus.send(message)
23 | print("Message sent: \tVehicle Stopped Moving")
24 | except can.CanError:
25 | print("Message NOT sent")
26 | if key.char == 'b': # for brake condition
27 | message = can.Message(arbitration_id=brakeMsgID,data=[1, 0],is_extended_id=False)
28 | try:
29 | bus.send(message)
30 | print("Message sent: \tSudden Break Applaid")
31 | except can.CanError:
32 | print("Message NOT sent")
33 | except AttributeError:
34 | pass
35 |
36 | def on_Key():
37 | keyboard.Listener(on_press=on_press).start()
38 |
39 | def on_Message():
40 | while True:
41 | response = bus.recv()
42 | msgData = response.data
43 | if response.arbitration_id == seatbeltMsgID: # from Seatbelt Message
44 | seatbeltLock = msgData[0] & (1<<1) # 1st bit of 0th Byte
45 | if (seatbeltLock):
46 | #if Seatbelt is Locked
47 | print("\tResponse: Seatbelt Locked")
48 | else:
49 | #if Seatbelt is Not Locked
50 | print("\tResponse: Seatbelt Un-locked")
51 |
52 | if __name__ == '__main__':
53 | print("Press keys 'a' or 'b' to Test\n")
54 | on_Key()
55 | threading.Thread(on_Message()).start()
--------------------------------------------------------------------------------
/python-can-usecases/03_SeatBeltControlECU/Seatbelt_ECU_DBC.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 30-Apr-2020
3 |
4 | @author: bk
5 | '''
6 |
7 | import can
8 | import cantools
9 | import threading
10 |
11 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
12 | db = cantools.db.load_file('Basic_DBC.dbc')
13 |
14 | brakeMsg = db.get_message_by_name('BrakeMsg')
15 | accelerationMsg = db.get_message_by_name('AccelarationMsg')
16 | seatbeltMsg = db.get_message_by_name('SeatbeltMsg')
17 |
18 | def _lock_Seatbelt():
19 | data = seatbeltMsg.encode({'SeatbeltStatus':1,'SeatbeltLock':1,})
20 | message = can.Message(arbitration_id=seatbeltMsg.frame_id, data=data, is_extended_id=False)
21 | try:
22 | bus.send(message)
23 | print("SEATBELT LOCKED")
24 | except can.CanError:
25 | print("Message not sent")
26 |
27 | def _unlock_Seatbelt():
28 | data = seatbeltMsg.encode({'SeatbeltStatus':1,'SeatbeltLock':0})
29 | message = can.Message(arbitration_id=seatbeltMsg.frame_id, data=data, is_extended_id=False)
30 | try:
31 | bus.send(message)
32 | print("SEATBELT UNLOCKED")
33 | except can.CanError:
34 | print("Message NOT sent")
35 |
36 | def on_Message():
37 | while True:
38 | message = bus.recv()
39 | msgData = db.decode_message(message.arbitration_id, message.data)
40 | if message.arbitration_id == accelerationMsg.frame_id:
41 | AcclrVal = (msgData['Acceleration'])
42 | if(AcclrVal == 0):
43 | _unlock_Seatbelt()
44 | if message.arbitration_id == brakeMsg.frame_id:
45 | _lock_Seatbelt()
46 |
47 | if __name__ == '__main__':
48 | threading.Thread(on_Message()).start()
--------------------------------------------------------------------------------
/python-can-usecases/03_SeatBeltControlECU/Seatbelt_Tester_DBC.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 15-Apr-2020
3 |
4 | @author: bk
5 | '''
6 |
7 | import can
8 | from pynput import keyboard
9 | import threading
10 | import cantools
11 |
12 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
13 | db = cantools.db.load_file('Basic_DBC.dbc')
14 |
15 | seatbeltMsg = db.get_message_by_name('SeatbeltMsg')
16 | brakeMsg = db.get_message_by_name('BrakeMsg')
17 | accelerationMsg = db.get_message_by_name('AccelarationMsg')
18 |
19 | def on_press(key):
20 | try:
21 | if key.char == 'a': # for Acceleration
22 | data = accelerationMsg.encode({'Acceleration':0})
23 | message = can.Message(arbitration_id=accelerationMsg.frame_id, data=data, is_extended_id=False)
24 | try:
25 | bus.send(message)
26 | print("Message sent: \tVehicle Stopped Moving")
27 | except can.CanError:
28 | print("Message NOT sent")
29 |
30 | if key.char == 'b': # for lock
31 | data = brakeMsg.encode({'BrakeStatus':1})
32 | message = can.Message(arbitration_id=brakeMsg.frame_id, data=data, is_extended_id=False)
33 | try:
34 | bus.send(message)
35 | print("Message sent: \tSudden Break Applaid")
36 | except can.CanError:
37 | print("Message NOT sent")
38 |
39 | except AttributeError:
40 | pass
41 |
42 | def on_Key():
43 | # with keyboard.Listener(on_press=on_press) as listener:
44 | # listener.join()
45 | keyboard.Listener(on_press=on_press).start()
46 |
47 | def on_Message():
48 | while True:
49 | message = bus.recv()
50 | msgData = db.decode_message(message.arbitration_id, message.data)
51 | if message.arbitration_id == seatbeltMsg.frame_id:
52 | seatbeltStatus = (msgData['SeatbeltLock'])
53 | if (seatbeltStatus == 'UnLock'):
54 | #if Seatbelt is not Locked
55 | print("\tResponse: Seatbelt Un-Locked")
56 | if (seatbeltStatus == 'Lock'):
57 | #if Seatbelt is Locked
58 | print("\tResponse: Seatbelt Locked")
59 |
60 | if __name__ == '__main__':
61 | print("Press keys 'a' or 'b' to Test\n")
62 | on_Key()
63 | threading.Thread(on_Message()).start()
--------------------------------------------------------------------------------
/python-can-usecases/03_SeatBeltControlECU/Seatbelt_ecu_raw.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 30-Apr-2020
3 |
4 | @author: bk
5 | '''
6 |
7 | import can
8 | import threading
9 |
10 | bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
11 |
12 | seatbeltMsgID = 0x101
13 | brakeMsgID = 0x105
14 | accelerationMsgID = 0x106
15 |
16 | def _lock_Seatbelt():
17 | message = can.Message(arbitration_id=seatbeltMsgID, data=[3,0,0,0], is_extended_id=False)
18 | #Seatbelt Worn and Lock
19 | try:
20 | bus.send(message)
21 | print("SEATBELT LOCKED")
22 | except can.CanError:
23 | print("Message not sent")
24 |
25 | def _unlock_Seatbelt():
26 | message = can.Message(arbitration_id=seatbeltMsgID, data=[1,0,0,0], is_extended_id=False)
27 | #Seatbelt Worn but unLock
28 | try:
29 | bus.send(message)
30 | print("SEATBELT UN-LOCKED")
31 | except can.CanError:
32 | print("Message not sent")
33 |
34 | def on_Message():
35 | while True:
36 | message = bus.recv()
37 | msgData = message.data
38 | if message.arbitration_id == accelerationMsgID:
39 | if((msgData[0] == 0) and (msgData[1] == 0)): #Check the Value in 2bytes == 0
40 | _unlock_Seatbelt()
41 |
42 | if message.arbitration_id == brakeMsgID:
43 | _lock_Seatbelt()
44 |
45 | if __name__ == '__main__':
46 | threading.Thread(on_Message()).start()
--------------------------------------------------------------------------------
/python-can-usecases/03_SeatBeltControlECU/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/03_SeatBeltControlECU/__init__.py
--------------------------------------------------------------------------------
/python-can-usecases/03_SeatBeltControlECU/precrash seatbelt test case.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/03_SeatBeltControlECU/precrash seatbelt test case.pdf
--------------------------------------------------------------------------------
/python-can-usecases/03_SeatBeltControlECU/seatbeltECU.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on 15-Apr-2020
3 |
4 | @author: bk
5 | '''
6 | import struct
7 | import can
8 |
9 | def create_message(seatbelt_status):
10 | return can.Message(arbitration_id=0x010,
11 | extended_id=False,
12 | data=struct.pack('= 20):
37 | data = climate_Control_MSg.encode({'ac_status':1})
38 | #data = climate_Control_MSg.encode({'ac_status':0})
39 | message = can.Message(arbitration_id=climate_Control_MSg.frame_id, data=data, is_extended_id=False)
40 | try:
41 | can_bus.send(message)
42 | print("AC is Turned ON")
43 | except can.CanError:
44 | print("Message NOT sent")
45 |
46 | def on_press(key):
47 | print("Key Event Identified")
48 | try:
49 | if key.char == 'a': # handles if key press is a
50 | # Message : climate_simulation_data
51 | data = climate_simulation_MSg.encode({'indoor_temp':0})
52 | message = can.Message(arbitration_id=climate_simulation_MSg.frame_id, data=data, is_extended_id=False)
53 | try:
54 | can_bus.send(message)
55 | print("Set Temp : 0")
56 | #print(" climate_simulation_data Message sent on {}".format(can_bus.channel_info))
57 | except can.CanError:
58 | print("Message NOT sent")
59 | if key.char == 'b': # handles if key press is a
60 | # Message : climate_simulation_data
61 | data = climate_simulation_MSg.encode({'indoor_temp':30})
62 | message = can.Message(arbitration_id=climate_simulation_MSg.frame_id, data=data, is_extended_id=False)
63 | try:
64 | can_bus.send(message)
65 | print("Set Temp : 30")
66 | #print(" climate_simulation_data Message sent on {}".format(can_bus.channel_info))
67 | except can.CanError:
68 | print("Message NOT sent")
69 | except AttributeError:
70 | print(" Unknown Key Event")
71 |
72 |
73 | def on_Key():
74 | keyboard.Listener(on_press=on_press).start()
75 |
76 | def sendMessage():
77 | # Message : vehicle_simulation_data
78 | example_message = db.get_message_by_name('vehicle_simulation_data')
79 | data = example_message.encode({'engine_speed':0,'vehicle_speed':0})
80 | message = can.Message(arbitration_id=example_message.frame_id, data=data, is_extended_id=False)
81 | try:
82 | task = can_bus.send_periodic(message,4.0) # cycle time
83 | print("Periodic Message Started")
84 | except can.CanError:
85 | print("Message NOT sent")
86 |
87 | if __name__ == '__main__':
88 |
89 | sendMessage()
90 | #on_Key()
91 | threading.Thread(on_Message()).start()
92 |
--------------------------------------------------------------------------------
/python-can-usecases/05_ClimateControlECU/readme.md:
--------------------------------------------------------------------------------
1 | #CLIMATE_CONTROL_ECU
2 |
3 | ## messages and signals
4 | 1. Vehicle_simulation_data
5 | a. vehicle_speed
6 | b. engine_speed.
7 | 2. climate_simulation_data
8 | a. indoor_temperature
9 | 3. climate_control_signal
10 | a. Ac status
11 |
12 |
13 | ## Functionality
14 | The climate ECU, gives the vehicle speed as a periodic message. It checks for the indoor temperature of the car. It set the AC status, according to the indoor temperature of the car.
15 |
16 | ## Pre-conditions
17 | To set the virtual can, use the following command:
18 | sudo modprobe vcan
19 | sudo ip link add vcan0 type vcan0
20 | sudo ip link set vcan0 up
21 |
22 |
23 | ## Use cases
24 | The vehicle speed is always taken into consideration. However, this does not affect the AC status. The indoor temperature of the car is read. If the temperature is lesser that 25, the AC shall be turned OFF, else the AC status is turned ON.
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/AirbagTestNode.py:
--------------------------------------------------------------------------------
1 | #Date : Wed Apr 16 2020
2 | #Author : Manzoor A
3 | #Script to Test Airbag ECU Simulation
4 |
5 | from __future__ import print_function
6 | import can
7 | import cantools
8 | import threading
9 | from pynput import keyboard
10 |
11 | db = cantools.db.load_file('DBC/Basic_DBC.dbc')
12 | can_bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=250000)
13 |
14 | VehicleMotionMsg = db.get_message_by_name('VehicleMotion')
15 | SeatbeltSystemMsg = db.get_message_by_name('SeatbeltMsg')
16 | airbagSystemMsg = db.get_message_by_name('AirbagMsg')
17 |
18 | def _SeatbeltUnock():
19 | # Send Seatbelt Unlock Message
20 | data = SeatbeltSystemMsg.encode({'SeatbeltStatus':0,'SeatbeltLock':0})
21 | message = can.Message(arbitration_id=SeatbeltSystemMsg.frame_id, data=data, is_extended_id=False)
22 | try:
23 | can_bus.send(message)
24 | print(" Seatbelt Unlocked")
25 | except can.CanError:
26 | print("Message NOT sent")
27 |
28 | def _SeatbeltLock():
29 | # Send Seatbelt Lock Message
30 | data = SeatbeltSystemMsg.encode({'SeatbeltStatus':1,'SeatbeltLock':0})
31 | message = can.Message(arbitration_id=SeatbeltSystemMsg.frame_id, data=data, is_extended_id=False)
32 | try:
33 | can_bus.send(message)
34 | print(" Seatbelt Locked")
35 | except can.CanError:
36 | print("Message NOT sent")
37 |
38 | def _crashDetected():
39 | # Send Crash Detected Message
40 | data = VehicleMotionMsg.encode({'Velocity':10,'CrashDetected':1,'EngineRunning':1})
41 | message = can.Message(arbitration_id=VehicleMotionMsg.frame_id, data=data, is_extended_id=False)
42 | try:
43 | can_bus.send(message)
44 | print(" Crash with Engine ON")
45 | except can.CanError:
46 | print("Message NOT sent")
47 |
48 | def _crashFree():
49 | # Send Crash Detected Message
50 | data = VehicleMotionMsg.encode({'Velocity':10,'CrashDetected':0,'EngineRunning':1})
51 | message = can.Message(arbitration_id=VehicleMotionMsg.frame_id, data=data, is_extended_id=False)
52 | try:
53 | can_bus.send(message)
54 | print(" No Crash with Engine ON")
55 | except can.CanError:
56 | print("Message NOT sent")
57 |
58 | def _engineOffCrash():
59 | # Send Engine off and Crash Detected Message
60 | data = VehicleMotionMsg.encode({'Velocity':0,'CrashDetected':1,'EngineRunning':0})
61 | message = can.Message(arbitration_id=VehicleMotionMsg.frame_id, data=data, is_extended_id=False)
62 | try:
63 | can_bus.send(message)
64 | print(" Crash with Engine Off")
65 | except can.CanError:
66 | print("Message NOT sent")
67 |
68 | def on_press(key):
69 | try:
70 | if key.char == 'l': # if key 'l' pressed
71 | _SeatbeltLock()
72 | if key.char == 'u': # if key 'u' pressed
73 | _SeatbeltUnock()
74 | if key.char == 'c': # if key 'c' pressed
75 | _crashDetected()
76 | if key.char == 'o': # if key 'f' pressed
77 | _engineOffCrash()
78 | if key.char == 'f': # if key 'c' pressed
79 | _crashFree()
80 | if key == keyboard.Key.esc: # if esc is pressed, terminate
81 | return False # Stop listener
82 | except AttributeError:
83 | print(" Unknown Key Event")
84 | #
85 | def on_Key():
86 | # Collect events until on_press return fail
87 | # with keyboard.Listener(on_press=on_press) as listener:
88 | # listener.start()
89 | keyboard.Listener(on_press=on_press).start()
90 |
91 |
92 | def on_Message():
93 | while True:
94 | response = can_bus.recv()
95 | msgData = db.decode_message(response.arbitration_id, response.data)
96 | if response.arbitration_id == airbagSystemMsg.frame_id:
97 | airbagState = (msgData['AirbagStatus'])
98 | if (airbagState == 'Ready'):
99 | # Trigger Idle Airbag
100 | print("\t\t\tAirbag is Ready")
101 | if (airbagState == 'NotReady'):
102 | #Trigger Inactive Airbag
103 | print("\t\t\tAirbag is Not Ready")
104 | if (airbagState == 'Released'):
105 | # Trigger Release Airbag
106 | print("\t\t\tAirbag Released")
107 |
108 | def instruction():
109 | print("Simulation Keys:\n\
110 | l: Lock Seatbelt\n\
111 | u: Unock Seatbelt\n\
112 | c: Crash with Engine On\n\
113 | o: Crash with Engine Off\n\
114 | f: Crash free with Engine On\n")
115 | print("--Test Msg--\t\t--Evaluated Msg--")
116 |
117 | if __name__ == '__main__':
118 | instruction()
119 | on_Key()
120 | threading.Thread(on_Message()).start()
121 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/DBC/Basic_DBC.dbc:
--------------------------------------------------------------------------------
1 | VERSION "created by canmatrix"
2 |
3 |
4 | NS_ :
5 |
6 | BS_:
7 |
8 | BU_:
9 |
10 |
11 | BO_ 257 SeatbeltMsg: 8 Vector__XXX
12 | SG_ SeatbeltStatus : 0|1@1+ (1,0) [0|1] "" Vector__XXX
13 | SG_ SeatbeltLock : 1|1@1+ (1,0) [0|1] "" Vector__XXX
14 |
15 | BO_ 258 AirbagMsg: 8 Vector__XXX
16 | SG_ AirbagStatus : 0|2@1+ (1,0) [0|3] "" Vector__XXX
17 | SG_ AirbagCondition : 2|1@1+ (1,0) [0|1] "" Vector__XXX
18 |
19 | BO_ 260 VehicleMotion: 8 Vector__XXX
20 | SG_ CrashDetected : 0|1@1+ (1,0) [0|1] "" Vector__XXX
21 | SG_ EngineRunning : 1|1@1+ (1,0) [0|1] "" Vector__XXX
22 | SG_ Velocity : 8|16@1+ (0.1,0) [0|65535] "km/h" Vector__XXX
23 |
24 | BO_ 261 BrakeMsg: 8 Vector__XXX
25 | SG_ BrakeStatus : 0|1@1+ (1,0) [0|1] "" Vector__XXX
26 |
27 | BO_ 262 AccelarationMsg: 8 Vector__XXX
28 | SG_ Acceleration : 0|16@1+ (0.1,0) [0|65535] "m/s2" Vector__XXX
29 |
30 |
31 |
32 | CM_ SG_ 257 SeatbeltStatus "Status of wether Seatbelt is worn or not";
33 | CM_ SG_ 257 SeatbeltLock "Status of wether Seatbelt is Locked";
34 | CM_ SG_ 258 AirbagStatus "Echos the state of the Airbag Condition";
35 | CM_ SG_ 258 AirbagCondition "state of the Airbag Health";
36 | CM_ SG_ 260 CrashDetected "Status of wether crash is detected or not";
37 | CM_ SG_ 260 EngineRunning "Echos Engine Running Status";
38 | CM_ SG_ 260 Velocity "Value of the Vehicles Velocity";
39 | CM_ SG_ 261 BrakeStatus "Status of wether Brake is applied or not";
40 | CM_ SG_ 262 Acceleration "Value of the Acceleration Applaid";
41 |
42 |
43 | BA_DEF_ BO_ "GenMsgCycleTimeActive" INT 0 65535;
44 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 65535;
45 | BA_DEF_ BO_ "GenMsgNrOfRepetitions" INT 0 65535;
46 | BA_DEF_ BO_ "GenMsgSendType" ENUM;
47 | BA_DEF_ SG_ "GenSigSNA" STRING;
48 |
49 |
50 |
51 |
52 | VAL_ 257 SeatbeltStatus 0 "NotWorn" 1 "Worn";
53 | VAL_ 257 SeatbeltLock 0 "UnLock" 1 "Lock";
54 | VAL_ 258 AirbagStatus 0 "Ready" 1 "NotReady" 2 "Released";
55 | VAL_ 258 AirbagCondition 0 "Damage" 1 "Healthy";
56 | VAL_ 260 CrashDetected 0 "CrashFree" 1 "Crash";
57 | VAL_ 260 EngineRunning 0 "NotRunning" 1 "Running";
58 | VAL_ 261 BrakeStatus 0 "BrakeNotApplied" 1 "BrakeApplied";
59 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/DBC/Basic_DBCinExcel.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/DBC/Basic_DBCinExcel.xlsx
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/RAW_Message/AirbagTestNode_RAW.py:
--------------------------------------------------------------------------------
1 | #Date : Wed Apr 29 2020
2 | #Author : Manzoor A
3 | #Script to Test Airbag ECU Simulation
4 |
5 | import can
6 | import threading
7 | from pynput import keyboard
8 |
9 | can_bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=250000)
10 |
11 | seatbeltMsgID = 0x101
12 | airbagMsgID = 0x102
13 | VehicleMotionMsgID = 0x104
14 |
15 | def _SeatbeltUnock():
16 | # Send Seatbelt Unlock Message
17 | data = [0x00, 0, 0, 0, 0, 0, 0, 0]
18 | message = can.Message(arbitration_id=seatbeltMsgID, data=data, is_extended_id=False)
19 | try:
20 | can_bus.send(message)
21 | print(" Seatbelt Unlocked")
22 | except can.CanError:
23 | print("Message NOT sent")
24 |
25 | def _SeatbeltLock():
26 | # Send Seatbelt Lock Message
27 | data = [0x01, 0, 0, 0, 0, 0, 0, 0]
28 | message = can.Message(arbitration_id=seatbeltMsgID, data=data, is_extended_id=False)
29 | try:
30 | can_bus.send(message)
31 | print(" Seatbelt Locked")
32 | except can.CanError:
33 | print("Message NOT sent")
34 |
35 | def _crashDetected():
36 | # Send Crash Detected Message
37 | data = [0x03, 0, 0x64, 0, 0, 0, 0, 0]
38 | message = can.Message(arbitration_id=VehicleMotionMsgID, data=data, is_extended_id=False)
39 | try:
40 | can_bus.send(message)
41 | print(" Crash with Engine ON")
42 | except can.CanError:
43 | print("Message NOT sent")
44 |
45 | def _crashFree():
46 | # Send Crash Detected Message
47 | data = [0x02, 0, 0x64, 0, 0, 0, 0, 0]
48 | message = can.Message(arbitration_id=VehicleMotionMsgID, data=data, is_extended_id=False)
49 | try:
50 | can_bus.send(message)
51 | print(" No Crash with Engine ON")
52 | except can.CanError:
53 | print("Message NOT sent")
54 |
55 | def _engineOffCrash():
56 | # Send Engine off and Crash Detected Message
57 | data = [0x01, 0, 0x00, 0, 0, 0, 0, 0]
58 | message = can.Message(arbitration_id=VehicleMotionMsgID, data=data, is_extended_id=False)
59 | try:
60 | can_bus.send(message)
61 | print(" Crash with Engine Off")
62 | except can.CanError:
63 | print("Message NOT sent")
64 |
65 | def on_press(key):
66 | try:
67 | if key.char == 'l': # if key 'l' pressed
68 | _SeatbeltLock()
69 | if key.char == 'u': # if key 'u' pressed
70 | _SeatbeltUnock()
71 | if key.char == 'c': # if key 'c' pressed
72 | _crashDetected()
73 | if key.char == 'o': # if key 'f' pressed
74 | _engineOffCrash()
75 | if key.char == 'f': # if key 'c' pressed
76 | _crashFree()
77 | if key == keyboard.Key.esc: # if esc is pressed, terminate
78 | return False # Stop listener
79 | except AttributeError:
80 | print(" Unknown Key Event")
81 | #
82 | def on_Key():
83 | # Collect events until on_press return fail
84 | # with keyboard.Listener(on_press=on_press) as listener:
85 | # listener.start()
86 | keyboard.Listener(on_press=on_press).start()
87 |
88 |
89 | def on_Message():
90 | while True:
91 | response = can_bus.recv()
92 | if response.arbitration_id == airbagMsgID:
93 | airbagNotReady = bool(response.data[0] & 1) #0th Bit of 0th Byte
94 | airbagReleased = bool(response.data[0] & (1<<1)) #1st Bit of 0th Byte
95 |
96 | # (airbagReleased): 0000 0010
97 | # (1<<1): 0000 0010
98 | # 0000 0010
99 |
100 | if (airbagReleased):
101 | #if(response.data[0] == 0x02):
102 | print("\t\t\tAirbag Released")
103 |
104 | elif(airbagNotReady):
105 | #elif(response.data[0] == 0x01):
106 | print("\t\t\tAirbag is Not Ready")
107 |
108 | elif (airbagNotReady is not True):
109 | #elif(response.data[0] == 0x00):
110 | print("\t\t\tAirbag is Ready")
111 |
112 | def instruction():
113 | print("Simulation Keys:\n\
114 | l: Lock Seatbelt\n\
115 | u: Unock Seatbelt\n\
116 | c: Crash with Engine On\n\
117 | o: Crash with Engine Off\n\
118 | f: Crash free with Engine On\n")
119 | print("--Test Msg--\t\t--Evaluated Msg--")
120 |
121 | if __name__ == '__main__':
122 | instruction()
123 | on_Key()
124 | threading.Thread(on_Message()).start()
125 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/RAW_Message/airbagECUSimulation_RAW.py:
--------------------------------------------------------------------------------
1 | #ANCIT CONSULTING
2 | #Date : Wed Apr 29
3 | #Author : Manzoor A
4 |
5 | from __future__ import print_function
6 | import can
7 | import threading
8 |
9 | can_bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=250000)
10 |
11 | seatbeltMsgID = 0x101
12 | airbagMsgID = 0x102
13 | VehicleMotionMsgID = 0x104
14 |
15 | def _Airbag_Not_Ready():
16 | # Send Not Ready Airbag Message
17 | data = [0x01, 0, 0, 0, 0, 0, 0, 0]
18 | message = can.Message(arbitration_id=airbagMsgID, data=data, is_extended_id=False)
19 | try:
20 | can_bus.send(message)
21 | print(" Airbag is Not Ready")
22 | except can.CanError:
23 | print("Message NOT sent")
24 |
25 | def _Airbag_Ready():
26 | # Send Airbag Ready state Message
27 | data = [0x00, 0, 0, 0, 0, 0, 0, 0]
28 | message = can.Message(arbitration_id=airbagMsgID, data=data, is_extended_id=False)
29 | try:
30 | can_bus.send(message)
31 | print(" Airbag is Ready")
32 | except can.CanError:
33 | print("Message NOT sent")
34 |
35 | def _Airbag_Release():
36 | # Send Airbag Release Message
37 | data = [0x02, 0, 0, 0, 0, 0, 0, 0]
38 | message = can.Message(arbitration_id=airbagMsgID, data=data, is_extended_id=False)
39 | try:
40 | can_bus.send(message)
41 | print(" Airbag Released")
42 | except can.CanError:
43 | print("Message NOT sent")
44 |
45 | def on_Message():
46 | while True:
47 | response = can_bus.recv()
48 | if response.arbitration_id == seatbeltMsgID:
49 | #seatbeltWorn = bool(response.data[0] & 1) #0th Bit of 0th Byte
50 | seatbeltWorn = (response.data[0] == 0x01)
51 |
52 | print(" Recieved Seatbelt Message")
53 | if (seatbeltWorn):
54 | # Trigger Airbag Ready
55 | _Airbag_Ready()
56 | else:
57 | #Trigger Airbag Not Ready
58 | _Airbag_Not_Ready()
59 |
60 | if response.arbitration_id == VehicleMotionMsgID:
61 | crashDetected = (bool(response.data[0] & (1))) #0th Bit of 0th Byte
62 | engineRunning = (bool(response.data[0] & (1<<1))) #1st Bit of 0th Byte
63 |
64 | print(" Recieved Vehcle Motion Message")
65 | #if Crash Detected, and Seatbelt is worn
66 | if (crashDetected):
67 | if (seatbeltWorn and engineRunning):
68 | # Trigger Airbag Release
69 | _Airbag_Release()
70 | else:
71 | #Trigger Airbag Not Ready
72 | _Airbag_Not_Ready()
73 |
74 | if __name__ == '__main__':
75 | threading.Thread(on_Message()).start()
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/base/averagetime.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import time
3 |
4 |
5 | class AverageTime:
6 | """ AverageTime calculate the average time between given ticks
7 | The precision can go to 100µs between two ticks, faster it
8 | will be unprecise
9 | """
10 |
11 | def __init__(self):
12 | """Instanciate a AverageTime object
13 | """
14 | self.tick = time.time()
15 | self.last_tick = time.time()
16 | self.time_array = []
17 | self.average = 0
18 | self.isnew = 1
19 |
20 | def put_tick(self):
21 | """ Add a tick
22 | """
23 | if self.isnew == 1:
24 | self.tick = time.time()
25 | self.isnew = 0
26 | else:
27 | self.last_tick = time.time()
28 | time_elapsed = self.last_tick - self.tick
29 | self.time_array.append(time_elapsed)
30 | self.tick = time.time()
31 |
32 | def get_average(self):
33 | """ Return average time between ticks
34 | """
35 | self.average = sum(self.time_array)/float(len(self.time_array))
36 | return self.average
37 |
38 | def get_list(self):
39 | """ Return list of elapsed times
40 | """
41 | return self.time_array
42 |
43 | def clean_list(self):
44 | """ Clean the list
45 | """
46 | self.time_array = []
47 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/dbc/airbag_MainBus.dbc:
--------------------------------------------------------------------------------
1 | VERSION ""
2 |
3 |
4 | NS_ :
5 |
6 | BS_:
7 |
8 | BU_: airbagECU airbag
9 |
10 |
11 | BO_ 1 SeatbeltSystem: 1 airbagECU
12 | SG_ SeatbeltState : 0|1@1+ (1,0) [0|0] "" Vector__XXX
13 |
14 | BO_ 0 AirbagSystem: 2 airbagECU
15 | SG_ airbagState : 0|2@1+ (1,0) [0|2] "" Vector__XXX
16 | SG_ AirbagCondition : 2|1@1+ (1,0) [0|1] "" Vector__XXX
17 |
18 | BO_ 50 VehicleMotion: 3 airbagECU
19 | SG_ EngineRunning : 17|1@1+ (1,0) [0|1] "" Vector__XXX
20 | SG_ CrashDetected : 16|1@1+ (1,0) [0|0] "" Vector__XXX
21 | SG_ Velocity : 0|16@1- (0.1,0) [-100|350] "km/h" Vector__XXX
22 |
23 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/dbc/system_MainBus.dbc:
--------------------------------------------------------------------------------
1 | VERSION "created by canmatrix"
2 |
3 |
4 | NS_ :
5 |
6 | BS_:
7 |
8 | BU_: Motor Controller
9 |
10 |
11 | BO_ 16 MotorStatus: 3 Motor
12 | SG_ MSSpeed : 0|16@1+ (1,0) [0|65535] "" Controller
13 | SG_ Load : 16|8@1+ (1,0) [0|255] "" Controller
14 |
15 | BO_ 17 MotorControl: 2 Controller
16 | SG_ MCSpeed : 0|16@1+ (1,0) [0|65535] "" Motor
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/outputs/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/canRaw.robot:
--------------------------------------------------------------------------------
1 | *** Settings ***
2 | Resource ../keywords/curf.robot
3 | Test Setup Set CAN Bus ${INTERFACE} ${CHANNEL} ${BITRATE} ${DB FILE}
4 | Test Teardown End Log Can
5 | Library DateTime
6 |
7 | *** Variables ***
8 | ${DB FILE} /home/ancit/Documents/malai/robotframework-can-uds-library-master/CURF/dbc/Example.dbc
9 | ${INTERFACE} socketcan
10 | ${CHANNEL} vcan0
11 | ${BITRATE} 500000
12 | ${DEFAULT TIMEOUT} 3
13 | ${DEFAULT NODE} DRIVER
14 |
15 |
16 | *** Test Cases ***
17 | Log Next Raw Frame
18 | ${Next_Frame} = Get Next Raw Can Frame
19 | Log ${Next_Frame}
20 |
21 | Check reception of message
22 | Check The Reception Of SENSOR_SONARS TimeOut ${DEFAULT TIMEOUT} Seconds
23 |
24 | Check non reception of message
25 | Check Message MOTOR_CMD TimeOut ${DEFAULT TIMEOUT} Seconds Is Not Received
26 |
27 | Check reception of message in a given node
28 | Check The Reception Of SENSOR_SONARS TimeOut ${DEFAULT TIMEOUT} Seconds In Node ${DEFAULT NODE}
29 |
30 | Check non reception of message in a given node
31 | Check Message SENSOR_SONARS TimeOut ${DEFAULT TIMEOUT} Seconds Is Not Received In Node ${DEFAULT NODE}
32 |
33 | Send a CAN frame
34 | Send Frame With ID 0x5D3 And DEADBEEF As Data
35 |
36 | Send a given signal
37 | Send Signal SENSOR_SONARS_err_count With Value 0
38 |
39 | Check reception of a frame
40 | Check The Frame Reception With ID 5D3 And 0x0 As Data Timeout ${DEFAULT TIMEOUT} Seconds
41 |
42 | Check reception of a frame with given ID and any data
43 | Check The Frame Reception With ID 5D3 And ANY As Data Timeout ${DEFAULT TIMEOUT} Seconds
44 |
45 | Send periodic message
46 | Start Transmission Of Message SENSOR_SONARS Without Data With 1 Seconds Period
47 | Waiting 5 Seconds
48 | Start Transmission Of Message MOTOR_STATUS And 2 As Data With 1 Seconds Period
49 | Waiting 5 Seconds
50 | Stop Transmission Of Messages
51 |
52 | Send periodic signal
53 | Start Transmission Of Signal SENSOR_SONARS_middle And 0 As Value With 1 Seconds Period
54 | Waiting 5 Seconds
55 | Stop Transmission Of Messages
56 |
57 | Check the reception of a CAN signal
58 | Check CAN Signal SENSOR_SONARS_middle Equals To 0 TimeOut ${DEFAULT TIMEOUT} Seconds
59 |
60 | Check the non reception of a CAN signal
61 | Check CAN Signal SENSOR_SONARS_err_count Is Not Received In Timeout ${DEFAULT TIMEOUT} Seconds
62 |
63 | Check the periodicity of a frame with a given ID
64 | Check Frame ID 0x5D3 For 10 Times Expect Period 1 Seconds
65 |
66 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_112844:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967125.508990 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_113018:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967219.509358 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_113200:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_113200
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_113315:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967396.693852 ID: 0000 S DLC: 2 02 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_113459:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967500.696469 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_113627:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967588.699874 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_113716:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967637.701405 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_114513:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968114.717622 ID: 0000 S DLC: 2 02 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Active Status_20200427_114640:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968201.722892 ID: 0000 S DLC: 2 02 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_112843:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967124.508969 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_113017:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967218.509504 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_113159:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967320.515926 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_113314:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967395.693489 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_113458:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967499.696840 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_113626:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967587.699454 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_113715:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967636.701712 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_114512:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968113.717574 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Idle Status_20200427_114639:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968200.722534 ID: 0000 S DLC: 2 00 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_112842:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967123.506168 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_113016:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967217.509502 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_113159:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967319.512889 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_113313:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967394.693110 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_113458:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967498.702198 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_113626:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967586.699176 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_113715:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967635.701205 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_114512:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968112.717579 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Check the reception of Airbag Inactive Status_20200427_114639:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968199.721486 ID: 0000 S DLC: 2 01 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_112844:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967124.524454 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_113018:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967218.559090 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_113200:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967320.558993 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_113315:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967395.735478 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_113459:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967499.741854 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_113627:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_113627
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_113716:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send Message VehicleMotion_20200427_113716
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected CAN frame_20200427_113018:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected CAN frame_20200427_113018
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected CAN frame_20200427_113200:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967320.532800 ID: 00000050 X DLC: 3 00 00 03 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected CAN frame_20200427_113315:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967395.717164 ID: 00000032 X DLC: 3 00 00 03 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected Signal_20200427_113459:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected Signal_20200427_113459
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected with Engine Run CAN frame_20200427_114513:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968113.731866 ID: 00000032 X DLC: 3 00 00 03 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected with Engine Run CAN frame_20200427_114640:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Crash Detected with Engine Run CAN frame_20200427_114640
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_112843:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967123.526686 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_113017:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967217.527246 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_113159:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967319.531035 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_113314:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967394.709659 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_113458:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_113458
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_113626:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967586.724789 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_113715:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_113715
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_114512:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968112.739969 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Engine Run Signal_20200427_114639:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968199.740037 ID: 00000032 X DLC: 3 00 00 02 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_112843:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967123.545781 ID: 00000001 X DLC: 1 01 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_113017:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_113017
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_113159:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967319.555942 ID: 00000001 X DLC: 1 01 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_113314:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967394.727170 ID: 00000001 X DLC: 1 01 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_113458:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967498.764062 ID: 00000001 X DLC: 1 01 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_113626:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967586.744033 ID: 00000001 X DLC: 1 01 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_113715:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967635.745898 ID: 00000001 X DLC: 1 01 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_114512:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968112.768514 ID: 00000001 X DLC: 1 01 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Lock Signal_20200427_114639:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968199.760255 ID: 00000001 X DLC: 1 01 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_112842:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967122.579197 ID: 00000001 X DLC: 1 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113016:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113016
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113159:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967319.236051 ID: 00000001 X DLC: 1 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113313:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113313
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113458:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113458
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113626:
--------------------------------------------------------------------------------
1 | Timestamp: 1587967586.255094 ID: 00000001 X DLC: 1 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113715:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_113715
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_114512:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968112.444428 ID: 00000001 X DLC: 1 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/outputs/20200427/Send a Seatbelt Un-lock Signal_20200427_114639:
--------------------------------------------------------------------------------
1 | Timestamp: 1587968199.535243 ID: 00000001 X DLC: 1 00 Channel: vcan0
2 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/Robot_Tester/testsuite/tester_Airbag_usecase.robot:
--------------------------------------------------------------------------------
1 | *** Settings ***
2 | Resource ../keywords/curf.robot
3 | Test Setup Set CAN Bus ${INTERFACE} ${CHANNEL} ${BITRATE} ${DB FILE}
4 | Test Teardown End Log Can
5 | Library DateTime
6 |
7 | *** Variables ***
8 | ${DB FILE} /home/manz/eclipse-workspace/AirbagTestNode_Robot/dbc/airbag_MainBus.dbc
9 | ${INTERFACE} socketcan
10 | ${CHANNEL} vcan0
11 | ${BITRATE} 250000
12 | ${DEFAULT TIMEOUT} 3
13 | ${DEFAULT NODE} DRIVER
14 |
15 |
16 | *** Test Cases ***
17 | #Check the reception of a CAN signal 01
18 | # Check CAN Signal SeatbeltState Equals To 0 TimeOut ${DEFAULT TIMEOUT} Seconds
19 | Send a Seatbelt Un-lock Signal
20 | Send Signal SeatbeltState With Value 0
21 |
22 | Check the reception of Airbag Inactive Status
23 | Check CAN Signal airbagState Equals To 1 TimeOut ${DEFAULT TIMEOUT} Seconds
24 |
25 | Send a Engine Run Signal
26 | Send Signal EngineRunning With Value 1
27 |
28 | Send a Seatbelt Lock Signal
29 | Send Signal SeatbeltState With Value 1
30 |
31 | Check the reception of Airbag Idle Status
32 | Check CAN Signal airbagState Equals To 0 TimeOut ${DEFAULT TIMEOUT} Seconds
33 |
34 | # Send a Crash Detected Signal
35 | # Send Signal EngineRunning With Value 1
36 | # Send Signal CrashDetected With Value 1
37 |
38 | Send a Crash Detected with Engine Run CAN frame
39 | Send Frame With ID 32 And 000003 As Data
40 |
41 | Check the reception of Airbag Active Status
42 | Check CAN Signal airbagState Equals To 2 TimeOut ${DEFAULT TIMEOUT} Seconds
43 |
44 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/06_AirBagControlECU/__init__.py
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/airbagECUSimulation.py.py:
--------------------------------------------------------------------------------
1 | #ANCIT CONSULTING
2 | #Date : Wed Apr 16
3 | #Author : Manzoor A
4 |
5 | from __future__ import print_function
6 | import can
7 | import cantools
8 | import threading
9 | db = cantools.db.load_file('DBC/Basic_DBC.dbc')
10 | can_bus = can.interface.Bus(bustype='socketcan',channel='vcan0',bitrate=250000)
11 |
12 | VehicleMotionMsg = db.get_message_by_name('VehicleMotion')
13 | SeatbeltSystemMsg = db.get_message_by_name('SeatbeltMsg')
14 | airbagSystemMsg = db.get_message_by_name('AirbagMsg')
15 |
16 | def _Airbag_Not_Ready():
17 | # Send In-activate Airbag Message
18 | msgData = {'AirbagStatus':1,'AirbagCondition':0 }
19 | data = airbagSystemMsg.encode(msgData)
20 | message = can.Message(arbitration_id=airbagSystemMsg.frame_id, data=data, is_extended_id=False)
21 | try:
22 | can_bus.send(message)
23 | print(" Airbag is Not Ready")
24 | except can.CanError:
25 | print("Message NOT sent")
26 |
27 | def _Airbag_Ready():
28 | # Send Idle Airbag state Message
29 | msgData = {'AirbagStatus':0,'AirbagCondition':0}
30 | data = airbagSystemMsg.encode(msgData)
31 | message = can.Message(arbitration_id=airbagSystemMsg.frame_id, data=data, is_extended_id=False)
32 | try:
33 | can_bus.send(message)
34 | print(" Airbag is Ready")
35 | except can.CanError:
36 | print("Message NOT sent")
37 |
38 | def _Airbag_Release():
39 | # Send Airbag Release Message
40 | msgData = {'AirbagStatus':2,'AirbagCondition':0}
41 | data = airbagSystemMsg.encode(msgData)
42 | message = can.Message(arbitration_id=airbagSystemMsg.frame_id, data=data, is_extended_id=False)
43 | try:
44 | can_bus.send(message)
45 | print(" Airbag Released")
46 | except can.CanError:
47 | print("Message NOT sent")
48 |
49 | def on_Message():
50 | while True:
51 | response = can_bus.recv()
52 | msgData = db.decode_message(response.arbitration_id, response.data)
53 | if response.arbitration_id == SeatbeltSystemMsg.frame_id:
54 | seatbeltState = (msgData['SeatbeltStatus'])
55 | print(" Recieved Seatbelt Message")
56 | #if Seatbelt is not Worn
57 | if (seatbeltState == 'NotWorn'):
58 | #Trigger Airbag Not Ready
59 | _Airbag_Not_Ready()
60 | else:
61 | # Trigger Airbag Ready
62 | _Airbag_Ready()
63 |
64 | if response.arbitration_id == VehicleMotionMsg.frame_id:
65 | crashDetected = (msgData['CrashDetected'])
66 | engineRunning = (msgData['EngineRunning'])
67 | print(" Recieved Vehcle Message:\t{}".format(msgData))
68 | #if Crash Detected, and Seatbelt is worn
69 | if (crashDetected=='Crash'):
70 | if (seatbeltState == 'Worn' and engineRunning=='Running'):
71 | # Trigger Airbag Release
72 | _Airbag_Release()
73 | else:
74 | #Trigger Airbag Not Ready
75 | _Airbag_Not_Ready()
76 |
77 | if __name__ == '__main__':
78 | threading.Thread(on_Message()).start()
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/airbag_MainBus.dbc:
--------------------------------------------------------------------------------
1 | VERSION ""
2 |
3 |
4 | NS_ :
5 | NS_DESC_
6 | CM_
7 | BA_DEF_
8 | BA_
9 | VAL_
10 | CAT_DEF_
11 | CAT_
12 | FILTER
13 | BA_DEF_DEF_
14 | EV_DATA_
15 | ENVVAR_DATA_
16 | SGTYPE_
17 | SGTYPE_VAL_
18 | BA_DEF_SGTYPE_
19 | BA_SGTYPE_
20 | SIG_TYPE_REF_
21 | VAL_TABLE_
22 | SIG_GROUP_
23 | SIG_VALTYPE_
24 | SIGTYPE_VALTYPE_
25 | BO_TX_BU_
26 | BA_DEF_REL_
27 | BA_REL_
28 | BA_DEF_DEF_REL_
29 | BU_SG_REL_
30 | BU_EV_REL_
31 | BU_BO_REL_
32 | SG_MUL_VAL_
33 |
34 | BS_:
35 |
36 | BU_: airbagECU airbag
37 | VAL_TABLE_ vtSig_airbagState 2 "Active" 1 "Inactive" 0 "Idle" ;
38 |
39 |
40 | BO_ 1 SeatbeltSystem: 1 airbagECU
41 | SG_ SeatbeltState : 0|1@1+ (1,0) [0|0] "" Vector__XXX
42 |
43 | BO_ 0 AirbagSystem: 2 airbagECU
44 | SG_ airbagState : 0|2@1+ (1,0) [0|2] "" Vector__XXX
45 | SG_ AirbagCondition : 2|1@1+ (1,0) [0|1] "" Vector__XXX
46 |
47 | BO_ 50 VehicleMotion: 3 airbagECU
48 | SG_ EngineRunning : 17|1@1+ (1,0) [0|1] "" Vector__XXX
49 | SG_ CrashDetected : 16|1@1+ (1,0) [0|0] "" Vector__XXX
50 | SG_ Velocity : 0|16@1- (0.1,0) [-100|350] "km/h" Vector__XXX
51 |
52 |
53 |
54 | BA_DEF_ "NmMessageCount" INT 0 0;
55 | BA_DEF_ BO_ "DiagResponse" ENUM "No","Yes";
56 | BA_DEF_ BO_ "DiagRequest" ENUM "No","Yes";
57 | BA_DEF_ BO_ "GenMsgFastOnStart" INT 0 0;
58 | BA_DEF_ BO_ "GenMsgStartDelayTime" INT 0 0;
59 | BA_DEF_ SG_ "NWM-WakeupAllowed" ENUM "No","Yes";
60 | BA_DEF_ BO_ "NmMessage" ENUM "no","yes";
61 | BA_DEF_ BO_ "GenMsgILSupport" ENUM "No","Yes";
62 | BA_DEF_ BU_ "NmNode" ENUM "no","yes";
63 | BA_DEF_ BU_ "NmStationAddress" INT 0 63;
64 | BA_DEF_ "NmBaseAddress" HEX 1024 1087;
65 | BA_DEF_ BO_ "GenMsgCycleTimeFast" INT 0 50000;
66 | BA_DEF_ "BusType" STRING ;
67 | BA_DEF_ BO_ "GenMsgCycleTime" INT 0 50000;
68 | BA_DEF_ BO_ "GenMsgDelayTime" INT 0 1000;
69 | BA_DEF_ BO_ "GenMsgNrOfRepetition" INT 0 999999;
70 | BA_DEF_ BO_ "GenMsgSendType" ENUM "Cyclic","NotUsed","NotUsed","NotUsed","NotUsed","Cyclic","NotUsed","IfActive","NoMsgSendType","NotUsed","vector_leerstring";
71 | BA_DEF_ SG_ "GenSigInactiveValue" INT 0 100000;
72 | BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType","NotUsed","NotUsed","NotUsed","NotUsed","NotUsed";
73 | BA_DEF_ SG_ "GenSigStartValue" FLOAT 0 100000000000;
74 | BA_DEF_DEF_ "NmMessageCount" 64;
75 | BA_DEF_DEF_ "DiagResponse" "No";
76 | BA_DEF_DEF_ "DiagRequest" "No";
77 | BA_DEF_DEF_ "GenMsgFastOnStart" 0;
78 | BA_DEF_DEF_ "GenMsgStartDelayTime" 0;
79 | BA_DEF_DEF_ "NWM-WakeupAllowed" "";
80 | BA_DEF_DEF_ "NmMessage" "no";
81 | BA_DEF_DEF_ "GenMsgILSupport" "Yes";
82 | BA_DEF_DEF_ "NmNode" "no";
83 | BA_DEF_DEF_ "NmStationAddress" 0;
84 | BA_DEF_DEF_ "NmBaseAddress" 1024;
85 | BA_DEF_DEF_ "GenMsgCycleTimeFast" 0;
86 | BA_DEF_DEF_ "BusType" "CAN";
87 | BA_DEF_DEF_ "GenMsgCycleTime" 100;
88 | BA_DEF_DEF_ "GenMsgDelayTime" 0;
89 | BA_DEF_DEF_ "GenMsgNrOfRepetition" 0;
90 | BA_DEF_DEF_ "GenMsgSendType" "NoMsgSendType";
91 | BA_DEF_DEF_ "GenSigInactiveValue" 0;
92 | BA_DEF_DEF_ "GenSigSendType" "Cyclic";
93 | BA_DEF_DEF_ "GenSigStartValue" 0;
94 | BA_ "GenSigSendType" SG_ 50 CrashDetected 1;
95 | VAL_ 0 airbagState 2 "Active" 1 "Inactive" 0 "Idle" ;
96 |
97 |
--------------------------------------------------------------------------------
/python-can-usecases/06_AirBagControlECU/readme.md:
--------------------------------------------------------------------------------
1 |
2 | # Use Case 6 - Airbag System ECU Simulation
3 |
4 | ## Expectation
5 | To Control the Airbag State according to the seatbelt and Engine running condition
6 |
7 | ## Functionality
8 | The Airbag will be released only if Seatbelt is worn and Crash detection happened and Engine On. Otherwise Airbag will be Inactive incase of Seatbelt is not Worn or Engine Off. Rest of the Time airbag will be in idle Condition
9 |
10 | ## Test Case
11 | Press the Below Keys from TestNode window, and Evaluate the Result on ECU Simulation Window
12 |
13 | Simulation Keys:
14 |
15 | - l: Lock Seatbelt
16 | - u: Unock Seatbelt
17 | - c: Crash with Engine On
18 | - o: Crash with Engine Off
19 | - f: Crash free with Engine On
20 |
21 | Expected Results:
22 |
23 | - Airbag Inactive : When Unlock Seatbelt, Crash with Engine Off,
24 | - Airbag Idle : Lock Seatbelt
25 | - Airbag Release : Lock Seatbelt + Crash with Engine On
26 | - No Update on Airbag: crash free with Engine On
27 |
28 | ## Pre-Conditions
29 | Enable Virtual CAN if on Linux Machine
30 |
31 | ```bash
32 | sudo modprobe vcan
33 | sudo ip link add vcan0 type vcan
34 | sudo ip link set vcan0 up
35 | if need to see the Trace: candump vcan0
36 | ```
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/python-can-usecases/Documents/System Test Engineer.odp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ANCIT/pythoncan-examples/fe8bf41e039574a2859d9b07ca42996b059fdcc7/python-can-usecases/Documents/System Test Engineer.odp
--------------------------------------------------------------------------------
/python-can-usecases/Tools/can_logFile.py:
--------------------------------------------------------------------------------
1 | """
2 | The Script will Log Can BUS and Display in Console
3 |
4 | Configure the Bus and Filter under bus_Config Class
5 |
6 | Filter - Can add the multiple coma separated filters.
7 | Fx: 100:7FC : Will allow only can_id 100 to 103
8 | 120:FF0 : Will allow only can_id containing 12X.
9 | 140:7BF : Will allow only can_id 120
10 |
11 | : (matches when & mask == can_id & mask)
12 | ~ (matches when & mask != can_id & mask)
13 |
14 | Press Esc Key to Save the Logfile with configured file name and terminate program
15 | - Can mention the directory along with name
16 | - incase of only name, the file will save in the same directory of script
17 | - file extension also can be choose (.log, .txt, etc)
18 | -------------------
19 | Created by Manzoor
20 | """
21 |
22 | from __future__ import absolute_import, print_function
23 |
24 | import socket
25 | from datetime import datetime
26 | from pynput import keyboard
27 |
28 | from can import Bus, Logger
29 | keep_going = True
30 |
31 | class bus_Cofing ():
32 | def __init__(self):
33 | self.channel = 'vcan0'
34 | self.interface = 'socketcan'
35 | self.bitrate = 250000
36 | self.filter = ['120:FF0', '140:7BF']
37 | self.log_file = 'logSample.txt'
38 |
39 | def logCan():
40 | results = bus_Cofing()
41 |
42 | can_filters = []
43 | if len(results.filter) > 0:
44 | print('Adding filter are:')
45 | for filt in results.filter:
46 | if ':' in filt:
47 | _ = filt.split(":")
48 | can_id = int(_[0], base=16)
49 | can_mask = int(_[1], base=16)
50 | print('Can ID: ', hex(can_id), 'mask: ', hex(can_mask))
51 |
52 | elif "~" in filt:
53 | can_id, can_mask = filt.split("~")
54 | can_id = int(can_id, base=16) | 0x20000000 # CAN_INV_FILTER
55 | can_mask = int(can_mask, base=16) & socket.CAN_ERR_FLAG
56 | print('Can ID: ', can_id, 'mask: ', can_mask)
57 | can_filters.append({"can_id": can_id, "can_mask": can_mask})
58 |
59 | config = {"can_filters": can_filters, "single_handle": True}
60 | if results.interface:
61 | config["interface"] = results.interface
62 | if results.bitrate:
63 | config["bitrate"] = results.bitrate
64 | bus = Bus(results.channel, **config)
65 |
66 | print('\nConnected to {}: {}'.format(bus.__class__.__name__, bus.channel_info))
67 | print('Can Logger (Started on {})\n'.format(datetime.now()))
68 | logger = Logger(results.log_file)
69 | while keep_going:
70 | msg = bus.recv(1)
71 | if msg is not None:
72 | print(msg)
73 | logger(msg)
74 |
75 | bus.shutdown()
76 | logger.stop()
77 |
78 | def termination_capture(key):
79 | global keep_going
80 | if key == keyboard.Key.esc:
81 | keep_going = False
82 |
83 | if __name__ == "__main__":
84 | keyboard.Listener(on_press=termination_capture).start()
85 | logCan()
--------------------------------------------------------------------------------
/python-can-usecases/output.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------