voltage_j1939
SAE J1939 protocol decoder for Rust. Provides PGN/SPN database and CAN frame parsing for heavy-duty vehicles and industrial equipment.
Features
- Zero dependencies - Pure Rust, no external crates required
- Built-in SPN database - 60+ SPNs across 12+ PGNs for engine/generator monitoring
- CAN ID parsing - Parse and build 29-bit extended J1939 CAN IDs
- Bit-level decoding - Extract values with scale, offset, and bit field support
- "Not available" detection - Automatic handling of J1939 special values (0xFF, 0xFFFF, etc.)
Installation
[]
= "0.1"
Quick Start
use ;
// Parse a J1939 CAN frame (EEC1 from SA=0x00)
let can_id = 0x0CF00400u32;
let data = ;
// Decode all SPNs in the frame
let decoded = decode_frame;
for spn in decoded
// Parse CAN ID components
let id = parse_can_id;
println!;
Decoding Individual SPNs
use ;
// Get SPN definition for Engine Coolant Temperature
let spn_def = get_spn_def.unwrap;
// Decode from raw CAN data
let data = ; // Raw value 130
if let Some = decode_spn
Supported PGNs
| PGN | Name | Description |
|---|---|---|
| 61444 | EEC1 | Electronic Engine Controller 1 |
| 61443 | EEC2 | Electronic Engine Controller 2 |
| 65270 | EEC3 | Electronic Engine Controller 3 |
| 65262 | ET1 | Engine Temperature 1 |
| 65263 | EFL/P1 | Engine Fluid Level/Pressure 1 |
| 65270 | IC1 | Inlet/Exhaust Conditions 1 |
| 65271 | VEP1 | Vehicle Electrical Power 1 |
| 65269 | AMB | Ambient Conditions |
| 65266 | LFE | Fuel Economy |
| 65253 | HOURS | Engine Hours/Revolutions |
| 65257 | FC | Fuel Consumption |
| 65259 | VH | Vehicle Hours |
| 65276 | DD | Dash Display |
| 65265 | CCVS | Cruise Control/Vehicle Speed |
J1939 CAN ID Format
J1939 uses 29-bit extended CAN IDs:
| Priority | R | DP | PF | PS/DA | SA |
| 3 bit |1b | 1b | 8b | 8b | 8b |
- Priority: Message priority (0-7, lower is higher)
- DP: Data Page (0 or 1)
- PF: PDU Format (determines PDU1 vs PDU2)
- PS/DA: PDU Specific or Destination Address
- SA: Source Address
PDU Format
- PDU1 (PF < 240): Peer-to-peer messages, PS is destination address
- PDU2 (PF >= 240): Broadcast messages, PS is part of PGN
Building Request PGN Frames
use build_request_pgn;
// Request Engine Hours (PGN 65253) from ECU at address 0x00
let = build_request_pgn;
// can_id = 0x18EA00FE
// data = [0xE5, 0xFE, 0x00] (PGN in little-endian)
Database Statistics
use ;
let = database_stats;
println!;
for pgn in list_supported_pgns
Integration with socketcan
This crate handles J1939 protocol decoding only. For CAN bus communication, use socketcan or similar:
use CanSocket;
use ;
let socket = open?;
loop
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.