host_can/adapter/
mod.rs

1//! CAN Adapter Interface
2#[cfg(feature = "pcan")]
3pub mod pcan;
4
5#[cfg(feature = "socketcan")]
6pub mod socketcan;
7
8use std::time::Duration;
9
10use thiserror::Error;
11
12use crate::frame::CanFrame;
13
14#[derive(Error, Debug)]
15pub enum AdapterError {
16    #[error("Could not open adapter interface")]
17    OpenFailed,
18    #[error("Unable to send message")]
19    WriteFailed,
20    #[error("Unable to receive message")]
21    ReadFailed,
22    #[error("The read operation timed out")]
23    ReadTimeout,
24}
25
26/// Base adapter interface (blocking)
27pub trait Adapter {
28    /// Send a CAN frame
29    fn send(&self, frame: &CanFrame) -> Result<(), Box<AdapterError>>;
30
31    /// Receive a CAN frame
32    fn recv(
33        &self,
34        timeout: Option<Duration>,
35    ) -> Result<CanFrame, Box<AdapterError>>;
36}