Struct Peripheral

Source
pub struct Peripheral { /* private fields */ }
Expand description

A remote peripheral device.

The Peripheral object represents remote peripheral devices that your app discovers with a central manager. Peripherals use universally unique identifiers (UUIDs) to identify themselves. Peripherals may contain one or more services or provide useful information about their connected signal strength.

You use this object to discover, explore, and interact with the services available on a remote peripheral that supports Bluetooth low energy. A service encapsulates the way part of the device behaves. For example, one service of a heart rate monitor may be to expose heart rate data from a sensor. Services themselves contain of characteristics or included services (references to other services). Characteristics provide further details about a peripheral’s service. For example, the heart rate service may contain multiple characteristics. One characteristic could describe the intended body location of the device’s heart rate sensor, and another characteristic could transmit the heart rate measurement data. Finally, characteristics contain any number of descriptors that provide more information about the characteristic’s value, such as a human-readable description and a way to format the value.

Implementations§

Source§

impl Peripheral

Source

pub fn id(&self) -> Uuid

Peripheral identifier.

Source

pub fn discover_services(&self)

Discovers all available services of the peripheral.

See discover_services_with_uuids.

Source

pub fn discover_services_with_uuids(&self, uuids: &[Uuid])

Discovers peripheral’s services with the specified uuids.

When the peripheral discovers one or more services, it triggers ServicesDiscovered event.

Source

pub fn discover_included_services(&self, service: &Service)

Discovers all available included services of a previously-discovered service.

See discover_included_services_with_uuids method.

Source

pub fn discover_included_services_with_uuids( &self, service: &Service, uuids: &[Uuid], )

Discovers the specified included services of a previously-discovered service.

When the peripheral discovers one or more included services, it triggers IncludedServicesDiscovered event.

Source

pub fn discover_characteristics(&self, service: &Service)

Discovers all available characteristics of a service.

See discover_characteristics_with_uuids method.

Source

pub fn discover_characteristics_with_uuids( &self, service: &Service, uuids: &[Uuid], )

Discovers the specified characteristics of a service.

When the peripheral discovers one or more characteristics, it triggers CharacteristicsDiscovered event.

Source

pub fn discover_descriptors(&self, characteristic: &Characteristic)

Discovers the descriptors of a characteristic.

When the peripheral discovers one or more descriptors, it triggers DescriptorsDiscovered event.

Source

pub fn subscribe(&self, characteristic: &Characteristic)

Subscribes to notifications or indications of the value of a specified characteristic.

After calling this method the peripheral triggers SubscriptionChangeResult event to inform whether the action succeeded. If successful, the peripheral then triggers CharacteristicValue event whenever the characteristic value changes.

Because the peripheral chooses when it sends an update, your app should prepare to handle them as long as subscription remains active. If the specified characteristic’s configuration allows both notifications and indications, calling this method enables notifications only. You can disable notifications and indications for a characteristic’s value by calling unsubscribe method.

Source

pub fn unsubscribe(&self, characteristic: &Characteristic)

Cancel subscription for characteristic value created by subscribe method.

Source

pub fn read_characteristic(&self, characteristic: &Characteristic)

Retrieves the value of a specified characteristic.

After calling this method the peripheral triggers CharacteristicValue event.

Not all characteristics have a readable value. You can determine whether a characteristic’s value is readable by accessing the relevant properties of the Properties object.

Source

pub fn write_characteristic( &self, characteristic: &Characteristic, value: &[u8], kind: WriteKind, )

Writes the value of a characteristic.

When you call this method to write the value of a characteristic, the peripheral triggers WriteCharacteristicResult event, but only if the WithResponse write kind is requested.

If you specify the write kind as WithoutResponse, Core Bluetooth attempts to write the value but doesn’t guarantee success. If the write doesn’t succeed in this case, you aren’t notified and you don’t receive an error indicating the cause of the failure.

Examine can_write and can_write_without_response properties to determine which kinds of writes you can perform.

Source

pub fn read_descriptor(&self, descriptor: &Descriptor)

Retrieves the value of a specified characteristic descriptor.

After calling this method the peripheral triggers DescriptorValue event.

Source

pub fn write_descriptor(&self, descriptor: &Descriptor, value: &[u8])

Writes the value of a characteristic descriptor.

When you call this method to write the value of a characteristic, the peripheral triggers WriteDescriptorResult event.

Source

pub fn read_rssi(&self)

Retrieves the current RSSI value for the peripheral while connected to the central manager.

After calling this method the peripheral triggers ReadRssiResult event.

Source

pub fn get_max_write_len(&self)

Queries for maximum length of data that can be written to characteristic in a single request. The result is returned as GetMaxWriteLenResult event.

Source

pub fn get_max_write_len_tagged(&self, tag: Tag)

Allows tagging an asynchronous get_max_write_len call with arbitrary tag.

Trait Implementations§

Source§

impl Clone for Peripheral

Source§

fn clone(&self) -> Peripheral

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Peripheral

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Peripheral

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Peripheral

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Peripheral

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.