Skip to content

Commit

Permalink
Adds diagnostic address parsing (LIN 1.3) (#108)
Browse files Browse the repository at this point in the history
* Diagnostic addresses added to grammar
* Bumps version to 0.17.0
* Diagnostic addresses loaded as initial nad
* Updates changelog
  • Loading branch information
c4deszes authored Oct 17, 2022
1 parent 6877b18 commit 094da17
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.0] - 2022-10-17

### Added

- Diagnostic addresses section in LIN 1.3 description files are now parsed correctly,
the `initial_nad` and `configured_nad` attributes will be set according to the address

## [0.16.0] - 2022-10-02

### Added
Expand Down
6 changes: 6 additions & 0 deletions ldfparser/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ def diagnostic_frame_definition(self, tree):
def diagnostic_frame_signals(self, tree):
return tree[0:]

def diagnostic_addresses(self, tree):
return ("diagnostic_addresses", dict(tree))

def diagnostic_address(self, tree):
return (tree[0], tree[1])

def node_attributes(self, tree):
return ("node_attributes", tree[0:])

Expand Down
6 changes: 5 additions & 1 deletion ldfparser/grammars/ldf.lark
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
start: ldf

ldf: (header_lin_description_file | header_protocol_version | header_language_version | header_speed | header_channel | nodes | node_compositions | signals | diagnostic_signals | frames | sporadic_frames | event_triggered_frames | diagnostic_frames | node_attributes | schedule_tables | signal_groups | signal_encoding_types | signal_representations)*
ldf: (header_lin_description_file | header_protocol_version | header_language_version | header_speed | header_channel | nodes | node_compositions | signals | diagnostic_signals | diagnostic_addresses | frames | sporadic_frames | event_triggered_frames | diagnostic_frames | node_attributes | schedule_tables | signal_groups | signal_encoding_types | signal_representations)*

ldf_identifier: CNAME
ldf_version: C_VERSION
Expand Down Expand Up @@ -56,6 +56,10 @@ diagnostic_frames: "Diagnostic_frames" "{" (diagnostic_frame_definition)+ "}"
diagnostic_frame_definition: ldf_identifier ":" ldf_integer "{" diagnostic_frame_signals "}"
diagnostic_frame_signals: (frame_signal+)

// LIN 1.3 Specification, section 7.5
diagnostic_addresses: "Diagnostic_addresses" "{" (diagnostic_address)* "}"
diagnostic_address: ldf_identifier ":" ldf_integer ";"

// LIN 2.1 Specification, section 9.2.2.2
node_attributes: "Node_attributes" "{" (node_definition*) "}"
node_definition: ldf_identifier "{" (node_definition_protocol | node_definition_configured_nad | node_definition_initial_nad | node_definition_product_id | node_definition_response_error | node_definition_fault_state_signals | node_definition_p2_min | node_definition_st_min | node_definition_n_as_timeout | node_definition_n_cr_timeout | node_definition_configurable_frames)* "}"
Expand Down
3 changes: 3 additions & 0 deletions ldfparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def _populate_ldf_nodes(json: dict, ldf: LDF):
node = LinSlave(slave)
node.lin_protocol = ldf.protocol_version
ldf._slaves[node.name] = node
if json.get('diagnostic_addresses') is not None and json['diagnostic_addresses'].get(node.name) is not None:
node.initial_nad = json['diagnostic_addresses'][node.name]
node.configured_nad = json['diagnostic_addresses'][node.name]

def _create_ldf2x_node(node: dict, language_version: float):
name = node['name']
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
version = 0.16.0
version = 0.17.0
5 changes: 5 additions & 0 deletions tests/ldf/lin13.ldf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Nodes {
Slaves : LSM,CPM;
}

Diagnostic_addresses {
LSM: 1;
CPM: 0x02;
}

Signals {
RearFogLampInd:1,0,CEM,LSM;
PositionLampInd:1,0,CEM,LSM;
Expand Down
2 changes: 2 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def test_load_valid_lin13():
assert ldf.frame('VL1_CEM_Frm1') is not None
assert ldf.slave('LSM') is not None

assert ldf.get_slave('CPM').initial_nad == 0x02


@pytest.mark.unit
def test_load_valid_lin20():
Expand Down

0 comments on commit 094da17

Please sign in to comment.