commit c45b455bfad255bb3e6cab35e1dbc6bd8ad9bc61 from: Thomas Böhler date: Tue Nov 22 09:41:37 2022 UTC Remove unused code, send 2Mbit without response commit - b06a845dd6f58f59bca5ba923fa9e6c8f4940c70 commit + c45b455bfad255bb3e6cab35e1dbc6bd8ad9bc61 blob - dbc73becf07d8b46149d62ef0e3b66cbd807a1e7 blob + 517246328d0094049b939cf24fe1793eb882594b --- src/main.rs +++ src/main.rs @@ -45,46 +45,6 @@ async fn find_device( 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::>(); - 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, @@ -110,6 +70,7 @@ async fn main() -> anyhow::Result<()> { 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"); } @@ -149,13 +110,6 @@ async fn main() -> anyhow::Result<()> { 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 @@ -171,18 +125,18 @@ async fn main() -> anyhow::Result<()> { .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 = 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(())