[][src]Trait btleplug::api::Peripheral

pub trait Peripheral: Send + Sync + Clone + Debug {
    fn address(&self) -> BDAddr;
fn properties(&self) -> PeripheralProperties;
fn characteristics(&self) -> BTreeSet<Characteristic>;
fn is_connected(&self) -> bool;
fn connect(&self) -> Result<()>;
fn disconnect(&self) -> Result<()>;
fn discover_characteristics(&self) -> Result<Vec<Characteristic>>;
fn discover_characteristics_in_range(
        &self,
        start: u16,
        end: u16
    ) -> Result<Vec<Characteristic>>;
fn command_async(
        &self,
        characteristic: &Characteristic,
        data: &[u8],
        handler: Option<CommandCallback>
    );
fn command(
        &self,
        characteristic: &Characteristic,
        data: &[u8]
    ) -> Result<()>;
fn request_async(
        &self,
        characteristic: &Characteristic,
        data: &[u8],
        handler: Option<RequestCallback>
    );
fn request(
        &self,
        characteristic: &Characteristic,
        data: &[u8]
    ) -> Result<Vec<u8>>;
fn read_async(
        &self,
        characteristic: &Characteristic,
        handler: Option<RequestCallback>
    );
fn read(&self, characteristic: &Characteristic) -> Result<Vec<u8>>;
fn read_by_type_async(
        &self,
        characteristic: &Characteristic,
        uuid: UUID,
        handler: Option<RequestCallback>
    );
fn read_by_type(
        &self,
        characteristic: &Characteristic,
        uuid: UUID
    ) -> Result<Vec<u8>>;
fn subscribe(&self, characteristic: &Characteristic) -> Result<()>;
fn unsubscribe(&self, characteristic: &Characteristic) -> Result<()>;
fn on_notification(&self, handler: NotificationHandler); }

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

fn address(&self) -> BDAddr

Returns the address of the peripheral.

fn properties(&self) -> PeripheralProperties

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

fn characteristics(&self) -> BTreeSet<Characteristic>

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

fn is_connected(&self) -> bool

Returns true iff we are currently connected to the device.

fn connect(&self) -> Result<()>

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.

fn disconnect(&self) -> Result<()>

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

fn discover_characteristics(&self) -> Result<Vec<Characteristic>>

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

fn discover_characteristics_in_range(
    &self,
    start: u16,
    end: u16
) -> Result<Vec<Characteristic>>

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

fn command_async(
    &self,
    characteristic: &Characteristic,
    data: &[u8],
    handler: Option<CommandCallback>
)

Sends a command (write-without-response) to the characteristic. Takes an optional callback that will be notified in case of error or when the command has been successfully acked by the device.

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

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.

fn request_async(
    &self,
    characteristic: &Characteristic,
    data: &[u8],
    handler: Option<RequestCallback>
)

Sends a request (write) to the device. Takes an optional callback with either an error if the request was not accepted or the response from the device.

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

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

fn read_async(
    &self,
    characteristic: &Characteristic,
    handler: Option<RequestCallback>
)

Sends a request (read) to the device. Takes an optional callback with either an error if the request was not accepted or the response from the device.

fn read(&self, characteristic: &Characteristic) -> Result<Vec<u8>>

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

fn read_by_type_async(
    &self,
    characteristic: &Characteristic,
    uuid: UUID,
    handler: Option<RequestCallback>
)

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. Takes an optional callback that will be called with an error or the device response.

fn read_by_type(
    &self,
    characteristic: &Characteristic,
    uuid: UUID
) -> Result<Vec<u8>>

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.

fn subscribe(&self, characteristic: &Characteristic) -> Result<()>

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

fn unsubscribe(&self, characteristic: &Characteristic) -> Result<()>

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

fn on_notification(&self, handler: NotificationHandler)

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

impl Peripheral for Peripheral[src]

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

Returns the address of the peripheral.

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.

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.

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

Returns true iff we are currently connected to the device.

fn connect(&self) -> Result<()>[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.

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

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

fn discover_characteristics(&self) -> Result<Vec<Characteristic>>[src]

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

fn discover_characteristics_in_range(
    &self,
    _start: u16,
    _end: u16
) -> Result<Vec<Characteristic>>
[src]

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

fn command_async(
    &self,
    _characteristic: &Characteristic,
    _data: &[u8],
    _handler: Option<CommandCallback>
)
[src]

Sends a command (write-without-response) to the characteristic. Takes an optional callback that will be notified in case of error or when the command has been successfully acked by the device.

fn command(&self, characteristic: &Characteristic, data: &[u8]) -> Result<()>[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.

fn request_async(
    &self,
    _characteristic: &Characteristic,
    _data: &[u8],
    _handler: Option<RequestCallback>
)
[src]

Sends a request (write) to the device. Takes an optional callback with either an error if the request was not accepted or the response from the device.

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

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

fn read_by_type_async(
    &self,
    _characteristic: &Characteristic,
    _uuid: UUID,
    _handler: Option<RequestCallback>
)
[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. Takes an optional callback that will be called with an error or the device response.

fn read_by_type(
    &self,
    _characteristic: &Characteristic,
    _uuid: UUID
) -> Result<Vec<u8>>
[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.

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

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

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

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

fn on_notification(&self, handler: NotificationHandler)[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...