Peripheral

public class Peripheral extends Object

Wrapper aroundBluetoothGattthat executes BLE commands using a queue.

Constructors

Peripheral

public Peripheral(BluetoothGatt bluetoothGatt, BleQueue bleQueue)

Create a new Peripheral for the providedBluetoothGatt. Since we can only do one asynchronous operation at a time we have a command queue to control execution.

Parameters

Name Description
BluetoothGatt bluetoothGatt

the underlying gatt to communicate with.

BleQueue bleQueue

a queue for executing commands.

Methods

readCharacteristic

public boolean readCharacteristic(BluetoothGattCharacteristic characteristic)

Reads from the characteristic. Results are emitted fromBleAdapter.

Parameters

Name Description
BluetoothGattCharacteristic characteristic

the characteristic to read from.

ReturnValue

Name Description
boolean

true, if the read operation was initiated successfully

writeCharacteristic

public boolean writeCharacteristic(BluetoothGattCharacteristic characteristic, WriteType writeType, byte[] payload)

Writes the payload to theBluetoothGattCharacteristicwith theWriteType. Results are emitted fromBleAdapter.

Parameters

Name Description
BluetoothGattCharacteristic characteristic

the characteristic to write to.

WriteType writeType

the write type. One of WriteType.

byte[] payload

the byte data to write.

ReturnValue

Name Description
boolean

true, if the write operation was initiated successfully

enableNotification

public boolean enableNotification(BluetoothGattCharacteristic characteristic, boolean enable)

Enabled or disabled notifications for the characteristic. Results are emitted fromBleAdapter.

Parameters

Name Description
BluetoothGattCharacteristic characteristic

the characteristic to toggle notification for.

boolean enable

wether to enable or disable notifications.

ReturnValue

Name Description
boolean

true, if the operation was initiated successfully

discoverServices

public boolean discoverServices()

Starts discovering services. Results are emitted fromBleAdapter.

ReturnValue

Name Description
boolean

true, if the operation was initiated successfully

getTagIdentifier

public String getTagIdentifier()

Returns the tags identifier.

ReturnValue

Name Description
String

getDefaultDisplayName

public String getDefaultDisplayName()

Returns the tag name from Bluetooth cache.

ReturnValue

Name Description
String

getJacquardService

public BluetoothGattService getJacquardService()

Returns the BluetoothGattService for accessing jacquard services.

ReturnValue

Name Description
BluetoothGattService

requestRssi

public boolean requestRssi()

ReturnValue

Name Description
boolean

requestConnectionPriority

public void requestConnectionPriority(int priority)

Sets Bluetooth connection priority for ble data transfer.

Parameters

Name Description
int priority

ReturnValue

Name Description
void