1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-18 14:31:23 +02:00

Always include short code in prettyPrint

This commit is contained in:
Erik Johansson
2018-11-15 20:46:44 +01:00
parent 779b5dcbd5
commit 9ad07a80fd
2 changed files with 20 additions and 17 deletions

View File

@@ -27,25 +27,28 @@ public class BluetoothGattUuid {
}
public static final String prettyPrint(UUID uuid) {
for (Field field : BluetoothGattUuid.class.getFields()) {
try {
if (uuid.equals(field.get(null))) {
final String name = field.getName();
return name.substring(name.indexOf('_') + 1);
}
}
catch (IllegalAccessException e) {
// Ignore
}
}
String str = uuid.toString();
final String str = uuid.toString();
if (str.endsWith(STANDARD_SUFFIX)) {
String code = str.substring(0, str.length() - STANDARD_SUFFIX.length());
if (code.startsWith("0000")) {
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;

View File

@@ -28,13 +28,13 @@ public class BluetoothGattUuidTest {
@Test
public void prettyPrint() throws Exception {
assertEquals("GENERIC_ACCESS",
assertEquals("0x1800 \"GENERIC ACCESS\"",
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.SERVICE_GENERIC_ACCESS));
assertEquals("CURRENT_TIME",
assertEquals("0x2a2b \"CURRENT TIME\"",
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME));
assertEquals("CLIENT_CHARACTERISTIC_CONFIGURATION",
assertEquals("0x2902 \"CLIENT CHARACTERISTIC CONFIGURATION\"",
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION));
assertEquals("GENERIC_ATTRIBUTE",
assertEquals("0x1801 \"GENERIC ATTRIBUTE\"",
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.fromShortCode(0x1801)));
assertEquals("0x0001",
BluetoothGattUuid.prettyPrint(BluetoothGattUuid.fromShortCode(0x1)));