├── .gitignore ├── src ├── main │ └── java │ │ └── de │ │ └── grundid │ │ └── ble │ │ ├── fingerprint │ │ ├── UnknownSensorException.java │ │ ├── SensorMatcher.java │ │ ├── Sensor.java │ │ └── SensorParser.java │ │ ├── gatt │ │ ├── GattService.java │ │ ├── GattCharacteristic.java │ │ ├── CharacteristicHelper.java │ │ └── GattDb.java │ │ ├── sensors │ │ ├── generic │ │ │ ├── AlertLevel.java │ │ │ ├── HeartMeasurement.java │ │ │ └── TxPowerLevel.java │ │ └── tokencube │ │ │ ├── TokencubeOrientation.java │ │ │ └── TokencubeTemperature.java │ │ └── utils │ │ └── BleUtils.java └── test │ ├── java │ └── de │ │ └── grundid │ │ └── ble │ │ ├── fingerprint │ │ ├── SensorParserTest.java │ │ └── SensorMatcherTest.java │ │ └── TestUtils.java │ └── resources │ └── sensors.xml ├── README.md ├── LICENSE └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | **.springBeans 2 | **.project 3 | **.classpath 4 | **.settings 5 | **/target 6 | **/bin 7 | target -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/fingerprint/UnknownSensorException.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.fingerprint; 2 | 3 | public class UnknownSensorException extends Exception { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/gatt/GattService.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.gatt; 2 | 3 | public class GattService { 4 | 5 | private String name; 6 | private String type; 7 | private String uuid; 8 | 9 | public GattService(String name, String type, String uuid) { 10 | this.name = name; 11 | this.type = type; 12 | this.uuid = uuid.toLowerCase(); 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public String getType() { 20 | return type; 21 | } 22 | 23 | public String getUuid() { 24 | return uuid; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/gatt/GattCharacteristic.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.gatt; 2 | 3 | public class GattCharacteristic { 4 | 5 | private String name; 6 | private String type; 7 | private String uuid; 8 | 9 | public GattCharacteristic(String name, String type, String uuid) { 10 | this.name = name; 11 | this.type = type; 12 | this.uuid = uuid.toLowerCase(); 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public String getType() { 20 | return type; 21 | } 22 | 23 | public String getUuid() { 24 | return uuid; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/de/grundid/ble/fingerprint/SensorParserTest.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.fingerprint; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.List; 6 | 7 | import org.junit.Test; 8 | import org.xmlpull.v1.XmlPullParser; 9 | 10 | import de.grundid.ble.TestUtils; 11 | 12 | public class SensorParserTest { 13 | 14 | @Test 15 | public void itShouldParseSensors() throws Exception { 16 | XmlPullParser xmlPullParser = TestUtils.createXmlPullParser("sensors.xml"); 17 | SensorParser parser = new SensorParser(xmlPullParser); 18 | List sensors = parser.parseSensors(); 19 | assertNotNull(sensors); 20 | assertEquals(2, sensors.size()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/de/grundid/ble/TestUtils.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble; 2 | 3 | import java.io.InputStream; 4 | 5 | import org.kxml2.io.KXmlParser; 6 | import org.xmlpull.v1.XmlPullParser; 7 | import org.xmlpull.v1.XmlPullParserException; 8 | 9 | public class TestUtils { 10 | 11 | public static XmlPullParser createXmlPullParser(String resourceName) { 12 | try { 13 | InputStream inputStream = TestUtils.class.getClassLoader().getResourceAsStream(resourceName); 14 | KXmlParser parser = new KXmlParser(); 15 | parser.setInput(inputStream, "utf8"); 16 | return parser; 17 | } 18 | catch (XmlPullParserException e) { 19 | throw new RuntimeException(e); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bluetooth Low Energy Tools for Android 2 | ====================================== 3 | 4 | This collection of tools and utility classes is meant for making the use of the 5 | bluetooth low energy functions of the Android 4.3+ easier. 6 | This project has just started and I don't have a common pattern how 7 | to implement all the goals. If you're working on BLE and have some reusable functions or classes 8 | please consider adding them to this collection of tools. 9 | 10 | The goals of the project are as follows: 11 | 12 | * design and implement patterns for the communication with BLE sensors 13 | * implement parsers for all the known characteristics 14 | * collect and implement parsers for proprietary sensors and characteristics 15 | * implement classes to read all values of a sensor 16 | * implement a fingerprint DB for sensors 17 | 18 | 19 | Since this project is quite fresh, there are no releases yet. Classes and functions might change quite often. 20 | Please clone and use it as a sub-project in your Android project. -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/sensors/generic/AlertLevel.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.sensors.generic; 2 | 3 | import java.util.UUID; 4 | 5 | import android.bluetooth.BluetoothGattCharacteristic; 6 | 7 | public class AlertLevel { 8 | 9 | private static final UUID MY_UUID = UUID.fromString("00002a06-0000-1000-8000-00805f9b34fb"); 10 | private BluetoothGattCharacteristic characteristic; 11 | 12 | public AlertLevel(BluetoothGattCharacteristic characteristic) { 13 | this.characteristic = characteristic; 14 | } 15 | 16 | public void setNoAlert() { 17 | setValue(0); 18 | } 19 | 20 | public void setMildAlert() { 21 | setValue(1); 22 | } 23 | 24 | public void setHighAlert() { 25 | setValue(2); 26 | } 27 | 28 | public static boolean isUuid(UUID uuid) { 29 | return MY_UUID.equals(uuid); 30 | } 31 | 32 | private void setValue(int value) { 33 | characteristic.setValue(value, BluetoothGattCharacteristic.FORMAT_UINT8, 0); 34 | characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/gatt/CharacteristicHelper.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.gatt; 2 | 3 | import android.bluetooth.BluetoothGattCharacteristic; 4 | 5 | public class CharacteristicHelper { 6 | 7 | private BluetoothGattCharacteristic characteristic; 8 | private int propertiesFlag; 9 | 10 | public CharacteristicHelper(BluetoothGattCharacteristic characteristic) { 11 | this.characteristic = characteristic; 12 | this.propertiesFlag = characteristic.getProperties(); 13 | } 14 | 15 | public boolean isRead() { 16 | return isBitSet(BluetoothGattCharacteristic.PROPERTY_READ); 17 | } 18 | 19 | public boolean isNotify() { 20 | return isBitSet(BluetoothGattCharacteristic.PROPERTY_NOTIFY); 21 | } 22 | 23 | public boolean isWrite() { 24 | return isBitSet(BluetoothGattCharacteristic.PROPERTY_WRITE); 25 | } 26 | 27 | public boolean isWriteNoResponse() { 28 | return isBitSet(BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE); 29 | } 30 | 31 | private boolean isBitSet(int bit) { 32 | return (propertiesFlag & bit) == bit; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/sensors/generic/HeartMeasurement.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.sensors.generic; 2 | 3 | import java.util.UUID; 4 | 5 | import android.bluetooth.BluetoothGattCharacteristic; 6 | 7 | public class HeartMeasurement { 8 | 9 | public final static UUID MY_UUID = UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb"); 10 | private int heartRate; 11 | 12 | public HeartMeasurement(int heartRate) { 13 | this.heartRate = heartRate; 14 | } 15 | 16 | public int getHeartRate() { 17 | return heartRate; 18 | } 19 | 20 | public static boolean isUuid(UUID uuid) { 21 | return MY_UUID.equals(uuid); 22 | } 23 | 24 | public static HeartMeasurement fromCharacteristic(BluetoothGattCharacteristic characteristic) { 25 | int flag = characteristic.getProperties(); 26 | int format = -1; 27 | if ((flag & 0x01) != 0) { 28 | format = BluetoothGattCharacteristic.FORMAT_UINT16; 29 | } 30 | else { 31 | format = BluetoothGattCharacteristic.FORMAT_UINT8; 32 | } 33 | int heartRate = characteristic.getIntValue(format, 1); 34 | return new HeartMeasurement(heartRate); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/fingerprint/SensorMatcher.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.fingerprint; 2 | 3 | import java.util.List; 4 | import java.util.Map.Entry; 5 | import java.util.Set; 6 | import java.util.UUID; 7 | 8 | public class SensorMatcher { 9 | 10 | private List sensors; 11 | 12 | public SensorMatcher(List sensors) { 13 | this.sensors = sensors; 14 | } 15 | 16 | public String identifySensor(Sensor sensorToMatch) throws UnknownSensorException { 17 | for (Sensor sensor : sensors) { 18 | if (matchesSensor(sensor, sensorToMatch)) 19 | return sensor.getName(); 20 | } 21 | throw new UnknownSensorException(); 22 | } 23 | 24 | public boolean matchesSensor(Sensor sensor, Sensor sensorToMatch) { 25 | for (Entry> entry : sensor.getServices()) { 26 | UUID serviceUuid = entry.getKey(); 27 | if (!sensorToMatch.hasService(serviceUuid)) { 28 | return false; 29 | } 30 | for (UUID charaUuid : entry.getValue()) { 31 | if (!sensorToMatch.hasCharacteristic(serviceUuid, charaUuid)) 32 | return false; 33 | } 34 | } 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Adrian Stabiszewski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/fingerprint/Sensor.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.fingerprint; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Map.Entry; 7 | import java.util.Set; 8 | import java.util.UUID; 9 | 10 | public class Sensor { 11 | 12 | private String name; 13 | private Map> services = new HashMap>(); 14 | 15 | public Sensor(String name) { 16 | this.name = name; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void addService(UUID serviceUuid) { 24 | services.put(serviceUuid, new HashSet()); 25 | } 26 | 27 | public void addCharacteristic(UUID serviceUuid, UUID charUuid) { 28 | Set service = services.get(serviceUuid); 29 | service.add(charUuid); 30 | } 31 | 32 | public boolean hasService(UUID uuid) { 33 | return services.containsKey(uuid); 34 | } 35 | 36 | public boolean hasCharacteristic(UUID serviceUuid, UUID characterictisUuid) { 37 | Set set = services.get(serviceUuid); 38 | return set != null && set.contains(characterictisUuid); 39 | } 40 | 41 | public Set>> getServices() { 42 | return services.entrySet(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | de.grundid.maven 7 | java-parent 8 | 2013.1 9 | 10 | de.grundid.ble 11 | bletools 12 | 1.0-SNAPSHOT 13 | jar 14 | 15 | 16 | 1.6 17 | 18 | 19 | 20 | 21 | 22 | junit 23 | junit 24 | 25 | 26 | com.android 27 | platform 28 | 19 29 | ${env.ANDROID_HOME}/platforms/android-19/android.jar 30 | system 31 | 32 | 33 | kxml2 34 | kxml2 35 | 2.3.0 36 | test 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/sensors/tokencube/TokencubeOrientation.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.sensors.tokencube; 2 | 3 | import java.util.UUID; 4 | 5 | import android.bluetooth.BluetoothGattCharacteristic; 6 | 7 | public class TokencubeOrientation { 8 | 9 | private static final double FACTOR = 4096; 10 | private static final UUID MY_UUID = UUID.fromString("00002b20-0000-1000-8000-00805f9b34fb"); 11 | private float xAxis; 12 | private float yAxis; 13 | private float zAxis; 14 | 15 | public TokencubeOrientation(float xAxis, float yAxis, float zAxis) { 16 | this.xAxis = xAxis; 17 | this.yAxis = yAxis; 18 | this.zAxis = zAxis; 19 | } 20 | 21 | public float getXAxis() { 22 | return xAxis; 23 | } 24 | 25 | public float getYAxis() { 26 | return yAxis; 27 | } 28 | 29 | public float getZAxis() { 30 | return zAxis; 31 | } 32 | 33 | public static boolean isUuid(UUID uuid) { 34 | return MY_UUID.equals(uuid); 35 | } 36 | 37 | public static TokencubeOrientation fromCharacteristic(BluetoothGattCharacteristic characteristic) { 38 | Integer xValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 0); 39 | Integer yValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 2); 40 | Integer zValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 4); 41 | if (xValue != null && yValue != null && zValue != null) { 42 | float xAxis = (float)((float)xValue.intValue() / FACTOR); 43 | float yAxis = (float)((float)yValue.intValue() / FACTOR); 44 | float zAxis = (float)((float)zValue.intValue() / FACTOR); 45 | return new TokencubeOrientation(xAxis, yAxis, zAxis); 46 | } 47 | else 48 | throw new RuntimeException("getIntValue retured null"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/utils/BleUtils.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.utils; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | import java.util.Map.Entry; 6 | 7 | import android.bluetooth.BluetoothGattCharacteristic; 8 | 9 | public class BleUtils { 10 | 11 | private static final Map PROPERTIES = new LinkedHashMap(); 12 | static { 13 | PROPERTIES.put(BluetoothGattCharacteristic.PROPERTY_BROADCAST, "BC"); 14 | PROPERTIES.put(BluetoothGattCharacteristic.PROPERTY_READ, "RD"); 15 | PROPERTIES.put(BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE, "WN"); 16 | PROPERTIES.put(BluetoothGattCharacteristic.PROPERTY_WRITE, "WR"); 17 | PROPERTIES.put(BluetoothGattCharacteristic.PROPERTY_NOTIFY, "NY"); 18 | PROPERTIES.put(BluetoothGattCharacteristic.PROPERTY_INDICATE, "IN"); 19 | PROPERTIES.put(BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE, "SW"); 20 | PROPERTIES.put(BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS, "EP"); 21 | } 22 | 23 | public static String createPropertiesField(int flag) { 24 | StringBuilder sb = new StringBuilder(); 25 | for (Entry entry : PROPERTIES.entrySet()) { 26 | int flagBit = entry.getKey().intValue(); 27 | if ((flag & flagBit) == flagBit) { 28 | sb.append(entry.getValue()); 29 | } 30 | else { 31 | sb.append("--"); 32 | } 33 | } 34 | return sb.toString(); 35 | } 36 | 37 | public static String convertBinToASCII(byte[] bin) { 38 | return convertBinToASCII(bin, 0, bin.length); 39 | } 40 | 41 | public static String convertBinToASCII(byte[] bin, int offset, int length) { 42 | StringBuilder sb = new StringBuilder(); 43 | for (int x = offset; x < offset + length; x++) { 44 | String s = Integer.toHexString(bin[x]); 45 | if (s.length() == 1) 46 | sb.append('0'); 47 | else 48 | s = s.substring(s.length() - 2); 49 | sb.append(s); 50 | } 51 | return sb.toString().toUpperCase(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/sensors/tokencube/TokencubeTemperature.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.sensors.tokencube; 2 | 3 | import java.util.UUID; 4 | 5 | import android.bluetooth.BluetoothGattCharacteristic; 6 | import android.os.Parcel; 7 | import android.os.Parcelable; 8 | import android.util.Log; 9 | import de.grundid.ble.utils.BleUtils; 10 | 11 | public class TokencubeTemperature implements Parcelable { 12 | 13 | private static final double FACTOR = 0.00390625; 14 | private static final UUID MY_UUID = UUID.fromString("00002b10-0000-1000-8000-00805f9b34fb"); 15 | private float temperature; 16 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 17 | 18 | @Override 19 | public TokencubeTemperature createFromParcel(Parcel source) { 20 | return new TokencubeTemperature(source); 21 | } 22 | 23 | @Override 24 | public TokencubeTemperature[] newArray(int size) { 25 | return new TokencubeTemperature[size]; 26 | } 27 | }; 28 | 29 | private TokencubeTemperature(Parcel source) { 30 | this.temperature = source.readFloat(); 31 | } 32 | 33 | public TokencubeTemperature(float temperature) { 34 | this.temperature = temperature; 35 | } 36 | 37 | public float getTemperature() { 38 | return temperature; 39 | } 40 | 41 | @Override 42 | public int describeContents() { 43 | return 0; 44 | } 45 | 46 | @Override 47 | public void writeToParcel(Parcel dest, int flags) { 48 | dest.writeFloat(temperature); 49 | } 50 | 51 | public static boolean isUuid(UUID uuid) { 52 | return MY_UUID.equals(uuid); 53 | } 54 | 55 | public static TokencubeTemperature fromCharacteristic(BluetoothGattCharacteristic characteristic) { 56 | byte[] byteValue = characteristic.getValue(); 57 | Log.i("BLE", "ByteValue: " + BleUtils.convertBinToASCII(byteValue)); 58 | Integer value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT16, 0); 59 | Log.i("BLE", "Value: " + value); 60 | if (value != null) { 61 | float temp = (float)(FACTOR * value.intValue()); 62 | return new TokencubeTemperature(temp); 63 | } 64 | else 65 | throw new RuntimeException("getIntValue retured null"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/sensors/generic/TxPowerLevel.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.sensors.generic; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.UUID; 6 | 7 | import android.bluetooth.BluetoothGattCharacteristic; 8 | 9 | public class TxPowerLevel { 10 | 11 | private static final UUID MY_UUID = UUID.fromString("00002a07-0000-1000-8000-00805f9b34fb"); 12 | private static final List LEVELS = new ArrayList(); 13 | private BluetoothGattCharacteristic characteristic; 14 | private int level; 15 | 16 | public static class PowerLevel { 17 | 18 | private byte value; 19 | private String label; 20 | 21 | public PowerLevel(int value, String label) { 22 | this.value = (byte)value; 23 | this.label = label; 24 | } 25 | 26 | public byte getValue() { 27 | return value; 28 | } 29 | 30 | public String getLabel() { 31 | return label; 32 | } 33 | } 34 | 35 | static { 36 | LEVELS.add(new PowerLevel(0x04, "4dBm")); 37 | LEVELS.add(new PowerLevel(0x00, "0dBm")); 38 | LEVELS.add(new PowerLevel(0xFC, "-4dBm")); 39 | LEVELS.add(new PowerLevel(0xF8, "-8dBm")); 40 | LEVELS.add(new PowerLevel(0xF4, "-12dBm")); 41 | LEVELS.add(new PowerLevel(0xF0, "-16dBm")); 42 | LEVELS.add(new PowerLevel(0xEC, "-20dBm")); 43 | LEVELS.add(new PowerLevel(0xD8, "-40dBm")); 44 | } 45 | 46 | public TxPowerLevel(BluetoothGattCharacteristic characteristic) { 47 | this.characteristic = characteristic; 48 | } 49 | 50 | private TxPowerLevel(int level) { 51 | this.level = level; 52 | } 53 | 54 | public void setLevel(int level) { 55 | this.level = level; 56 | characteristic.setValue(level, BluetoothGattCharacteristic.FORMAT_SINT8, 0); 57 | } 58 | 59 | public int getLevel() { 60 | return level; 61 | } 62 | 63 | public static boolean isUuid(UUID uuid) { 64 | return MY_UUID.equals(uuid); 65 | } 66 | 67 | public static TxPowerLevel fromCharacteristic(BluetoothGattCharacteristic characteristic) { 68 | Integer value = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT8, 0); 69 | if (value != null) { 70 | return new TxPowerLevel(value.intValue()); 71 | } 72 | else 73 | throw new RuntimeException("getIntValue retured null"); 74 | } 75 | 76 | public static List getLevels() { 77 | return LEVELS; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/de/grundid/ble/fingerprint/SensorMatcherTest.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.fingerprint; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.UUID; 8 | 9 | import org.junit.Test; 10 | 11 | public class SensorMatcherTest { 12 | 13 | private static final String DEFAULT_UUID_SUFFIX = "-0000-1000-8000-00805f9b34fb"; 14 | 15 | @Test(expected = UnknownSensorException.class) 16 | public void itShouldThrowExceptionIfNoMatch() throws Exception { 17 | SensorMatcher matcher = new SensorMatcher(new ArrayList()); 18 | matcher.identifySensor(new Sensor("unknown")); 19 | } 20 | 21 | @Test 22 | public void itShouldMatchSensor() throws Exception { 23 | List sensors = new ArrayList(); 24 | sensors.add(appendService(new Sensor("s1"), "00001800", "00002a00")); 25 | SensorMatcher matcher = new SensorMatcher(sensors); 26 | Sensor sensorToMatch = new Sensor(null); 27 | appendService(sensorToMatch, "00001800", "00002a00"); 28 | String name = matcher.identifySensor(sensorToMatch); 29 | assertEquals("s1", name); 30 | } 31 | 32 | @Test 33 | public void itShouldMatchSingleSensor() throws Exception { 34 | SensorMatcher matcher = new SensorMatcher(null); 35 | Sensor sensor = new Sensor("s1"); 36 | appendService(sensor, "00001800", "00002a00"); 37 | Sensor sensorToMatch = new Sensor(null); 38 | appendService(sensorToMatch, "00001800", "00002a00"); 39 | assertTrue(matcher.matchesSensor(sensor, sensorToMatch)); 40 | } 41 | 42 | @Test 43 | public void itShouldMatchSensorWithMoreServices() throws Exception { 44 | SensorMatcher matcher = new SensorMatcher(null); 45 | Sensor sensor = new Sensor("s1"); 46 | appendService(sensor, "00001800", "00002a00"); 47 | Sensor sensorToMatch = new Sensor(null); 48 | appendService(sensorToMatch, "00001800", "00002a00"); 49 | appendService(sensorToMatch, "0000180a", "00002a29"); 50 | assertTrue(matcher.matchesSensor(sensor, sensorToMatch)); 51 | } 52 | 53 | private static Sensor appendService(Sensor sensor, String serviceUuid, String... charUuids) { 54 | UUID uuid = UUID.fromString(serviceUuid + DEFAULT_UUID_SUFFIX); 55 | sensor.addService(uuid); 56 | for (String charUuid : charUuids) { 57 | sensor.addCharacteristic(uuid, UUID.fromString(charUuid + DEFAULT_UUID_SUFFIX)); 58 | } 59 | return sensor; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/resources/sensors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/fingerprint/SensorParser.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.fingerprint; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map.Entry; 6 | import java.util.Set; 7 | import java.util.UUID; 8 | 9 | import org.xmlpull.v1.XmlPullParser; 10 | 11 | public class SensorParser { 12 | 13 | private XmlPullParser xmlParser; 14 | 15 | public SensorParser(XmlPullParser xmlParser) { 16 | this.xmlParser = xmlParser; 17 | } 18 | 19 | private String getAttribute(String name) { 20 | return xmlParser.getAttributeValue(null, name); 21 | } 22 | 23 | public static String toXml(Sensor sensor) { 24 | StringBuilder sb = new StringBuilder(); 25 | sb.append(""); 26 | for (Entry> entry : sensor.getServices()) { 27 | sb.append(""); 28 | for (UUID characteristic : entry.getValue()) { 29 | sb.append(""); 30 | } 31 | sb.append(""); 32 | } 33 | sb.append(""); 34 | return sb.toString(); 35 | } 36 | 37 | public List parseSensors() { 38 | try { 39 | List result = new ArrayList(); 40 | int eventType = xmlParser.getEventType(); 41 | while (eventType != XmlPullParser.END_DOCUMENT) { 42 | if (eventType == XmlPullParser.START_TAG) { 43 | if ("sensors".equals(xmlParser.getName())) { 44 | processSensors(result); 45 | } 46 | } 47 | eventType = xmlParser.next(); 48 | } 49 | return result; 50 | } 51 | catch (Exception e) { 52 | throw new RuntimeException(e); 53 | } 54 | } 55 | 56 | private void processSensors(List result) throws Exception { 57 | int eventType = 0; 58 | do { 59 | eventType = xmlParser.next(); 60 | if (eventType == XmlPullParser.START_TAG) { 61 | if ("sensor".equals(xmlParser.getName())) { 62 | result.add(processSensor()); 63 | } 64 | } 65 | } while (eventType != XmlPullParser.END_TAG); 66 | } 67 | 68 | private Sensor processSensor() throws Exception { 69 | Sensor sensor = new Sensor(getAttribute("name")); 70 | int eventType = 0; 71 | do { 72 | eventType = xmlParser.next(); 73 | if (eventType == XmlPullParser.START_TAG) { 74 | if ("service".equals(xmlParser.getName())) { 75 | processService(sensor); 76 | } 77 | } 78 | } while (eventType != XmlPullParser.END_TAG); 79 | return sensor; 80 | } 81 | 82 | private void processService(Sensor sensor) throws Exception { 83 | UUID serviceUuid = UUID.fromString(getAttribute("uuid")); 84 | sensor.addService(serviceUuid); 85 | int eventType = 0; 86 | do { 87 | eventType = xmlParser.next(); 88 | if (eventType == XmlPullParser.START_TAG) { 89 | if ("characteristic".equals(xmlParser.getName())) { 90 | sensor.addCharacteristic(serviceUuid, processCharacteristic()); 91 | } 92 | } 93 | } while (eventType != XmlPullParser.END_TAG); 94 | } 95 | 96 | private UUID processCharacteristic() throws Exception { 97 | UUID uuid = UUID.fromString(getAttribute("uuid")); 98 | int eventType = 0; 99 | do { 100 | eventType = xmlParser.next(); 101 | } while (eventType != XmlPullParser.END_TAG); 102 | return uuid; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/de/grundid/ble/gatt/GattDb.java: -------------------------------------------------------------------------------- 1 | package de.grundid.ble.gatt; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class GattDb { 7 | 8 | // FIXME convert all UUIDs to lower case 9 | private static List gattServices = new ArrayList(); 10 | private static List gattCharacteristics = new ArrayList(); 11 | static { 12 | gattCharacteristics.add(new GattCharacteristic("Alert Category ID", 13 | "org.bluetooth.characteristic.alert_category_id", "00002A43-0000-1000-8000-00805f9b34fb")); 14 | gattCharacteristics.add(new GattCharacteristic("Alert Category ID Bit Mask", 15 | "org.bluetooth.characteristic.alert_category_id_bit_mask", "00002A42-0000-1000-8000-00805f9b34fb")); 16 | gattCharacteristics.add(new GattCharacteristic("Alert Level", "org.bluetooth.characteristic.alert_level", 17 | "00002A06-0000-1000-8000-00805f9b34fb")); 18 | gattCharacteristics 19 | .add(new GattCharacteristic("Alert Notification Control Point", 20 | "org.bluetooth.characteristic.alert_notification_control_point", 21 | "00002A44-0000-1000-8000-00805f9b34fb")); 22 | gattCharacteristics.add(new GattCharacteristic("Alert Status", "org.bluetooth.characteristic.alert_status", 23 | "00002A3F-0000-1000-8000-00805f9b34fb")); 24 | gattCharacteristics.add(new GattCharacteristic("Appearance", "org.bluetooth.characteristic.gap.appearance", 25 | "00002A01-0000-1000-8000-00805f9b34fb")); 26 | gattCharacteristics.add(new GattCharacteristic("Battery Level", "org.bluetooth.characteristic.battery_level", 27 | "00002A19-0000-1000-8000-00805f9b34fb")); 28 | gattCharacteristics.add(new GattCharacteristic("Blood Pressure Feature", 29 | "org.bluetooth.characteristic.blood_pressure_feature", "00002A49-0000-1000-8000-00805f9b34fb")); 30 | gattCharacteristics.add(new GattCharacteristic("Blood Pressure Measurement", 31 | "org.bluetooth.characteristic.blood_pressure_measurement", "00002A35-0000-1000-8000-00805f9b34fb")); 32 | gattCharacteristics.add(new GattCharacteristic("Body Sensor Location", 33 | "org.bluetooth.characteristic.body_sensor_location", "00002A38-0000-1000-8000-00805f9b34fb")); 34 | gattCharacteristics.add(new GattCharacteristic("Boot Keyboard Input Report", 35 | "org.bluetooth.characteristic.boot_keyboard_input_report", "00002A22-0000-1000-8000-00805f9b34fb")); 36 | gattCharacteristics.add(new GattCharacteristic("Boot Keyboard Output Report", 37 | "org.bluetooth.characteristic.boot_keyboard_output_report", "00002A32-0000-1000-8000-00805f9b34fb")); 38 | gattCharacteristics.add(new GattCharacteristic("Boot Mouse Input Report", 39 | "org.bluetooth.characteristic.boot_mouse_input_report", "00002A33-0000-1000-8000-00805f9b34fb")); 40 | gattCharacteristics.add(new GattCharacteristic("CSC Feature", "org.bluetooth.characteristic.csc_feature", 41 | "00002A5C-0000-1000-8000-00805f9b34fb")); 42 | gattCharacteristics.add(new GattCharacteristic("CSC Measurement", 43 | "org.bluetooth.characteristic.csc_measurement", "00002A5B-0000-1000-8000-00805f9b34fb")); 44 | gattCharacteristics.add(new GattCharacteristic("Current Time", "org.bluetooth.characteristic.current_time", 45 | "00002A2B-0000-1000-8000-00805f9b34fb")); 46 | gattCharacteristics.add(new GattCharacteristic("Cycling Power Control Point", 47 | "bluetooth.characteristic.cycling_power_control_point", "00002A66-0000-1000-8000-00805f9b34fb")); 48 | gattCharacteristics.add(new GattCharacteristic("Cycling Power Feature", 49 | "org.bluteooth.characteristic.cycling_power_feature", "00002A65-0000-1000-8000-00805f9b34fb")); 50 | gattCharacteristics.add(new GattCharacteristic("Cycling Power Measurement", 51 | "org.blueeooth.cycling_power_measurement", "00002A63-0000-1000-8000-00805f9b34fb")); 52 | gattCharacteristics.add(new GattCharacteristic("Cycling Power Vector", 53 | "org.bluetooth.characteristic.cycling_power_vector", "00002A64-0000-1000-8000-00805f9b34fb")); 54 | gattCharacteristics.add(new GattCharacteristic("Date Time", "org.bluetooth.characteristic.date_time", 55 | "00002A08-0000-1000-8000-00805f9b34fb")); 56 | gattCharacteristics.add(new GattCharacteristic("Day Date Time", "org.bluetooth.characteristic.day_date_time", 57 | "00002A0A-0000-1000-8000-00805f9b34fb")); 58 | gattCharacteristics.add(new GattCharacteristic("Day of Week", "org.bluetooth.characteristic.day_of_week", 59 | "00002A09-0000-1000-8000-00805f9b34fb")); 60 | gattCharacteristics.add(new GattCharacteristic("Device Name", "org.bluetooth.characteristic.gap.device_name", 61 | "00002A00-0000-1000-8000-00805f9b34fb")); 62 | gattCharacteristics.add(new GattCharacteristic("DST Offset", "org.bluetooth.characteristic.dst_offset", 63 | "00002A0D-0000-1000-8000-00805f9b34fb")); 64 | gattCharacteristics.add(new GattCharacteristic("Exact Time 256", "org.bluetooth.characteristic.exact_time_256", 65 | "00002A0C-0000-1000-8000-00805f9b34fb")); 66 | gattCharacteristics.add(new GattCharacteristic("Firmware Revision String", 67 | "org.bluetooth.characteristic.firmware_revision_string", "00002A26-0000-1000-8000-00805f9b34fb")); 68 | gattCharacteristics.add(new GattCharacteristic("Glucose Feature", 69 | "org.bluetooth.characteristic.glucose_feature", "00002A51-0000-1000-8000-00805f9b34fb")); 70 | gattCharacteristics.add(new GattCharacteristic("Glucose Measurement", 71 | "org.bluetooth.characteristic.glucose_measurement", "00002A18-0000-1000-8000-00805f9b34fb")); 72 | gattCharacteristics.add(new GattCharacteristic("Glucose Measurement Context", 73 | "org.bluetooth.characteristic.glucose_measurement_context", "00002A34-0000-1000-8000-00805f9b34fb")); 74 | gattCharacteristics.add(new GattCharacteristic("Hardware Revision String", 75 | "org.bluetooth.characteristic.hardware_revision_string", "00002A27-0000-1000-8000-00805f9b34fb")); 76 | gattCharacteristics.add(new GattCharacteristic("Heart Rate Control Point", 77 | "org.bluetooth.characteristic.heart_rate_control_point", "00002A39-0000-1000-8000-00805f9b34fb")); 78 | gattCharacteristics.add(new GattCharacteristic("Heart Rate Measurement", 79 | "org.bluetooth.characteristic.heart_rate_measurement", "00002A37-0000-1000-8000-00805f9b34fb")); 80 | gattCharacteristics.add(new GattCharacteristic("HID Control Point", 81 | "org.bluetooth.characteristic.hid_control_point", "00002A4C-0000-1000-8000-00805f9b34fb")); 82 | gattCharacteristics.add(new GattCharacteristic("HID Information", 83 | "org.bluetooth.characteristic.hid_information", "00002A4A-0000-1000-8000-00805f9b34fb")); 84 | gattCharacteristics.add(new GattCharacteristic("IEEE 11073-20601 Regulatory Certification Data List", 85 | "org.bluetooth.characteristic.ieee_11073-20601_regulatory_certification_data_list", 86 | "00002A2A-0000-1000-8000-00805f9b34fb")); 87 | gattCharacteristics.add(new GattCharacteristic("Intermediate Cuff Pressure", 88 | "org.bluetooth.characteristic.intermediate_blood_pressure", "00002A36-0000-1000-8000-00805f9b34fb")); 89 | gattCharacteristics.add(new GattCharacteristic("Intermediate Temperature", 90 | "org.bluetooth.characteristic.intermediate_temperature", "00002A1E-0000-1000-8000-00805f9b34fb")); 91 | gattCharacteristics.add(new GattCharacteristic("LN Control Point", "org.bluetooth.ln_control_point", 92 | "00002A6B-0000-1000-8000-00805f9b34fb")); 93 | gattCharacteristics.add(new GattCharacteristic("LN Feature", "org.bluetooth.characteristic.ln_feature", 94 | "00002A6A-0000-1000-8000-00805f9b34fb")); 95 | gattCharacteristics.add(new GattCharacteristic("Local Time Information", 96 | "org.bluetooth.characteristic.local_time_information", "00002A0F-0000-1000-8000-00805f9b34fb")); 97 | gattCharacteristics.add(new GattCharacteristic("Location and Speed", "org.bluetooth.location_and_speed", 98 | "00002A67-0000-1000-8000-00805f9b34fb")); 99 | gattCharacteristics.add(new GattCharacteristic("Manufacturer Name String", 100 | "org.bluetooth.characteristic.manufacturer_name_string", "00002A29-0000-1000-8000-00805f9b34fb")); 101 | gattCharacteristics.add(new GattCharacteristic("Measurement Interval", 102 | "org.bluetooth.characteristic.measurement_interval", "00002A21-0000-1000-8000-00805f9b34fb")); 103 | gattCharacteristics.add(new GattCharacteristic("Model Number String", 104 | "org.bluetooth.characteristic.model_number_string", "00002A24-0000-1000-8000-00805f9b34fb")); 105 | gattCharacteristics.add(new GattCharacteristic("Navigation", "org.bluetooth.characteristic.navigation", 106 | "00002A68-0000-1000-8000-00805f9b34fb")); 107 | gattCharacteristics.add(new GattCharacteristic("New Alert", "org.bluetooth.characteristic.new_alert", 108 | "00002A46-0000-1000-8000-00805f9b34fb")); 109 | gattCharacteristics.add(new GattCharacteristic("Peripheral Preferred Connection Parameters", 110 | "org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters", 111 | "00002A04-0000-1000-8000-00805f9b34fb")); 112 | gattCharacteristics.add(new GattCharacteristic("Peripheral Privacy Flag", 113 | "org.bluetooth.characteristic.gap.peripheral_privacy_flag", "00002A02-0000-1000-8000-00805f9b34fb")); 114 | gattCharacteristics.add(new GattCharacteristic("PnP ID", "org.bluetooth.characteristic.pnp_id", 115 | "00002A50-0000-1000-8000-00805f9b34fb")); 116 | gattCharacteristics.add(new GattCharacteristic("Position Quality", "org.bluetooth.position_quality", 117 | "00002A69-0000-1000-8000-00805f9b34fb")); 118 | gattCharacteristics.add(new GattCharacteristic("Protocol Mode", "org.bluetooth.characteristic.protocol_mode", 119 | "00002A4E-0000-1000-8000-00805f9b34fb")); 120 | gattCharacteristics.add(new GattCharacteristic("Reconnection Address", 121 | "org.bluetooth.characteristic.gap.reconnection_address", "00002A03-0000-1000-8000-00805f9b34fb")); 122 | gattCharacteristics.add(new GattCharacteristic("Record Access Control Point", 123 | "org.bluetooth.characteristic.record_access_control_point", "00002A52-0000-1000-8000-00805f9b34fb")); 124 | gattCharacteristics.add(new GattCharacteristic("Reference Time Information", 125 | "org.bluetooth.characteristic.reference_time_information", "00002A14-0000-1000-8000-00805f9b34fb")); 126 | gattCharacteristics.add(new GattCharacteristic("Report", "org.bluetooth.characteristic.report", 127 | "00002A4D-0000-1000-8000-00805f9b34fb")); 128 | gattCharacteristics.add(new GattCharacteristic("Report Map", "org.bluetooth.characteristic.report_map", 129 | "00002A4B-0000-1000-8000-00805f9b34fb")); 130 | gattCharacteristics.add(new GattCharacteristic("Ringer Control Point", 131 | "org.bluetooth.characteristic.ringer_control_point", "00002A40-0000-1000-8000-00805f9b34fb")); 132 | gattCharacteristics.add(new GattCharacteristic("Ringer Setting", "org.bluetooth.characteristic.ringer_setting", 133 | "00002A41-0000-1000-8000-00805f9b34fb")); 134 | gattCharacteristics.add(new GattCharacteristic("RSC Feature", "org.bluetooth.characteristic.rsc_feature", 135 | "00002A54-0000-1000-8000-00805f9b34fb")); 136 | gattCharacteristics.add(new GattCharacteristic("RSC Measurement", 137 | "org.bluetooth.characteristic.rsc_measurement", "00002A53-0000-1000-8000-00805f9b34fb")); 138 | gattCharacteristics.add(new GattCharacteristic("SC Control Point", 139 | "org.bluetooth.characteristic.sc_control_point", "00002A55-0000-1000-8000-00805f9b34fb")); 140 | gattCharacteristics.add(new GattCharacteristic("Scan Interval Window", 141 | "org.bluetooth.characteristic.scan_interval_window", "00002A4F-0000-1000-8000-00805f9b34fb")); 142 | gattCharacteristics.add(new GattCharacteristic("Scan Refresh", "org.bluetooth.characteristic.scan_refresh", 143 | "00002A31-0000-1000-8000-00805f9b34fb")); 144 | gattCharacteristics.add(new GattCharacteristic("Sensor Location", 145 | "org.bluetooth.characteristic.sensor_location", "00002A5D-0000-1000-8000-00805f9b34fb")); 146 | gattCharacteristics.add(new GattCharacteristic("Serial Number String", 147 | "org.bluetooth.characteristic.serial_number_string", "00002A25-0000-1000-8000-00805f9b34fb")); 148 | gattCharacteristics.add(new GattCharacteristic("Service Changed", 149 | "org.bluetooth.characteristic.gatt.service_changed", "00002A05-0000-1000-8000-00805f9b34fb")); 150 | gattCharacteristics.add(new GattCharacteristic("Software Revision String", 151 | "org.bluetooth.characteristic.software_revision_string", "00002A28-0000-1000-8000-00805f9b34fb")); 152 | gattCharacteristics.add(new GattCharacteristic("Supported New Alert Category", 153 | "org.bluetooth.characteristic.supported_new_alert_category", "00002A47-0000-1000-8000-00805f9b34fb")); 154 | gattCharacteristics 155 | .add(new GattCharacteristic("Supported Unread Alert Category", 156 | "org.bluetooth.characteristic.supported_unread_alert_category", 157 | "00002A48-0000-1000-8000-00805f9b34fb")); 158 | gattCharacteristics.add(new GattCharacteristic("System ID", "org.bluetooth.characteristic.system_id", 159 | "00002A23-0000-1000-8000-00805f9b34fb")); 160 | gattCharacteristics.add(new GattCharacteristic("Temperature Measurement", 161 | "org.bluetooth.characteristic.temperature_measurement", "00002A1C-0000-1000-8000-00805f9b34fb")); 162 | gattCharacteristics.add(new GattCharacteristic("Temperature Type", 163 | "org.bluetooth.characteristic.temperature_type", "00002A1D-0000-1000-8000-00805f9b34fb")); 164 | gattCharacteristics.add(new GattCharacteristic("Time Accuracy", "org.bluetooth.characteristic.time_accuracy", 165 | "00002A12-0000-1000-8000-00805f9b34fb")); 166 | gattCharacteristics.add(new GattCharacteristic("Time Source", "org.bluetooth.characteristic.time_source", 167 | "00002A13-0000-1000-8000-00805f9b34fb")); 168 | gattCharacteristics.add(new GattCharacteristic("Time Update Control Point", 169 | "org.bluetooth.characteristic.time_update_control_point", "00002A16-0000-1000-8000-00805f9b34fb")); 170 | gattCharacteristics.add(new GattCharacteristic("Time Update State", 171 | "org.bluetooth.characteristic.time_update_state", "00002A17-0000-1000-8000-00805f9b34fb")); 172 | gattCharacteristics.add(new GattCharacteristic("Time with DST", "org.bluetooth.characteristic.time_with_dst", 173 | "00002A11-0000-1000-8000-00805f9b34fb")); 174 | gattCharacteristics.add(new GattCharacteristic("Time Zone", "org.bluetooth.characteristic.time_zone", 175 | "00002A0E-0000-1000-8000-00805f9b34fb")); 176 | gattCharacteristics.add(new GattCharacteristic("Tx Power Level", "org.bluetooth.characteristic.tx_power_level", 177 | "00002A07-0000-1000-8000-00805f9b34fb")); 178 | gattCharacteristics.add(new GattCharacteristic("Unread Alert Status", 179 | "org.bluetooth.characteristic.unread_alert_status", "00002A45-0000-1000-8000-00805f9b34fb")); 180 | gattCharacteristics.add(new GattCharacteristic("Advertising Interval", "", 181 | "00002b30-0000-1000-8000-00805f9b34fb")); 182 | gattCharacteristics.add(new GattCharacteristic("Acceleration/Orientation", "", 183 | "00002b20-0000-1000-8000-00805f9b34fb")); 184 | gattCharacteristics.add(new GattCharacteristic("Temperature", "", "00002b10-0000-1000-8000-00805f9b34fb")); 185 | gattServices.add(new GattService("Alert Notification Service", "org.bluetooth.service.alert_notification", 186 | "00001811-0000-1000-8000-00805f9b34fb")); 187 | gattServices.add(new GattService("Battery Service", "org.bluetooth.service.battery_service", 188 | "0000180F-0000-1000-8000-00805f9b34fb")); 189 | gattServices.add(new GattService("Blood Pressure", "org.bluetooth.service.blood_pressure", 190 | "00001810-0000-1000-8000-00805f9b34fb")); 191 | gattServices.add(new GattService("Current Time Service", "org.bluetooth.service.current_time", 192 | "00001805-0000-1000-8000-00805f9b34fb")); 193 | gattServices.add(new GattService("Cycling Power", "org.bluetooth.service.cycling_power", 194 | "00001818-0000-1000-8000-00805f9b34fb")); 195 | gattServices.add(new GattService("Cycling Speed and Cadence", 196 | "org.bluetooth.service.cycling_speed_and_cadence", "00001816-0000-1000-8000-00805f9b34fb")); 197 | gattServices.add(new GattService("Device Information", "org.bluetooth.service.device_information", 198 | "0000180A-0000-1000-8000-00805f9b34fb")); 199 | gattServices.add(new GattService("Generic Access", "org.bluetooth.service.generic_access", 200 | "00001800-0000-1000-8000-00805f9b34fb")); 201 | gattServices.add(new GattService("Generic Attribute", "org.bluetooth.service.generic_attribute", 202 | "00001801-0000-1000-8000-00805f9b34fb")); 203 | gattServices.add(new GattService("Glucose", "org.bluetooth.service.glucose", 204 | "00001808-0000-1000-8000-00805f9b34fb")); 205 | gattServices.add(new GattService("Health Thermometer", "org.bluetooth.service.health_thermometer", 206 | "00001809-0000-1000-8000-00805f9b34fb")); 207 | gattServices.add(new GattService("Heart Rate", "org.bluetooth.service.heart_rate", 208 | "0000180D-0000-1000-8000-00805f9b34fb")); 209 | gattServices.add(new GattService("Human Interface Device", "org.bluetooth.service.human_interface_device", 210 | "00001812-0000-1000-8000-00805f9b34fb")); 211 | gattServices.add(new GattService("Immediate Alert", "org.bluetooth.service.immediate_alert", 212 | "00001802-0000-1000-8000-00805f9b34fb")); 213 | gattServices.add(new GattService("Link Loss", "org.bluetooth.service.link_loss", 214 | "00001803-0000-1000-8000-00805f9b34fb")); 215 | gattServices.add(new GattService("Location and Navigation", "org.bluetooth.service.location_and_navigation", 216 | "00001819-0000-1000-8000-00805f9b34fb")); 217 | gattServices.add(new GattService("Next DST Change Service", "org.bluetooth.service.next_dst_change", 218 | "00001807-0000-1000-8000-00805f9b34fb")); 219 | gattServices.add(new GattService("Phone Alert Status Service", "org.bluetooth.service.phone_alert_status", 220 | "0000180E-0000-1000-8000-00805f9b34fb")); 221 | gattServices.add(new GattService("Reference Time Update Service", 222 | "org.bluetooth.service.reference_time_update", "00001806-0000-1000-8000-00805f9b34fb")); 223 | gattServices.add(new GattService("Running Speed and Cadence", 224 | "org.bluetooth.service.running_speed_and_cadence", "00001814-0000-1000-8000-00805f9b34fb")); 225 | gattServices.add(new GattService("Scan Parameters", "org.bluetooth.service.scan_parameters", 226 | "00001813-0000-1000-8000-00805f9b34fb")); 227 | gattServices.add(new GattService("Tx Power", "org.bluetooth.service.tx_power", 228 | "00001804-0000-1000-8000-00805f9b34fb")); 229 | gattServices.add(new GattService("Advertising Interval Service", "", "00001930-0000-1000-8000-00805f9b34fb")); 230 | gattServices.add(new GattService("Temperature Service", "", "00001910-0000-1000-8000-00805f9b34fb")); 231 | gattServices 232 | .add(new GattService("Acceleration/Orientation Service", "", "00001920-0000-1000-8000-00805f9b34fb")); 233 | } 234 | 235 | public static List getGattServices() { 236 | return gattServices; 237 | } 238 | 239 | public static List getGattCharacteristics() { 240 | return gattCharacteristics; 241 | } 242 | } 243 | --------------------------------------------------------------------------------