I am implementing a application on Android using BLE Api (SDK 18), and I have a issue that the transfer data process is delay very slow. This is my log.
03-1
This seems to be a problem for me as well. If you delay the calls in the debugger you can confirm that there is a delay when writing to BLE radios. I will be implementing a queue in my application to handle the latency.
Here is what I do for queueing up commands:
public void sendWriteCommandToConnectedMachine(byte[] commandByte) {
if(commandByte.length > 20)
dissectAndSendCommandBytes(commandByte);
else
queueCommand(commandByte); //TODO - need to figure out if service is valid or not
}
private void queueCommand(byte[] command) {
mCommandQueue.add(command);
if(!mWaitingCommandResponse)
dequeCommand();
}
Hereis what I do for dequeuing BLE commands
private void dequeCommand() {
if(mCommandQueue.size() > 0) {
byte[] command = mCommandQueue.get(0);
mCommandQueue.remove(0);
sendWriteCommand(command);
}
}
here is my characteristic write method
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
if(status != BluetoothGatt.GATT_SUCCESS)
logMachineResponse(characteristic, status);
mWaitingCommandResponse = false;
dequeCommand();
}