Skip to main content

peat_btle/discovery/
mod.rs

1// Copyright (c) 2025-2026 (r)evolve - Revolve Team LLC
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Peat Discovery Module
17//!
18//! This module implements BLE discovery for Peat mesh networks, including:
19//! - Beacon format encoding/decoding
20//! - Advertising for broadcasting presence
21//! - Scanning for discovering peers
22//!
23//! ## Discovery Flow
24//!
25//! 1. **Advertising**: Nodes broadcast their presence using Peat beacons
26//!    containing node ID, hierarchy level, capabilities, and battery status.
27//!
28//! 2. **Scanning**: Nodes scan for Peat beacons, filtering by hierarchy level
29//!    and signal strength to find potential parents.
30//!
31//! 3. **Parent Selection**: The scanner tracks discovered devices and selects
32//!    the best parent candidate based on hierarchy level and RSSI.
33//!
34//! ## Example
35//!
36//! ```ignore
37//! use peat_btle::discovery::{Advertiser, Scanner, ScanFilter};
38//! use peat_btle::{NodeId, HierarchyLevel};
39//! use peat_btle::config::DiscoveryConfig;
40//!
41//! // Create advertiser
42//! let config = DiscoveryConfig::default();
43//! let mut advertiser = Advertiser::new(config.clone(), NodeId::new(0x12345678))
44//!     .with_name("PEAT-Node".to_string());
45//!
46//! advertiser.set_hierarchy_level(HierarchyLevel::Squad);
47//! advertiser.start();
48//!
49//! // Create scanner
50//! let mut scanner = Scanner::new(config);
51//! scanner.set_filter(ScanFilter::potential_parents(HierarchyLevel::Platform));
52//! scanner.start();
53//! ```
54
55mod advertiser;
56mod beacon;
57mod encrypted_beacon;
58mod scanner;
59
60pub use advertiser::{Advertiser, AdvertiserState, AdvertisingMode, AdvertisingPacket};
61pub use beacon::{
62    ParsedAdvertisement, PeatBeacon, BEACON_COMPACT_SIZE, BEACON_SIZE, BEACON_VERSION,
63};
64pub use encrypted_beacon::{
65    mesh_id_to_bytes, BeaconKey, EncryptedBeacon, ENCRYPTED_BEACON_SIZE, ENCRYPTED_BEACON_VERSION,
66    ENCRYPTED_DEVICE_NAME,
67};
68#[cfg(feature = "std")]
69pub use scanner::Scanner;
70pub use scanner::{ScanFilter, ScannerState, TrackedDevice};