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>
impl<'reference, C: Controller, P: PacketPool, const MAX_SERVICES: usize> GattClient<'reference, C, P, MAX_SERVICES>
Sourcepub async fn new(
_stack: &Stack<'_, C, P>,
connection: &Connection<'reference, P>,
) -> Result<GattClient<'reference, C, P, MAX_SERVICES>, BleHostError<C::Error>>
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.
Sourcepub async fn services(
&self,
) -> Result<Vec<ServiceHandle, MAX_SERVICES>, BleHostError<C::Error>>
pub async fn services( &self, ) -> Result<Vec<ServiceHandle, MAX_SERVICES>, BleHostError<C::Error>>
Discover primary services associated with a UUID.
Sourcepub async fn services_by_uuid(
&self,
uuid: &Uuid,
) -> Result<Vec<ServiceHandle, MAX_SERVICES>, BleHostError<C::Error>>
pub async fn services_by_uuid( &self, uuid: &Uuid, ) -> Result<Vec<ServiceHandle, MAX_SERVICES>, BleHostError<C::Error>>
Discover primary services associated with a UUID.
Sourcepub async fn characteristics<const N: usize>(
&self,
service: &ServiceHandle,
) -> Result<Vec<Characteristic<[u8]>, N>, BleHostError<C::Error>>
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
Sourcepub async fn characteristic_by_uuid<T: AsGatt + ?Sized>(
&self,
service: &ServiceHandle,
uuid: &Uuid,
) -> Result<Characteristic<T>, BleHostError<C::Error>>
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.
Sourcepub async fn find_information<R>(
&self,
start: u16,
end: u16,
callback: impl FnMut(u16, Uuid) -> ControlFlow<R>,
) -> Result<Option<R>, BleHostError<C::Error>>
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.
Sourcepub async fn descriptors<T: AsGatt + ?Sized, const N: usize>(
&self,
characteristic: &Characteristic<T>,
) -> Result<Vec<Descriptor<[u8]>, N>, BleHostError<C::Error>>
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.
Sourcepub async fn descriptor_by_uuid<T: AsGatt + ?Sized, DT: AsGatt + ?Sized>(
&self,
characteristic: &Characteristic<T>,
uuid: &Uuid,
) -> Result<Descriptor<DT>, BleHostError<C::Error>>
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.
Sourcepub 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>>
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).
Sourcepub async fn read_characteristic<T: AsGatt + ?Sized>(
&self,
characteristic: &Characteristic<T>,
dest: &mut [u8],
) -> Result<usize, BleHostError<C::Error>>
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.
Sourcepub async fn read_characteristic_by_uuid(
&self,
service: &ServiceHandle,
uuid: &Uuid,
dest: &mut [u8],
) -> Result<usize, BleHostError<C::Error>>
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.
Sourcepub async fn write_characteristic<T: AsGatt + ?Sized>(
&self,
handle: &Characteristic<T>,
buf: &[u8],
) -> Result<(), BleHostError<C::Error>>
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.
Sourcepub async fn write_characteristic_without_response<T: AsGatt + ?Sized>(
&self,
handle: &Characteristic<T>,
buf: &[u8],
) -> Result<(), BleHostError<C::Error>>
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.
Sourcepub async fn read_handle(
&self,
handle: u16,
dest: &mut [u8],
) -> Result<usize, BleHostError<C::Error>>
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.
Sourcepub async fn read_handle_blob(
&self,
handle: u16,
offset: u16,
dest: &mut [u8],
) -> Result<usize, BleHostError<C::Error>>
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.
Sourcepub async fn write_handle(
&self,
handle: u16,
buf: &[u8],
) -> Result<(), BleHostError<C::Error>>
pub async fn write_handle( &self, handle: u16, buf: &[u8], ) -> Result<(), BleHostError<C::Error>>
Write an attribute by raw handle.
Sourcepub async fn write_handle_without_response(
&self,
handle: u16,
buf: &[u8],
) -> Result<(), BleHostError<C::Error>>
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.
Sourcepub async fn read_descriptor<T: AsGatt + ?Sized>(
&self,
descriptor: &Descriptor<T>,
dest: &mut [u8],
) -> Result<usize, BleHostError<C::Error>>
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.
Sourcepub async fn write_descriptor<T: AsGatt + ?Sized>(
&self,
descriptor: &Descriptor<T>,
buf: &[u8],
) -> Result<(), BleHostError<C::Error>>
pub async fn write_descriptor<T: AsGatt + ?Sized>( &self, descriptor: &Descriptor<T>, buf: &[u8], ) -> Result<(), BleHostError<C::Error>>
Write a descriptor value.
Sourcepub async fn subscribe<T: AsGatt + ?Sized>(
&self,
characteristic: &Characteristic<T>,
indication: bool,
) -> Result<NotificationListener<'_, 512>, BleHostError<C::Error>>
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
Sourcepub fn listen<T: AsGatt + ?Sized>(
&self,
characteristic: &Characteristic<T>,
) -> Result<NotificationListener<'_, 512>, BleHostError<C::Error>>
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).
Sourcepub fn listen_all(
&self,
) -> Result<NotificationListener<'_, 512>, BleHostError<C::Error>>
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.
Sourcepub async fn unsubscribe<T: AsGatt + ?Sized>(
&self,
characteristic: &Characteristic<T>,
) -> Result<(), BleHostError<C::Error>>
pub async fn unsubscribe<T: AsGatt + ?Sized>( &self, characteristic: &Characteristic<T>, ) -> Result<(), BleHostError<C::Error>>
Unsubscribe from a given Characteristic
Sourcepub async fn confirm_indication(&self) -> Result<(), BleHostError<C::Error>>
pub async fn confirm_indication(&self) -> Result<(), BleHostError<C::Error>>
Confirm an indication that was received.