Interface BLEHandlerAPI


public interface BLEHandlerAPI

Field Summary

Modifier and Type Field and Description
static int MODE_LOCAL_COMMAND 
static int MODE_REMOTE_COMMAND 
static int MODE_STREAM 

Method Summary

Modifier and Type Method and Description
void abortBinaryWrite()
Abort a binary write in progress.
boolean connect(java.lang.String deviceName, boolean autoReconnect)
Connect to device with given name.
void deinit()
De-initialise BLE manager.
boolean disconnect(java.lang.String deviceName, boolean disableTxNotification)
Disconnect from device.
java.lang.String getAddress(java.lang.String deviceName)
Get Bluetooth HW address for connected device
BLECallbacks.ReceiveMode getReceiveMode()
Get receive mode, determines how received data is passed back.
boolean init(android.content.Context context, BLECallbacks callbacks)
Initialise BLE manager.
boolean isBLEEnabled()
Check state of BLE hardware.
boolean isConnected(java.lang.String deviceName)
Check connection state.
boolean isScanning()
Check scan state.
boolean readBinaryData(java.lang.String deviceName)
Read a data packet from a connected device and interpret as bytes.
boolean readCharacteristic(java.lang.String deviceName, java.util.UUID serviceId, java.util.UUID charID) 
boolean readFirmwareRev(java.lang.String deviceName)
Read firmware version of connected device.
boolean readMode(java.lang.String deviceName)
Read mode of connected device.
boolean readStringData(java.lang.String deviceName)
Read a data packet from a connected device and interpret as a String.
boolean setNotification(java.lang.String deviceName, java.util.UUID serviceId, java.util.UUID charID, boolean notifyEnabled) 
void setOTACallbacks(OTACallbacks callbacks)
Set OTA callbacks to use (only required if using OTA functionality).
boolean setOTAControlNotify(java.lang.String deviceName, boolean enable)
Set the notification setting for the device OTA Control characteristic.
boolean setReceiveMode(BLECallbacks.ReceiveMode mode)
Set receive mode, determines how received data is passed back.
boolean setTxNotify(java.lang.String deviceName, boolean enable)
Set the notification setting for the device TX characteristic (received data).
boolean startBLEScan()
Starts undirected BLE scan.
boolean stopBLEScan()
Stop BLE scan.
boolean writeCharacteristic(java.lang.String deviceName, java.util.UUID serviceId, java.util.UUID charID, java.nio.ByteBuffer data) 
boolean writeData(java.lang.String deviceName, java.nio.ByteBuffer data)
Write Binary data to connected device.
boolean writeData(java.lang.String deviceName, java.lang.String data)
Write String data to connected device.
boolean writeMode(java.lang.String deviceName, int mode)
Write new mode to connected device.
boolean writeOTAControl(java.lang.String deviceName, java.nio.ByteBuffer data)
Write binary data to the OTA Control characteristic.
boolean writeOTAData(java.lang.String deviceName, java.nio.ByteBuffer data)
Write binary data to the OTA Data characteristic.

Field Detail

Method Detail

  • init

    boolean init(android.content.Context context,
               BLECallbacks callbacks)
    Initialise BLE manager.
    Parameters:
    context - activity context (requires BLE admin permissions)
    callbacks - BLE callbacks to use.
    Returns:
    true on success
  • deinit

    void deinit()
    De-initialise BLE manager.
  • setOTACallbacks

    void setOTACallbacks(OTACallbacks callbacks)
    Set OTA callbacks to use (only required if using OTA functionality).
    Parameters:
    callbacks - OTA callbacks to use.
  • isConnected

    boolean isConnected(java.lang.String deviceName)
    Check connection state.
    Parameters:
    deviceName - name of device to check connection for
    Returns:
    true if connected
  • isBLEEnabled

    boolean isBLEEnabled()
    Check state of BLE hardware.
    Returns:
    true if BLE hardware enabled
  • isScanning

    boolean isScanning()
    Check scan state.
    Returns:
    true if scanning for device
  • startBLEScan

    boolean startBLEScan()
    Starts undirected BLE scan.
    Returns:
    true if scan started successfully
  • stopBLEScan

    boolean stopBLEScan()
    Stop BLE scan.
    Returns:
    true if scan stopped successfully
  • connect

    boolean connect(java.lang.String deviceName,
                  boolean autoReconnect)
    Connect to device with given name.
    Parameters:
    deviceName - name of device
    autoReconnect - true if BLE stack should try to reconnect automatically
    Returns:
    true if connection request successfully submitted
  • disconnect

    boolean disconnect(java.lang.String deviceName,
                     boolean disableTxNotification)
    Disconnect from device.
    Parameters:
    deviceName - name of device
    disableTxNotification - true if TX notify should be disabled before disconnect (important for some devices eg Samsung Galaxy S3)
    Returns:
    true if disconnect request successfully submitted
  • readStringData

    boolean readStringData(java.lang.String deviceName)
    Read a data packet from a connected device and interpret as a String.
    Parameters:
    deviceName - name of device
    Returns:
    true if read request submitted
  • readBinaryData

    boolean readBinaryData(java.lang.String deviceName)
    Read a data packet from a connected device and interpret as bytes.
    Parameters:
    deviceName - name of device
    Returns:
    true if read request submitted
  • getReceiveMode

    BLECallbacks.ReceiveMode getReceiveMode()
    Get receive mode, determines how received data is passed back. String data returns data with onStringDataRead(). Binary data returns data with onBinaryDataRead().
    Returns:
    current receive mode
  • setReceiveMode

    boolean setReceiveMode(BLECallbacks.ReceiveMode mode)
    Set receive mode, determines how received data is passed back. String data returns data with onStringDataRead(). Binary data returns data with onBinaryDataRead().
    Parameters:
    mode - new receive mode
    Returns:
    true on success
  • writeData

    boolean writeData(java.lang.String deviceName,
                    java.lang.String data)
    Write String data to connected device.
    Parameters:
    deviceName - name of device
    data - data to write
    Returns:
    true if request submitted
  • writeData

    boolean writeData(java.lang.String deviceName,
                    java.nio.ByteBuffer data)
    Write Binary data to connected device.
    Parameters:
    deviceName - name of device
    data - data to write
    Returns:
    true if request submitted
  • abortBinaryWrite

    void abortBinaryWrite()
    Abort a binary write in progress.
  • readMode

    boolean readMode(java.lang.String deviceName)
    Read mode of connected device.
    Parameters:
    deviceName - name of device
    Returns:
    true if request submitted
  • writeMode

    boolean writeMode(java.lang.String deviceName,
                    int mode)
    Write new mode to connected device.
    Parameters:
    deviceName - name of device
    mode - ZentriOS BLE mode
    Returns:
    true if request submitted
  • setTxNotify

    boolean setTxNotify(java.lang.String deviceName,
                      boolean enable)
    Set the notification setting for the device TX characteristic (received data).
    Parameters:
    deviceName - name of device
    enable - value of notification setting
    Returns:
    true if request submitted
  • setOTAControlNotify

    boolean setOTAControlNotify(java.lang.String deviceName,
                              boolean enable)
    Set the notification setting for the device OTA Control characteristic.
    Parameters:
    deviceName - name of device
    enable - value of notification setting
    Returns:
    true if request submitted
  • writeOTAControl

    boolean writeOTAControl(java.lang.String deviceName,
                          java.nio.ByteBuffer data)
    Write binary data to the OTA Control characteristic.
    Parameters:
    deviceName - name of device
    data - data to write
    Returns:
    true if request submitted
  • writeOTAData

    boolean writeOTAData(java.lang.String deviceName,
                       java.nio.ByteBuffer data)
    Write binary data to the OTA Data characteristic.
    Parameters:
    deviceName - name of device
    data - data to write
    Returns:
    true if request submitted
  • readFirmwareRev

    boolean readFirmwareRev(java.lang.String deviceName)
    Read firmware version of connected device.
    Parameters:
    deviceName - name of device
    Returns:
    true if request submitted
  • writeCharacteristic

    boolean writeCharacteristic(java.lang.String deviceName,
                              java.util.UUID serviceId,
                              java.util.UUID charID,
                              java.nio.ByteBuffer data)
  • readCharacteristic

    boolean readCharacteristic(java.lang.String deviceName,
                             java.util.UUID serviceId,
                             java.util.UUID charID)
  • setNotification

    boolean setNotification(java.lang.String deviceName,
                          java.util.UUID serviceId,
                          java.util.UUID charID,
                          boolean notifyEnabled)
  • getAddress

    java.lang.String getAddress(java.lang.String deviceName)
    Get Bluetooth HW address for connected device
    Parameters:
    deviceName - name of device
    Returns:
    HW address of device