feat(xcp): add XCP master implementation with worker script API - #432
Draft
frankie-zeng wants to merge 2 commits into
Draft
feat(xcp): add XCP master implementation with worker script API#432frankie-zeng wants to merge 2 commits into
frankie-zeng wants to merge 2 commits into
Conversation
Add an XCP (ASAM MCD-1 XCP) master, mirroring the CAN-TP architecture: - src/main/xcp/xcpProtocol.ts: transport-agnostic command/response codec covering STD, CAL/PAG, DAQ and PGM commands, with Intel/Motorola byte-order handling. Byte layout validated against the pyXCP master test vectors. - src/main/xcp/xcpMaster.ts: high-level XcpMaster over a pluggable transport, negotiating slave byte order at CONNECT. - src/main/xcp/xcpCan.ts: XCP-on-CAN transport binding on the existing CAN layer. - src/main/worker/xcp.ts: worker script API (XcpCreateConnection, XcpConnect, XcpShortUpload, DAQ/PGM helpers, ...) bridged via the 'xcpApi' RPC. - nodeItem.ts: xcpApi handler dispatching whitelisted master methods. Tests (test/xcp): 79 codec/master vectors ported from pyXCP plus 5 end-to-end XCP-on-CAN tests over the simulate backend. Also add ambient *?asset / *?asset&asarUnpack module declarations so the worker webpack bundle builds (pre-existing gap that blocked npm run worker:js).
Drive XCP-on-CAN through two independent SocketCAN sockets that exchange packed Linux can_frame/canfd_frame buffers, in addition to the existing simulate backend. Prefer a real vcan/can interface when AF_CAN works; fall back to an in-process bus on kernels without CONFIG_CAN (this Cloud VM). Frame layout is checked against Python struct.pack of the uapi ABI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an XCP (ASAM MCD-1 XCP) master to EcuBus-Pro, following the existing CAN-TP architecture, and exposes it to user scripts. This is the first iteration: it adds the main-process implementation plus the worker/script API surface (no renderer/UI yet).
The protocol codec is implemented test-first, constrained by the byte-level test vectors of the mature open-source XCP master pyXCP (
pyxcp/tests/test_master.py). The byte encodings are dictated by the ASAM XCP standard; the ported vectors act as a correctness oracle.What's included
Mirrors the CAN-TP layering (
worker/cantp.ts→nodeItem.canApi→docan/cantp.ts):src/main/xcp/xcpProtocol.ts— pure, transport-agnostic command builders and response parsers. Covers STD, calibration/paging (CAL_PAG), DAQ and programming (PGM) commands, with Intel/Motorola byte-order handling negotiated atCONNECT.src/main/xcp/xcpMaster.ts—XcpMaster, a high-level master over a pluggableXcpTransport, tracking slave properties (byte order, MAX_CTO/MAX_DTO, resources).src/main/xcp/xcpCan.ts—XcpCanTransport, XCP-on-CAN binding on the existingCAN_SOCKET/CanBaselayer.src/main/worker/xcp.ts— worker script API (XcpCreateConnection,XcpConnect,XcpGetStatus,XcpShortUpload,XcpSetMta, DAQ/PGM helpers, ...) bridged via a newxcpApiRPC, mirroring the CAN-TP worker API. Re-exported fromworker/index.ts.src/main/nodeItem.ts—xcpApihandler that opens/closes connections and dispatches whitelistedXcpMastermethods.src/main/worker/node.d.ts— ambient*?asset/*?asset&asarUnpackmodule declarations. This is a pre-existing gap that preventednpm run worker:jsfrom emitting the worker bundle (ts-loaderTS2307on those asset imports, unrelated to XCP); adding the shims — identical in spirit to the existing*.node/*.html?rawshims in the same file — unblocks the mandated worker rebuild.Example script usage
Testing
test/xcp/xcp.test.ts— 79 tests: command builders and response parsers for every STD/CAL_PAG/DAQ/PGM command, plusXcpMasterend-to-end flow over a mock transport. Expectations are the pyXCP vectors minus the 4-byte XCP-on-Ethernet transport header.test/xcp/xcpCan.test.ts— 5 end-to-end tests drivingXcpMasterthrough the realXcpCanTransportover thesimulateCAN backend, against a tiny simulated XCP slave (CONNECT / GET_STATUS / SHORT_UPLOAD / SET_MTA / DISCONNECT).test/xcp/xcpCanSocketcan.test.ts— the same 5 XCP-on-CAN session tests over SocketCAN: two independent sockets sharing one bus, exchanging packed Linuxstruct can_framebuffers. Prefers a realvcan/caninterface whenAF_CANworks; falls back to an in-process bus on kernels withoutCONFIG_CAN.test/docan/socketcan.test.ts— SocketCAN ABI codec tests (checked against Pythonstruct.packofcan_frame/canfd_frame), two-socket I/O, fan-out, timeout, and kernel vcan smoke tests (skipped when AF_CAN is unavailable).test/xcp/xcpCanHarness.ts. Linux AF_CAN worker:test/helpers/socketcan_worker.py.npm run test -- --run test/xcp test/docan/socketcan.test.ts→ 100 passed, 2 skipped (kernel vcan; this Cloud kernel has noCONFIG_CAN).npm run typecheck→ clean (node + web).npm run worker:js→ builds and the bundle + generated worker typings include the XCP API.To run the real kernel path on a normal Linux host:
Scope / follow-ups