Java Code Examples for android.bluetooth.BluetoothGattCharacteristic#FORMAT_UINT32
The following examples show how to use
android.bluetooth.BluetoothGattCharacteristic#FORMAT_UINT32 .
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: 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 2
Source File: ParserUtils.java From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static int getIntValue(final byte[] source, final int offset, final int formatType) { if ((offset + getTypeLen(formatType)) > source.length) throw new ArrayIndexOutOfBoundsException(); switch (formatType) { case BluetoothGattCharacteristic.FORMAT_UINT8: return unsignedByteToInt(source[offset]); case BluetoothGattCharacteristic.FORMAT_UINT16: return unsignedBytesToInt(source[offset], source[offset + 1]); case FORMAT_UINT24: return unsignedBytesToInt(source[offset], source[offset + 1], source[offset + 2]); case BluetoothGattCharacteristic.FORMAT_UINT32: return unsignedBytesToInt(source[offset], source[offset + 1], source[offset + 2], source[offset + 3]); case FORMAT_UINT16_BIG_INDIAN: return unsignedBytesToInt(source[offset + 1], source[offset]); case FORMAT_UINT32_BIG_INDIAN: return unsignedBytesToInt(source[offset + 3], source[offset + 2], source[offset + 1], source[offset]); case BluetoothGattCharacteristic.FORMAT_SINT8: return unsignedToSigned(unsignedByteToInt(source[offset]), 8); case BluetoothGattCharacteristic.FORMAT_SINT16: return unsignedToSigned(unsignedBytesToInt(source[offset], source[offset + 1]), 16); case FORMAT_SINT24: return unsignedToSigned(unsignedBytesToInt(source[offset], source[offset + 1], source[offset + 2]), 24); case BluetoothGattCharacteristic.FORMAT_SINT32: return unsignedToSigned(unsignedBytesToInt(source[offset], source[offset + 1], source[offset + 2], source[offset + 3]), 32); } return 0; }
Example 3
Source File: ByteUtil.java From EasyBle with Apache License 2.0 | 5 votes |
/** * Return the stored value of this characteristic. * * <p>The formatType parameter determines how the characteristic value * is to be interpreted. For example, settting formatType to * {@link #FORMAT_UINT16} specifies that the first two bytes of the * characteristic value at the given offset are interpreted to generate the * return value. * * @param formatType The format type used to interpret the characteristic * value. * @param offset Offset at which the integer value can be found. * @return Cached value of the characteristic or null of offset exceeds * value size. */ public static Integer getIntValue(byte[] data, int formatType, int offset) { if ((offset + getTypeLen(formatType)) > data.length) return null; switch (formatType) { case BluetoothGattCharacteristic.FORMAT_UINT8: return unsignedByteToInt(data[offset]); case BluetoothGattCharacteristic.FORMAT_UINT16: return unsignedBytesToInt(data[offset], data[offset+1]); case BluetoothGattCharacteristic.FORMAT_UINT32: return unsignedBytesToInt(data[offset], data[offset+1], data[offset+2], data[offset+3]); case BluetoothGattCharacteristic.FORMAT_SINT8: return unsignedToSigned(unsignedByteToInt(data[offset]), 8); case BluetoothGattCharacteristic.FORMAT_SINT16: return unsignedToSigned(unsignedBytesToInt(data[offset], data[offset+1]), 16); case BluetoothGattCharacteristic.FORMAT_SINT32: return unsignedToSigned(unsignedBytesToInt(data[offset], data[offset+1], data[offset+2], data[offset+3]), 32); } return null; }
Example 4
Source File: CharacteristicDetailsActivity.java From BLEService with BSD 3-Clause "New" or "Revised" License | 5 votes |
public int getValueFormat(BluetoothGattCharacteristic ch) { int properties = ch.getProperties(); if((BluetoothGattCharacteristic.FORMAT_FLOAT & properties) != 0) return BluetoothGattCharacteristic.FORMAT_FLOAT; if((BluetoothGattCharacteristic.FORMAT_SFLOAT & properties) != 0) return BluetoothGattCharacteristic.FORMAT_SFLOAT; if((BluetoothGattCharacteristic.FORMAT_SINT16 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_SINT16; if((BluetoothGattCharacteristic.FORMAT_SINT32 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_SINT32; if((BluetoothGattCharacteristic.FORMAT_SINT8 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_SINT8; if((BluetoothGattCharacteristic.FORMAT_UINT16 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_UINT16; if((BluetoothGattCharacteristic.FORMAT_UINT32 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_UINT32; if((BluetoothGattCharacteristic.FORMAT_UINT8 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_UINT8; return 0; }
Example 5
Source File: BleWrapper.java From BLEService with BSD 3-Clause "New" or "Revised" License | 5 votes |
public int getValueFormat(BluetoothGattCharacteristic ch) { int properties = ch.getProperties(); if((BluetoothGattCharacteristic.FORMAT_FLOAT & properties) != 0) return BluetoothGattCharacteristic.FORMAT_FLOAT; if((BluetoothGattCharacteristic.FORMAT_SFLOAT & properties) != 0) return BluetoothGattCharacteristic.FORMAT_SFLOAT; if((BluetoothGattCharacteristic.FORMAT_SINT16 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_SINT16; if((BluetoothGattCharacteristic.FORMAT_SINT32 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_SINT32; if((BluetoothGattCharacteristic.FORMAT_SINT8 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_SINT8; if((BluetoothGattCharacteristic.FORMAT_UINT16 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_UINT16; if((BluetoothGattCharacteristic.FORMAT_UINT32 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_UINT32; if((BluetoothGattCharacteristic.FORMAT_UINT8 & properties) != 0) return BluetoothGattCharacteristic.FORMAT_UINT8; return 0; }
Example 6
Source File: ParserUtils.java From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static int setValue(final byte[] dest, int offset, int value, int formatType) { int len = offset + getTypeLen(formatType); if (len > dest.length) return offset; switch (formatType) { case BluetoothGattCharacteristic.FORMAT_SINT8: value = intToSignedBits(value, 8); // Fall-through intended case BluetoothGattCharacteristic.FORMAT_UINT8: dest[offset] = (byte) (value & 0xFF); break; case BluetoothGattCharacteristic.FORMAT_SINT16: value = intToSignedBits(value, 16); // Fall-through intended case BluetoothGattCharacteristic.FORMAT_UINT16: dest[offset++] = (byte) (value & 0xFF); dest[offset] = (byte) ((value >> 8) & 0xFF); break; case FORMAT_SINT24: value = intToSignedBits(value, 24); // Fall-through intended case FORMAT_UINT24: dest[offset++] = (byte) (value & 0xFF); dest[offset++] = (byte) ((value >> 8) & 0xFF); dest[offset] = (byte) ((value >> 16) & 0xFF); break; case FORMAT_UINT16_BIG_INDIAN: dest[offset++] = (byte) ((value >> 8) & 0xFF); dest[offset] = (byte) (value & 0xFF); break; case BluetoothGattCharacteristic.FORMAT_SINT32: value = intToSignedBits(value, 32); // Fall-through intended case BluetoothGattCharacteristic.FORMAT_UINT32: dest[offset++] = (byte) (value & 0xFF); dest[offset++] = (byte) ((value >> 8) & 0xFF); dest[offset++] = (byte) ((value >> 16) & 0xFF); dest[offset] = (byte) ((value >> 24) & 0xFF); break; case FORMAT_UINT32_BIG_INDIAN: dest[offset++] = (byte) ((value >> 24) & 0xFF); dest[offset++] = (byte) ((value >> 16) & 0xFF); dest[offset++] = (byte) ((value >> 8) & 0xFF); dest[offset] = (byte) (value & 0xFF); break; default: return offset; } return len; }