commit - b06a845dd6f58f59bca5ba923fa9e6c8f4940c70
commit + c45b455bfad255bb3e6cab35e1dbc6bd8ad9bc61
blob - dbc73becf07d8b46149d62ef0e3b66cbd807a1e7
blob + 517246328d0094049b939cf24fe1793eb882594b
--- src/main.rs
+++ src/main.rs
Ok(None)
}
-async fn handle_buffer_ready(
- peripheral: &btleplug::platform::Peripheral,
- characteristic: &Characteristic,
- ready: bool,
- buffer_len: usize,
-) {
- debug!("In handle_buffer_ready");
- if !ready {
- //info!(
- // "Unsubscribing from characteristic {:?}",
- // characteristic.uuid
- //);
- //if let Err(e) = peripheral.unsubscribe(characteristic).await {
- // error!(
- // "Unable to unsubscribe from characteristic {:?} of periheral {:?}: {:?}",
- // characteristic.uuid,
- // peripheral.address(),
- // e
- // );
- //}
- info!("Peripheral not ready, exiting handle_buffer_ready");
- return;
- }
-
- // write buffer of peripheral
- let buf = std::iter::repeat(1).take(buffer_len).collect::<Vec<_>>();
- if let Err(e) = peripheral
- .write(characteristic, &buf, WriteType::WithoutResponse)
- .await
- {
- error!(
- "Unable to write buffer to peripheral ({:?}): {:?}",
- peripheral.address(),
- e
- );
- }
-
- debug!("Done with handle_buffer_ready");
-}
-
async fn get_buffer_len(
peripheral: &btleplug::platform::Peripheral,
characteristic: &Characteristic,
let adapter_list = manager.adapters().await?;
info!("adapters: {:?}", adapter_list);
+ // TODO: only allow adapters that support BLE 5.0 or higher
if adapter_list.is_empty() {
anyhow::bail!("No adapters found");
}
info!("Service {:?} provides all characteristics", SERVICE_UUID);
}
- let buffer_ready_char = service
- .characteristics
- .iter()
- .find(|c| c.uuid == BUFFER_READY_UUID)
- .unwrap();
- //esp.subscribe(buffer_ready_char).await?;
-
// get the buffer length the esp set to know how big the buffer is
let buffer_len_char = service
.characteristics
.find(|c| c.uuid == DATA_BUFFER_UUID)
.unwrap();
- loop {
+ // send around (512 byte * 8) * 512 iteration / (10^3) = 2097.152 kbit
+ for _ in 0..512 {
let buffer: Vec<u8> = std::iter::repeat_with(rand::random)
.take(buffer_len)
.collect();
- // calls to `write` with a `WriteType` of `WithResponse` *should* wait for a response
- // before continuing
- esp.write(data_buffer_char, &buffer, WriteType::WithResponse)
+ esp.write(data_buffer_char, &buffer, WriteType::WithoutResponse)
.await?;
+ log::info!("Sending another {} bytes", buffer.len());
}
- info!("Nothing else to do. Disconnecting");
+ info!("Done");
esp.disconnect().await?;
Ok(())