Trait idasen::Device[][src]

pub trait Device: Clone + Send + Sync + Debug {
    pub fn address(&self) -> BDAddr;
pub fn properties(&self) -> PeripheralProperties;
pub fn characteristics(&self) -> BTreeSet<Characteristic>;
pub fn is_connected(&self) -> bool;
pub fn connect(&self) -> Result<(), Error>;
pub fn disconnect(&self) -> Result<(), Error>;
pub fn discover_characteristics(
        &self
    ) -> Result<Vec<Characteristic, Global>, Error>;
pub fn discover_characteristics_in_range(
        &self,
        start: u16,
        end: u16
    ) -> Result<Vec<Characteristic, Global>, Error>;
pub fn command(
        &self,
        characteristic: &Characteristic,
        data: &[u8]
    ) -> Result<(), Error>;
pub fn request(
        &self,
        characteristic: &Characteristic,
        data: &[u8]
    ) -> Result<(), Error>;
pub fn read(
        &self,
        characteristic: &Characteristic
    ) -> Result<Vec<u8, Global>, Error>;
pub fn read_by_type(
        &self,
        characteristic: &Characteristic,
        uuid: UUID
    ) -> Result<Vec<u8, Global>, Error>;
pub fn subscribe(
        &self,
        characteristic: &Characteristic
    ) -> Result<(), Error>;
pub fn unsubscribe(
        &self,
        characteristic: &Characteristic
    ) -> Result<(), Error>;
pub fn on_notification(
        &self,
        handler: Box<dyn FnMut(ValueNotification) + 'static + Send, Global>
    ); }

Peripheral is the device that you would like to communicate with (the "server" of BLE). This struct contains both the current state of the device (its properties, characteristics, etc.) as well as functions for communication.

Required methods

pub fn address(&self) -> BDAddr[src]

Returns the address of the peripheral.

pub fn properties(&self) -> PeripheralProperties[src]

Returns the set of properties associated with the peripheral. These may be updated over time as additional advertising reports are received.

pub fn characteristics(&self) -> BTreeSet<Characteristic>[src]

The set of characteristics we've discovered for this device. This will be empty until discover_characteristics or discover_characteristics_in_range is called.

pub fn is_connected(&self) -> bool[src]

Returns true iff we are currently connected to the device.

pub fn connect(&self) -> Result<(), Error>[src]

Creates a connection to the device. This is a synchronous operation; if this method returns Ok there has been successful connection. Note that peripherals allow only one connection at a time. Operations that attempt to communicate with a device will fail until it is connected.

pub fn disconnect(&self) -> Result<(), Error>[src]

Terminates a connection to the device. This is a synchronous operation.

pub fn discover_characteristics(
    &self
) -> Result<Vec<Characteristic, Global>, Error>
[src]

Discovers all characteristics for the device. This is a synchronous operation.

pub fn discover_characteristics_in_range(
    &self,
    start: u16,
    end: u16
) -> Result<Vec<Characteristic, Global>, Error>
[src]

Discovers characteristics within the specified range of handles. This is a synchronous operation.

pub fn command(
    &self,
    characteristic: &Characteristic,
    data: &[u8]
) -> Result<(), Error>
[src]

Sends a command (write without response) to the characteristic. Synchronously returns a Result with an error set if the command was not accepted by the device.

pub fn request(
    &self,
    characteristic: &Characteristic,
    data: &[u8]
) -> Result<(), Error>
[src]

Sends a request (write) to the characteristic. Synchronously returns a Result with an error set if the request was not accepted by the device.

pub fn read(
    &self,
    characteristic: &Characteristic
) -> Result<Vec<u8, Global>, Error>
[src]

Sends a request (read) to the device. Synchronously returns either an error if the request was not accepted or the response from the device.

pub fn read_by_type(
    &self,
    characteristic: &Characteristic,
    uuid: UUID
) -> Result<Vec<u8, Global>, Error>
[src]

Sends a read-by-type request to device for the range of handles covered by the characteristic and for the specified declaration UUID. See here for valid UUIDs. Synchronously returns either an error or the device response.

pub fn subscribe(&self, characteristic: &Characteristic) -> Result<(), Error>[src]

Enables either notify or indicate (depending on support) for the specified characteristic. This is a synchronous call.

pub fn unsubscribe(&self, characteristic: &Characteristic) -> Result<(), Error>[src]

Disables either notify or indicate (depending on support) for the specified characteristic. This is a synchronous call.

pub fn on_notification(
    &self,
    handler: Box<dyn FnMut(ValueNotification) + 'static + Send, Global>
)
[src]

Registers a handler that will be called when value notification messages are received from the device. This method should only be used after a connection has been established. Note that the handler will be called in a common thread, so it should not block.

Loading content...

Implementors

Loading content...