From b6ba421a622efc4e20c7046a6bcac2765ded1fce Mon Sep 17 00:00:00 2001 From: Johannes Krude Date: Mon, 28 Aug 2023 21:52:14 +0200 Subject: [PATCH] Casio2C2D: refactor CasioConstants.characteristicToByte --- .../devices/casio/CasioConstants.java | 25 --------- .../devices/casio/Casio2C2DSupport.java | 25 ++++++++- .../gbx100/CasioGBX100DeviceSupport.java | 8 +-- .../gbx100/GetConfigurationOperation.java | 9 ++-- .../devices/casio/gbx100/InitOperation.java | 52 ++++++++++--------- .../gbx100/SetConfigurationOperation.java | 19 +++---- .../gwb5600/CasioGWB5600DeviceSupport.java | 1 + .../casio/gwb5600/CasioGWB5600TimeZone.java | 21 ++++---- .../devices/casio/gwb5600/InitOperation.java | 10 ++-- 9 files changed, 89 insertions(+), 81 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/CasioConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/CasioConstants.java index c3a155115..8bca67d35 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/CasioConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/casio/CasioConstants.java @@ -145,29 +145,4 @@ public final class CasioConstants { public static final int CASIO_AUTOREMOVE_MESSAGE_DELAY = 10000; - public static Map characteristicToByte = new HashMap() { - { - put("CASIO_WATCH_NAME", (byte) 0x23); - put("CASIO_APP_INFORMATION", (byte) 0x22); - put("CASIO_BLE_FEATURES", (byte) 0x10); - put("CASIO_SETTING_FOR_BLE", (byte) 0x11); - put("CASIO_ADVERTISE_PARAMETER_MANAGER", (byte) 0x3b); - put("CASIO_CONNECTION_PARAMETER_MANAGER", (byte) 0x3a); - put("CASIO_MODULE_ID", (byte) 0x26); - put("CASIO_WATCH_CONDITION", (byte) 0x28); - put("CASIO_VERSION_INFORMATION", (byte) 0x20); - put("CASIO_DST_WATCH_STATE", (byte) 0x1d); - put("CASIO_DST_SETTING", (byte) 0x1e); - put("CASIO_WORLD_CITY", (byte) 0x1f); - put("CASIO_SERVICE_DISCOVERY_MANAGER", (byte) 0x47); - put("CASIO_CURRENT_TIME", (byte) 0x09); - put("CASIO_SETTING_FOR_USER_PROFILE", (byte) 0x45); - put("CASIO_SETTING_FOR_TARGET_VALUE", (byte) 0x43); - put("ALERT_LEVEL", (byte) 0x0a); - put("CASIO_SETTING_FOR_ALM", (byte) 0x15); - put("CASIO_SETTING_FOR_ALM2", (byte) 0x16); - put("CASIO_SETTING_FOR_BASIC", (byte) 0x13); - put("CASIO_CURRENT_TIME_MANAGER", (byte) 0x39); - } - }; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/Casio2C2DSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/Casio2C2DSupport.java index 6670eb568..29ad65065 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/Casio2C2DSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/Casio2C2DSupport.java @@ -30,6 +30,29 @@ import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants; public abstract class Casio2C2DSupport extends CasioSupport { + public static final byte FEATURE_CURRENT_TIME = 0x09; + public static final byte FEATURE_ALERT_LEVEL = 0x0a; + public static final byte FEATURE_BLE_FEATURES = 0x10; + public static final byte FEATURE_SETTING_FOR_BLE = 0x11; + public static final byte FEATURE_SETTING_FOR_BASIC = 0x13; + public static final byte FEATURE_SETTING_FOR_ALM = 0x15; + public static final byte FEATURE_SETTING_FOR_ALM2 = 0x16; + public static final byte FEATURE_VERSION_INFORMATION = 0x20; + public static final byte FEATURE_APP_INFORMATION = 0x22; + public static final byte FEATURE_WATCH_NAME = 0x23; + public static final byte FEATURE_MODULE_ID = 0x26; + public static final byte FEATURE_WATCH_CONDITION = 0x28; + public static final byte FEATURE_DST_WATCH_STATE = 0x1d; + public static final byte FEATURE_DST_SETTING = 0x1e; + public static final byte FEATURE_WORLD_CITY = 0x1f; + public static final byte FEATURE_CURRENT_TIME_MANAGER = 0x39; + public static final byte FEATURE_CONNECTION_PARAMETER_MANAGER = 0x3a; + public static final byte FEATURE_ADVERTISE_PARAMETER_MANAGER = 0x3b; + public static final byte FEATURE_SETTING_FOR_TARGET_VALUE = 0x43; + public static final byte FEATURE_SETTING_FOR_USER_PROFILE = 0x45; + public static final byte FEATURE_SERVICE_DISCOVERY_MANAGER = 0x47; + + public Casio2C2DSupport(Logger logger) { super(logger); } @@ -44,7 +67,7 @@ public abstract class Casio2C2DSupport extends CasioSupport { public void writeCurrentTime(TransactionBuilder builder, ZonedDateTime time) { byte[] arr = new byte[11]; - arr[0] = CasioConstants.characteristicToByte.get("CASIO_CURRENT_TIME"); + arr[0] = FEATURE_CURRENT_TIME; byte[] tmp = prepareCurrentTime(time); System.arraycopy(tmp, 0, arr, 1, 10); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java index 15a3ee180..1521067e0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gbx100/CasioGBX100DeviceSupport.java @@ -211,14 +211,14 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared return true; if (characteristicUUID.equals(CasioConstants.CASIO_ALL_FEATURES_CHARACTERISTIC_UUID)) { - if(data[0] == CasioConstants.characteristicToByte.get("ALERT_LEVEL")) { + if(data[0] == FEATURE_ALERT_LEVEL) { if(data[1] == 0x02) { onReverseFindDevice(true); } else { onReverseFindDevice(false); } return true; - } else if(data[0] == CasioConstants.characteristicToByte.get("CASIO_CURRENT_TIME_MANAGER")) { + } else if(data[0] == FEATURE_CURRENT_TIME_MANAGER) { if(data[1] == 0x00) { try { TransactionBuilder builder = performInitialized("writeCurrentTime"); @@ -509,8 +509,8 @@ public class CasioGBX100DeviceSupport extends Casio2C2DSupport implements Shared if(!isConnected()) return; - data1[0] = CasioConstants.characteristicToByte.get("CASIO_SETTING_FOR_ALM"); - data2[0] = CasioConstants.characteristicToByte.get("CASIO_SETTING_FOR_ALM2"); + data1[0] = FEATURE_SETTING_FOR_ALM; + data2[0] = FEATURE_SETTING_FOR_ALM2; for(int i=0; i { private static final Logger LOG = LoggerFactory.getLogger(InitOperation.class); @@ -91,47 +93,47 @@ public class InitOperation extends AbstractBTLEOperation> 8 & 0xff; byte arr[] = new byte[20]; - arr[0] = CasioConstants.characteristicToByte.get("CASIO_ADVERTISE_PARAMETER_MANAGER"); + arr[0] = Casio2C2DSupport.FEATURE_ADVERTISE_PARAMETER_MANAGER; arr[1] = (byte)0x50; arr[2] = (byte)0x00; arr[3] = (byte)0x0a; @@ -236,7 +238,7 @@ public class InitOperation extends AbstractBTLEOperation> 8 & 0xff; byte[] arr = new byte[10]; - arr[0] = CasioConstants.characteristicToByte.get("CASIO_CONNECTION_PARAMETER_MANAGER"); + arr[0] = Casio2C2DSupport.FEATURE_CONNECTION_PARAMETER_MANAGER; arr[1] = (byte)0x00; arr[2] = (byte)0x34; arr[3] = (byte)0x01; @@ -292,43 +294,43 @@ public class InitOperation extends AbstractBTLEOperation= 9) { + if (response[0] == Casio2C2DSupport.FEATURE_DST_WATCH_STATE && response.length >= 9) { if (response[1] == slot) { dstSetting = response[3]; number = new byte[] {response[5], response[6]}; @@ -198,12 +199,12 @@ PONTA DELGADA E4 00 FC 04 02 dstSetting = response[4]; number = new byte[] {response[7], response[8]}; } - } else if (response[0] == CasioConstants.characteristicToByte.get("CASIO_DST_SETTING") && response.length >= 7 && response[1] == slot) { + } else if (response[0] == Casio2C2DSupport.FEATURE_DST_SETTING && response.length >= 7 && response[1] == slot) { number = new byte[] {response[2], response[3]}; offset = response[4]; dstOffset = response[5]; dstRules = response[6]; - } else if (response[0] == CasioConstants.characteristicToByte.get("CASIO_WORLD_CITY") && response.length >= 2 && response[1] == slot) { + } else if (response[0] == Casio2C2DSupport.FEATURE_WORLD_CITY && response.length >= 2 && response[1] == slot) { int size; for (size = 0; size < response.length-2; size++) { if (response[2+size] == 0) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gwb5600/InitOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gwb5600/InitOperation.java index 3b4eb42fa..b6158fd32 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gwb5600/InitOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/casio/gwb5600/InitOperation.java @@ -39,6 +39,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEOperation; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.OperationStatus; +import nodomain.freeyourgadget.gadgetbridge.devices.casio.CasioConstants; +import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.Casio2C2DSupport; +import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gwb5600.CasioGWB5600DeviceSupport; +import nodomain.freeyourgadget.gadgetbridge.service.devices.casio.gwb5600.CasioGWB5600TimeZone; public class InitOperation extends AbstractBTLEOperation { private static final Logger LOG = LoggerFactory.getLogger(InitOperation.class); @@ -79,9 +83,9 @@ public class InitOperation extends AbstractBTLEOperation 0 && - (data[0] == CasioConstants.characteristicToByte.get("CASIO_DST_WATCH_STATE") || - data[0] == CasioConstants.characteristicToByte.get("CASIO_DST_SETTING") || - data[0] == CasioConstants.characteristicToByte.get("CASIO_WORLD_CITY"))) { + (data[0] == Casio2C2DSupport.FEATURE_DST_WATCH_STATE || + data[0] == Casio2C2DSupport.FEATURE_DST_SETTING || + data[0] == Casio2C2DSupport.FEATURE_WORLD_CITY)) { responses.add(data); if (responses.size() == 13) { TransactionBuilder builder = createTransactionBuilder("setClocks");