Search in sources :

Example 11 with ReplyProcessor

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

Example 12 with ReplyProcessor

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

Example 13 with ReplyProcessor

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

Example 14 with ReplyProcessor

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

Example 15 with ReplyProcessor

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();
}
Also used : UUID(java.util.UUID) Cloner(com.rits.cloning.Cloner) 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