Java Code Examples for no.nordicsemi.android.ble.data.Data#FORMAT_UINT8
The following examples show how to use
no.nordicsemi.android.ble.data.Data#FORMAT_UINT8 .
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: TemplateDataCallback.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { if (data.size() < 2) { onInvalidDataReceived(device, data); return; } // Read flags int offset = 0; final int flags = data.getIntValue(Data.FORMAT_UINT8, offset); final int hearRateType = (flags & 0x01) == 0 ? Data.FORMAT_UINT8 : Data.FORMAT_UINT16; offset += 1; // Validate packet length. The type's lower nibble is its length. if (data.size() < 1 + (hearRateType & 0x0F)) { onInvalidDataReceived(device, data); return; } final int value = data.getIntValue(hearRateType, offset); // offset += hearRateType & 0xF; // ... // Report the parsed value(s) onSampleValueReceived(device, value); }
Example 2
Source File: HeartRateMeasurementDataCallback.java From Android-BLE-Common-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { super.onDataReceived(device, data); if (data.size() < 2) { onInvalidDataReceived(device, data); return; } // Read flags int offset = 0; final int flags = data.getIntValue(Data.FORMAT_UINT8, offset); final int hearRateType = (flags & 0x01) == 0 ? Data.FORMAT_UINT8 : Data.FORMAT_UINT16; final int sensorContactStatus = (flags & 0x06) >> 1; final boolean sensorContactSupported = sensorContactStatus == 2 || sensorContactStatus == 3; final boolean sensorContactDetected = sensorContactStatus == 3; final boolean energyExpandedPresent = (flags & 0x08) != 0; final boolean rrIntervalsPresent = (flags & 0x10) != 0; offset += 1; // Validate packet length if (data.size() < 1 + (hearRateType & 0x0F) + (energyExpandedPresent ? 2 : 0) + (rrIntervalsPresent ? 2 : 0)) { onInvalidDataReceived(device, data); return; } // Prepare data final Boolean sensorContact = sensorContactSupported ? sensorContactDetected : null; final int heartRate = data.getIntValue(hearRateType, offset); offset += hearRateType & 0xF; Integer energyExpanded = null; if (energyExpandedPresent) { energyExpanded = data.getIntValue(Data.FORMAT_UINT16, offset); offset += 2; } List<Integer> rrIntervals = null; if (rrIntervalsPresent) { final int count = (data.size() - offset) / 2; final List<Integer> intervals = new ArrayList<>(count); for (int i = 0; i < count; ++i) { intervals.add(data.getIntValue(Data.FORMAT_UINT16, offset)); offset += 2; } rrIntervals = Collections.unmodifiableList(intervals); } onHeartRateMeasurementReceived(device, heartRate, sensorContact, energyExpanded, rrIntervals); }
Example 3
Source File: HeartRateMeasurementDataCallback.java From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onDataReceived(@NonNull final BluetoothDevice device, @NonNull final Data data) { super.onDataReceived(device, data); if (data.size() < 2) { onInvalidDataReceived(device, data); return; } // Read flags int offset = 0; final int flags = data.getIntValue(Data.FORMAT_UINT8, offset); final int hearRateType = (flags & 0x01) == 0 ? Data.FORMAT_UINT8 : Data.FORMAT_UINT16; final int sensorContactStatus = (flags & 0x06) >> 1; final boolean sensorContactSupported = sensorContactStatus == 2 || sensorContactStatus == 3; final boolean sensorContactDetected = sensorContactStatus == 3; final boolean energyExpandedPresent = (flags & 0x08) != 0; final boolean rrIntervalsPresent = (flags & 0x10) != 0; offset += 1; // Validate packet length if (data.size() < 1 + (hearRateType & 0x0F) + (energyExpandedPresent ? 2 : 0) + (rrIntervalsPresent ? 2 : 0)) { onInvalidDataReceived(device, data); return; } // Prepare data final Boolean sensorContact = sensorContactSupported ? sensorContactDetected : null; final int heartRate = data.getIntValue(hearRateType, offset); offset += hearRateType & 0xF; Integer energyExpanded = null; if (energyExpandedPresent) { energyExpanded = data.getIntValue(Data.FORMAT_UINT16, offset); offset += 2; } List<Integer> rrIntervals = null; if (rrIntervalsPresent) { final int count = (data.size() - offset) / 2; final List<Integer> intervals = new ArrayList<>(count); for (int i = 0; i < count; ++i) { intervals.add(data.getIntValue(Data.FORMAT_UINT16, offset)); offset += 2; } rrIntervals = Collections.unmodifiableList(intervals); } onHeartRateMeasurementReceived(device, heartRate, sensorContact, energyExpanded, rrIntervals); }