A general-purpose CAN (Controller Area Network) toolbox with support for .dbc
file parsing, CAN message decoding, and more.
Install the package via npm:
npm install @montra-connect/dbc-parser
- 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.
import { Can, Dbc } from '@montra-connect/dbc-parser';
import dbcReader from '@montra-connect/dbc-parser/lib/filesystem/DbcReader';
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
// 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);
To build the package, run:
npm run build
This will compile the TypeScript source files into JavaScript.
To run the test suite:
npm run test
This command will execute all test cases to ensure the package works as expected.
To check the code for linting errors:
npm run lint
This command will run ESLint on the codebase to ensure code quality and consistency.
This project is licensed under the MIT License.
Feel free to contribute to the project or report any issues you encounter.