Search in sources :

Example 6 with ReplyProcessor

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

Example 7 with ReplyProcessor

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

Example 8 with ReplyProcessor

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

Example 9 with ReplyProcessor

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);
    }
}
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 10 with ReplyProcessor

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;
}
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