pub trait PayloadChannel: Send + Sync {
    // Required methods
    fn open(&mut self) -> ChannelResult<()>;
    fn close(&mut self) -> ChannelResult<()>;
    fn set_ids(&mut self, send: u32, recv: u32) -> ChannelResult<()>;
    fn read_bytes(&mut self, timeout_ms: u32) -> ChannelResult<Vec<u8>>;
    fn write_bytes(
        &mut self,
        addr: u32,
        ext_id: Option<u8>,
        buffer: &[u8],
        timeout_ms: u32
    ) -> ChannelResult<()>;
    fn clear_rx_buffer(&mut self) -> ChannelResult<()>;
    fn clear_tx_buffer(&mut self) -> ChannelResult<()>;

    // Provided method
    fn read_write_bytes(
        &mut self,
        addr: u32,
        ext_id: Option<u8>,
        buffer: &[u8],
        write_timeout_ms: u32,
        read_timeout_ms: u32
    ) -> ChannelResult<Vec<u8>> { ... }
}
Expand description

A payload channel is a way for a device to have a bi-directional communication link with a specific ECU

Required Methods§

source

fn open(&mut self) -> ChannelResult<()>

This function opens the interface. It is ONLY called after set_ids and any other configuration function

source

fn close(&mut self) -> ChannelResult<()>

Closes and destroys the channel

source

fn set_ids(&mut self, send: u32, recv: u32) -> ChannelResult<()>

Configures the diagnostic channel with specific IDs for configuring the diagnostic server

§Parameters
  • send - Send ID (ECU will listen for data with this ID)
  • recv - Receiving ID (ECU will send data with this ID)
source

fn read_bytes(&mut self, timeout_ms: u32) -> ChannelResult<Vec<u8>>

Attempts to read bytes from the channel.

The contents being read should not include any protocol related bytes, just the payload destined for the diagnostic application

§Parameters
  • timeout_ms - Timeout for reading bytes. If a value of 0 is used, it instructs the channel to immediately return with whatever was in its receiving buffer
source

fn write_bytes( &mut self, addr: u32, ext_id: Option<u8>, buffer: &[u8], timeout_ms: u32 ) -> ChannelResult<()>

Attempts to write bytes to the channel.

The contents being sent will just be the raw payload being sent to the device, it is up to the implementor of this function to add related protocol bytes to the message where necessary.

§Parameters
  • addr - Target address of the message
  • ext_id - Optional extended address of the message
  • buffer - The buffer of bytes to write to the channel
  • timeout_ms - Timeout for writing bytes. If a value of 0 is used, it tells the channel to write without checking if data was actually written.
source

fn clear_rx_buffer(&mut self) -> ChannelResult<()>

Tells the channel to clear its Rx buffer. This means all pending messages to be read should be wiped from the devices queue, such that PayloadChannel::read_bytes does not read them

source

fn clear_tx_buffer(&mut self) -> ChannelResult<()>

Tells the channel to clear its Tx buffer. This means all messages that are queued to be sent to the ECU should be wiped.

Provided Methods§

source

fn read_write_bytes( &mut self, addr: u32, ext_id: Option<u8>, buffer: &[u8], write_timeout_ms: u32, read_timeout_ms: u32 ) -> ChannelResult<Vec<u8>>

Attempts to write bytes to the channel, then listen for the channels response

§Parameters
  • Target address of the message
  • ext_id - Optional extended address of the message
  • buffer - The buffer of bytes to write to the channel as the request
  • write_timeout_ms - Timeout for writing bytes. If a value of 0 is used, it tells the channel to write without checking if data was actually written.
  • read_timeout_ms - Timeout for reading bytes. If a value of 0 is used, it instructs the channel to immediately return with whatever was in its receiving buffer

Implementations on Foreign Types§

source§

impl<T: PayloadChannel + ?Sized> PayloadChannel for Box<T>

source§

fn open(&mut self) -> ChannelResult<()>

source§

fn close(&mut self) -> ChannelResult<()>

source§

fn set_ids(&mut self, send: u32, recv: u32) -> ChannelResult<()>

source§

fn read_bytes(&mut self, timeout_ms: u32) -> ChannelResult<Vec<u8>>

source§

fn write_bytes( &mut self, addr: u32, ext_id: Option<u8>, buffer: &[u8], timeout_ms: u32 ) -> ChannelResult<()>

source§

fn clear_rx_buffer(&mut self) -> ChannelResult<()>

source§

fn clear_tx_buffer(&mut self) -> ChannelResult<()>

source§

impl<T: PayloadChannel + ?Sized> PayloadChannel for Arc<Mutex<T>>

source§

fn open(&mut self) -> ChannelResult<()>

source§

fn close(&mut self) -> ChannelResult<()>

source§

fn set_ids(&mut self, send: u32, recv: u32) -> ChannelResult<()>

source§

fn read_bytes(&mut self, timeout_ms: u32) -> ChannelResult<Vec<u8>>

source§

fn write_bytes( &mut self, addr: u32, ext_id: Option<u8>, buffer: &[u8], timeout_ms: u32 ) -> ChannelResult<()>

source§

fn clear_rx_buffer(&mut self) -> ChannelResult<()>

source§

fn clear_tx_buffer(&mut self) -> ChannelResult<()>

Implementors§