@csselectronics/can-decode 0.0.0-stage → 0.1.0
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.
- package/LICENSE +36 -0
- package/README.md +29 -2
- package/index.d.ts +101 -0
- package/index.js +2 -0
- package/models/CanTypes.d.ts +133 -0
- package/models/CanTypes.js +2 -0
- package/models/DecodedSignal.d.ts +11 -0
- package/models/DecodedSignal.js +1 -0
- package/models/dbc/BusDbcAssignment.d.ts +45 -0
- package/models/dbc/BusDbcAssignment.js +2 -0
- package/models/dbc/DbcDefinition.d.ts +117 -0
- package/models/dbc/DbcDefinition.js +2 -0
- package/models/dbc/DbcUnion.d.ts +92 -0
- package/models/dbc/DbcUnion.js +2 -0
- package/models/dbc/IDbcDefinition.d.ts +72 -0
- package/models/dbc/IDbcDefinition.js +1 -0
- package/package.json +33 -4
- package/services/pipeline/DecodingEngine.d.ts +107 -0
- package/services/pipeline/DecodingEngine.js +2 -0
- package/services/pipeline/DecodingService.d.ts +52 -0
- package/services/pipeline/DecodingService.js +2 -0
- package/services/pipeline/dbc/DbcAssignmentService.d.ts +84 -0
- package/services/pipeline/dbc/DbcAssignmentService.js +2 -0
- package/services/pipeline/dbc/DbcManagerService.d.ts +95 -0
- package/services/pipeline/dbc/DbcManagerService.js +2 -0
- package/utils/DbcParser.d.ts +26 -0
- package/utils/DbcParser.js +2 -0
- package/utils/JsonParser.d.ts +25 -0
- package/utils/JsonParser.js +2 -0
- package/utils/SignalDecoder.d.ts +38 -0
- package/utils/SignalDecoder.js +2 -0
- package/utils/SignalEncoder.d.ts +46 -0
- package/utils/SignalEncoder.js +2 -0
- package/utils/SignalIdParser.d.ts +41 -0
- package/utils/SignalIdParser.js +2 -0
- package/utils/dbcKey.d.ts +1 -0
- package/utils/dbcKey.js +2 -0
- package/utils/downsampleMinMax.d.ts +8 -0
- package/utils/downsampleMinMax.js +2 -0
- package/utils/signalQuery.d.ts +45 -0
- package/utils/signalQuery.js +2 -0
- package/utils/signalReductions.d.ts +23 -0
- package/utils/signalReductions.js +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Copyright CSS Electronics ApS. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to use,
|
|
5
|
+
copy, modify, and distribute the Software, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
1. HARDWARE RESTRICTION. The Software, including any modified versions,
|
|
8
|
+
derivative works, or substantially similar implementations based on or
|
|
9
|
+
derived from the Software, may only be used in conjunction with hardware
|
|
10
|
+
products manufactured or sold by CSS Electronics ApS (including but not
|
|
11
|
+
limited to CANsub, CANmod, CANedge, and CLX000 devices).
|
|
12
|
+
|
|
13
|
+
2. PROHIBITED USE. Use of the Software, or any modified version, adaptation,
|
|
14
|
+
translation, or derivative work based on or incorporating any portion of
|
|
15
|
+
the Software, with hardware or software products not manufactured or sold
|
|
16
|
+
by CSS Electronics ApS is expressly prohibited without prior written
|
|
17
|
+
consent from CSS Electronics ApS.
|
|
18
|
+
|
|
19
|
+
3. DERIVATIVE WORKS. Any modified version or derivative work of the Software
|
|
20
|
+
remains subject to all terms and conditions of this license. The hardware
|
|
21
|
+
restriction in Section 1 applies regardless of the extent of modification,
|
|
22
|
+
refactoring, or reimplementation.
|
|
23
|
+
|
|
24
|
+
4. COMPILED FORMS. Portions of the Software that CSS Electronics ApS
|
|
25
|
+
distributes only in compiled or minified form may not be decompiled,
|
|
26
|
+
de-minified, or otherwise reverse engineered.
|
|
27
|
+
|
|
28
|
+
5. NOTICE. This copyright notice and permission notice shall be included in
|
|
29
|
+
all copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
34
|
+
CSS ELECTRONICS APS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
35
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
36
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @csselectronics/can-decode
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DBC parsing and CAN signal decoding for CANsub frame streams: Load DBC files, assign them per CAN bus and decode signals from `CanFrame`s in real time.
|
|
4
|
+
|
|
5
|
+
Part of the [CANsub JS SDK](https://github.com/CSS-Electronics/js-sdk-cansub), which has a starter app and runnable examples (see `signal-chart`). Published in compiled form; the type definitions document the API.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install @csselectronics/can-decode
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What's included
|
|
12
|
+
|
|
13
|
+
| Export (module) | Purpose |
|
|
14
|
+
|---|---|
|
|
15
|
+
| `DbcDefinition` (`models/dbc/DbcDefinition`) | One parsed DBC file: `fromFile` / `fromDBC`, `getMessageInfo(id, isExtended)`, `listMessages()`, `getSignalInfo(message, name)` |
|
|
16
|
+
| `DbcUnion` (`models/dbc/DbcUnion`) | Several DBC files as one definition; the first file with a matching ID wins |
|
|
17
|
+
| `CanMessage`, `CanSignal` (`models/CanTypes`) | Message and signal definitions: name, ID, signals, bit layout, factor, offset, unit, value table |
|
|
18
|
+
| `DecodingEngine` (`services/pipeline/DecodingEngine`) | Decodes frames: `setDefinition(bus, definition)`, `decodeFrame(frame)`. Results are read with `frame.getSignalKeys()` / `frame.getSignalValue(key)` |
|
|
19
|
+
| `DecodingService` (`services/pipeline/DecodingService`) | `DecodingEngine` driven by the per-bus DBC assignment, registering new signals with `FilterSelectionService` |
|
|
20
|
+
| `DbcManagerService` (`services/pipeline/dbc/DbcManagerService`) | The pool of loaded DBC files: `loadLocal`, `replaceLocal`, `removeLocal` |
|
|
21
|
+
| `DbcAssignmentService` (`services/pipeline/dbc/DbcAssignmentService`) | DBC files per bus, in priority order: `initBuses`, `getAssignment(bus).dbcFilenames`, `resolveForBus` |
|
|
22
|
+
| `encodeSignalInto`, `physicalToRaw`, `theoreticalRange` (`utils/SignalEncoder`) | Write physical signal values into frame data bytes, e.g. to transmit a DBC message |
|
|
23
|
+
| `querySignals` (`utils/signalQuery`) | Signal values from a frame store over a time window, downsampled (min/max) for plotting |
|
|
24
|
+
| `parseSignalId` (`utils/SignalIdParser`) | Split a signal key (`<frame key>_<signal name>`) into bus, ID, flags and signal name |
|
|
25
|
+
|
|
26
|
+
Uses `@csselectronics/websocket-client` for frames and bus types, `@csselectronics/can-types` for the decoding types and `@csselectronics/can-pipeline` for signal registration. The services hold state only: Your app decides how to persist DBC files and assignments.
|
|
27
|
+
|
|
28
|
+
## Licence
|
|
29
|
+
|
|
30
|
+
For use with CSS Electronics hardware only. See `LICENSE`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @csselectronics/can-decode - CAN Signal Decoding Engine
|
|
3
|
+
*
|
|
4
|
+
* DBC parsing, bit-level signal extraction and encoding, and per-bus DBC assignment.
|
|
5
|
+
* Depends on `@csselectronics/websocket-client` for `CanFrame` + bus types, on
|
|
6
|
+
* `@csselectronics/can-types` for the decoding types and on `@csselectronics/can-pipeline`
|
|
7
|
+
* for `FilterSelectionService` (signal registration).
|
|
8
|
+
*
|
|
9
|
+
* ## Decode with one DBC, no services
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { DbcDefinition, DecodingEngine } from '@csselectronics/can-decode';
|
|
13
|
+
*
|
|
14
|
+
* const engine = new DecodingEngine();
|
|
15
|
+
* engine.setDefinition('CAN1', DbcDefinition.fromFile(dbcText, 'vehicle.dbc'));
|
|
16
|
+
*
|
|
17
|
+
* bridge.onBatch(frames => {
|
|
18
|
+
* for (const frame of frames) {
|
|
19
|
+
* engine.decodeFrame(frame);
|
|
20
|
+
* const keys = frame.getSignalKeys(); // e.g. 'CAN1_291_IDE0_DIR0_RTR0_TP0_VehicleSpeed'
|
|
21
|
+
* for (let i = 0; i < keys.length; i++) console.log(keys[i], frame.getSignalValueByIndex(i));
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* ## Several DBC files per bus, with signal registration
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { DbcManagerService, DbcAssignmentService, DecodingService } from '@csselectronics/can-decode';
|
|
30
|
+
*
|
|
31
|
+
* const dbcFiles = new DbcManagerService(); // the pool of loaded files (state only)
|
|
32
|
+
* const dbcAssignment = new DbcAssignmentService(dbcFiles); // files per bus, in priority order
|
|
33
|
+
* const decoding = new DecodingService(dbcAssignment, filterSelection);
|
|
34
|
+
*
|
|
35
|
+
* dbcAssignment.initBuses([1, 2], connection); // after reading the device's channels
|
|
36
|
+
* dbcFiles.loadLocal('vehicle.dbc', dbcText);
|
|
37
|
+
* dbcAssignment.getAssignment('CAN1')!.dbcFilenames.value = ['vehicle.dbc'];
|
|
38
|
+
*
|
|
39
|
+
* // Per frame, in this order: register the message, decode, then store.
|
|
40
|
+
* filterSelection.registerMessage(f.bus, f.arbitration_id, f.ide, f.is_rtr, f.is_tx, f.is_error, f.synthetic);
|
|
41
|
+
* decoding.decodeFrame(f);
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* The assignment resolves when a bus connects. To change it on a connected bus, call
|
|
45
|
+
* `dbcAssignment.resolveForBus(bus)` and `decoding.clearRegistrationCache()`.
|
|
46
|
+
* The services hold state only: The app persists DBC files and assignments.
|
|
47
|
+
*
|
|
48
|
+
* @module
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* Immutable signal definition parsed from a DBC or JSON file.
|
|
52
|
+
* Describes the bit layout, scaling, and metadata for one signal.
|
|
53
|
+
*/
|
|
54
|
+
export { CanSignal, CanMessage } from './models/CanTypes.js';
|
|
55
|
+
/** A single decoded value paired with its signal definition. */
|
|
56
|
+
export type { DecodedSignal } from './models/DecodedSignal.js';
|
|
57
|
+
/**
|
|
58
|
+
* Common interface implemented by DbcDefinition and DbcUnion.
|
|
59
|
+
* Pass to DecodingEngine.setDefinition() or DecodingEngine.decodeFrame().
|
|
60
|
+
*/
|
|
61
|
+
export type { IDbcDefinition, DbcMetadata } from './models/dbc/IDbcDefinition.js';
|
|
62
|
+
/** Single-file DBC definition. Use DbcUnion to merge multiple files. */
|
|
63
|
+
export { DbcDefinition } from './models/dbc/DbcDefinition.js';
|
|
64
|
+
/**
|
|
65
|
+
* Merges multiple IDbcDefinition instances with priority ordering.
|
|
66
|
+
* First definition with a matching message ID wins (sequential lookup).
|
|
67
|
+
*/
|
|
68
|
+
export { DbcUnion } from './models/dbc/DbcUnion.js';
|
|
69
|
+
/**
|
|
70
|
+
* Pure decoding core — no Preact signals or service dependencies.
|
|
71
|
+
* Use directly if you don't need the reactive service layer.
|
|
72
|
+
*/
|
|
73
|
+
export { DecodingEngine, UNMATCHED } from './services/pipeline/DecodingEngine.js';
|
|
74
|
+
export type { SignalDecodedCallback } from './services/pipeline/DecodingEngine.js';
|
|
75
|
+
/**
|
|
76
|
+
* High-level decoding service that wraps DecodingEngine and wires
|
|
77
|
+
* signal discovery to FilterSelectionService.
|
|
78
|
+
*/
|
|
79
|
+
export { DecodingService } from './services/pipeline/DecodingService.js';
|
|
80
|
+
/**
|
|
81
|
+
* The pool of loaded DBC files: loads and validates them. Holds state only; the app persists them.
|
|
82
|
+
* Provides the pool of available definitions that DbcAssignmentService draws from.
|
|
83
|
+
*/
|
|
84
|
+
export { DbcManagerService } from './services/pipeline/dbc/DbcManagerService.js';
|
|
85
|
+
export type { LoadedDefinition } from './services/pipeline/dbc/DbcManagerService.js';
|
|
86
|
+
/**
|
|
87
|
+
* Maps each CAN bus to an IDbcDefinition.
|
|
88
|
+
* Call getResolvedDefinition(bus) to get the active definition for a bus.
|
|
89
|
+
*/
|
|
90
|
+
export { DbcAssignmentService } from './services/pipeline/dbc/DbcAssignmentService.js';
|
|
91
|
+
/**
|
|
92
|
+
* Parse a Vector CANdb++ DBC file into an IDbcDefinition.
|
|
93
|
+
* Supports multiplexing, J1939 attributes, signal comments, and value tables.
|
|
94
|
+
*/
|
|
95
|
+
export { parseDBC } from './utils/DbcParser.js';
|
|
96
|
+
/**
|
|
97
|
+
* Bit-level signal encoding utilities — the inverse of SignalDecoder.
|
|
98
|
+
* Used by the transmit-side "Encode from DBC" flow to turn physical
|
|
99
|
+
* signal values into raw CAN data bytes.
|
|
100
|
+
*/
|
|
101
|
+
export { putBitsLittleEndian, putBitsBigEndian, putFloat32, putFloat64, physicalToRaw, encodeSignalInto, theoreticalRange, } from './utils/SignalEncoder.js';
|
package/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @csselectronics/can-decode v0.1.0 (c) CSS Electronics ApS, see LICENSE */
|
|
2
|
+
import{CanSignal as i,CanMessage as n}from"./models/CanTypes.js";import{DbcDefinition as r}from"./models/dbc/DbcDefinition.js";import{DbcUnion as p}from"./models/dbc/DbcUnion.js";import{DecodingEngine as D,UNMATCHED as d}from"./services/pipeline/DecodingEngine.js";import{DecodingService as g}from"./services/pipeline/DecodingService.js";import{DbcManagerService as m}from"./services/pipeline/dbc/DbcManagerService.js";import{DbcAssignmentService as x}from"./services/pipeline/dbc/DbcAssignmentService.js";import{parseDBC as S}from"./utils/DbcParser.js";import{putBitsLittleEndian as y,putBitsBigEndian as C,putFloat32 as E,putFloat64 as M,physicalToRaw as u,encodeSignalInto as B,theoreticalRange as I}from"./utils/SignalEncoder.js";export{n as CanMessage,i as CanSignal,x as DbcAssignmentService,r as DbcDefinition,m as DbcManagerService,p as DbcUnion,D as DecodingEngine,g as DecodingService,d as UNMATCHED,B as encodeSignalInto,S as parseDBC,u as physicalToRaw,C as putBitsBigEndian,y as putBitsLittleEndian,E as putFloat32,M as putFloat64,I as theoreticalRange};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ICanMessage, ICanSignal } from '@csselectronics/can-types/types/DecodingTypes';
|
|
2
|
+
import type { DecodedSignal } from './DecodedSignal.js';
|
|
3
|
+
/**
|
|
4
|
+
* CanSignal - Immutable signal definition from a DBC/JSON file.
|
|
5
|
+
* Used as singleton references in Maps/Sets.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CanSignal implements ICanSignal {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly bitpos: number;
|
|
10
|
+
readonly bitlen: number;
|
|
11
|
+
readonly bigendian: boolean;
|
|
12
|
+
readonly signed: boolean;
|
|
13
|
+
readonly factor: number;
|
|
14
|
+
readonly offset: number;
|
|
15
|
+
readonly min: number;
|
|
16
|
+
readonly max: number;
|
|
17
|
+
readonly unit: string;
|
|
18
|
+
readonly ignored: boolean;
|
|
19
|
+
readonly lineNo: number;
|
|
20
|
+
readonly isFloat?: boolean;
|
|
21
|
+
readonly isDouble?: boolean;
|
|
22
|
+
readonly isMultiplexer?: boolean;
|
|
23
|
+
readonly isRootMultiplexer?: boolean;
|
|
24
|
+
readonly isMuxedChild?: boolean;
|
|
25
|
+
readonly valueTable?: Map<number, string>;
|
|
26
|
+
readonly multiplexedSignals?: Map<number, CanSignal[]>;
|
|
27
|
+
/** Minimum data bytes required for this signal to be fully contained in a frame */
|
|
28
|
+
readonly requiredBytes: number;
|
|
29
|
+
/** True when factor===1 && offset===0 - allows skipping multiply+add in decode hot path */
|
|
30
|
+
readonly isIdentityScale: boolean;
|
|
31
|
+
/** DBC `CM_ SG_` description, capped at parse time; not read while decoding. Declared, never
|
|
32
|
+
* conditionally assigned, so all instances share one hidden class - see CanTypes.shape.test.ts. */
|
|
33
|
+
readonly comment?: string;
|
|
34
|
+
constructor(params: {
|
|
35
|
+
name: string;
|
|
36
|
+
bitpos: number;
|
|
37
|
+
bitlen: number;
|
|
38
|
+
bigendian: boolean;
|
|
39
|
+
signed: boolean;
|
|
40
|
+
factor: number;
|
|
41
|
+
offset: number;
|
|
42
|
+
min: number;
|
|
43
|
+
max: number;
|
|
44
|
+
unit: string;
|
|
45
|
+
ignored: boolean;
|
|
46
|
+
lineNo: number;
|
|
47
|
+
isFloat?: boolean;
|
|
48
|
+
isDouble?: boolean;
|
|
49
|
+
isMultiplexer?: boolean;
|
|
50
|
+
isRootMultiplexer?: boolean;
|
|
51
|
+
isMuxedChild?: boolean;
|
|
52
|
+
valueTable?: Map<number, string>;
|
|
53
|
+
multiplexedSignals?: Map<number, CanSignal[]>;
|
|
54
|
+
comment?: string;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* CanMessage - Immutable message definition from a DBC/JSON file.
|
|
59
|
+
* Used as singleton references in Maps/Sets.
|
|
60
|
+
*/
|
|
61
|
+
export declare class CanMessage implements ICanMessage {
|
|
62
|
+
readonly key: number;
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly length: number;
|
|
65
|
+
readonly isExtended: boolean;
|
|
66
|
+
/** The CAN ID as written in the DBC (no IDE bit). Equals `key` except for J1939 DBCs, whose `key` is PGN-masked. */
|
|
67
|
+
readonly dbcId: number;
|
|
68
|
+
readonly isMultiplexed: boolean;
|
|
69
|
+
readonly multiplexorSignal?: CanSignal;
|
|
70
|
+
/**
|
|
71
|
+
* True if this message has variable-length payload (e.g. J1939 DM1).
|
|
72
|
+
* Decoded via the `decodeNonMuxVariable` path: per-frame keys/values, signals
|
|
73
|
+
* whose `requiredBytes > frame.data.length` are omitted entirely (no NaN-fill,
|
|
74
|
+
* no `onSignalDecoded`). Set via the `BA_ "VariableLength" BO_ <id> 1;` DBC attribute.
|
|
75
|
+
*/
|
|
76
|
+
readonly isVariableLength: boolean;
|
|
77
|
+
readonly lineNo?: number;
|
|
78
|
+
/** DBC per-message attributes (`BA_ "Name" BO_ <id> "Value";`). Empty when none. */
|
|
79
|
+
readonly attributes: ReadonlyMap<string, string | number>;
|
|
80
|
+
readonly signals: Map<string, CanSignal>;
|
|
81
|
+
private readonly _signalsArray;
|
|
82
|
+
private readonly _topLevelSignalsArray;
|
|
83
|
+
/** DBC `CM_ BO_` description, capped at parse time; display-only. See CanSignal.comment. */
|
|
84
|
+
readonly comment?: string;
|
|
85
|
+
/** Flat array of all signals (plain + multiplexors + muxed children). For enumeration; do not traverse for decoding. */
|
|
86
|
+
get signalsArray(): readonly CanSignal[];
|
|
87
|
+
/**
|
|
88
|
+
* Top-level signals only — plain signals plus the root multiplexor (and any further top-level multiplexors).
|
|
89
|
+
* Muxed children are reached recursively via `multiplexorSignal.multiplexedSignals`. Decode/encode
|
|
90
|
+
* dispatch starts here, then recurses into the active mux branch.
|
|
91
|
+
*/
|
|
92
|
+
get topLevelSignalsArray(): readonly CanSignal[];
|
|
93
|
+
constructor(params: {
|
|
94
|
+
key: number;
|
|
95
|
+
name: string;
|
|
96
|
+
length: number;
|
|
97
|
+
isExtended: boolean;
|
|
98
|
+
dbcId?: number;
|
|
99
|
+
isMultiplexed: boolean;
|
|
100
|
+
isVariableLength?: boolean;
|
|
101
|
+
multiplexorSignal?: CanSignal;
|
|
102
|
+
lineNo?: number;
|
|
103
|
+
signals?: CanSignal[];
|
|
104
|
+
attributes?: ReadonlyMap<string, string | number>;
|
|
105
|
+
comment?: string;
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* Get a signal by name
|
|
109
|
+
*/
|
|
110
|
+
getSignal(name: string): CanSignal | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Check if message has any multiplexed signals
|
|
113
|
+
*/
|
|
114
|
+
get hasMultiplexing(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Format CAN ID as hex string
|
|
117
|
+
* @returns "0x123" for standard IDs (3 hex digits), "0x00001234" for extended IDs (8 hex digits)
|
|
118
|
+
*/
|
|
119
|
+
getIdFormatted(): string;
|
|
120
|
+
/**
|
|
121
|
+
* Decode all active signals from raw CAN data.
|
|
122
|
+
*
|
|
123
|
+
* Starts from the message's top-level signals (plain signals + multiplexor entry points),
|
|
124
|
+
* decodes each unconditionally, and for any signal that is a multiplexor recurses into its
|
|
125
|
+
* active child by decoded value. Plain signals coexisting with multiplexors in the same
|
|
126
|
+
* message decode every frame regardless of mux value.
|
|
127
|
+
*
|
|
128
|
+
* @param data - Raw CAN data bytes
|
|
129
|
+
* @returns Array of decoded signals (plain + active mux chain)
|
|
130
|
+
*/
|
|
131
|
+
decodeSignals(frame: Uint8Array): DecodedSignal[];
|
|
132
|
+
private decodeLevel;
|
|
133
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @csselectronics/can-decode v0.1.0 (c) CSS Electronics ApS, see LICENSE */
|
|
2
|
+
var d=Object.defineProperty;var a=(o,e)=>d(o,"name",{value:e,configurable:!0});import{decodeSignal as g}from"../utils/SignalDecoder.js";import{formatCanId as u}from"@csselectronics/websocket-client/utils/DataFormatter";class c{static{a(this,"CanSignal")}name;bitpos;bitlen;bigendian;signed;factor;offset;min;max;unit;ignored;lineNo;isFloat;isDouble;isMultiplexer;isRootMultiplexer;isMuxedChild;valueTable;multiplexedSignals;requiredBytes;isIdentityScale;comment;constructor(e){if(this.name=e.name,this.bitpos=e.bitpos,this.bitlen=e.bitlen,this.bigendian=e.bigendian,this.signed=e.signed,this.factor=e.factor,this.offset=e.offset,this.min=e.min,this.max=e.max,this.unit=e.unit,this.ignored=e.ignored,this.lineNo=e.lineNo,this.isFloat=e.isFloat,this.isDouble=e.isDouble,this.isMultiplexer=e.isMultiplexer,this.isRootMultiplexer=e.isRootMultiplexer,this.isMuxedChild=e.isMuxedChild,this.valueTable=e.valueTable,this.multiplexedSignals=e.multiplexedSignals,this.isIdentityScale=this.factor===1&&this.offset===0,this.isFloat)this.requiredBytes=Math.floor(this.bitpos/8)+4;else if(this.isDouble)this.requiredBytes=Math.floor(this.bitpos/8)+8;else if(this.bigendian){const i=8*Math.floor(this.bitpos/8)+(7-this.bitpos%8);this.requiredBytes=Math.floor((i+this.bitlen-1)/8)+1}else this.requiredBytes=Math.floor((this.bitpos+this.bitlen-1)/8)+1;this.comment=e.comment}}class m{static{a(this,"CanMessage")}key;name;length;isExtended;dbcId;isMultiplexed;multiplexorSignal;isVariableLength;lineNo;attributes;signals;_signalsArray;_topLevelSignalsArray;comment;get signalsArray(){return this._signalsArray}get topLevelSignalsArray(){return this._topLevelSignalsArray}constructor(e){if(this.key=e.key,this.name=e.name,this.length=e.length,this.isExtended=e.isExtended,this.dbcId=e.dbcId??e.key,this.isMultiplexed=e.isMultiplexed,this.isVariableLength=e.isVariableLength??!1,this.multiplexorSignal=e.multiplexorSignal,this.lineNo=e.lineNo,this.attributes=e.attributes??new Map,this.signals=new Map,e.signals)for(const i of e.signals)i.bitlen>32&&!i.isFloat&&!i.isDouble||this.signals.set(i.name,i);if(this._signalsArray=Array.from(this.signals.values()),!e.isMultiplexed)this._topLevelSignalsArray=this._signalsArray;else{const i=new Set;for(const l of this._signalsArray)if(l.isMultiplexer&&l.multiplexedSignals)for(const n of l.multiplexedSignals.values())for(const t of n)i.add(t);this._topLevelSignalsArray=i.size>0?this._signalsArray.filter(l=>!i.has(l)):this._signalsArray}this.comment=e.comment}getSignal(e){return this.signals.get(e)}get hasMultiplexing(){return!!this.multiplexorSignal}getIdFormatted(){return u(this.key,this.isExtended)}decodeSignals(e){const i=[];return this.decodeLevel(e,this._topLevelSignalsArray,i),i}decodeLevel(e,i,l){for(const n of i){if(n.bitlen>32&&!n.isFloat&&!n.isDouble)continue;const t=g(e,n);if(n.ignored||l.push(t),n.isMultiplexer&&n.multiplexedSignals){const r=n.isIdentityScale?t.value:Math.round((t.value-n.offset)/n.factor),s=n.multiplexedSignals.get(r);s&&s.length>0&&this.decodeLevel(e,s,l)}}}}export{m as CanMessage,c as CanSignal};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CanSignal } from './CanTypes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Decoded signal value with signal reference.
|
|
4
|
+
*
|
|
5
|
+
* Result of decoding a single signal from a CAN frame.
|
|
6
|
+
* The signal reference avoids redundant Map lookups in the decode pipeline.
|
|
7
|
+
*/
|
|
8
|
+
export interface DecodedSignal {
|
|
9
|
+
signal: CanSignal;
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! @csselectronics/can-decode v0.1.0 (c) CSS Electronics ApS, see LICENSE */
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Signal } from '@preact/signals-core';
|
|
2
|
+
import type { CanBusName } from '@csselectronics/websocket-client/types/CanBusTypes';
|
|
3
|
+
import type { IDbcDefinition } from './IDbcDefinition.js';
|
|
4
|
+
/**
|
|
5
|
+
* BusDbcAssignment - DBC file assignment for a single CAN bus.
|
|
6
|
+
*
|
|
7
|
+
* Holds ordered DBC filenames (reactive, persisted to localStorage)
|
|
8
|
+
* and the runtime-resolved definition (set on connect, cleared on disconnect).
|
|
9
|
+
*/
|
|
10
|
+
export declare class BusDbcAssignment {
|
|
11
|
+
/**
|
|
12
|
+
* Bus identifier (immutable)
|
|
13
|
+
*/
|
|
14
|
+
readonly busName: CanBusName;
|
|
15
|
+
/**
|
|
16
|
+
* DBC filenames (in priority order) - reactive signal
|
|
17
|
+
* First filename has highest priority for signal decoding
|
|
18
|
+
* User-editable while disconnected, auto-saved to localStorage
|
|
19
|
+
*/
|
|
20
|
+
readonly dbcFilenames: Signal<string[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Resolved definition (plain property, not signal)
|
|
23
|
+
* Set during connect (from dbcFilenames), cleared on disconnect
|
|
24
|
+
* Read by services per-frame for decoding
|
|
25
|
+
*/
|
|
26
|
+
private _resolvedDefinition;
|
|
27
|
+
constructor(busName: CanBusName, dbcFilenames?: string[]);
|
|
28
|
+
/**
|
|
29
|
+
* Add a DBC filename (appends to end of priority list)
|
|
30
|
+
*/
|
|
31
|
+
addFilename(filename: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Remove a DBC filename
|
|
34
|
+
*/
|
|
35
|
+
removeFilename(filename: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get resolved definition (set during connect, cleared on disconnect)
|
|
38
|
+
* Called by services per-frame for decoding
|
|
39
|
+
*/
|
|
40
|
+
getResolvedDefinition(): IDbcDefinition | null;
|
|
41
|
+
/**
|
|
42
|
+
* Set resolved definition (called by DbcAssignmentService during connect)
|
|
43
|
+
*/
|
|
44
|
+
setResolvedDefinition(definition: IDbcDefinition | null): void;
|
|
45
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @csselectronics/can-decode v0.1.0 (c) CSS Electronics ApS, see LICENSE */
|
|
2
|
+
var t=Object.defineProperty;var s=(n,i)=>t(n,"name",{value:i,configurable:!0});import{signal as l}from"@preact/signals-core";class r{static{s(this,"BusDbcAssignment")}busName;dbcFilenames;_resolvedDefinition=null;constructor(i,e=[]){this.busName=i,this.dbcFilenames=l(e)}addFilename(i){const e=this.dbcFilenames.value;e.includes(i)||(this.dbcFilenames.value=[...e,i])}removeFilename(i){this.dbcFilenames.value=this.dbcFilenames.value.filter(e=>e!==i)}getResolvedDefinition(){return this._resolvedDefinition}setResolvedDefinition(i){this._resolvedDefinition=i}}export{r as BusDbcAssignment};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { CanMessage, CanSignal } from '../CanTypes.js';
|
|
2
|
+
import type { IDbcDefinition, DbcMetadata } from './IDbcDefinition.js';
|
|
3
|
+
/**
|
|
4
|
+
* DbcDefinition - CAN message and signal database from a single DBC/JSON file.
|
|
5
|
+
*
|
|
6
|
+
* Implements IDbcDefinition for polymorphic use with DbcUnion.
|
|
7
|
+
* Supports multiplexed messages and J1939 PGN masking.
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const def = DbcDefinition.fromDBC(dbcText, 'engine.dbc');
|
|
11
|
+
* const msg = def.getMessageInfo(0x100);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class DbcDefinition implements IDbcDefinition {
|
|
15
|
+
private readonly messages;
|
|
16
|
+
private readonly metadata;
|
|
17
|
+
/**
|
|
18
|
+
* Human-readable name (typically the filename)
|
|
19
|
+
*/
|
|
20
|
+
get name(): string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new CAN data definition instance
|
|
23
|
+
*
|
|
24
|
+
* @param messages - Map of message ID to CanMessage definitions
|
|
25
|
+
* @param metadata - Optional partial metadata (will be auto-filled)
|
|
26
|
+
* @throws {Error} If messages structure is invalid
|
|
27
|
+
*/
|
|
28
|
+
constructor(messages: Map<number, CanMessage>, metadata?: Partial<DbcMetadata>);
|
|
29
|
+
/**
|
|
30
|
+
* Create DbcDefinition from file content (auto-detects format by extension)
|
|
31
|
+
*
|
|
32
|
+
* @param content - Raw file content
|
|
33
|
+
* @param fileName - File name (used to detect format and for reference)
|
|
34
|
+
* @returns New DbcDefinition instance
|
|
35
|
+
* @throws {Error} If parsing fails or format is unsupported
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const cdd = DbcDefinition.fromFile(content, 'engine.dbc');
|
|
39
|
+
* const cdd2 = DbcDefinition.fromFile(content, 'chassis.json');
|
|
40
|
+
*/
|
|
41
|
+
static fromFile(content: string, fileName: string): DbcDefinition;
|
|
42
|
+
/**
|
|
43
|
+
* Create DbcDefinition from DBC file content
|
|
44
|
+
*
|
|
45
|
+
* @param dbcText - Raw DBC file content
|
|
46
|
+
* @param fileName - Optional file name for reference
|
|
47
|
+
* @returns New DbcDefinition instance
|
|
48
|
+
* @throws {Error} If parsing fails
|
|
49
|
+
*/
|
|
50
|
+
static fromDBC(dbcText: string, fileName?: string): DbcDefinition;
|
|
51
|
+
/**
|
|
52
|
+
* Create DbcDefinition from JSON file content
|
|
53
|
+
*
|
|
54
|
+
* @param jsonText - Raw JSON file content
|
|
55
|
+
* @param fileName - Optional file name for reference
|
|
56
|
+
* @returns New DbcDefinition instance
|
|
57
|
+
* @throws {Error} If parsing fails
|
|
58
|
+
*/
|
|
59
|
+
static fromJSON(jsonText: string, fileName?: string): DbcDefinition;
|
|
60
|
+
/**
|
|
61
|
+
* Validate messages Map structure
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
private validateMessages;
|
|
65
|
+
/**
|
|
66
|
+
* Build metadata from messages and partial metadata
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
private buildMetadata;
|
|
70
|
+
/**
|
|
71
|
+
* Check if this definition is for J1939 protocol
|
|
72
|
+
*
|
|
73
|
+
* @returns True if protocol type is J1939
|
|
74
|
+
*/
|
|
75
|
+
isJ1939(): boolean;
|
|
76
|
+
/** Mask CAN ID to PGN bits — PDU1 strips DA, PDU2 keeps GE. */
|
|
77
|
+
private maskToPgn;
|
|
78
|
+
/**
|
|
79
|
+
* Get message information.
|
|
80
|
+
*
|
|
81
|
+
* Map keys are IDE-encoded via `encodeIdeKey` so std and ext variants of
|
|
82
|
+
* the same numeric arbId stay distinct. Callers must supply the frame's
|
|
83
|
+
* IDE so the right variant is returned.
|
|
84
|
+
*
|
|
85
|
+
* @param messageId - Clean 29-bit-masked CAN ID (no IDE flag bit)
|
|
86
|
+
* @param isExtended - Frame's IDE bit
|
|
87
|
+
* @returns Message definition or null
|
|
88
|
+
*/
|
|
89
|
+
getMessageInfo(messageId: number, isExtended: boolean): CanMessage | null;
|
|
90
|
+
/**
|
|
91
|
+
* Get signal information
|
|
92
|
+
*
|
|
93
|
+
* @param message - CAN message definition
|
|
94
|
+
* @param signalName - Signal name
|
|
95
|
+
* @returns Signal definition or null
|
|
96
|
+
*/
|
|
97
|
+
getSignalInfo(message: CanMessage, signalName: string): CanSignal | null;
|
|
98
|
+
/**
|
|
99
|
+
* List all defined messages
|
|
100
|
+
*
|
|
101
|
+
* @returns Array of CanMessage definitions
|
|
102
|
+
*/
|
|
103
|
+
listMessages(): CanMessage[];
|
|
104
|
+
/**
|
|
105
|
+
* List all signals for a message
|
|
106
|
+
*
|
|
107
|
+
* @param message - CAN message definition
|
|
108
|
+
* @returns Array of CanSignal definitions
|
|
109
|
+
*/
|
|
110
|
+
listSignals(message: CanMessage): CanSignal[];
|
|
111
|
+
/**
|
|
112
|
+
* Get metadata about this definition
|
|
113
|
+
*
|
|
114
|
+
* @returns Definition metadata
|
|
115
|
+
*/
|
|
116
|
+
getMetadata(): DbcMetadata;
|
|
117
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @csselectronics/can-decode v0.1.0 (c) CSS Electronics ApS, see LICENSE */
|
|
2
|
+
var g=Object.defineProperty;var o=(l,t)=>g(l,"name",{value:t,configurable:!0});import{parseDBC as m}from"../../utils/DbcParser.js";import{parseJSON as p}from"../../utils/JsonParser.js";import{encodeIdeKey as u}from"../../utils/dbcKey.js";import{pgnMaskFor as f}from"@csselectronics/can-types/utils/j1939";class r{static{o(this,"DbcDefinition")}messages;metadata;get name(){return this.metadata.fileName}constructor(t,e){this.validateMessages(t),this.messages=t,this.metadata=this.buildMetadata(t,e)}static fromFile(t,e){const a=e.toLowerCase().split(".").pop();switch(a){case"dbc":return r.fromDBC(t,e);case"json":return r.fromJSON(t,e);default:throw new Error(`Unsupported file format: .${a} (supported: .dbc, .json)`)}}static fromDBC(t,e){const a=m(t,e||null),s=a.metadata.attributes.get("ProtocolType");return new r(a.messages,{fileName:a.metadata.fileName,protocolType:typeof s=="string"?s:void 0,skippedSignals:a.metadata.skippedSignals})}static fromJSON(t,e){const a=p(t,e||null);return new r(a.messages,{fileName:a.metadata.fileName,skippedSignals:a.metadata.skippedSignals})}validateMessages(t){if(!t||!(t instanceof Map))throw new Error("Invalid messages: must be a Map instance");for(const[e,a]of t){const s=e&536870911;if(typeof e!="number"||e<0||s>536870911||e>>>0>4294967295)throw new Error(`Invalid message ID ${e}: must be 0-536870911 (or that value with IDE bit set)`);if(!a||typeof a!="object")throw new Error(`Invalid message at ID ${e}: must be an object`);if(!a.name||typeof a.name!="string")throw new Error(`Invalid message name at ID ${e}: must be a non-empty string`);if(typeof a.length!="number"||a.length<0||a.length>1024)throw new Error(`Invalid length ${a.length} for message ${e}: must be 0-1024`);if(!a.signals||!(a.signals instanceof Map))throw new Error(`Invalid signals for message ${e}: must be a Map instance`);for(const[i,n]of a.signals){if(typeof n.bitpos!="number"||n.bitpos<0||n.bitpos>=8192)throw new Error(`Invalid bitpos for signal ${i} in message ${e}`);if(typeof n.bitlen!="number"||n.bitlen<=0||n.bitlen>64)throw new Error(`Invalid bitlen for signal ${i} in message ${e}`)}}}buildMetadata(t,e){let a=0,s=!1;for(const i of t.values())a+=i.signals.size,i.isMultiplexed&&(s=!0);return{fileName:e?.fileName||null,loadTime:e?.loadTime||new Date,version:e?.version,hasMultiplexing:e?.hasMultiplexing!==void 0?e.hasMultiplexing:s,messageCount:t.size,signalCount:a,protocolType:e?.protocolType,skippedSignals:e?.skippedSignals??[]}}isJ1939(){return this.metadata.protocolType==="J1939"}maskToPgn(t){return t&f(t)}getMessageInfo(t,e){const a=this.isJ1939()&&e?this.maskToPgn(t):t;return this.messages.get(u(a,e))??null}getSignalInfo(t,e){return t.signals.get(e)||null}listMessages(){return Array.from(this.messages.values())}listSignals(t){return Array.from(t.signals.values())}getMetadata(){return{...this.metadata}}}export{r as DbcDefinition};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { CanMessage, type CanSignal } from '../CanTypes.js';
|
|
2
|
+
import type { IDbcDefinition, DbcMetadata } from './IDbcDefinition.js';
|
|
3
|
+
/**
|
|
4
|
+
* DbcUnion - Combines multiple CAN data definitions with priority.
|
|
5
|
+
*
|
|
6
|
+
* Sequential lookup: first definition with a matching message ID wins.
|
|
7
|
+
* Supports mixed J1939 + non-J1939 DBCs (each handles its own masking).
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const union = new DbcUnion([j1939Def, vehicleDef]);
|
|
11
|
+
* const message = union.getMessageInfo(canId);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class DbcUnion implements IDbcDefinition {
|
|
15
|
+
/**
|
|
16
|
+
* Ordered list of definitions (priority: first to last)
|
|
17
|
+
*/
|
|
18
|
+
private readonly definitions;
|
|
19
|
+
/**
|
|
20
|
+
* Human-readable name (union of all definition names)
|
|
21
|
+
*/
|
|
22
|
+
get name(): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Create a union of multiple CAN data definitions
|
|
25
|
+
*
|
|
26
|
+
* @param definitions - Array of definitions in priority order (first = highest priority)
|
|
27
|
+
*/
|
|
28
|
+
constructor(definitions: IDbcDefinition[]);
|
|
29
|
+
/**
|
|
30
|
+
* Check if this union is for J1939 protocol
|
|
31
|
+
* Returns true if ANY definition is J1939
|
|
32
|
+
*
|
|
33
|
+
* @returns True if any definition is J1939
|
|
34
|
+
*/
|
|
35
|
+
isJ1939(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Get message information (searches definitions in priority order).
|
|
38
|
+
*/
|
|
39
|
+
getMessageInfo(messageId: number, isExtended: boolean): CanMessage | null;
|
|
40
|
+
/**
|
|
41
|
+
* Get signal information
|
|
42
|
+
* Uses the message object to get signal directly
|
|
43
|
+
*
|
|
44
|
+
* @param message - CAN message definition
|
|
45
|
+
* @param signalName - Signal name
|
|
46
|
+
* @returns Signal definition or null
|
|
47
|
+
*/
|
|
48
|
+
getSignalInfo(message: CanMessage, signalName: string): CanSignal | null;
|
|
49
|
+
/**
|
|
50
|
+
* List all defined messages across all definitions
|
|
51
|
+
* Note: Returns unique messages - duplicates across definitions are filtered
|
|
52
|
+
*
|
|
53
|
+
* @returns Array of CanMessage definitions
|
|
54
|
+
*/
|
|
55
|
+
listMessages(): CanMessage[];
|
|
56
|
+
/**
|
|
57
|
+
* List all signals for a message
|
|
58
|
+
* Uses the message object to list signals directly
|
|
59
|
+
*
|
|
60
|
+
* @param message - CAN message definition
|
|
61
|
+
* @returns Array of CanSignal definitions
|
|
62
|
+
*/
|
|
63
|
+
listSignals(message: CanMessage): CanSignal[];
|
|
64
|
+
/**
|
|
65
|
+
* Get aggregated metadata across all definitions
|
|
66
|
+
*
|
|
67
|
+
* @returns Aggregated metadata
|
|
68
|
+
*/
|
|
69
|
+
getMetadata(): DbcMetadata;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Result of conflict detection across multiple DBC definitions.
|
|
73
|
+
*/
|
|
74
|
+
export interface ConflictResult {
|
|
75
|
+
/** Number of message keys that appear in more than one definition */
|
|
76
|
+
count: number;
|
|
77
|
+
/** First conflicting message (name + formatted ID), or null if no conflicts */
|
|
78
|
+
firstExample: {
|
|
79
|
+
name: string;
|
|
80
|
+
id: string;
|
|
81
|
+
} | null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Detect duplicate message keys across multiple CAN definitions.
|
|
85
|
+
*
|
|
86
|
+
* For J1939 definitions the keys are already PGN-masked, so duplicates
|
|
87
|
+
* are detected at PGN level (which is the correct granularity).
|
|
88
|
+
*
|
|
89
|
+
* @param definitions - Two or more definitions to compare
|
|
90
|
+
* @returns Conflict count and an example of the first duplicate found
|
|
91
|
+
*/
|
|
92
|
+
export declare function detectConflicts(definitions: IDbcDefinition[]): ConflictResult;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! @csselectronics/can-decode v0.1.0 (c) CSS Electronics ApS, see LICENSE */
|
|
2
|
+
var u=Object.defineProperty;var f=(r,e)=>u(r,"name",{value:e,configurable:!0});import{encodeIdeKey as g}from"../../utils/dbcKey.js";class M{static{f(this,"DbcUnion")}definitions;get name(){const e=this.definitions.map(n=>n.name).filter(n=>n!==null);return e.length>0?e.join(", "):null}constructor(e){this.definitions=[...e]}isJ1939(){return this.definitions.some(e=>e.isJ1939())}getMessageInfo(e,n){for(const a of this.definitions){const t=a.getMessageInfo(e,n);if(t)return t}return null}getSignalInfo(e,n){return e.signals.get(n)||null}listMessages(){const e=new Map;for(const n of this.definitions){const a=n.listMessages();for(const t of a){const s=g(t.key,t.isExtended);e.has(s)||e.set(s,t)}}return Array.from(e.values())}listSignals(e){return Array.from(e.signals.values())}getMetadata(){let e=0,n=0,a=!1,t;const s=[],o=[];for(const l of this.definitions){const i=l.getMetadata();e+=i.messageCount||0,n+=i.signalCount||0,a=a||i.hasMultiplexing,i.skippedSignals&&o.push(...i.skippedSignals),i.protocolType==="J1939"&&(t="J1939"),i.fileName&&s.push(i.fileName)}return{fileName:s.join(", ")||null,loadTime:new Date,version:void 0,hasMultiplexing:a,messageCount:e,signalCount:n,protocolType:t,skippedSignals:o}}}function b(r){if(r.length<2)return{count:0,firstExample:null};const e=r.map(s=>{const o=new Map;for(const l of s.listMessages())o.set(g(l.key,l.isExtended),l);return o});let n=0,a=null;const t=new Set;for(let s=0;s<e.length;s++)for(const[o,l]of e[s])if(!t.has(o)){for(let i=s+1;i<e.length;i++)if(e[i].has(o)){n++,a||(a={name:l.name,id:l.getIdFormatted()}),t.add(o);break}}return{count:n,firstExample:a}}f(b,"detectConflicts");export{M as DbcUnion,b as detectConflicts};
|