From 566f0311b9caa977e99a9f0b6fa8f7eb111e6bda Mon Sep 17 00:00:00 2001 From: Louis-Guillaume DUBOIS Date: Thu, 1 Jun 2017 12:40:25 +0200 Subject: [PATCH] Petites modifications --- .idea/misc.xml | 2 +- .../bluetoothlegatt/BluetoothLeService.java | 8 +++++++ .../bluetoothlegatt/SampleGattAttributes.java | 23 ++++++++++++++----- .../src/main/res/values/base-strings.xml | 3 ++- TODO.md | 9 ++++++++ 5 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 TODO.md diff --git a/.idea/misc.xml b/.idea/misc.xml index 44bc9b2..3d21ecd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/Application/src/main/java/com/example/android/bluetoothlegatt/BluetoothLeService.java b/Application/src/main/java/com/example/android/bluetoothlegatt/BluetoothLeService.java index 694faaf..54e77e9 100644 --- a/Application/src/main/java/com/example/android/bluetoothlegatt/BluetoothLeService.java +++ b/Application/src/main/java/com/example/android/bluetoothlegatt/BluetoothLeService.java @@ -63,8 +63,10 @@ public class BluetoothLeService extends Service { public final static String EXTRA_DATA = "com.example.bluetooth.le.EXTRA_DATA"; + /* TODO public final static UUID UUID_HEART_RATE_MEASUREMENT = UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT); + */ // Implements callback methods for GATT events that the app cares about. For example, // connection change and services discovered. @@ -123,6 +125,7 @@ public class BluetoothLeService extends Service { final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); + /* TODO // This is special handling for the Heart Rate Measurement profile. Data parsing is // carried out as per profile specifications: // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml @@ -140,6 +143,7 @@ public class BluetoothLeService extends Service { Log.d(TAG, String.format("Received heart rate: %d", heartRate)); intent.putExtra(EXTRA_DATA, String.valueOf(heartRate)); } else { + */ // For all other profiles, writes the data formatted in HEX. final byte[] data = characteristic.getValue(); if (data != null && data.length > 0) { @@ -148,7 +152,9 @@ public class BluetoothLeService extends Service { stringBuilder.append(String.format("%02X ", byteChar)); intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString()); } + /* TODO } + */ sendBroadcast(intent); } @@ -296,6 +302,7 @@ public class BluetoothLeService extends Service { } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); + /* TODO // This is specific to Heart Rate Measurement. if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { BluetoothGattDescriptor descriptor = characteristic.getDescriptor( @@ -303,6 +310,7 @@ public class BluetoothLeService extends Service { descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } + */ } /** diff --git a/Application/src/main/java/com/example/android/bluetoothlegatt/SampleGattAttributes.java b/Application/src/main/java/com/example/android/bluetoothlegatt/SampleGattAttributes.java index e8db74c..b2eb58b 100644 --- a/Application/src/main/java/com/example/android/bluetoothlegatt/SampleGattAttributes.java +++ b/Application/src/main/java/com/example/android/bluetoothlegatt/SampleGattAttributes.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2017 Louis-Guillaume Dubois * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,16 +24,26 @@ import java.util.HashMap; */ public class SampleGattAttributes { private static HashMap attributes = new HashMap(); - public static String HEART_RATE_MEASUREMENT = "00002a37-0000-1000-8000-00805f9b34fb"; - public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb"; static { // Sample Services. - attributes.put("0000180d-0000-1000-8000-00805f9b34fb", "Heart Rate Service"); - attributes.put("0000180a-0000-1000-8000-00805f9b34fb", "Device Information Service"); + attributes.put("0000180a-0000-1000-8000-00805f9b34fb", "Device Information"); + attributes.put("00001801-0000-1000-8000-00805f9b34fb", "Generic Attribute"); + attributes.put("00001800-0000-1000-8000-00805f9b34fb", "Generic Access"); + attributes.put("0000180f-0000-1000-8000-00805f9b34fb", "Battery Service"); + + attributes.put("11223344-5566-7788-9900-aabbccddeeff", "Private Service"); + + // Sample Characteristics. - attributes.put(HEART_RATE_MEASUREMENT, "Heart Rate Measurement"); - attributes.put("00002a29-0000-1000-8000-00805f9b34fb", "Manufacturer Name String"); + attributes.put("00002a19-0000-1000-8000-00805f9b34fb", "Battery Level"); + attributes.put("00002a00-0000-1000-8000-00805f9b34fb", "Device Name"); + attributes.put("00002a01-0000-1000-8000-00805f9b34fb", "Appearance"); + attributes.put("00002a04-0000-1000-8000-00805f9b34fb", "Peripheral Preferred Connection Parameters"); + attributes.put("00002a29-0000-1000-8000-00805f9b34fb", "Manufacturer Name"); + + attributes.put("01020304-0506-0708-0900-0a0b0c0d0e0f", "5-byte r char."); + attributes.put("ff020304-0506-0708-0900-0a0b0c0d0e0f", "3-byte rw notif. char."); } public static String lookup(String uuid, String defaultName) { diff --git a/Application/src/main/res/values/base-strings.xml b/Application/src/main/res/values/base-strings.xml index 8b742b7..62b5ed0 100644 --- a/Application/src/main/res/values/base-strings.xml +++ b/Application/src/main/res/values/base-strings.xml @@ -1,6 +1,7 @@ - BluetoothLeGatt + Client BLE