| Crates.io | smoltcp_null_modem |
| lib.rs | smoltcp_null_modem |
| version | 0.1.0-alpha4 |
| created_at | 2024-10-17 09:00:00.666443+00 |
| updated_at | 2024-10-17 09:02:21.573041+00 |
| description | smoltcp null modem drivers |
| homepage | https://pub.npry.dev/interstice/about |
| repository | https://pub.npry.dev/interstice |
| max_upload_size | |
| id | 1412808 |
| size | 11,080 |
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).
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]);
});