use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip-plus by jamorham.
the class BlueJayService method authenticate.
private void authenticate(final QueueMe requeueItem) {
val authReply = AuthReqTx.getNextAuthPacket(null);
new QueueMe().setBytes(authReply.getBytes()).setDescription("Auth hello packet").setProcessor(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] bytes) {
UserError.Log.d(TAG, "Processing likely auth challenge");
val authReply2 = AuthReqTx.getNextAuthPacket(bytes);
if (authReply2 != null) {
new QueueMe().setBytes(authReply2.getBytes()).setDescription("Auth challenge reply").setProcessor(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] bytes) {
if (AuthReqTx.isAccessGranted(bytes)) {
UserError.Log.d(TAG, "Authentication complete!");
if (requeueItem != null) {
// retry the item that we got stopped for authentication
requeueItem.insert();
}
} else {
UserError.Log.e(TAG, "Authentication failed! " + JoH.bytesToHex(bytes));
}
}
}).insert();
}
}
}).expireInSeconds(60).insert();
}
use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip-plus by jamorham.
the class BlueJayService method runQueueItem.
// TJ protocol queue items
private synchronized void runQueueItem(final ThinJamItem item) {
UserError.Log.d(TAG, "Running queue item queued: " + item.queuedTimestamp);
if (item.width > 0) {
final BaseTx packet = new DefineWindowTx((byte) 1, (byte) item.windowType, (byte) item.x, (byte) item.y, (byte) item.width, (byte) item.height, (byte) 0, (byte) item.colourEffect);
queueGenericCommand(packet.getBytes(), "define window: (" + item.windowType + ") " + item.x + "," + item.y + " w:" + item.width + " h:" + item.height, null, getARInstance(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] response) {
if (D)
UserError.Log.d(TAG, "Wrote qui record request request: " + bytesToHex(response));
if (packet.responseOk(response)) {
requestBulk(item);
} else {
UserError.Log.d(TAG, "Define Window failed: " + packet.responseText(response));
}
}
}));
} else {
// is not a window request - is flash write
requestBulk(item);
}
}
use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip-plus by jamorham.
the class BlueJayService method identify.
public void identify() {
addToLog("Pairing / Identifying Watch");
val item = new QueueMe().setBytes(new byte[] { OPCODE_IDENTIFY }).setDescription("Get identity value").setDelayMs(300).expireInSeconds(60);
item.setProcessor(new AuthReplyProcessor(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] bytes) {
if (bytes.length == 18) {
if (bytes[0] == (byte) 0x41 && bytes[1] == (byte) 0x92) {
final String identityHex = JoH.bytesToHex(Arrays.copyOfRange(bytes, 2, 18));
UserError.Log.d(TAG, "Storing identity for " + I.address + " of: " + identityHex);
BlueJay.storeIdentityKey(I.address, identityHex);
}
} else {
addToLog("Got wrong reply from pairing - try again");
UserError.Log.d(TAG, "Wrong size for identity reply: " + bytes.length + " " + JoH.bytesToHex(bytes));
}
}
}).setTag(item)).queue();
doQueue();
}
use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip-plus by jamorham.
the class BlueJayService method queueGenericCommand.
QueueMe queueGenericCommand(final byte[] cmd, final String description, final Runnable runnable, final ReplyProcessor processor) {
val item = new QueueMe().setBytes(cmd);
if (processor != null)
processor.setTag(item);
item.setDescription(description).setProcessor(processor != null ? processor : new AuthReplyProcessor(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] bytes) {
UserError.Log.d(TAG, "Reply for: " + description + " " + JoH.bytesToHex(bytes));
}
}).setTag(item)).expireInSeconds(60);
if (runnable != null) {
item.setRunnable(runnable);
}
item.queue();
doQueue();
return item;
}
Aggregations