use of com.eveningoutpost.dexdrip.insulin.inpen.messages.AdvertRx in project xDrip by NightscoutFoundation.
the class InPenService method bondAuthority.
private void bondAuthority() {
final AdvertRx adv = new AdvertRx().fromBytes(PersistentStore.getBytes(STORE_INPEN_ADVERT + I.address));
if (adv != null) {
final float bondUnits = JoH.roundFloat((float) Pref.getStringToDouble("inpen_prime_units", DEFAULT_BOND_UNITS), 1);
final BondTx btx = new BondTx(bondUnits, adv.getFlagBytes());
I.connection.writeCharacteristic(BONDCONTROL, btx.getBytes()).subscribe(value -> {
UserError.Log.d(TAG, "Sent BondAuthority ok: " + bytesToHex(value));
changeNextState();
}, throwable -> {
if (isErrorResponse(throwable)) {
// user dialed up the wrong number of units!
err("Cannot bond with pen as incorrect number of units dialed up for pairing. Should be " + bondUnits + " or other error");
bondAsRequired(false);
} else {
UserError.Log.e(TAG, "Could not write BondAuthority " + throwable);
}
});
} else {
err("Cannot find valid scan record for: " + I.address);
}
}
use of com.eveningoutpost.dexdrip.insulin.inpen.messages.AdvertRx in project xDrip-plus by jamorham.
the class InPenService method bondAuthority.
private void bondAuthority() {
final AdvertRx adv = new AdvertRx().fromBytes(PersistentStore.getBytes(STORE_INPEN_ADVERT + I.address));
if (adv != null) {
final float bondUnits = JoH.roundFloat((float) Pref.getStringToDouble("inpen_prime_units", DEFAULT_BOND_UNITS), 1);
final BondTx btx = new BondTx(bondUnits, adv.getFlagBytes());
I.connection.writeCharacteristic(BONDCONTROL, btx.getBytes()).subscribe(value -> {
UserError.Log.d(TAG, "Sent BondAuthority ok: " + bytesToHex(value));
changeNextState();
}, throwable -> {
if (isErrorResponse(throwable)) {
// user dialed up the wrong number of units!
err("Cannot bond with pen as incorrect number of units dialed up for pairing. Should be " + bondUnits + " or other error");
bondAsRequired(false);
} else {
UserError.Log.e(TAG, "Could not write BondAuthority " + throwable);
}
});
} else {
err("Cannot find valid scan record for: " + I.address);
}
}