Reading over WireWeaver and USB¶
The drive is still running on the bench, pushing can0 as fast as the bus delivers it. An engineer wants to
watch it right now, not wait for the next power cut or carry the card to a desk. How does a live device's ring
reach a host, over its WireWeaver API, or as files on a USB disk?
Reading over WireWeaver¶
[`TrackStore`] turns one track of a mounted ring into a WireWeaver stream. It answers the same push, read
and release calls any stream server makes on any medium. A host that opens the drive's can0 stream gets every
record the track holds, the way a card image does, but new records keep arriving.
let frame = |id: u32| CanFrame {
id,
data: RefVec::Slice {
slice: &[1, 2, 3, 4, 5, 6, 7, 8],
},
};
let mut item = [0u8; 32];
let mut buf = [0u8; 64];
let bytes = frame(0x101).to_ww_bytes(&mut item).unwrap();
shared
.lock()
.await
.push(track::CAN0, bytes, None)
.await
.unwrap();
shared.lock().await.sync().await.unwrap();
// a host reads back only what reached the card, not what the stage buffer still holds
let event = store
.read(0, &mut buf)
.await
.unwrap()
.expect("the frame is on the card");
assert_eq!(CanFrame::from_ww_bytes(event.item).unwrap().id, 0x101);
// a second frame, not yet synced: staged in the writer's buffer, invisible to a live reader
let bytes = frame(0x102).to_ww_bytes(&mut item).unwrap();
shared
.lock()
.await
.push(track::CAN0, bytes, None)
.await
.unwrap();
assert!(
store.read(1, &mut buf).await.unwrap().is_none(),
"staged, not yet on the card"
);
// once it syncs, the same read returns it
shared.lock().await.sync().await.unwrap();
let event = store
.read(1, &mut buf)
.await
.unwrap()
.expect("the frame reached the card");
assert_eq!(CanFrame::from_ww_bytes(event.item).unwrap().id, 0x102);
A [`TrackStore`] read only returns what already reached the card. The test pushes a second frame without
syncing: a read at its position comes back empty, because the frame still sits in the writer's [`Buffers`]
stage. Once the next sync writes it, the same read returns it.
[`Logring::durable`] moves forward at every write of the stage buffer to the card, not only when a flush
ends. A host watching live therefore lags the push rate by about one stage write, not a whole flush interval.
The drive's stage buffer is 4 KiB, a quarter of its 16 KiB flush. A frame reaches the card, and a live reader, well before its flush closes, not after a full second.
ww_stream's resend buffer wraps the same store for a host that reboots, or loses the link for a while. It resumes
exactly where it left off: everything that reached the card since, once, in order, across sessions and power
cuts. That resend logic is ww_stream's own job, covered in the WireWeaver book. This book's part of it stops at
[`TrackStore`], which turns a track into a store.
Reading as files on a USB disk¶
The same ring is meant to show up as ordinary files, too. A read-only tree with one split file per recording
and a plain index would let a bare laptop read the files directly. It could pull a day's log or can0 straight
off a USB cable.
A passthrough logical unit would carry the card's own exFAT volume alongside it. Its small region of read-write files would stay an ordinary Secure Digital (SD) card to the host.
This view is designed, not built. Today's reading on a personal computer (PC) still goes through Reading a log on a PC's sources, never live.
Tapes and logring comes next: when the device's own reach is enough, and when a host recording is the better fit.