A general purpose CAN (Controller Area Network) toolbox with support for .dbc file parsing, CAN message decoding, and more
.dbc file parsing, CAN message decoding, and more.
bash
npm install @montra-connect/dbc-parser
`
Features
- Parse .dbc files to extract CAN message definitions.
- Decode CAN messages using the parsed definitions.
- Filesystem-based .dbc file reading support.
- Utilities for working with CAN messages and databases.
Usage
$3
`javascript
import { Can, Dbc } from '@montra-connect/dbc-parser';
import dbcReader from '@montra-connect/dbc-parser/lib/filesystem/DbcReader';
`
$3
`javascript
const canDB = new Can();
const dbc = new Dbc();
// Read the DBC file content (replace 'path/to/your/file.dbc' with your actual DBC file path)
const result = await dbcReader('path/to/your/file.dbc');
// Load the DBC content into the Dbc instance
const res = dbc.load(result.toString());
// Now you can use the 'canDB' and 'dbc' instances for decoding CAN messages
`
$3
`javascript
// Assuming you have a CAN message to decode
const canMessage = {
id: 0x123,
data: Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05])
};
// Decode the message using the DBC definitions
const decodedMessage = canDB.decode(canMessage);
console.log(decodedMessage);
`
Build
To build the package, run:
`bash
npm run build
`
This will compile the TypeScript source files into JavaScript.
Testing
To run the test suite:
`bash
npm run test
`
This command will execute all test cases to ensure the package works as expected.
Linting
To check the code for linting errors:
`bash
npm run lint
``