Skip to main content

peat_btle/gatt/
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 GATT Service Module
17//!
18//! Provides the GATT service implementation for Peat Protocol BLE communication.
19//!
20//! ## Service Structure
21//!
22//! ```text
23//! Peat GATT Service (UUID: f47ac10b-58cc-4372-a567-0e02b2c3d479)
24//! ├── Node Info (read)           - Basic node information
25//! ├── Sync State (read/notify)   - Current sync status
26//! ├── Sync Data (write/indicate) - Sync data transfer
27//! ├── Command (write)            - Control commands
28//! └── Status (read/notify)       - Node status updates
29//! ```
30//!
31//! ## Usage
32//!
33//! ```ignore
34//! use peat_btle::gatt::{PeatGattService, PeatCharacteristics};
35//! use peat_btle::{NodeId, HierarchyLevel};
36//!
37//! // Create the GATT service
38//! let service = PeatGattService::new(
39//!     NodeId::new(0x12345678),
40//!     HierarchyLevel::Platform,
41//!     0, // capabilities
42//! );
43//!
44//! // Get characteristic descriptors for registration
45//! let chars = service.characteristics();
46//!
47//! // Handle reads
48//! let node_info = service.read_node_info().await;
49//!
50//! // Handle writes
51//! service.write_command(&command_data).await?;
52//! ```
53//!
54//! ## Sync Protocol
55//!
56//! The sync protocol uses fragmentation for large messages:
57//!
58//! ```ignore
59//! use peat_btle::gatt::SyncProtocol;
60//!
61//! let mut protocol = SyncProtocol::new();
62//! protocol.set_mtu(251); // Use negotiated MTU
63//!
64//! // Start sync with local sync vector
65//! protocol.start_sync(sync_vector);
66//!
67//! // Send outgoing messages
68//! while let Some(msg) = protocol.next_outgoing() {
69//!     // Write msg.encode() to Sync Data characteristic
70//! }
71//!
72//! // Process incoming messages
73//! if let Some((msg_type, payload)) = protocol.process_incoming(&data) {
74//!     // Handle received message
75//! }
76//! ```
77
78mod characteristics;
79mod protocol;
80#[cfg(feature = "std")]
81mod service;
82
83pub use characteristics::{
84    CharacteristicProperties, Command, CommandType, NodeInfo, PeatCharacteristicUuids, StatusData,
85    StatusFlags, SyncDataHeader, SyncDataOp, SyncState, SyncStateData,
86};
87pub use protocol::{
88    fragment_payload, max_payload_size, FragmentReassembler, SyncMessage, SyncMessageType,
89    SyncProtocol, SyncProtocolState, DEFAULT_MAX_PAYLOAD,
90};
91#[cfg(feature = "std")]
92pub use service::{
93    CharacteristicDescriptor, GattEvent, GattEventCallback, PeatCharacteristics, PeatGattService,
94};