Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
Public Member Functions | List of all members
org.direct_bt.BTAdapter Interface Reference

Provides access to Bluetooth adapters. More...

Inheritance diagram for org.direct_bt.BTAdapter:
Collaboration diagram for org.direct_bt.BTAdapter:

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< BTDevicegetDiscoveredDevices ()
 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...
 

Detailed Description

Provides access to Bluetooth adapters.

See also
Bluetooth Specification
BlueZ adapter API

Definition at line 40 of file BTAdapter.java.

Member Function Documentation

◆ addDeviceToWhitelist() [1/2]

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.

Parameters
address
address_type
ctype
Returns
true
if successful, otherwise
false
.
See also
#addDeviceToWhitelist(String, BDAddressType, HCIWhitelistConnectType, short, short, short, short)
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ addDeviceToWhitelist() [2/2]

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.

Parameters
address
address_type
ctype
conn_interval_mindefault value 0x000F
conn_interval_maxdefault value 0x000F
conn_latencydefault value 0x0000
timeoutin units of 10ms, default value 1000 for 10000ms or 10s.
Returns
true
if successful, otherwise
false
.
See also
#addDeviceToWhitelist(String, BDAddressType, HCIWhitelistConnectType)
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ addStatusListener()

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.

Parameters
listenerA AdapterStatusListener instance
Returns
true if the given listener is not element of the list and has been newly added, otherwise false.
Since
2.3.0
See also
BTDevice#addStatusListener(AdapterStatusListener)
removeStatusListener(AdapterStatusListener)
removeAllStatusListener()

Implemented in jau.direct_bt.DBTAdapter.

◆ connectDevice()

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.

Parameters
addressThe Bluetooth device address of the remote device. This parameter is mandatory.
addressTypeThe 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:
  • public
    - Public address
  • random
    - Random address

Implemented in jau.direct_bt.DBTAdapter.

◆ find() [1/2]

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

Returns
An object matching the name and address.

Implemented in jau.direct_bt.DBTAdapter.

◆ find() [2/2]

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.

Returns
An object matching the name and address or null if not found before timeout expires.

Implemented in jau.direct_bt.DBTAdapter.

◆ getAddressAndType()

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.

Since
2.2.8
See also
getVisibleAddressAndType()

Implemented in jau.direct_bt.DBTAdapter.

Here is the caller graph for this function:

◆ getAlias()

String org.direct_bt.BTAdapter.getAlias ( )

Returns the friendly name of this adapter.

Returns
The friendly name of this adapter, or NULL if not set.

Implemented in jau.direct_bt.DBTAdapter.

◆ getCurrentScanType()

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.

See also
#startDiscovery(boolean)
stopDiscovery()
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

Here is the caller graph for this function:

◆ getDevID()

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.

Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

Here is the caller graph for this function:

◆ getDiscoverable()

boolean org.direct_bt.BTAdapter.getDiscoverable ( )

Returns the discoverable state the adapter.

Returns
The discoverable state of the adapter.

Implemented in jau.direct_bt.DBTAdapter.

◆ getDiscoveredDevices()

List<BTDevice> org.direct_bt.BTAdapter.getDiscoveredDevices ( )

Returns a list of discovered BluetoothDevices from this adapter.

Returns
A list of discovered BluetoothDevices on this adapter, NULL if an error occurred

Implemented in jau.direct_bt.DBTAdapter.

Here is the caller graph for this function:

◆ getManager()

BTManager org.direct_bt.BTAdapter.getManager ( )

Returns the used singleton BTManager instance, used to create this adapter.

Implemented in jau.direct_bt.DBTAdapter.

◆ getName()

String org.direct_bt.BTAdapter.getName ( )

Returns the system name of this adapter.

Returns
The system name of this adapter.

Implemented in jau.direct_bt.DBTAdapter.

Here is the caller graph for this function:

◆ getPoweredState()

boolean org.direct_bt.BTAdapter.getPoweredState ( )

Returns the power state the adapter.

Consider using isPowered()

Returns
The power state of the adapter.
Since
2.0.0 Renamed from getPowered() to getPoweredState()
See also
isPowered()
isSuspended()
isValid()

Implemented in jau.direct_bt.DBTAdapter.

◆ getVisibleAddressAndType()

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).

Since
2.2.8
See also
getAddressAndType()

Implemented in jau.direct_bt.DBTAdapter.

◆ isDeviceWhitelisted()

boolean org.direct_bt.BTAdapter.isDeviceWhitelisted ( final BDAddressAndType  addressAndType)

Returns true, if the adapter's device is already whitelisted.

Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ isPowered()

boolean org.direct_bt.BTAdapter.isPowered ( )

Returns whether the adapter is valid, plugged in and powered.

Returns
true if isValid(), HCI channel open and POWERED state is set.
See also
isSuspended()
isValid()
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

Here is the caller graph for this function:

◆ isSuspended()

boolean org.direct_bt.BTAdapter.isSuspended ( )

Returns whether the adapter is suspended, i.e.

valid and plugged in, but not powered.

Returns
true if isValid(), HCI channel open and POWERED state is not set.
See also
isPowered()
isValid()

Implemented in jau.direct_bt.DBTAdapter.

◆ isValid()

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().

Returns
true if this adapter references are valid and hadn't been close()'ed
See also
isPowered()
isSuspended()
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ printDeviceLists()

void org.direct_bt.BTAdapter.printDeviceLists ( )

Print the internally maintained BTDevice lists to stderr:

  • sharedDevices
  • connectedDevice
  • discoveredDevices
  • StatusListener

This is intended as a debug facility.

Since
2.3.0

Implemented in jau.direct_bt.DBTAdapter.

◆ removeAllStatusListener()

int org.direct_bt.BTAdapter.removeAllStatusListener ( )

Remove all AdapterStatusListener from the list.

Returns
number of removed listener.
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ removeDeviceFromWhitelist()

boolean org.direct_bt.BTAdapter.removeDeviceFromWhitelist ( final BDAddressAndType  addressAndType)

Remove the given device from the adapter's autoconnect whitelist.

Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ removeDiscoveredDevice()

boolean org.direct_bt.BTAdapter.removeDiscoveredDevice ( final BDAddressAndType  addressAndType)

Discards matching discovered devices.

Returns
true
if found and removed, otherwise false.
Since
2.2.0

Implemented in jau.direct_bt.DBTAdapter.

◆ removeDiscoveredDevices()

int org.direct_bt.BTAdapter.removeDiscoveredDevices ( ) throws BTException

Remove all the discovered devices found on this adapter.

Returns
The number of removed discovered devices on this adapter
Exceptions
BTException
Since
2.2.0 @implNote Changed from 'removeDiscoveredDevices()' for clarity since version 2.2.0

Implemented in jau.direct_bt.DBTAdapter.

◆ removeStatusListener()

boolean org.direct_bt.BTAdapter.removeStatusListener ( final AdapterStatusListener  l)

Remove the given AdapterStatusListener from the list.

Parameters
listenerA AdapterStatusListener instance
Returns
true if the given listener is an element of the list and has been removed, otherwise false.
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ reset()

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
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ setAlias()

void org.direct_bt.BTAdapter.setAlias ( String  value)

Sets the friendly name of this adapter.

Implemented in jau.direct_bt.DBTAdapter.

◆ setDiscoverable()

boolean org.direct_bt.BTAdapter.setDiscoverable ( boolean  value)

Sets the discoverable state the adapter.

@apiNote return value boolean since 2.0.0

Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ setPairable()

boolean org.direct_bt.BTAdapter.setPairable ( boolean  value)

Sets the discoverable state the adapter.

@apiNote return value boolean since 2.0.0

Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ setPowered()

boolean org.direct_bt.BTAdapter.setPowered ( boolean  value)

Sets the power state the adapter.

@apiNote return value boolean since 2.0.0

Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

◆ startDiscovery() [1/2]

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
+---+-------+--------+-----------+----------------------------------------------------+
Parameters
keepAliveif
true
, indicates that discovery shall be restarted if stopped by the underlying Bluetooth implementation (BlueZ, ..). Using startDiscovery(
keepAlive=true
) and stopDiscovery() is the recommended workflow for a reliable discovery process.
le_scan_activetrue enables delivery of active scanning PDUs, otherwise no scanning PDUs shall be sent (default)
Returns
HCIStatusCode#SUCCESS if successful, otherwise the HCIStatusCode error state
Exceptions
BTException
Since
2.0.0
2.2.8
See also
#startDiscovery(boolean, boolean, int, int, byte)
#getDiscovering()

Implemented in jau.direct_bt.DBTAdapter.

Here is the caller graph for this function:

◆ startDiscovery() [2/2]

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.

Parameters
keepAlive
le_scan_activetrue enables delivery of active scanning PDUs, otherwise no scanning PDUs shall be sent (default)
le_scan_intervalin units of 0.625ms, default value 24 for 15ms; Value range [4 .. 0x4000] for [2.5ms .. 10.24s]
le_scan_windowin units of 0.625ms, default value 24 for 15ms; Value range [4 .. 0x4000] for [2.5ms .. 10.24s]. Shall be <= le_scan_interval
filter_policy0x00 accepts all PDUs (default), 0x01 only of whitelisted, ...
Returns
HCIStatusCode#SUCCESS if successful, otherwise the HCIStatusCode error state
Exceptions
BTException
Since
2.2.8
See also
startDiscovery(boolean, boolean)
#getDiscovering()

Implemented in jau.direct_bt.DBTAdapter.

◆ stopDiscovery()

HCIStatusCode org.direct_bt.BTAdapter.stopDiscovery ( ) throws BTException

Turns off device discovery if it is enabled.

Returns
HCIStatusCode#SUCCESS if successful, otherwise the HCIStatusCode error state @apiNote return HCIStatusCode since 2.0.0
Since
2.0.0

Implemented in jau.direct_bt.DBTAdapter.

Here is the caller graph for this function:

The documentation for this interface was generated from the following file:
jau
jau.direct_bt
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2020 Gothel Software e.K.
Definition: DBTAdapter.java:26