pub struct WindowsBLEGattServer { /* private fields */ }Expand description
SRS-006: Windows BLE GATT Server.
A BLE peripheral that exposes a GATT service with multiple characteristics supporting Read and Notify operations.
§Lifecycle
- Create with
new() - Add characteristics with
add_characteristic() - Optionally select adapter with
use_adapter() - Start with
start() - Send data with
notify(name, data) - Stop with
stop()(or drop)
Implementations§
Source§impl WindowsBLEGattServer
impl WindowsBLEGattServer
Sourcepub fn new(device_name: String, service_uuid: Uuid) -> Self
pub fn new(device_name: String, service_uuid: Uuid) -> Self
SRS-007: Create a new BLE GATT server instance.
After creation, add characteristics with add_characteristic() before calling start().
§Arguments
device_name- Name for the BLE device (may not appear in scans on Windows)service_uuid- UUID for the GATT service
Sourcepub fn add_characteristic(
&mut self,
name: impl Into<String>,
uuid: Uuid,
description: impl Into<String>,
) -> &mut Self
pub fn add_characteristic( &mut self, name: impl Into<String>, uuid: Uuid, description: impl Into<String>, ) -> &mut Self
Register a characteristic on this service.
Must be called before start(). Each characteristic is identified by a unique name
that is used later to send notifications.
§Arguments
name- Unique name used to reference this characteristic (e.g. “heart_rate”)uuid- UUID for the GATT characteristicdescription- Human-readable description (creates a 0x2901 descriptor)
Sourcepub fn use_adapter(&mut self, adapter: &AdapterInfo) -> &mut Self
pub fn use_adapter(&mut self, adapter: &AdapterInfo) -> &mut Self
SRS-009: Select a specific Bluetooth adapter.
Call before start() to use a non-default adapter.
Sourcepub fn use_default_adapter(&mut self) -> &mut Self
pub fn use_default_adapter(&mut self) -> &mut Self
SRS-010: Use the system default adapter.
Sourcepub fn device_name(&self) -> &str
pub fn device_name(&self) -> &str
Get the device name.
Sourcepub fn service_uuid(&self) -> Uuid
pub fn service_uuid(&self) -> Uuid
Get the service UUID.
Sourcepub fn characteristic_uuid(&self, name: &str) -> Option<Uuid>
pub fn characteristic_uuid(&self, name: &str) -> Option<Uuid>
Get the UUID of a characteristic by name.
Sourcepub fn characteristic_names(&self) -> Vec<&str>
pub fn characteristic_names(&self) -> Vec<&str>
List all configured characteristic names in registration order.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if the server is currently running.
Sourcepub async fn start(&mut self) -> Result<()>
pub async fn start(&mut self) -> Result<()>
SRS-011: Start the BLE GATT server.
Creates the GATT service, registers all characteristics, and begins advertising.
Sourcepub async fn notify(&self, name: &str, data: &[u8]) -> Result<()>
pub async fn notify(&self, name: &str, data: &[u8]) -> Result<()>
Send raw bytes as a notification on a named characteristic.
This is the base method - all other notify methods use this internally.
Sourcepub async fn notify_str(&self, name: &str, s: &str) -> Result<()>
pub async fn notify_str(&self, name: &str, s: &str) -> Result<()>
Send a string as a notification.
Sourcepub async fn notify_fmt(&self, name: &str, args: Arguments<'_>) -> Result<()>
pub async fn notify_fmt(&self, name: &str, args: Arguments<'_>) -> Result<()>
Send a formatted string as a notification.
Sourcepub async fn notify_u8(&self, name: &str, value: u8) -> Result<()>
pub async fn notify_u8(&self, name: &str, value: u8) -> Result<()>
Send a u8 as a notification (1 byte).
Sourcepub async fn notify_i8(&self, name: &str, value: i8) -> Result<()>
pub async fn notify_i8(&self, name: &str, value: i8) -> Result<()>
Send an i8 as a notification (1 byte).
Sourcepub async fn notify_u16(&self, name: &str, value: u16) -> Result<()>
pub async fn notify_u16(&self, name: &str, value: u16) -> Result<()>
Send a u16 as a notification (2 bytes, little-endian).
Sourcepub async fn notify_i16(&self, name: &str, value: i16) -> Result<()>
pub async fn notify_i16(&self, name: &str, value: i16) -> Result<()>
Send an i16 as a notification (2 bytes, little-endian).
Sourcepub async fn notify_u32(&self, name: &str, value: u32) -> Result<()>
pub async fn notify_u32(&self, name: &str, value: u32) -> Result<()>
Send a u32 as a notification (4 bytes, little-endian).
Sourcepub async fn notify_i32(&self, name: &str, value: i32) -> Result<()>
pub async fn notify_i32(&self, name: &str, value: i32) -> Result<()>
Send an i32 as a notification (4 bytes, little-endian).
Sourcepub async fn notify_u64(&self, name: &str, value: u64) -> Result<()>
pub async fn notify_u64(&self, name: &str, value: u64) -> Result<()>
Send a u64 as a notification (8 bytes, little-endian).
Sourcepub async fn notify_i64(&self, name: &str, value: i64) -> Result<()>
pub async fn notify_i64(&self, name: &str, value: i64) -> Result<()>
Send an i64 as a notification (8 bytes, little-endian).
Sourcepub async fn notify_f32(&self, name: &str, value: f32) -> Result<()>
pub async fn notify_f32(&self, name: &str, value: f32) -> Result<()>
Send an f32 as a notification (4 bytes, IEEE 754).
Sourcepub async fn notify_f64(&self, name: &str, value: f64) -> Result<()>
pub async fn notify_f64(&self, name: &str, value: f64) -> Result<()>
Send an f64 as a notification (8 bytes, IEEE 754).