1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-19 15:01:53 +02:00

Use BluetoothGattUuid constants and makeShortCode

This commit is contained in:
Erik Johansson
2018-11-15 22:19:36 +01:00
parent a2eb34b11a
commit 789a7db7e2
14 changed files with 77 additions and 115 deletions

View File

@@ -43,59 +43,8 @@ import timber.log.Timber;
public class BluetoothBeurerSanitas extends BluetoothCommunication { public class BluetoothBeurerSanitas extends BluetoothCommunication {
enum DeviceType { BEURER_BF700_800_RT_LIBRA, BEURER_BF710, SANITAS_SBF70_70 } enum DeviceType { BEURER_BF700_800_RT_LIBRA, BEURER_BF710, SANITAS_SBF70_70 }
private static final int PRIMARY_SERVICE = 0x180A; private static final UUID CUSTOM_SERVICE_1 = BluetoothGattUuid.fromShortCode(0xffe0);
private static final UUID SYSTEM_ID = UUID.fromString("00002A23-0000-1000-8000-00805F9B34FB"); private static final UUID CUSTOM_CHARACTERISTIC_WEIGHT = BluetoothGattUuid.fromShortCode(0xffe1);
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 final DeviceType deviceType; private final DeviceType deviceType;
private int startByte; private int startByte;

View File

@@ -30,8 +30,8 @@ import java.util.UUID;
import timber.log.Timber; import timber.log.Timber;
public class BluetoothCustomOpenScale extends BluetoothCommunication { public class BluetoothCustomOpenScale extends BluetoothCommunication {
private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xffe0);
private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb"); // Bluetooth Modul HM-10 private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xffe1); // Bluetooth Modul HM-10
private String string_data = new String(); private String string_data = new String();

View File

@@ -50,8 +50,8 @@ public class BluetoothDebug extends BluetoothCommunication {
private boolean isBlacklisted(BluetoothGattService service, BluetoothGattCharacteristic characteristic) { private boolean isBlacklisted(BluetoothGattService service, BluetoothGattCharacteristic characteristic) {
// Reading this triggers a pairing request on Beurer BF710 // Reading this triggers a pairing request on Beurer BF710
if (service.getUuid().equals(UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb")) if (service.getUuid().equals(BluetoothGattUuid.fromShortCode(0xffe0))
&& characteristic.getUuid().equals(UUID.fromString("0000ffe5-0000-1000-8000-00805f9b34fb"))) { && characteristic.getUuid().equals(BluetoothGattUuid.fromShortCode(0xffe5))) {
return true; return true;
} }

View File

@@ -30,9 +30,9 @@ import java.util.UUID;
import timber.log.Timber; import timber.log.Timber;
public class BluetoothDigooDGSO38H extends BluetoothCommunication { public class BluetoothDigooDGSO38H 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 = UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1);
private final UUID EXTRA_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000fff2-0000-1000-8000-00805f9b34fb"); private final UUID EXTRA_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff2);
public BluetoothDigooDGSO38H(Context context) { public BluetoothDigooDGSO38H(Context context) {
super(context); super(context);

View File

@@ -29,9 +29,9 @@ import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
public class BluetoothExcelvanCF36xBLE extends BluetoothCommunication { public class BluetoothExcelvanCF36xBLE 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 = UUID.fromString("0000FFF1-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff1);
private final UUID WEIGHT_CUSTOM0_CHARACTERISTIC = UUID.fromString("0000FFF4-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_CUSTOM0_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff4);
private byte[] receivedData = new byte[]{}; private byte[] receivedData = new byte[]{};

View File

@@ -26,9 +26,9 @@ import java.util.Date;
import java.util.UUID; import java.util.UUID;
public class BluetoothHesley extends BluetoothCommunication { public class BluetoothHesley 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 = UUID.fromString("0000fff4-0000-1000-8000-00805f9b34fb"); // read, notify private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xfff4); // read, 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 BluetoothHesley(Context context) { public BluetoothHesley(Context context) {
super(context); super(context);

View File

@@ -33,7 +33,7 @@ import java.util.Arrays;
import timber.log.Timber; import timber.log.Timber;
public class BluetoothIhealthHS3 extends BluetoothCommunication { 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 BluetoothSocket btSocket = null;
private BluetoothDevice btDevice = null; private BluetoothDevice btDevice = null;

View File

@@ -33,9 +33,9 @@ import java.util.UUID;
public class BluetoothMGB extends BluetoothCommunication { public class BluetoothMGB extends BluetoothCommunication {
private static final UUID uuid_service = UUID.fromString("0000ffb0-0000-1000-8000-00805f9b34fb"); private static final UUID uuid_service = BluetoothGattUuid.fromShortCode(0xffb0);
private static final UUID uuid_char_cfg = UUID.fromString("0000ffb1-0000-1000-8000-00805f9b34fb"); private static final UUID uuid_char_cfg = BluetoothGattUuid.fromShortCode(0xffb1);
private static final UUID uuid_char_ctrl = UUID.fromString("0000ffb2-0000-1000-8000-00805f9b34fb"); private static final UUID uuid_char_ctrl = BluetoothGattUuid.fromShortCode(0xffb2);
private Calendar now; private Calendar now;

View File

@@ -26,12 +26,11 @@ import java.util.Date;
import java.util.UUID; import java.util.UUID;
public class BluetoothMedisanaBS44x extends BluetoothCommunication { public class BluetoothMedisanaBS44x extends BluetoothCommunication {
private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("000078b2-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0x78b2);
private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a21-0000-1000-8000-00805f9b34fb"); // indication, read-only private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0x8a21); // indication, read-only
private final UUID FEATURE_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a22-0000-1000-8000-00805f9b34fb"); // indication, read-only private final UUID FEATURE_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0x8a22); // indication, read-only
private final UUID CUSTOM3_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a20-0000-1000-8000-00805f9b34fb"); // read-only private final UUID CMD_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0x8a81); // write-only
private final UUID CMD_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a81-0000-1000-8000-00805f9b34fb"); // write-only private final UUID CUSTOM5_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0x8a82); // indication, read-only
private final UUID CUSTOM5_MEASUREMENT_CHARACTERISTIC = UUID.fromString("00008a82-0000-1000-8000-00805f9b34fb"); // indication, read-only
private ScaleMeasurement btScaleMeasurement; private ScaleMeasurement btScaleMeasurement;

View File

@@ -40,10 +40,7 @@ import timber.log.Timber;
import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_UNEXPECTED_ERROR; import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_UNEXPECTED_ERROR;
public class BluetoothMiScale extends BluetoothCommunication { 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_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) { public BluetoothMiScale(Context context) {
super(context); super(context);
@@ -103,7 +100,8 @@ public class BluetoothMiScale extends BluetoothCommunication {
switch (stateNr) { switch (stateNr) {
case 0: case 0:
// read device time // read device time
readBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC); readBytes(BluetoothGattUuid.SERVICE_WEIGHT_SCALE,
BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME);
break; break;
case 1: case 1:
// set current time // 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}; 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; break;
case 2: case 2:
// set notification on for weight measurement history // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
case 3: case 3:
// Set on history weight measurement // Set on history weight measurement
byte[] magicBytes = new byte[]{(byte)0x01, (byte)0x96, (byte)0x8a, (byte)0xbd, (byte)0x62}; 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; break;
default: default:
return false; return false;
@@ -142,12 +143,14 @@ public class BluetoothMiScale extends BluetoothCommunication {
switch (stateNr) { switch (stateNr) {
case 0: case 0:
// set notification on for weight measurement history // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
case 1: case 1:
// set notification on for weight measurement // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
case 2: case 2:
@@ -155,21 +158,25 @@ public class BluetoothMiScale extends BluetoothCommunication {
int uniqueNumber = getUniqueNumber(); int uniqueNumber = getUniqueNumber();
byte[] userIdentifier = new byte[]{(byte)0x01, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; 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; break;
case 3: case 3:
// set notification off for weight measurement history // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
case 4: case 4:
// set notification on for weight measurement history // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
case 5: case 5:
// invoke receiving history data // 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; break;
default: default:
return false; return false;
@@ -184,14 +191,16 @@ public class BluetoothMiScale extends BluetoothCommunication {
switch (stateNr) { switch (stateNr) {
case 0: case 0:
// send stop command to mi scale // 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; break;
case 1: case 1:
// acknowledge that you received the last history data // acknowledge that you received the last history data
int uniqueNumber = getUniqueNumber(); int uniqueNumber = getUniqueNumber();
byte[] userIdentifier = new byte[]{(byte)0x04, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; 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; break;
default: default:
return false; return false;

View File

@@ -47,11 +47,7 @@ import timber.log.Timber;
import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_UNEXPECTED_ERROR; import static com.health.openscale.core.bluetooth.BluetoothCommunication.BT_STATUS_CODE.BT_UNEXPECTED_ERROR;
public class BluetoothMiScale2 extends BluetoothCommunication { 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_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_SERVICE = UUID.fromString("00001530-0000-3512-2118-0009af100700");
private final UUID WEIGHT_CUSTOM_CONFIG = UUID.fromString("00001542-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}; 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; break;
case 2: case 2:
// set notification on for weight measurement history // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
default: default:
@@ -135,21 +133,25 @@ public class BluetoothMiScale2 extends BluetoothCommunication {
int uniqueNumber = getUniqueNumber(); int uniqueNumber = getUniqueNumber();
byte[] userIdentifier = new byte[]{(byte)0x01, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; 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; break;
case 1: case 1:
// set notification off for weight measurement history // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
case 2: case 2:
// set notification on for weight measurement history // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
case 3: case 3:
// invoke receiving history data // 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; break;
default: default:
return false; return false;
@@ -164,18 +166,21 @@ public class BluetoothMiScale2 extends BluetoothCommunication {
switch (stateNr) { switch (stateNr) {
case 0: case 0:
// send stop command to mi scale // 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; break;
case 1: case 1:
// acknowledge that you received the last history data // acknowledge that you received the last history data
int uniqueNumber = getUniqueNumber(); int uniqueNumber = getUniqueNumber();
byte[] userIdentifier = new byte[]{(byte)0x04, (byte)0xFF, (byte)0xFF, (byte) ((uniqueNumber & 0xFF00) >> 8), (byte) ((uniqueNumber & 0xFF) >> 0)}; 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; break;
case 2: case 2:
// set notification on for body composition measurement // 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); BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION);
break; break;
default: default:

View File

@@ -31,11 +31,11 @@ import java.util.UUID;
import timber.log.Timber; import timber.log.Timber;
public class BluetoothOneByone extends BluetoothCommunication { 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) { public BluetoothOneByone(Context context) {

View File

@@ -44,15 +44,15 @@ public class BluetoothTrisaBodyAnalyze extends BluetoothCommunication {
// GATT service UUID // GATT service UUID
private static final UUID WEIGHT_SCALE_SERVICE_UUID = private static final UUID WEIGHT_SCALE_SERVICE_UUID =
UUID.fromString("00007802-0000-1000-8000-00805f9b34fb"); BluetoothGattUuid.fromShortCode(0x7802);
// GATT service characteristics. // GATT service characteristics.
private static final UUID MEASUREMENT_CHARACTERISTIC_UUID = 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 = 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 = private static final UUID UPLOAD_COMMAND_CHARACTERISTIC_UUID =
UUID.fromString("00008a82-0000-1000-8000-00805f9b34fb"); BluetoothGattUuid.fromShortCode(0x8a82);
// Commands sent from device to host. // Commands sent from device to host.
private static final byte UPLOAD_PASSWORD = (byte) 0xa0; private static final byte UPLOAD_PASSWORD = (byte) 0xa0;

View File

@@ -35,10 +35,10 @@ import java.util.UUID;
import timber.log.Timber; import timber.log.Timber;
public class BluetoothYunmaiSE_Mini extends BluetoothCommunication { public class BluetoothYunmaiSE_Mini extends BluetoothCommunication {
private final UUID WEIGHT_MEASUREMENT_SERVICE = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_SERVICE = BluetoothGattUuid.fromShortCode(0xffe0);
private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = UUID.fromString("0000ffe4-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_MEASUREMENT_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xffe4);
private final UUID WEIGHT_CMD_SERVICE = UUID.fromString("0000ffe5-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_CMD_SERVICE = BluetoothGattUuid.fromShortCode(0xffe5);
private final UUID WEIGHT_CMD_CHARACTERISTIC = UUID.fromString("0000ffe9-0000-1000-8000-00805f9b34fb"); private final UUID WEIGHT_CMD_CHARACTERISTIC = BluetoothGattUuid.fromShortCode(0xffe9);
private boolean isMini; private boolean isMini;