List of usage examples for android.bluetooth BluetoothGattCharacteristic getIntValue
public Integer getIntValue(int formatType, int offset)
From source file:Main.java
public static Integer shortUnsignedAtOffset(BluetoothGattCharacteristic c, int offset) { Integer lowerByte = c.getIntValue(FORMAT_UINT8, offset); if (lowerByte == null) return 0; Integer upperByte = c.getIntValue(FORMAT_UINT8, offset + 1); // Note: interpret MSB as unsigned. if (upperByte == null) return 0; return (upperByte << 8) + lowerByte; }
From source file:Main.java
public static Integer shortUnsignedAtOffset(BluetoothGattCharacteristic c, int offset) { Integer lowerByte = c.getIntValue(FORMAT_UINT8, offset); if (lowerByte == null) { return 0; }//ww w. ja v a 2 s. com Integer upperByte = c.getIntValue(FORMAT_UINT8, offset + 1); // Note: interpret MSB as unsigned. if (upperByte == null) { return 0; } return (upperByte << 8) + lowerByte; }
From source file:Main.java
/** * Gyroscope, Magnetometer, Barometer, IR temperature * all store 16 bit two's complement values in the awkward format * LSB MSB, which cannot be directly parsed as getIntValue(FORMAT_SINT16, offset) * because the bytes are stored in the "wrong" direction. * * This function extracts these 16 bit two's complement values. * *///from w w w. ja v a 2s. com public static Integer shortSignedAtOffset(BluetoothGattCharacteristic c, int offset) { Integer lowerByte = c.getIntValue(FORMAT_UINT8, offset); if (lowerByte == null) return 0; Integer upperByte = c.getIntValue(FORMAT_SINT8, offset + 1); // Note: interpret MSB as signed. if (upperByte == null) return 0; return (upperByte << 8) + lowerByte; }
From source file:Main.java
/** * Gyroscope, Magnetometer, Barometer, IR temperature * all store 16 bit two's complement values in the awkward format * LSB MSB, which cannot be directly parsed as getIntValue(FORMAT_SINT16, offset) * because the bytes are stored in the "wrong" direction. * <p/>/* w w w .j a va 2 s .co m*/ * This function extracts these 16 bit two's complement values. */ public static Integer shortSignedAtOffset(BluetoothGattCharacteristic c, int offset) { Integer lowerByte = c.getIntValue(FORMAT_UINT8, offset); if (lowerByte == null) { return 0; } Integer upperByte = c.getIntValue(FORMAT_SINT8, offset + 1); // Note: interpret MSB as signed. if (upperByte == null) { return 0; } return (upperByte << 8) + lowerByte; }
From source file:Main.java
/** * Returns the Transmission power information from the characteristic * //from ww w. ja v a 2 s. c o m * @param characteristics * @return {@link integer} */ @SuppressLint("NewApi") public static int getTransmissionPower(BluetoothGattCharacteristic characteristics) { int power_level = characteristics.getIntValue(BluetoothGattCharacteristic.FORMAT_SINT8, 0); return power_level; }
From source file:Main.java
/** * Returns the Alert level information from the characteristics * /*from ww w .j a va 2 s . c om*/ * @param characteristics * @return {@link String} */ @SuppressLint("NewApi") public static String getAlertLevel(BluetoothGattCharacteristic characteristics) { int alert_level = characteristics.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); return String.valueOf(alert_level); }
From source file:Main.java
/** * Returns the battery level information from the characteristics * /*w w w. j ava2 s.c om*/ * @param characteristics * @return {@link String} */ @SuppressLint("NewApi") public static String getBatteryLevel(BluetoothGattCharacteristic characteristics) { int battery_level = characteristics.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0); return String.valueOf(battery_level); }
From source file:com.chenls.smartlock.UartService.java
/** * ???/* w ww . jav a 2s .c om*/ * * @param action * @param characteristic */ private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); // 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 if (TX_CHAR_UUID.equals(characteristic.getUuid())) { intent.putExtra(EXTRA_DATA, "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0)); } else if (RX_CHAR_UUID.equals(characteristic.getUuid())) { intent.putExtra(CHAR1_DATA, "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0)); } else if (Battery_Level_UUID.equals(characteristic.getUuid())) { intent.putExtra(EXTRA_DATA, "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0)); } LocalBroadcastManager.getInstance(this).sendBroadcast(intent); }
From source file:com.example.android.bluetoothlegatt.BluetoothLeService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); // 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 if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { int flag = characteristic.getProperties(); int format = -1; if ((flag & 0x01) != 0) { format = BluetoothGattCharacteristic.FORMAT_UINT16; Log.d(TAG, "Heart rate format UINT16."); } else {/*from www.ja va 2 s .c o m*/ format = BluetoothGattCharacteristic.FORMAT_UINT8; Log.d(TAG, "Heart rate format UINT8."); } final int heartRate = characteristic.getIntValue(format, 1); 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) { //// print data received. final StringBuilder stringBuilder = new StringBuilder(data.length); for (byte byteChar : data) stringBuilder.append(String.format("%02X ", byteChar)); //Log.i(TAG, "windsome1:"+ stringBuilder.toString()); //Log.i(TAG, "windsome2:"+ new String(data)); intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString()); //// write to file. long currTime = System.currentTimeMillis(); /*if ((currTime - cacheTime) > 500) { Log.i(TAG, "write cache to file! currTime="+currTime+", cacheTime="+cacheTime+", interval="+(currTime - cacheTime)); boolean isSame = writeCacheToFile2 (); cacheData2.clear(); intent.putExtra(EXTRA_DATA_SAME, isSame); }*/ cacheData2.add(data); cacheTime = currTime; mToastHandler.removeCallbacks(mRunnable); mToastHandler.postDelayed(mRunnable, 300); } } sendBroadcast(intent); }
From source file:com.qi.airstat.BluetoothLeService.java
private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); int signal = 0; // 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 if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { int flag = characteristic.getProperties(); int format = -1; if ((flag & 0x01) != 0) { format = BluetoothGattCharacteristic.FORMAT_UINT16; Log.d(TAG, "Heart rate format UINT16."); } else {//from w w w. j ava 2 s . c om format = BluetoothGattCharacteristic.FORMAT_UINT8; Log.d(TAG, "Heart rate format UINT8."); } final int heartRate = characteristic.getIntValue(format, 1); signal = heartRate; 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) { final StringBuilder stringBuilder = new StringBuilder(data.length); for (byte byteChar : data) stringBuilder.append(String.format("%02X ", byteChar)); intent.putExtra(EXTRA_DATA, new String(data) + "\n" + stringBuilder.toString()); signal = Integer.parseInt(new String(data)); } } DatabaseManager databaseManager = new DatabaseManager(BluetoothLeService.this); SQLiteDatabase database = databaseManager.getWritableDatabase(); ContentValues values = new ContentValues(); String date = new SimpleDateFormat("yyMMddHHmmss").format(new java.util.Date()); values.put(Constants.DATABASE_COMMON_COLUMN_TIME_STAMP, date); values.put(Constants.DATABASE_HEART_RATE_COLUMN_HEART_RATE, signal); database.insert(Constants.DATABASE_HEART_RATE_TABLE, null, values); database.close(); try { Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); latitude = location.getLatitude(); longitude = location.getLongitude(); } catch (SecurityException exception) { exception.printStackTrace(); } JSONObject reformedObject = new JSONObject(); JSONArray reformedArray = new JSONArray(); try { JSONObject item = new JSONObject(); item.put("timeStamp", date); item.put("connectionID", Constants.CID_BLE); item.put("heartrate", signal); item.put("latitude", latitude); item.put("longitude", longitude); reformedArray.put(item); reformedObject.put("HR", reformedArray); } catch (JSONException e) { e.printStackTrace(); } HttpService httpService = new HttpService(); String responseCode = httpService.executeConn(null, "POST", "http://teamc-iot.calit2.net/IOT/public/rcv_json_data", reformedObject); sendBroadcast(intent); }