use of com.eveningoutpost.dexdrip.watch.thinjam.messages.BulkUpRequestTx in project xDrip by NightscoutFoundation.
the class BlueJayService method requestBulk.
private synchronized void requestBulk(final ThinJamItem item) {
if (item.buffer == null) {
UserError.Log.d(TAG, "ThinJamItem buffer is null! " + item.toS());
return;
}
if (item.inProgress) {
UserError.Log.d(TAG, "Blocking duplicate request for in progress item: " + item.queuedTimestamp);
return;
}
item.inProgress = true;
final BulkUpRequestTx packet = new BulkUpRequestTx(item.type, item.getId(), BulkUpRequestTx.encodeLength(item.sequence, item.buffer.length), item.buffer, item.quiet);
if (D)
UserError.Log.d(TAG, "Bulk request request: " + item.sequence + " " + bytesToHex(packet.getBytes()));
// value will get notification result itself
if (I.connection == null) {
item.inProgress = false;
UserError.Log.d(TAG, "Connection is null skipping");
}
I.connection.writeCharacteristic(THINJAM_WRITE, packet.getBytes()).subscribe(response -> {
if (D)
UserError.Log.d(TAG, "Bulk request response: " + bytesToHex(response));
if (packet.responseOk(response)) {
lastBulkOk = tsl();
UserError.Log.d(TAG, "Bulk channel opcode: " + packet.getBulkUpOpcode(response));
bulkSend(packet.getBulkUpOpcode(response), item.buffer, 15, item.quiet);
} else {
UserError.Log.d(TAG, "Bulk request failed: " + packet.responseText(response));
if (packet.responseText(response).toLowerCase().contains("busy") && item.retryCounterOk()) {
UserError.Log.d(TAG, "Device is busy, scheduling retry");
Inevitable.task("bulk-retry-" + item.toS(), 3000, () -> {
UserError.Log.d(TAG, "Retrying requestBulk: " + item.toS());
item.inProgress = false;
requestBulk(item);
});
} else if (packet.responseText(response).toLowerCase().contains("out of range") || packet.responseText(response).toLowerCase().contains("unknown error")) {
UserError.Log.d(TAG, "Setting item to not retry again due to out of range");
item.inProgress = false;
item.dontRetryAgain();
Inevitable.task("tj-next-queue", 0, this::processQueue);
}
}
item.inProgress = false;
}, throwable -> {
UserError.Log.e(TAG, "Failed to write bulk request: " + throwable);
if (throwable instanceof BleGattCharacteristicException) {
final int status = ((BleGattCharacteristicException) throwable).getStatus();
UserError.Log.e(TAG, "Got status message: " + Helper.getStatusName(status));
} else {
UserError.Log.d(TAG, "Throwable in Bulk End write: " + throwable);
}
item.inProgress = false;
});
}
use of com.eveningoutpost.dexdrip.watch.thinjam.messages.BulkUpRequestTx in project xDrip-plus by jamorham.
the class BlueJayService method requestBulk.
private synchronized void requestBulk(final ThinJamItem item) {
if (item.buffer == null) {
UserError.Log.d(TAG, "ThinJamItem buffer is null! " + item.toS());
return;
}
if (item.inProgress) {
UserError.Log.d(TAG, "Blocking duplicate request for in progress item: " + item.queuedTimestamp);
return;
}
item.inProgress = true;
final BulkUpRequestTx packet = new BulkUpRequestTx(item.type, item.getId(), BulkUpRequestTx.encodeLength(item.sequence, item.buffer.length), item.buffer, item.quiet);
if (D)
UserError.Log.d(TAG, "Bulk request request: " + item.sequence + " " + bytesToHex(packet.getBytes()));
// value will get notification result itself
if (I.connection == null) {
item.inProgress = false;
UserError.Log.d(TAG, "Connection is null skipping");
}
I.connection.writeCharacteristic(THINJAM_WRITE, packet.getBytes()).subscribe(response -> {
if (D)
UserError.Log.d(TAG, "Bulk request response: " + bytesToHex(response));
if (packet.responseOk(response)) {
lastBulkOk = tsl();
UserError.Log.d(TAG, "Bulk channel opcode: " + packet.getBulkUpOpcode(response));
bulkSend(packet.getBulkUpOpcode(response), item.buffer, 15, item.quiet);
} else {
UserError.Log.d(TAG, "Bulk request failed: " + packet.responseText(response));
if (packet.responseText(response).toLowerCase().contains("busy") && item.retryCounterOk()) {
UserError.Log.d(TAG, "Device is busy, scheduling retry");
Inevitable.task("bulk-retry-" + item.toS(), 3000, () -> {
UserError.Log.d(TAG, "Retrying requestBulk: " + item.toS());
item.inProgress = false;
requestBulk(item);
});
} else if (packet.responseText(response).toLowerCase().contains("out of range") || packet.responseText(response).toLowerCase().contains("unknown error")) {
UserError.Log.d(TAG, "Setting item to not retry again due to out of range");
item.inProgress = false;
item.dontRetryAgain();
Inevitable.task("tj-next-queue", 0, this::processQueue);
}
}
item.inProgress = false;
}, throwable -> {
UserError.Log.e(TAG, "Failed to write bulk request: " + throwable);
if (throwable instanceof BleGattCharacteristicException) {
final int status = ((BleGattCharacteristicException) throwable).getStatus();
UserError.Log.e(TAG, "Got status message: " + Helper.getStatusName(status));
} else {
UserError.Log.d(TAG, "Throwable in Bulk End write: " + throwable);
}
item.inProgress = false;
});
}
Aggregations