Search in sources :

Example 96 with TransactionBuilder

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

the class WatchXPlusDeviceSupport method getUnitsSettings.

/**
 * request watch units
 * for testing purposes only
 */
private WatchXPlusDeviceSupport getUnitsSettings() {
    LOG.info(" Get units from watch... ");
    try {
        TransactionBuilder builder = performInitialized("getUnits");
        builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_SET_UNITS, WatchXPlusConstants.READ_VALUE));
        builder.queue(getQueue());
    } catch (IOException e) {
        LOG.warn(" Unable to get units ", e);
    }
    return this;
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 97 with TransactionBuilder

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

the class WatchXPlusDeviceSupport method setTime.

// set only digital time
private void setTime(Calendar calendar) {
    try {
        TransactionBuilder builder = performInitialized("setTime");
        int timezoneOffsetMinutes = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / (60 * 1000);
        int timezoneOffsetIndustrialMinutes = Math.round((Math.abs(timezoneOffsetMinutes) % 60) * 100f / 60f);
        byte[] time = new byte[] { BcdUtil.toBcd8(calendar.get(Calendar.YEAR) % 100), BcdUtil.toBcd8(calendar.get(Calendar.MONTH) + 1), BcdUtil.toBcd8(calendar.get(Calendar.DAY_OF_MONTH)), BcdUtil.toBcd8(calendar.get(Calendar.HOUR_OF_DAY)), BcdUtil.toBcd8(calendar.get(Calendar.MINUTE)), BcdUtil.toBcd8(calendar.get(Calendar.SECOND)), (byte) (timezoneOffsetMinutes / 60), (byte) timezoneOffsetIndustrialMinutes, (byte) (calendar.get(Calendar.DAY_OF_WEEK) - 1) };
        builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_TIME_SETTINGS, WatchXPlusConstants.WRITE_VALUE, time));
        builder.queue(getQueue());
    } catch (IOException e) {
        LOG.warn(" Unable to set time ", e);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 98 with TransactionBuilder

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

the class WatchXPlusDeviceSupport method onFetchRecordedData.

@Override
public void onFetchRecordedData(int dataTypes) {
    TransactionBuilder builder;
    // get battery state
    try {
        builder = performInitialized("getBatteryInfo");
        builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_BATTERY_INFO, WatchXPlusConstants.READ_VALUE));
        builder.queue(getQueue());
    } catch (IOException e) {
        LOG.warn(" Unable to retrieve battery data ", e);
    }
    try {
        builder = performInitialized("fetchData");
        builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_DAY_STEPS_INFO, WatchXPlusConstants.READ_VALUE));
        // Fetch heart rate data samples count
        requestDataCount(DataType.HEART_RATE);
        builder.queue(getQueue());
    } catch (IOException e) {
        LOG.warn(" Unable to retrieve recorded data ", e);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 99 with TransactionBuilder

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

the class WatchXPlusDeviceSupport method requestDataContentForTimestamp.

private void requestDataContentForTimestamp(int timestamp, DataType dataType) {
    byte[] command = WatchXPlusConstants.CMD_RETRIEVE_DATA_CONTENT;
    try {
        TransactionBuilder builder = performInitialized("requestDataContentForTimestamp");
        byte[] ts = Conversion.toByteArr32(timestamp);
        byte[] req = BLETypeConversions.join(dataType.getValue(), ts);
        req = BLETypeConversions.join(req, Conversion.toByteArr16(0));
        requestedDataTimestamp = timestamp;
        builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(command, WatchXPlusConstants.READ_VALUE, req));
        builder.queue(getQueue());
    } catch (IOException e) {
        LOG.warn(" Unable to request data content ", e);
    }
}
Also used : TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException)

Example 100 with TransactionBuilder

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

the class WatchXPlusDeviceSupport method handleAck.

private void handleAck() {
    try {
        TransactionBuilder builder = performInitialized("handleAck");
        builder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand());
        builder.queue(getQueue());
    } catch (IOException e) {
        LOG.warn(" Unable to response to ACK ", 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