Skip to main content

LDF Language support for Python

Project description

LDF Parser

Workflow Github Pages PyPI version PyPI - Python Version codecov.io Total alerts Language grade: Python GitHub last commit License: MIT

This tool is able parse LIN Description Files, retrieve signal names and frames from them, as well as encoding messages using frame definitions and decoding them.


Disclaimer

The tool has been written according the LIN standards 1.3, 2.0, 2.1 and 2.2A, but due to errors in the documentation there's no guarantee that the library will be able to parse your LDF. In such cases if possible first verify the LDF with a commercial tool such as Vector LDF Explorer or the tool that was used to create the LDF. If the LDF seems to be correct then open a new issue. I also recommend trying the LDF to JSON conversion mechanism, see if that succeeds.

Also the LIN standard is now known as ISO 17987 which clears up some of the confusing parts in the 2.2A specification. Since this new standard is not freely available this library won't support the modifications present in ISO 17987. I don't think it's going to a huge problem because the LIN 2.2A released in 2010 has overall better adoption.

The LDF usually contains sensitive information, if you need to open an issue related to the parser then try to provide either an anonymized version with signals and frames obfuscated or just the relevant segments in an example LDF when opening issues.


Installation

You can install this library from PyPI using pip.

pip install ldfparser

Examples

import ldfparser
import binascii

# Load LDF
ldf = ldfparser.parseLDF(path = "network.ldf")
frame = ldf.frame('Frame_1')

# Get baudrate from LDF
print(ldf.baudrate)

# Encode signal values into frame
message = frame.raw({"Signal_1": 123, "Signal_2": 0})
print(binascii.hexlify(message))
>>> 0x7B00

# Decode message into dictionary of signal names and values
received = bytearray([0x7B, 0x00])
print(frame.parse(received, ldf.converters))
>>> {"Signal_1": 123, "Signal_2": 0}

# Encode signal values through converters
message = frame.data({"MotorRPM": 100, "FanState": "ON"}, ldf.converters)
print(binascii.hexlify(message))
>>> 0xFE01

More examples can be found in the examples directory.


Documentation

Documentation is published to Github Pages.


Features

  • Semantic validation of LDF files

  • Retrieve header information (version, baudrate)

  • Retrieve Signal and Frame information

  • Retrieve Signal encoding types and use them to convert values

  • Retrieve Node attributes

  • Command Line Interface

  • Capturing comments

Currently not supported

  • Scheduling table

  • Diagnostics


Development

Install the requirements via pip install -r requirements.txt

Install the library locally by running python setup.py install

Pytest is used for testing, to execute all tests run pytest -m 'not snapshot'

Flake8 is used for linting, run flake8 to print out all linting errors.


Contributors

@c4deszes (Author)


Credits

Inspired by uCAN-LIN LinUSBConverter, specifically the LDF parsing mechanism via Lark. Previously the library included most of the lark file, parsing code and examples, since 0.5.0 they've been completely rewritten to better accomodate the different LIN standards.


License

License: MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ldfparser-0.10.0.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ldfparser-0.10.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file ldfparser-0.10.0.tar.gz.

File metadata

  • Download URL: ldfparser-0.10.0.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

File hashes

Hashes for ldfparser-0.10.0.tar.gz
Algorithm Hash digest
SHA256 bad20313d54f3088e004c751776f24abb312de831ad74e2968fa3cd7d86e74cb
MD5 6a5456d2600c4cb6a3f733a9a7998afc
BLAKE2b-256 37dd527b18f57e37302b76b352a718cfeabdc017b18fa6ab2cf259d0ba551cd2

See more details on using hashes here.

File details

Details for the file ldfparser-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: ldfparser-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

File hashes

Hashes for ldfparser-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eba70b2f0f3fd71e256155f925b6f005b8476aa3c225b3ccd1107b77f2ea21c3
MD5 c6919dfe3df8088e3b531d6600324a1d
BLAKE2b-256 42b5b71ef3ecbe7678e2ca0168b5f7334dd0d55ed49683f14fdd22d3f7f14bce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page