3 Interface Description

3.1 Bluetooth Proxy class

IBluetoothManager is an interface class that users must implement.
It is necessary to use this interface class to obtain important content such as the Bluetooth control interface of the user SDK and Bluetooth transmission data.

Method Name

Parameters

Result

Describe

Mode of action

onBtDeviceConnection

device: Bluetooth Device

void

Transmit Bluetooth connection status

User call
Implementing state transfer

onReceiveDeviceData

device: Bluetooth Device
data: Raw Data

void

Passing received Bluetooth data

User call
Realize data transfer

onMtuChanged

gatt: Bluetooth Gatt
mtu: Negotiated BLE mtu
status: Status

void

Passes the negotiated BLE MTU

User call
Can not be realized

onError

error: Error Event

void

Propagating error events

User call
Can not be realized

getConnectedDevice

BluetoothDevice - Bluetooth Device
Note: When no device is connected, null is returned.

Get the connected Bluetooth device object

Need to be implemented by the user

getConnectedBluetoothGatt

BluetoothGatt - Bluetooth Gatt
Note: When no device is connected, null is returned.

Get the connected GATT control object

Need to be implemented by the user
It can be not implemented, SPP does not implement

connectBluetoothDevice

device: Bluetooth Device

void

Connecting Bluetooth Device

Need to be implemented by the user
Used for SDK to implement reconnection to device

disconnectBluetoothDevice

device: Bluetooth Device

void

Disconnecting Bluetooth Device

Need to be implemented by the user
Used for SDK to implement reconnection to device

sendDataToDevice

device: Bluetooth Device
data: Data Pack

boolean - Operation Results

Sending data to Bluetooth device

Users must implement

queryMandatoryUpdate

IActionCallback<TargetInfoResponse> - Result Callback

void

Query device upgrade status

Direct Call

Important

1. connectBluetoothDevice must ensure a separate connection and will not affect other connections
- BLE mode, only connect to BLE, not to classic Bluetooth
- The passed connection state needs to be converted to a connection state with 3.6   Status Code
2. sendDataToDevice needs to ensure that the data is sent completely
- For BLE mode, you need to divide packets according to MTU and send data in queue. The API will notify the data sent without considering MTU.
You can refer to the implementation of SendBleDataThread in Demo
- SPP mode, no special processing required
3. The following points should be noted when implementing the sendDataToDevice interface via BLE
- It is necessary to perform MTU subpacketization according to the MTU value of BLE
- Cannot send data concurrently, need to send data in queue
- Because the OTA function needs to send a large amount of data, it needs to be sent in a queue to ensure that the data is sent completely and correctly.

3.2 OTA operation interface

IUpgradeManager is mainly used to implement the OTA process functions. It is implemented by the OTA library. Users can implement OTA upgrades by calling the corresponding interface.

Method Name

Parameters

Result

Describe

configure

2.2.1   BluetoothOTAConfigure - OTA Parameters

void

Configure OTA implementation parameters

startOTA

3.3   OTA process callback - OTA status callback

void

Start OTA process

cancelOTA

void

void

Cancel OTA process

release

void

void

Release Resources

isOTA

void

boolean

Whether to perform OTA

getDeviceInfo

void

2.4.1   TargetInfoResponse

Get cached device information,
Can be used as a flag to indicate whether initialization is complete

Important

  1. cancelOTA : If it is a single backup solution, the API is invalid; if it is a double backup solution, the API is valid

3.3 OTA process callback

IUpgradeCallback is the status callback of the OTA process, used to update the UI.

public interface IUpgradeCallback {

   /**
    * Callback OTA start
    */
   void onStartOTA();

   /**
    * Callback device information that needs to be reconnected
    *
    * <p>Notice:<br/>
    * 1.Only connect to BLE communication channel<br/>
    * 2.For single backup OTA</p>
    *
    * @param addr Reconnect device's MAC address
    * @param isNewReconnectWay Whether to use the new connection method
    */
   void onNeedReconnect(String addr, boolean isNewReconnectWay);

   /**
    * Callback Progress
    *
    * @param type     type
    *                 <p>0 -- Download Resources
    *                 or 1 -- Upgrade Firmware</p>
    * @param progress progress
    */
   void onProgress(int type, float progress);

   /**
    * Callback OTA completion
    */
   void onStopOTA();

   /**
    * Callback OTA canceled
    */
   void onCancelOTA();

   /**
    * Callback OTA failure information
    *
    * @param error error message
    */
   void onError(BaseError error);
}

3.3.1 BaseError

Error Message

public class BaseError {
   /**
    * Main error code
    */
    private final int code;
   /**
    * Sub-error code
    */
   private final int subCode;
   /**
    * Operation Code
    */
   private int opCode;
   /**
    * Description
    */
   private final String message;
}

3.4 Bluetooth event callback

IBluetoothCallback

public interface IBluetoothCallback {
   /**
    * Callback Bluetooth adapter switch status
    *
    * @param bEnabled Switch Status
    * @param bHasBle  Whether to support BLE function
    */
   void onAdapterStatus(boolean bEnabled, boolean bHasBle);

   /**
    * Callback to search for Bluetooth device status
    *
    * @param bBle Whether to search BLE
    * @param bStart Search Status
    */
   void onDiscoveryStatus(boolean bBle, boolean bStart);

   /**
    * Callback of discovered Bluetooth devices
    *
    * @param device Bluetooth device
    */
   @Deprecated
   void onDiscovery(BluetoothDevice device);

   /**
    * Callback of discovered Bluetooth devices
    *
    * @param device Bluetooth device
    * @param bleScanMessage BLE broadcast data
    */
   void onDiscovery(BluetoothDevice device, BleScanMessage bleScanMessage);

   /**
    * Callback Bluetooth device pairing status
    *
    * @param device Bluetooth device
    * @param status Bound status
    */
   void onBondStatus(BluetoothDevice device, int status);

   /**
    * Callback of BLE negotiated MTU
    *
    * @param device Bluetooth device
    * @param block Negotiated MTU
    * @param status 0 - Success, others failure
    */
   void onBleDataBlockChanged(BluetoothDevice device, int block, int status);

   /**
    * Callback of classic Bluetooth connection status
    *
    * @param device Bluetooth device
    * @param status Connection Status
    */
   void onBtDeviceConnection(BluetoothDevice device, int status);

   /**
    * Callback for Bluetooth device connection
    *
    * @param device Bluetooth device
    * @param status Connection Status
    */
   void onConnection(BluetoothDevice device, int status);

   /**
    * Callback for data received from the Bluetooth device
    *
    * @param device Bluetooth device
    * @param data   Raw Data
    */
   void onReceiveData(BluetoothDevice device, byte[] data);

   /**
    * Callback the connection status of the A2DP service
    *
    * @param device Bluetooth device
    * @param status Connection Status
    */
   void onA2dpStatus(BluetoothDevice device, int status);

   /**
    * Callback the connection status of the HFP service
    *
    * @param device Bluetooth device
    * @param status Connection Status
    */
   void onHfpStatus(BluetoothDevice device, int status);

   /**
    * Callback error event
    *
    * @param error error event
    */
   void onError(BaseError error);
}

3.5 Error Code

Class Name: ErrorCode

3.5.1 Main Error Code

Code

Name

Describe

-1

ErrorCode#ERR_UNKNOWN

Unknown Error

0

ErrorCode#ERR_NONE

No Error

1

ErrorCode#ERR_COMMON

Common Error

2

ErrorCode#ERR_STATUS

Status Error

3

ErrorCode#ERR_COMMUNICATION

Communication Error

4

ErrorCode#ERR_OTA

OTA Error

5

ErrorCode#ERR_OTHER

Other Error

3.5.2 Detailed Error Code

Format: 0x[Primary Code Value][Serial Number]

Code

Name

Describe

Remark

0x1001(4097)

ErrorCode#SUB_ERR_PARAMETER

Parameter Error

0x1012(4114)

ErrorCode#SUB_ERR_REMOTE_NOT_CONNECTED

The remote device is not connected

2.1 The Bluetooth device is connected, why does calling the OTA library interface return an error, 4114(0x1012), the device is not connected


0x3002(12290)

ErrorCode#SUB_ERR_SEND_FAILED

Failed to send data

2.2 Error code: 12290(0x3002), Failed to send data

0x3003(12291)

ErrorCode#SUB_ERR_PAIR_TIMEOUT

Pairing Timeout

0x3004(12292)

ErrorCode#SUB_ERR_DATA_FORMAT

Abnormal Data Format

0x3005(12293)

ErrorCode#SUB_ERR_PARSE_DATA

Unpacking Exception

0x3007(12295)

ErrorCode#SUB_ERR_SEND_TIMEOUT

Timeout for sending data

2.4 Error code: 12295(0x3007), Timeout in sending data

0x3008(12296)

ErrorCode#SUB_ERR_RESPONSE_BAD_STATUS

Reply failure status

2.6 Error code: 12296 (0x3008), response failed

0x300A(12298)

ErrorCode#SUB_ERR_RESPONSE_BAD_RESULT

The device responds with an error result

0x300B(12299)

ErrorCode#SUB_ERR_WAITING_COMMAND_TIMEOUT

Waiting for command timeout

3.1 Upgrade failed, error code: 12299(0x300B), waiting for command timeout


0x4001(16385)

ErrorCode#SUB_ERR_OTA_FAILED

OTA Update Failed

3.3 Upgrade failed, error code: 16385(0x4001), OTA upgrade failed

0x4002(16386)

ErrorCode#SUB_ERR_DEVICE_LOW_VOLTAGE

Equipment Low Voltage

3.4 Upgrade failed, error code: 16386(0x4002), device low voltage

0x4003(16387)

ErrorCode#SUB_ERR_CHECK_UPGRADE_FILE

Upgrade File Error

3.5 Upgrade failed, error code: 16387(0x4003), upgrade file error

0x4004(16388)

ErrorCode#SUB_ERR_OFFSET_OVER

Failed to read offset

The offset of the device request data is out of bounds

0x4005(16389)

ErrorCode#SUB_ERR_CHECK_RECEIVED_DATA_FAILED

Data Verification Failed

3.6 Upgrade failed, error: 16389(0x4005), data verification failed

0x4006(16390)

ErrorCode#SUB_ERR_UPGRADE_KEY_NOT_MATCH

Encryption key does not match

3.12 Upgrade failed, error code: 16390(0x4006), encryption key does not match

0x4007(16391)

ErrorCode#SUB_ERR_UPGRADE_TYPE_NOT_MATCH

Upgrade Type Error

0x4008(16392)

ErrorCode#SUB_ERR_OTA_IN_HANDLE

Upgrade process in progress

3.2 Upgrade failed, error code: 16392(0x4008), Upgrade process in progress

0x4009(16393)

ErrorCode#SUB_ERR_UPGRADE_DATA_LEN

Length error during upgrade

0x400A(16394)

ErrorCode#SUB_ERR_UPGRADE_FLASH_READ

Flash read and write errors

0x400B(16395)

ErrorCode#SUB_ERR_UPGRADE_CMD_TIMEOUT

Command Timeout

0x400C(16396)

ErrorCode#SUB_ERR_UPGRADE_FILE_VERSION_SAME

Firmware version is consistent

3.7 Upgrade failed, error code: 16396 (0x400C), the firmware version of the upgrade file is the same

0x400D(16397)

ErrorCode#SUB_ERR_TWS_NOT_CONNECT

TWS not connected

3.8 Upgrade failed, error code: 16397(0x400D), TWS not connected

0x400E(16398)

ErrorCode#SUB_ERR_HEADSET_NOT_IN_CHARGING_BIN

The earphones are not in the charging case

0x400F(16399)

ErrorCode#SUB_ERR_UPGRADE_SAME_FILE

Same File

3.9 Upgrade failed, error code: 16399(0x400F), same file

0x4010(16400)

ErrorCode#SUB_ERR_UPGRADE_UNKNOWN

Unknown Upgrade Error

0x4011(16401)

ErrorCode#SUB_ERR_RECONNECT_TIMEOUT

Reconnecting device timed out

3.10 Upgrade failed, error code: 16401(0x4011), timeout on connecting to device

0x4012(16402)

ErrorCode#SUB_ERR_RECONNECT_FAILED

Failed to reconnect the device

0x4013(16403)

ErrorCode#SUB_ERR_OTA_IN_PROGRESS

The device is being upgraded

0x4014(16404)

ErrorCode#SUB_ERR_DEVICE_IN_DOUBLE_CONNECTION

The device is in dual-connection mode

3.11 Upgrade failed, error code: 16404(0x4014), the device is in dual-connection mode

0x4FFE(20478)

ErrorCode#SUB_ERR_NEED_UPDATE_RESOURCE

After the firmware upgrade is completed,
it is necessary to reconnect to update resources.

Used for the special upgrade process with reused storage space.


0x5001(20481)

ErrorCode#SUB_ERR_AUTH_DEVICE

Failed to authenticate device

2.5 Error code: 20481 (0x5001), Device authentication failed

0x5004(20484)

ErrorCode#SUB_ERR_FILE_NOT_FOUND

Upgrade file not found

3.13 Upgrade failed, error code: 20484(0x5004), upgrade file not found

0x5005(20485)

ErrorCode#SUB_ERR_DATA_NOT_FOUND

No upgrade data found

0x5006(20486)

ErrorCode#SUB_ERR_IO_EXCEPTION

IO Exception

0x5007(20487)

ErrorCode#SUB_ERR_SDK_RELEASE

SDK Destroy

3.6 Status Code

Class Name: StateCode

3.6.1 Connection Status

Code

Name

Describe

0

StateCode#CONNECTION_DISCONNECT

Disconnect

1

StateCode#CONNECTION_OK

Connection Successful

2

StateCode#CONNECTION_FAILED

Connection Failed

3

StateCode#CONNECTION_CONNECTING

Connecting

4

StateCode#CONNECTION_CONNECTED

Connected (deprecated)

3.6.2 Reply Status

Code

Name

Describe

0

StateCode#STATUS_SUCCESS

Success Status

1

StateCode#STATUS_FAIL

Failure Status

2

StateCode#STATUS_UNKOWN_CMD

Unknown Command

3

StateCode#STATUS_BUSY

Busy State

4

StateCode#STATUS_NO_RESOURCE

No Resources

5

StateCode#STATUS_CRC_ERROR

CRC check error

6

StateCode#STATUS_ALL_DATA_CRC_ERROR

All data CRC errors

7

StateCode#STATUS_PARAMETER_ERROR

Parameter Error

8

StateCode#STATUS_RESPONSE_DATA_OVER_LIMIT

Reply data exceeds limit

3.7 ICmdSnGenerator

Command number generator
Used for multiplexing of multiple JieLi libraries to unify Seq generation
public interface ICmdSnGenerator {

   /**
    * Get the Rcsp command serial number
    *
    * @param device Bluetooth Device
    * @return Serial Number
    * <p>
    * range: 0-255<br>
    * Each time it is called, it is accumulated once
    * </p>
    */
   int getRcspCmdSeq(BluetoothDevice device);
}