Protocol

Trait Protocol 

Source
pub trait Protocol {
    // Required methods
    fn get_timeout(&self) -> Duration;
    fn get_polling_interval(&self) -> Duration;
    fn get_identifier(&self) -> &str;
    fn read(&mut self, bytes: usize) -> Result<Vec<u8>, CommunicationError>;
    fn write_packet_raw(
        &mut self,
        data: &[u8],
    ) -> Result<(), CommunicationError>;
    fn read_packet_raw(
        &mut self,
        packet_code: u8,
    ) -> Result<Vec<u8>, CommunicationError>;

    // Provided methods
    fn write_packet_concrete<T>(
        &mut self,
        packet: T,
    ) -> Result<(), CommunicationError>
       where T: PacketConstruct + Packet { ... }
    fn read_packet_concrete<T>(&mut self) -> Result<T, CommunicationError>
       where T: PacketParse + Packet { ... }
}
Expand description

Core protocol trait for McuBoot communication

This trait defines the methods that all McuBoot protocol implementations must provide.

Required Methods§

Source

fn get_timeout(&self) -> Duration

Get the configured timeout duration for operations

Source

fn get_polling_interval(&self) -> Duration

Get the polling interval for checking responses

Source

fn get_identifier(&self) -> &str

Get a string identifier for this protocol instance

Source

fn read(&mut self, bytes: usize) -> Result<Vec<u8>, CommunicationError>

Read raw bytes from the device

§Arguments
  • bytes - Number of bytes to read
§Returns

A Result containing the read bytes or an error

§Errors

Any errors that occured while reading, from being unable to read to invalid CRC checksum.

Source

fn write_packet_raw(&mut self, data: &[u8]) -> Result<(), CommunicationError>

Write raw packet data to the device

§Arguments
  • data - Raw packet bytes to send
§Returns

A Result indicating success or error

§Errors

Any errors that occured while writing, from being unable to write to invalid CRC checksum.

Source

fn read_packet_raw( &mut self, packet_code: u8, ) -> Result<Vec<u8>, CommunicationError>

Read a raw packet with specific type code

§Arguments
  • packet_code - Expected packet type code
§Returns

A Result containing the packet payload or an error

§Errors

Any errors that occured while reading, from being unable to read to invalid CRC checksum.

Provided Methods§

Source

fn write_packet_concrete<T>( &mut self, packet: T, ) -> Result<(), CommunicationError>

Write a strongly-typed packet to the device

This method handles packet construction and transmission for any type that implements the required packet traits.

§Arguments
  • packet - The packet to send
§Returns

A Result indicating success or error

§Errors

Any errors that occured while writing, from being unable to write to invalid CRC checksum.

Source

fn read_packet_concrete<T>(&mut self) -> Result<T, CommunicationError>
where T: PacketParse + Packet,

Read a strongly-typed packet from the device

This method handles packet reception and parsing for any type that implements the required packet traits.

§Returns

A Result containing the parsed packet or an error

§Errors

Any errors that occured while reading, from being unable to read to invalid CRC checksum.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§