Skip to main content

WindowsBLEGattServer

Struct WindowsBLEGattServer 

Source
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

  1. Create with new()
  2. Add characteristics with add_characteristic()
  3. Optionally select adapter with use_adapter()
  4. Start with start()
  5. Send data with notify(name, data)
  6. Stop with stop() (or drop)

Implementations§

Source§

impl WindowsBLEGattServer

Source

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
Source

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 characteristic
  • description - Human-readable description (creates a 0x2901 descriptor)
Source

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.

Source

pub fn use_default_adapter(&mut self) -> &mut Self

SRS-010: Use the system default adapter.

Source

pub fn device_name(&self) -> &str

Get the device name.

Source

pub fn service_uuid(&self) -> Uuid

Get the service UUID.

Source

pub fn characteristic_uuid(&self, name: &str) -> Option<Uuid>

Get the UUID of a characteristic by name.

Source

pub fn characteristic_names(&self) -> Vec<&str>

List all configured characteristic names in registration order.

Source

pub fn is_running(&self) -> bool

Check if the server is currently running.

Source

pub async fn start(&mut self) -> Result<()>

SRS-011: Start the BLE GATT server.

Creates the GATT service, registers all characteristics, and begins advertising.

Source

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.

Source

pub async fn notify_str(&self, name: &str, s: &str) -> Result<()>

Send a string as a notification.

Source

pub async fn notify_fmt(&self, name: &str, args: Arguments<'_>) -> Result<()>

Send a formatted string as a notification.

Source

pub async fn notify_u8(&self, name: &str, value: u8) -> Result<()>

Send a u8 as a notification (1 byte).

Source

pub async fn notify_i8(&self, name: &str, value: i8) -> Result<()>

Send an i8 as a notification (1 byte).

Source

pub async fn notify_u16(&self, name: &str, value: u16) -> Result<()>

Send a u16 as a notification (2 bytes, little-endian).

Source

pub async fn notify_i16(&self, name: &str, value: i16) -> Result<()>

Send an i16 as a notification (2 bytes, little-endian).

Source

pub async fn notify_u32(&self, name: &str, value: u32) -> Result<()>

Send a u32 as a notification (4 bytes, little-endian).

Source

pub async fn notify_i32(&self, name: &str, value: i32) -> Result<()>

Send an i32 as a notification (4 bytes, little-endian).

Source

pub async fn notify_u64(&self, name: &str, value: u64) -> Result<()>

Send a u64 as a notification (8 bytes, little-endian).

Source

pub async fn notify_i64(&self, name: &str, value: i64) -> Result<()>

Send an i64 as a notification (8 bytes, little-endian).

Source

pub async fn notify_f32(&self, name: &str, value: f32) -> Result<()>

Send an f32 as a notification (4 bytes, IEEE 754).

Source

pub async fn notify_f64(&self, name: &str, value: f64) -> Result<()>

Send an f64 as a notification (8 bytes, IEEE 754).

Source

pub async fn notify_bool(&self, name: &str, value: bool) -> Result<()>

Send a bool as a notification (1 byte: 0x00 or 0x01).

Source

pub fn stop(&mut self) -> Result<()>

SRS-014: Stop the BLE server.

Stops advertising and releases resources.

Trait Implementations§

Source§

impl Drop for WindowsBLEGattServer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.