Skip to content

Commit

Permalink
add tests and dbc for frame decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroecker committed Oct 25, 2018
1 parent d727635 commit 3e70b14
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/canmatrix/tests/test_frame_decoding.dbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
VERSION "created by canmatrix"


NS_ :

BS_:

BU_:


BO_ 1 testFrame1: 8 TEST_ECU
SG_ sig0 : 1|2@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig1 : 7|6@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig2 : 15|11@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig3 : 20|12@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig4 : 24|9@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig5 : 50|3@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig6 : 53|3@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig7 : 47|10@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig8 : 58|3@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig9 : 61|3@0+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ sig10 : 63|2@0+ (1.0,0.0) [0|0] "" CCL_TEST

BO_ 2 testFrame2: 8 TEST_ECU
SG_ secSig1 : 60|2@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig2 : 55|1@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig3 : 20|4@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig4 : 62|2@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig5 : 34|3@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig6 : 37|3@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig7 : 59|1@1- (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig8 : 56|3@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig9 : 52|3@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig10 : 8|12@1+ (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig11 : 24|10@1- (1.0,0.0) [0|0] "" CCL_TEST
SG_ secSig12 : 0|8@1+ (1.0,0.0) [0|0] "" CCL_TEST









40 changes: 40 additions & 0 deletions src/canmatrix/tests/test_frame_decoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest
import canmatrix.formats


def test_decode_from_dbc():
cm = canmatrix.formats.loadp("test_frame_decoding.dbc", flatImport = True)

This comment has been minimized.

Copy link
@altendky

altendky Oct 26, 2018

Collaborator

I tend to put something like this at the top of the file.

here = pathlib.Path(__file__).parent

Then on this line you can

cm = canmatrix.formats.loadp(here/"test_frame_decoding.dbc", flatImport = True)

Otherwise this path would be referencing a file in the cwd?

And yes, we'd need the pathlib2 backport of pathlib since we support py2.

# 001#8d00100100820100
frameData1 = bytes([141, 0, 16, 1, 0, 130, 1, 0])

# 002#0C00057003CD1F83
frameData2 = bytes([12, 0, 5, 112, 3, 205, 31, 131])

frame1 = cm.frameById(1)
decoded1 = frame1.decode(frameData1)
assert decoded1["sig0"] == 1
assert decoded1["sig1"] == 35
assert decoded1["sig2"] == 0
assert decoded1["sig3"] == 2048
assert decoded1["sig4"] == 256
assert decoded1["sig5"] == 1
assert decoded1["sig6"] == 0
assert decoded1["sig7"] == 520
assert decoded1["sig8"] == 0
assert decoded1["sig9"] == 0
assert decoded1["sig10"] == 0

frame2 = cm.frameById(2)
decoded2 = frame2.decode(frameData2)
assert decoded2["secSig1"] == 0
assert decoded2["secSig2"] == 0
assert decoded2["secSig3"] == 0
assert decoded2["secSig4"] == 2
assert decoded2["secSig5"] == 0
assert decoded2["secSig6"] == 0
assert decoded2["secSig7"] == 0
assert decoded2["secSig8"] == 3
assert decoded2["secSig9"] == 1
assert decoded2["secSig10"] == 1280
assert decoded2["secSig11"] == -144
assert decoded2["secSig12"] == 12

This comment has been minimized.

Copy link
@altendky

altendky Oct 26, 2018

Collaborator

tsk-tsk get that EOL in at the EOF :]

1 comment on commit 3e70b14

@ebroecker
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not fix #119 yet, but I'm quite sure, the expectations of this test is correct.

Please sign in to comment.