dbc-matrix-audit 1.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 autosar-agent-skills contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,372 @@
1
+ Metadata-Version: 2.4
2
+ Name: dbc-matrix-audit
3
+ Version: 1.3.1
4
+ Summary: Zero-dependency DBC / ARXML auditor for AUTOSAR and CAN (FD): 11 matrix checks, revision diff, frame decoding, 26 ARXML-vs-DBC cross-checks.
5
+ Author-email: Harry Zhao <tech.harry.zhao@gmail.com>
6
+ Maintainer-email: Harry Zhao <tech.harry.zhao@gmail.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://autosar-skills.github.io/autosar-agent-skills/
9
+ Project-URL: Documentation, https://autosar-skills.github.io/autosar-agent-skills/
10
+ Project-URL: Repository, https://github.com/autosar-skills/autosar-agent-skills
11
+ Project-URL: Changelog, https://github.com/autosar-skills/autosar-agent-skills/blob/main/CHANGELOG.md
12
+ Project-URL: Bug Tracker, https://github.com/autosar-skills/autosar-agent-skills/issues
13
+ Project-URL: Design write-up, https://me.tech-harry.top/blog/dbc-matrix-audit-skill.en.html
14
+ Project-URL: Debugging story, https://me.tech-harry.top/blog/arxml-dbc-consistency.en.html
15
+ Keywords: autosar,can,canfd,dbc,arxml,ecu,communication-matrix,lint,static-analysis,embedded,agent-skills
16
+ Classifier: Development Status :: 4 - Beta
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: Manufacturing
19
+ Classifier: License :: OSI Approved :: MIT License
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.8
23
+ Classifier: Programming Language :: Python :: 3.9
24
+ Classifier: Programming Language :: Python :: 3.10
25
+ Classifier: Programming Language :: Python :: 3.11
26
+ Classifier: Programming Language :: Python :: 3.12
27
+ Classifier: Programming Language :: Python :: 3.13
28
+ Classifier: Topic :: Software Development :: Embedded Systems
29
+ Classifier: Topic :: Software Development :: Quality Assurance
30
+ Classifier: Typing :: Typed
31
+ Requires-Python: >=3.8
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=8; extra == "dev"
36
+ Requires-Dist: ruff>=0.5; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # autosar-agent-skills
40
+
41
+ ![Python 3.8+](https://img.shields.io/badge/python-3.8%2B-blue)
42
+ ![dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen)
43
+ ![license: MIT](https://img.shields.io/badge/license-MIT-green)
44
+ ![checks: 11 + 26](https://img.shields.io/badge/checks-11%20%2B%2026-orange)
45
+ ![tests: 65](https://img.shields.io/badge/tests-65-blueviolet)
46
+
47
+ [English](README.en.md) | [中文](README.md)
48
+
49
+ Agent skills for AUTOSAR Classic Platform engineering. Zero third-party
50
+ dependencies — every script is standard-library Python, so it runs inside an
51
+ air-gapped build server, a CI container, or an agent sandbox without a network
52
+ round-trip or a `pip install`.
53
+
54
+ Every skill here is self-contained: drop the directory into an agent's skill
55
+ path and the agent loads it, or run the script directly as a CLI tool.
56
+
57
+ They all target one class of engineering problem: **bugs that compile cleanly
58
+ and only surface during ECU integration testing** — a signal decoded three bits
59
+ off, a frame length that changed without anyone updating the config, a receiver
60
+ that silently drops every frame because a CRC seed moved.
61
+
62
+ ## Skills
63
+
64
+ | Skill | What it does | Deps |
65
+ |---|---|---|
66
+ | [dbc-matrix-audit](https://github.com/autosar-skills/autosar-agent-skills/tree/main/skills/dbc-matrix-audit) | DBC communication matrix audit: bit-field overlap, out-of-range signals, left/right asymmetry, naming drift, GBK encoding | **none** |
67
+ | [arxml-dbc-consistency](https://github.com/autosar-skills/autosar-agent-skills/tree/main/skills/arxml-dbc-consistency) | ARXML comm-stack × DBC cross-validation: binding, DLC, bit geometry, byte order, init values, PduR routing, TX/RX direction | **none** |
68
+
69
+ Also listed on the Agensi marketplace: **[DBC Matrix Audit](https://www.agensi.io/skills/dbc-matrix-audit)** (free).
70
+ The English packages uploaded there are generated from this repo by
71
+ `tools/pack_marketplace.py`; the same input produces byte-identical output.
72
+
73
+ > Note: `LISTING.md` records the sha256 of the zip **as submitted**. Editing a
74
+ > skill's text afterwards (e.g. `8b27f44` fixed an example README) changes the
75
+ > rebuild hash — that is content changing, not broken reproducibility. To verify,
76
+ > build on the corresponding commit first, then compare.
77
+
78
+ ## dbc-matrix-audit
79
+
80
+ Static auditor for DBC communication matrices: 11 structural checks, **two-revision
81
+ diff**, live frame decoding, and CSV export — standard library only.
82
+
83
+ ```bash
84
+ python skills/dbc-matrix-audit/scripts/dbc_analyze.py info matrix.dbc
85
+ python skills/dbc-matrix-audit/scripts/dbc_analyze.py messages matrix.dbc
86
+ python skills/dbc-matrix-audit/scripts/dbc_analyze.py lint matrix.dbc
87
+ python skills/dbc-matrix-audit/scripts/dbc_analyze.py decode matrix.dbc 0x1D2 1234052a00000000
88
+ python skills/dbc-matrix-audit/scripts/dbc_analyze.py export matrix.dbc --csv inventory.csv
89
+ python skills/dbc-matrix-audit/scripts/dbc_analyze.py diff old.dbc new.dbc
90
+ ```
91
+
92
+ ### Checks
93
+
94
+ | Code | Severity | Meaning |
95
+ |---|---|---|
96
+ | `ENC-001` | error | File is not UTF-8 (typically GBK comments) |
97
+ | `BIT-001` | error | Two signals in one frame occupy the same bit |
98
+ | `RNG-001` | error | Signal extends past the frame length |
99
+ | `DLC-001` | error | Illegal DLC |
100
+ | `ENU-001` | warn | ENUM attribute assigned a numeric index |
101
+ | `SYM-001` | warn | Left/right signal sets (L/R, A/B, FL/FR…) are asymmetric |
102
+ | `TYP-001` | warn | Same signal spelled differently once the side token is removed |
103
+ | `DUP-001` | warn | Signal name reused across frames |
104
+ | `STA-001` | info | Many signals have no `GenSigStartValue` |
105
+ | `NOD-001` | info | Transmitting node not declared in `BU_` |
106
+ | `VAL-001` | info | Short signal (≤4 bit) has no value table |
107
+
108
+ ### Revision diff
109
+
110
+ | Code | Severity | Meaning |
111
+ |---|---|---|
112
+ | `DIF-GEO` | error | Signal bit definition changed |
113
+ | `DIF-DLC` | error | Frame length changed |
114
+ | `DIF-REN` | error | Frame / signal / node renamed |
115
+ | `DIF-ID` | error | Frame with the same name moved to a different CAN ID |
116
+ | `DIF-CRC` | error | DataID inside the checksum comment changed |
117
+ | `DIF-DEL` | warn | Frame or signal deleted |
118
+ | `DIF-SCL` | warn | Factor / offset changed |
119
+ | `DIF-RNG` | warn | Min / max / unit changed |
120
+ | `DIF-VAL` | warn | Value table changed |
121
+ | `DIF-CYC` | warn | Cycle time changed |
122
+ | `DIF-TX` | warn | Transmitting node changed |
123
+ | `DIF-TYP` | warn | Send type changed |
124
+ | `DIF-ADD` | info | Frame or signal added |
125
+ | `DIF-CMT` | info | Comment-only change |
126
+
127
+ Two miss patterns handled deliberately:
128
+
129
+ - **Same name, new ID.** Comparing by ID alone degrades into "one deleted + one
130
+ added", burying the actual cause. The tool pairs by name first and suppresses
131
+ the misleading add/delete pair.
132
+ - **CRC DataID change.** It hides inside a `CM_` comment
133
+ (`CRC16 checksum (DataID: 0x61D2)`), so a plain comment diff reports `info`.
134
+ The tool regex-extracts it and escalates to `error` — every receiver will
135
+ reject the whole frame.
136
+
137
+ Renames are matched by **bit definition** (the name is precisely what changed),
138
+ so `Bus_Off_Count` → `Bus_Off_Cnt` is one `DIF-REN`, not a delete plus an add.
139
+
140
+ ```bash
141
+ # Real case: NM frame moved to a new ID + CRC DataID changed — either one breaks the link
142
+ $ python skills/dbc-matrix-audit/scripts/dbc_analyze.py diff old.dbc new.dbc
143
+ [E] DIF-CRC Node_Info_Checksum: checksum data id changed (0x1D2)
144
+ 0x61D2 -> 0x41D2. Every receiver that validates this CRC will reject
145
+ the frame until it is rebuilt with the new id.
146
+ [E] DIF-ID NM_Autosar_ECU_R: CAN id changed (0x457 -> 0x46B)
147
+ Same name, different address: routing tables and filters still point
148
+ at the old id.
149
+ ```
150
+
151
+ Rule details and **false-positive scenarios**: [references/checks.md](https://github.com/autosar-skills/autosar-agent-skills/blob/main/skills/dbc-matrix-audit/references/checks.md).
152
+
153
+ ### Why not cantools
154
+
155
+ cantools is a good library, but parsing throws away exactly what an audit needs:
156
+
157
+ | Data | cantools | This tool |
158
+ |---|---|---|
159
+ | Cycle time `GenMsgCycleTime` | ✗ | ✓ |
160
+ | Value tables `VAL_` | partial | ✓ |
161
+ | Comments `CM_` | ✗ | ✓ |
162
+ | Frame/signal attributes `BA_` | ✗ | ✓ |
163
+
164
+ cantools also **silently tolerates** GBK byte sequences — parsing appears to
165
+ succeed while every comment is lost. This tool reports `ENC-001` instead.
166
+
167
+ ### Example
168
+
169
+ ```bash
170
+ $ python skills/dbc-matrix-audit/scripts/dbc_analyze.py lint skills/dbc-matrix-audit/examples/demo.dbc
171
+ [I] STA-001 165/167 signals have no GenSigStartValue
172
+ ...
173
+ summary: 0 error, 0 warn, 1 info
174
+
175
+ $ python skills/dbc-matrix-audit/scripts/dbc_analyze.py lint skills/dbc-matrix-audit/examples/demo_broken.dbc
176
+ [E] BIT-001 ACM_B_Supply_Voltage and ACM_B_Temperature occupy overlapping bits (0x201 ACM_B_Status)
177
+ [E] DLC-001 illegal DLC 13 (0x500 Log_Snapshot)
178
+ [E] ENC-001 file is not valid UTF-8 (detected: gbk)
179
+ [E] RNG-001 Log_Word_4 extends past the frame length (0x500 Log_Snapshot)
180
+ [W] DUP-001 signal name Node_Status_Counter appears in 2 frames
181
+ [W] ENU-001 1 ENUM attribute assignments use numeric indices
182
+ [W] SYM-001 ACM_A_Status / ACM_B_Status are not symmetric (0x200 vs 0x201)
183
+ [W] TYP-001 same signal spelled differently (beyond the side token)
184
+ ACM_X_Projection_State vs ACM_X_Projection_statE
185
+ summary: 4 error, 4 warn, 2 info
186
+ ```
187
+
188
+ `examples/demo.dbc` is a clean synthetic matrix; `demo_broken.dbc` plants 10
189
+ classes of defect for demonstration. Both are generated by `tools/gen_demo_dbc.py`,
190
+ which computes bit allocation programmatically — they cannot structurally overlap.
191
+
192
+ ## arxml-dbc-consistency
193
+
194
+ Cross-validates AUTOSAR Classic ECU configuration (Com / PduR / CanIf / CanDrv
195
+ ECUC containers) against a DBC communication matrix. 26 check codes, **standard
196
+ library only**.
197
+
198
+ ```bash
199
+ python skills/arxml-dbc-consistency/scripts/arxml_dbc_check.py probe ecuconfig.xml
200
+ python skills/arxml-dbc-consistency/scripts/arxml_dbc_check.py check ecuconfig.xml matrix.dbc
201
+ python skills/arxml-dbc-consistency/scripts/arxml_dbc_check.py matrix ecuconfig.xml matrix.dbc --csv inventory.csv
202
+ python skills/arxml-dbc-consistency/scripts/arxml_dbc_check.py selftest
203
+ ```
204
+
205
+ `probe` inspects structure first (vendor container names, parameter names, and
206
+ where signals are mounted vary enormously); `check` then compares. `check` exits
207
+ 1 on error, so it drops straight into CI.
208
+
209
+ ### Why name matching cannot work
210
+
211
+ In a real configuration Com and CanIf are **not directly connected**; the only
212
+ sound binding key is the CAN ID:
213
+
214
+ ```
215
+ DBC frame ──CanId──> CanIf PDU ──CanIfXxxPduRef──> EcuC Pdu(X)
216
+ ──PduR routing──> EcuC Pdu(COM_X)
217
+ ──ComPduIdRef──> Com IPdu
218
+ ```
219
+
220
+ `IPDU_COM_TP_Param` has nothing name-wise in common with the DBC frame
221
+ `Diag_CalData`, yet they are the same link
222
+ (`COM_TP_Param → CanTp_TP_Param → 0x9B`). Joining by name is guaranteed wrong.
223
+
224
+ ### There is exactly one correct bit-geometry formula
225
+
226
+ AUTOSAR's `ComBitPosition` always stores the signal **LSB** (flat numbering,
227
+ bit0 = LSB of byte0), **regardless of byte order**. DBC numbers Motorola signals
228
+ in sawtooth form and stores the **MSB**, so first walk back `len-1` steps:
229
+
230
+ ```python
231
+ def motorola_msb_from_lsb(lsb, length):
232
+ pos = lsb
233
+ for _ in range(length - 1):
234
+ pos = pos - 15 if pos % 8 == 7 else pos + 1
235
+ return pos
236
+ ```
237
+
238
+ Measured on a production project: **215/215** signals matched. An earlier version
239
+ assumed "MSB and LSB schools coexist", tried both, and accepted either — that
240
+ design is wrong: a genuine error gets whitewashed by a coincidental match, and
241
+ the measured hit rate was only 153/215.
242
+
243
+ ### A whole-network matrix is not one ECU's view
244
+
245
+ A DBC may describe only this ECU (a dozen frames), or the entire network
246
+ (hundreds of frames, with many other nodes under `BU_:`). In the latter, most
247
+ frames belong to other parties and **this ECU should have no configuration for
248
+ them at all**. The script decides frame by frame — "sender is this ECU, or some
249
+ signal's receiver includes this ECU" — and only raises `error` on relevant frames.
250
+
251
+ On an 11-node, 91-frame matrix, the old "every frame must be configured"
252
+ assumption produced **99 false errors** and buried all 6 real defects.
253
+
254
+ ### Bus coverage
255
+
256
+ An ARXML often drives several CAN buses at once. The script walks back through
257
+ `CanIfBufferCfg → CanIfHthCfg → CanIfHthCanCtrlIdRef` to identify the bus and
258
+ computes each bus's hit rate against the DBC: ≥20% is compared normally, <20% is
259
+ skipped wholesale with an info. The `check` header prints it, and reports must
260
+ quote it verbatim:
261
+
262
+ ```
263
+ bus CANIF_CTR_BCAN 16/21 compared | CANIF_CTR_PCAN 0/32 skipped
264
+ ```
265
+
266
+ ### Reference docs
267
+
268
+ - Chinese: `skills/arxml-dbc-consistency/references/checks.md`
269
+ - English: `skills/arxml-dbc-consistency/references/checks.en.md`
270
+ - English SKILL.md (for marketplace packages): `packaging/agensi/arxml-dbc-consistency/SKILL.md`
271
+
272
+ ## Documentation site
273
+
274
+ Rendered docs with full schema markup: https://autosar-skills.github.io/autosar-agent-skills/
275
+
276
+ ## Install
277
+
278
+ ```bash
279
+ git clone https://github.com/autosar-skills/autosar-agent-skills.git
280
+ cd autosar-agent-skills
281
+ python -m unittest discover -s tests # 65 tests, standard library only
282
+ ```
283
+
284
+ No `pip install` required — the scripts run from the clone as-is. If you want
285
+ the short commands on your PATH:
286
+
287
+ ```bash
288
+ pip install dbc-matrix-audit
289
+ dbc-analyze lint matrix.dbc # DBC auditor
290
+ arxml-dbc-check check cfg.arxml matrix.dbc # ARXML x DBC cross-check
291
+ ```
292
+
293
+ > Note: `dbc-analyze` output and help are English. `arxml-dbc-check` currently
294
+ > emits Chinese messages — the audit vocabulary (bit geometry, PduR routing,
295
+ > FD flags) is identical, but the prose is not translated yet.
296
+
297
+ ## Using as an agent skill
298
+
299
+ `skills/<name>/SKILL.md` follows the general AgentSkill format. Put the whole
300
+ `skills/<name>/` directory on the agent's skill path; scripts are invoked by the
301
+ relative path `scripts/dbc_analyze.py`.
302
+
303
+ SKILL.md is a **runbook for the agent** (mode detection → execution order →
304
+ output interpretation), not human documentation. This README is the human-facing
305
+ half. The split:
306
+
307
+ | Location | Reader | Contents |
308
+ |---|---|---|
309
+ | `README.md` / `README.en.md` | humans | Why it is designed this way, what rules mean, sample output |
310
+ | `SKILL.md` | agent | Step 0–4 workflow, commands, reporting format |
311
+ | `references/checks.md` | loaded on demand | Per-rule decision detail and false-positive scenarios |
312
+
313
+ OpenClaw users:
314
+
315
+ ```bash
316
+ openclaw skills install skills/dbc-matrix-audit # first install
317
+ openclaw skills install --force skills/dbc-matrix-audit # re-sync after repo changes
318
+ openclaw skills info dbc-matrix-audit # confirm Ready
319
+ ```
320
+
321
+ Installation **copies** the directory into `~/.openclaw/workspace/skills/`, so a
322
+ repo update requires re-running with `--force`.
323
+
324
+ ## Repository layout
325
+
326
+ ```
327
+ skills/dbc-matrix-audit/
328
+ ├── SKILL.md agent runbook (Chinese: mode / flow / reporting)
329
+ ├── scripts/dbc_analyze.py implementation (single file, standard library)
330
+ ├── examples/ synthetic fixtures (clean / seeded), shipped with the skill
331
+ └── references/ rule detail, encoding notes, DBC syntax
332
+ skills/arxml-dbc-consistency/
333
+ ├── SKILL.md bilingual runbook (mode / flow / reporting)
334
+ ├── README.md English description (repo and marketplace)
335
+ ├── scripts/arxml_dbc_check.py implementation (single file, standard library)
336
+ ├── scripts/demo_fixtures.py program-generated fixtures (topology must match production)
337
+ ├── scripts/test_contract.py bidirectional assertion: documented codes ↔ emitted codes
338
+ └── references/ checks.md (zh) / checks.en.md (en)
339
+ tools/gen_demo_dbc.py fixture generator
340
+ tools/pack_marketplace.py marketplace packager (reproducible, structure-checked)
341
+ tests/ 65 unit tests (including diff-specific)
342
+ packaging/agensi/ listing material: English SKILL.md / README overlays, copy archive, logo
343
+ CHANGELOG.md version history
344
+ dist/ build output (gitignored, regenerate with the scripts above)
345
+ ```
346
+
347
+ ### Marketplace packaging
348
+
349
+ ```bash
350
+ python3 tools/pack_marketplace.py # → dist/agensi/dbc-matrix-audit.zip
351
+ python3 tools/pack_marketplace.py --skill arxml-dbc-consistency # → dist/agensi/arxml-dbc-consistency.zip
352
+ python3 tools/pack_marketplace.py --check # validate without writing
353
+ ```
354
+
355
+ `SKILL.md` / `README.md` under `packaging/<market>/<skill>/` override the Chinese
356
+ originals; every other file comes from `skills/<name>/`. The flat layout
357
+ `packaging/<market>/` is still supported for older skills — only its top-level
358
+ files are read, so a sibling skill's overlay cannot leak in. The packager strips
359
+ `__pycache__`, binaries, dotfiles and symlinks, and validates "single top-level
360
+ folder + SKILL.md at its root + README present", failing otherwise. Entries are
361
+ sorted with fixed timestamps, so repeated builds are byte-identical.
362
+
363
+ ## License
364
+
365
+ MIT. All sample DBC files are fictional and contain no real vehicle model,
366
+ supplier, or personnel information.
367
+
368
+ ## Background
369
+
370
+ Design rationale and the debugging story behind these tools:
371
+ [How I designed an engineering-grade skill for AI agents](https://me.tech-harry.top/blog/dbc-matrix-audit-skill.html) ·
372
+ [105 errors, 99 of them fake](https://me.tech-harry.top/blog/arxml-dbc-consistency.html)