How christoph2/pyxcp works
Project type and purpose
• pyXCP is an open-source, full-featured Python library and CLI toolset for communicating with XCP (ASAM MCD-1)-enabled devices (primarily automotive ECUs).
• It provides APIs to take measurements, adjust parameters, flash ECUs, record/log data, and generate DAQ stimuli.
• Supports multiple transports (CAN, Ethernet, USB, SCI), seed-and-key unlocking, and high-performance data recording via C++ extensions.
File structure
• Top-level folders and files:
• container/ – Docker/Tmux/Zsh configuration for development environments
• docs/ – Sphinx documentation and tutorials
• pyxcp/ – core Python package
• pyxcp/cpp_ext/ – C++ extension wrappers for performance-critical operations
• pyxcp/transport/ – transport adapter modules (CAN, Ethernet, SXI, USB)
• pyxcp/daq_stim/ – DAQ stimulus scheduler and optimizer (C++ and Python)
• pyxcp/recorder/ – data recording library (LZ4, file I/O, C++ and Python glue)
• pyxcp/asam/ – ASAM-A2L parsing and data type definitions
• pyxcp/master/ – master state machine and command handling
• pyxcp/scripts/ – helper CLI scripts (auto-discovery, profiling, conversion)
• pyxcp/examples/ – end-user examples illustrating common use cases
• pyxcp/tests/ – unit/integration tests for each component
• Build and CI:
• CMakeLists.txt & build_ext.py for building C++ modules
• setup.py/pyproject.toml for packaging
• .github/workflows, appveyor.yml, code climate etc. for CI, linting, coverage
README for additional insights
• Confirms purpose: lightweight Python library to talk to XCP-enabled devices.
• Mentions Python ≥3.7, optional seed-and-key DLLs on Windows requiring a bridge executable.
• Setup via pip, source installation, or Docker (container).
a. Main components to include
1. Client layer
– User applications and CLI scripts (pyxcp/scripts, pyxcp/examples)
2. Core Python API
– pyxcp.master (state machine, command dispatch)
– pyxcp.cmdline (entry points)
3. ASAM and configuration
– pyxcp.asam (A2L parsing, data types)
– pyxcp.config/legacy (configuration management)
4. Transport layer
– Python adapters: can.py, eth.py, sxi.py, usb_transport.py
– C++ transport wrapper (transport_wrapper.cpp)
5. C++ performance extensions
– pyxcp/cpp_ext (helper.hpp, tsqueue, event, blockmem, etc.)
– used by recorder and DAQ stimulus
6. DAQ stimulus engine
– pyxcp.daq_stim (scheduler, bin-packing optimizer, C++ wrappers)
7. Data recorder
– pyxcp.recorder (LZ4 compressor, file I/O, reader/writer, Rekorder C++ backend)
8. External systems
– ECU hardware over CAN/Ethernet/USB/SXI
– Optional seed-and-key DLL bridge (asamkeydll.exe)
9. Storage & logs
– Local file system (recorded data files, configurations)
b. Relationships and data flows
• User invokes CLI ➔ Python API (master, cmdline)
• API loads ASAM A2L definitions ➔ config module
• API issues commands ➔ transport adapter ➔ C++ wrapper (if performance-critical) ➔ physical bus ➔ ECU
• ECU responses flow back through transport ➔ API event queue ➔ user callback or recorder
• Recorder may compress and persist data to disk via C++ Rekorder core
• DAQ stimulus scheduler packages stimuli via C++ optimizer ➔ transport to ECU
c. Architectural patterns and design principles
• Layered architecture: separation of concerns (API, transport, data processing, persistence)
• Plugin-style transport adapters: new bus protocols can be added under pyxcp/transport
• High-performance sections isolated into C++ extensions to minimize Python overhead
• Configuration and ASAM parsing decoupled from command logic (single responsibility)
• CLI/scripts layer thinly wraps core library for discoverability and automation
d. Key technologies, frameworks, and libraries
• Python 3.7+, setuptools, pyproject.toml
• C++11 for extensions, CMake for build glue
• LZ4 for data compression in recorder
• pytest for tests, Sphinx for docs, Docker for dev container
• Black, pylintrc, pre-commit for code style
Essential details
• Plugin boundaries (transport, C++ ext, recorder)
• Call out performance-critical paths vs. control-flow paths
• That external dependencies (ECU hardware, DLLs, file storage) are represented