Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic CAN Transport Interface for python-can #229

Merged
merged 44 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5e31dfc
change_ti_api
mdabrowski1990 Feb 6, 2022
633cad7
notes
mdabrowski1990 Feb 7, 2022
b52bcfd
save
mdabrowski1990 Feb 10, 2022
2179927
save
mdabrowski1990 Feb 18, 2022
ee4adc2
queue performance
mdabrowski1990 Feb 4, 2023
ebad7fb
Merge remote-tracking branch 'origin/main' into python-can-transport-…
mdabrowski1990 Apr 10, 2023
bd6383a
Create kvaser.py
mdabrowski1990 Apr 10, 2023
f9fee3c
make it simple
mdabrowski1990 Apr 10, 2023
190a954
Merge branch 'main' of https://github.com/mdabrowski1990/uds into pyt…
mdabrowski1990 Apr 11, 2023
f2d10f7
Merge branch 'main' of https://github.com/mdabrowski1990/uds into pyt…
mdabrowski1990 Apr 12, 2023
e9e0358
adjust api
mdabrowski1990 Apr 12, 2023
678c026
save
mdabrowski1990 May 17, 2023
79bf285
Update python_can_transport_interface.py
mdabrowski1990 May 17, 2023
6d77b4e
SCA update
mdabrowski1990 May 17, 2023
7d12139
tmp
Maciej-Dabrowski-Tieto Jul 26, 2023
9a12fae
adjust abstract classes
mdabrowski1990 Aug 17, 2023
3e50fef
addressing information fix
mdabrowski1990 Aug 23, 2023
8637c7d
adjust can segmenter
mdabrowski1990 Sep 13, 2023
4179cc9
temporary version - sync send_packet
mdabrowski1990 Sep 21, 2023
153f3e2
provide synchronous and asynchronous implementation for sending/recei…
mdabrowski1990 Sep 29, 2023
880de97
Update can_transport_interface.py
mdabrowski1990 Sep 29, 2023
88084e3
add system tests
mdabrowski1990 Oct 4, 2023
323698b
system tests update
mdabrowski1990 Oct 5, 2023
97df931
system tests for transport interface
mdabrowski1990 Oct 6, 2023
13e4972
update system tests
mdabrowski1990 Oct 11, 2023
2f1523b
update system tests
mdabrowski1990 Oct 13, 2023
7f3ac08
resolve notifiers problem
mdabrowski1990 Oct 17, 2023
fb27b11
system tests ready
mdabrowski1990 Oct 18, 2023
a76d46c
unit tests and python-can transport interface updated
mdabrowski1990 Oct 19, 2023
8e2b2b9
Update can_packet_type.py
mdabrowski1990 Oct 19, 2023
48c9ed3
Update requirements.txt
mdabrowski1990 Oct 19, 2023
2d1478f
Update pyproject.toml
mdabrowski1990 Oct 19, 2023
9066563
Update can_packet_type.py
mdabrowski1990 Oct 19, 2023
db29abd
Merge branch 'main' into python-can-transport-interface
mdabrowski1990 Oct 19, 2023
a48886b
update examples
mdabrowski1990 Oct 19, 2023
8f1cf54
adjust dependencies
mdabrowski1990 Oct 19, 2023
4cefeae
updated testing dependencies
mdabrowski1990 Oct 19, 2023
73f8787
Update reffering to script location
mdabrowski1990 Oct 19, 2023
241aa35
formatting
mdabrowski1990 Oct 19, 2023
037d75a
Update conftest.py
mdabrowski1990 Oct 19, 2023
83e977f
Update conftest.py
mdabrowski1990 Oct 19, 2023
3d0bc39
Update ci.yml
mdabrowski1990 Oct 19, 2023
457425f
self-review
mdabrowski1990 Oct 20, 2023
3d5c6c7
Update test_python_can.py
mdabrowski1990 Oct 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -32,26 +32,26 @@ jobs:

- name: Execute unit tests with coverage report [pytest]
run: |
pytest --cov-report=term-missing --cov=uds -m "not integration and not performance"
pytest tests/software_tests --cov-report=term-missing --cov=uds -m "not integration and not performance"

- name: Execute integration tests with coverage report [pytest]
run: |
pytest --cov-report=term-missing --cov=uds -m "integration"
pytest tests/software_tests --cov-report=term-missing --cov=uds -m "integration"

# TODO: uncomment when performance tests are added
# - name: Execute performance tests with coverage report [pytest]
# run: |
# pytest --cov-report=term-missing --cov=uds -m "performance"
# pytest tests/software_tests --cov-report=term-missing --cov=uds -m "performance"


code_coverage:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: 3.11

Expand All @@ -72,21 +72,21 @@ jobs:

- name: Execute unit tests [pytest]
run: |
pytest --cov-report=xml --cov=uds -m "not integration and not performance"
pytest tests/software_tests --cov-report=xml --cov=uds -m "not integration and not performance"

- name: Upload unit tests report [CodeCov]
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
flags: unit-tests

- name: Execute integration tests [pytest]
run: |
pytest --cov-report=xml --cov=uds -m "integration"
pytest tests/software_tests --cov-report=xml --cov=uds -m "integration"

- name: Upload integration tests report [CodeCov]
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
Expand All @@ -95,10 +95,10 @@ jobs:
# TODO: uncomment when performance tests are added
# - name: Execute performance tests [pytest]
# run: |
# pytest --cov-report=xml --cov=uds -m "performance"
# pytest tests/software_tests --cov-report=xml --cov=uds -m "performance"
#
# - name: Upload performance tests report [CodeCov]
# uses: codecov/codecov-action@v2
# uses: codecov/codecov-action@v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: coverage.xml
Expand All @@ -112,10 +112,10 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -133,10 +133,6 @@ jobs:
run: |
prospector --profile tests/prospector_profile.yaml uds

- name: Execute static code analysis [pyroma]
run: |
pyroma -a .


dependency_checks:
runs-on: ubuntu-latest
Expand All @@ -145,10 +141,10 @@ jobs:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down
221 changes: 221 additions & 0 deletions examples/can/kvaser with python-can/config.wcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE CK[
<!ELEMENT CK (DIR)* >
<!ELEMENT DIR (DIR|INT|EXTENDED|DOUBLE|BINARY|BOOL|STR)* >
<!ELEMENT INT (#PCDATA)>
<!ELEMENT EXTENDED (#PCDATA)>
<!ELEMENT DOUBLE (#PCDATA)>
<!ELEMENT BINARY (#PCDATA)>
<!ELEMENT BOOL (#PCDATA)>
<!ELEMENT STR (#PCDATA)>
<!ATTLIST CK version CDATA #REQUIRED>
<!ATTLIST DIR Name CDATA #REQUIRED>
<!ATTLIST INT Name CDATA #REQUIRED>
<!ATTLIST EXTENDED Name CDATA #REQUIRED>
<!ATTLIST DOUBLE Name CDATA #REQUIRED>
<!ATTLIST BINARY Name CDATA #REQUIRED>
<!ATTLIST BOOL Name CDATA #REQUIRED>
<!ATTLIST STR Name CDATA #REQUIRED>
]>
<CK version="1.2">
<DIR Name="Config">
<DIR Name="CANKingProj">
<DIR Name="ProjMgr">
<INT Name="PixelsPerInch">96</INT>
<INT Name="Left">515</INT>
<INT Name="Top">215</INT>
<INT Name="Width">435</INT>
<INT Name="Height">300</INT>
<INT Name="State">0</INT>
<INT Name="Visible">0</INT>
</DIR>
<DIR Name="Desktop">
<INT Name="PixelsPerInch">96</INT>
<INT Name="Left">6</INT>
<INT Name="Top">21</INT>
<INT Name="Width">663</INT>
<INT Name="Height">101</INT>
<INT Name="State">0</INT>
<INT Name="Visible">1</INT>
<STR Name="Caption">Kvaser CanKing</STR>
</DIR>
<DIR Name="ConnectionRules">
<STR Name="R0">^TCANKingDialog\.,$,,0,TCanCtrlWin,,0</STR>
<STR Name="R1">^TCANKingDialog\.,$,,0,THistoryWindow,,0</STR>
<STR Name="R2">TTrafficGenerator$,$,,0,TCanCtrlWin,,0</STR>
<STR Name="R3">TTimedTransmission$,$,,0,TCanCtrlWin,,0</STR>
</DIR>
<DIR Name="Windows">
<DIR Name="0">
<STR Name="Class">TCanCtrlWin</STR>
<INT Name="Left">6</INT>
<INT Name="Top">127</INT>
<INT Name="Width">340</INT>
<INT Name="Height">650</INT>
<INT Name="State">0</INT>
<INT Name="Visible">1</INT>
<STR Name="Caption">CAN 1</STR>
<INT Name="PixelsPerInch">96</INT>
<INT Name="BitR">1000000</INT>
<INT Name="T1">5</INT>
<INT Name="T2">2</INT>
<INT Name="SJW">2</INT>
<INT Name="ArgBitR">500000</INT>
<INT Name="ArgT1">63</INT>
<INT Name="ArgT2">16</INT>
<INT Name="ArgSJW">16</INT>
<INT Name="DataBitR">4000000</INT>
<INT Name="DataT1">7</INT>
<INT Name="DataT2">2</INT>
<INT Name="DataSJW">2</INT>
<INT Name="Chan">1</INT>
<INT Name="Drv">0</INT>
<INT Name="CanFd">1</INT>
<INT Name="Page">0</INT>
</DIR>
<DIR Name="1">
<STR Name="Class">TFormatter</STR>
<INT Name="Left">351</INT>
<INT Name="Top">127</INT>
<INT Name="Width">319</INT>
<INT Name="Height">316</INT>
<INT Name="State">0</INT>
<INT Name="Visible">1</INT>
<STR Name="Caption">Select Formatters</STR>
<INT Name="PixelsPerInch">96</INT>
<DIR Name="Fmt0">
<STR Name="Name">StandardText</STR>
<INT Name="Octal">0</INT>
<INT Name="Hex">0</INT>
<INT Name="DeltaTime">0</INT>
<INT Name="ShowAscii">0</INT>
<INT Name="DefaultBase">0</INT>
<INT Name="CompactHex">0</INT>
<INT Name="HistoryList">0</INT>
</DIR>
</DIR>
<DIR Name="2">
<STR Name="Class">TOutputWindow</STR>
<INT Name="Left">676</INT>
<INT Name="Top">21</INT>
<INT Name="Width">1724</INT>
<INT Name="Height">1061</INT>
<INT Name="State">0</INT>
<INT Name="Visible">1</INT>
<STR Name="Caption">Output Window</STR>
<INT Name="PixelsPerInch">96</INT>
<INT Name="AutoScroll">1</INT>
<INT Name="FixedPos">0</INT>
</DIR>
<DIR Name="3">
<STR Name="Class">THistoryWindow</STR>
<INT Name="Left">389</INT>
<INT Name="Top">411</INT>
<INT Name="Width">453</INT>
<INT Name="Height">275</INT>
<INT Name="State">0</INT>
<INT Name="Visible">0</INT>
<STR Name="Caption">History list</STR>
<INT Name="PixelsPerInch">96</INT>
</DIR>
<DIR Name="4">
<STR Name="Class">TTimedTransmission</STR>
<INT Name="Left">389</INT>
<INT Name="Top">411</INT>
<INT Name="State">0</INT>
<INT Name="Visible">0</INT>
<STR Name="Caption">Timed transmission</STR>
<INT Name="PixelsPerInch">96</INT>
<INT Name="Interval">10</INT>
<INT Name="Mode">0</INT>
<INT Name="Timing">0</INT>
</DIR>
<DIR Name="5">
<STR Name="Class">TLogToFile</STR>
<INT Name="Left">530</INT>
<INT Name="Top">448</INT>
<INT Name="State">0</INT>
<INT Name="Visible">0</INT>
<STR Name="Caption">Log To Text File</STR>
<INT Name="PixelsPerInch">96</INT>
<STR Name="FileName"></STR>
</DIR>
<DIR Name="6">
<STR Name="Class">TTextWindow</STR>
<INT Name="Left">389</INT>
<INT Name="Top">411</INT>
<INT Name="Width">600</INT>
<INT Name="Height">233</INT>
<INT Name="State">0</INT>
<INT Name="Visible">0</INT>
<STR Name="Caption">System Messages</STR>
<INT Name="PixelsPerInch">96</INT>
</DIR>
<DIR Name="7">
<STR Name="Class">TLogFilePlayer</STR>
<INT Name="Left">356</INT>
<INT Name="Top">455</INT>
<INT Name="State">0</INT>
<INT Name="Visible">0</INT>
<STR Name="Caption">Log File Player</STR>
<INT Name="PixelsPerInch">96</INT>
<STR Name="FileName"></STR>
<INT Name="AutoStart">1</INT>
</DIR>
<STR Name="ReverseZOrder">1,0,2</STR>
</DIR>
<DIR Name="Connections">
<STR Name="C0">0,1,0,0</STR>
<STR Name="C1">1,2,0,0</STR>
<STR Name="C2">3,4,1,0</STR>
<STR Name="C3">1,2,1,1</STR>
<STR Name="C4">4,0,0,0</STR>
<STR Name="C5">1,5,0,0</STR>
<STR Name="C6">1,5,1,1</STR>
<STR Name="C7">7,4,0,0</STR>
</DIR>
</DIR>
<DIR Name="CKMenu">
<DIR Name="0">
<STR Name="Parent">$MAIN</STR>
<INT Name="InsertBefore">0</INT>
<STR Name="TargetItem">View1</STR>
<STR Name="Item0">*,&amp;Messages,MsgMenu</STR>
</DIR>
<DIR Name="MsgMenu">
<STR Name="Item0">Universal,C,U,TCanKingDialog.TUtilPage.TUniversalMessage</STR>
<STR Name="Item1">Traffic Generator,C,G,TTrafficGenerator</STR>
<STR Name="Item2">*,Misc,MiscMenu</STR>
</DIR>
<DIR Name="MiscMenu">
<STR Name="Item0">1-4 Ints,C,I,TCanKingDialog.TUtilPage.TInt4Page</STR>
<STR Name="Item1">1-2 Longs,C,L,TCanKingDialog.TUtilPage.TLongintPage</STR>
<STR Name="Item2">1-2 Floats,C,F,TCanKingDialog.TUtilPage.TFloatPage</STR>
<STR Name="Item3">String,C,S,TCanKingDialog.TUtilPage.TStrPage</STR>
<STR Name="Item4">Error Frame,C,E,TCanKingDialog.TUtilPage.TErrorFlagPage</STR>
</DIR>
<DIR Name="1">
<STR Name="Parent">$MAIN</STR>
<INT Name="InsertBefore">0</INT>
<STR Name="TargetItem">_MsgMenu</STR>
<STR Name="Item0">*,&amp;Options,OptionsMenu</STR>
</DIR>
<DIR Name="OptionsMenu">
<STR Name="Item0">&amp;Global...,,,TGlobalOptionsDlg</STR>
</DIR>
</DIR>
<DIR Name="Plugin">
<DIR Name="&#123;FC073F12-61C1-11D2-BCE1-0060089830AD&#125;">
<INT Name="KingsEnvelope">0</INT>
<INT Name="DefaultCityGrpAddress">0</INT>
<INT Name="KingsEnvIsExt">0</INT>
</DIR>
</DIR>
<DIR Name="MdiMode">
<INT Name="MdiMode">0</INT>
</DIR>
<DIR Name="Global">
<INT Name="UseHex">0</INT>
</DIR>
</DIR>
</CK>
29 changes: 29 additions & 0 deletions examples/can/kvaser with python-can/python_can_timing_issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""UDS Issue: https://github.com/mdabrowski1990/uds/issues/228"""

from time import time
from threading import Timer
from can import Notifier, BufferedReader, Bus, Message

if __name__ == "__main__":
kvaser_interface_1 = Bus(interface="kvaser", channel=0, fd=True, receive_own_messages=True)
kvaser_interface_2 = Bus(interface="kvaser", channel=1, fd=True, receive_own_messages=True) # connected with bus 1

buffered_reader = BufferedReader()
notifier = Notifier(bus=kvaser_interface_1, listeners=[buffered_reader])

message = Message(data=[0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0], arbitration_id=0x100)

for _ in range(10):
Timer(interval=0.1, function=kvaser_interface_1.send, args=(message,)).start()

sent_message = buffered_reader.get_message(timeout=1)
timestamp_after_send = time()

print(f"-----------------------------------------------\n"
f"Result:\n"
f"Message timestamp: {sent_message.timestamp}\n"
f"Current timestamp: {timestamp_after_send}\n"
f"Message timestamp <= Current timestamp: {sent_message.timestamp <= timestamp_after_send} (expected `True`)")

kvaser_interface_1.shutdown()
kvaser_interface_2.shutdown()
Loading