Improve initialization sequence

This commit is contained in:
Andreas Böhler
2020-11-19 23:09:51 +01:00
committed by Gitea
parent 9d710308fa
commit 80df573ccf

View File

@@ -260,6 +260,16 @@ public class InitOperationGBX100 extends AbstractBTLEOperation<CasioGBX100Device
} }
} }
private void setInitialized() {
try {
TransactionBuilder builder = createTransactionBuilder("setInitialized");
support.setInitialized(builder);
support.performImmediately(builder);
} catch(IOException e) {
LOG.error("Error setting device to initialized: " + e.getMessage());
}
}
private void enableAllFeatures(TransactionBuilder builder, boolean enable) { private void enableAllFeatures(TransactionBuilder builder, boolean enable) {
builder.notify(getCharacteristic(CasioConstants.CASIO_ALL_FEATURES_CHARACTERISTIC_UUID), enable); builder.notify(getCharacteristic(CasioConstants.CASIO_ALL_FEATURES_CHARACTERISTIC_UUID), enable);
} }
@@ -333,7 +343,10 @@ public class InitOperationGBX100 extends AbstractBTLEOperation<CasioGBX100Device
// The writeAllFeaturesInit request triggers bonding. However, the transaction // The writeAllFeaturesInit request triggers bonding. However, the transaction
// never completes. Instead, the watch sends 0x4701 notification and we abort // never completes. Instead, the watch sends 0x4701 notification and we abort
// the current transaction. // the current transaction.
LOG.debug("We need to bond here. This is actually the request for the current time."); // This is actually the request for the link loss service - it's only received
// on first connection, later reconnects receive 0x47 0x01.
// We also need to send the current time, if not, the watch says "Failed".
LOG.debug("We need to bond here. This is actually the request for the link loss service.");
try { try {
TransactionBuilder builder = createTransactionBuilder("writeCurrentTime"); TransactionBuilder builder = createTransactionBuilder("writeCurrentTime");
support.writeCurrentTime(builder); support.writeCurrentTime(builder);
@@ -346,19 +359,18 @@ public class InitOperationGBX100 extends AbstractBTLEOperation<CasioGBX100Device
// The writeAllFeaturesInit request triggers encryption (again). However, the transaction // The writeAllFeaturesInit request triggers encryption (again). However, the transaction
// never completes. Instead, the watch reports with 0x3d and we abort the current // never completes. Instead, the watch reports with 0x3d and we abort the current
// transaction. // transaction.
// This write is only required for the first connect, for later reconnections,
// it's not required and the watch does not respond with 0x3d. Thus, we set
// it directly to initialized.
if(mFirstConnect) if(mFirstConnect)
writeAllFeaturesInit(); writeAllFeaturesInit();
else
setInitialized();
} }
} else if(data[0] == 0x3d) { } else if(data[0] == 0x3d) {
LOG.info("Init operation done."); LOG.info("Init operation done.");
// Finally, we set the state to initialized here! // Finally, we set the state to initialized here!
try { setInitialized();
TransactionBuilder builder = createTransactionBuilder("setInitialized");
support.setInitialized(builder);
support.performImmediately(builder);
} catch(IOException e) {
LOG.error("Error setting device to initialized: " + e.getMessage());
}
} }
return true; return true;
} else { } else {