This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The reader erroneously referred to a non-existing (private) member of the DBCReader. This has been fixed. Also added some tests for verifying the J1939Reader's functionality.
- Loading branch information
1 parent
a5a6e29
commit b929265
Showing
8 changed files
with
233 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<!-- | ||
Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
<NetworkDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://kayak.2codeornot2code.org/1.0 https://raw.githubusercontent.com/dschanoeh/Kayak/master/Kayak-kcd/src/main/resources/com/github/kayak/canio/kcd/loader/Definition.xsd" | ||
xmlns="http://kayak.2codeornot2code.org/1.0"> | ||
<Document /> | ||
<Bus name="Private"> | ||
<Message id="0x01FFFF10" name="Test_Message" length="24" format="extended"> | ||
<Signal length="16" name="Signal_Two" offset="8"> | ||
<Value type="signed" /> | ||
</Signal> | ||
<Signal length="8" name="Signal_One" offset="0"> | ||
<Value max="213" type="unsigned" /> | ||
</Signal> | ||
</Message> | ||
</Bus> | ||
</NetworkDefinition> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"A": { | ||
"children": { | ||
"One": { | ||
"datatype": "uint8", | ||
"dbc2vss": { | ||
"on_change": true, | ||
"signal": "Signal_One" | ||
}, | ||
"description": "...", | ||
"type": "sensor", | ||
"unit": "km" | ||
}, | ||
"Two": { | ||
"datatype": "int16", | ||
"dbc2vss": { | ||
"on_change": true, | ||
"signal": "Signal_Two" | ||
}, | ||
"description": "...", | ||
"type": "sensor", | ||
"unit": "ms" | ||
} | ||
}, | ||
"description": "Branch A.", | ||
"type": "branch" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
######################################################################## | ||
# Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
######################################################################## | ||
|
||
# | ||
# Source file for tests | ||
# Generate file used by test (test.json) with help of vss-tools | ||
# https://github.com/COVESA/vss-tools | ||
# When cloned execute something like this from this folder: | ||
# ~/vss-tools/vspec2json.py -e dbc2vss --json-pretty <name>.vspec <name>.json | ||
# | ||
A: | ||
type: branch | ||
description: Branch A. | ||
|
||
A.One: | ||
datatype: uint8 | ||
type: sensor | ||
unit: km | ||
description: "..." | ||
dbc2vss: | ||
signal: "Signal_One" | ||
on_change: true | ||
|
||
A.Two: | ||
datatype: int16 | ||
type: sensor | ||
unit: ms | ||
description: "..." | ||
dbc2vss: | ||
signal: "Signal_Two" | ||
on_change: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/python3 | ||
|
||
######################################################################## | ||
# Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
######################################################################## | ||
|
||
import os | ||
|
||
from queue import Empty, Queue | ||
from typing import Dict | ||
|
||
import pytest # type: ignore | ||
|
||
from dbcfeederlib.dbc2vssmapper import Mapper, VSSObservation | ||
from dbcfeederlib.dbcparser import DBCParser | ||
from dbcfeederlib.j1939reader import J1939Reader | ||
|
||
test_path = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
def test_on_message_processes_j1939_message(): | ||
|
||
# GIVEN a reader based on CAN message and mapping definitions | ||
dbc2val_queue = Queue(10) | ||
parser = DBCParser([test_path + "/j1939.kcd"], expect_extended_frame_ids=True) | ||
mapper = Mapper(test_path + "/simple_mapping.json", parser, "") | ||
reader = J1939Reader(rxqueue=dbc2val_queue, mapper=mapper, dbc_parser=parser) | ||
|
||
# WHEN a message is received from the CAN bus for which a mapping gas been defined | ||
reader.on_message(priority=1, pgn=0x1FFFF, sa=0x45, timestamp=0, data=[0x10, 0x32, 0x54]) | ||
|
||
# THEN the reader determines both VSS Data Entries that the CAN signals are mapped to | ||
signal_mappings: Dict[str, VSSObservation] = {} | ||
obs: VSSObservation = dbc2val_queue.get(block=False) | ||
signal_mappings[obs.dbc_name] = obs | ||
obs = dbc2val_queue.get(block=False) | ||
signal_mappings[obs.dbc_name] = obs | ||
|
||
assert signal_mappings["Signal_One"].vss_name == "A.One" | ||
assert signal_mappings["Signal_One"].raw_value == 0x10 | ||
assert signal_mappings["Signal_Two"].vss_name == "A.Two" | ||
assert signal_mappings["Signal_Two"].raw_value == 0x5432 | ||
|
||
|
||
def test_on_message_ignores_unknown_CAN_messages(): | ||
|
||
# GIVEN a reader based on CAN message and mapping definitions | ||
dbc2val_queue = Queue(10) | ||
parser = DBCParser([test_path + "/j1939.kcd"], expect_extended_frame_ids=True) | ||
mapper = Mapper(test_path + "/simple_mapping.json", parser, "") | ||
reader = J1939Reader(rxqueue=dbc2val_queue, mapper=mapper, dbc_parser=parser) | ||
|
||
# WHEN a message with an unknown PGN is received from the CAN bus | ||
reader.on_message(priority=1, pgn=0x1FFFA, sa=0x12, timestamp=0, data=[0x10, 0x32, 0x54]) | ||
|
||
# THEN the reader ignores the message | ||
with pytest.raises(Empty): | ||
dbc2val_queue.get(block=False) |