Skip to content

Commit

Permalink
quick-fix for issue/pr #680 (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroecker authored Jan 20, 2023
1 parent 7332f91 commit 7f4b282
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/canmatrix/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def load(f, **_options):
if "messages" in json_data:
for frame in json_data["messages"]:
# new_frame = Frame(frame["id"],frame["name"],8,None)
new_frame = canmatrix.Frame(frame["name"], arbitration_id=frame["id"], size=8)
arb_id = canmatrix.canmatrix.ArbitrationId(id=frame["id"], extended=frame.get("is_extended_frame", "False"))
new_frame = canmatrix.Frame(frame["name"], arbitration_id=arb_id, size=8)
if "length" in frame:
new_frame.size = frame["length"]

Expand Down
15 changes: 15 additions & 0 deletions src/canmatrix/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def test_import_min_max():
assert matrix.frames[0].signals[0].min == -5
assert matrix.frames[0].signals[0].max == 42


def test_import_native():
json_input = """{
"messages": [
Expand Down Expand Up @@ -208,6 +209,7 @@ def test_export_native():
assert (data['messages'][0]['signals'][0]['factor'] == 0.123)
assert (data['messages'][0]['signals'][0]['offset'] == 1)


def test_export_all_native():
matrix = canmatrix.canmatrix.CanMatrix()
frame = canmatrix.canmatrix.Frame(name="test_frame", size=6, arbitration_id=10)
Expand All @@ -222,3 +224,16 @@ def test_export_all_native():
assert (data['messages'][0]['signals'][0]['factor'] == 0.123)
assert (data['messages'][0]['signals'][0]['offset'] == 1)
assert (data['messages'][0]['is_fd'] is False)


def test_export_extended():
matrix = canmatrix.canmatrix.CanMatrix()
frame = canmatrix.canmatrix.Frame(name="test_frame", size=6, arbitration_id=canmatrix.canmatrix.ArbitrationId(extended=True, id=10))
frame.pgn=22
signal = canmatrix.Signal(name="someSigName", size=40)
frame.add_signal(signal)
matrix.add_frame(frame)
out_file = io.BytesIO()
canmatrix.formats.dump(matrix, out_file, "json")
# data = json.loads(out_file.getvalue().decode("utf-8"))
matrix = canmatrix.formats.loads_flat(out_file.getvalue().decode("utf-8"), "json", jsonExportAll=True)

0 comments on commit 7f4b282

Please sign in to comment.