Skip to content

Commit

Permalink
Remove old code
Browse files Browse the repository at this point in the history
This has been moved to the `ble_handler` mod.
  • Loading branch information
lukipuki committed Sep 30, 2024
1 parent 41f83a7 commit 50cac09
Showing 1 changed file with 0 additions and 64 deletions.
64 changes: 0 additions & 64 deletions src/utils_internal.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#[cfg(feature = "bluetooth-le")]
use crate::errors_internal::BleConnectionError;
use crate::errors_internal::Error;
#[cfg(feature = "bluetooth-le")]
use btleplug::api::{Central, Manager as _, Peripheral as _, ScanFilter};
#[cfg(feature = "bluetooth-le")]
use btleplug::platform::{Adapter, Manager, Peripheral};
#[cfg(feature = "bluetooth-le")]
use log::error;
use std::time::Duration;
use std::time::UNIX_EPOCH;
#[cfg(feature = "bluetooth-le")]
use uuid::Uuid;

use rand::{distributions::Standard, prelude::Distribution, Rng};
use tokio_serial::{available_ports, SerialPort, SerialStream};
Expand Down Expand Up @@ -204,60 +194,6 @@ pub async fn build_tcp_stream(
Ok(StreamHandle::from_stream(stream))
}

#[cfg(feature = "bluetooth-le")]
#[allow(dead_code)]
const MSH_SERVICE: Uuid = Uuid::from_u128(0x6ba1b218_15a8_461f_9fa8_5dcae273eafd);

#[cfg(feature = "bluetooth-le")]
#[allow(dead_code)]
async fn scan_peripherals(adapter: &Adapter) -> Result<Vec<Peripheral>, btleplug::Error> {
adapter
.start_scan(ScanFilter {
services: vec![MSH_SERVICE],
})
.await?;
adapter.peripherals().await
}

/// Finds a BLE radio matching a given name and running meshtastic.
/// It searches for the 'MSH_SERVICE' running on the device.
#[cfg(feature = "bluetooth-le")]
#[allow(dead_code)]
async fn find_ble_radio(name: String) -> Result<Peripheral, Error> {
//TODO: support searching both by a name and by a MAC address
let scan_error_fn = |e: btleplug::Error| Error::StreamBuildError {
source: Box::new(e),
description: "Failed to scan for BLE devices".to_owned(),
};
let manager = Manager::new().await.map_err(scan_error_fn)?;
let adapters = manager.adapters().await.map_err(scan_error_fn)?;

for adapter in &adapters {
let peripherals = scan_peripherals(adapter).await;
match peripherals {
Err(e) => {
error!("Error while scanning for meshtastic peripherals: {e:?}");
// We continue, as there can be another adapter that can work
continue;
}
Ok(peripherals) => {
for peripheral in peripherals {
if let Ok(Some(peripheral_properties)) = peripheral.properties().await {
if peripheral_properties.local_name == Some(name.clone()) {
return Ok(peripheral);
}
}
}
}
}
}
Err(Error::StreamBuildError {
source: Box::new(BleConnectionError()),
description: format!("Failed to find {name}, or meshtastic is not running on the device")
+ ", or it's already connected.",
})
}

/// A helper method to generate random numbers using the `rand` crate.
///
/// This method is intended to be used to generate random id values. This method
Expand Down

0 comments on commit 50cac09

Please sign in to comment.