use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip by NightscoutFoundation.
the class BlueJayService method sendNotification.
public void sendNotification(final String message_type, final String msg) {
UserError.Log.d(TAG, "SendNotification: " + message_type + " " + msg);
if (!versionSufficient(getInfo().buildNumber, FEATURE_TJ_DISP_A))
return;
if (BlueJayAsset.queueBusy()) {
UserError.Log.d(TAG, "Refusing to send notification as asset queue is busy");
return;
}
int notificationType = 1;
if (message_type != null) {
switch(message_type.toUpperCase()) {
case THINJAM_NOTIFY_TYPE_CANCEL:
if (msSince(lastLongPress1) < SECOND_IN_MS) {
UserError.Log.d(TAG, "Not doing circular cancel");
return;
}
notificationType = 0;
break;
case THINJAM_NOTIFY_TYPE_TEXTBOX1:
notificationType = 6;
break;
case THINJAM_NOTIFY_TYPE_DIALOG:
notificationType = 9;
break;
case THINJAM_NOTIFY_TYPE_LOW_ALERT:
notificationType = 2;
break;
case THINJAM_NOTIFY_TYPE_HIGH_ALERT:
notificationType = 1;
break;
}
}
val list = getPacketStreamForNotification(notificationType, msg);
int counter = 0;
for (val part : list) {
counter++;
val item = new QueueMe().setBytes(part.getBytes()).expireInSeconds(60).setDescription("Notify type:" + message_type + " part:" + counter);
item.setProcessor(new AuthReplyProcessor(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] bytes) {
UserError.Log.d(TAG, "Notify reply processor: " + HexDump.dumpHexString(bytes));
}
}).setTag(item));
item.queue();
}
doQueue();
}
use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip by NightscoutFoundation.
the class BlueJayService method getBackFill.
public void getBackFill(int records) {
if (BlueJay.haveAuthKey(I.address)) {
if (!flashRunning()) {
val outbound = new BackFillTx(records);
val item = new QueueMe().setBytes(outbound.getBytes()).setDescription("Get BackFill " + records).expireInSeconds(30);
item.setProcessor(new AuthReplyProcessor(new ReplyProcessor(I.connection) {
@Override
public void process(byte[] bytes) {
UserError.Log.d(TAG, "BackFill request response: " + JoH.bytesToHex(bytes));
}
}).setTag(item)).queue();
} else {
UserError.Log.d(TAG, "No backfill as flash running");
}
} else {
UserError.Log.d(TAG, "Cannot back fill as we don't have auth key");
}
}
use of com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor in project xDrip by NightscoutFoundation.
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 by NightscoutFoundation.
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 by NightscoutFoundation.
the class JamBaseBluetoothSequencer method addToWriteQueue.
private void addToWriteQueue(final QueueMe queueMe, final boolean unique, final boolean atHead) {
Cloner cloner = null;
if (queueMe.byteslist == null) {
queueMe.byteslist = new LinkedList<>();
if (queueMe.generator != null) {
// create pseudo entry if this is using a generator
queueMe.byteslist.add(null);
}
}
final boolean multiple = queueMe.byteslist.size() > 1;
for (final byte[] bytes : queueMe.byteslist) {
if (unique) {
// skip if duplicate bytes
if (doesWriteQueueContainBytes(bytes))
continue;
}
ReplyProcessor replyProcessor = queueMe.processor;
if (replyProcessor != null) {
if (multiple) {
if (cloner == null)
cloner = new Cloner();
replyProcessor = cloner.shallowClone(queueMe.processor);
}
if (replyProcessor != null) {
replyProcessor.setOutbound(bytes);
} else {
UserError.Log.wtf(TAG, "Could not create clone of reply processor needed!!");
}
}
UUID queueWriteCharacterstic = queueMe.queueWriteCharacterstic;
if (queueWriteCharacterstic == null)
queueWriteCharacterstic = I.queue_write_characterstic;
if (atHead) {
I.write_queue.addFirst(new QueueItem(queueWriteCharacterstic, bytes, queueMe.timeout_seconds, queueMe.delay_ms, queueMe.description, queueMe.expect_reply, queueMe.expireAt).setRunnable(queueMe.runnable).setProcessor(replyProcessor).setGenerator(queueMe.generator));
} else {
I.write_queue.add(new QueueItem(queueWriteCharacterstic, bytes, queueMe.timeout_seconds, queueMe.delay_ms, queueMe.description, queueMe.expect_reply, queueMe.expireAt).setRunnable(queueMe.runnable).setProcessor(replyProcessor).setGenerator(queueMe.generator));
}
}
if (queueMe.start_now)
startQueueSend();
}
Aggregations