Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@ Decode / parse CAN frames into messages/signals in a fast and easy way.
[![Crates.io](https://img.shields.io/crates/v/can_decode.svg)](https://crates.io/crates/can_decode)
[![Docs.rs](https://docs.rs/can_decode/badge.svg)](https://docs.rs/can_decode)

## Features

- Parse DBC (CAN Database) files
- Decode CAN messages into signals with physical values
- Support for both standard and extended CAN IDs
- Handle big-endian and little-endian byte ordering
- Support for signed and unsigned signal values
- Apply scaling factors and offsets

## Example

```rust
fn main() {
env_logger::init();

let parser = match can_decode::Parser::from_dbc_file(Path::new("./CAN.dbc")) {
Ok(p) => p,
Err(e) => {
eprintln!("Error parsing DBC file: {}", e);
std::process::exit(1);
}
};

let arb_id = 0x123;
let data = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08];
let decoded = parser.decode_msg(arb_id, &data);
match decoded {
Some(msg) => {
println!("Decoded message: {:?}", msg);
}
None => {
println!("No message found for arb_id: {:#X}", arb_id);
use can_decode::Parser;
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load a DBC file
let parser = Parser::from_dbc_file(Path::new("my_can_database.dbc"))?;

// Decode a CAN message
let msg_id = 0x123;
let data = [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0];
if let Some(decoded) = parser.decode_msg(msg_id, &data) {
println!("Message: {}", decoded.name);
for (signal_name, signal) in &decoded.signals {
println!(" {}: {} {}", signal_name, signal.value, signal.unit);
}
}

Ok(())
}
```
Loading
Loading