mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-19 06:51:57 +02:00
Always include short code in prettyPrint
This commit is contained in:
@@ -27,25 +27,28 @@ public class BluetoothGattUuid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final String prettyPrint(UUID uuid) {
|
public static final String prettyPrint(UUID uuid) {
|
||||||
for (Field field : BluetoothGattUuid.class.getFields()) {
|
String str = uuid.toString();
|
||||||
try {
|
|
||||||
if (uuid.equals(field.get(null))) {
|
|
||||||
final String name = field.getName();
|
|
||||||
return name.substring(name.indexOf('_') + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final String str = uuid.toString();
|
|
||||||
if (str.endsWith(STANDARD_SUFFIX)) {
|
if (str.endsWith(STANDARD_SUFFIX)) {
|
||||||
String code = str.substring(0, str.length() - STANDARD_SUFFIX.length());
|
String code = str.substring(0, str.length() - STANDARD_SUFFIX.length());
|
||||||
if (code.startsWith("0000")) {
|
if (code.startsWith("0000")) {
|
||||||
code = code.substring(4);
|
code = code.substring(4);
|
||||||
}
|
}
|
||||||
return "0x" + code;
|
str = "0x" + code;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Field field : BluetoothGattUuid.class.getFields()) {
|
||||||
|
try {
|
||||||
|
if (uuid.equals(field.get(null))) {
|
||||||
|
String name = field.getName();
|
||||||
|
name = name.substring(name.indexOf('_') + 1);
|
||||||
|
str = String.format("%s \"%s\"", str, name.replace('_', ' '));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
@@ -28,13 +28,13 @@ public class BluetoothGattUuidTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void prettyPrint() throws Exception {
|
public void prettyPrint() throws Exception {
|
||||||
assertEquals("GENERIC_ACCESS",
|
assertEquals("0x1800 \"GENERIC ACCESS\"",
|
||||||
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.SERVICE_GENERIC_ACCESS));
|
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.SERVICE_GENERIC_ACCESS));
|
||||||
assertEquals("CURRENT_TIME",
|
assertEquals("0x2a2b \"CURRENT TIME\"",
|
||||||
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME));
|
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME));
|
||||||
assertEquals("CLIENT_CHARACTERISTIC_CONFIGURATION",
|
assertEquals("0x2902 \"CLIENT CHARACTERISTIC CONFIGURATION\"",
|
||||||
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION));
|
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION));
|
||||||
assertEquals("GENERIC_ATTRIBUTE",
|
assertEquals("0x1801 \"GENERIC ATTRIBUTE\"",
|
||||||
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.fromShortCode(0x1801)));
|
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.fromShortCode(0x1801)));
|
||||||
assertEquals("0x0001",
|
assertEquals("0x0001",
|
||||||
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.fromShortCode(0x1)));
|
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.fromShortCode(0x1)));
|
||||||
|
Reference in New Issue
Block a user