trouble-host

Crates

git

Versions

default

Flavors

GattClient

Struct GattClient 

Source
pub struct GattClient<'reference, T: Controller, P: PacketPool, const MAX_SERVICES: usize> { /* private fields */ }
Expand description

A GATT client capable of using the GATT protocol.

Implementations§

Source§

impl<'reference, C: Controller, P: PacketPool, const MAX_SERVICES: usize> GattClient<'reference, C, P, MAX_SERVICES>

Source

pub async fn new( _stack: &Stack<'_, C, P>, connection: &Connection<'reference, P>, ) -> Result<GattClient<'reference, C, P, MAX_SERVICES>, BleHostError<C::Error>>

Creates a GATT client capable of processing the GATT protocol using the provided table of attributes.

Source

pub async fn services( &self, ) -> Result<Vec<ServiceHandle, MAX_SERVICES>, BleHostError<C::Error>>

Discover primary services associated with a UUID.

Source

pub async fn services_by_uuid( &self, uuid: &Uuid, ) -> Result<Vec<ServiceHandle, MAX_SERVICES>, BleHostError<C::Error>>

Discover primary services associated with a UUID.

Source

pub async fn characteristics<const N: usize>( &self, service: &ServiceHandle, ) -> Result<Vec<Characteristic<[u8]>, N>, BleHostError<C::Error>>

Discover all characteristics in a given service

Source

pub async fn characteristic_by_uuid<T: AsGatt + ?Sized>( &self, service: &ServiceHandle, uuid: &Uuid, ) -> Result<Characteristic<T>, BleHostError<C::Error>>

Discover characteristics in a given service using a UUID.

Source

pub async fn find_information<R>( &self, start: u16, end: u16, callback: impl FnMut(u16, Uuid) -> ControlFlow<R>, ) -> Result<Option<R>, BleHostError<C::Error>>

Discover descriptors in a handle range, calling callback for each discovered handle/UUID pair.

Returns Ok(Some(val)) if callback returns ControlFlow::Break(val), or Ok(None) if the entire range was iterated without breaking.

Source

pub async fn descriptors<T: AsGatt + ?Sized, const N: usize>( &self, characteristic: &Characteristic<T>, ) -> Result<Vec<Descriptor<[u8]>, N>, BleHostError<C::Error>>

Discover all descriptors for a characteristic.

Returns a list of descriptors found in the handle range belonging to the characteristic.

Source

pub async fn descriptor_by_uuid<T: AsGatt + ?Sized, DT: AsGatt + ?Sized>( &self, characteristic: &Characteristic<T>, uuid: &Uuid, ) -> Result<Descriptor<DT>, BleHostError<C::Error>>

Find a specific descriptor by UUID for a characteristic.

Returns the first descriptor matching the given UUID.

Source

pub async fn read_by_type<R>( &self, start: u16, end: u16, attribute_type: &Uuid, callback: impl FnMut(u16, &[u8]) -> ControlFlow<R>, ) -> Result<Option<R>, BleHostError<C::Error>>

Read attributes by type in a handle range, calling callback for each discovered handle/data pair.

Paginates automatically using successive ATT ReadByType requests. Returns Ok(Some(val)) if callback returns ControlFlow::Break(val), or Ok(None) if the entire range was iterated without breaking (i.e. ATTRIBUTE_NOT_FOUND was received).

Source

pub async fn read_characteristic<T: AsGatt + ?Sized>( &self, characteristic: &Characteristic<T>, dest: &mut [u8], ) -> Result<usize, BleHostError<C::Error>>

Read a characteristic described by a handle.

The number of bytes copied into the provided buffer is returned.

Source

pub async fn read_characteristic_by_uuid( &self, service: &ServiceHandle, uuid: &Uuid, dest: &mut [u8], ) -> Result<usize, BleHostError<C::Error>>

Read a characteristic described by a UUID.

The number of bytes copied into the provided buffer is returned.

Source

pub async fn write_characteristic<T: AsGatt + ?Sized>( &self, handle: &Characteristic<T>, buf: &[u8], ) -> Result<(), BleHostError<C::Error>>

Write to a characteristic described by a handle.

Source

pub async fn write_characteristic_without_response<T: AsGatt + ?Sized>( &self, handle: &Characteristic<T>, buf: &[u8], ) -> Result<(), BleHostError<C::Error>>

Write without waiting for a response to a characteristic described by a handle.

Source

pub async fn read_handle( &self, handle: u16, dest: &mut [u8], ) -> Result<usize, BleHostError<C::Error>>

Read an attribute by raw handle.

The number of bytes copied into the provided buffer is returned.

Source

pub async fn read_handle_blob( &self, handle: u16, offset: u16, dest: &mut [u8], ) -> Result<usize, BleHostError<C::Error>>

Read an attribute value by raw handle using Read Blob requests.

The offset parameter specifies the starting offset within the attribute value.

Source

pub async fn write_handle( &self, handle: u16, buf: &[u8], ) -> Result<(), BleHostError<C::Error>>

Write an attribute by raw handle.

Source

pub async fn write_handle_without_response( &self, handle: u16, buf: &[u8], ) -> Result<(), BleHostError<C::Error>>

Write an attribute by raw handle without waiting for a response.

Source

pub async fn read_descriptor<T: AsGatt + ?Sized>( &self, descriptor: &Descriptor<T>, dest: &mut [u8], ) -> Result<usize, BleHostError<C::Error>>

Read a descriptor value.

The number of bytes copied into the provided buffer is returned.

Source

pub async fn write_descriptor<T: AsGatt + ?Sized>( &self, descriptor: &Descriptor<T>, buf: &[u8], ) -> Result<(), BleHostError<C::Error>>

Write a descriptor value.

Source

pub async fn subscribe<T: AsGatt + ?Sized>( &self, characteristic: &Characteristic<T>, indication: bool, ) -> Result<NotificationListener<'_, 512>, BleHostError<C::Error>>

Subscribe to indication/notification of a given Characteristic

A listener is returned, which has a next() method

Source

pub fn listen<T: AsGatt + ?Sized>( &self, characteristic: &Characteristic<T>, ) -> Result<NotificationListener<'_, 512>, BleHostError<C::Error>>

Listen for notifications/indications on a given Characteristic without writing the CCCD.

Use this for reconnection scenarios where the server remembers the subscription (per BLE spec 10.3.2.2, CCCD values persist across disconnections for bonded devices).

Source

pub fn listen_all( &self, ) -> Result<NotificationListener<'_, 512>, BleHostError<C::Error>>

Listen for notifications/indications on all characteristics without writing the CCCD.

Returns a catch-all listener that receives notifications for ALL handles. Use Notification::handle() to determine which characteristic the notification is for.

Source

pub async fn unsubscribe<T: AsGatt + ?Sized>( &self, characteristic: &Characteristic<T>, ) -> Result<(), BleHostError<C::Error>>

Unsubscribe from a given Characteristic

Source

pub async fn confirm_indication(&self) -> Result<(), BleHostError<C::Error>>

Confirm an indication that was received.

Source

pub async fn task(&self) -> Result<(), BleHostError<C::Error>>

Task which handles GATT rx data (needed for notifications to work)

Auto Trait Implementations§

§

impl<'reference, T, P, const MAX_SERVICES: usize> !Freeze for GattClient<'reference, T, P, MAX_SERVICES>

§

impl<'reference, T, P, const MAX_SERVICES: usize> !RefUnwindSafe for GattClient<'reference, T, P, MAX_SERVICES>

§

impl<'reference, T, P, const MAX_SERVICES: usize> !Send for GattClient<'reference, T, P, MAX_SERVICES>

§

impl<'reference, T, P, const MAX_SERVICES: usize> !Sync for GattClient<'reference, T, P, MAX_SERVICES>

§

impl<'reference, T, P, const MAX_SERVICES: usize> Unpin for GattClient<'reference, T, P, MAX_SERVICES>
where T: Unpin, <P as PacketPool>::Packet: Unpin,

§

impl<'reference, T, P, const MAX_SERVICES: usize> !UnwindSafe for GattClient<'reference, T, P, MAX_SERVICES>

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.