Merge pull request #1756 from dhylands/fix-usb-logger

Make usb-logger read and discard input data
This commit is contained in:
Dario Nieuwenhuis 2023-08-06 23:35:53 +00:00 committed by GitHub
commit 28eb3b95b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,22 +77,29 @@ impl<const N: usize> UsbLogger<N> {
); );
// Create classes on the builder. // Create classes on the builder.
let mut class = CdcAcmClass::new(&mut builder, &mut state.state, MAX_PACKET_SIZE as u16); let class = CdcAcmClass::new(&mut builder, &mut state.state, MAX_PACKET_SIZE as u16);
let (mut sender, mut receiver) = class.split();
// Build the builder. // Build the builder.
let mut device = builder.build(); let mut device = builder.build();
loop { loop {
let run_fut = device.run(); let run_fut = device.run();
let log_fut = async { let log_fut = async {
let mut rx: [u8; MAX_PACKET_SIZE as usize] = [0; MAX_PACKET_SIZE as usize]; let mut rx: [u8; MAX_PACKET_SIZE as usize] = [0; MAX_PACKET_SIZE as usize];
class.wait_connection().await; sender.wait_connection().await;
loop { loop {
let len = self.buffer.read(&mut rx[..]).await; let len = self.buffer.read(&mut rx[..]).await;
let _ = class.write_packet(&rx[..len]).await; let _ = sender.write_packet(&rx[..len]).await;
} }
}; };
join(run_fut, log_fut).await; let discard_fut = async {
let mut discard_buf: [u8; MAX_PACKET_SIZE as usize] = [0; MAX_PACKET_SIZE as usize];
receiver.wait_connection().await;
loop {
let _ = receiver.read_packet(&mut discard_buf).await;
}
};
join(run_fut, join(log_fut, discard_fut)).await;
} }
} }
} }