Search in sources :

Example 21 with ReplyProcessor

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();
}
Also used : lombok.val(lombok.val) ReplyProcessor(com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor)

Example 22 with ReplyProcessor

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);
    }
}
Also used : DefineWindowTx(com.eveningoutpost.dexdrip.watch.thinjam.messages.DefineWindowTx) BaseTx(com.eveningoutpost.dexdrip.watch.thinjam.messages.BaseTx) ReplyProcessor(com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor)

Example 23 with ReplyProcessor

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();
}
Also used : lombok.val(lombok.val) ReplyProcessor(com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor)

Example 24 with ReplyProcessor

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;
}
Also used : lombok.val(lombok.val) ReplyProcessor(com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor)

Aggregations

ReplyProcessor (com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor)24 lombok.val (lombok.val)18 BaseTx (com.eveningoutpost.dexdrip.watch.thinjam.messages.BaseTx)4 DefineWindowTx (com.eveningoutpost.dexdrip.watch.thinjam.messages.DefineWindowTx)4 SuppressLint (android.annotation.SuppressLint)2 BytesGenerator (com.eveningoutpost.dexdrip.utils.BytesGenerator)2 SlidingWindowConstraint (com.eveningoutpost.dexdrip.utils.time.SlidingWindowConstraint)2 BackFillTx (com.eveningoutpost.dexdrip.watch.thinjam.messages.BackFillTx)2 GlucoseTx (com.eveningoutpost.dexdrip.watch.thinjam.messages.GlucoseTx)2 SetTimeTx (com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx)2 StandbyTx (com.eveningoutpost.dexdrip.watch.thinjam.messages.StandbyTx)2 Cloner (com.rits.cloning.Cloner)2 UUID (java.util.UUID)2