1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-14 19:57:32 +01:00

Mi Band 6: Send all old settings to new characteristics

This adds a compatibility wrapper to make it easier
This commit is contained in:
Andreas Shimokawa 2021-09-01 13:38:48 +02:00
parent 117cd57463
commit 4a27825931

View File

@ -655,12 +655,11 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSetAlarms(ArrayList<? extends Alarm> alarms) { public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
try { try {
BluetoothGattCharacteristic characteristic = getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION);
TransactionBuilder builder = performInitialized("Set alarm"); TransactionBuilder builder = performInitialized("Set alarm");
boolean anyAlarmEnabled = false; boolean anyAlarmEnabled = false;
for (Alarm alarm : alarms) { for (Alarm alarm : alarms) {
anyAlarmEnabled |= alarm.getEnabled(); anyAlarmEnabled |= alarm.getEnabled();
queueAlarm(alarm, builder, characteristic); queueAlarm(alarm, builder);
} }
builder.queue(getQueue()); builder.queue(getQueue());
if (anyAlarmEnabled) { if (anyAlarmEnabled) {
@ -1038,7 +1037,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
} }
public HuamiSupport sendFactoryReset(TransactionBuilder builder) { public HuamiSupport sendFactoryReset(TransactionBuilder builder) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_FACTORY_RESET); writeToConfiguration(builder, HuamiService.COMMAND_FACTORY_RESET);
return this; return this;
} }
@ -1446,7 +1445,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
try { try {
TransactionBuilder builder = performInitialized("acknowledge find phone"); TransactionBuilder builder = performInitialized("acknowledge find phone");
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), AmazfitBipService.COMMAND_ACK_FIND_PHONE_IN_PROGRESS); writeToConfiguration(builder,AmazfitBipService.COMMAND_ACK_FIND_PHONE_IN_PROGRESS);
builder.queue(getQueue()); builder.queue(getQueue());
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("Error sending current weather", ex); LOG.error("Error sending current weather", ex);
@ -1795,7 +1794,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
* @param builder * @param builder
* @param characteristic * @param characteristic
*/ */
private void queueAlarm(Alarm alarm, TransactionBuilder builder, BluetoothGattCharacteristic characteristic) { private void queueAlarm(Alarm alarm, TransactionBuilder builder) {
Calendar calendar = AlarmUtils.toCalendar(alarm); Calendar calendar = AlarmUtils.toCalendar(alarm);
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice); DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
@ -1831,13 +1830,8 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
(byte) calendar.get(Calendar.MINUTE), (byte) calendar.get(Calendar.MINUTE),
(byte) daysMask, (byte) daysMask,
}; };
if (force2021Protocol) {
alarmMessage = ArrayUtils.insert(0, alarmMessage, (byte) 0x01);
writeToChunked2021(builder, HuamiService.CHUNKED2021_ENDPOINT_COMPAT, getNextHandle(), alarmMessage, true);
} else {
builder.write(characteristic, alarmMessage);
}
writeToConfiguration(builder,alarmMessage);
// TODO: react on 0x10, 0x02, 0x01 on notification (success) // TODO: react on 0x10, 0x02, 0x01 on notification (success)
} }
@ -1877,8 +1871,6 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
* @param builder * @param builder
*/ */
private HuamiSupport sendCalendarEvents(TransactionBuilder builder) { private HuamiSupport sendCalendarEvents(TransactionBuilder builder) {
BluetoothGattCharacteristic characteristic = getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION);
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress())); Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
int availableSlots = prefs.getInt(PREF_RESERVER_ALARMS_CALENDAR, 0); int availableSlots = prefs.getInt(PREF_RESERVER_ALARMS_CALENDAR, 0);
@ -1899,7 +1891,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(mEvt.getBegin()); calendar.setTimeInMillis(mEvt.getBegin());
Alarm alarm = AlarmUtils.createSingleShot(slotToUse, false, true, calendar); Alarm alarm = AlarmUtils.createSingleShot(slotToUse, false, true, calendar);
queueAlarm(alarm, builder, characteristic); queueAlarm(alarm, builder);
iteration++; iteration++;
} }
} }
@ -2332,10 +2324,10 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
LOG.info("Setting date display to " + dateTimeDisplay); LOG.info("Setting date display to " + dateTimeDisplay);
switch (dateTimeDisplay) { switch (dateTimeDisplay) {
case TIME: case TIME:
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.DATEFORMAT_TIME); writeToConfiguration(builder,HuamiService.DATEFORMAT_TIME);
break; break;
case DATE_TIME: case DATE_TIME:
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.DATEFORMAT_DATE_TIME); writeToConfiguration(builder,HuamiService.DATEFORMAT_DATE_TIME);
break; break;
} }
return this; return this;
@ -2352,7 +2344,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
case "dd/MM/yyyy": case "dd/MM/yyyy":
byte[] command = HuamiService.DATEFORMAT_DATE_MM_DD_YYYY; byte[] command = HuamiService.DATEFORMAT_DATE_MM_DD_YYYY;
System.arraycopy(dateFormat.getBytes(), 0, command, 3, 10); System.arraycopy(dateFormat.getBytes(), 0, command, 3, 10);
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command); writeToConfiguration(builder,command);
break; break;
default: default:
LOG.warn("unsupported date format " + dateFormat); LOG.warn("unsupported date format " + dateFormat);
@ -2367,9 +2359,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
LOG.info("Setting time format to " + timeFormat); LOG.info("Setting time format to " + timeFormat);
if (timeFormat.equals("24h")) { if (timeFormat.equals("24h")) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.DATEFORMAT_TIME_24_HOURS); writeToConfiguration(builder,HuamiService.DATEFORMAT_TIME_24_HOURS);
} else { } else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.DATEFORMAT_TIME_12_HOURS); writeToConfiguration(builder,HuamiService.DATEFORMAT_TIME_12_HOURS);
} }
return this; return this;
} }
@ -2378,9 +2370,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
boolean enable = HuamiCoordinator.getGoalNotification(); boolean enable = HuamiCoordinator.getGoalNotification();
LOG.info("Setting goal notification to " + enable); LOG.info("Setting goal notification to " + enable);
if (enable) { if (enable) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENABLE_GOAL_NOTIFICATION); writeToConfiguration(builder,HuamiService.COMMAND_ENABLE_GOAL_NOTIFICATION);
} else { } else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_GOAL_NOTIFICATION); writeToConfiguration(builder,HuamiService.COMMAND_DISABLE_GOAL_NOTIFICATION);
} }
return this; return this;
} }
@ -2391,10 +2383,10 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
switch (displayOnLift) { switch (displayOnLift) {
case ON: case ON:
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST); writeToConfiguration(builder, HuamiService.COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST);
break; break;
case OFF: case OFF:
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST); writeToConfiguration(builder, HuamiService.COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST);
break; break;
case SCHEDULED: case SCHEDULED:
byte[] cmd = HuamiService.COMMAND_SCHEDULE_DISPLAY_ON_LIFT_WRIST.clone(); byte[] cmd = HuamiService.COMMAND_SCHEDULE_DISPLAY_ON_LIFT_WRIST.clone();
@ -2411,7 +2403,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
cmd[6] = (byte) calendar.get(Calendar.HOUR_OF_DAY); cmd[6] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
cmd[7] = (byte) calendar.get(Calendar.MINUTE); cmd[7] = (byte) calendar.get(Calendar.MINUTE);
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), cmd); writeToConfiguration(builder, cmd);
} }
return this; return this;
} }
@ -2440,7 +2432,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_BATTERY)) { if (pages.contains(MiBandConst.PREF_MI2_DISPLAY_ITEM_BATTERY)) {
data[HuamiService.SCREEN_CHANGE_BYTE] |= HuamiService.DISPLAY_ITEM_BIT_BATTERY; data[HuamiService.SCREEN_CHANGE_BYTE] |= HuamiService.DISPLAY_ITEM_BIT_BATTERY;
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), data); writeToConfiguration(builder,data);
} }
return this; return this;
@ -2513,7 +2505,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
command[2] = (byte) ((enabled_mask >> 8 & 0xff)); command[2] = (byte) ((enabled_mask >> 8 & 0xff));
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), command); writeToConfiguration(builder, command);
return this; return this;
} }
@ -2592,15 +2584,15 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
boolean enable = HuamiCoordinator.getRotateWristToSwitchInfo(gbDevice.getAddress()); boolean enable = HuamiCoordinator.getRotateWristToSwitchInfo(gbDevice.getAddress());
LOG.info("Setting rotate wrist to cycle info to " + enable); LOG.info("Setting rotate wrist to cycle info to " + enable);
if (enable) { if (enable) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENABLE_ROTATE_WRIST_TO_SWITCH_INFO); writeToConfiguration(builder, HuamiService.COMMAND_ENABLE_ROTATE_WRIST_TO_SWITCH_INFO);
} else { } else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_ROTATE_WRIST_TO_SWITCH_INFO); writeToConfiguration(builder, HuamiService.COMMAND_DISABLE_ROTATE_WRIST_TO_SWITCH_INFO);
} }
return this; return this;
} }
private HuamiSupport setDisplayCaller(TransactionBuilder builder) { private HuamiSupport setDisplayCaller(TransactionBuilder builder) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENABLE_DISPLAY_CALLER); writeToConfiguration(builder, HuamiService.COMMAND_ENABLE_DISPLAY_CALLER);
return this; return this;
} }
@ -2609,10 +2601,10 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
LOG.info("Setting do not disturb to " + doNotDisturb); LOG.info("Setting do not disturb to " + doNotDisturb);
switch (doNotDisturb) { switch (doNotDisturb) {
case OFF: case OFF:
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DO_NOT_DISTURB_OFF); writeToConfiguration(builder, HuamiService.COMMAND_DO_NOT_DISTURB_OFF);
break; break;
case AUTOMATIC: case AUTOMATIC:
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DO_NOT_DISTURB_AUTOMATIC); writeToConfiguration(builder, HuamiService.COMMAND_DO_NOT_DISTURB_AUTOMATIC);
break; break;
case SCHEDULED: case SCHEDULED:
byte[] data = HuamiService.COMMAND_DO_NOT_DISTURB_SCHEDULED.clone(); byte[] data = HuamiService.COMMAND_DO_NOT_DISTURB_SCHEDULED.clone();
@ -2629,7 +2621,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
data[HuamiService.DND_BYTE_END_HOURS] = (byte) calendar.get(Calendar.HOUR_OF_DAY); data[HuamiService.DND_BYTE_END_HOURS] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
data[HuamiService.DND_BYTE_END_MINUTES] = (byte) calendar.get(Calendar.MINUTE); data[HuamiService.DND_BYTE_END_MINUTES] = (byte) calendar.get(Calendar.MINUTE);
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), data); writeToConfiguration(builder, data);
break; break;
} }
@ -2683,9 +2675,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
data[HuamiService.INACTIVITY_WARNINGS_INTERVAL_1_END_MINUTES] = (byte) calendar.get(Calendar.MINUTE); data[HuamiService.INACTIVITY_WARNINGS_INTERVAL_1_END_MINUTES] = (byte) calendar.get(Calendar.MINUTE);
} }
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), data); writeToConfiguration(builder, data);
} else { } else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_INACTIVITY_WARNINGS); writeToConfiguration(builder, HuamiService.COMMAND_DISABLE_INACTIVITY_WARNINGS);
} }
return this; return this;
@ -2697,10 +2689,10 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
switch (disconnectNotificationSetting) { switch (disconnectNotificationSetting) {
case ON: case ON:
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENABLE_DISCONNECT_NOTIFCATION); writeToConfiguration(builder, HuamiService.COMMAND_ENABLE_DISCONNECT_NOTIFCATION);
break; break;
case OFF: case OFF:
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_DISCONNECT_NOTIFCATION); writeToConfiguration(builder, HuamiService.COMMAND_DISABLE_DISCONNECT_NOTIFCATION);
break; break;
case SCHEDULED: case SCHEDULED:
byte[] cmd = HuamiService.COMMAND_ENABLE_DISCONNECT_NOTIFCATION.clone(); byte[] cmd = HuamiService.COMMAND_ENABLE_DISCONNECT_NOTIFCATION.clone();
@ -2717,7 +2709,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
cmd[6] = (byte) calendar.get(Calendar.HOUR_OF_DAY); cmd[6] = (byte) calendar.get(Calendar.HOUR_OF_DAY);
cmd[7] = (byte) calendar.get(Calendar.MINUTE); cmd[7] = (byte) calendar.get(Calendar.MINUTE);
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), cmd); writeToConfiguration(builder, cmd);
} }
return this; return this;
} }
@ -2726,9 +2718,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
MiBandConst.DistanceUnit unit = HuamiCoordinator.getDistanceUnit(); MiBandConst.DistanceUnit unit = HuamiCoordinator.getDistanceUnit();
LOG.info("Setting distance unit to " + unit); LOG.info("Setting distance unit to " + unit);
if (unit == MiBandConst.DistanceUnit.METRIC) { if (unit == MiBandConst.DistanceUnit.METRIC) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISTANCE_UNIT_METRIC); writeToConfiguration(builder, HuamiService.COMMAND_DISTANCE_UNIT_METRIC);
} else { } else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISTANCE_UNIT_IMPERIAL); writeToConfiguration(builder, HuamiService.COMMAND_DISTANCE_UNIT_IMPERIAL);
} }
return this; return this;
} }
@ -2738,9 +2730,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
LOG.info("Setting band screen unlock to " + enable); LOG.info("Setting band screen unlock to " + enable);
if (enable) { if (enable) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand3Service.COMMAND_ENABLE_BAND_SCREEN_UNLOCK); writeToConfiguration(builder, MiBand3Service.COMMAND_ENABLE_BAND_SCREEN_UNLOCK);
} else { } else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), MiBand3Service.COMMAND_DISABLE_BAND_SCREEN_UNLOCK); writeToConfiguration(builder, MiBand3Service.COMMAND_DISABLE_BAND_SCREEN_UNLOCK);
} }
return this; return this;
@ -2779,19 +2771,22 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
default: default:
command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH; command_old = AmazfitBipService.COMMAND_SET_LANGUAGE_ENGLISH;
} }
final byte[] finalCommand_old = command_old; if (force2021Protocol) {
builder.add(new ConditionalWriteAction(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION)) { writeToConfiguration(builder,command_new);
@Override } else {
protected byte[] checkCondition() { final byte[] finalCommand_old = command_old;
if ((gbDevice.getType() == DeviceType.AMAZFITBIP && new Version(gbDevice.getFirmwareVersion()).compareTo(new Version("0.1.0.77")) < 0) || builder.add(new ConditionalWriteAction(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION)) {
(gbDevice.getType() == DeviceType.AMAZFITCOR && new Version(gbDevice.getFirmwareVersion()).compareTo(new Version("1.0.7.23")) < 0)) { @Override
return finalCommand_old; protected byte[] checkCondition() {
} else { if ((gbDevice.getType() == DeviceType.AMAZFITBIP && new Version(gbDevice.getFirmwareVersion()).compareTo(new Version("0.1.0.77")) < 0) ||
return command_new; (gbDevice.getType() == DeviceType.AMAZFITCOR && new Version(gbDevice.getFirmwareVersion()).compareTo(new Version("1.0.7.23")) < 0)) {
return finalCommand_old;
} else {
return command_new;
}
} }
} });
}); }
return this; return this;
} }
@ -2801,9 +2796,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
LOG.info("Setting exposure of HR to third party apps to: " + enable); LOG.info("Setting exposure of HR to third party apps to: " + enable);
if (enable) { if (enable) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENBALE_HR_CONNECTION); writeToConfiguration(builder, HuamiService.COMMAND_ENBALE_HR_CONNECTION);
} else { } else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_HR_CONNECTION); writeToConfiguration(builder, HuamiService.COMMAND_DISABLE_HR_CONNECTION);
} }
return this; return this;
@ -2814,9 +2809,9 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
LOG.info("Setting connected advertisement to: " + enable); LOG.info("Setting connected advertisement to: " + enable);
if (enable) { if (enable) {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_ENABLE_BT_CONNECTED_ADVERTISEMENT); writeToConfiguration(builder, HuamiService.COMMAND_ENABLE_BT_CONNECTED_ADVERTISEMENT);
} else { } else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_DISABLE_BT_CONNECTED_ADVERTISEMENT); writeToConfiguration(builder, HuamiService.COMMAND_DISABLE_BT_CONNECTED_ADVERTISEMENT);
} }
return this; return this;
@ -2916,7 +2911,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
chunk[3] = handle; chunk[3] = handle;
chunk[4] = count; chunk[4] = count;
System.arraycopy(data, data.length-remaining, chunk, header_size, copybytes); System.arraycopy(data, data.length - remaining, chunk, header_size, copybytes);
builder.write(characteristicChunked2021Write, chunk); builder.write(characteristicChunked2021Write, chunk);
remaining -= copybytes; remaining -= copybytes;
header_size = 5; header_size = 5;
@ -2924,15 +2919,24 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
} }
} }
protected void writeToConfiguration(TransactionBuilder builder, byte[] data) {
if (force2021Protocol) {
data = ArrayUtils.insert(0, data, (byte) 1);
writeToChunked2021(builder, HuamiService.CHUNKED2021_ENDPOINT_COMPAT, getNextHandle(), data, true);
} else {
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), data);
}
}
protected HuamiSupport requestGPSVersion(TransactionBuilder builder) { protected HuamiSupport requestGPSVersion(TransactionBuilder builder) {
LOG.info("Requesting GPS version"); LOG.info("Requesting GPS version");
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_REQUEST_GPS_VERSION); writeToConfiguration(builder, HuamiService.COMMAND_REQUEST_GPS_VERSION);
return this; return this;
} }
private HuamiSupport requestAlarms(TransactionBuilder builder) { private HuamiSupport requestAlarms(TransactionBuilder builder) {
LOG.info("Requesting alarms"); LOG.info("Requesting alarms");
builder.write(getCharacteristic(HuamiService.UUID_CHARACTERISTIC_3_CONFIGURATION), HuamiService.COMMAND_REQUEST_ALARMS); writeToConfiguration(builder, HuamiService.COMMAND_REQUEST_ALARMS);
return this; return this;
} }