Search in sources :

Example 71 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class UpdateFirmwareOperation2020 method sendFwInfo.

public boolean sendFwInfo() {
    try {
        TransactionBuilder builder = performInitialized("send firmware info");
        builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.updating_firmware), getContext()));
        int fwSize = getFirmwareInfo().getSize();
        byte[] sizeBytes = BLETypeConversions.fromUint32(fwSize);
        int crc32 = firmwareInfo.getCrc32();
        byte[] chunkSizeBytes = BLETypeConversions.fromUint16(mChunkLength);
        byte[] crcBytes = BLETypeConversions.fromUint32(crc32);
        byte[] bytes = new byte[] { COMMAND_SEND_FIRMWARE_INFO, getFirmwareInfo().getFirmwareType().getValue(), sizeBytes[0], sizeBytes[1], sizeBytes[2], sizeBytes[3], crcBytes[0], crcBytes[1], crcBytes[2], crcBytes[3], chunkSizeBytes[0], chunkSizeBytes[1], // ??
        0, // index
        0, // count
        1, // total size? right now it is equal to the size above
        sizeBytes[0], sizeBytes[1], sizeBytes[2], sizeBytes[3] };
        if (getFirmwareInfo().getFirmwareType() == HuamiFirmwareType.WATCHFACE) {
            byte[] fwBytes = firmwareInfo.getBytes();
            if (ArrayUtils.startsWith(fwBytes, UIHH_HEADER)) {
                getSupport().writeToConfiguration(builder, new byte[] { 0x39, 0x00, sizeBytes[0], sizeBytes[1], sizeBytes[2], sizeBytes[3], fwBytes[18], fwBytes[19], fwBytes[20], fwBytes[21] });
            }
        }
        builder.write(fwCControlChar, bytes);
        builder.queue(getQueue());
        return true;
    } catch (IOException e) {
        LOG.error("Error sending firmware info: " + e.getLocalizedMessage(), e);
        return false;
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) SetDeviceBusyAction(nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction) IOException(java.io.IOException)

Example 72 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class UpdateFirmwareOperation2020 method sendTransferComplete.

protected void sendTransferComplete() throws IOException {
    TransactionBuilder builder = performInitialized("trasfer complete");
    builder.write(fwCControlChar, new byte[] { COMMAND_COMPLETE_TRANSFER });
    builder.queue(getQueue());
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)

Example 73 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class AbstractID115Operation method operationFinished.

@Override
protected void operationFinished() {
    operationStatus = OperationStatus.FINISHED;
    if (getDevice() != null && getDevice().isConnected()) {
        unsetBusy();
        try {
            TransactionBuilder builder = performInitialized("reenabling disabled notifications");
            enableNotifications(builder, false);
            // unset ourselves from being the queue's gatt callback
            builder.setGattCallback(null);
            builder.queue(getQueue());
        } catch (IOException ex) {
            GB.toast(getContext(), "Error enabling ID115 notifications, you may need to connect and disconnect", Toast.LENGTH_LONG, GB.ERROR, ex);
        }
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 74 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class ID115Support method onSetTime.

@Override
public void onSetTime() {
    try {
        TransactionBuilder builder = performInitialized("time");
        setTime(builder);
        builder.queue(getQueue());
    } catch (IOException e) {
        LOG.warn("Unable to send current time", e);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 75 with TransactionBuilder

use of nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder in project Gadgetbridge by Freeyourgadget.

the class ID115Support method onReset.

@Override
public void onReset(int flags) {
    try {
        getQueue().clear();
        TransactionBuilder builder = performInitialized("reboot");
        builder.write(normalWriteCharacteristic, new byte[] { ID115Constants.CMD_ID_DEVICE_RESTART, ID115Constants.CMD_KEY_REBOOT });
        builder.queue(getQueue());
    } catch (Exception e) {
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Aggregations

TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)279 IOException (java.io.IOException)218 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)17 Alarm (nodomain.freeyourgadget.gadgetbridge.model.Alarm)16 UnsupportedEncodingException (java.io.UnsupportedEncodingException)12 GregorianCalendar (java.util.GregorianCalendar)11 UUID (java.util.UUID)11 Calendar (java.util.Calendar)10 SetDeviceBusyAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction)10 ByteBuffer (java.nio.ByteBuffer)8 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)8 ServerTransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.ServerTransactionBuilder)7 SetDeviceStateAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction)7 GBException (nodomain.freeyourgadget.gadgetbridge.GBException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 SetProgressAction (nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetProgressAction)4 AlertNotificationProfile (nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile)4 NewAlert (nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert)4 GBPrefs (nodomain.freeyourgadget.gadgetbridge.util.GBPrefs)4 InvalidKeyException (java.security.InvalidKeyException)3