Trait profirust::phy::ProfibusPhy

source ·
pub trait ProfibusPhy {
    // Required methods
    fn poll_transmission(&mut self, now: Instant) -> bool;
    fn transmit_data<F, R>(&mut self, now: Instant, f: F) -> R
       where F: FnOnce(&mut [u8]) -> (usize, R);
    fn receive_data<F, R>(&mut self, now: Instant, f: F) -> R
       where F: FnOnce(&[u8]) -> (usize, R);

    // Provided methods
    fn transmit_telegram<F>(
        &mut self,
        now: Instant,
        f: F
    ) -> Option<TelegramTxResponse>
       where F: FnOnce(TelegramTx<'_>) -> Option<TelegramTxResponse> { ... }
    fn receive_telegram<F, R>(&mut self, now: Instant, f: F) -> Option<R>
       where F: FnOnce(Telegram<'_>) -> R { ... }
    fn poll_pending_received_bytes(&mut self, now: Instant) -> usize { ... }
}
Expand description

Generic abstraction for profirust PHY implementations

Required Methods§

source

fn poll_transmission(&mut self, now: Instant) -> bool

Poll an ongoing transmission.

Should return true while the transmission is still in progress and false once it has been completed.

While this function returns true, calling any of the transmit_*() or receive_*() functions may panic.

source

fn transmit_data<F, R>(&mut self, now: Instant, f: F) -> R
where F: FnOnce(&mut [u8]) -> (usize, R),

Schedule transmission of some data.

The data is written by the closure f into the buffer passed to it. f then returns how many bytes were written. Only this many bytes must be transmitted.

Important: This function must not block on the actual transmission!

§Panics

This function may panic when a transmission is already ongoing.

source

fn receive_data<F, R>(&mut self, now: Instant, f: F) -> R
where F: FnOnce(&[u8]) -> (usize, R),

Try receiving some data.

The closure f will process all received data and return how many bytes should be dropped from the receive buffer.

Important: This function must not block on the actually receiving data and should instead return an empty buffer if no data is available!

§Panics

This function may panic when a transmission is ongoing.

Provided Methods§

source

fn transmit_telegram<F>( &mut self, now: Instant, f: F ) -> Option<TelegramTxResponse>
where F: FnOnce(TelegramTx<'_>) -> Option<TelegramTxResponse>,

Schedule transmission of a telegram.

The closure f may (or may not) call one of the methods of [fdl::TelegramTx][crate::fdl::TelegramTx] to schedule transmission of a telegram. This function returns Some(n) (n = number of bytes for transmission) when a telegram was scheduled and None otherwise.

Important: This function must not block on the actual transmission!

§Panics

This function may panic when a transmission is already ongoing.

source

fn receive_telegram<F, R>(&mut self, now: Instant, f: F) -> Option<R>
where F: FnOnce(Telegram<'_>) -> R,

Try receiving a telegram.

When a full and correct telegram was received, the closure f is called to process it.

Important: This function must not block on the actually receiving a telegram and should return None in case no full telegram was received yet!

§Panics

This function may panic when a transmission is ongoing.

source

fn poll_pending_received_bytes(&mut self, now: Instant) -> usize

Poll for the current amount of bytes waiting in the receive buffer.

The receive buffer is not emptied by this call.

Important: This function must not block on the actually receiving data and should instead return 0 if no data is available!

§Panics

This function may panic when a transmission is ongoing.

Object Safety§

This trait is not object safe.

Implementors§