Skip to content

Commit

Permalink
issue #531 Lin Converters
Browse files Browse the repository at this point in the history
add support for LIN-Converters
  • Loading branch information
ebroecker committed Feb 10, 2021
1 parent 70cf576 commit acdd5d3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/canmatrix/formats/ldf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import ldfparser
import canmatrix
import ldfparser.encoding


def load(f, **options): # type: (typing.IO, **typing.Any) -> canmatrix.CanMatrix
ldf = ldfparser.parseLDF(path=f.name) # using f.name is not nice, but works

db = canmatrix.CanMatrix()

for lin_frame in ldf.frames:
Expand All @@ -17,6 +20,17 @@ def load(f, **options): # type: (typing.IO, **typing.Any) -> canmatrix.CanMatri
for mapping in lin_frame.signal_map:
lin_signal = mapping[1]
cm_signal = canmatrix.Signal()
if lin_signal.name in ldf.converters:
for converter in ldf.converters[lin_signal.name]._converters:
if isinstance(converter, ldfparser.encoding.LogicalValue):
cm_signal.add_values(converter.phy_value, converter.info)
if isinstance(converter, ldfparser.encoding.PhysicalValue):
cm_signal.offset = converter.offset
cm_signal.factor = converter.scale
cm_signal.unit = converter.unit
cm_signal.min = converter.phy_min
cm_signal.max = converter.phy_max

cm_signal.name = lin_signal.name
cm_signal.size = lin_signal.width
cm_signal.initial_value = lin_signal.init_value
Expand Down

0 comments on commit acdd5d3

Please sign in to comment.