pub struct Scanner { /* private fields */ }Expand description
BLE Scanner for discovering HIVE nodes
Handles beacon reception, filtering, deduplication, and device tracking.
Note: This type requires the std feature for full functionality.
Implementations§
Source§impl Scanner
impl Scanner
Sourcepub fn new(config: DiscoveryConfig) -> Self
pub fn new(config: DiscoveryConfig) -> Self
Create a new scanner with default settings
Sourcepub fn set_time_ms(&mut self, time_ms: u64)
pub fn set_time_ms(&mut self, time_ms: u64)
Set the current time (call periodically from platform)
Sourcepub fn set_filter(&mut self, filter: ScanFilter)
pub fn set_filter(&mut self, filter: ScanFilter)
Set the scan filter
Sourcepub fn set_device_timeout_ms(&mut self, timeout_ms: u64)
pub fn set_device_timeout_ms(&mut self, timeout_ms: u64)
Set device timeout in milliseconds
Sourcepub fn set_beacon_key(&mut self, key: BeaconKey, mesh_id_bytes: [u8; 4])
pub fn set_beacon_key(&mut self, key: BeaconKey, mesh_id_bytes: [u8; 4])
Configure beacon key for decrypting encrypted advertisements
§Arguments
key- Beacon encryption key from mesh genesismesh_id_bytes- Expected 4-byte mesh identifier for filtering
When configured, the scanner will attempt to decrypt encrypted beacons and only accept those from the specified mesh.
Sourcepub fn clear_beacon_key(&mut self)
pub fn clear_beacon_key(&mut self)
Clear beacon key (stop accepting encrypted beacons)
Sourcepub fn can_decrypt_beacons(&self) -> bool
pub fn can_decrypt_beacons(&self) -> bool
Check if this scanner can decrypt encrypted beacons
Sourcepub fn state(&self) -> ScannerState
pub fn state(&self) -> ScannerState
Get current state
Sourcepub fn process_advertisement(&mut self, adv: ParsedAdvertisement) -> bool
pub fn process_advertisement(&mut self, adv: ParsedAdvertisement) -> bool
Process a received advertisement
Returns true if this is a new or updated device that passes the filter.
Handles both plaintext and encrypted beacons:
- Plaintext beacons are processed directly from
adv.beacon - Encrypted beacons (in
adv.encrypted_service_data) are decrypted if a beacon key is configured
Sourcepub fn get_device(&self, node_id: &NodeId) -> Option<&TrackedDevice>
pub fn get_device(&self, node_id: &NodeId) -> Option<&TrackedDevice>
Get a tracked device by node ID
Sourcepub fn get_node_id_for_address(&self, address: &str) -> Option<&NodeId>
pub fn get_node_id_for_address(&self, address: &str) -> Option<&NodeId>
Get node ID for an address
Sourcepub fn devices(&self) -> impl Iterator<Item = &TrackedDevice>
pub fn devices(&self) -> impl Iterator<Item = &TrackedDevice>
Get all tracked devices
Sourcepub fn devices_by_rssi(&self) -> Vec<&TrackedDevice>
pub fn devices_by_rssi(&self) -> Vec<&TrackedDevice>
Get devices sorted by RSSI (strongest first)
Sourcepub fn devices_by_hierarchy(&self) -> Vec<&TrackedDevice>
pub fn devices_by_hierarchy(&self) -> Vec<&TrackedDevice>
Get devices sorted by hierarchy level (highest first)
Sourcepub fn device_count(&self) -> usize
pub fn device_count(&self) -> usize
Get count of tracked devices
Sourcepub fn remove_stale(&mut self) -> usize
pub fn remove_stale(&mut self) -> usize
Remove stale devices
Returns the number of devices removed.
Sourcepub fn find_best_parent(
&self,
our_level: HierarchyLevel,
) -> Option<&TrackedDevice>
pub fn find_best_parent( &self, our_level: HierarchyLevel, ) -> Option<&TrackedDevice>
Find the best parent candidate
Selects based on hierarchy level (prefer higher) and RSSI (prefer stronger).