fn udp_send_if_free(&mut self, sn: Sn, buf: &[u8]) -> Result<u16, Self::Error> {
        debug_assert_eq!(self.sn_sr(sn)?, Ok(SocketStatus::Udp));

        let data_len: u16 = match u16::try_from(buf.len()) {
            Ok(l) => l,
            Err(_) => return Ok(0),
        };
        let free_size: u16 = self.sn_tx_fsr(sn)?;
        if data_len <= free_size {
            let ptr: u16 = self.sn_tx_wr(sn)?;
            self.set_sn_tx_buf(sn, ptr, buf)?;
            self.set_sn_tx_wr(sn, ptr.wrapping_add(data_len))?;
            self.set_sn_cr(sn, SocketCommand::Send)?;
        }
        Ok(data_len)
    }
/// Sends data to the currently configured destination.
/// On success, returns the number of bytes written.
///
/// The destination is set by the last call to [`Registers::set_sn_dest`],
/// [`Udp::udp_send_to`], or [`UdpWriter::udp_send_to`].
///
/// This will transmit only if there is enough free space in the W5500
/// transmit buffer.
///
/// # Panics
///
/// * (debug) The socket must be opened as a UDP socket.
///
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// use w5500_hl::{
///     ll::{Registers, Sn::Sn0},
///     net::{Ipv4Addr, SocketAddrV4},
///     Udp,
/// };
///
/// const DEST: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 0, 2, 1), 8081);
///
/// w5500.udp_bind(Sn0, 8080)?;
/// let buf: [u8; 10] = [0; 10];
/// let tx_bytes: u16 = w5500.udp_send_to_if_free(Sn0, &buf, &DEST)?;
/// assert_eq!(usize::from(tx_bytes), buf.len());
/// // send the same to the same destination
/// let tx_bytes: u16 = w5500.udp_send_if_free(Sn0, &buf)?;
/// assert_eq!(usize::from(tx_bytes), buf.len());
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// ```
///
/// [`UdpWriter::udp_send_to`]: crate::UdpWriter::udp_send_to
Sends data to the currently configured destination.
On success, returns the number of bytes written.



This will transmit only if there is enough free space in the W5500
transmit buffer.
Sends data to the currently configured destination . On success returns the number of bytes written . This will transmit only if there is enough free space in the W5500 transmit buffer .
fn udp_send_if_free(&mut self, sn: Sn, buf: &[u8]) -> Result<u16, Self::Error> {
        debug_assert_eq!(self.sn_sr(sn)?, Ok(SocketStatus::Udp));
        let data_len: u16 = match u16::try_from(buf.len()) {
            Ok(l) => l,
            Err(_) => return Ok(0),
        };
        let free_size: u16 = self.sn_tx_fsr(sn)?;
        if data_len <= free_size {
            let ptr: u16 = self.sn_tx_wr(sn)?;
            self.set_sn_tx_buf(sn, ptr, buf)?;
            self.set_sn_tx_wr(sn, ptr.wrapping_add(data_len))?;
            self.set_sn_cr(sn, SocketCommand::Send)?;
        }
        Ok(data_len)
    }
fn udp_send_if_free ( & mut self , sn : Sn , buf : & [ u8 ] ) -> Result < u16 , Self :: Error > { debug_assert_eq ! ( self sn_sr ( sn ) Ok ( SocketStatus Udp ) ) ; let data_len : u16 = match u16 :: try_from ( buf . len ( ) ) { Ok ( l ) => l , Err ( _ ) => return Ok ( 0 ) , } ; let free_size : u16 = self . sn_tx_fsr ( sn ) ? ; if data_len <= free_size { let ptr : u16 = self . sn_tx_wr ( sn ) ? ; self . set_sn_tx_buf ( sn , ptr , buf ) ? ; self . set_sn_tx_wr ( sn , ptr . wrapping_add ( data_len ) ) ? ; self . set_sn_cr ( sn , SocketCommand :: Send ) ? ; } Ok ( data_len ) }
Sends data to the currently configured destination.
Sends data to the currently configured destination .
&mut self
sn
Sn
buf
&[u8]
&mut self
sn
Sn
buf
&[u8]
panics
(debug) The socket must be opened as a UDP socket.
( debug ) The socket must be opened as a UDP socket .
example
None
use embedded_hal_mock as h;
None
let mut w5500 = w5500_ll::blocking::vdm::w5500::new(h::spi::mock::new(&[]), h::pin::mock::new(&[]));
None
ok::<(), w5500_hl::ll::blocking::vdm::error<_, _>>(())
None