Struct StandardId

Source
pub struct StandardId(/* private fields */);
Expand description

Standard 11-bit CAN Identifier (0..=0x7FF).

Implementations§

Source§

impl StandardId

Source

pub const ZERO: StandardId

CAN ID 0, the highest priority.

Source

pub const MAX: StandardId

CAN ID 0x7FF, the lowest priority.

Source

pub const fn new(raw: u16) -> Option<StandardId>

Tries to create a StandardId from a raw 16-bit integer.

This will return None if raw is out of range of an 11-bit integer (> 0x7FF).

Examples found in repository?
examples/isotprecv.rs (line 6)
3fn main() -> Result<(), socketcan_isotp::Error> {
4    let mut tp_socket = IsoTpSocket::open(
5        "vcan0",
6        StandardId::new(0x123).expect("Invalid rx id"),
7        StandardId::new(0x321).expect("Invalid tx id"),
8    )?;
9
10    let buffer = tp_socket.read()?;
11    println!("read {} bytes", buffer.len());
12
13    for x in buffer {
14        print!("{:X?} ", x);
15    }
16
17    println!("");
18
19    Ok(())
20}
More examples
Hide additional examples
examples/isotpsend.rs (line 7)
4fn main() -> Result<(), socketcan_isotp::Error> {
5    let tp_socket = IsoTpSocket::open(
6        "vcan0",
7        StandardId::new(0x321).expect("Invalid rx id"),
8        StandardId::new(0x123).expect("Invalid tx id"),
9    )?;
10
11    loop {
12        tp_socket.write(&[0xAA, 0x11, 0x22, 0x33, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF])?;
13        println!("Sent frame");
14        std::thread::sleep(Duration::from_millis(1000));
15    }
16}
examples/uds.rs (line 14)
8fn main() -> Result<(), socketcan_isotp::Error> {
9    let (tx, rx) = mpsc::channel();
10
11    // Reader
12    let mut reader_tp_socket = IsoTpSocket::open(
13        "vcan0",
14        StandardId::new(0x7E8).expect("Invalid rx CAN ID"),
15        StandardId::new(0x77A).expect("Invalid tx CAN ID"),
16    )?;
17    std::thread::spawn(move || loop {
18        let buffer = reader_tp_socket.read().expect("Failed to read from socket");
19        tx.send(buffer.to_vec()).expect("Receiver deallocated");
20    });
21
22    let tp_socket = IsoTpSocket::open(
23        "vcan0",
24        StandardId::new(0x77A).expect("Invalid rx CAN ID"),
25        StandardId::new(0x7E0).expect("Invalid tx CAN ID"),
26    )?;
27
28    // 0x22 - Service Identifier for "Read data by identifier" request
29    // 0xF189 - Data identifer - VehicleManufacturerECUSoftwareVersionNumberDataIdentifier
30    tp_socket.write(&[0x22, 0xF1, 0x89])?;
31
32    println!("Sent read data by identifier 0xF189 - VehicleManufacturerECUSoftwareVersionNumberDataIdentifier");
33
34    loop {
35        let recv_buffer = rx.recv().expect("Failed to receive");
36        // 0x62 - Service Identifier for "Read data by identifier" response
37        // 0xF189 - Data identifer - VehicleManufacturerECUSoftwareVersionNumberDataIdentifier
38        if recv_buffer[0..=2] != [0x62, 0xF1, 0x89] {
39            println!("Skipping: {:X?}", recv_buffer);
40        } else {
41            println!("Response: {:X?}", &recv_buffer[3..]);
42        }
43    }
44}
Source

pub const unsafe fn new_unchecked(raw: u16) -> StandardId

Creates a new StandardId without checking if it is inside the valid range.

§Safety

Using this method can create an invalid ID and is thus marked as unsafe.

Source

pub fn as_raw(&self) -> u16

Returns this CAN Identifier as a raw 16-bit integer.

Trait Implementations§

Source§

impl Clone for StandardId

Source§

fn clone(&self) -> StandardId

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StandardId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<StandardId> for Id

Source§

fn from(id: StandardId) -> Id

Converts to this type from the input type.
Source§

impl Hash for StandardId

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for StandardId

Source§

fn cmp(&self, other: &StandardId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for StandardId

Source§

fn eq(&self, other: &StandardId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for StandardId

Source§

fn partial_cmp(&self, other: &StandardId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for StandardId

Source§

impl Eq for StandardId

Source§

impl StructuralPartialEq for StandardId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.