pub fn packets(buffer: &[u8]) -> impl Iterator<Item = Packet<'_>>Expand description
Walks every packet the buffer holds, in the order the chip wrote them.
§Arguments
buffer- the bytes read out of the receive buffer.
§Returns
Each packet in turn. The walk stops at the first thing that does not read as one, which is how the end of the written part of the buffer announces itself.
§Examples
use pamoja_radios::sx1302::rx::packets;
// Two packets back to back, then the unwritten rest of the buffer.
let mut buffer = Vec::new();
for payload in [&b"one"[..], &b"two"[..]] {
buffer.extend_from_slice(&[0xa5, 0xc0, payload.len() as u8, 0, 0, 0, 0, 0, 0]);
buffer.extend_from_slice(payload);
buffer.extend_from_slice(&[0u8; 14]);
}
buffer.extend_from_slice(&[0u8; 32]);
let read: Vec<_> = packets(&buffer).map(|packet| packet.payload.to_vec()).collect();
assert_eq!(read, [b"one".to_vec(), b"two".to_vec()]);