use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip-plus by jamorham.
the class BlueJayService method standby.
public void standby() {
if (BlueJayInfo.getInfo(I.address).buildNumber > 39) {
addToLog("Requesting watch standby");
val description = "Watch Standby";
val item = new QueueMe().setBytes(new StandbyTx().getBytes());
item.setDescription(description).setProcessor(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);
item.queueUnique();
doQueue();
invalidateCache();
} else {
JoH.static_toast_long("Needs BlueJay firmware upgrade to support standby");
}
}
use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip-plus by jamorham.
the class BlueJayService method easyAuth.
public void easyAuth() {
addToLog("Attempting easy authentication");
val item = new QueueMe().setBytes(new byte[] { OPCODE_EASY_AUTH }).setDescription("Get easy auth").expireInSeconds(60);
item.setProcessor(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] bytes) {
if (bytes.length == 18) {
if (bytes[0] == (byte) 0x41 && bytes[1] == (byte) 0x93) {
final String identityHex = JoH.bytesToHex(Arrays.copyOfRange(bytes, 2, 18));
UserError.Log.d(TAG, "Storing easy auth " + I.address + " of: " + identityHex);
BlueJay.storeAuthKey(I.address, identityHex);
identify();
}
} else if (bytes.length == 2) {
switch(bytes[1]) {
case ERROR_INVALID:
addToLog("Cannot easy auth as not connected to charger");
break;
case ERROR_OUT_OF_RANGE:
addToLog("Cannot easy auth as button is already pressed");
break;
case ERROR_MISC:
addToLog("Already authenticated, no need to easy auth");
break;
case ERROR_OK:
addToLog("Easy Auth mode - press the button for 2 seconds");
awaiting_easy_auth = tsl();
break;
}
} else {
UserError.Log.d(TAG, "Wrong size for easy auth reply: " + bytes.length);
}
}
}).queue();
doQueue();
}
use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip-plus by jamorham.
the class BlueJayService method sendGlucose.
public void sendGlucose() {
val last = BgReading.last();
if (last != null && msSince(last.timestamp) < Constants.HOUR_IN_MS) {
val info = BlueJayInfo.getInfo(BlueJay.getMac());
if (Math.abs(info.lastReadingTime - last.timestamp) > Constants.MINUTE_IN_MS * 3) {
val glucoseTx = new GlucoseTx(last);
if (glucoseTx.isValid()) {
val item = new QueueMe().setBytes(glucoseTx.getBytes()).expireInSeconds(60).setDescription("Glucose to watch");
item.setProcessor(new AuthReplyProcessor(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] bytes) {
UserError.Log.d(TAG, "Glucose Incoming reply processor: " + HexDump.dumpHexString(bytes));
info.displayUpdated();
}
}).setTag(item));
item.queue();
doQueue();
} else {
UserError.Log.d(TAG, "GlucoseTX wasn't valid so not sending.");
}
} else {
UserError.Log.d(TAG, "Watch already has recent reading");
// watch reading too close to the reading we were going to send
}
}
}
use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip by NightscoutFoundation.
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 by NightscoutFoundation.
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