diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerSanitas.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerSanitas.java index 0a411434..815ad752 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerSanitas.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothBeurerSanitas.java @@ -43,59 +43,8 @@ import timber.log.Timber; public class BluetoothBeurerSanitas extends BluetoothCommunication { enum DeviceType { BEURER_BF700_800_RT_LIBRA, BEURER_BF710, SANITAS_SBF70_70 } - private static final int PRIMARY_SERVICE = 0x180A; - private static final UUID SYSTEM_ID = UUID.fromString("00002A23-0000-1000-8000-00805F9B34FB"); - private static final UUID MODEL_NUMBER_STRING = - UUID.fromString("00002A24-0000-1000-8000-00805F9B34FB"); - private static final UUID SERIAL_NUMBER_STRING = - UUID.fromString("00002A25-0000-1000-8000-00805F9B34FB"); - private static final UUID FIRMWARE_REVISION_STRING = - UUID.fromString("00002A26-0000-1000-8000-00805F9B34FB"); - private static final UUID HARDWARE_REVISION_STRING = - UUID.fromString("00002A27-0000-1000-8000-00805F9B34FB"); - private static final UUID SOFTWARE_REVISION_STRING = - UUID.fromString("00002A28-0000-1000-8000-00805F9B34FB"); - private static final UUID MANUFACTURER_NAME_STRING = - UUID.fromString("00002A29-0000-1000-8000-00805F9B34FB"); - private static final UUID IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST = - UUID.fromString("00002A2A-0000-1000-8000-00805F9B34FB"); - private static final UUID PNP_ID = - UUID.fromString("00002A50-0000-1000-8000-00805F9B34FB"); - private static final UUID DEVICE_NAME = - UUID.fromString("00002A00-0000-1000-8000-00805F9B34FB"); - private static final UUID APPEARANCE = - UUID.fromString("00002A01-0000-1000-8000-00805F9B34FB"); - private static final UUID PERIPHERICAL_PRIVACY_FLAG = - UUID.fromString("00002A02-0000-1000-8000-00805F9B34FB"); - private static final UUID RECONNECTION_ADDRESS = - UUID.fromString("00002A03-0000-1000-8000-00805F9B34FB"); - private static final UUID PERIPHERICAL_PREFERRED_CONNECTION_PARAMETERS = - UUID.fromString("00002A04-0000-1000-8000-00805F9B34FB"); - - private static final UUID GENERIC_ATTRIBUTE = - UUID.fromString("00001801-0000-1000-8000-00805F9B34FB"); - private static final UUID SERVICE_CHANGED = - UUID.fromString("00002A05-0000-1000-8000-00805F9B34FB"); - - private static final UUID CUSTOM_SERVICE_1 = - UUID.fromString("0000FFE0-0000-1000-8000-00805F9B34FB"); - private static final UUID CUSTOM_CHARACTERISTIC_1 = // read-write - UUID.fromString("0000FFE4-0000-1000-8000-00805F9B34FB"); - private static final UUID CUSTOM_CHARACTERISTIC_2 = // read-only - UUID.fromString("0000FFE2-0000-1000-8000-00805F9B34FB"); - private static final UUID CUSTOM_CHARACTERISTIC_3 = // write-only - UUID.fromString("0000FFE3-0000-1000-8000-00805F9B34FB"); - private static final UUID CUSTOM_CHARACTERISTIC_WEIGHT = // write-only, notify ; handle=0x002e - UUID.fromString("0000FFE1-0000-1000-8000-00805F9B34FB"); - private static final UUID CUSTOM_CHARACTERISTIC_5 = // write-only, notify - UUID.fromString("0000FFE5-0000-1000-8000-00805F9B34FB"); - - private static final UUID CUSTOM_SERVICE_2 = - UUID.fromString("F000FFCD-0451-4000-8000-000000000000"); // primary service - private static final UUID CUSTOM_CHARACTERISTIC_IMG_IDENTIFY = // write-only, notify - UUID.fromString("F000FFC1-0451-4000-8000-000000000000"); - private static final UUID CUSTOM_CHARACTERISTIC_IMG_BLOCK = // write-only, notify - UUID.fromString("F000FFC2-0451-4000-8000-000000000000"); + private static final UUID CUSTOM_SERVICE_1 = BluetoothGattUuid.fromShortCode(0xffe0); + private static final UUID CUSTOM_CHARACTERISTIC_WEIGHT = BluetoothGattUuid.fromShortCode(0xffe1); private final DeviceType deviceType; private int startByte; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCustomOpenScale.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCustomOpenScale.java index 311c3786..abf642b8 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCustomOpenScale.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCustomOpenScale.java @@ -30,8 +30,8 @@ import java.util.UUID; import timber.log.Timber; public class BluetoothCustomOpenScale extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb"); // Bluetooth Modul HM-10 + private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xffe0); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xffe1); // Bluetooth Modul HM-10 private String string_data = new String(); diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDebug.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDebug.java index 0a978378..310ebb4e 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDebug.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDebug.java @@ -50,8 +50,8 @@ public class BluetoothDebug extends BluetoothCommunication { private boolean isBlacklisted(BluetoothGattService service, BluetoothGattCharacteristic characteristic) { // Reading this triggers a pairing request on Beurer BF710 - if (service.getUuid().equals(UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb")) - && characteristic.getUuid().equals(UUID.fromString("0000ffe5-0000-1000-8000-00805f9b34fb"))) { + if (service.getUuid().equals(BluetoothGattUuid.fromShortCode(0xffe0)) + && characteristic.getUuid().equals(BluetoothGattUuid.fromShortCode(0xffe5))) { return true; } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDigooDGSO38H.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDigooDGSO38H.java index a677449b..4b42cff1 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDigooDGSO38H.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothDigooDGSO38H.java @@ -30,9 +30,9 @@ import java.util.UUID; import timber.log.Timber; public class BluetoothDigooDGSO38H extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); - private final UUID EXTRA_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff2-0000-1000-8000-00805f9b34fb"); + private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xfff0); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1); + private final UUID EXTRA_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2); public BluetoothDigooDGSO38H(Context context) { super(context); diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExcelvanCF36xBLE.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExcelvanCF36xBLE.java index c4570976..89432f40 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExcelvanCF36xBLE.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExcelvanCF36xBLE.java @@ -29,9 +29,9 @@ import java.util.Arrays; import java.util.UUID; public class BluetoothExcelvanCF36xBLE extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000FFF0-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000FFF1-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_CUSTOM0_CHARACTERISTIC = UUID.fromString("0000FFF4-0000-1000-8000-00805f9b34fb"); + private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xfff0); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1); + private final UUID WEIGHT_CUSTOM0_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff4); private byte[] receivedData = new byte[]{}; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothHesley.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothHesley.java index 348d68ae..12491499 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothHesley.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothHesley.java @@ -26,9 +26,9 @@ import java.util.Date; import java.util.UUID; public class BluetoothHesley extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff4-0000-1000-8000-00805f9b34fb"); // read, notify - private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); // write only + private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xfff0); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff4); // read, notify + private final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1); // write only public BluetoothHesley(Context context) { super(context); diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothIhealthHS3.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothIhealthHS3.java index db01ae5d..0e181e64 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothIhealthHS3.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothIhealthHS3.java @@ -33,7 +33,7 @@ import java.util.Arrays; import timber.log.Timber; public class BluetoothIhealthHS3 extends BluetoothCommunication { - private final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // Standard SerialPortService ID + private final UUID uuid = BluetoothGattUuid.fromShortCode(0x1101); // Standard SerialPortService ID private BluetoothSocket btSocket = null; private BluetoothDevice btDevice = null; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMGB.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMGB.java index eb3eeb0e..c52f64f1 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMGB.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMGB.java @@ -33,9 +33,9 @@ import java.util.UUID; public class BluetoothMGB extends BluetoothCommunication { - private static final UUID uuid_service = UUID.fromString("0000ffb0-0000-1000-8000-00805f9b34fb"); - private static final UUID uuid_char_cfg = UUID.fromString("0000ffb1-0000-1000-8000-00805f9b34fb"); - private static final UUID uuid_char_ctrl = UUID.fromString("0000ffb2-0000-1000-8000-00805f9b34fb"); + private static final UUID uuid_service = BluetoothGattUuid.fromShortCode(0xffb0); + private static final UUID uuid_char_cfg = BluetoothGattUuid.fromShortCode(0xffb1); + private static final UUID uuid_char_ctrl = BluetoothGattUuid.fromShortCode(0xffb2); private Calendar now; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS44x.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS44x.java index 611fc9da..2d578925 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS44x.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMedisanaBS44x.java @@ -26,12 +26,11 @@ import java.util.Date; import java.util.UUID; public class BluetoothMedisanaBS44x extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("000078b2-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a21-0000-1000-8000-00805f9b34fb"); // indication, read-only - private final UUID FEATURE_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a22-0000-1000-8000-00805f9b34fb"); // indication, read-only - private final UUID CUSTOM3_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a20-0000-1000-8000-00805f9b34fb"); // read-only - private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a81-0000-1000-8000-00805f9b34fb"); // write-only - private final UUID CUSTOM5_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a82-0000-1000-8000-00805f9b34fb"); // indication, read-only + private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0x78b2); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0x8a21); // indication, read-only + private final UUID FEATURE_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0x8a22); // indication, read-only + private final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0x8a81); // write-only + private final UUID CUSTOM5_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0x8a82); // indication, read-only private ScaleMeasurement btScaleMeasurement; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java index fba8b3e8..a125102c 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale.java @@ -40,10 +40,7 @@ import timber.log.Timber; import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_UNEXPECTED_ERROR; public class BluetoothMiScale extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000181d-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00002a9d-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC = UUID.fromString("00002a2f-0000-3512-2118-0009af100700"); - private final UUID WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC = UUID.fromString("00002a2b-0000-1000-8000-00805f9b34fb"); public BluetoothMiScale(Context context) { super(context); @@ -103,7 +100,8 @@ public class BluetoothMiScale extends BluetoothCommunication { switch (stateNr) { case 0: // read device time - readBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC); + readBytes(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME); break; case 1: // set current time @@ -117,18 +115,21 @@ public class BluetoothMiScale extends BluetoothCommunication { byte[] dateTimeByte = {(byte)(year), (byte)(year >> 8), month, day, hour, min, sec, 0x03, 0x00, 0x00}; - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC, dateTimeByte); + writeBytes(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME, dateTimeByte); break; case 2: // set notification on for weight measurement history - setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, + setNotificationOn(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; case 3: // Set on history weight measurement byte[] magicBytes = new byte[]{(byte)0x01, (byte)0x96, (byte)0x8a, (byte)0xbd, (byte)0x62}; - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, magicBytes); + writeBytes(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, magicBytes); break; default: return false; @@ -142,12 +143,14 @@ public class BluetoothMiScale extends BluetoothCommunication { switch (stateNr) { case 0: // set notification on for weight measurement history - setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, + setNotificationOn(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; case 1: // set notification on for weight measurement - setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, + setNotificationOn(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + BluetoothGattUuid.CHARACTERISTIC_WEIGHT_MEASUREMENT, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; case 2: @@ -155,21 +158,25 @@ public class BluetoothMiScale extends BluetoothCommunication { int uniqueNumber = getUniqueNumber(); byte[] userIdentifier = new byte[]{(byte)0x01, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier); + writeBytes(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier); break; case 3: // set notification off for weight measurement history - setNotificationOff(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, + setNotificationOff(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; case 4: // set notification on for weight measurement history - setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, + setNotificationOn(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; case 5: // invoke receiving history data - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x02}); + writeBytes(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x02}); break; default: return false; @@ -184,14 +191,16 @@ public class BluetoothMiScale extends BluetoothCommunication { switch (stateNr) { case 0: // send stop command to mi scale - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x03}); + writeBytes(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x03}); break; case 1: // acknowledge that you received the last history data int uniqueNumber = getUniqueNumber(); byte[] userIdentifier = new byte[]{(byte)0x04, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier); + writeBytes(BluetoothGattUuid.SERVICE_WEIGHT_SCALE, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier); break; default: return false; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale2.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale2.java index 2e59c5a7..d305575b 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale2.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale2.java @@ -47,11 +47,7 @@ import timber.log.Timber; import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_UNEXPECTED_ERROR; public class BluetoothMiScale2 extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000181b-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC = UUID.fromString("00002a2f-0000-3512-2118-0009af100700"); - private final UUID WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC = UUID.fromString("00002a2b-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_BODY_COMPOSITION_FEATURE = UUID.fromString("00002a9b-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_BODY_COMPOSITION_MEASUREMENT = UUID.fromString("00002a9c-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_CUSTOM_SERVICE = UUID.fromString("00001530-0000-3512-2118-0009af100700"); private final UUID WEIGHT_CUSTOM_CONFIG = UUID.fromString("00001542-0000-3512-2118-0009af100700"); @@ -113,11 +109,13 @@ public class BluetoothMiScale2 extends BluetoothCommunication { byte[] dateTimeByte = {(byte)(year), (byte)(year >> 8), month, day, hour, min, sec, 0x03, 0x00, 0x00}; - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC, dateTimeByte); + writeBytes(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME, dateTimeByte); break; case 2: // set notification on for weight measurement history - setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, + setNotificationOn(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; default: @@ -135,21 +133,25 @@ public class BluetoothMiScale2 extends BluetoothCommunication { int uniqueNumber = getUniqueNumber(); byte[] userIdentifier = new byte[]{(byte)0x01, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier); + writeBytes(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier); break; case 1: // set notification off for weight measurement history - setNotificationOff(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, + setNotificationOff(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; case 2: // set notification on for weight measurement history - setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, + setNotificationOn(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; case 3: // invoke receiving history data - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x02}); + writeBytes(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x02}); break; default: return false; @@ -164,18 +166,21 @@ public class BluetoothMiScale2 extends BluetoothCommunication { switch (stateNr) { case 0: // send stop command to mi scale - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x03}); + writeBytes(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, new byte[]{0x03}); break; case 1: // acknowledge that you received the last history data int uniqueNumber = getUniqueNumber(); byte[] userIdentifier = new byte[]{(byte)0x04, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; - writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier); + writeBytes(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, userIdentifier); break; case 2: // set notification on for body composition measurement - setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_BODY_COMPOSITION_MEASUREMENT, + setNotificationOn(BluetoothGattUuid.SERVICE_BODY_COMPOSITION, + BluetoothGattUuid.CHARACTERISTIC_BODY_COMPOSITION_MEASUREMENT, BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION); break; default: diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java index 9a4e4860..ede4db4c 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothOneByone.java @@ -31,11 +31,11 @@ import java.util.UUID; import timber.log.Timber; public class BluetoothOneByone extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"); + private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xfff0); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC_BODY_COMPOSITION = UUID.fromString("0000fff4-0000-1000-8000-00805f9b34fb"); // notify + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC_BODY_COMPOSITION = BluetoothGattUuid.fromShortCode(0xfff4); // notify - private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); // write only + private final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1); // write only public BluetoothOneByone(Context context) { diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothTrisaBodyAnalyze.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothTrisaBodyAnalyze.java index abd1d004..52dab296 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothTrisaBodyAnalyze.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothTrisaBodyAnalyze.java @@ -44,15 +44,15 @@ public class BluetoothTrisaBodyAnalyze extends BluetoothCommunication { // GATT service UUID private static final UUID WEIGHT_SCALE_SERVICE_UUID = - UUID.fromString("00007802-0000-1000-8000-00805f9b34fb"); + BluetoothGattUuid.fromShortCode(0x7802); // GATT service characteristics. private static final UUID MEASUREMENT_CHARACTERISTIC_UUID = - UUID.fromString("00008a21-0000-1000-8000-00805f9b34fb"); + BluetoothGattUuid.fromShortCode(0x8a21); private static final UUID DOWNLOAD_COMMAND_CHARACTERISTIC_UUID = - UUID.fromString("00008a81-0000-1000-8000-00805f9b34fb"); + BluetoothGattUuid.fromShortCode(0x8a81); private static final UUID UPLOAD_COMMAND_CHARACTERISTIC_UUID = - UUID.fromString("00008a82-0000-1000-8000-00805f9b34fb"); + BluetoothGattUuid.fromShortCode(0x8a82); // Commands sent from device to host. private static final byte UPLOAD_PASSWORD = (byte) 0xa0; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java index b4317f87..598a4f4f 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothYunmaiSE_Mini.java @@ -35,10 +35,10 @@ import java.util.UUID; import timber.log.Timber; public class BluetoothYunmaiSE_Mini extends BluetoothCommunication { - private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000ffe4-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_CMD_SERVICE = UUID.fromString("0000ffe5-0000-1000-8000-00805f9b34fb"); - private final UUID WEIGHT_CMD_CHARACTERISTIC = UUID.fromString("0000ffe9-0000-1000-8000-00805f9b34fb"); + private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xffe0); + private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xffe4); + private final UUID WEIGHT_CMD_SERVICE = BluetoothGattUuid.fromShortCode(0xffe5); + private final UUID WEIGHT_CMD_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xffe9); private boolean isMini;