use of com.welie.blessed.BluetoothCommandStatus in project openremote by openremote.
the class SendSingleDataSegmentCommand method sendData.
// Public Instance Methods ----------------------------------------------------------------
public boolean sendData() {
boolean isSuccess = false;
if (isWaitForCallback) {
return false;
}
isWaitForCallback = true;
LOG.info("Sending '" + data.length + "' bytes to mesh proxy: [data=" + dataAsHexString(data) + "]");
Runnable runnable = () -> this.dataInCharacteristic.getService().getPeripheral().writeCharacteristic(this.dataInCharacteristic, data, BluetoothGattCharacteristic.WriteType.WITHOUT_RESPONSE);
commandSerializer.enqueue(runnable);
try {
// TODO: timeout constant
BluetoothCommandStatus status = resultQueue.poll(5000, TimeUnit.MILLISECONDS);
if (status != null) {
isSuccess = (status == BluetoothCommandStatus.COMMAND_SUCCESS);
if (isSuccess) {
LOG.info("Successfully sent '" + data.length + "' bytes to mesh proxy: [data=" + dataAsHexString(data) + "]");
} else {
LOG.warning("Failed to send '" + data.length + "' bytes to mesh proxy: [data=" + dataAsHexString(data) + ", status=" + status + "]");
}
} else {
// Callback timeout
LOG.severe("Failed to send '" + data.length + "' bytes to mesh proxy [data=" + dataAsHexString(data) + "] because of confirmation timeout");
isSuccess = false;
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
if (callback != null) {
final boolean callbackResult = isSuccess;
executorService.execute(() -> callback.onDataSent(meshProxy, data, callbackResult));
}
return isSuccess;
}
Aggregations