Search in sources :

Example 1 with SetTimeTx

use of com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx in project xDrip by NightscoutFoundation.

the class BlueJayService method setTime.

public void setTime() {
    new QueueMe().setGenerator(new BytesGenerator() {

        @Override
        public byte[] produce() {
            timeOutbound = new SetTimeTx();
            return timeOutbound.getBytes();
        }
    }).setDescription("Set time").expireInSeconds(30).setProcessor(new ReplyProcessor(I.connection) {

        @Override
        public void process(byte[] bytes) {
            final SetTimeTx reply = new SetTimeTx(bytes);
            UserError.Log.d(TAG, "Time Process callback: " + JoH.bytesToHex(bytes));
            getInfo().parseSetTime(reply, timeOutbound);
            UserError.Log.d(TAG, "Time difference with watch: " + ((timeOutbound.getTimestamp() - reply.getTimestamp()) / 1000d));
        }
    }).queue();
}
Also used : BytesGenerator(com.eveningoutpost.dexdrip.utils.BytesGenerator) SetTimeTx(com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx) ReplyProcessor(com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor)

Example 2 with SetTimeTx

use of com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx in project xDrip by NightscoutFoundation.

the class BlueJayService method sendTime.

// Not using packet queue due to reactive time sensitive nature
private void sendTime() {
    final String func = "SetTime";
    final SetTimeTx outbound = new SetTimeTx();
    UserError.Log.d(TAG, "Outbound: " + bytesToHex(outbound.getBytes()));
    I.connection.writeCharacteristic(THINJAM_WRITE, outbound.getBytes()).subscribe(response -> {
        SetTimeTx reply = new SetTimeTx(response);
        if (D)
            UserError.Log.d(TAG, func + " response: " + bytesToHex(response) + " " + reply.toS());
        UserError.Log.e(TAG, "Time difference with watch: " + ((outbound.getTimestamp() - reply.getTimestamp()) / 1000d));
        changeNextState();
    }, throwable -> {
        UserError.Log.e(TAG, "Failed to write " + func + " request: " + throwable);
        if (throwable instanceof BleGattCharacteristicException) {
            final int status = ((BleGattCharacteristicException) throwable).getStatus();
            UserError.Log.e(TAG, "Got status message: " + Helper.getStatusName(status));
        } else {
            UserError.Log.d(TAG, "Throwable in " + func + " " + throwable);
            if (throwable instanceof BleCharacteristicNotFoundException) {
                UserError.Log.d(TAG, "Assuming wrong firmware version");
                changeNextState();
            } else {
                changeState(CLOSE);
            }
        }
    });
}
Also used : BleGattCharacteristicException(com.polidea.rxandroidble2.exceptions.BleGattCharacteristicException) BleCharacteristicNotFoundException(com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException) SetTimeTx(com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx) SuppressLint(android.annotation.SuppressLint) SlidingWindowConstraint(com.eveningoutpost.dexdrip.utils.time.SlidingWindowConstraint)

Example 3 with SetTimeTx

use of com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx in project xDrip-plus by jamorham.

the class BlueJayService method setTime.

public void setTime() {
    new QueueMe().setGenerator(new BytesGenerator() {

        @Override
        public byte[] produce() {
            timeOutbound = new SetTimeTx();
            return timeOutbound.getBytes();
        }
    }).setDescription("Set time").expireInSeconds(30).setProcessor(new ReplyProcessor(I.connection) {

        @Override
        public void process(byte[] bytes) {
            final SetTimeTx reply = new SetTimeTx(bytes);
            UserError.Log.d(TAG, "Time Process callback: " + JoH.bytesToHex(bytes));
            getInfo().parseSetTime(reply, timeOutbound);
            UserError.Log.d(TAG, "Time difference with watch: " + ((timeOutbound.getTimestamp() - reply.getTimestamp()) / 1000d));
        }
    }).queue();
}
Also used : BytesGenerator(com.eveningoutpost.dexdrip.utils.BytesGenerator) SetTimeTx(com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx) ReplyProcessor(com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor)

Example 4 with SetTimeTx

use of com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx in project xDrip-plus by jamorham.

the class BlueJayService method sendTime.

// Not using packet queue due to reactive time sensitive nature
private void sendTime() {
    final String func = "SetTime";
    final SetTimeTx outbound = new SetTimeTx();
    UserError.Log.d(TAG, "Outbound: " + bytesToHex(outbound.getBytes()));
    I.connection.writeCharacteristic(THINJAM_WRITE, outbound.getBytes()).subscribe(response -> {
        SetTimeTx reply = new SetTimeTx(response);
        if (D)
            UserError.Log.d(TAG, func + " response: " + bytesToHex(response) + " " + reply.toS());
        UserError.Log.e(TAG, "Time difference with watch: " + ((outbound.getTimestamp() - reply.getTimestamp()) / 1000d));
        changeNextState();
    }, throwable -> {
        UserError.Log.e(TAG, "Failed to write " + func + " request: " + throwable);
        if (throwable instanceof BleGattCharacteristicException) {
            final int status = ((BleGattCharacteristicException) throwable).getStatus();
            UserError.Log.e(TAG, "Got status message: " + Helper.getStatusName(status));
        } else {
            UserError.Log.d(TAG, "Throwable in " + func + " " + throwable);
            if (throwable instanceof BleCharacteristicNotFoundException) {
                UserError.Log.d(TAG, "Assuming wrong firmware version");
                changeNextState();
            } else {
                changeState(CLOSE);
            }
        }
    });
}
Also used : BleGattCharacteristicException(com.polidea.rxandroidble2.exceptions.BleGattCharacteristicException) BleCharacteristicNotFoundException(com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException) SetTimeTx(com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx) SuppressLint(android.annotation.SuppressLint) SlidingWindowConstraint(com.eveningoutpost.dexdrip.utils.time.SlidingWindowConstraint)

Aggregations

SetTimeTx (com.eveningoutpost.dexdrip.watch.thinjam.messages.SetTimeTx)4 SuppressLint (android.annotation.SuppressLint)2 BytesGenerator (com.eveningoutpost.dexdrip.utils.BytesGenerator)2 ReplyProcessor (com.eveningoutpost.dexdrip.utils.bt.ReplyProcessor)2 SlidingWindowConstraint (com.eveningoutpost.dexdrip.utils.time.SlidingWindowConstraint)2 BleCharacteristicNotFoundException (com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException)2 BleGattCharacteristicException (com.polidea.rxandroidble2.exceptions.BleGattCharacteristicException)2