smoltcp_null_modem

Crates.iosmoltcp_null_modem
lib.rssmoltcp_null_modem
version0.1.0-alpha4
created_at2024-10-17 09:00:00.666443+00
updated_at2024-10-17 09:02:21.573041+00
descriptionsmoltcp null modem drivers
homepagehttps://pub.npry.dev/interstice/about
repositoryhttps://pub.npry.dev/interstice
max_upload_size
id1412808
size11,080
Nathan Perry (mammothbane)

documentation

README

This crate provides "null modem" PHY drivers for smoltcp in both allocating and non-allocating variants.

You can see a null modem as a two-ended in-memory pipe, where both ends are smoltcp::phy::Device and the TX of one is connected directly to the RX of the other (and vice versa).

Example

use smoltcp::{
    phy::{
        Medium,
        Device as _,
        TxToken as _,
        RxToken as _,
    },
    time::Instant,
};

const MTU: usize = 128;
const CAPACITY: usize = 4;

let mut modem = smoltcp_null_modem::noalloc::<CAPACITY, MTU>(Medium::Ethernet);
let (mut phy1, mut phy2) = modem.split();

// Send a frame into the first interface
let tok = phy1.transmit(Instant::now()).unwrap();
tok.consume(10, |buf| {
    buf.copy_from_slice(&[0xa5; 10]);
});

// And it appears on the second
let (tok, _) = phy2.receive(Instant::now()).unwrap();
tok.consume(|buf| {
    assert_eq!(buf, &[0xa5; 10]);
});
Commit count: 0

cargo fmt