0.0.4 • Published 1 year ago
@montra-connect/dbc-parser v0.0.4
@montra-connect/dbc-parser
A general-purpose CAN (Controller Area Network) toolbox with support for .dbc file parsing, CAN message decoding, and more.
Table of Contents
Installation
Install the package via npm:
npm install @montra-connect/dbc-parserFeatures
- Parse
.dbcfiles to extract CAN message definitions. - Decode CAN messages using the parsed definitions.
- Filesystem-based
.dbcfile reading support. - Utilities for working with CAN messages and databases.
Usage
Importing the Package
import { Can, Dbc } from '@montra-connect/dbc-parser';
import dbcReader from '@montra-connect/dbc-parser/lib/filesystem/DbcReader';Parsing a DBC File
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 messagesDecoding a CAN Message
// 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:
npm run buildThis will compile the TypeScript source files into JavaScript.
Testing
To run the test suite:
npm run testThis command will execute all test cases to ensure the package works as expected.
Linting
To check the code for linting errors:
npm run lintThis command will run ESLint on the codebase to ensure code quality and consistency.
License
This project is licensed under the MIT License.
Feel free to contribute to the project or report any issues you encounter.