pax_global_header00006660000000000000000000000064152070043410014506gustar00rootroot0000000000000052 comment=31eab59d09b9e9a91f28a9ff415dd1921f1ca9d9 vblf-0.3.0/000077500000000000000000000000001520700434100124375ustar00rootroot00000000000000vblf-0.3.0/.github/000077500000000000000000000000001520700434100137775ustar00rootroot00000000000000vblf-0.3.0/.github/dependabot.yml000066400000000000000000000010611520700434100166250ustar00rootroot00000000000000version: 2 updates: # Enable version updates for GitHub Actions - package-ecosystem: "github-actions" directory: "/" schedule: interval: "monthly" cooldown: default-days: 7 groups: github-actions: patterns: - "*" # Enable version updates for development dependencies - package-ecosystem: "pip" directory: "/" schedule: interval: "monthly" cooldown: default-days: 7 versioning-strategy: "increase-if-necessary" groups: dev-deps: patterns: - "*" vblf-0.3.0/.github/release.yml000066400000000000000000000000731520700434100161420ustar00rootroot00000000000000changelog: exclude: authors: - dependabot[bot] vblf-0.3.0/.github/workflows/000077500000000000000000000000001520700434100160345ustar00rootroot00000000000000vblf-0.3.0/.github/workflows/ci.yml000066400000000000000000000075451520700434100171650ustar00rootroot00000000000000name: CI on: pull_request: push: tags: - 'v*' branches-ignore: - 'dependabot/**' env: PY_COLORS: "1" permissions: contents: read jobs: test: runs-on: ${{ matrix.os }} strategy: matrix: os: [ "ubuntu-latest", "windows-latest", "macos-latest" ] python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "pypy-3.11"] fail-fast: false steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 6.0.2 with: fetch-depth: 0 persist-credentials: false - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # 6.2.0 with: python-version: ${{ matrix.python-version }} allow-prereleases: true - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install tox - name: Test run: | tox -e py linter: runs-on: ubuntu-latest steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 6.0.2 with: fetch-depth: 0 persist-credentials: false - name: Set up Python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # 6.2.0 with: python-version: "3.12" - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install tox - name: Run ruff linter run: | tox -e format,lint,type build: name: Build package runs-on: ubuntu-latest steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 6.0.2 with: fetch-depth: 0 persist-credentials: false - name: Set up Python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # 6.2.0 with: python-version: "3.12" - name: Install dependencies run: python -m pip install build twine - name: Build wheel and sdist run: python -m build - name: Check artifacts run: twine check --strict dist/* - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # 7.0.1 with: name: dist-artifact path: dist/* docs: name: Build documentation runs-on: ubuntu-latest steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # 6.0.2 with: fetch-depth: 0 persist-credentials: false - name: Set up Python uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # 6.2.0 with: python-version: "3.12" - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install tox - name: Build documentation run: | tox -e docs - name: Upload documentation artifact uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # 7.0.1 with: name: doc-artifact path: build/* upload_pypi: name: Publish needs: build runs-on: ubuntu-latest environment: name: pypi url: https://pypi.org/p/vblf permissions: id-token: write # IMPORTANT: this permission is mandatory for trusted publishing contents: write # for action-gh-release attestations: write # for attest-build-provenance # create a new release for tagged commits if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') steps: - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # 8.0.1 with: name: dist-artifact path: dist - name: Generate artifact attestation uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # 4.1.0 with: subject-path: 'dist/*' - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # 1.14.0 vblf-0.3.0/.gitignore000066400000000000000000000012421520700434100144260ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ cover/ # Sphinx documentation docs/_build/ # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # mypy .mypy_cache/ .dmypy.json dmypy.json # IDEs .idea/ .vscode/ vblf-0.3.0/.pre-commit-config.yaml000066400000000000000000000015661520700434100167300ustar00rootroot00000000000000repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 hooks: - id: check-added-large-files args: ['--maxkb=1000'] - id: check-case-conflict - id: check-merge-conflict - id: check-symlinks - id: check-yaml - id: debug-statements - id: end-of-file-fixer - id: mixed-line-ending - id: requirements-txt-fixer - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit rev: "v0.15.15" hooks: # Run the linter. - id: ruff-check args: ["--fix", "--show-fixes"] # Run the formatter. - id: ruff-format - repo: https://github.com/woodruffw/zizmor-pre-commit # Zizmor version. rev: v1.25.2 hooks: # Run the linter. - id: zizmor - repo: https://github.com/twisted/towncrier rev: 25.8.0 hooks: - id: towncrier-check vblf-0.3.0/.readthedocs.yaml000066400000000000000000000011471520700434100156710ustar00rootroot00000000000000# Read the Docs configuration file # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details # Required version: 2 # Set the OS, Python version, and other tools you might need build: os: ubuntu-24.04 tools: python: "3.12" # Build documentation in the "docs/" directory with Sphinx sphinx: configuration: docs/conf.py # Optionally, but recommended, # declare the Python requirements required to build your documentation # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html python: install: - requirements: docs/requirements.txt - method: pip path: . vblf-0.3.0/CHANGELOG.md000066400000000000000000000017331520700434100142540ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the changes for the upcoming release can be found in . ## [v0.3.0](https://github.com/zariiii9003/vblf/tree/v0.3.0) - 2026-05-31 ### Added - SystemTime: add to_datetime() ([#18](https://github.com/zariiii9003/vblf/issues/18)) ## [v0.2.1](https://github.com/zariiii9003/vblf/tree/v0.2.1) - 2025-10-21 ### Added - Implement EthernetFrameEx, EthernetStatistic and DiagRequestInterpretation. ([#10](https://github.com/zariiii9003/vblf/issues/10)) ## [v0.1.0](https://github.com/zariiii9003/vblf/tree/v0.1.0) - 2025-06-20 ### Added - Initial implementation vblf-0.3.0/CONTRIBUTING.md000066400000000000000000000062231520700434100146730ustar00rootroot00000000000000# Contributing to vblf Thank you for your interest in contributing to **vblf**! This guide will help you set up your development environment, run tests, ensure code quality, and add changelog entries for your contributions. ## 1. Clone the Repository First, clone the repository from GitHub: ```bash git clone https://github.com/zariiii9003/vblf.git cd vblf ``` - This will create a local copy of the project and move you into the project directory. ## 2. Install Development Dependencies To get started, install the development dependencies. These include tools for testing, linting, formatting, and documentation. ```bash python -m pip install -e . --group dev ``` - This command installs the package in editable mode and all dependencies listed under the `dev` group in `pyproject.toml` (including `tox`, `towncrier`, linters, etc.). ## 3. Set Up Pre-commit Hooks After installing development dependencies, set up pre-commit hooks to automatically check formatting and linting before each commit: ```bash pre-commit install ``` - This command installs the git hooks defined in `.pre-commit-config.yaml` (if present), so checks like formatting and linting run automatically when you commit. ## 4. Running All Checks and Tests To run all predefined checks and tests, simply run: ```bash tox ``` - This will execute all environments defined in `tox.ini`: formatting, linting, type checking, tests, and documentation build. It's the easiest way to ensure your code passes all quality checks before submitting a contribution. If you want to check only a specific aspect, you can run an individual environment: - **Formatting:** ```bash tox -e format ``` Checks code formatting using `ruff`. - **Linting:** ```bash tox -e lint ``` Runs `ruff` for linting and code style checks. - **Type Checking:** ```bash tox -e type ``` Runs `mypy` for static type checking. - **Tests:** ```bash tox -e py ``` Runs all tests using `pytest`. - **Documentation:** ```bash tox -e docs ``` Builds the documentation using Sphinx. ## 5. Adding a News Fragment (Changelog Entry) This project uses [towncrier](https://towncrier.readthedocs.io/) to manage the changelog. For every user-facing change, add a news fragment in the `changelog.d/` directory. - The filename should be `..md`, e.g., `123.added.md` or `456.fixed.md`. Both issue and pull request numbers are valid. - Valid types are: `added`, `changed`, `deprecated`, `removed`, `fixed`, `security`. - Write a short description of your change in the file. You can create a news fragment manually, or from the command line using towncrier: ```bash towncrier create -c "Fixed a bug!" 5.fixed.md ``` This will create a file `changelog.d/5.fixed.md` with the provided content. Example: ``` changelog.d/123.added.md ``` Content: ``` Added support for new BLF message type. ``` When a release is made, these fragments are automatically compiled into `CHANGELOG.md`. ## 6. Submitting Your Contribution - Ensure your code passes all checks and tests. - Add a news fragment for your change. - Open a pull request with a clear description of your changes. Thank you for helping improve **vblf**! vblf-0.3.0/LICENSE000066400000000000000000000021171520700434100134450ustar00rootroot00000000000000MIT License Copyright (c) 2024-present Artur Drogunow Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. vblf-0.3.0/README.md000066400000000000000000000030261520700434100137170ustar00rootroot00000000000000# Binary Logging Format Library for Python [![PyPI - Version](https://img.shields.io/pypi/v/vblf.svg)](https://pypi.org/project/vblf) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/vblf.svg)](https://pypi.org/project/vblf) ## Introduction A Python library for reading and writing BLF files, a proprietary binary logging format of Vector Informatik GmbH. BLF files are commonly used in automotive logging and testing scenarios. ## Installation ```bash pip install vblf ``` ## Usage ### Reading BLF Files ```python from vblf.can import CanMessage, CanMessage2 from vblf.reader import BlfReader # Open a BLF file with BlfReader("example.blf") as reader: # Iterate through all objects in the file for obj in reader: print(f"Type: {obj.header.base.object_type.name}") print(f"Timestamp: {obj.header.object_time_stamp}") # Handle CAN messages if isinstance(obj, (CanMessage, CanMessage2)): print(f"CAN ID: {obj.id}") print(f"Data: {obj.data.hex()}") ``` ### Writing BLF Files ```python from vblf.can import CanMessage from vblf.writer import BlfWriter # Create a new BLF file with BlfWriter("output.blf") as writer: # Create a CAN message msg = CanMessage(...) # Write the message to the file writer.write(msg) ``` ## License This project is licensed under the MIT License. ## Acknowledgments - Vector Informatik GmbH for the BLF file format - Tobias Lorenz for his C++ library [vector_blf](https://bitbucket.org/tobylorenz/vector_blf/src/master/) vblf-0.3.0/changelog.d/000077500000000000000000000000001520700434100146105ustar00rootroot00000000000000vblf-0.3.0/changelog.d/.gitignore000066400000000000000000000001421520700434100165750ustar00rootroot00000000000000* !.gitignore !*.security.md !*.removed.md !*.deprecated.md !*.added.md !*.changed.md !*.fixed.md vblf-0.3.0/docs/000077500000000000000000000000001520700434100133675ustar00rootroot00000000000000vblf-0.3.0/docs/can.rst000066400000000000000000000000621520700434100146600ustar00rootroot00000000000000CAN Objects ----------- .. automodule:: vblf.can vblf-0.3.0/docs/conf.py000066400000000000000000000030511520700434100146650ustar00rootroot00000000000000# Configuration file for the Sphinx documentation builder. # # For the full list of built-in configuration values, see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information project = "vblf" copyright = "2024, Artur Drogunow" # noqa: A001 author = "Artur Drogunow" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration extensions = [ "sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.viewcode", ] templates_path = ["_templates"] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # location of typehints autodoc_typehints = "description" # The default autodoc directive flags autodoc_default_options = { "members": True, "show-inheritance": True, "undoc-members": True, "member-order": "bysource", } # decide whether module names are prepended to all object names add_module_names = False # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = "furo" # -- Options for intersphinx extension --------------------------------------- # https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#configuration intersphinx_mapping = { "python": ("https://docs.python.org/3", None), } vblf-0.3.0/docs/constants.rst000066400000000000000000000000641520700434100161350ustar00rootroot00000000000000Constants --------- .. automodule:: vblf.constants vblf-0.3.0/docs/ethernet.rst000066400000000000000000000001011520700434100157270ustar00rootroot00000000000000Ethernet Objects ---------------- .. automodule:: vblf.ethernet vblf-0.3.0/docs/flexray.rst000066400000000000000000000000761520700434100155760ustar00rootroot00000000000000FlexRay Objects --------------- .. automodule:: vblf.flexray vblf-0.3.0/docs/general.rst000066400000000000000000000000761520700434100155410ustar00rootroot00000000000000General Objects --------------- .. automodule:: vblf.general vblf-0.3.0/docs/index.rst000066400000000000000000000036071520700434100152360ustar00rootroot00000000000000BLF Library for Python ====================== .. image:: https://img.shields.io/pypi/v/vblf.svg :target: https://pypi.org/project/vblf :alt: PyPI - Version .. image:: https://img.shields.io/pypi/pyversions/vblf.svg :target: https://pypi.org/project/vblf :alt: PyPI - Python Version .. toctree:: :maxdepth: 1 :caption: Contents: reader writer general can ethernet flexray lin most constants Introduction ------------ This is a Python library for reading and writing BLF files, a proprietary binary logging format of Vector Informatik GmbH. BLF files are commonly used in automotive logging and testing scenarios. Installation ------------ .. code-block:: bash pip install vblf Usage ----- Reading BLF Files ~~~~~~~~~~~~~~~~~ .. code-block:: python from vblf.can import CanMessage, CanMessage2 from vblf.reader import BlfReader # Open a BLF file with BlfReader("example.blf") as reader: # Iterate through all objects in the file for obj in reader: print(f"Type: {obj.header.base.object_type.name}") print(f"Timestamp: {obj.header.object_time_stamp}") # Handle CAN messages if isinstance(obj, (CanMessage, CanMessage2)): print(f"CAN ID: {obj.id}") print(f"Data: {obj.data.hex()}") Writing BLF Files ~~~~~~~~~~~~~~~~~ .. code-block:: python from vblf.can import CanMessage from vblf.writer import BlfWriter # Create a new BLF file with BlfWriter("output.blf") as writer: # Create a CAN message msg = CanMessage(...) # Write the message to the file writer.write(msg) License ------- This project is licensed under the MIT License. Acknowledgments --------------- - Vector Informatik GmbH for the BLF file format - Tobias Lorenz for his C++ library `vector_blf `_ vblf-0.3.0/docs/lin.rst000066400000000000000000000000621520700434100147010ustar00rootroot00000000000000LIN Objects ----------- .. automodule:: vblf.lin vblf-0.3.0/docs/most.rst000066400000000000000000000000651520700434100151040ustar00rootroot00000000000000MOST Objects ------------ .. automodule:: vblf.most vblf-0.3.0/docs/reader.rst000066400000000000000000000000611520700434100153600ustar00rootroot00000000000000BlfReader --------- .. automodule:: vblf.reader vblf-0.3.0/docs/requirements.txt000066400000000000000000000000351520700434100166510ustar00rootroot00000000000000furo>=2024.8.6 sphinx>=8.1.3 vblf-0.3.0/docs/writer.rst000066400000000000000000000000611520700434100154320ustar00rootroot00000000000000BlfWriter --------- .. automodule:: vblf.writer vblf-0.3.0/pyproject.toml000066400000000000000000000052061520700434100153560ustar00rootroot00000000000000[build-system] requires = ["setuptools==82.*", "setuptools-scm>=8"] build-backend = "setuptools.build_meta" [project] name = "vblf" description = "A library to read and write Vector BLF files (binary log format)" readme = "README.md" authors = [{ name = "Artur Drogunow", email = "Artur.Drogunow@zf.com" }] license = { text = "MIT" } requires-python = ">=3.9" dependencies = [ "typing_extensions>=4.0.0" ] dynamic = ["version"] keywords = ["BLF", "Vector", "binary log format", "Automotive"] classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ] [project.urls] Issues = "https://github.com/zariiii9003/vblf/issues" Source = "https://github.com/zariiii9003/vblf" Homepage = "https://github.com/zariiii9003/vblf" [tool.setuptools_scm] # presence of this section triggers setuptools_scm to manage the version [dependency-groups] dev = [ "tox>=4.23.2", "towncrier", {include-group = "lint"}, ] test = [ "pytest==8.4.*", ] lint = [ "ruff==0.15.*", "mypy==1.19.*", ] [tool.ruff] line-length = 100 lint.extend-select = [ "A", # flake8-builtins "B", # flake8-bugbear "BLE", # flake8-blind-except "C4", # flake8-comprehensions "E", # pycodestyle "EM", # flake8-errmsg "F", # pyflakes "FURB", # refurb "G", # flake8-logging-format "I", # isort "N", # pep8-naming "PERF", # Perflint "PIE", # flake8-pie "PL", # pylint "RSE", # flake8-raise "RUF", # Ruff-specific rules "SIM", # flake8-simplify "T20", # flake8-print "TC", # flake8-type-checking "UP", # pyupgrade "W", # pycodestyle ] lint.ignore = [ "PLR0913", # too-many-arguments ] lint.per-file-ignores."tests/**.py" = [ "PL", # pylint ] [tool.towncrier] directory = "changelog.d" filename = "CHANGELOG.md" start_string = "\n" underlines = ["", "", ""] title_format = "## [{version}](https://github.com/zariiii9003/vblf/tree/{version}) - {project_date}" issue_format = "[#{issue}](https://github.com/zariiii9003/vblf/issues/{issue})" [[tool.towncrier.type]] directory = "security" name = "Security" showcontent = true [[tool.towncrier.type]] directory = "removed" name = "Removed" showcontent = true [[tool.towncrier.type]] directory = "deprecated" name = "Deprecated" showcontent = true [[tool.towncrier.type]] directory = "added" name = "Added" showcontent = true [[tool.towncrier.type]] directory = "changed" name = "Changed" showcontent = true [[tool.towncrier.type]] directory = "fixed" name = "Fixed" showcontent = true vblf-0.3.0/src/000077500000000000000000000000001520700434100132265ustar00rootroot00000000000000vblf-0.3.0/src/vblf/000077500000000000000000000000001520700434100141575ustar00rootroot00000000000000vblf-0.3.0/src/vblf/__init__.py000066400000000000000000000002421520700434100162660ustar00rootroot00000000000000import contextlib from importlib.metadata import PackageNotFoundError, version with contextlib.suppress(PackageNotFoundError): __version__ = version("vblf") vblf-0.3.0/src/vblf/can.py000066400000000000000000000475401520700434100153040ustar00rootroot00000000000000import struct from dataclasses import dataclass from typing import ClassVar from typing_extensions import Self from vblf.constants import CanFdFlags, ObjFlags, ObjType from .general import ObjectHeader, ObjectWithHeader @dataclass class CanMessage(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HBBI8s") header: ObjectHeader channel: int flags: int dlc: int frame_id: int data: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( channel, flags, dlc, frame_id, data_, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, flags, dlc, frame_id, data_, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.flags, self.dlc, self.frame_id, self.data, ) @classmethod def new( cls, object_flags: ObjFlags, object_time_stamp: int, channel: int, flags: int, dlc: int, frame_id: int, data: bytes, ) -> Self: header = ObjectHeader.new( ObjectHeader.SIZE + cls._FORMAT.size, ObjType.CAN_MESSAGE, object_flags, 0, object_time_stamp, ) return cls( header, channel, flags, dlc, frame_id, data, ) @dataclass class CanMessage2(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HBBI8sIBBH") header: ObjectHeader channel: int flags: int dlc: int frame_id: int data: bytes frame_length: int bit_count: int reserved1: int reserved2: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( channel, flags, dlc, frame_id, data_, frame_length, bit_count, reserved1, reserved2, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, flags, dlc, frame_id, data_, frame_length, bit_count, reserved1, reserved2, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.flags, self.dlc, self.frame_id, self.data, self.frame_length, self.bit_count, self.reserved1, self.reserved2, ) @classmethod def new( cls, object_flags: ObjFlags, object_time_stamp: int, channel: int, flags: int, dlc: int, frame_id: int, data: bytes, frame_length: int, bit_count: int, ) -> Self: header = ObjectHeader.new( ObjectHeader.SIZE + cls._FORMAT.size, ObjType.CAN_MESSAGE2, object_flags, 0, object_time_stamp, ) return cls( header, channel, flags, dlc, frame_id, data, frame_length, bit_count, 0, 0, ) @dataclass class CanFdMessage(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HBBIIBBBBI64sI") header: ObjectHeader channel: int flags: int dlc: int frame_id: int frame_length: int arb_bit_count: int canfd_flags: CanFdFlags valid_data_bytes: int reserved1: int reserved2: int data: bytes reserved3: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( channel, flags, dlc, frame_id, frame_length, arb_bit_count, canfd_flags, valid_data_bytes, reserved1, reserved2, data_, reserved3, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, flags, dlc, frame_id, frame_length, arb_bit_count, CanFdFlags(canfd_flags), valid_data_bytes, reserved1, reserved2, data_, reserved3, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.flags, self.dlc, self.frame_id, self.frame_length, self.arb_bit_count, self.canfd_flags, self.valid_data_bytes, self.reserved1, self.reserved2, self.data, self.reserved3, ) @classmethod def new( cls, object_flags: ObjFlags, object_time_stamp: int, channel: int, flags: int, dlc: int, frame_id: int, frame_length: int, arb_bit_count: int, canfd_flags: CanFdFlags, data: bytes, ) -> Self: header = ObjectHeader.new( ObjectHeader.SIZE + cls._FORMAT.size, ObjType.CAN_FD_MESSAGE, object_flags, 0, object_time_stamp, ) return cls( header, channel, flags, dlc, frame_id, frame_length, arb_bit_count, canfd_flags, len(data), 0, 0, data, 0, ) @dataclass class CanFdMessage64(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("BBBBIIIIIIIHBBI") _FORMAT_EXT: ClassVar[struct.Struct] = struct.Struct("II") header: ObjectHeader channel: int dlc: int valid_data_bytes: int tx_count: int frame_id: int frame_length: int flags: CanFdFlags btr_cfg_arb: int btr_cfg_data: int time_offset_brs_ns: int time_offset_crc_del_ns: int bit_count: int dir: int ext_data_offset: int crc: int data: bytes btr_ext_arb: int btr_ext_data: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) # get fixed size values ( channel, dlc, valid_data_bytes, tx_count, frame_id, frame_length, flags, btr_cfg_arb, btr_cfg_data, time_offset_brs_ns, time_offset_crc_del_ns, bit_count, direction, ext_data_offset, crc, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) # get data data_offset = ObjectHeader.SIZE + cls._FORMAT.size data_length = (ext_data_offset or header.base.object_size) - data_offset data = buffer[data_offset : data_offset + data_length] # get ext frame data btr_ext_arb, btr_ext_data = 0, 0 if ( ext_data_offset != 0 and header.base.object_size >= ext_data_offset + cls._FORMAT_EXT.size ): btr_ext_arb, btr_ext_data = cls._FORMAT_EXT.unpack_from(buffer, ext_data_offset) return cls( header, channel, dlc, valid_data_bytes, tx_count, frame_id, frame_length, CanFdFlags(flags), btr_cfg_arb, btr_cfg_data, time_offset_brs_ns, time_offset_crc_del_ns, bit_count, direction, ext_data_offset, crc, data, btr_ext_arb, btr_ext_data, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) # pack header self.header.pack_into(buffer, 0) # pack fixed size values self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.channel, self.dlc, self.valid_data_bytes, self.tx_count, self.frame_id, self.frame_length, self.flags, self.btr_cfg_arb, self.btr_cfg_data, self.time_offset_brs_ns, self.time_offset_crc_del_ns, self.bit_count, self.dir, self.ext_data_offset, self.crc, ) # pack data data_offset = ObjectHeader.SIZE + self._FORMAT.size buffer[data_offset : data_offset + len(self.data)] = self.data # pack ext frame data if ( self.ext_data_offset != 0 and self.header.base.object_size >= self.ext_data_offset + self._FORMAT_EXT.size ): self._FORMAT_EXT.pack_into( buffer, self.ext_data_offset, self.btr_ext_arb, self.btr_ext_data ) return bytes(buffer) @dataclass class CanDriverStatistic(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHIIIIIII") header: ObjectHeader channel: int bus_load: int standard_data_frames: int extended_data_frames: int standard_remote_frames: int extended_remote_frames: int error_frames: int overload_frames: int reserved: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( channel, bus_load, standard_data_frames, extended_data_frames, standard_remote_frames, extended_remote_frames, error_frames, overload_frames, reserved, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, bus_load, standard_data_frames, extended_data_frames, standard_remote_frames, extended_remote_frames, error_frames, overload_frames, reserved, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.bus_load, self.standard_data_frames, self.extended_data_frames, self.standard_remote_frames, self.extended_remote_frames, self.error_frames, self.overload_frames, self.reserved, ) @dataclass class CanDriverError(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HBBI") header: ObjectHeader channel: int tx_errors: int rx_errors: int error_code: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( channel, tx_errors, rx_errors, error_code, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, tx_errors, rx_errors, error_code, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.tx_errors, self.rx_errors, self.error_code, ) @dataclass class CanDriverErrorExt(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HBBIIBBH4I") header: ObjectHeader channel: int tx_errors: int rx_errors: int error_code: int flags: int state: int reserved1: int reserved2: int reserved3: list[int] @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( channel, tx_errors, rx_errors, error_code, flags, state, reserved1, reserved2, reserved3_0, reserved3_1, reserved3_2, reserved3_3, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, tx_errors, rx_errors, error_code, flags, state, reserved1, reserved2, [reserved3_0, reserved3_1, reserved3_2, reserved3_3], ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.tx_errors, self.rx_errors, self.error_code, self.flags, self.state, self.reserved1, self.reserved2, self.reserved3[0], self.reserved3[1], self.reserved3[2], self.reserved3[3], ) @dataclass class CanErrorFrame(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHI") header: ObjectHeader channel: int length: int reserved: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) channel, length, reserved = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls(header, channel, length, reserved) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack(self.channel, self.length, self.reserved) @dataclass class CanErrorFrameExt(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHIBBBBIIHH8s") header: ObjectHeader channel: int length: int flags: int ecc: int position: int dlc: int reserved1: int frame_length_in_ns: int frame_id: int flags_ext: int reserved2: int data: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( channel, length, flags, ecc, position, dlc, reserverd1, frame_length_in_ns, frame_id, flags_ext, reserved2, data, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, length, flags, ecc, position, dlc, reserverd1, frame_length_in_ns, frame_id, flags_ext, reserved2, data, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.length, self.flags, self.ecc, self.position, self.dlc, self.reserved1, self.frame_length_in_ns, self.frame_id, self.flags_ext, self.reserved2, self.data, ) @dataclass class CanFdErrorFrame64(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("BBBBHHHBBIIIIIIIHH") _FORMAT_EXT: ClassVar[struct.Struct] = struct.Struct("II") header: ObjectHeader channel: int dlc: int valid_data_bytes: int ecc: int flags: int error_code_ext: int ext_flags: int ext_data_offset: int reserved1: int frame_id: int frame_length: int btr_cfg_arb: int btr_cfg_data: int time_offset_brs_ns: int time_offset_crc_del_ns: int crc: int error_position: int reserved2: int data: bytes btr_ext_arb: int btr_ext_data: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) # get fixed size values ( channel, dlc, valid_data_bytes, ecc, flags, error_code_ext, ext_flags, ext_data_offset, reserved1, frame_id, frame_length, btr_cfg_arb, btr_cfg_data, time_offset_brs_ns, time_offset_crc_del_ns, crc, error_position, reserved2, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) # get data data_offset = ObjectHeader.SIZE + cls._FORMAT.size data = buffer[data_offset : data_offset + valid_data_bytes] # get ext frame data btr_ext_arb, btr_ext_data = 0, 0 if header.base.object_size >= ext_data_offset + cls._FORMAT_EXT.size: btr_ext_arb, btr_ext_data = cls._FORMAT_EXT.unpack_from(buffer, ext_data_offset) return cls( header, channel, dlc, valid_data_bytes, ecc, flags, error_code_ext, ext_flags, ext_data_offset, reserved1, frame_id, frame_length, btr_cfg_arb, btr_cfg_data, time_offset_brs_ns, time_offset_crc_del_ns, crc, error_position, reserved2, data, btr_ext_arb, btr_ext_data, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) # pack header self.header.pack_into(buffer, 0) # pack fixed size values self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.channel, self.dlc, self.valid_data_bytes, self.ecc, self.flags, self.error_code_ext, self.ext_flags, self.ext_data_offset, self.reserved1, self.frame_id, self.frame_length, self.btr_cfg_arb, self.btr_cfg_data, self.time_offset_brs_ns, self.time_offset_crc_del_ns, self.crc, self.error_position, self.reserved2, ) # pack data data_offset = ObjectHeader.SIZE + self._FORMAT.size buffer[data_offset : data_offset + self.valid_data_bytes] = self.data # pack ext frame data if self.header.base.object_size >= self.ext_data_offset + self._FORMAT_EXT.size: self._FORMAT_EXT.pack_into( buffer, self.ext_data_offset, self.btr_ext_arb, self.btr_ext_data ) return bytes(buffer) @dataclass class CanDriverHwSync(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HBBI") header: ObjectHeader channel: int flags: int reserved1: int reserved2: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) channel, flags, reserved1, reserved2 = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls(header, channel, flags, reserved1, reserved2) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.flags, self.reserved1, self.reserved2 ) @dataclass class CanOverloadFrame(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHI") header: ObjectHeader channel: int reserved1: int reserved2: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) channel, reserved1, reserved2 = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls(header, channel, reserved1, reserved2) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack(self.channel, self.reserved1, self.reserved2) vblf-0.3.0/src/vblf/constants.py000066400000000000000000000123371520700434100165530ustar00rootroot00000000000000from enum import IntEnum, IntFlag from typing import Final FILE_SIGNATURE: Final = b"LOGG" OBJ_SIGNATURE: Final = b"LOBJ" OBJ_SIGNATURE_SIZE: Final = len(OBJ_SIGNATURE) class ObjType(IntEnum): UNKNOWN = 0 CAN_MESSAGE = 1 CAN_ERROR = 2 CAN_OVERLOAD = 3 CAN_STATISTIC = 4 APP_TRIGGER = 5 ENV_INTEGER = 6 ENV_DOUBLE = 7 ENV_STRING = 8 ENV_DATA = 9 LOG_CONTAINER = 10 LIN_MESSAGE = 11 LIN_CRC_ERROR = 12 LIN_DLC_INFO = 13 LIN_RCV_ERROR = 14 LIN_SND_ERROR = 15 LIN_SLV_TIMEOUT = 16 LIN_SCHED_MODCH = 17 LIN_SYN_ERROR = 18 LIN_BAUDRATE = 19 LIN_SLEEP = 20 LIN_WAKEUP = 21 MOST_SPY = 22 MOST_CTRL = 23 MOST_LIGHTLOCK = 24 MOST_STATISTIC = 25 reserved_1 = 26 reserved_2 = 27 reserved_3 = 28 FLEXRAY_DATA = 29 FLEXRAY_SYNC = 30 CAN_DRIVER_ERROR = 31 MOST_PKT = 32 MOST_PKT2 = 33 MOST_HWMODE = 34 MOST_REG = 35 MOST_GENREG = 36 MOST_NETSTATE = 37 MOST_DATALOST = 38 MOST_TRIGGER = 39 FLEXRAY_CYCLE = 40 FLEXRAY_MESSAGE = 41 LIN_CHECKSUM_INFO = 42 LIN_SPIKE_EVENT = 43 CAN_DRIVER_SYNC = 44 FLEXRAY_STATUS = 45 GPS_EVENT = 46 FR_ERROR = 47 FR_STATUS = 48 FR_STARTCYCLE = 49 FR_RCVMESSAGE = 50 REALTIMECLOCK = 51 AVAILABLE2 = 52 AVAILABLE3 = 53 LIN_STATISTIC = 54 J1708_MESSAGE = 55 J1708_VIRTUAL_MSG = 56 LIN_MESSAGE2 = 57 LIN_SND_ERROR2 = 58 LIN_SYN_ERROR2 = 59 LIN_CRC_ERROR2 = 60 LIN_RCV_ERROR2 = 61 LIN_WAKEUP2 = 62 LIN_SPIKE_EVENT2 = 63 LIN_LONG_DOM_SIG = 64 APP_TEXT = 65 FR_RCVMESSAGE_EX = 66 MOST_STATISTICEX = 67 MOST_TXLIGHT = 68 MOST_ALLOCTAB = 69 MOST_STRESS = 70 ETHERNET_FRAME = 71 SYS_VARIABLE = 72 CAN_ERROR_EXT = 73 CAN_DRIVER_ERROR_EXT = 74 LIN_LONG_DOM_SIG2 = 75 MOST_150_MESSAGE = 76 MOST_150_PKT = 77 MOST_ETHERNET_PKT = 78 MOST_150_MESSAGE_FRAGMENT = 79 MOST_150_PKT_FRAGMENT = 80 MOST_ETHERNET_PKT_FRAGMENT = 81 MOST_SYSTEM_EVENT = 82 MOST_150_ALLOCTAB = 83 MOST_50_MESSAGE = 84 MOST_50_PKT = 85 CAN_MESSAGE2 = 86 LIN_UNEXPECTED_WAKEUP = 87 LIN_SHORT_OR_SLOW_RESPONSE = 88 LIN_DISTURBANCE_EVENT = 89 SERIAL_EVENT = 90 OVERRUN_ERROR = 91 EVENT_COMMENT = 92 WLAN_FRAME = 93 WLAN_STATISTIC = 94 MOST_ECL = 95 GLOBAL_MARKER = 96 AFDX_FRAME = 97 AFDX_STATISTIC = 98 KLINE_STATUSEVENT = 99 CAN_FD_MESSAGE = 100 CAN_FD_MESSAGE_64 = 101 ETHERNET_RX_ERROR = 102 ETHERNET_STATUS = 103 CAN_FD_ERROR_64 = 104 LIN_SHORT_OR_SLOW_RESPONSE2 = 105 AFDX_STATUS = 106 AFDX_BUS_STATISTIC = 107 reserved_4 = 108 AFDX_ERROR_EVENT = 109 A429_ERROR = 110 A429_STATUS = 111 A429_BUS_STATISTIC = 112 A429_MESSAGE = 113 ETHERNET_STATISTIC = 114 reserved_5 = 115 reserved_6 = 116 reserved_7 = 117 TEST_STRUCTURE = 118 DIAG_REQUEST_INTERPRETATION = 119 ETHERNET_FRAME_EX = 120 ETHERNET_FRAME_FORWARDED = 121 ETHERNET_ERROR_EX = 122 ETHERNET_ERROR_FORWARDED = 123 FUNCTION_BUS = 124 DATA_LOST_BEGIN = 125 DATA_LOST_END = 126 WATER_MARK_EVENT = 127 TRIGGER_CONDITION = 128 @staticmethod def from_int(object_type: int) -> "ObjType": try: return ObjType(object_type) except ValueError: return ObjType.UNKNOWN class AppId(IntEnum): UNKNOWN = 0 CANALYZER = 1 CANOE = 2 CANSTRESS = 3 CANLOG = 4 CANAPE = 5 CANCASEXLLOG = 6 VLCONFIG = 7 PORSCHELOGGER = 200 @staticmethod def from_int(application_id: int) -> "AppId": try: return AppId(application_id) except ValueError: return AppId.UNKNOWN class Compression(IntEnum): NONE = 0 SPEED = 1 DEFAULT = 6 MAX = 9 @staticmethod def from_int(compression_level: int) -> "Compression | int": try: return Compression(compression_level) except ValueError: return compression_level class ObjFlags(IntFlag): TIME_TEN_MICS = 0x1 TIME_ONE_NANS = 0x2 class TriggerFlag(IntFlag): SINGLE_TRIGGER = 0x0 LOGGING_START = 0x1 LOGGING_STOP = 0x2 class CanFdFlags(IntFlag): NERR = 0x0004 HIGH_VOLTAGE_WAKE_UP = 0x0008 REMOTE_FRAME = 0x0010 TX_ACKNOWLEDGE = 0x0040 TX_REQUEST = 0x0080 SRR = 0x0200 R0 = 0x0400 R1 = 0x0800 FDF = 0x1000 BRS = 0x2000 ESI = 0x4000 FRAME_PART_OF_BURST = 0x20000 SINGLE_SHOT_MODE_NOT_TRANSMITTED = 0x40000 SINGLE_SHOT_MODE_REASON = 0x80000 # 0 = arbitration lost, 1 = frame disturbed class SysVarType(IntEnum): DOUBLE = 1 LONG = 2 STRING = 3 DOUBLEARRAY = 4 LONGARRAY = 5 LONGLONG = 6 BYTEARRAY = 7 class BusType(IntEnum): CAN = 1 LIN = 5 MOST = 6 FLEXRAY = 7 J1708 = 9 ETHERNET = 10 WLAN = 13 AFDX = 14 class AppTextSource(IntEnum): MEASUREMENTCOMMENT = 0 DBCHANNELINFO = 1 METADATA = 2 ATTACHMENT = 3 TRACELINE = 4 class FunctionBusType(IntEnum): UNDEFINED = 0 SIGNAL = 1 SERVICE_FUNCTION = 2 STATE = 3 class TriggerConditionStatus(IntEnum): UNKNOWN = 0 START = 1 STOP = 2 STARTSTOP = 3 vblf-0.3.0/src/vblf/ethernet.py000066400000000000000000000101441520700434100163470ustar00rootroot00000000000000import struct from dataclasses import dataclass from typing import ClassVar from typing_extensions import Self from vblf.general import ObjectHeader, ObjectWithHeader @dataclass class EthernetFrameEx(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHHHQIHHII") header: ObjectHeader struct_length: int flags: int channel: int hardware_channel: int frame_duration: int frame_checksum: int dir: int frame_length: int frame_handle: int reserved: int frame_data: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) ( struct_length, flags, channel, hardware_channel, frame_duration, frame_checksum, direction, frame_length, frame_handle, reserved, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) # get data_bytes data_offset = ObjectHeader.SIZE + cls._FORMAT.size available_bytes = min(frame_length, len(buffer) - data_offset) data_bytes = buffer[data_offset : data_offset + available_bytes] return cls( header, struct_length, flags, channel, hardware_channel, frame_duration, frame_checksum, direction, frame_length, frame_handle, reserved, data_bytes, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) self.header.pack_into(buffer, 0) self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.struct_length, self.flags, self.channel, self.hardware_channel, self.frame_duration, self.frame_checksum, self.dir, self.frame_length, self.frame_handle, self.reserved, ) # pack data_bytes data_offset = ObjectHeader.SIZE + self._FORMAT.size buffer[data_offset : data_offset + len(self.frame_data)] = self.frame_data return bytes(buffer) @dataclass class EthernetStatistic(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHIQQQQQQQhHI") channel: int reserved_1: int reserved_2: int rcv_ok_hw: int xmit_ok_hw: int rcv_error_hw: int xmit_error_hw: int rcv_bytes_hw: int xmit_bytes_hw: int rcv_no_buffer_hw: int sqi: int hardware_channel: int reserved_3: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) ( channel, reserved_1, reserved_2, rcv_ok_hw, xmit_ok_hw, rcv_error_hw, xmit_error_hw, rcv_bytes_hw, xmit_bytes_hw, rcv_no_buffer_hw, sqi, hardware_channel, reserved_3, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, reserved_1, reserved_2, rcv_ok_hw, xmit_ok_hw, rcv_error_hw, xmit_error_hw, rcv_bytes_hw, xmit_bytes_hw, rcv_no_buffer_hw, sqi, hardware_channel, reserved_3, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) self.header.pack_into(buffer, 0) self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.channel, self.reserved_1, self.reserved_2, self.rcv_ok_hw, self.xmit_ok_hw, self.rcv_error_hw, self.xmit_error_hw, self.rcv_bytes_hw, self.xmit_bytes_hw, self.rcv_no_buffer_hw, self.sqi, self.hardware_channel, self.reserved_3, ) return bytes(buffer) vblf-0.3.0/src/vblf/flexray.py000066400000000000000000000064431520700434100162120ustar00rootroot00000000000000import struct from dataclasses import dataclass from typing import ClassVar from typing_extensions import Self from vblf.general import ObjectHeader, ObjectWithHeader @dataclass class FlexrayVFrReceiveMsgEx(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHHHIIHHHHHHIIIIIIHHH26s") header: ObjectHeader channel: int version: int channel_mask: int dir_flags: int client_index: int cluster_no: int frame_id: int header_crc1: int header_crc2: int byte_count: int data_count: int cycle: int tag: int data: int frame_flags: int app_parameter: int frame_crc: int frame_length_ns: int frame_id1: int pdu_offset: int blf_log_mask: int reserved: bytes data_bytes: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) ( channel, version, channel_mask, dir_flags, client_index, cluster_no, frame_id, header_crc1, header_crc2, byte_count, data_count, cycle, tag, data, frame_flags, app_parameter, frame_crc, frame_length_ns, frame_id1, pdu_offset, blf_log_mask, reserved, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) # get data_bytes data_offset = ObjectHeader.SIZE + cls._FORMAT.size available_bytes = min(data_count, len(buffer) - data_offset) data_bytes = buffer[data_offset : data_offset + available_bytes] return cls( header, channel, version, channel_mask, dir_flags, client_index, cluster_no, frame_id, header_crc1, header_crc2, byte_count, data_count, cycle, tag, data, frame_flags, app_parameter, frame_crc, frame_length_ns, frame_id1, pdu_offset, blf_log_mask, reserved, data_bytes, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) self.header.pack_into(buffer, 0) self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.channel, self.version, self.channel_mask, self.dir_flags, self.client_index, self.cluster_no, self.frame_id, self.header_crc1, self.header_crc2, self.byte_count, self.data_count, self.cycle, self.tag, self.data, self.frame_flags, self.app_parameter, self.frame_crc, self.frame_length_ns, self.frame_id1, self.pdu_offset, self.blf_log_mask, self.reserved, ) # pack data_bytes data_offset = ObjectHeader.SIZE + self._FORMAT.size buffer[data_offset : data_offset + len(self.data_bytes)] = self.data_bytes return bytes(buffer) vblf-0.3.0/src/vblf/general.py000066400000000000000000000664451520700434100161650ustar00rootroot00000000000000import datetime import struct from dataclasses import dataclass from typing import ClassVar, Generic, Optional, TypeVar, Union from typing_extensions import Self from vblf import __version__ from vblf.constants import ( FILE_SIGNATURE, OBJ_SIGNATURE, AppId, AppTextSource, BusType, Compression, FunctionBusType, ObjFlags, ObjType, SysVarType, TriggerConditionStatus, TriggerFlag, ) HeaderType = TypeVar("HeaderType", bound="HeaderWithBase") @dataclass class SystemTime: _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHHHHHHH") year: int month: int day_of_week: int day: int hour: int minute: int second: int milliseconds: int @classmethod def unpack(cls, buffer: bytes) -> Self: return cls(*cls._FORMAT.unpack(buffer)) def pack(self) -> bytes: return self._FORMAT.pack(*self.__dict__.values()) @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: return cls(*cls._FORMAT.unpack_from(buffer, offset)) def pack_into(self, buffer: bytearray, offset: int) -> None: return self._FORMAT.pack_into(buffer, offset, *self.__dict__.values()) @classmethod def from_datetime(cls, dt: Optional[datetime.datetime] = None) -> Self: if not dt: dt = datetime.datetime.now(tz=datetime.timezone.utc) return cls( dt.year, dt.month, (dt.weekday() + 1) % 7, dt.day, dt.hour, dt.minute, dt.second, min(999, round(dt.microsecond / 1000.0)), ) def to_datetime(self) -> datetime.datetime: return datetime.datetime( self.year, self.month, self.day, self.hour, self.minute, self.second, self.milliseconds * 1000, ) @dataclass class ObjectHeaderBase: _FORMAT: ClassVar[struct.Struct] = struct.Struct("4sHHII") SIZE: ClassVar[int] = _FORMAT.size signature: bytes header_size: int header_version: int object_size: int object_type: ObjType @classmethod def unpack(cls, buffer: bytes) -> Self: ( signature, header_size, header_version, object_size, object_type, ) = cls._FORMAT.unpack(buffer) return cls( signature, header_size, header_version, object_size, ObjType.from_int(object_type), ) @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: ( signature, header_size, header_version, object_size, object_type, ) = cls._FORMAT.unpack_from(buffer, offset) return cls( signature, header_size, header_version, object_size, ObjType.from_int(object_type), ) def pack(self) -> bytes: return self._FORMAT.pack(*self.__dict__.values()) def pack_into(self, buffer: bytearray, offset: int) -> None: self._FORMAT.pack_into(buffer, offset, *self.__dict__.values()) @dataclass class HeaderWithBase: base: ObjectHeaderBase @classmethod def unpack(cls, buffer: bytes) -> Self: raise NotImplementedError @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: raise NotImplementedError def pack(self) -> bytes: raise NotImplementedError def pack_into(self, buffer: bytearray, offset: int) -> None: raise NotImplementedError @dataclass class VarObjectHeader(HeaderWithBase): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IHHQ") SIZE: ClassVar[int] = ObjectHeaderBase.SIZE + _FORMAT.size object_flags: ObjFlags object_static_size: int object_version: int object_time_stamp: int @classmethod def unpack(cls, buffer: bytes) -> Self: base = ObjectHeaderBase.unpack_from(buffer, 0) ( object_flags, object_static_size, object_version, object_time_stamp, ) = cls._FORMAT.unpack_from(buffer, ObjectHeaderBase.SIZE) return cls( base, ObjFlags(object_flags), object_static_size, object_version, object_time_stamp, ) @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: base = ObjectHeaderBase.unpack_from(buffer, 0) ( object_flags, object_static_size, object_version, object_time_stamp, ) = cls._FORMAT.unpack_from(buffer, offset + ObjectHeaderBase.SIZE) return cls( base, ObjFlags(object_flags), object_static_size, object_version, object_time_stamp, ) def pack(self) -> bytes: return self.base.pack() + self._FORMAT.pack( self.object_flags, self.object_static_size, self.object_version, self.object_time_stamp, ) def pack_into(self, buffer: bytearray, offset: int) -> None: self.base.pack_into(buffer, offset) self._FORMAT.pack_into( buffer, offset + ObjectHeaderBase.SIZE, self.object_flags, self.object_static_size, self.object_version, self.object_time_stamp, ) @dataclass class ObjectHeader(HeaderWithBase): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IHHQ") SIZE: ClassVar[int] = ObjectHeaderBase.SIZE + _FORMAT.size object_flags: ObjFlags client_index: int object_version: int object_time_stamp: int @classmethod def unpack(cls, buffer: bytes) -> Self: base = ObjectHeaderBase.unpack_from(buffer, 0) ( object_flags, client_index, object_version, object_time_stamp, ) = cls._FORMAT.unpack_from(buffer, ObjectHeaderBase.SIZE) return cls( base, ObjFlags(object_flags), client_index, object_version, object_time_stamp, ) @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: base = ObjectHeaderBase.unpack_from(buffer, offset) ( object_flags, client_index, object_version, object_time_stamp, ) = cls._FORMAT.unpack_from(buffer, offset + ObjectHeaderBase.SIZE) return cls( base, ObjFlags(object_flags), client_index, object_version, object_time_stamp, ) def pack(self) -> bytes: return self.base.pack() + self._FORMAT.pack( self.object_flags, self.client_index, self.object_version, self.object_time_stamp, ) def pack_into(self, buffer: bytearray, offset: int) -> None: self.base.pack_into(buffer, offset) self._FORMAT.pack_into( buffer, offset + ObjectHeaderBase.SIZE, self.object_flags, self.client_index, self.object_version, self.object_time_stamp, ) @classmethod def new( cls, object_size: int, object_type: ObjType, object_flags: ObjFlags, object_version: int, object_time_stamp: int, ) -> Self: base = ObjectHeaderBase( signature=OBJ_SIGNATURE, header_size=cls.SIZE, header_version=1, object_size=object_size, object_type=object_type, ) header = cls( base, object_flags, 0, object_version, object_time_stamp, ) return header # @dataclass # class ObjectHeader2(ObjectHeaderBase): # _FORMAT: ClassVar[struct.Struct] = struct.Struct("IBBHQQ") # SIZE: ClassVar[int] = ObjectHeaderBase.SIZE + _FORMAT.size # object_flags: int # time_stamp_status: int # reserved1: int # object_version: int # object_time_stamp: int # original_time_stamp: int @dataclass class ObjectWithHeader(Generic[HeaderType]): header: HeaderType @classmethod def unpack(cls, buffer: bytes) -> Self: raise NotImplementedError def pack(self) -> bytes: raise NotImplementedError @dataclass class NotImplementedObject(ObjectWithHeader[HeaderWithBase]): header: HeaderWithBase buffer: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: base = ObjectHeaderBase.unpack_from(buffer, 0) header = HeaderWithBase(base) return cls(header, buffer) def pack(self) -> bytes: return self.buffer @dataclass class FileStatistics: _FORMAT: ClassVar[struct.Struct] = struct.Struct("4sIIBBBBQQII32xQ64s") SIZE: ClassVar[int] = _FORMAT.size signature: bytes statistics_size: int api_number: int application_id: AppId compression_level: Union[int, Compression] application_major: int application_minor: int file_size: int uncompressed_file_size: int object_count: int application_build: int measurement_start_time: SystemTime last_object_time: SystemTime restore_points_offset: int reserved: bytes @classmethod def unpack(cls, buffer: bytes) -> "FileStatistics": ( signature, statistics_size, api_number, application_id, compression_level, application_major, application_minor, file_size, uncompressed_file_size, object_count, application_build, restore_points_offset, reserved, ) = cls._FORMAT.unpack(buffer) measurement_start_time = SystemTime.unpack_from(buffer, 40) last_object_time = SystemTime.unpack_from(buffer, 56) return cls( signature, statistics_size, api_number, AppId.from_int(application_id), Compression.from_int(compression_level), application_major, application_minor, file_size, uncompressed_file_size, object_count, application_build, measurement_start_time, last_object_time, restore_points_offset, reserved, ) def pack(self) -> bytes: buffer = bytearray(self._FORMAT.size) self._FORMAT.pack_into( buffer, 0, self.signature, self.statistics_size, self.api_number, self.application_id, self.compression_level, self.application_major, self.application_minor, self.file_size, self.uncompressed_file_size, self.object_count, self.application_build, self.restore_points_offset, self.reserved, ) self.measurement_start_time.pack_into(buffer, 40) self.last_object_time.pack_into(buffer, 56) return bytes(buffer) @classmethod def new(cls) -> Self: major_version, minor_version, *_ = __version__.split(".") return cls( signature=FILE_SIGNATURE, statistics_size=FileStatistics.SIZE, api_number=0x3E4630, application_id=AppId.UNKNOWN, compression_level=Compression.DEFAULT, application_major=int(major_version), application_minor=int(minor_version), file_size=FileStatistics.SIZE, uncompressed_file_size=FileStatistics.SIZE, object_count=0, application_build=0, measurement_start_time=SystemTime.from_datetime(), last_object_time=SystemTime.from_datetime(), restore_points_offset=0, reserved=bytes(64), ) @dataclass class LogContainer(ObjectWithHeader[ObjectHeader]): header: ObjectHeader data: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) return cls(header, buffer[ObjectHeader.SIZE :]) def pack(self) -> bytes: return self.header.pack() + self.data @classmethod def new( cls, data: bytes, time_stamp: int, flags: ObjFlags = ObjFlags.TIME_ONE_NANS, client_index: int = 0, ) -> Self: base = ObjectHeaderBase( signature=OBJ_SIGNATURE, header_size=ObjectHeader.SIZE, header_version=1, object_size=ObjectHeader.SIZE + len(data), object_type=ObjType.LOG_CONTAINER, ) header = ObjectHeader( base=base, object_flags=flags, client_index=client_index, object_version=0, object_time_stamp=time_stamp, ) return cls( header=header, data=data, ) @dataclass class AppText(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IIII") header: ObjectHeader source: AppTextSource reserved1: int text_length: int reserved2: int text: str @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( source, reserved1, text_length, reserved2, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) text_offset = ObjectHeader.SIZE + cls._FORMAT.size text = buffer[text_offset : text_offset + text_length - 1].decode("cp1252") return cls( header, AppTextSource(source), reserved1, text_length, reserved2, text, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) self.header.pack_into(buffer, 0) self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.source, self.reserved1, self.text_length, self.reserved2, ) encoded_text = self.text.encode("cp1252") + b"\x00" text_offset = ObjectHeader.SIZE + self._FORMAT.size buffer[text_offset : text_offset + self.text_length] = encoded_text return bytes(buffer) @dataclass class AppTrigger(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("QQHHI") header: ObjectHeader pre_trigger_time: int post_trigger_time: int channel: int flags: TriggerFlag app_specific: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) ( pre_trigger_time, post_trigger_time, channel, flags, app_specific, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, pre_trigger_time, post_trigger_time, channel, TriggerFlag(flags), app_specific, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.pre_trigger_time, self.post_trigger_time, self.channel, self.flags, self.app_specific, ) @dataclass class EnvironmentVariable(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IIQ") header: ObjectHeader name_length: int data_length: int reserved: int name: str data: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) (name_length, data_length, reserved) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) # get name name_offset = ObjectHeader.SIZE + cls._FORMAT.size name = buffer[name_offset : name_offset + name_length].decode("cp1252") # get data data_offset = name_offset + name_length data = buffer[data_offset : data_offset + data_length] return cls( header, name_length, data_length, reserved, name, data, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) # write header self.header.pack_into(buffer, 0) # write fixed size values self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.name_length, self.data_length, self.reserved, ) # write name name_offset = ObjectHeader.SIZE + self._FORMAT.size buffer[name_offset : name_offset + self.name_length] = self.name.encode("cp1252") # write data data_offset = name_offset + self.name_length buffer[data_offset : data_offset + self.data_length] = self.data return bytes(buffer) @dataclass class SystemVariable(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IIQIIQ") header: ObjectHeader type: SysVarType representation: int reserved1: int name_length: int data_length: int reserved2: int name: str data: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) ( type_, representation, reserved1, name_length, data_length, reserved2, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) # get name name_offset = ObjectHeader.SIZE + cls._FORMAT.size name = buffer[name_offset : name_offset + name_length].decode("cp1252") # get data data_offset = name_offset + name_length data = buffer[data_offset : data_offset + data_length] return cls( header, SysVarType(type_), representation, reserved1, name_length, data_length, reserved2, name, data, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) # write header self.header.pack_into(buffer, 0) # write fixed size values self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.type, self.representation, self.reserved1, self.name_length, self.data_length, self.reserved2, ) # write name name_offset = ObjectHeader.SIZE + self._FORMAT.size buffer[name_offset : name_offset + self.name_length] = self.name.encode("cp1252") # write data data_offset = name_offset + self.name_length buffer[data_offset : data_offset + self.data_length] = self.data return bytes(buffer) @dataclass class RealTimeClock(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("QQ") header: ObjectHeader time: int logging_offset: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) time, logging_offset = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls(header, time, logging_offset) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack(self.time, self.logging_offset) @dataclass class DriverOverrun(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IHH") header: ObjectHeader bus_type: BusType channel: int reserved: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) ( bus_type, channel, reserved, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, BusType(bus_type), channel, reserved, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.bus_type, self.channel, self.reserved, ) @dataclass class EventComment(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IIQ") header: ObjectHeader commented_event_type: int text_length: int reserved: int text: str @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( commented_event_type, text_length, reserved, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) text_offset = ObjectHeader.SIZE + cls._FORMAT.size text = buffer[text_offset : text_offset + text_length].decode("cp1252") return cls( header, commented_event_type, text_length, reserved, text, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) self.header.pack_into(buffer, 0) self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.commented_event_type, self.text_length, self.reserved, ) encoded_text = self.text.encode("cp1252") text_offset = ObjectHeader.SIZE + self._FORMAT.size buffer[text_offset : text_offset + self.text_length] = encoded_text return bytes(buffer) @dataclass class GlobalMarker(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IIIBBHIIIIQ") header: ObjectHeader commented_event_type: int foreground_color: int background_color: int is_relocatable: int reserved1: int reserved2: int group_name_length: int marker_name_length: int description_length: int reserved3: int reserved4: int group_name: str marker_name: str description: str @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) ( commented_event_type, foreground_color, background_color, is_relocatable, reserved1, reserved2, group_name_length, marker_name_length, description_length, reserved3, reserved4, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) # get group_name group_name_offset = ObjectHeader.SIZE + cls._FORMAT.size _group_name = buffer[group_name_offset : group_name_offset + group_name_length] group_name = _group_name.decode("cp1252") # get marker_name marker_name_offset = group_name_offset + group_name_length _marker_name = buffer[marker_name_offset : marker_name_offset + marker_name_length] marker_name = _marker_name.decode("cp1252") # get marker_name description_offset = marker_name_offset + marker_name_length _description = buffer[description_offset : description_offset + description_length] description = _description.decode("cp1252") return cls( header, commented_event_type, foreground_color, background_color, is_relocatable, reserved1, reserved2, group_name_length, marker_name_length, description_length, reserved3, reserved4, group_name, marker_name, description, ) def pack(self) -> bytes: return ( self.header.pack() + self._FORMAT.pack( self.commented_event_type, self.foreground_color, self.background_color, self.is_relocatable, self.reserved1, self.reserved2, self.group_name_length, self.marker_name_length, self.description_length, self.reserved3, self.reserved4, ) + self.group_name.encode("cp1252") + self.marker_name.encode("cp1252") + self.description.encode("cp1252") ) @dataclass class FunctionBus(ObjectWithHeader[VarObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IIII") header: VarObjectHeader object_type: FunctionBusType ve_type: int name_length: int data_length: int name: str data: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = VarObjectHeader.unpack_from(buffer, 0) ( object_type, ve_type, name_length, data_length, ) = cls._FORMAT.unpack_from(buffer, VarObjectHeader.SIZE) # get name name_offset = ObjectHeader.SIZE + cls._FORMAT.size _name = buffer[name_offset : name_offset + name_length] name = _name.decode("cp1252") # get data data_offset = name_offset + name_length data = buffer[data_offset : data_offset + data_length] return cls( header, FunctionBusType(object_type), ve_type, name_length, data_length, name, data, ) def pack(self) -> bytes: return ( self.header.pack() + self._FORMAT.pack( self.object_type, self.ve_type, self.name_length, self.data_length, ) + self.name.encode("cp1252") + self.data ) @dataclass class TriggerCondition(ObjectWithHeader[VarObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("III") header: VarObjectHeader state: TriggerConditionStatus trigger_block_name_length: int trigger_condition_length: int trigger_block_name: str trigger_condition: str @classmethod def unpack(cls, buffer: bytes) -> Self: header = VarObjectHeader.unpack_from(buffer, 0) ( state, trigger_block_name_length, trigger_condition_length, ) = cls._FORMAT.unpack_from(buffer, VarObjectHeader.SIZE) # get trigger_block_name trigger_block_name_offset = ObjectHeader.SIZE + cls._FORMAT.size _trigger_block_name = buffer[ trigger_block_name_offset : trigger_block_name_offset + trigger_block_name_length ] trigger_block_name = _trigger_block_name.decode("cp1252") # get trigger_condition trigger_condition_offset = trigger_block_name_offset + trigger_block_name_length _trigger_condition = buffer[ trigger_condition_offset : trigger_condition_offset + trigger_condition_length ] trigger_condition = _trigger_condition.decode("cp1252") return cls( header, TriggerConditionStatus(state), trigger_block_name_length, trigger_condition_length, trigger_block_name, trigger_condition, ) def pack(self) -> bytes: return ( self.header.pack() + self._FORMAT.pack( self.state, self.trigger_block_name_length, self.trigger_condition_length, ) + self.trigger_block_name.encode("cp1252") + self.trigger_condition.encode("cp1252") ) vblf-0.3.0/src/vblf/lin.py000066400000000000000000000213071520700434100153160ustar00rootroot00000000000000import struct from dataclasses import dataclass from typing import ClassVar from typing_extensions import Self from vblf.general import ObjectHeader, ObjectWithHeader @dataclass class LinMessage(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("HBB8sBBBBHB5s") header: ObjectHeader channel: int id: int dlc: int data: bytes fsm_id: int fsm_state: int header_time: int full_time: int crc: int dir: int reserved: bytes @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) ( channel, lin_id, dlc, data_, fsm_id, fsm_state, header_time, full_time, crc, direction, reserved, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) return cls( header, channel, lin_id, dlc, data_, fsm_id, fsm_state, header_time, full_time, crc, direction, reserved, ) def pack(self) -> bytes: return self.header.pack() + self._FORMAT.pack( self.channel, self.id, self.dlc, self.data, self.fsm_id, self.fsm_state, self.header_time, self.full_time, self.crc, self.dir, self.reserved, ) @dataclass class LinBusEvent: _FORMAT: ClassVar[struct.Struct] = struct.Struct("QIH2s") SIZE: ClassVar[int] = _FORMAT.size sof: int event_baudrate: int channel: int reserved: bytes @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: ( sof, event_baudrate, channel, reserved, ) = cls._FORMAT.unpack_from(buffer, offset) return cls( sof, event_baudrate, channel, reserved, ) def pack_into(self, buffer: bytearray, offset: int) -> None: self._FORMAT.pack_into( buffer, offset, self.sof, self.event_baudrate, self.channel, self.reserved ) @dataclass class LinSynchFieldEvent: _FORMAT: ClassVar[struct.Struct] = struct.Struct("QQ") SIZE: ClassVar[int] = LinBusEvent.SIZE + _FORMAT.size lin_bus_event: LinBusEvent synch_break_length: int synch_del_length: int @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: lin_bus_event = LinBusEvent.unpack_from(buffer, offset) ( synch_break_length, synch_del_length, ) = cls._FORMAT.unpack_from(buffer, offset + LinBusEvent.SIZE) return cls( lin_bus_event, synch_break_length, synch_del_length, ) def pack_into(self, buffer: bytearray, offset: int) -> None: self.lin_bus_event.pack_into(buffer, offset) self._FORMAT.pack_into( buffer, offset + LinBusEvent.SIZE, self.synch_break_length, self.synch_del_length ) @dataclass class LinMessageDescriptor: _FORMAT: ClassVar[struct.Struct] = struct.Struct("HHBBBB") SIZE: ClassVar[int] = LinSynchFieldEvent.SIZE + _FORMAT.size lin_synch_field_event: LinSynchFieldEvent supplier_id: int message_id: int nad: int id: int dlc: int checksum_model: int @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: lin_synch_field_event = LinSynchFieldEvent.unpack_from(buffer, offset) ( supplier_id, message_id, nad, lin_id, dlc, checksum_model, ) = cls._FORMAT.unpack_from(buffer, offset + LinSynchFieldEvent.SIZE) return cls( lin_synch_field_event, supplier_id, message_id, nad, lin_id, dlc, checksum_model, ) def pack_into(self, buffer: bytearray, offset: int) -> None: self.lin_synch_field_event.pack_into(buffer, offset) self._FORMAT.pack_into( buffer, offset + LinSynchFieldEvent.SIZE, self.supplier_id, self.message_id, self.nad, self.id, self.dlc, self.checksum_model, ) @dataclass class LinDatabyteTimestampEvent: _FORMAT: ClassVar[struct.Struct] = struct.Struct("9Q") SIZE: ClassVar[int] = LinMessageDescriptor.SIZE + _FORMAT.size lin_msg_descr_event: LinMessageDescriptor databyte_timestamps: tuple[int] @classmethod def unpack_from(cls, buffer: bytes, offset: int = 0) -> Self: lin_msg_descr_event = LinMessageDescriptor.unpack_from(buffer, offset) databyte_timestamps = cls._FORMAT.unpack_from(buffer, offset + LinMessageDescriptor.SIZE) return cls( lin_msg_descr_event, databyte_timestamps, ) def pack_into(self, buffer: bytearray, offset: int) -> None: self.lin_msg_descr_event.pack_into(buffer, offset) self._FORMAT.pack_into( buffer, offset + LinMessageDescriptor.SIZE, *self.databyte_timestamps ) @dataclass class LinMessage2(ObjectWithHeader[ObjectHeader]): _FORMAT_V1: ClassVar[struct.Struct] = struct.Struct("8sHBBBBBBB3s") _FORMAT_V2: ClassVar[struct.Struct] = struct.Struct("I") _FORMAT_V3: ClassVar[struct.Struct] = struct.Struct("dII") _V1_SIZE: ClassVar[int] = ObjectHeader.SIZE + LinDatabyteTimestampEvent.SIZE + _FORMAT_V1.size _V2_SIZE: ClassVar[int] = _V1_SIZE + _FORMAT_V2.size _V3_SIZE: ClassVar[int] = _V2_SIZE + _FORMAT_V3.size header: ObjectHeader # V1 lin_timestamp_event: LinDatabyteTimestampEvent data: bytes crc: int direction: int simulated: int is_etf: int etf_assoc_index: int etf_assoc_etf_id: int fsm_id: int fsm_state: int reserved: bytes # V2 resp_baudrate: int # V3 exact_header_baudrate: float early_stopbit_offset: int early_stopbit_offset_response: int @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer) lin_timestamp_event = LinDatabyteTimestampEvent.unpack_from(buffer, ObjectHeader.SIZE) ( data_, crc, direction, simulated, is_etf, etf_assoc_index, etf_assoc_etf_id, fsm_id, fsm_state, reserved, ) = cls._FORMAT_V1.unpack_from(buffer, ObjectHeader.SIZE + LinDatabyteTimestampEvent.SIZE) if header.base.object_size >= cls._V2_SIZE: (resp_baudrate,) = cls._FORMAT_V2.unpack_from(buffer, cls._V1_SIZE) else: resp_baudrate = 0 if header.base.object_size >= cls._V3_SIZE: ( exact_header_baudrate, early_stopbit_offset, early_stopbit_offset_response, ) = cls._FORMAT_V3.unpack_from(buffer, cls._V2_SIZE) else: exact_header_baudrate = 0 early_stopbit_offset = 0 early_stopbit_offset_response = 0 return cls( header, lin_timestamp_event, data_, crc, direction, simulated, is_etf, etf_assoc_index, etf_assoc_etf_id, fsm_id, fsm_state, reserved, resp_baudrate, exact_header_baudrate, early_stopbit_offset, early_stopbit_offset_response, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) self.header.pack_into(buffer, 0) self.lin_timestamp_event.pack_into(buffer, ObjectHeader.SIZE) self._FORMAT_V1.pack_into( buffer, ObjectHeader.SIZE + LinDatabyteTimestampEvent.SIZE, self.data, self.crc, self.direction, self.simulated, self.is_etf, self.etf_assoc_index, self.etf_assoc_etf_id, self.fsm_id, self.fsm_state, self.reserved, ) if self.header.base.object_size >= self._V2_SIZE: self._FORMAT_V2.pack_into(buffer, self._V1_SIZE, self.resp_baudrate) if self.header.base.object_size >= self._V3_SIZE: self._FORMAT_V3.pack_into( buffer, self._V2_SIZE, self.exact_header_baudrate, self.early_stopbit_offset, self.early_stopbit_offset_response, ) return bytes(buffer) vblf-0.3.0/src/vblf/most.py000066400000000000000000000000001520700434100155010ustar00rootroot00000000000000vblf-0.3.0/src/vblf/py.typed000066400000000000000000000000001520700434100156440ustar00rootroot00000000000000vblf-0.3.0/src/vblf/reader.py000066400000000000000000000253071520700434100160020ustar00rootroot00000000000000import logging import os import zlib from collections.abc import Iterator from contextlib import AbstractContextManager from io import BytesIO from types import TracebackType from typing import Any, BinaryIO, Final, Optional, Union from vblf.can import ( CanDriverError, CanDriverErrorExt, CanDriverHwSync, CanDriverStatistic, CanErrorFrame, CanErrorFrameExt, CanFdErrorFrame64, CanFdMessage, CanFdMessage64, CanMessage, CanMessage2, CanOverloadFrame, ) from vblf.constants import FILE_SIGNATURE, OBJ_SIGNATURE, OBJ_SIGNATURE_SIZE, ObjType from vblf.ethernet import EthernetFrameEx, EthernetStatistic from vblf.flexray import FlexrayVFrReceiveMsgEx from vblf.general import ( AppText, AppTrigger, DriverOverrun, EnvironmentVariable, EventComment, FileStatistics, FunctionBus, GlobalMarker, LogContainer, NotImplementedObject, ObjectHeaderBase, ObjectWithHeader, RealTimeClock, SystemVariable, TriggerCondition, ) from vblf.lin import LinMessage, LinMessage2 from vblf.tp_diag import DiagRequestInterpretation LOG = logging.getLogger("vblf") class BlfReader(AbstractContextManager["BlfReader"]): """Binary Log Format (BLF) file reader. Reads Vector BLF log files and provides an iterator interface to access the contained objects. Handles automatic decompression of log containers. :param file: Path to BLF file or file-like object :raises TypeError: If file parameter is of unsupported type :raises ValueError: If file format is invalid :ivar file_statistics: Statistics about the BLF file :type file_statistics: FileStatistics """ def __init__(self, file: Union[str, bytes, os.PathLike[Any], BinaryIO]): """Initialize BLF reader. See class documentation for details. """ self._file: BinaryIO if isinstance(file, (str, bytes, os.PathLike)): self._file = open(file, "rb") # noqa: SIM115 elif isinstance(file, bytes): self._file = BytesIO(file) elif hasattr(file, "read"): self._file = file else: err_msg = "Unsupported type {type(file)}" raise TypeError(err_msg) obj_data = self._file.read(FileStatistics.SIZE) if len(obj_data) < FileStatistics.SIZE or not obj_data.startswith(FILE_SIGNATURE): err_msg = "Unexpected file format" raise ValueError(err_msg) self.file_statistics = FileStatistics.unpack(obj_data) self._incomplete_data: bytes = b"" self._generator = self._generate_objects(self._file) def _generate_objects(self, stream: BinaryIO) -> Iterator[ObjectWithHeader[Any]]: """Generate objects from the BLF stream. :param stream: Binary stream containing BLF data :returns: Iterator yielding parsed BLF objects """ while True: # find start of next object (search for b"LOBJ") signature = stream.read(OBJ_SIGNATURE_SIZE) if len(signature) != OBJ_SIGNATURE_SIZE: self._incomplete_data = signature break if signature != OBJ_SIGNATURE: # skip padding byte and try again stream.seek(1 - OBJ_SIGNATURE_SIZE, os.SEEK_CUR) continue # parse base header of object header_base_data = signature + stream.read(ObjectHeaderBase.SIZE - OBJ_SIGNATURE_SIZE) if len(header_base_data) < ObjectHeaderBase.SIZE: self._incomplete_data = header_base_data break else: header_base = ObjectHeaderBase.unpack(header_base_data) # read object data obj_data = header_base_data + stream.read( header_base.object_size - ObjectHeaderBase.SIZE ) if len(obj_data) < header_base.object_size: self._incomplete_data = obj_data break # find class for given object_type obj_class: type[ObjectWithHeader[Any]] = ( OBJ_MAP.get(header_base.object_type) or NotImplementedObject ) if obj_class is LogContainer: # decompress data container = LogContainer.unpack(obj_data) uncompressed = ( zlib.decompress(container.data) if self.file_statistics.compression_level > 0 else container.data ) # prepend incomplete data of previous container uncompressed = self._incomplete_data + uncompressed self._incomplete_data = b"" # parse LogContainer data yield from self._generate_objects(BytesIO(uncompressed)) else: yield obj_class.unpack(obj_data) def read_object(self) -> Optional[ObjectWithHeader[Any]]: """Retrieve the next parsed object from the BLF file. This method fetches the next object from the underlying generator that parses the BLF file. If there are no more objects to read, it returns `None`. :returns: The next parsed BLF object or `None` if the end of the file is reached. """ return next(self._generator, None) def __iter__(self) -> Iterator[ObjectWithHeader[Any]]: """Iterate over objects in the BLF file. :returns: Iterator yielding parsed BLF objects """ return self._generator.__iter__() def __enter__(self) -> "BlfReader": """Enter context manager. :returns: BlfReader instance """ return self def __exit__( self, exc_type: Optional[type[BaseException]], exc_value: Optional[BaseException], traceback: Optional[TracebackType], ) -> None: """Exit context manager and close file. :param exc_type: Exception type if an exception occurred :param exc_value: Exception instance if an exception occurred :param traceback: Traceback if an exception occurred """ self._file.close() OBJ_MAP: Final[dict[ObjType, Optional[type[ObjectWithHeader[Any]]]]] = { ObjType.UNKNOWN: None, ObjType.CAN_MESSAGE: CanMessage, ObjType.CAN_ERROR: CanErrorFrame, ObjType.CAN_OVERLOAD: CanOverloadFrame, ObjType.CAN_STATISTIC: CanDriverStatistic, ObjType.APP_TRIGGER: AppTrigger, ObjType.ENV_INTEGER: EnvironmentVariable, ObjType.ENV_DOUBLE: EnvironmentVariable, ObjType.ENV_STRING: EnvironmentVariable, ObjType.ENV_DATA: EnvironmentVariable, ObjType.LOG_CONTAINER: LogContainer, ObjType.LIN_MESSAGE: LinMessage, ObjType.LIN_CRC_ERROR: None, ObjType.LIN_DLC_INFO: None, ObjType.LIN_RCV_ERROR: None, ObjType.LIN_SND_ERROR: None, ObjType.LIN_SLV_TIMEOUT: None, ObjType.LIN_SCHED_MODCH: None, ObjType.LIN_SYN_ERROR: None, ObjType.LIN_BAUDRATE: None, ObjType.LIN_SLEEP: None, ObjType.LIN_WAKEUP: None, ObjType.MOST_SPY: None, ObjType.MOST_CTRL: None, ObjType.MOST_LIGHTLOCK: None, ObjType.MOST_STATISTIC: None, ObjType.reserved_1: None, ObjType.reserved_2: None, ObjType.reserved_3: None, ObjType.FLEXRAY_DATA: None, ObjType.FLEXRAY_SYNC: None, ObjType.CAN_DRIVER_ERROR: CanDriverError, ObjType.MOST_PKT: None, ObjType.MOST_PKT2: None, ObjType.MOST_HWMODE: None, ObjType.MOST_REG: None, ObjType.MOST_GENREG: None, ObjType.MOST_NETSTATE: None, ObjType.MOST_DATALOST: None, ObjType.MOST_TRIGGER: None, ObjType.FLEXRAY_CYCLE: None, ObjType.FLEXRAY_MESSAGE: None, ObjType.LIN_CHECKSUM_INFO: None, ObjType.LIN_SPIKE_EVENT: None, ObjType.CAN_DRIVER_SYNC: CanDriverHwSync, ObjType.FLEXRAY_STATUS: None, ObjType.GPS_EVENT: None, ObjType.FR_ERROR: None, ObjType.FR_STATUS: None, ObjType.FR_STARTCYCLE: None, ObjType.FR_RCVMESSAGE: None, ObjType.REALTIMECLOCK: RealTimeClock, ObjType.AVAILABLE2: None, ObjType.AVAILABLE3: None, ObjType.LIN_STATISTIC: None, ObjType.J1708_MESSAGE: None, ObjType.J1708_VIRTUAL_MSG: None, ObjType.LIN_MESSAGE2: LinMessage2, ObjType.LIN_SND_ERROR2: None, ObjType.LIN_SYN_ERROR2: None, ObjType.LIN_CRC_ERROR2: None, ObjType.LIN_RCV_ERROR2: None, ObjType.LIN_WAKEUP2: None, ObjType.LIN_SPIKE_EVENT2: None, ObjType.LIN_LONG_DOM_SIG: None, ObjType.APP_TEXT: AppText, ObjType.FR_RCVMESSAGE_EX: FlexrayVFrReceiveMsgEx, ObjType.MOST_STATISTICEX: None, ObjType.MOST_TXLIGHT: None, ObjType.MOST_ALLOCTAB: None, ObjType.MOST_STRESS: None, ObjType.ETHERNET_FRAME: None, ObjType.SYS_VARIABLE: SystemVariable, ObjType.CAN_ERROR_EXT: CanErrorFrameExt, ObjType.CAN_DRIVER_ERROR_EXT: CanDriverErrorExt, ObjType.LIN_LONG_DOM_SIG2: None, ObjType.MOST_150_MESSAGE: None, ObjType.MOST_150_PKT: None, ObjType.MOST_ETHERNET_PKT: None, ObjType.MOST_150_MESSAGE_FRAGMENT: None, ObjType.MOST_150_PKT_FRAGMENT: None, ObjType.MOST_ETHERNET_PKT_FRAGMENT: None, ObjType.MOST_SYSTEM_EVENT: None, ObjType.MOST_150_ALLOCTAB: None, ObjType.MOST_50_MESSAGE: None, ObjType.MOST_50_PKT: None, ObjType.CAN_MESSAGE2: CanMessage2, ObjType.LIN_UNEXPECTED_WAKEUP: None, ObjType.LIN_SHORT_OR_SLOW_RESPONSE: None, ObjType.LIN_DISTURBANCE_EVENT: None, ObjType.SERIAL_EVENT: None, ObjType.OVERRUN_ERROR: DriverOverrun, ObjType.EVENT_COMMENT: EventComment, ObjType.WLAN_FRAME: None, ObjType.WLAN_STATISTIC: None, ObjType.MOST_ECL: None, ObjType.GLOBAL_MARKER: GlobalMarker, ObjType.AFDX_FRAME: None, ObjType.AFDX_STATISTIC: None, ObjType.KLINE_STATUSEVENT: None, ObjType.CAN_FD_MESSAGE: CanFdMessage, ObjType.CAN_FD_MESSAGE_64: CanFdMessage64, ObjType.ETHERNET_RX_ERROR: None, ObjType.ETHERNET_STATUS: None, ObjType.CAN_FD_ERROR_64: CanFdErrorFrame64, ObjType.LIN_SHORT_OR_SLOW_RESPONSE2: None, ObjType.AFDX_STATUS: None, ObjType.AFDX_BUS_STATISTIC: None, ObjType.reserved_4: None, ObjType.AFDX_ERROR_EVENT: None, ObjType.A429_ERROR: None, ObjType.A429_STATUS: None, ObjType.A429_BUS_STATISTIC: None, ObjType.A429_MESSAGE: None, ObjType.ETHERNET_STATISTIC: EthernetStatistic, ObjType.reserved_5: None, ObjType.reserved_6: None, ObjType.reserved_7: None, ObjType.TEST_STRUCTURE: None, ObjType.DIAG_REQUEST_INTERPRETATION: DiagRequestInterpretation, ObjType.ETHERNET_FRAME_EX: EthernetFrameEx, ObjType.ETHERNET_FRAME_FORWARDED: None, ObjType.ETHERNET_ERROR_EX: None, ObjType.ETHERNET_ERROR_FORWARDED: None, ObjType.FUNCTION_BUS: FunctionBus, ObjType.DATA_LOST_BEGIN: None, ObjType.DATA_LOST_END: None, ObjType.WATER_MARK_EVENT: None, ObjType.TRIGGER_CONDITION: TriggerCondition, } vblf-0.3.0/src/vblf/tp_diag.py000066400000000000000000000062311520700434100161420ustar00rootroot00000000000000import struct from dataclasses import dataclass from typing import ClassVar from typing_extensions import Self from vblf.general import ObjectHeader, ObjectWithHeader @dataclass class DiagRequestInterpretation(ObjectWithHeader[ObjectHeader]): _FORMAT: ClassVar[struct.Struct] = struct.Struct("IIIIII") diag_description_handle: int diag_variant_handle: int diag_service_handle: int ecu_qualifier_length: int variant_qualifier_length: int service_qualifier_length: int ecu_qualifier: str variant_qualifier: str service_qualifier: str @classmethod def unpack(cls, buffer: bytes) -> Self: header = ObjectHeader.unpack_from(buffer, 0) ( diag_description_handle, diag_variant_handle, diag_service_handle, ecu_qualifier_length, variant_qualifier_length, service_qualifier_length, ) = cls._FORMAT.unpack_from(buffer, ObjectHeader.SIZE) ecu_qualifier_offset = ObjectHeader.SIZE + cls._FORMAT.size variant_qualifier_offset = ecu_qualifier_offset + ecu_qualifier_length service_qualifier_offset = variant_qualifier_offset + variant_qualifier_length ecu_qualifier = buffer[ ecu_qualifier_offset : ecu_qualifier_offset + ecu_qualifier_length ].decode("utf-8") variant_qualifier = buffer[ variant_qualifier_offset : variant_qualifier_offset + variant_qualifier_length ].decode("utf-8") service_qualifier = buffer[ service_qualifier_offset : service_qualifier_offset + service_qualifier_length ].decode("utf-8") return cls( header, diag_description_handle, diag_variant_handle, diag_service_handle, ecu_qualifier_length, variant_qualifier_length, service_qualifier_length, ecu_qualifier, variant_qualifier, service_qualifier, ) def pack(self) -> bytes: buffer = bytearray(self.header.base.object_size) self.header.pack_into(buffer, 0) self._FORMAT.pack_into( buffer, ObjectHeader.SIZE, self.diag_description_handle, self.diag_variant_handle, self.diag_service_handle, self.ecu_qualifier_length, self.variant_qualifier_length, self.service_qualifier_length, ) ecu_qualifier_offset = ObjectHeader.SIZE + self._FORMAT.size variant_qualifier_offset = ecu_qualifier_offset + self.ecu_qualifier_length service_qualifier_offset = variant_qualifier_offset + self.variant_qualifier_length buffer[ecu_qualifier_offset : ecu_qualifier_offset + self.ecu_qualifier_length] = ( self.ecu_qualifier.encode("utf-8") ) buffer[ variant_qualifier_offset : variant_qualifier_offset + self.variant_qualifier_length ] = self.variant_qualifier.encode("utf-8") buffer[ service_qualifier_offset : service_qualifier_offset + self.service_qualifier_length ] = self.service_qualifier.encode("utf-8") return bytes(buffer) vblf-0.3.0/src/vblf/writer.py000066400000000000000000000121761520700434100160540ustar00rootroot00000000000000import datetime import os import time import zlib from contextlib import AbstractContextManager from typing import Any, BinaryIO, Final from vblf.constants import Compression, ObjFlags from vblf.general import FileStatistics, HeaderWithBase, LogContainer, ObjectWithHeader, SystemTime BYTE_ALIGNMENT: Final = 8 class BlfWriter(AbstractContextManager["BlfWriter"]): """Binary Log Format (BLF) file writer. Writes Vector BLF log files with optional compression. Handles automatic buffering and container creation for optimal file structure. :param file: Path to BLF file or file-like object :param compression_level: Compression level (0-9), defaults to no compression :param buffer_size: Size of internal buffer in bytes before flushing, defaults to 128 KiB :raises TypeError: If file parameter is of unsupported type """ def __init__( self, file: os.PathLike[Any], compression_level: Compression = Compression.NONE, buffer_size: int = 128 * 1024, ) -> None: """Initialize BLF writer. See class documentation for details. """ self._buffer_size = buffer_size self._buffer = bytearray() self._measurement_start_time = time.time() self._time_of_last_object = self._measurement_start_time self._file: BinaryIO if isinstance(file, (str, bytes, os.PathLike)): self._file = open(file, "wb") # noqa: SIM115 elif hasattr(file, "write"): self._file = file else: err_msg = f"Unsupported type {type(file)}" raise TypeError(err_msg) # write file statistics self._file_statistics = FileStatistics.new() self._file_statistics.compression_level = compression_level self._file.write(self._file_statistics.pack()) def write(self, obj: ObjectWithHeader[HeaderWithBase]) -> None: """Write an object to the BLF file. The object is first buffered and only written to disk when the buffer is full or when the file is closed. :param obj: Object to write :raises ValueError: If object size doesn't match its header """ # byte alignment if rest := len(self._buffer) % BYTE_ALIGNMENT: self._buffer.extend(b"\x00" * (BYTE_ALIGNMENT - rest)) obj_data = obj.pack() if len(obj_data) != obj.header.base.object_size: err_msg = f"Object size mismatch: {len(obj_data)} != {obj.header.base.object_size}" raise ValueError(err_msg) self._buffer.extend(obj_data) self._file_statistics.object_count += 1 self._file_statistics.uncompressed_file_size += len(obj_data) self._time_of_last_object = time.time() if len(self._buffer) >= self._buffer_size: self._flush_container() def _flush_container(self) -> None: """Flush the internal buffer to disk. Creates a LogContainer with the buffered data and writes it to the file. Handles compression if enabled. """ if not self._buffer: return # byte alignment if rest := self._file.tell() % BYTE_ALIGNMENT: self._file.write(b"\x00" * (BYTE_ALIGNMENT - rest)) buffer, self._buffer = self._buffer[: self._buffer_size], self._buffer[self._buffer_size :] if self._file_statistics.compression_level > Compression.NONE: compressed_data = zlib.compress(buffer, level=self._file_statistics.compression_level) else: compressed_data = bytes(buffer) log_container = LogContainer.new( data=compressed_data, time_stamp=round((time.time() - self._measurement_start_time) * 1e9), flags=ObjFlags.TIME_ONE_NANS, ) self._file.write(log_container.pack()) self._file_statistics.file_size = self._file.tell() def _update_file_statistics(self) -> None: """Update file statistics and write them to the beginning of the file. Updates the object count, file size and timestamps in the file header. """ self._file_statistics.last_object_time = SystemTime.from_datetime( datetime.datetime.fromtimestamp(self._time_of_last_object, datetime.timezone.utc) ) self._file.seek(0) self._file.write(self._file_statistics.pack()) def close(self) -> None: """Close the BLF file. Flushes any remaining buffered data and updates file statistics before closing. """ if not self._file.closed: while self._buffer: self._flush_container() self._update_file_statistics() self._file.close() def __enter__(self) -> "BlfWriter": """Enter context manager. :returns: BlfWriter instance """ return self def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: """Exit context manager and close file. :param exc_type: Exception type if an exception occurred :param exc_value: Exception instance if an exception occurred :param traceback: Traceback if an exception occurred """ self.close() vblf-0.3.0/tests/000077500000000000000000000000001520700434100136015ustar00rootroot00000000000000vblf-0.3.0/tests/__init__.py000066400000000000000000000001041520700434100157050ustar00rootroot00000000000000from pathlib import Path DATA_DIR = Path(__file__).parent / "data" vblf-0.3.0/tests/data/000077500000000000000000000000001520700434100145125ustar00rootroot00000000000000vblf-0.3.0/tests/data/A429_BUS_STATISTIC.lobj000066400000000000000000000011101520700434100201320ustar00rootroot00000000000000LOBJ Hp"""""""""3333DDDDUUUUffffwwˆˆ™™ªª»»ÌÌÝÝîîÿÿ  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿvblf-0.3.0/tests/data/A429_ERROR.lobj000066400000000000000000000020601520700434100167500ustar00rootroot00000000000000LOBJ 0n""""""""""3333DDDDxyzxyzvblf-0.3.0/tests/data/A429_MESSAGE.lobj000066400000000000000000000001301520700434100171370ustar00rootroot00000000000000LOBJ Xq"""""""""3DUUfwˆˆˆˆ™™™yªª»»»»»»»»ÌÌÌÌÝÝîîîîÿÿÿÿvblf-0.3.0/tests/data/A429_STATUS.lobj000066400000000000000000000000701520700434100171010ustar00rootroot00000000000000LOBJ 8o"""""""""33DDDDUUUUffffwwwwvblf-0.3.0/tests/data/AFDX_BUS_STATISTIC.lobj000066400000000000000000000001401520700434100202370ustar00rootroot00000000000000LOBJ `k""""""""""3333DDDDUUUUffffwwwwˆˆˆˆ™™™™ªªªª»»»»ÌÌÌÌÝÝÝÝîîîîÿ""33vblf-0.3.0/tests/data/AFDX_ERROR_EVENT.lobj000066400000000000000000000020501520700434100200130ustar00rootroot00000000000000LOBJ (m""""""""""3333xyzxyzvblf-0.3.0/tests/data/AFDX_FRAME.lobj000066400000000000000000000001131520700434100170110ustar00rootroot00000000000000LOBJ Ka"""""""""3DUfwwˆ™ª»ÌÝîîÿÿ"33DDDDvblf-0.3.0/tests/data/AFDX_STATISTIC.lobj000066400000000000000000000001301520700434100175250ustar00rootroot00000000000000LOBJ Xb""""""""""3333DDDDUUUUffffwwwwˆˆˆˆ™™™™ªªªª»»»»ÌÌÌÌÝÝÝÝîîîîÿÿÿÿvblf-0.3.0/tests/data/AFDX_STATUS.lobj000066400000000000000000000001101520700434100171770ustar00rootroot00000000000000LOBJ Hj"""""""""3DUfwˆ™ªªªª"3DUfwˆ™ªªªªvblf-0.3.0/tests/data/APP_TEXT.lobj000066400000000000000000000001411520700434100166420ustar00rootroot00000000000000LOBJ aA1C:\Users\user\Desktop\project car\myDatabase.dbcvblf-0.3.0/tests/data/APP_TRIGGER.lobj000066400000000000000000000000701520700434100171620ustar00rootroot00000000000000LOBJ 8""""""""""""""""33DDDDvblf-0.3.0/tests/data/CAN_DRIVER_ERROR.lobj000066400000000000000000000000501520700434100200020ustar00rootroot00000000000000LOBJ (ºöhvblf-0.3.0/tests/data/CAN_DRIVER_ERROR_EXT.lobj000066400000000000000000000001001520700434100205160ustar00rootroot00000000000000LOBJ @J"""""""""3DDDDUUUUfwˆˆ™™™™ªªªª»»»»ÌÌÌÌvblf-0.3.0/tests/data/CAN_DRIVER_SYNC.lobj000066400000000000000000000000501520700434100176650ustar00rootroot00000000000000LOBJ (,"""""""""3vblf-0.3.0/tests/data/CAN_ERROR.lobj000066400000000000000000000000501520700434100167270ustar00rootroot00000000000000LOBJ (""""""""""vblf-0.3.0/tests/data/CAN_ERROR_EXT.lobj000066400000000000000000000001001520700434100174430ustar00rootroot00000000000000LOBJ @I""""""""""3333DUfwˆˆˆˆ™™™™ªª»»ÌÝîÿ"3Dvblf-0.3.0/tests/data/CAN_FD_ERROR_64.lobj000066400000000000000000000002301520700434100176110ustar00rootroot00000000000000LOBJ ˜h"""""""""@DUUffwwŒ™ªªªª»»»»ÌÌÌÌÝÝÝÝîîîîÿÿÿÿ""33  !"#$%&'()*+,-./0123456789:;<=>?""""vblf-0.3.0/tests/data/CAN_FD_MESSAGE.lobj000066400000000000000000000001701520700434100174760ustar00rootroot00000000000000LOBJ xd"""""""""3DDDDUUUUfw@™ªªªª  !"#$%&'()*+,-./0123456789:;<=>?vblf-0.3.0/tests/data/CAN_FD_MESSAGE_64.lobj000066400000000000000000000001301520700434100200030ustar00rootroot00000000000000LOBJ Xe³¨.—00PPFP(Kÿ þ@†PEF€¸Ú€ÿ6  vblf-0.3.0/tests/data/CAN_MESSAGE.lobj000066400000000000000000000000601520700434100171230ustar00rootroot00000000000000LOBJ 0"""""""""3DDDDUfwˆ™ª»Ìvblf-0.3.0/tests/data/CAN_MESSAGE2.lobj000066400000000000000000000000701520700434100172060ustar00rootroot00000000000000LOBJ 8V"""""""""3DDDDUfwˆ™ª»ÌÝÝÝÝîÿvblf-0.3.0/tests/data/CAN_OVERLOAD.lobj000066400000000000000000000000501520700434100172510ustar00rootroot00000000000000LOBJ (""""""""""vblf-0.3.0/tests/data/CAN_STATISTIC.lobj000066400000000000000000000001001520700434100174010ustar00rootroot00000000000000LOBJ @ê—…<Ö -]vblf-0.3.0/tests/data/DIAG_REQUEST_INTERPRETATION.lobj000066400000000000000000000001011520700434100215150ustar00rootroot00000000000000LOBJ Aw""""""""""""3333xyzxyzxyzvblf-0.3.0/tests/data/ENV_DATA.lobj000066400000000000000000000000661520700434100166050ustar00rootroot00000000000000LOBJ 6 """"""""xyzvblf-0.3.0/tests/data/ENV_DOUBLE.lobj000066400000000000000000000000731520700434100170440ustar00rootroot00000000000000LOBJ ;""""""""xyz@vblf-0.3.0/tests/data/ENV_INTEGER.lobj000066400000000000000000000000671520700434100171720ustar00rootroot00000000000000LOBJ 7""""""""xyzvblf-0.3.0/tests/data/ENV_STRING.lobj000066400000000000000000000000661520700434100171020ustar00rootroot00000000000000LOBJ 6""""""""xyzxyzvblf-0.3.0/tests/data/ETHERNET_ERROR_EX.lobj000066400000000000000000000001031520700434100201370ustar00rootroot00000000000000LOBJ Cz""""""""""33DDDDDDDDUUUUffˆˆˆˆ™™™™ª»Ìvblf-0.3.0/tests/data/ETHERNET_ERROR_FORWARDED.lobj000066400000000000000000000001031520700434100211400ustar00rootroot00000000000000LOBJ C{""""""""""33DDDDDDDDUUUUffˆˆˆˆ™™™™ª»Ìvblf-0.3.0/tests/data/ETHERNET_FRAME.lobj000066400000000000000000000001031520700434100175040ustar00rootroot00000000000000LOBJ CG"""""""""3DUfwwˆ™ª»ÌÝîîÿÿ""vblf-0.3.0/tests/data/ETHERNET_FRAME_EX.lobj000066400000000000000000000001031520700434100201000ustar00rootroot00000000000000LOBJ Cx""""""""""33DDDDDDDDUUUUffˆˆˆˆ™™™™ª»Ìvblf-0.3.0/tests/data/ETHERNET_FRAME_FORWARDED.lobj000066400000000000000000000001031520700434100211010ustar00rootroot00000000000000LOBJ Cy""""""""""33DDDDDDDDUUUUffˆˆˆˆ™™™™ª»Ìvblf-0.3.0/tests/data/ETHERNET_RX_ERROR.lobj000066400000000000000000000000671520700434100201650ustar00rootroot00000000000000LOBJ 7f""""""""""33DDDDffwwwwˆ™ªvblf-0.3.0/tests/data/ETHERNET_STATISTIC.lobj000066400000000000000000000001501520700434100202230ustar00rootroot00000000000000LOBJ hr""""""""""""""""33333333DDDDDDDDUUUUUUUUffffffffwwwwwwwwˆˆˆˆˆˆˆˆ™yªªvblf-0.3.0/tests/data/ETHERNET_STATUS.lobj000066400000000000000000000000601520700434100176770ustar00rootroot00000000000000LOBJ 0g""""""""""3DUfwˆ™ª»»»»vblf-0.3.0/tests/data/EVENT_COMMENT.lobj000066400000000000000000000000631520700434100174240ustar00rootroot00000000000000LOBJ 3\""""""""xyzvblf-0.3.0/tests/data/FILE_STATISTICS.logg000066400000000000000000000002201520700434100176470ustar00rootroot00000000000000LOGG0F> xÜy·ÊWeè Rè 2Èz¯yvblf-0.3.0/tests/data/FLEXRAY_CYCLE.lobj000066400000000000000000000000701520700434100174100ustar00rootroot00000000000000LOBJ 8("""""""""3DDDDUUUUffffwwwwˆ™ªªvblf-0.3.0/tests/data/FLEXRAY_DATA.lobj000066400000000000000000000000701520700434100172620ustar00rootroot00000000000000LOBJ 8"""""""""3DDUUfwˆˆ vblf-0.3.0/tests/data/FLEXRAY_MESSAGE.lobj000066400000000000000000000002001520700434100176300ustar00rootroot00000000000000LOBJ €)"""""""""3DDDDUUUUffffwwwwˆˆ™™ªª»ÌÝîÿÿ  !"#$%&'()*+,-./0123456789:;<=>?vblf-0.3.0/tests/data/FLEXRAY_STATUS.lobj000066400000000000000000000001201520700434100175700ustar00rootroot00000000000000LOBJ P-""""""""""33DDUUff vblf-0.3.0/tests/data/FLEXRAY_SYNC.lobj000066400000000000000000000000701520700434100173250ustar00rootroot00000000000000LOBJ 8"""""""""3DDUUfwˆˆ ™vblf-0.3.0/tests/data/FR_ERROR.lobj000066400000000000000000000001101520700434100166320ustar00rootroot00000000000000LOBJ H/""""""""""33DUUUUffffwwwwˆˆˆˆ™™™™ªªªª»»»»ÌÌvblf-0.3.0/tests/data/FR_RCVMESSAGE.lobj000066400000000000000000000005201520700434100174050ustar00rootroot00000000000000LOBJ P2""""""""""33DUUUUffffwwˆˆ™™ªª»»ÌÝÝÝÝîîîîÿÿÿÿ  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüývblf-0.3.0/tests/data/FR_RCVMESSAGE_EX.lobj000066400000000000000000000005621520700434100200070ustar00rootroot00000000000000LOBJ rB""""""""""33DDUUUUffffwwˆˆ™™ªªþÌÌÝÝÝÝîîîîÿÿÿÿ""""3333DDUUffwwˆˆˆˆ™™™™ªªªª»»»»ÌÌÌÌÝÝÝÝ  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüývblf-0.3.0/tests/data/FR_STARTCYCLE.lobj000066400000000000000000000001401520700434100174210ustar00rootroot00000000000000LOBJ `1""""""""""33DUffffwwwwˆˆ ™™™™ªªªª»»»»ÌÌÌÌÝÝÝÝîîîîÿÿvblf-0.3.0/tests/data/FR_STATUS.lobj000066400000000000000000000001501520700434100167700ustar00rootroot00000000000000LOBJ h0""""""""""33DUUUUffffwwwwˆˆˆˆ™™™™ªªªª»»»» vblf-0.3.0/tests/data/FUNCTION_BUS.lobj000066400000000000000000000001321520700434100173140ustar00rootroot00000000000000LOBJ Z|"""""""functionBusObjectNamefunctionBusObjectDatavblf-0.3.0/tests/data/GLOBAL_MARKER.lobj000066400000000000000000000001211520700434100173550ustar00rootroot00000000000000LOBJ Q`""""""""""""3333Dxyzxyzxyzvblf-0.3.0/tests/data/GPS_EVENT.lobj000066400000000000000000000001201520700434100167450ustar00rootroot00000000000000LOBJ P.""""""""""33@@@@ @vblf-0.3.0/tests/data/J1708_MESSAGE.lobj000066400000000000000000000004501520700434100172360ustar00rootroot00000000000000LOBJ (7"""""""""33D  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþvblf-0.3.0/tests/data/J1708_VIRTUAL_MSG.lobj000066400000000000000000000004501520700434100200060ustar00rootroot00000000000000LOBJ (8"""""""""33D  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþvblf-0.3.0/tests/data/KLINE_STATUSEVENT.lobj000066400000000000000000000001101520700434100201210ustar00rootroot00000000000000LOBJ Hc""""""""""3333DDDDïÍ«‰gE#ïÍ«‰gE#ïÍ«‰gE#vblf-0.3.0/tests/data/LIN_BAUDRATE.lobj000066400000000000000000000000501520700434100172460ustar00rootroot00000000000000LOBJ (""""""""""3333vblf-0.3.0/tests/data/LIN_CHECKSUM_INFO.lobj000066400000000000000000000000501520700434100200740ustar00rootroot00000000000000LOBJ (*"""""""""3vblf-0.3.0/tests/data/LIN_CRC_ERROR.lobj000066400000000000000000000000701520700434100174410ustar00rootroot00000000000000LOBJ 8 """""""""3DUfwˆ™ª»ÌÝîÿ"3vblf-0.3.0/tests/data/LIN_CRC_ERROR2.lobj000066400000000000000000000002701520700434100175250ustar00rootroot00000000000000LOBJ ¸<""""""""""""33DD""""""3DUf"3DUfwˆ™™ª»ÌÝîîÿÿÿÿ@3333DDDDvblf-0.3.0/tests/data/LIN_DISTURBANCE_EVENT.lobj000066400000000000000000000000701520700434100205650ustar00rootroot00000000000000LOBJ 8Y"""""""""3DDDDUUUUffffwwwwˆˆˆˆvblf-0.3.0/tests/data/LIN_DLC_INFO.lobj000066400000000000000000000000501520700434100172740ustar00rootroot00000000000000LOBJ ( """""""""3vblf-0.3.0/tests/data/LIN_LONG_DOM_SIG.lobj000066400000000000000000000000701520700434100200210ustar00rootroot00000000000000LOBJ 8@""""""""""""33DD"""vblf-0.3.0/tests/data/LIN_LONG_DOM_SIG2.lobj000066400000000000000000000001001520700434100200750ustar00rootroot00000000000000LOBJ @K""""""""""""33DD"3DUfwˆªªªªªªªªvblf-0.3.0/tests/data/LIN_MESSAGE.lobj000066400000000000000000000000701520700434100171450ustar00rootroot00000000000000LOBJ 8 """""""""3DUfwˆ™ª»ÌÝîÿ"3vblf-0.3.0/tests/data/LIN_MESSAGE2.lobj000066400000000000000000000002701520700434100172310ustar00rootroot00000000000000LOBJ ¸9""""""""""""33DD""""""""""3DUf""""""""33333333DDDDDDDDUUUUUUUUffffffffwwwwwwwwˆˆˆˆˆˆˆˆ™™™™™™™™"3DUfwˆ™™ª»ÌÝîÿ"33DDDD@ffffwwwwvblf-0.3.0/tests/data/LIN_RCV_ERROR.lobj000066400000000000000000000000601520700434100174630ustar00rootroot00000000000000LOBJ 0"""""""""3DUfwˆ™ª»vblf-0.3.0/tests/data/LIN_RCV_ERROR2.lobj000066400000000000000000000002701520700434100175500ustar00rootroot00000000000000LOBJ ¸=""""""""""""33DD""""""""""3DUf""""""""33333333DDDDDDDDUUUUUUUUffffffffwwwwwwwwˆˆˆˆˆˆˆˆ™™™™™™™™"3DUfwˆ™ª»ÌÝîÿ""""3333@UUUUffffvblf-0.3.0/tests/data/LIN_SCHED_MODCH.lobj000066400000000000000000000000501520700434100176170ustar00rootroot00000000000000LOBJ ("""""""""3vblf-0.3.0/tests/data/LIN_SHORT_OR_SLOW_RESPONSE.lobj000066400000000000000000000002401520700434100215410ustar00rootroot00000000000000LOBJ  X""""""""""""33DD""""""""""3DUf""""""""33333333DDDDDDDDUUUUUUUUffffffffwwwwwwwwˆˆˆˆˆˆˆˆ™™™™™™™™"3Dvblf-0.3.0/tests/data/LIN_SHORT_OR_SLOW_RESPONSE2.lobj000066400000000000000000000002601520700434100216250ustar00rootroot00000000000000LOBJ °i""""""""""""33DD""""""3DUf"3DUfwˆ™ª»ÌÝ,@vblf-0.3.0/tests/data/LIN_SLEEP.lobj000066400000000000000000000000501520700434100167270ustar00rootroot00000000000000LOBJ ("""""""""3vblf-0.3.0/tests/data/LIN_SLV_TIMEOUT.lobj000066400000000000000000000000501520700434100177310ustar00rootroot00000000000000LOBJ ("""""""""3DDDDvblf-0.3.0/tests/data/LIN_SND_ERROR.lobj000066400000000000000000000000501520700434100174540ustar00rootroot00000000000000LOBJ ("""""""""3DUfwvblf-0.3.0/tests/data/LIN_SND_ERROR2.lobj000066400000000000000000000001501520700434100175370ustar00rootroot00000000000000LOBJ h:""""""""""""33DD""""""""""3DUf"3DUffff@ˆˆˆˆvblf-0.3.0/tests/data/LIN_SPIKE_EVENT.lobj000066400000000000000000000000501520700434100176730ustar00rootroot00000000000000LOBJ (+""""""""""""vblf-0.3.0/tests/data/LIN_SPIKE_EVENT2.lobj000066400000000000000000000000701520700434100177570ustar00rootroot00000000000000LOBJ 8?""""""""""""33DD"3DUvblf-0.3.0/tests/data/LIN_STATISTIC.lobj000066400000000000000000000001101520700434100174230ustar00rootroot00000000000000LOBJ H6""""""""@3333DDDDUUUUffffwwwwvblf-0.3.0/tests/data/LIN_SYN_ERROR.lobj000066400000000000000000000000601520700434100175020ustar00rootroot00000000000000LOBJ 0""""""""""33DDUUffvblf-0.3.0/tests/data/LIN_SYN_ERROR2.lobj000066400000000000000000000001101520700434100175600ustar00rootroot00000000000000LOBJ H;""""""""""""33DD""""""""""33DDvblf-0.3.0/tests/data/LIN_UNEXPECTED_WAKEUP.lobj000066400000000000000000000001001520700434100205730ustar00rootroot00000000000000LOBJ @W""""""""""""33DD"3333333vblf-0.3.0/tests/data/LIN_WAKEUP.lobj000066400000000000000000000000501520700434100170530ustar00rootroot00000000000000LOBJ ("""""""""3vblf-0.3.0/tests/data/LIN_WAKEUP2.lobj000066400000000000000000000000701520700434100171370ustar00rootroot00000000000000LOBJ 8>""""""""""""33DD"3Dvblf-0.3.0/tests/data/LOG_CONTAINER.lobj000066400000000000000000000001701520700434100174030ustar00rootroot00000000000000LOBJx XLOBJ 0"""""""""3DDDDUfwˆ™ª»ÌLOBJ 0"""""""""3DDDDvblf-0.3.0/tests/data/LORENZ_LICENSE.txt000066400000000000000000001042031520700434100174260ustar00rootroot00000000000000Upstream-Name: Vector::BLF Upstream-Contact: Tobias Lorenz Source: http://tomilo.org/vector_blf.html Files: src/Vector/BLF/tests/unittests/events_from_binlog/*.blf Copyright: 2013-2021 Tobias Lorenz License: GPL-3.0-or-later GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright © 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. “This License†refers to version 3 of the GNU General Public License. “Copyright†also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. “The Program†refers to any copyrightable work licensed under this License. Each licensee is addressed as “youâ€. “Licensees†and “recipients†may be individuals or organizations. To “modify†a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version†of the earlier work or a work “based on†the earlier work. A “covered work†means either the unmodified Program or a work based on the Program. To “propagate†a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To “convey†a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays “Appropriate Legal Notices†to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The “source code†for a work means the preferred form of the work for making modifications to it. “Object code†means any non-source form of a work. A “Standard Interface†means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The “System Libraries†of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Componentâ€, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The “Corresponding Source†for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all noticesâ€. c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate†if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A “User Product†is either (1) a “consumer productâ€, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used†refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. “Installation Information†for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. “Additional permissions†are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered “further restrictions†within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An “entity transaction†is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A “contributor†is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor versionâ€. A contributor's “essential patent claims†are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control†includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a “patent license†is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant†such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying†means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is “discriminatory†if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version†applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS†WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright†line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about boxâ€. You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer†for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . vblf-0.3.0/tests/data/MOST_150_ALLOCTAB.lobj000066400000000000000000000000731520700434100177720ustar00rootroot00000000000000LOBJ(;S"3DDDDDDDDUUUUUUUU""33vblf-0.3.0/tests/data/MOST_150_MESSAGE.lobj000066400000000000000000000001131520700434100176700ustar00rootroot00000000000000LOBJ(KL"3DDDDDDDDUUUUUUUU"3DDDDUUUUfwˆ™ªª»ÌÝîvblf-0.3.0/tests/data/MOST_150_MESSAGE_FRAGMENT.lobj000066400000000000000000000001231520700434100211540ustar00rootroot00000000000000LOBJ(SO"3DDDDDDDDUUUUUUUU"3DDDDUUUUffffwˆ™ª»»»»ÌÌÌÌÝÝÝÝvblf-0.3.0/tests/data/MOST_150_PKT.lobj000066400000000000000000000001131520700434100172420ustar00rootroot00000000000000LOBJ(KM"3DDDDDDDDUUUUUUUU"3DDDDUUUUfwˆ™ªª»ÌÝîvblf-0.3.0/tests/data/MOST_150_PKT_FRAGMENT.lobj000066400000000000000000000001231520700434100205260ustar00rootroot00000000000000LOBJ(SP"3DDDDDDDDUUUUUUUU"3DDDDUUUUffffwˆ™ª»»»»ÌÌÌÌÝÝÝÝvblf-0.3.0/tests/data/MOST_50_MESSAGE.lobj000066400000000000000000000001131520700434100176070ustar00rootroot00000000000000LOBJ(KT"3DDDDDDDDUUUUUUUU"3DDDDUUUUfwˆ™ªª»»ÌÝvblf-0.3.0/tests/data/MOST_50_PKT.lobj000066400000000000000000000001131520700434100171610ustar00rootroot00000000000000LOBJ(KU"3DDDDDDDDUUUUUUUU"3DDDDUUUUfwˆ™ªª»»ÌÝvblf-0.3.0/tests/data/MOST_ALLOCTAB.lobj000066400000000000000000000000631520700434100174040ustar00rootroot00000000000000LOBJ(3E"3DDDDDDDDUUUUUUUUvblf-0.3.0/tests/data/MOST_CTRL.lobj000066400000000000000000000001101520700434100167600ustar00rootroot00000000000000LOBJ H"""""""""3DDDDUUUU fwwˆ™ª»vblf-0.3.0/tests/data/MOST_DATALOST.lobj000066400000000000000000000001101520700434100174270ustar00rootroot00000000000000LOBJ(H&"3DDDDDDDDUUUUUUUU""3333DDDDUUUUffffffffwwwwwwwwvblf-0.3.0/tests/data/MOST_ECL.lobj000066400000000000000000000000601520700434100166230ustar00rootroot00000000000000LOBJ(0_"3DDDDDDDDUUUUUUUU""33DDvblf-0.3.0/tests/data/MOST_ETHERNET_PKT.lobj000066400000000000000000000001331520700434100201550ustar00rootroot00000000000000LOBJ([N"3DDDDDDDDUUUUUUUU"3DDDDUUUUfwˆ™ªª»Ìvblf-0.3.0/tests/data/MOST_ETHERNET_PKT_FRAGMENT.lobj000066400000000000000000000001331520700434100214400ustar00rootroot00000000000000LOBJ([Q"3DDDDDDDDUUUUUUUU"3DDDDUUUUffffwˆ™™ªªªª»»»»ÌÌÌÌvblf-0.3.0/tests/data/MOST_GENREG.lobj000066400000000000000000000001001520700434100171620ustar00rootroot00000000000000LOBJ(@$"3DDDDDDDDUUUUUUUU"3DDDDUUffwwwwˆˆˆˆˆˆˆˆvblf-0.3.0/tests/data/MOST_HWMODE.lobj000066400000000000000000000000601520700434100172030ustar00rootroot00000000000000LOBJ(0""3DDDDDDDDUUUUUUUU""33DDvblf-0.3.0/tests/data/MOST_LIGHTLOCK.lobj000066400000000000000000000000501520700434100175370ustar00rootroot00000000000000LOBJ (""""""""""vblf-0.3.0/tests/data/MOST_NETSTATE.lobj000066400000000000000000000000601520700434100174470ustar00rootroot00000000000000LOBJ(0%"3DDDDDDDDUUUUUUUU""33DDvblf-0.3.0/tests/data/MOST_PKT.lobj000066400000000000000000000001031520700434100166540ustar00rootroot00000000000000LOBJ C """""""""3DDDDUUUUfwˆ™™ª»Ìvblf-0.3.0/tests/data/MOST_PKT2.lobj000066400000000000000000000001131520700434100167370ustar00rootroot00000000000000LOBJ(K!"3DDDDDDDDUUUUUUUU"3DDDDUUUUfwˆ™™ª»Ìvblf-0.3.0/tests/data/MOST_REG.lobj000066400000000000000000000001101520700434100166310ustar00rootroot00000000000000LOBJ(H#"3DDDDDDDDUUUUUUUU"3DDDDUUUUffww vblf-0.3.0/tests/data/MOST_SPY.lobj000066400000000000000000000001101520700434100166670ustar00rootroot00000000000000LOBJ H"""""""""3DDDDUUUU fwwˆ™ª»ÌÌÌÌvblf-0.3.0/tests/data/MOST_STATISTIC.lobj000066400000000000000000000000601520700434100175670ustar00rootroot00000000000000LOBJ 0""""""""""3333DDDDUUUUvblf-0.3.0/tests/data/MOST_STATISTICEX.lobj000066400000000000000000000000701520700434100200250ustar00rootroot00000000000000LOBJ(8C"3DDDDDDDDUUUUUUUU""3333DDDDvblf-0.3.0/tests/data/MOST_STRESS.lobj000066400000000000000000000000601520700434100172430ustar00rootroot00000000000000LOBJ(0F"3DDDDDDDDUUUUUUUU""33DDvblf-0.3.0/tests/data/MOST_SYSTEM_EVENT.lobj000066400000000000000000000000701520700434100202060ustar00rootroot00000000000000LOBJ(8R"3DDDDDDDDUUUUUUUU""3333DDDDvblf-0.3.0/tests/data/MOST_TRIGGER.lobj000066400000000000000000000000701520700434100173240ustar00rootroot00000000000000LOBJ(8'"3DDDDDDDDUUUUUUUU""33DDUUUUffffvblf-0.3.0/tests/data/MOST_TXLIGHT.lobj000066400000000000000000000000601520700434100173430ustar00rootroot00000000000000LOBJ(0D"3DDDDDDDDUUUUUUUU""vblf-0.3.0/tests/data/OVERRUN_ERROR.lobj000066400000000000000000000000501520700434100174660ustar00rootroot00000000000000LOBJ ([""""""""""33vblf-0.3.0/tests/data/REALTIMECLOCK.lobj000066400000000000000000000000601520700434100173340ustar00rootroot00000000000000LOBJ 03""""""""""""""""vblf-0.3.0/tests/data/SERIAL_EVENT.lobj000066400000000000000000000001331520700434100172770ustar00rootroot00000000000000LOBJ [Z""""""""""""3333DDDD"3DDUUffvblf-0.3.0/tests/data/SYS_VARIABLE__BYTEARRAY.lobj000066400000000000000000000001061520700434100210630ustar00rootroot00000000000000LOBJ FH""""""""""""3333DDDDxyzvblf-0.3.0/tests/data/SYS_VARIABLE__DOUBLE.lobj000066400000000000000000000001131520700434100204710ustar00rootroot00000000000000LOBJ KH""""""""""""3333DDDDxyz@vblf-0.3.0/tests/data/SYS_VARIABLE__DOUBLEARRAY.lobj000066400000000000000000000001331520700434100212720ustar00rootroot00000000000000LOBJ [H""""""""""""3333DDDDxyzð?@@vblf-0.3.0/tests/data/SYS_VARIABLE__LONG.lobj000066400000000000000000000001071520700434100202610ustar00rootroot00000000000000LOBJ GH""""""""""""3333DDDDxyzvblf-0.3.0/tests/data/SYS_VARIABLE__LONGARRAY.lobj000066400000000000000000000001171520700434100210610ustar00rootroot00000000000000LOBJ OH""""""""""""3333DDDD xyzvblf-0.3.0/tests/data/SYS_VARIABLE__LONGLONG.lobj000066400000000000000000000001131520700434100207360ustar00rootroot00000000000000LOBJ KH""""""""""""3333DDDDxyzvblf-0.3.0/tests/data/SYS_VARIABLE__STRING.lobj000066400000000000000000000001061520700434100205270ustar00rootroot00000000000000LOBJ FH""""""""""""3333DDDDxyzxyzvblf-0.3.0/tests/data/TEST_STRUCTURE.lobj000066400000000000000000000001161520700434100176170ustar00rootroot00000000000000LOBJ Nv""""""""""""xyzxyzxyzvblf-0.3.0/tests/data/TRIGGER_CONDITION.lobj000066400000000000000000000001171520700434100200720ustar00rootroot00000000000000LOBJ O€ """""""TriggerBlockName_TriggerCondition__vblf-0.3.0/tests/data/WLAN_FRAME.lobj000066400000000000000000000000631520700434100170340ustar00rootroot00000000000000LOBJ 3]""""""""""3DUUff vblf-0.3.0/tests/data/WLAN_STATISTIC.lobj000066400000000000000000000001001520700434100175410ustar00rootroot00000000000000LOBJ @^""""""""""3333DDDDUUUUffffwwwwˆˆˆˆvblf-0.3.0/tests/test_can.py000066400000000000000000000265361520700434100157670ustar00rootroot00000000000000from tests import DATA_DIR from vblf.can import ( CanDriverError, CanDriverErrorExt, CanDriverHwSync, CanDriverStatistic, CanErrorFrame, CanErrorFrameExt, CanFdErrorFrame64, CanFdFlags, CanFdMessage, CanFdMessage64, CanMessage, CanMessage2, CanOverloadFrame, ) from vblf.constants import ObjFlags, ObjType def test_can_message(): raw = (DATA_DIR / "CAN_MESSAGE.lobj").read_bytes() obj = CanMessage.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_MESSAGE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.flags == 0x22 assert obj.dlc == 0x33 assert obj.frame_id == 0x44444444 assert obj.data == b"\x55\x66\x77\x88\x99\xaa\xbb\xcc" assert obj.pack() == raw def test_can_message2(): raw = (DATA_DIR / "CAN_MESSAGE2.lobj").read_bytes() obj = CanMessage2.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_MESSAGE2 assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.flags == 0x22 assert obj.dlc == 0x33 assert obj.frame_id == 0x44444444 assert obj.data == b"\x55\x66\x77\x88\x99\xaa\xbb\xcc" assert obj.frame_length == 0xDDDDDDDD assert obj.bit_count == 0xEE assert obj.reserved1 == 0xFF assert obj.reserved2 == 0x1111 assert obj.pack() == raw def test_canfd_message(): raw = (DATA_DIR / "CAN_FD_MESSAGE.lobj").read_bytes() obj = CanFdMessage.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_FD_MESSAGE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.flags == 0x22 assert obj.dlc == 0x33 assert obj.frame_id == 0x44444444 assert obj.frame_length == 0x55555555 assert obj.arb_bit_count == 0x66 assert obj.canfd_flags == 0x77 assert obj.valid_data_bytes == 64 assert obj.reserved1 == 0x99 assert obj.reserved2 == 0xAAAAAAAA assert obj.data == bytes(range(64)) assert obj.reserved3 == 0 assert obj.pack() == raw def test_canfd_message64(): raw = (DATA_DIR / "CAN_FD_MESSAGE_64.lobj").read_bytes() obj = CanFdMessage64.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_FD_MESSAGE_64 assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 1181363 assert obj.channel == 1 assert obj.dlc == 8 assert obj.valid_data_bytes == 8 assert obj.tx_count == 0 assert obj.frame_id == 0xA8 assert obj.frame_length == 104238 assert obj.flags == 3158016 assert isinstance(obj.flags, CanFdFlags) assert obj.btr_cfg_arb == 0x46500250 assert obj.btr_cfg_data == 0x4B280150 assert obj.time_offset_brs_ns == 68863 assert obj.time_offset_crc_del_ns == 16638 assert obj.bit_count == 134 assert obj.dir == 0 assert obj.ext_data_offset == 80 assert obj.crc == 2147501637 assert obj.data == b"\xb8\xda\x1f\x80\xff\x00\x00\x00" assert obj.btr_ext_arb == 0x20011736 assert obj.btr_ext_data == 0x2000091C assert obj.pack() == raw def test_can_driver_statistic(): raw = (DATA_DIR / "CAN_STATISTIC.lobj").read_bytes() obj = CanDriverStatistic.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_STATISTIC assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 1015388138 assert obj.channel == 1 assert obj.bus_load == 3286 assert obj.standard_data_frames == 2093 assert obj.extended_data_frames == 93 assert obj.standard_remote_frames == 0 assert obj.extended_remote_frames == 0 assert obj.error_frames == 0 assert obj.overload_frames == 0 assert obj.reserved == 0 assert obj.pack() == raw def test_can_driver_error(): raw = (DATA_DIR / "CAN_DRIVER_ERROR.lobj").read_bytes() obj = CanDriverError.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_DRIVER_ERROR assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 16971450 assert obj.channel == 1 assert obj.tx_errors == 0 assert obj.rx_errors == 0 assert obj.error_code == 104 assert obj.pack() == raw def test_can_driver_error_ext(): raw = (DATA_DIR / "CAN_DRIVER_ERROR_EXT.lobj").read_bytes() obj = CanDriverErrorExt.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_DRIVER_ERROR_EXT assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.tx_errors == 0x22 assert obj.rx_errors == 0x33 assert obj.error_code == 0x44444444 assert obj.flags == 0x55555555 assert obj.state == 0x66 assert obj.pack() == raw def test_can_error_frame(): raw = (DATA_DIR / "CAN_ERROR.lobj").read_bytes() obj = CanErrorFrame.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_ERROR assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.length == 0x2222 assert obj.reserved == 0 assert obj.pack() == raw def test_can_error_frame_ext(): raw = (DATA_DIR / "CAN_ERROR_EXT.lobj").read_bytes() obj = CanErrorFrameExt.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_ERROR_EXT assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.length == 0x2222 assert obj.flags == 0x33333333 assert obj.ecc == 0x44 assert obj.position == 0x55 assert obj.dlc == 0x66 assert obj.reserved1 == 0x77 assert obj.frame_length_in_ns == 0x88888888 assert obj.frame_id == 0x99999999 assert obj.flags_ext == 0xAAAA assert obj.reserved2 == 0xBBBB assert obj.data == b"\xcc\xdd\xee\xff\x11\x22\x33\x44" assert obj.pack() == raw def test_canfd_error_frame64(): raw = (DATA_DIR / "CAN_FD_ERROR_64.lobj").read_bytes() obj = CanFdErrorFrame64.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_FD_ERROR_64 assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x11 assert obj.dlc == 0x22 assert obj.valid_data_bytes == 64 assert obj.ecc == 0x44 assert obj.flags == 0x5555 assert obj.error_code_ext == 0x6666 assert obj.ext_flags == 0x7777 assert obj.ext_data_offset == 140 assert obj.reserved1 == 0x99 assert obj.frame_id == 0xAAAAAAAA assert obj.frame_length == 0xBBBBBBBB assert obj.btr_cfg_arb == 0xCCCCCCCC assert obj.btr_cfg_data == 0xDDDDDDDD assert obj.time_offset_brs_ns == 0xEEEEEEEE assert obj.time_offset_crc_del_ns == 0xFFFFFFFF assert obj.crc == 0x11111111 assert obj.error_position == 0x2222 assert obj.reserved2 == 0x3333 assert obj.data == bytes(range(64)) assert obj.btr_ext_arb == 0x11111111 assert obj.btr_ext_data == 0x22222222 assert obj.pack() == raw def test_can_driver_hw_sync(): raw = (DATA_DIR / "CAN_DRIVER_SYNC.lobj").read_bytes() obj = CanDriverHwSync.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_DRIVER_SYNC assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.flags == 0x22 assert obj.reserved1 == 0x33 assert obj.reserved2 == 0 assert obj.pack() == raw def test_can_overload_frame(): raw = (DATA_DIR / "CAN_OVERLOAD.lobj").read_bytes() obj = CanOverloadFrame.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.CAN_OVERLOAD assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.reserved1 == 0x2222 assert obj.reserved2 == 0 assert obj.pack() == raw vblf-0.3.0/tests/test_ethernet.py000066400000000000000000000045131520700434100170330ustar00rootroot00000000000000from tests import DATA_DIR from vblf.constants import ObjFlags, ObjType from vblf.ethernet import EthernetFrameEx, EthernetStatistic def test_ethernet_frame_ex(): raw = (DATA_DIR / "ETHERNET_FRAME_EX.lobj").read_bytes() obj = EthernetFrameEx.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.ETHERNET_FRAME_EX assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.struct_length == 30 # ? assert obj.flags == 0x1111 assert obj.channel == 0x2222 assert obj.hardware_channel == 0x3333 assert obj.frame_duration == 0x4444444444444444 assert obj.frame_checksum == 0x55555555 assert obj.dir == 0x6666 assert obj.frame_length == 3 assert obj.frame_handle == 0x88888888 assert obj.reserved == 0x99999999 assert obj.frame_data == b"\xaa\xbb\xcc" assert obj.pack() == raw def test_ethernet_statistic(): raw = (DATA_DIR / "ETHERNET_STATISTIC.lobj").read_bytes() obj = EthernetStatistic.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.ETHERNET_STATISTIC assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.reserved_1 == 0x0 assert obj.reserved_2 == 0x0 assert obj.rcv_ok_hw == 0x2222222222222222 assert obj.xmit_ok_hw == 0x3333333333333333 assert obj.rcv_error_hw == 0x4444444444444444 assert obj.xmit_error_hw == 0x5555555555555555 assert obj.rcv_bytes_hw == 0x6666666666666666 assert obj.xmit_bytes_hw == 0x7777777777777777 assert obj.rcv_no_buffer_hw == 0x8888888888888888 assert obj.sqi == 0x7999 assert obj.hardware_channel == 0xAAAA assert obj.reserved_3 == 0x0 assert obj.pack() == raw vblf-0.3.0/tests/test_flexray.py000066400000000000000000000032601520700434100166650ustar00rootroot00000000000000from tests import DATA_DIR from vblf.constants import ObjFlags, ObjType from vblf.flexray import FlexrayVFrReceiveMsgEx def test_flexray_v_fr_receive_msg_ex(): raw = (DATA_DIR / "FR_RCVMESSAGE_EX.lobj").read_bytes() obj = FlexrayVFrReceiveMsgEx.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.FR_RCVMESSAGE_EX assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.version == 0x2222 assert obj.channel_mask == 0x3333 assert obj.dir_flags == 0x4444 assert obj.client_index == 0x55555555 assert obj.cluster_no == 0x66666666 assert obj.frame_id == 0x7777 assert obj.header_crc1 == 0x8888 assert obj.header_crc2 == 0x9999 assert obj.byte_count == 0xAAAA assert obj.data_count == 254 assert obj.cycle == 0xCCCC assert obj.tag == 0xDDDDDDDD assert obj.data == 0xEEEEEEEE assert obj.frame_flags == 0xFFFFFFFF assert obj.app_parameter == 0x11111111 assert obj.frame_crc == 0x22222222 assert obj.frame_length_ns == 0x33333333 assert obj.frame_id1 == 0x4444 assert obj.pdu_offset == 0x5555 assert obj.blf_log_mask == 0x6666 assert obj.reserved == ( b"\x77\x77" b"\x88\x88\x88\x88\x99\x99\x99\x99\xaa\xaa\xaa\xaa" b"\xbb\xbb\xbb\xbb\xcc\xcc\xcc\xcc\xdd\xdd\xdd\xdd" ) assert obj.pack() == raw vblf-0.3.0/tests/test_general.py000066400000000000000000000436371520700434100166440ustar00rootroot00000000000000from tests import DATA_DIR from vblf.constants import ( AppId, AppTextSource, BusType, Compression, FunctionBusType, ObjFlags, ObjType, SysVarType, TriggerConditionStatus, TriggerFlag, ) from vblf.general import ( AppText, AppTrigger, DriverOverrun, EnvironmentVariable, EventComment, FileStatistics, FunctionBus, GlobalMarker, RealTimeClock, SystemVariable, TriggerCondition, ) def test_file_statistics(): raw = (DATA_DIR / "FILE_STATISTICS.logg").read_bytes() obj = FileStatistics.unpack(raw) assert obj.signature == b"LOGG" assert obj.statistics_size == 144 assert obj.api_number == 0x3E4630 assert obj.application_id is AppId.CANOE assert obj.compression_level is Compression.SPEED assert obj.application_major == 12 assert obj.application_minor == 0 assert obj.file_size == 24763512 assert obj.uncompressed_file_size == 89639607 assert obj.object_count == 923421 assert obj.application_build == 101 assert obj.measurement_start_time.year == 2024 assert obj.measurement_start_time.month == 11 assert obj.measurement_start_time.day == 20 assert obj.measurement_start_time.hour == 15 assert obj.measurement_start_time.minute == 20 assert obj.measurement_start_time.second == 24 assert obj.measurement_start_time.milliseconds == 850 assert obj.last_object_time.year == 2024 assert obj.last_object_time.month == 11 assert obj.last_object_time.day == 20 assert obj.last_object_time.hour == 15 assert obj.last_object_time.minute == 23 assert obj.last_object_time.second == 50 assert obj.last_object_time.milliseconds == 712 assert obj.restore_points_offset == 24751994 assert obj.pack() == raw def test_app_text(): raw = (DATA_DIR / "APP_TEXT.lobj").read_bytes() obj = AppText.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.APP_TEXT assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0 assert obj.source is AppTextSource.DBCHANNELINFO assert obj.reserved1 == 0x01010101 assert obj.text_length == 49 assert obj.reserved2 == 0 assert obj.text == "C:\\Users\\user\\Desktop\\project car\\myDatabase.dbc" assert obj.pack() == raw def test_app_trigger(): raw = (DATA_DIR / "APP_TRIGGER.lobj").read_bytes() obj = AppTrigger.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.APP_TRIGGER assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.pre_trigger_time == 0x1111111111111111 assert obj.post_trigger_time == 0x2222222222222222 assert obj.channel == 0x3333 assert obj.flags == TriggerFlag.SINGLE_TRIGGER assert obj.app_specific == 0x44444444 assert obj.pack() == raw def test_environment_variable_integer(): raw = (DATA_DIR / "ENV_INTEGER.lobj").read_bytes() obj = EnvironmentVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.ENV_INTEGER assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.name_length == 3 assert obj.data_length == 4 assert obj.reserved == 0 assert obj.name == "xyz" assert obj.data == b"\x11\x11\x11\x11" assert obj.pack() == raw def test_environment_variable_double(): raw = (DATA_DIR / "ENV_DOUBLE.lobj").read_bytes() obj = EnvironmentVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.ENV_DOUBLE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.name_length == 3 assert obj.data_length == 8 assert obj.reserved == 0 assert obj.name == "xyz" assert obj.data == b"\x00\x00\x00\x00\x00\x00\x00\x40" assert obj.pack() == raw def test_environment_variable_string(): raw = (DATA_DIR / "ENV_STRING.lobj").read_bytes() obj = EnvironmentVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.ENV_STRING assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.name_length == 3 assert obj.data_length == 3 assert obj.reserved == 0 assert obj.name == "xyz" assert obj.data == b"xyz" assert obj.pack() == raw def test_environment_variable_data(): raw = (DATA_DIR / "ENV_DATA.lobj").read_bytes() obj = EnvironmentVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.ENV_DATA assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.name_length == 3 assert obj.data_length == 3 assert obj.reserved == 0 assert obj.name == "xyz" assert obj.data == b"\x01\x02\x03" assert obj.pack() == raw def test_system_variable_double(): raw = (DATA_DIR / "SYS_VARIABLE__DOUBLE.lobj").read_bytes() obj = SystemVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.SYS_VARIABLE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.type is SysVarType.DOUBLE assert obj.representation == 0x22222222 assert obj.reserved1 == 0x4444444433333333 assert obj.name_length == 3 assert obj.data_length == 8 assert obj.reserved2 == 0 assert obj.name == "xyz" assert obj.data == b"\x00\x00\x00\x00\x00\x00\x00\x40" assert obj.pack() == raw def test_system_variable_long(): raw = (DATA_DIR / "SYS_VARIABLE__LONG.lobj").read_bytes() obj = SystemVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.SYS_VARIABLE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.type is SysVarType.LONG assert obj.representation == 0x22222222 assert obj.reserved1 == 0x4444444433333333 assert obj.name_length == 3 assert obj.data_length == 4 assert obj.reserved2 == 0 assert obj.name == "xyz" assert obj.data == b"\x11\x11\x11\x11" assert obj.pack() == raw def test_system_variable_string(): raw = (DATA_DIR / "SYS_VARIABLE__STRING.lobj").read_bytes() obj = SystemVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.SYS_VARIABLE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.type is SysVarType.STRING assert obj.representation == 0x22222222 assert obj.reserved1 == 0x4444444433333333 assert obj.name_length == 3 assert obj.data_length == 3 assert obj.reserved2 == 0 assert obj.name == "xyz" assert obj.data == b"xyz" assert obj.pack() == raw def test_system_variable_double_array(): raw = (DATA_DIR / "SYS_VARIABLE__DOUBLEARRAY.lobj").read_bytes() obj = SystemVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.SYS_VARIABLE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.type is SysVarType.DOUBLEARRAY assert obj.representation == 0x22222222 assert obj.reserved1 == 0x4444444433333333 assert obj.name_length == 3 assert obj.data_length == 24 assert obj.reserved2 == 0 assert obj.name == "xyz" assert obj.data == ( b"\x00\x00\x00\x00\x00\x00\xf0\x3f" b"\x00\x00\x00\x00\x00\x00\x00\x40" b"\x00\x00\x00\x00\x00\x00\x08\x40" ) assert obj.pack() == raw def test_system_variable_long_array(): raw = (DATA_DIR / "SYS_VARIABLE__LONGARRAY.lobj").read_bytes() obj = SystemVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.SYS_VARIABLE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.type is SysVarType.LONGARRAY assert obj.representation == 0x22222222 assert obj.reserved1 == 0x4444444433333333 assert obj.name_length == 3 assert obj.data_length == 12 assert obj.reserved2 == 0 assert obj.name == "xyz" assert obj.data == b"\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00" assert obj.pack() == raw def test_system_variable_longlong(): raw = (DATA_DIR / "SYS_VARIABLE__LONGLONG.lobj").read_bytes() obj = SystemVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.SYS_VARIABLE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.type is SysVarType.LONGLONG assert obj.representation == 0x22222222 assert obj.reserved1 == 0x4444444433333333 assert obj.name_length == 3 assert obj.data_length == 8 assert obj.reserved2 == 0 assert obj.name == "xyz" assert obj.data == b"\x11\x11\x11\x11\x11\x11\x11\x11" assert obj.pack() == raw def test_system_variable_bytearray(): raw = (DATA_DIR / "SYS_VARIABLE__BYTEARRAY.lobj").read_bytes() obj = SystemVariable.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.SYS_VARIABLE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.type is SysVarType.BYTEARRAY assert obj.representation == 0x22222222 assert obj.reserved1 == 0x4444444433333333 assert obj.name_length == 3 assert obj.data_length == 3 assert obj.reserved2 == 0 assert obj.name == "xyz" assert obj.data == b"\x01\x02\x03" assert obj.pack() == raw def test_real_time_clock(): raw = (DATA_DIR / "REALTIMECLOCK.lobj").read_bytes() obj = RealTimeClock.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.REALTIMECLOCK assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.time == 0x1111111111111111 assert obj.logging_offset == 0x2222222222222222 assert obj.pack() == raw def test_driver_overrun(): raw = (DATA_DIR / "OVERRUN_ERROR.lobj").read_bytes() obj = DriverOverrun.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.OVERRUN_ERROR assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.bus_type is BusType.CAN assert obj.channel == 0x2222 assert obj.reserved == 0x3333 assert obj.pack() == raw def test_event_comment(): raw = (DATA_DIR / "EVENT_COMMENT.lobj").read_bytes() obj = EventComment.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.EVENT_COMMENT assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.commented_event_type == 0x11111111 assert obj.text_length == 3 assert obj.reserved == 0 assert obj.text == "xyz" assert obj.pack() == raw def test_global_marker(): raw = (DATA_DIR / "GLOBAL_MARKER.lobj").read_bytes() obj = GlobalMarker.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.GLOBAL_MARKER assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.commented_event_type == 0x11111111 assert obj.foreground_color == 0x22222222 assert obj.background_color == 0x33333333 assert obj.is_relocatable == 0x44 assert obj.reserved1 == 0 assert obj.reserved2 == 0 assert obj.group_name_length == 3 assert obj.marker_name_length == 3 assert obj.description_length == 3 assert obj.group_name == "xyz" assert obj.marker_name == "xyz" assert obj.description == "xyz" assert obj.pack() == raw def test_function_bus(): raw = (DATA_DIR / "FUNCTION_BUS.lobj").read_bytes() obj = FunctionBus.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 3 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.FUNCTION_BUS assert obj.header.object_flags is ObjFlags.TIME_TEN_MICS assert obj.header.object_static_size == 16 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x22222222222222 assert obj.object_type is FunctionBusType.SIGNAL assert obj.ve_type == 0x11111111 assert obj.name_length == 21 assert obj.data_length == 21 assert obj.name == "functionBusObjectName" assert obj.data == b"functionBusObjectData" assert obj.pack() == raw def test_trigger_condition(): raw = (DATA_DIR / "TRIGGER_CONDITION.lobj").read_bytes() obj = TriggerCondition.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 3 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.TRIGGER_CONDITION assert obj.header.object_flags is ObjFlags.TIME_TEN_MICS assert obj.header.object_static_size == 12 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x22222222222222 assert obj.state is TriggerConditionStatus.START assert obj.trigger_block_name_length == 17 assert obj.trigger_condition_length == 18 assert obj.trigger_block_name == "TriggerBlockName_" assert obj.trigger_condition == "TriggerCondition__" assert obj.pack() == raw vblf-0.3.0/tests/test_lin.py000066400000000000000000000067571520700434100160130ustar00rootroot00000000000000from tests import DATA_DIR from vblf.constants import ObjFlags, ObjType from vblf.lin import LinMessage, LinMessage2 def test_lin_message(): raw = (DATA_DIR / "LIN_MESSAGE.lobj").read_bytes() obj = LinMessage.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.LIN_MESSAGE assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.channel == 0x1111 assert obj.id == 0x22 assert obj.dlc == 0x33 assert obj.data == b"\x44\x55\x66\x77\x88\x99\xaa\xbb" assert obj.fsm_id == 0xCC assert obj.fsm_state == 0xDD assert obj.header_time == 0xEE assert obj.full_time == 0xFF assert obj.crc == 0x1111 assert obj.dir == 0x22 assert obj.reserved == b"\x33\x00\x00\x00\x00" assert obj.pack() == raw def test_lin_message2(): raw = (DATA_DIR / "LIN_MESSAGE2.lobj").read_bytes() obj = LinMessage2.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.LIN_MESSAGE2 assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 3 assert obj.header.object_time_stamp == 0x2222222222222222 lin_bus_event = obj.lin_timestamp_event.lin_msg_descr_event.lin_synch_field_event.lin_bus_event assert lin_bus_event.sof == 0x1111111111111111 assert lin_bus_event.event_baudrate == 0x22222222 assert lin_bus_event.channel == 0x3333 assert lin_bus_event.reserved == b"\x44\x44" lin_synch_field_event = obj.lin_timestamp_event.lin_msg_descr_event.lin_synch_field_event assert lin_synch_field_event.synch_break_length == 0x1111111111111111 assert lin_synch_field_event.synch_del_length == 0x2222222222222222 assert obj.lin_timestamp_event.lin_msg_descr_event.supplier_id == 0x1111 assert obj.lin_timestamp_event.lin_msg_descr_event.message_id == 0x2222 assert obj.lin_timestamp_event.lin_msg_descr_event.nad == 0x33 assert obj.lin_timestamp_event.lin_msg_descr_event.id == 0x44 assert obj.lin_timestamp_event.lin_msg_descr_event.dlc == 0x55 assert obj.lin_timestamp_event.lin_msg_descr_event.checksum_model == 0x66 assert obj.lin_timestamp_event.databyte_timestamps == ( 0x1111111111111111, 0x2222222222222222, 0x3333333333333333, 0x4444444444444444, 0x5555555555555555, 0x6666666666666666, 0x7777777777777777, 0x8888888888888888, 0x9999999999999999, ) assert obj.data == b"\x11\x22\x33\x44\x55\x66\x77\x88" assert obj.crc == 0x9999 assert obj.direction == 0xAA assert obj.simulated == 0xBB assert obj.is_etf == 0xCC assert obj.etf_assoc_index == 0xDD assert obj.etf_assoc_etf_id == 0xEE assert obj.fsm_id == 0xFF assert obj.fsm_state == 0x11 assert obj.reserved == b"\x22\x33\x33" assert obj.resp_baudrate == 0x44444444 assert obj.exact_header_baudrate == 5.0 assert obj.early_stopbit_offset == 0x66666666 assert obj.early_stopbit_offset_response == 0x77777777 assert obj.pack() == raw vblf-0.3.0/tests/test_tp_diag.py000066400000000000000000000022541520700434100166240ustar00rootroot00000000000000from tests import DATA_DIR from vblf.constants import ObjFlags, ObjType from vblf.tp_diag import DiagRequestInterpretation def test_diag_request_interpretation(): raw = (DATA_DIR / "DIAG_REQUEST_INTERPRETATION.lobj").read_bytes() obj = DiagRequestInterpretation.unpack(raw) assert obj.header.base.signature == b"LOBJ" assert obj.header.base.header_size == 32 assert obj.header.base.header_version == 1 assert obj.header.base.object_size == len(raw) assert obj.header.base.object_type is ObjType.DIAG_REQUEST_INTERPRETATION assert obj.header.object_flags is ObjFlags.TIME_ONE_NANS assert obj.header.client_index == 0x1111 assert obj.header.object_version == 0 assert obj.header.object_time_stamp == 0x2222222222222222 assert obj.diag_description_handle == 0x11111111 assert obj.diag_variant_handle == 0x22222222 assert obj.diag_service_handle == 0x33333333 assert obj.ecu_qualifier_length == 3 assert obj.variant_qualifier_length == 3 assert obj.service_qualifier_length == 3 assert obj.ecu_qualifier == "xyz" assert obj.variant_qualifier == "xyz" assert obj.service_qualifier == "xyz" assert obj.pack() == raw vblf-0.3.0/tests/test_writer.py000066400000000000000000000053421520700434100165320ustar00rootroot00000000000000import tempfile from pathlib import Path import pytest from tests import DATA_DIR from vblf.can import CanFdMessage64 from vblf.constants import Compression, ObjType from vblf.general import ObjectHeaderBase from vblf.reader import OBJ_MAP, BlfReader from vblf.writer import BlfWriter @pytest.mark.parametrize( "compression_level", [Compression.NONE, Compression.SPEED, Compression.DEFAULT, Compression.MAX], ) def test_roundtrip(compression_level: Compression): # Read original objects and compare original_objects = [] roundtrip_objects = [] for fp in DATA_DIR.rglob("*.lobj"): obj_data = fp.read_bytes() base = ObjectHeaderBase.unpack_from(obj_data) if base.object_type is ObjType.LOG_CONTAINER: # BlfReader does not return LogContainer instances, so a comparison is not possible continue obj_class = OBJ_MAP.get(base.object_type) if not obj_class: continue obj = obj_class.unpack(obj_data) original_objects.append(obj) # Write objects to BLF file with tempfile.TemporaryDirectory() as temp_dir: output_file = Path(temp_dir) / "test_output.blf" with BlfWriter(output_file, compression_level=compression_level) as writer: for obj in original_objects: writer.write(obj) # Read objects from BLF file and compare with BlfReader(output_file) as reader: roundtrip_objects.extend(reader) assert len(original_objects) == len(roundtrip_objects) for original_obj, written_obj in zip(original_objects, roundtrip_objects): assert written_obj == original_obj @pytest.mark.parametrize( "compression_level", [Compression.NONE, Compression.SPEED, Compression.DEFAULT, Compression.MAX], ) def test_writer_buffer(compression_level: Compression): lobj_path = DATA_DIR / f"{ObjType.CAN_FD_MESSAGE_64.name}.lobj" lobj_data = lobj_path.read_bytes() original_obj = CanFdMessage64.unpack(lobj_data) # written data shall be greater than buffer size buffer_size = 128 * 1024 # 128 KiB write_count = round(5.0 * buffer_size / len(lobj_data)) with tempfile.TemporaryDirectory() as temp_dir: # write object to file repeatedly output_file = Path(temp_dir) / "test_output.blf" with BlfWriter(output_file, compression_level=compression_level) as writer: for _ in range(write_count): writer.write(original_obj) # read objects and compare with BlfReader(output_file) as reader: read_count = 0 while written_obj := reader.read_object(): read_count += 1 assert written_obj == original_obj assert read_count == write_count vblf-0.3.0/tox.ini000066400000000000000000000017461520700434100137620ustar00rootroot00000000000000[tox] min_version = 4.23 env_list = format,lint,type,py,docs [testenv] passenv = GITHUB_* allowlist_externals = pytest mypy ruff sphinx-build dependency_groups = test commands = pytest -v {tty:--color=yes} {posargs} tests [testenv:lint] description = Run linter skip_install = True dependency_groups = lint commands = ruff check src docs tests [testenv:format] description = Check formatting skip_install = True dependency_groups = lint commands = ruff format --check src docs tests [testenv:type] description = Test type annotations dependency_groups = lint commands = mypy --strict src [testenv:docs] basepython = py312 description = Build and test the documentation dependency_groups = deps = -r docs/requirements.txt commands = sphinx-build -j auto -b html docs build