|
1 |
| -#[cfg(feature = "bluetooth-le")] |
2 |
| -use crate::errors_internal::BleConnectionError; |
3 | 1 | use crate::errors_internal::Error;
|
4 |
| -#[cfg(feature = "bluetooth-le")] |
5 |
| -use btleplug::api::{Central, Manager as _, Peripheral as _, ScanFilter}; |
6 |
| -#[cfg(feature = "bluetooth-le")] |
7 |
| -use btleplug::platform::{Adapter, Manager, Peripheral}; |
8 |
| -#[cfg(feature = "bluetooth-le")] |
9 |
| -use log::error; |
10 | 2 | use std::time::Duration;
|
11 | 3 | use std::time::UNIX_EPOCH;
|
12 |
| -#[cfg(feature = "bluetooth-le")] |
13 |
| -use uuid::Uuid; |
14 | 4 |
|
15 | 5 | use rand::{distributions::Standard, prelude::Distribution, Rng};
|
16 | 6 | use tokio_serial::{available_ports, SerialPort, SerialStream};
|
@@ -204,60 +194,6 @@ pub async fn build_tcp_stream(
|
204 | 194 | Ok(StreamHandle::from_stream(stream))
|
205 | 195 | }
|
206 | 196 |
|
207 |
| -#[cfg(feature = "bluetooth-le")] |
208 |
| -#[allow(dead_code)] |
209 |
| -const MSH_SERVICE: Uuid = Uuid::from_u128(0x6ba1b218_15a8_461f_9fa8_5dcae273eafd); |
210 |
| - |
211 |
| -#[cfg(feature = "bluetooth-le")] |
212 |
| -#[allow(dead_code)] |
213 |
| -async fn scan_peripherals(adapter: &Adapter) -> Result<Vec<Peripheral>, btleplug::Error> { |
214 |
| - adapter |
215 |
| - .start_scan(ScanFilter { |
216 |
| - services: vec![MSH_SERVICE], |
217 |
| - }) |
218 |
| - .await?; |
219 |
| - adapter.peripherals().await |
220 |
| -} |
221 |
| - |
222 |
| -/// Finds a BLE radio matching a given name and running meshtastic. |
223 |
| -/// It searches for the 'MSH_SERVICE' running on the device. |
224 |
| -#[cfg(feature = "bluetooth-le")] |
225 |
| -#[allow(dead_code)] |
226 |
| -async fn find_ble_radio(name: String) -> Result<Peripheral, Error> { |
227 |
| - //TODO: support searching both by a name and by a MAC address |
228 |
| - let scan_error_fn = |e: btleplug::Error| Error::StreamBuildError { |
229 |
| - source: Box::new(e), |
230 |
| - description: "Failed to scan for BLE devices".to_owned(), |
231 |
| - }; |
232 |
| - let manager = Manager::new().await.map_err(scan_error_fn)?; |
233 |
| - let adapters = manager.adapters().await.map_err(scan_error_fn)?; |
234 |
| - |
235 |
| - for adapter in &adapters { |
236 |
| - let peripherals = scan_peripherals(adapter).await; |
237 |
| - match peripherals { |
238 |
| - Err(e) => { |
239 |
| - error!("Error while scanning for meshtastic peripherals: {e:?}"); |
240 |
| - // We continue, as there can be another adapter that can work |
241 |
| - continue; |
242 |
| - } |
243 |
| - Ok(peripherals) => { |
244 |
| - for peripheral in peripherals { |
245 |
| - if let Ok(Some(peripheral_properties)) = peripheral.properties().await { |
246 |
| - if peripheral_properties.local_name == Some(name.clone()) { |
247 |
| - return Ok(peripheral); |
248 |
| - } |
249 |
| - } |
250 |
| - } |
251 |
| - } |
252 |
| - } |
253 |
| - } |
254 |
| - Err(Error::StreamBuildError { |
255 |
| - source: Box::new(BleConnectionError()), |
256 |
| - description: format!("Failed to find {name}, or meshtastic is not running on the device") |
257 |
| - + ", or it's already connected.", |
258 |
| - }) |
259 |
| -} |
260 |
| - |
261 | 197 | /// A helper method to generate random numbers using the `rand` crate.
|
262 | 198 | ///
|
263 | 199 | /// This method is intended to be used to generate random id values. This method
|
|
0 commit comments