Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Provides access to Bluetooth adapters. More...
Public Member Functions | |
BTManager | getManager () |
Returns the used singleton BTManager instance, used to create this adapter. More... | |
BTDevice | find (String name, BDAddressAndType addressAndType, long timeoutMS) |
Find a BluetoothDevice. More... | |
BTDevice | find (String name, BDAddressAndType addressAndType) |
Find a BluetoothDevice. More... | |
boolean | isDeviceWhitelisted (final BDAddressAndType addressAndType) |
Returns true, if the adapter's device is already whitelisted. More... | |
boolean | addDeviceToWhitelist (final BDAddressAndType addressAndType, final HCIWhitelistConnectType ctype, final short conn_interval_min, final short conn_interval_max, final short conn_latency, final short timeout) |
Add the given device to the adapter's autoconnect whitelist. More... | |
boolean | addDeviceToWhitelist (final BDAddressAndType addressAndType, final HCIWhitelistConnectType ctype) |
Add the given device to the adapter's autoconnect whitelist. More... | |
boolean | removeDeviceFromWhitelist (final BDAddressAndType addressAndType) |
Remove the given device from the adapter's autoconnect whitelist. More... | |
HCIStatusCode | startDiscovery (final boolean keepAlive, final boolean le_scan_active) throws BTException |
Turns on device discovery if it is disabled. More... | |
HCIStatusCode | startDiscovery (final boolean keepAlive, final boolean le_scan_active, final short le_scan_interval, final short le_scan_window, final byte filter_policy) throws BTException |
Shares same implementation as startDiscovery(boolean, boolean), but allows setting custom scan values. More... | |
HCIStatusCode | stopDiscovery () throws BTException |
Turns off device discovery if it is enabled. More... | |
List< BTDevice > | getDiscoveredDevices () |
Returns a list of discovered BluetoothDevices from this adapter. More... | |
int | removeDiscoveredDevices () throws BTException |
Remove all the discovered devices found on this adapter. More... | |
boolean | removeDiscoveredDevice (final BDAddressAndType addressAndType) |
Discards matching discovered devices. More... | |
BDAddressAndType | getAddressAndType () |
Returns the adapter's public BDAddressAndType. More... | |
BDAddressAndType | getVisibleAddressAndType () |
Returns the adapter's currently visible BDAddressAndType. More... | |
String | getName () |
Returns the system name of this adapter. More... | |
int | getDevID () |
Returns the BluetoothAdapter's internal temporary device id. More... | |
String | getAlias () |
Returns the friendly name of this adapter. More... | |
void | setAlias (String value) |
Sets the friendly name of this adapter. More... | |
boolean | isPowered () |
Returns whether the adapter is valid, plugged in and powered. More... | |
boolean | isSuspended () |
Returns whether the adapter is suspended, i.e. More... | |
boolean | isValid () |
Returns whether the adapter is valid, i.e. More... | |
boolean | getPoweredState () |
Returns the power state the adapter. More... | |
boolean | setPowered (boolean value) |
Sets the power state the adapter. More... | |
HCIStatusCode | reset () |
Reset the adapter. More... | |
boolean | getDiscoverable () |
Returns the discoverable state the adapter. More... | |
boolean | setDiscoverable (boolean value) |
Sets the discoverable state the adapter. More... | |
BTDevice | connectDevice (BDAddressAndType addressAndType) |
This method connects to device without need of performing General Discovery. More... | |
boolean | setPairable (boolean value) |
Sets the discoverable state the adapter. More... | |
ScanType | getCurrentScanType () |
Returns the current meta discovering ScanType. More... | |
boolean | addStatusListener (final AdapterStatusListener listener) |
Add the given AdapterStatusListener to the list if not already present. More... | |
boolean | removeStatusListener (final AdapterStatusListener l) |
Remove the given AdapterStatusListener from the list. More... | |
int | removeAllStatusListener () |
Remove all AdapterStatusListener from the list. More... | |
void | printDeviceLists () |
Print the internally maintained BTDevice lists to stderr: More... | |
Public Member Functions inherited from org.direct_bt.BTObject | |
BTType | getBluetoothType () |
Returns the BluetoothType of this object. More... | |
boolean | equals (Object obj) |
int | hashCode () |
void | close () |
Release the native memory associated with this object The object should not be used following a call to close. More... | |
Provides access to Bluetooth adapters.
Definition at line 40 of file BTAdapter.java.
boolean org.direct_bt.BTAdapter.addDeviceToWhitelist | ( | final BDAddressAndType | addressAndType, |
final HCIWhitelistConnectType | ctype | ||
) |
Add the given device to the adapter's autoconnect whitelist.
This variant of addDeviceToWhitelist(String, BDAddressType, HCIWhitelistConnectType, short, short, short, short) uses default connection parameter, which will be uploaded to the kernel for the given device first.
Method will reject duplicate devices, in which case it should be removed first.
address | |
address_type | |
ctype |
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.addDeviceToWhitelist | ( | final BDAddressAndType | addressAndType, |
final HCIWhitelistConnectType | ctype, | ||
final short | conn_interval_min, | ||
final short | conn_interval_max, | ||
final short | conn_latency, | ||
final short | timeout | ||
) |
Add the given device to the adapter's autoconnect whitelist.
The given LE connection parameter will be uploaded to the kernel for the given device first, if the device is of type BDAddressType#BDADDR_LE_PUBLIC or BDAddressType#BDADDR_LE_RANDOM.
Method will reject duplicate devices, in which case it should be removed first.
address | |
address_type | |
ctype | |
conn_interval_min | default value 0x000F |
conn_interval_max | default value 0x000F |
conn_latency | default value 0x0000 |
timeout | in units of 10ms, default value 1000 for 10000ms or 10s. |
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.addStatusListener | ( | final AdapterStatusListener | listener | ) |
Add the given AdapterStatusListener to the list if not already present.
In case the AdapterStatusListener's lifecycle and event delivery shall be constrained to this device, please use BTDevice#addStatusListener(AdapterStatusListener).
The newly added AdapterStatusListener will receive an initial adapterSettingsChanged event, passing an empty oldMask and changedMask, as well as current newMask.
This allows the receiver to be aware of this adapter's current settings.
listener | A AdapterStatusListener instance |
Implemented in jau.direct_bt.DBTAdapter.
BTDevice org.direct_bt.BTAdapter.connectDevice | ( | BDAddressAndType | addressAndType | ) |
This method connects to device without need of performing General Discovery.
Connection mechanism is similar to Connect method from Device1 interface with exception that this method returns success when physical connection is established. After this method returns, services discovery will continue and any supported profile will be connected. There is no need for calling Connect on Device1 after this call. If connection was successful this method returns object path to created device object.
address | The Bluetooth device address of the remote device. This parameter is mandatory. |
addressType | The Bluetooth device Address Type. This is address type that should be used for initial connection. If this parameter is not present BR/EDR device is created. Possible values:
|
Implemented in jau.direct_bt.DBTAdapter.
BTDevice org.direct_bt.BTAdapter.find | ( | String | name, |
BDAddressAndType | addressAndType | ||
) |
Find a BluetoothDevice.
If parameters name and address are not null, the returned object will have to match them. It will first check for existing objects. It will not turn on discovery or connect to devices. @parameter name optionally specify the name of the object you are waiting for @parameter address optionally specify the MAC address of the device you are waiting for
Implemented in jau.direct_bt.DBTAdapter.
BTDevice org.direct_bt.BTAdapter.find | ( | String | name, |
BDAddressAndType | addressAndType, | ||
long | timeoutMS | ||
) |
Find a BluetoothDevice.
If parameters name and address are not null, the returned object will have to match them. It will first check for existing objects. It will not turn on discovery or connect to devices. @parameter name optionally specify the name of the object you are waiting for @parameter address optionally specify the MAC address of the device you are waiting for @parameter timeoutMS the function will return after timeout time in milliseconds, a value of zero means wait forever. If object is not found during this time null will be returned.
Implemented in jau.direct_bt.DBTAdapter.
BDAddressAndType org.direct_bt.BTAdapter.getAddressAndType | ( | ) |
Returns the adapter's public BDAddressAndType.
The adapter's address as initially reported by the system is always its public address, i.e. BDAddressType#BDADDR_LE_PUBLIC.
Implemented in jau.direct_bt.DBTAdapter.
String org.direct_bt.BTAdapter.getAlias | ( | ) |
Returns the friendly name of this adapter.
Implemented in jau.direct_bt.DBTAdapter.
ScanType org.direct_bt.BTAdapter.getCurrentScanType | ( | ) |
Returns the current meta discovering ScanType.
It can be modified through startDiscovery(boolean, boolean) and stopDiscovery().
Note that if startDiscovery(boolean, boolean) has been issued with keepAlive==true, the meta ScanType will still keep the desired ScanType enabled even if it has been temporarily disabled.
Implemented in jau.direct_bt.DBTAdapter.
int org.direct_bt.BTAdapter.getDevID | ( | ) |
Returns the BluetoothAdapter's internal temporary device id.
The internal device id is constant across the adapter lifecycle, but may change after its destruction.
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.getDiscoverable | ( | ) |
Returns the discoverable state the adapter.
Implemented in jau.direct_bt.DBTAdapter.
List<BTDevice> org.direct_bt.BTAdapter.getDiscoveredDevices | ( | ) |
Returns a list of discovered BluetoothDevices from this adapter.
Implemented in jau.direct_bt.DBTAdapter.
BTManager org.direct_bt.BTAdapter.getManager | ( | ) |
Returns the used singleton BTManager instance, used to create this adapter.
Implemented in jau.direct_bt.DBTAdapter.
String org.direct_bt.BTAdapter.getName | ( | ) |
Returns the system name of this adapter.
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.getPoweredState | ( | ) |
Returns the power state the adapter.
Consider using isPowered()
Implemented in jau.direct_bt.DBTAdapter.
BDAddressAndType org.direct_bt.BTAdapter.getVisibleAddressAndType | ( | ) |
Returns the adapter's currently visible BDAddressAndType.
The adapter's address as initially reported by the system is always its public address, i.e. BDAddressType#BDADDR_LE_PUBLIC.
The adapter's visible BDAddressAndType might be set to BDAddressType#BDADDR_LE_RANDOM before scanning / discovery mode (TODO).
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.isDeviceWhitelisted | ( | final BDAddressAndType | addressAndType | ) |
Returns true, if the adapter's device is already whitelisted.
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.isPowered | ( | ) |
Returns whether the adapter is valid, plugged in and powered.
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.isSuspended | ( | ) |
Returns whether the adapter is suspended, i.e.
valid and plugged in, but not powered.
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.isValid | ( | ) |
Returns whether the adapter is valid, i.e.
reference is valid, plugged in and generally operational, but not necessarily isPowered().
Implemented in jau.direct_bt.DBTAdapter.
void org.direct_bt.BTAdapter.printDeviceLists | ( | ) |
Print the internally maintained BTDevice lists to stderr:
This is intended as a debug facility.
Implemented in jau.direct_bt.DBTAdapter.
int org.direct_bt.BTAdapter.removeAllStatusListener | ( | ) |
Remove all AdapterStatusListener from the list.
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.removeDeviceFromWhitelist | ( | final BDAddressAndType | addressAndType | ) |
Remove the given device from the adapter's autoconnect whitelist.
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.removeDiscoveredDevice | ( | final BDAddressAndType | addressAndType | ) |
Discards matching discovered devices.
Implemented in jau.direct_bt.DBTAdapter.
int org.direct_bt.BTAdapter.removeDiscoveredDevices | ( | ) | throws BTException |
Remove all the discovered devices found on this adapter.
BTException |
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.removeStatusListener | ( | final AdapterStatusListener | l | ) |
Remove the given AdapterStatusListener from the list.
listener | A AdapterStatusListener instance |
Implemented in jau.direct_bt.DBTAdapter.
HCIStatusCode org.direct_bt.BTAdapter.reset | ( | ) |
Reset the adapter.
The semantics are specific to the HCI host implementation, however, it shall comply at least with the HCI Reset command and bring up the device from standby into a POWERED functional state afterwards.
BT Core Spec v5.2: Vol 4, Part E HCI: 7.3.2 Reset command
Implemented in jau.direct_bt.DBTAdapter.
void org.direct_bt.BTAdapter.setAlias | ( | String | value | ) |
Sets the friendly name of this adapter.
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.setDiscoverable | ( | boolean | value | ) |
Sets the discoverable state the adapter.
@apiNote return value boolean since 2.0.0
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.setPairable | ( | boolean | value | ) |
Sets the discoverable state the adapter.
@apiNote return value boolean since 2.0.0
Implemented in jau.direct_bt.DBTAdapter.
boolean org.direct_bt.BTAdapter.setPowered | ( | boolean | value | ) |
Sets the power state the adapter.
@apiNote return value boolean since 2.0.0
Implemented in jau.direct_bt.DBTAdapter.
HCIStatusCode org.direct_bt.BTAdapter.startDiscovery | ( | final boolean | keepAlive, |
final boolean | le_scan_active | ||
) | throws BTException |
Turns on device discovery if it is disabled.
's implementation will always issue removeDiscoveredDevices(), ensuring all scanned devices will be found after calling this method. Regardless whether discovery is already running.
+ --+-------+--------+-----------+----------------------------------------------------+ | # | meta | native | keepAlive | Note +---+-------+--------+-----------+----------------------------------------------------+ | 1 | true | true | false | - | 2 | false | false | false | - +---+-------+--------+-----------+----------------------------------------------------+ | 3 | true | true | true | - | 4 | true | false | true | temporarily disabled -> startDiscoveryBackground() | 5 | false | false | true | [4] -> [5] requires manual DISCOVERING event +---+-------+--------+-----------+----------------------------------------------------+
keepAlive | if true
keepAlive=true
|
le_scan_active | true enables delivery of active scanning PDUs, otherwise no scanning PDUs shall be sent (default) |
BTException |
Implemented in jau.direct_bt.DBTAdapter.
HCIStatusCode org.direct_bt.BTAdapter.startDiscovery | ( | final boolean | keepAlive, |
final boolean | le_scan_active, | ||
final short | le_scan_interval, | ||
final short | le_scan_window, | ||
final byte | filter_policy | ||
) | throws BTException |
Shares same implementation as startDiscovery(boolean, boolean), but allows setting custom scan values.
keepAlive | |
le_scan_active | true enables delivery of active scanning PDUs, otherwise no scanning PDUs shall be sent (default) |
le_scan_interval | in units of 0.625ms, default value 24 for 15ms; Value range [4 .. 0x4000] for [2.5ms .. 10.24s] |
le_scan_window | in units of 0.625ms, default value 24 for 15ms; Value range [4 .. 0x4000] for [2.5ms .. 10.24s]. Shall be <= le_scan_interval |
filter_policy | 0x00 accepts all PDUs (default), 0x01 only of whitelisted, ... |
BTException |
Implemented in jau.direct_bt.DBTAdapter.
HCIStatusCode org.direct_bt.BTAdapter.stopDiscovery | ( | ) | throws BTException |
Turns off device discovery if it is enabled.
Implemented in jau.direct_bt.DBTAdapter.