can
60 items · generated by scribe fromstdlib/can.fd· synced 2026-11-15
Contents
- CanFrame (struct)
- can_frame_standard (function)
- can_frame_extended (function)
- can_frame_remote_standard (function)
- can_frame_remote_extended (function)
- can_frame_id (function)
- can_frame_dlc (function)
- can_frame_is_extended (function)
- can_frame_is_remote (function)
- can_frame_data (function)
- can_frame_byte (function)
- can_validate_standard_id (function)
- can_validate_extended_id (function)
- can_validate_dlc (function)
- j1939_id (function)
- j1939_priority (function)
- j1939_pdu_format (function)
- j1939_pdu_specific (function)
- j1939_source_addr (function)
- j1939_is_pdu1 (function)
- j1939_is_pdu2 (function)
- j1939_pgn (function)
- UDS_SERVICE_DIAGNOSTIC_SESSION_CONTROL: (const)
- UDS_NRC_GENERAL_REJECT: (const)
- uds_service_id (function)
- uds_sub_function (function)
- uds_data (function)
- uds_response_positive (function)
- uds_response_negative (function)
- uds_is_positive_response (function)
- uds_is_negative_response (function)
- uds_nrc (function)
- DTC_SYSTEM_POWERTRAIN: (const)
- dtc_encode (function)
- dtc_system (function)
- dtc_code (function)
- dtc_system_char (function)
- obd_read_dtcs (function)
- obd_clear_dtcs (function)
- obd_supported_pids (function)
- obd_engine_rpm_request (function)
- obd_decode_engine_rpm (function)
- obd_vehicle_speed_request (function)
- obd_decode_vehicle_speed (function)
- obd_coolant_temp_request (function)
- obd_decode_coolant_temp (function)
- OBD_BROADCAST_ID: (const)
- OBD_RESPONSE_BASE: (const)
- obd_request_to_ecu (function)
- obd_is_response_from_ecu (function)
- obd_is_response (function)
- UDS_SESSION_DEFAULT: (const)
- uds_session_control (function)
- UDS_RESET_HARD: (const)
- uds_ecu_reset (function)
- uds_security_access_request_seed (function)
- uds_security_access_send_key (function)
- uds_read_data_by_id (function)
- UDS_DID_VIN: (const)
- can_frame_print (function)
CanFrame
A CAN frame (standard or extended, data or remote). Layout: [id: i64, dlc: i64, is_extended: bool, is_remote: bool, data: Vec]
pub struct CanFrame {Fields:
| Name | Type |
|---|---|
id | i64 |
dlc | i64 |
is_extended | bool |
is_remote | bool |
data | Vec<i64> |
Defined at line 39
can_frame_standard
Create a standard (11-bit ID) data frame. ID must be in range 0x000-0x7FF. DLC is the data length code (0-8).
pub fn can_frame_standard(id: i64, data: Vec<i64>) -> CanFrame {Parameters:
id:i64data:Vec<i64>
Returns: CanFrame
Defined at line 51
can_frame_extended
Create an extended (29-bit ID) data frame. ID must be in range 0x00000000-0x1FFFFFFF.
pub fn can_frame_extended(id: i64, data: Vec<i64>) -> CanFrame {Parameters:
id:i64data:Vec<i64>
Returns: CanFrame
Defined at line 59
can_frame_remote_standard
Create a standard remote frame (request for data, no payload).
pub fn can_frame_remote_standard(id: i64, dlc: i64) -> CanFrame {Parameters:
id:i64dlc:i64
Returns: CanFrame
Defined at line 66
can_frame_remote_extended
Create an extended remote frame.
pub fn can_frame_remote_extended(id: i64, dlc: i64) -> CanFrame {Parameters:
id:i64dlc:i64
Returns: CanFrame
Defined at line 73
can_frame_id
Get the CAN ID (11 or 29 bit).
pub fn can_frame_id(frame: CanFrame) -> i64 {Parameters:
frame:CanFrame
Returns: i64
Defined at line 82
can_frame_dlc
Get the data length code (0-8 for classic CAN, 0-64 for CAN FD).
pub fn can_frame_dlc(frame: CanFrame) -> i64 {Parameters:
frame:CanFrame
Returns: i64
Defined at line 87
can_frame_is_extended
Check if the frame uses an extended (29-bit) ID.
pub fn can_frame_is_extended(frame: CanFrame) -> bool {Parameters:
frame:CanFrame
Returns: bool
Defined at line 92
can_frame_is_remote
Check if the frame is a remote frame (no data payload).
pub fn can_frame_is_remote(frame: CanFrame) -> bool {Parameters:
frame:CanFrame
Returns: bool
Defined at line 97
can_frame_data
Get the data payload as a Vec of bytes.
pub fn can_frame_data(frame: CanFrame) -> Vec<i64> {Parameters:
frame:CanFrame
Returns: Vec<i64>
Defined at line 102
can_frame_byte
Get a single byte from the frame data at the given index. Returns -1 if index is out of bounds.
pub fn can_frame_byte(frame: CanFrame, index: i64) -> i64 {Parameters:
frame:CanFrameindex:i64
Returns: i64
Defined at line 108
can_validate_standard_id
Validate a standard CAN ID (11-bit, 0x000-0x7FF).
pub fn can_validate_standard_id(id: i64) -> bool {Parameters:
id:i64
Returns: bool
Defined at line 118
can_validate_extended_id
Validate an extended CAN ID (29-bit, 0x00000000-0x1FFFFFFF).
pub fn can_validate_extended_id(id: i64) -> bool {Parameters:
id:i64
Returns: bool
Defined at line 123
can_validate_dlc
Validate a DLC value (0-8 for classic CAN).
pub fn can_validate_dlc(dlc: i64) -> bool {Parameters:
dlc:i64
Returns: bool
Defined at line 128
j1939_id
Build a J1939 CAN ID from its components. priority: 0-7 (0 = highest) reserved: 0 or 1 data_page: 0 or 1 pdu_format: 0-255 pdu_specific: 0-255 source_addr: 0-255
pub fn j1939_id(priority: i64, reserved: i64, data_page: i64, pdu_format: i64, pdu_specific: i64, source_addr: i64) -> i64 {Parameters:
priority:i64reserved:i64data_page:i64pdu_format:i64pdu_specific:i64source_addr:i64
Returns: i64
Defined at line 148
j1939_priority
Extract the priority (0-7) from a J1939 CAN ID.
pub fn j1939_priority(id: i64) -> i64 {Parameters:
id:i64
Returns: i64
Defined at line 159
j1939_pdu_format
Extract the PDU Format (0-255) from a J1939 CAN ID.
pub fn j1939_pdu_format(id: i64) -> i64 {Parameters:
id:i64
Returns: i64
Defined at line 164
j1939_pdu_specific
Extract the PDU Specific (destination or group extension) from a J1939 CAN ID.
pub fn j1939_pdu_specific(id: i64) -> i64 {Parameters:
id:i64
Returns: i64
Defined at line 169
j1939_source_addr
Extract the Source Address (0-255) from a J1939 CAN ID.
pub fn j1939_source_addr(id: i64) -> i64 {Parameters:
id:i64
Returns: i64
Defined at line 174
j1939_is_pdu1
Check if a J1939 frame is PDU1 (destination-specific, PF >= 240).
pub fn j1939_is_pdu1(id: i64) -> bool {Parameters:
id:i64
Returns: bool
Defined at line 179
j1939_is_pdu2
Check if a J1939 frame is PDU2 (broadcast, PF < 240).
pub fn j1939_is_pdu2(id: i64) -> bool {Parameters:
id:i64
Returns: bool
Defined at line 184
j1939_pgn
Extract the PGN (Parameter Group Number) from a J1939 CAN ID. For PDU1 (PF >= 240): PGN = (DP << 16) | (PF << 8) | 0 For PDU2 (PF < 240): PGN = (DP << 16) | (PF << 8) | PS
pub fn j1939_pgn(id: i64) -> i64 {Parameters:
id:i64
Returns: i64
Defined at line 191
UDS_SERVICE_DIAGNOSTIC_SESSION_CONTROL:
UDS Service IDs (ISO 14229-1)
pub const UDS_SERVICE_DIAGNOSTIC_SESSION_CONTROL: i64 = 0x10; pub const UDS_SERVICE_ECU_RESET: i64 = 0x11; pub const UDS_SERVICE_CLEAR_DTC: i64 = 0x14; pub const UDS_SERVICE_READ_DTC: i64 = 0x19; pub const UDS_SERVICE_READ_DATA_BY_ID: i64 = 0x22; pub const UDS_SERVICE_READ_MEMORY_BY_ADDR: i64 = 0x23; pub const UDS_SERVICE_WRITE_DATA_BY_ID: i64 = 0x2E; pub const UDS_SERVICE_INPUT_OUTPUT_CONTROL_BY_ID: i64 = 0x2F; pub const UDS_SERVICE_ROUTINE_CONTROL: i64 = 0x31; pub const UDS_SERVICE_REQUEST_DOWNLOAD: i64 = 0x34; pub const UDS_SERVICE_REQUEST_UPLOAD: i64 = 0x35; pub const UDS_SERVICE_TRANSFER_DATA: i64 = 0x36; pub const UDS_SERVICE_REQUEST_TRANSFER_EXIT: i64 = 0x37; pub const UDS_SERVICE_REQUEST_FILE_TRANSFER: i64 = 0x38; pub const UDS_SERVICE_TESTER_PRESENT: i64 = 0x3E; pub const UDS_SERVICE_ACCESS_TIMING: i64 = 0x83; pub const UDS_SERVICE_SECURED_DATA_TRANSMISSION: i64 = 0x84; pub const UDS_SERVICE_CONTROL_DTC_SETTING: i64 = 0x85; pub const UDS_SERVICE_RESPONSE_ON_EVENT: i64 = 0x86; pub const UDS_SERVICE_LINK_CONTROL: i64 = 0x87; pub const UDS_SERVICE_READ_DATA_BY_PERIODIC_ID: i64 = 0x2A; pub const UDS_SERVICE_DYNAMICALLY_DEFINE_DATA_ID: i64 = 0x2C; pub const UDS_SERVICE_DEFINE_DATA_BY_ID: i64 = 0x2B; pub const UDS_SERVICE_WRITE_MEMORY_BY_ADDR: i64 = 0x3D; pub const UDS_SERVICE_COMMUNICATION_CONTROL: i64 = 0x28; pub const UDS_SERVICE_AUTHENTICATION: i64 = 0x29;Defined at line 211
UDS_NRC_GENERAL_REJECT:
UDS Negative Response Codes (NRC)
pub const UDS_NRC_GENERAL_REJECT: i64 = 0x10; pub const UDS_NRC_SERVICE_NOT_SUPPORTED: i64 = 0x11; pub const UDS_NRC_SUB_FUNCTION_NOT_SUPPORTED: i64 = 0x12; pub const UDS_NRC_INVALID_FORMAT: i64 = 0x13; pub const UDS_NRC_RESPONSE_TOO_LONG: i64 = 0x14; pub const UDS_NRC_BUSY_REPEAT_REQUEST: i64 = 0x21; pub const UDS_NRC_CONDITIONS_NOT_CORRECT: i64 = 0x22; pub const UDS_NRC_REQUEST_SEQUENCE_ERROR: i64 = 0x24; pub const UDS_NRC_REQUEST_OUT_OF_RANGE: i64 = 0x31; pub const UDS_NRC_SECURITY_ACCESS_DENIED: i64 = 0x33; pub const UDS_NRC_INVALID_KEY: i64 = 0x35; pub const UDS_NRC_EXCEEDED_NUMBER_OF_ATTEMPTS: i64 = 0x36; pub const UDS_NRC_REQUIRED_TIME_DELAY_NOT_EXPIRED: i64 = 0x37; pub const UDS_NRC_RESPONSE_PENDING: i64 = 0x78; pub const UDS_NRC_SUB_FUNCTION_NOT_SUPPORTED_ACTIVE: i64 = 0x7E; pub const UDS_NRC_SERVICE_NOT_SUPPORTED_ACTIVE: i64 = 0x7F;Defined at line 213
uds_service_id
Extract the UDS service ID from a CAN frame’s first data byte. Returns -1 if the frame has no data.
pub fn uds_service_id(frame: CanFrame) -> i64 {Parameters:
frame:CanFrame
Returns: i64
Defined at line 216
uds_sub_function
Extract the UDS sub-function from a CAN frame’s second data byte. Returns -1 if the frame has fewer than 2 bytes.
pub fn uds_sub_function(frame: CanFrame) -> i64 {Parameters:
frame:CanFrame
Returns: i64
Defined at line 225
uds_data
Extract UDS data payload (bytes after service ID + sub-function). Returns a Vec of the remaining bytes.
pub fn uds_data(frame: CanFrame) -> Vec<i64> {Parameters:
frame:CanFrame
Returns: Vec<i64>
Defined at line 234
uds_response_positive
Build a positive UDS response frame. The response service ID is (request_service_id | 0x40). Format: [Service ID + 0x40] [Sub-function] [data…]
pub fn uds_response_positive(request: CanFrame, response_data: Vec<i64>) -> CanFrame {Parameters:
request:CanFrameresponse_data:Vec<i64>
Returns: CanFrame
Defined at line 248
uds_response_negative
Build a negative UDS response frame. Format: [0x7F] [Service ID] [NRC]
pub fn uds_response_negative(request: CanFrame, nrc: i64) -> CanFrame {Parameters:
request:CanFramenrc:i64
Returns: CanFrame
Defined at line 264
uds_is_positive_response
Check if a CAN frame is a UDS positive response.
pub fn uds_is_positive_response(frame: CanFrame) -> bool {Parameters:
frame:CanFrame
Returns: bool
Defined at line 274
uds_is_negative_response
Check if a CAN frame is a UDS negative response.
pub fn uds_is_negative_response(frame: CanFrame) -> bool {Parameters:
frame:CanFrame
Returns: bool
Defined at line 280
uds_nrc
Extract the NRC from a negative response frame. Returns -1 if the frame is not a negative response.
pub fn uds_nrc(frame: CanFrame) -> i64 {Parameters:
frame:CanFrame
Returns: i64
Defined at line 286
DTC_SYSTEM_POWERTRAIN:
DTC system prefixes
pub const DTC_SYSTEM_POWERTRAIN: i64 = 0; pub const DTC_SYSTEM_CHASSIS: i64 = 1; pub const DTC_SYSTEM_BODY: i64 = 2; pub const DTC_SYSTEM_NETWORK: i64 = 3;Defined at line 305
dtc_encode
Encode a DTC from system (0-3) and code digits (3 hex digits as i64). Returns a 2-byte packed i64: [system << 14 | code]
pub fn dtc_encode(system: i64, code: i64) -> i64 {Parameters:
system:i64code:i64
Returns: i64
Defined at line 308
dtc_system
Decode the system prefix (0=Powertrain, 1=Chassis, 2=Body, 3=Network).
pub fn dtc_system(dtc: i64) -> i64 {Parameters:
dtc:i64
Returns: i64
Defined at line 313
dtc_code
Decode the DTC code digits (14-bit).
pub fn dtc_code(dtc: i64) -> i64 {Parameters:
dtc:i64
Returns: i64
Defined at line 318
dtc_system_char
Get the DTC system as a character: ‘P’, ‘C’, ‘B’, ‘U’.
pub fn dtc_system_char(dtc: i64) -> str {Parameters:
dtc:i64
Returns: str
Defined at line 323
obd_read_dtcs
OBD-II Mode 03: Read DTCs. Build a request frame.
pub fn obd_read_dtcs() -> CanFrame {Returns: CanFrame
Defined at line 340
obd_clear_dtcs
OBD-II Mode 04: Clear DTCs. Build a request frame.
pub fn obd_clear_dtcs() -> CanFrame {Returns: CanFrame
Defined at line 347
obd_supported_pids
OBD-II Mode 01 PID 00: Supported PIDs 01-20.
pub fn obd_supported_pids() -> CanFrame {Returns: CanFrame
Defined at line 354
obd_engine_rpm_request
OBD-II Mode 01 PID 0C: Engine RPM. Response: [0x41, 0x0C, RPM_High, RPM_Low] where RPM = ((A*256)+B)/4
pub fn obd_engine_rpm_request() -> CanFrame {Returns: CanFrame
Defined at line 363
obd_decode_engine_rpm
Decode engine RPM from an OBD-II Mode 01 PID 0C response. Returns RPM as i64, or -1 if the frame is invalid.
pub fn obd_decode_engine_rpm(frame: CanFrame) -> i64 {Parameters:
frame:CanFrame
Returns: i64
Defined at line 372
obd_vehicle_speed_request
OBD-II Mode 01 PID 0D: Vehicle Speed (km/h).
pub fn obd_vehicle_speed_request() -> CanFrame {Returns: CanFrame
Defined at line 388
obd_decode_vehicle_speed
Decode vehicle speed from an OBD-II Mode 01 PID 0D response. Returns speed in km/h, or -1 if the frame is invalid.
pub fn obd_decode_vehicle_speed(frame: CanFrame) -> i64 {Parameters:
frame:CanFrame
Returns: i64
Defined at line 397
obd_coolant_temp_request
OBD-II Mode 01 PID 05: Engine Coolant Temperature (°C). Response: [0x41, 0x05, Temp] where Temp = A - 40
pub fn obd_coolant_temp_request() -> CanFrame {Returns: CanFrame
Defined at line 412
obd_decode_coolant_temp
Decode coolant temperature from an OBD-II Mode 01 PID 05 response. Returns temperature in °C, or -1 if the frame is invalid.
pub fn obd_decode_coolant_temp(frame: CanFrame) -> i64 {Parameters:
frame:CanFrame
Returns: i64
Defined at line 421
OBD_BROADCAST_ID:
OBD-II functional broadcast ID (requests to all ECUs).
pub const OBD_BROADCAST_ID: i64 = 0x7DF;Defined at line 437
OBD_RESPONSE_BASE:
OBD-II ECU response ID base (0x7E8-0x7EF for 8 ECUs).
pub const OBD_RESPONSE_BASE: i64 = 0x7E8;Defined at line 439
obd_request_to_ecu
Build an OBD-II request to a specific ECU (0-7).
pub fn obd_request_to_ecu(ecu: i64, mode: i64, pid: i64) -> CanFrame {Parameters:
ecu:i64mode:i64pid:i64
Returns: CanFrame
Defined at line 441
obd_is_response_from_ecu
Check if a frame is an OBD-II response from a specific ECU.
pub fn obd_is_response_from_ecu(frame: CanFrame, ecu: i64) -> bool {Parameters:
frame:CanFrameecu:i64
Returns: bool
Defined at line 449
obd_is_response
Check if a frame is an OBD-II response from any ECU.
pub fn obd_is_response(frame: CanFrame) -> bool {Parameters:
frame:CanFrame
Returns: bool
Defined at line 454
UDS_SESSION_DEFAULT:
UDS Session Types
pub const UDS_SESSION_DEFAULT: i64 = 0x01; pub const UDS_SESSION_PROGRAMMING: i64 = 0x02; pub const UDS_SESSION_EXTENDED: i64 = 0x03; pub const UDS_SESSION_SAFETY: i64 = 0x04; pub const UDS_SESSION_PROTECTION: i64 = 0x05;Defined at line 461
uds_session_control
Build a UDS Diagnostic Session Control request.
pub fn uds_session_control(session: i64) -> CanFrame {Parameters:
session:i64
Returns: CanFrame
Defined at line 463
UDS_RESET_HARD:
UDS Reset Types
pub const UDS_RESET_HARD: i64 = 0x01; pub const UDS_RESET_KEY_OFF: i64 = 0x02; pub const UDS_RESET_SOFT: i64 = 0x03; pub const UDS_RESET_ENABLE_RAPID: i64 = 0x04; pub const UDS_RESET_DISABLE_RAPID: i64 = 0x05;Defined at line 473
uds_ecu_reset
Build a UDS ECU Reset request.
pub fn uds_ecu_reset(reset_type: i64) -> CanFrame {Parameters:
reset_type:i64
Returns: CanFrame
Defined at line 475
uds_security_access_request_seed
Build a UDS Security Access - Request Seed frame.
pub fn uds_security_access_request_seed(level: i64) -> CanFrame {Parameters:
level:i64
Returns: CanFrame
Defined at line 485
uds_security_access_send_key
Build a UDS Security Access - Send Key frame.
pub fn uds_security_access_send_key(level: i64, key: Vec<i64>) -> CanFrame {Parameters:
level:i64key:Vec<i64>
Returns: CanFrame
Defined at line 493
uds_read_data_by_id
Build a UDS Read Data By Identifier request. did: 16-bit Data Identifier (0x0000-0xFFFF)
pub fn uds_read_data_by_id(did: i64) -> CanFrame {Parameters:
did:i64
Returns: CanFrame
Defined at line 507
UDS_DID_VIN:
Common UDS Data Identifiers
pub const UDS_DID_VIN: i64 = 0xF190; pub const UDS_DID_ECU_SERIAL_NUMBER: i64 = 0xF18C; pub const UDS_DID_ECU_MANUFACTURE_DATE: i64 = 0xF18B; pub const UDS_DID_ECU_SOFTWARE_VERSION: i64 = 0xF191; pub const UDS_DID_ECU_HARDWARE_VERSION: i64 = 0xF192; pub const UDS_DID_BOOT_SOFTWARE_IDENTIFICATION: i64 = 0xF195;Defined at line 516
can_frame_print
Print a CAN frame in a human-readable format. Format: “CAN [STD|EXT] ID:0xXXX DLC:N [DATA]”
pub fn can_frame_print(frame: CanFrame) -> void {Parameters:
frame:CanFrame
Returns: void
Defined at line 521
Generated by scribe, the Fides documentation generator