Java Code Examples for android.bluetooth.BluetoothGattCharacteristic#getStringValue()
The following examples show how to use
android.bluetooth.BluetoothGattCharacteristic#getStringValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DfuBaseService.java From microbit with Apache License 2.0 | 6 votes |
private String readCharacteristicNoFailure(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) { if (mConnectionState != STATE_CONNECTED_AND_READY) return "not_ready"; if (characteristic == null) return "unknown"; logi("readCharacteristicNoFailure"); gatt.readCharacteristic(characteristic); try { synchronized (mLock) { while ((!mRequestCompleted && mConnectionState == STATE_CONNECTED_AND_READY && mError == 0 && !mAborted) || mPaused) mLock.wait(); } } catch (final InterruptedException e) { loge("Sleeping interrupted", e); } if (mAborted) return "unknown"; if (mError != 0) return "unknown"; if (mConnectionState != STATE_CONNECTED_AND_READY) return "unknown"; return characteristic.getStringValue(0); }
Example 2
Source File: BleService.java From bleTester with Apache License 2.0 | 6 votes |
@SuppressLint("NewApi") private void broadcastUpdate(String action, BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(); intent.setAction(action); final byte[] data = characteristic.getValue(); final String stringData = characteristic.getStringValue(0); if (data != null && data.length > 0) { final StringBuilder stringBuilder = new StringBuilder(data.length); for (byte byteChar : data) { stringBuilder.append(String.format("%X", byteChar)); } if (stringData != null) { intent.putExtra(EXTRA_STRING_DATA, stringData); } else { Log.v("tag", "characteristic.getStringValue is null"); } notify_result = stringBuilder.toString(); notify_string_result = stringData; notify_result_length = data.length; intent.putExtra(EXTRA_DATA, notify_result); intent.putExtra(EXTRA_DATA_LENGTH, notify_result_length); } sendBroadcast(intent); }
Example 3
Source File: BluetoothLEGatt.java From EFRConnect-android with Apache License 2.0 | 5 votes |
private static Object getCharacteristicsValue(BluetoothGattCharacteristic gattCharacteristic) { if (gattCharacteristic.getValue() == null) { return null; } GattCharacteristic characteristic = GATT_CHARACTER_DESCS.get(getIdentification(gattCharacteristic.getUuid())); if (characteristic == null) { return gattCharacteristic.getValue(); } final int format = characteristic.format; switch (format) { case BluetoothGattCharacteristic.FORMAT_UINT8: case BluetoothGattCharacteristic.FORMAT_UINT16: case BluetoothGattCharacteristic.FORMAT_UINT32: case BluetoothGattCharacteristic.FORMAT_SINT8: case BluetoothGattCharacteristic.FORMAT_SINT16: case BluetoothGattCharacteristic.FORMAT_SINT32: return gattCharacteristic.getIntValue(format, 0); case BluetoothGattCharacteristic.FORMAT_FLOAT: case BluetoothGattCharacteristic.FORMAT_SFLOAT: return gattCharacteristic.getFloatValue(format, 0); case 0: final String value = gattCharacteristic.getStringValue(0); final int firstNullCharPos = value.indexOf('\u0000'); return (firstNullCharPos >= 0) ? value.substring(0, firstNullCharPos) : value; default: return characteristic.createValue(gattCharacteristic); } }
Example 4
Source File: FirmwareUpdater.java From Bluefruit_LE_Connect_Android with MIT License | 5 votes |
private String readCharacteristicValueAsString(BluetoothGattCharacteristic characteristic) { String string = ""; // Not null try { string = characteristic.getStringValue(0); } catch (Exception e) { Log.w(TAG, "readCharacteristicValueAsString" + e); } return string; }
Example 5
Source File: DeviceProfile.java From bean-sdk-android with MIT License | 5 votes |
@Override public void onCharacteristicRead(GattClient client, BluetoothGattCharacteristic characteristic) { if (characteristic.getUuid().equals(Constants.UUID_DEVICE_INFO_CHAR_FIRMWARE_VERSION)) { Log.i(TAG, "Read response (FW Version): " + Convert.bytesToHexString(characteristic.getValue())); mFirmwareVersion = characteristic.getStringValue(0); } else if (characteristic.getUuid().equals(Constants.UUID_DEVICE_INFO_CHAR_HARDWARE_VERSION)) { Log.i(TAG, "Read response (HW Version): " + Convert.bytesToHexString(characteristic.getValue())); mHardwareVersion = characteristic.getStringValue(0); } else if (characteristic.getUuid().equals(Constants.UUID_DEVICE_INFO_CHAR_SOFTWARE_VERSION)) { Log.i(TAG, "Read response (SW Version): " + Convert.bytesToHexString(characteristic.getValue())); mSoftwareVersion = characteristic.getStringValue(0); } if (mFirmwareVersion != null && mSoftwareVersion != null && mHardwareVersion != null && deviceInfoCallback != null) { DeviceInfo info = DeviceInfo.create(mHardwareVersion, mSoftwareVersion, mFirmwareVersion); deviceInfoCallback.onDeviceInfo(info); deviceInfoCallback = null; } if (mFirmwareVersion != null && firmwareVersionCallback != null) { firmwareVersionCallback.onComplete(mFirmwareVersion); firmwareVersionCallback = null; } if (mHardwareVersion != null && hardwareVersionCallback != null) { hardwareVersionCallback.onComplete(mHardwareVersion); hardwareVersionCallback = null; } }
Example 6
Source File: TestBeanBLE.java From bean-sdk-android with MIT License | 5 votes |
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { if (characteristic.getUuid().equals(Constants.UUID_DEVICE_INFO_CHAR_HARDWARE_VERSION)) { hardwareVersionString = characteristic.getStringValue(0); readHardwareVersionLatch.countDown(); } } }
Example 7
Source File: InfoService.java From BleSensorTag with MIT License | 4 votes |
@Override protected boolean apply(final BluetoothGattCharacteristic c, final M data) { value = c.getStringValue(0); // always set it to true to notify update return true; }
Example 8
Source File: BleWrapper.java From BLEService with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void getCharacteristicValue(BluetoothGattCharacteristic ch) { if (mBluetoothAdapter == null || mBluetoothGatt == null || ch == null) return; byte[] rawValue = ch.getValue(); String strValue = null; int intValue = 0; // lets read and do real parsing of some characteristic to get meaningful value from it UUID uuid = ch.getUuid(); if(uuid.equals(BleDefinedUUIDs.Characteristic.HEART_RATE_MEASUREMENT)) { // heart rate // follow https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml // first check format used by the device - it is specified in bit 0 and tells us if we should ask for index 1 (and uint8) or index 2 (and uint16) int index = ((rawValue[0] & 0x01) == 1) ? 2 : 1; // also we need to define format int format = (index == 1) ? BluetoothGattCharacteristic.FORMAT_UINT8 : BluetoothGattCharacteristic.FORMAT_UINT16; // now we have everything, get the value intValue = ch.getIntValue(format, index); strValue = intValue + " bpm"; // it is always in bpm units } else if (uuid.equals(BleDefinedUUIDs.Characteristic.HEART_RATE_MEASUREMENT) || // manufacturer name string uuid.equals(BleDefinedUUIDs.Characteristic.MODEL_NUMBER_STRING) || // model number string) uuid.equals(BleDefinedUUIDs.Characteristic.FIRMWARE_REVISION_STRING)) // firmware revision string { // follow https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml etc. // string value are usually simple utf8s string at index 0 strValue = ch.getStringValue(0); } else if(uuid.equals(BleDefinedUUIDs.Characteristic.APPEARANCE)) { // appearance // follow: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml intValue = ((int)rawValue[1]) << 8; intValue += rawValue[0]; strValue = BleNamesResolver.resolveAppearance(intValue); } else if(uuid.equals(BleDefinedUUIDs.Characteristic.BODY_SENSOR_LOCATION)) { // body sensor location // follow: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.body_sensor_location.xml intValue = rawValue[0]; strValue = BleNamesResolver.resolveHeartRateSensorLocation(intValue); } else if(uuid.equals(BleDefinedUUIDs.Characteristic.BATTERY_LEVEL)) { // battery level // follow: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.battery_level.xml intValue = rawValue[0]; strValue = "" + intValue + "% battery level"; } else { // not known type of characteristic, so we need to handle this in "general" way // get first four bytes and transform it to integer intValue = 0; if(rawValue.length > 0) intValue = (int)rawValue[0]; if(rawValue.length > 1) intValue = intValue + ((int)rawValue[1] << 8); if(rawValue.length > 2) intValue = intValue + ((int)rawValue[2] << 8); if(rawValue.length > 3) intValue = intValue + ((int)rawValue[3] << 8); if (rawValue.length > 0) { final StringBuilder stringBuilder = new StringBuilder(rawValue.length); for(byte byteChar : rawValue) { stringBuilder.append(String.format("%c", byteChar)); } strValue = stringBuilder.toString(); } } String timestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS").format(new Date()); mUiCallback.uiNewValueForCharacteristic(mBluetoothGatt, mBluetoothDevice, mBluetoothSelectedService, ch, strValue, intValue, rawValue, timestamp); }
Example 9
Source File: CharacteristicDetailsActivity.java From BLEService with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void getCharacteristicValue(BluetoothGattCharacteristic ch) { byte[] rawValue = ch.getValue(); String strValue = null; int intValue = 0; // lets read and do real parsing of some characteristic to get meaningful value from it UUID uuid = ch.getUuid(); if(uuid.equals(BleDefinedUUIDs.Characteristic.HEART_RATE_MEASUREMENT)) { // heart rate // follow https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml // first check format used by the device - it is specified in bit 0 and tells us if we should ask for index 1 (and uint8) or index 2 (and uint16) int index = ((rawValue[0] & 0x01) == 1) ? 2 : 1; // also we need to define format int format = (index == 1) ? BluetoothGattCharacteristic.FORMAT_UINT8 : BluetoothGattCharacteristic.FORMAT_UINT16; // now we have everything, get the value intValue = ch.getIntValue(format, index); strValue = intValue + " bpm"; // it is always in bpm units } else if (uuid.equals(BleDefinedUUIDs.Characteristic.HEART_RATE_MEASUREMENT) || // manufacturer name string uuid.equals(BleDefinedUUIDs.Characteristic.MODEL_NUMBER_STRING) || // model number string) uuid.equals(BleDefinedUUIDs.Characteristic.FIRMWARE_REVISION_STRING)) // firmware revision string { // follow https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.manufacturer_name_string.xml etc. // string value are usually simple utf8s string at index 0 strValue = ch.getStringValue(0); } else if(uuid.equals(BleDefinedUUIDs.Characteristic.APPEARANCE)) { // appearance // follow: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml intValue = ((int)rawValue[1]) << 8; intValue += rawValue[0]; strValue = BleNamesResolver.resolveAppearance(intValue); } else if(uuid.equals(BleDefinedUUIDs.Characteristic.BODY_SENSOR_LOCATION)) { // body sensor location // follow: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.body_sensor_location.xml intValue = rawValue[0]; strValue = BleNamesResolver.resolveHeartRateSensorLocation(intValue); } else if(uuid.equals(BleDefinedUUIDs.Characteristic.BATTERY_LEVEL)) { // battery level // follow: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.battery_level.xml intValue = rawValue[0]; strValue = "" + intValue + "% battery level"; } else { // not known type of characteristic, so we need to handle this in "general" way // get first four bytes and transform it to integer intValue = 0; if(rawValue.length > 0) intValue = (int)rawValue[0]; if(rawValue.length > 1) intValue = intValue + ((int)rawValue[1] << 8); if(rawValue.length > 2) intValue = intValue + ((int)rawValue[2] << 8); if(rawValue.length > 3) intValue = intValue + ((int)rawValue[3] << 8); if (rawValue.length > 0) { final StringBuilder stringBuilder = new StringBuilder(rawValue.length); for(byte byteChar : rawValue) { try { stringBuilder.append(String.format("%c", byteChar)); } catch (Exception ex) { // swallow illegal characters } } strValue = stringBuilder.toString(); } } String timestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS").format(new Date()); mRawValue = rawValue; mIntValue = intValue; mAsciiValue = getHexString(rawValue); mStrValue = strValue; mLastUpdateTime = timestamp; }
Example 10
Source File: BtBand.java From sony-smartband-open-api with MIT License | 4 votes |
private void handleGADeviceName( BluetoothGattCharacteristic characteristic ) { String name = characteristic.getStringValue( 0 ); for( BtBandListener listener : mListeners ) { listener.onGADeviceName( name ); } }
Example 11
Source File: BtBand.java From sony-smartband-open-api with MIT License | 4 votes |
private void handleAASDeviceData( BluetoothGattCharacteristic characteristic ) { String data = characteristic.getStringValue( 0 ); for( BtBandListener listener : mListeners ) { listener.onAASDeviceData( data ); } }
Example 12
Source File: BtBand.java From sony-smartband-open-api with MIT License | 4 votes |
private void handleAASDeviceProductId( BluetoothGattCharacteristic characteristic ) { String productId = characteristic.getStringValue( 0 ); for( BtBandListener listener : mListeners ) { listener.onAASDeviceProductId( productId ); } }
Example 13
Source File: BtBand.java From sony-smartband-open-api with MIT License | 4 votes |
private void handleDeviceInfoManufacturerName( BluetoothGattCharacteristic characteristic ) { String name = characteristic.getStringValue( 0 ); for( BtBandListener listener : mListeners ) { listener.onManufacturerName( name ); } }
Example 14
Source File: BtBand.java From sony-smartband-open-api with MIT License | 4 votes |
private void handleDeviceInfoHardwareRevision( BluetoothGattCharacteristic characteristic ) { String revision = characteristic.getStringValue( 0 ); for( BtBandListener listener : mListeners ) { listener.onHardwareRevision( revision ); } }
Example 15
Source File: BtBand.java From sony-smartband-open-api with MIT License | 4 votes |
private void handleDeviceInfoSoftwareRevision( BluetoothGattCharacteristic characteristic ) { String revision = characteristic.getStringValue( 0 ); for( BtBandListener listener : mListeners ) { listener.onSoftwareRevision( revision ); } }
Example 16
Source File: BtBand.java From sony-smartband-open-api with MIT License | 4 votes |
private void handleDeviceInfoFirmwareRevision( BluetoothGattCharacteristic characteristic ) { String revision = characteristic.getStringValue( 0 ); for( BtBandListener listener : mListeners ) { listener.onFirmwareRevision( revision ); } }
Example 17
Source File: MainActivity.java From Android-BLE-Terminal with MIT License | 4 votes |
@Override public void onReceive(Context context, BluetoothGattCharacteristic rx) { String msg = rx.getStringValue(0); rindex = rindex + msg.length(); writeLine("> " + rindex + ":" + msg); }
Example 18
Source File: BluetoothGlucoseMeter.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { if (characteristic.getUuid().equals(TIME_CHARACTERISTIC)) { UserError.Log.d(TAG, "Got time characteristic read data"); ct = new CurrentTimeRx(characteristic.getValue()); statusUpdate("Device time: " + ct.toNiceString()); } else if (characteristic.getUuid().equals(DATE_TIME_CHARACTERISTIC)) { UserError.Log.d(TAG, "Got date time characteristic read data"); ct = new CurrentTimeRx(characteristic.getValue()); statusUpdate("Device time: " + ct.toNiceString()); } else if (characteristic.getUuid().equals(MANUFACTURER_NAME)) { mLastManufacturer = characteristic.getStringValue(0); UserError.Log.d(TAG, "Manufacturer Name: " + mLastManufacturer); statusUpdate("Device from: " + mLastManufacturer); await_acks = false; // reset // Roche Aviva Connect uses a DateTime characteristic instead if (mLastManufacturer.startsWith("Roche")) { Bluetooth_CMD.transmute_command(CURRENT_TIME_SERVICE, TIME_CHARACTERISTIC, GLUCOSE_SERVICE, DATE_TIME_CHARACTERISTIC); } // Diamond Mobile Mini DM30b firmware v1.2.4 // v1.2.4 has reversed sequence numbers and first item is last item and no clock access if (mLastManufacturer.startsWith("TaiDoc")) { // no time service! Bluetooth_CMD.delete_command(CURRENT_TIME_SERVICE, TIME_CHARACTERISTIC); ct = new CurrentTimeRx(); // implicitly trust meter time stamps!! beware daylight saving time changes ct.noClockAccess = true; ct.sequenceNotReliable = true; // no glucose context! Bluetooth_CMD.delete_command(GLUCOSE_SERVICE, CONTEXT_CHARACTERISTIC); Bluetooth_CMD.delete_command(GLUCOSE_SERVICE, CONTEXT_CHARACTERISTIC); // only request last reading - diamond mini seems to make sequence 0 be the most recent record Bluetooth_CMD.replace_command(GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, "W", new Bluetooth_CMD("W", GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, RecordsCmdTx.getFirstRecord(), "request newest reading")); } // Caresens Dual if (mLastManufacturer.startsWith("i-SENS")) { Bluetooth_CMD.delete_command(CURRENT_TIME_SERVICE, TIME_CHARACTERISTIC); ct = new CurrentTimeRx(); // implicitly trust meter time stamps!! beware daylight saving time changes ct.noClockAccess = true; Bluetooth_CMD.notify(ISENS_TIME_SERVICE, ISENS_TIME_CHARACTERISTIC, "notify isens clock"); Bluetooth_CMD.write(ISENS_TIME_SERVICE, ISENS_TIME_CHARACTERISTIC, new TimeTx(JoH.tsl()).getByteSequence(), "set isens clock"); Bluetooth_CMD.write(ISENS_TIME_SERVICE, ISENS_TIME_CHARACTERISTIC, new TimeTx(JoH.tsl()).getByteSequence(), "set isens clock"); Bluetooth_CMD.replace_command(GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, "W", new Bluetooth_CMD("W", GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, RecordsCmdTx.getNewerThanSequence(getHighestSequence()), "request reading newer than " + getHighestSequence())); } // LifeScan Verio Flex if (mLastManufacturer.startsWith("LifeScan")) { await_acks = true; Bluetooth_CMD.empty_queue(); // Verio Flex isn't standards compliant Bluetooth_CMD.notify(VERIO_F7A1_SERVICE, VERIO_F7A3_NOTIFICATION, "verio general notification"); Bluetooth_CMD.enable_notification_value(VERIO_F7A1_SERVICE, VERIO_F7A3_NOTIFICATION, "verio general notify value"); Bluetooth_CMD.write(VERIO_F7A1_SERVICE, VERIO_F7A2_WRITE, VerioHelper.getTimeCMD(), "verio ask time"); Bluetooth_CMD.write(VERIO_F7A1_SERVICE, VERIO_F7A2_WRITE, VerioHelper.getTcounterCMD(), "verio T data query"); // don't change order with R Bluetooth_CMD.write(VERIO_F7A1_SERVICE, VERIO_F7A2_WRITE, VerioHelper.getRcounterCMD(), "verio R data query"); // don't change order with T } } else { Log.d(TAG, "Got a different charactersitic! " + characteristic.getUuid().toString()); } Bluetooth_CMD.poll_queue(); } else { Log.e(TAG, "Got gatt read failure: " + status); Bluetooth_CMD.retry_last_command(status); } }
Example 19
Source File: BluetoothGlucoseMeter.java From xDrip with GNU General Public License v3.0 | 4 votes |
@Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { if (characteristic.getUuid().equals(TIME_CHARACTERISTIC)) { UserError.Log.d(TAG, "Got time characteristic read data"); ct = new CurrentTimeRx(characteristic.getValue()); statusUpdate("Device time: " + ct.toNiceString()); } else if (characteristic.getUuid().equals(DATE_TIME_CHARACTERISTIC)) { UserError.Log.d(TAG, "Got date time characteristic read data"); ct = new CurrentTimeRx(characteristic.getValue()); statusUpdate("Device time: " + ct.toNiceString()); } else if (characteristic.getUuid().equals(MANUFACTURER_NAME)) { mLastManufacturer = characteristic.getStringValue(0); UserError.Log.d(TAG, "Manufacturer Name: " + mLastManufacturer); statusUpdate("Device from: " + mLastManufacturer); await_acks = false; // reset // Roche Aviva Connect uses a DateTime characteristic instead if (mLastManufacturer.startsWith("Roche")) { Bluetooth_CMD.transmute_command(CURRENT_TIME_SERVICE, TIME_CHARACTERISTIC, GLUCOSE_SERVICE, DATE_TIME_CHARACTERISTIC); } // Diamond Mobile Mini DM30b firmware v1.2.4 // v1.2.4 has reversed sequence numbers and first item is last item and no clock access if (mLastManufacturer.startsWith("TaiDoc")) { // no time service! Bluetooth_CMD.delete_command(CURRENT_TIME_SERVICE, TIME_CHARACTERISTIC); ct = new CurrentTimeRx(); // implicitly trust meter time stamps!! beware daylight saving time changes ct.noClockAccess = true; ct.sequenceNotReliable = true; // no glucose context! Bluetooth_CMD.delete_command(GLUCOSE_SERVICE, CONTEXT_CHARACTERISTIC); Bluetooth_CMD.delete_command(GLUCOSE_SERVICE, CONTEXT_CHARACTERISTIC); // only request last reading - diamond mini seems to make sequence 0 be the most recent record Bluetooth_CMD.replace_command(GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, "W", new Bluetooth_CMD("W", GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, RecordsCmdTx.getFirstRecord(), "request newest reading")); } // Caresens Dual if (mLastManufacturer.startsWith("i-SENS")) { Bluetooth_CMD.delete_command(CURRENT_TIME_SERVICE, TIME_CHARACTERISTIC); ct = new CurrentTimeRx(); // implicitly trust meter time stamps!! beware daylight saving time changes ct.noClockAccess = true; Bluetooth_CMD.notify(ISENS_TIME_SERVICE, ISENS_TIME_CHARACTERISTIC, "notify isens clock"); Bluetooth_CMD.write(ISENS_TIME_SERVICE, ISENS_TIME_CHARACTERISTIC, new TimeTx(JoH.tsl()).getByteSequence(), "set isens clock"); Bluetooth_CMD.write(ISENS_TIME_SERVICE, ISENS_TIME_CHARACTERISTIC, new TimeTx(JoH.tsl()).getByteSequence(), "set isens clock"); Bluetooth_CMD.replace_command(GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, "W", new Bluetooth_CMD("W", GLUCOSE_SERVICE, RECORDS_CHARACTERISTIC, RecordsCmdTx.getNewerThanSequence(getHighestSequence()), "request reading newer than " + getHighestSequence())); } // LifeScan Verio Flex if (mLastManufacturer.startsWith("LifeScan")) { await_acks = true; Bluetooth_CMD.empty_queue(); // Verio Flex isn't standards compliant Bluetooth_CMD.notify(VERIO_F7A1_SERVICE, VERIO_F7A3_NOTIFICATION, "verio general notification"); Bluetooth_CMD.enable_notification_value(VERIO_F7A1_SERVICE, VERIO_F7A3_NOTIFICATION, "verio general notify value"); Bluetooth_CMD.write(VERIO_F7A1_SERVICE, VERIO_F7A2_WRITE, VerioHelper.getTimeCMD(), "verio ask time"); Bluetooth_CMD.write(VERIO_F7A1_SERVICE, VERIO_F7A2_WRITE, VerioHelper.getTcounterCMD(), "verio T data query"); // don't change order with R Bluetooth_CMD.write(VERIO_F7A1_SERVICE, VERIO_F7A2_WRITE, VerioHelper.getRcounterCMD(), "verio R data query"); // don't change order with T } } else { Log.d(TAG, "Got a different charactersitic! " + characteristic.getUuid().toString()); } Bluetooth_CMD.poll_queue(); } else { Log.e(TAG, "Got gatt read failure: " + status); Bluetooth_CMD.retry_last_command(status); } }
Example 20
Source File: BLEService.java From microbit with Apache License 2.0 | 4 votes |
private boolean registerNotifications(boolean enable) { logi("registerNotifications() : " + enable); //Read micro:bit firmware version BluetoothGattService deviceInfoService = getService(GattServiceUUIDs.DEVICE_INFORMATION_SERVICE); if(deviceInfoService != null) { BluetoothGattCharacteristic firmwareCharacteristic = deviceInfoService.getCharacteristic (CharacteristicUUIDs.FIRMWARE_REVISION_UUID); if(firmwareCharacteristic != null) { String firmware = ""; BluetoothGattCharacteristic characteristic = readCharacteristic(firmwareCharacteristic); if(characteristic != null && characteristic.getValue() != null && characteristic.getValue().length != 0) { firmware = firmwareCharacteristic.getStringValue(0); } sendMicrobitFirmware(firmware); logi("Micro:bit firmware version String = " + firmware); } } else { Log.e(TAG, "Not found DeviceInformationService"); } BluetoothGattService eventService = getService(GattServiceUUIDs.EVENT_SERVICE); if(eventService == null) { Log.e(TAG, "Not found EventService"); logi("registerNotifications() :: not found service : Constants.EVENT_SERVICE"); return false; } logi("Constants.EVENT_SERVICE = " + GattServiceUUIDs.EVENT_SERVICE.toString()); logi("Constants.ES_MICROBIT_REQUIREMENTS = " + CharacteristicUUIDs.ES_MICROBIT_REQUIREMENTS.toString()); logi("Constants.ES_CLIENT_EVENT = " + CharacteristicUUIDs.ES_CLIENT_EVENT.toString()); logi("Constants.ES_MICROBIT_EVENT = " + CharacteristicUUIDs.ES_MICROBIT_EVENT.toString()); logi("Constants.ES_CLIENT_REQUIREMENTS = " + CharacteristicUUIDs.ES_CLIENT_REQUIREMENTS.toString()); if(!registerMicrobitRequirements(eventService, enable)) { if(DEBUG) { logi("***************** Cannot Register Microbit Requirements.. Will continue ************** "); } } register_AppRequirement(eventService, enable); if(!registerMicroBitEvents(eventService, enable)) { logi("Failed to registerMicroBitEvents"); return false; } logi("registerNotifications() : done"); return true; }