Skip to content

Commit

Permalink
bug fix with ble notifications and indications
Browse files Browse the repository at this point in the history
  • Loading branch information
bayosip committed Nov 16, 2021
1 parent 1eae98c commit 0917315
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,19 @@ public void onReceive(Context context, Intent intent) {
case Constants.ACTION_BLE_CHARX_DATA_CHANGE:
Log.w("DATA", ""+intent.getStringExtra(Constants.BLE_EXTRA_DATA_RAW));
// This is called after a Notify completes
GeneralUtil.message(intent.getStringExtra(Constants.BLE_EXTRA_DATA_RAW));
//GeneralUtil.message(intent.getStringExtra(Constants.BLE_EXTRA_DATA_RAW));
break;
case Constants.ACTION_BLE_CHARX_DATA_CHANGE_RAW:
Log.w("DATA", "onReceive: ->" +
Arrays.toString(intent.getByteArrayExtra(inc.osips.iot_wireless_communication
.wireless_comms_module.remote_comms.utility.Constants.BLE_EXTRA_DATA_RAW)));
case Constants.P2P_ACTION_DATA_AVAILABLE:
String s = intent.getStringExtra(Constants.P2P_EXTRA_DATA);
if(s != null)
if(s != null) {
Log.w("DATA", s);
// This is called after a Notify completes
GeneralUtil.message(s);
// This is called after a Notify completes
GeneralUtil.message(s);
}
break;
case WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION:
if(type.equalsIgnoreCase(Constants.P2P)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,30 +796,36 @@ public void writeToDescriptorToEnableIndicator(String serviceUUID, String charxU

private void writeToDescriptorToEnableNotifications(BluetoothGattCharacteristic characteristic, BluetoothGatt gatt){
if (setCharacteristicNotification(gatt, characteristic, true)) {
BluetoothGattDescriptor descriptor = characteristic.getDescriptors().get(0);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
List<BluetoothGattDescriptor> descriptors = characteristic.getDescriptors();
if(descriptors!=null && !descriptors.isEmpty()) {
BluetoothGattDescriptor descriptor = descriptors.get(0);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

String deviceAddress = gatt.getDevice().getAddress();
Queue<Object> BleWriteQueue = writeQueueMap.get(deviceAddress);
Objects.requireNonNull(BleWriteQueue).add(descriptor);
writeQueueMap.put(deviceAddress, BleWriteQueue);
if(BleWriteQueue.size()==1)
Log.d(TAG, "writeToDescriptorToEnableNotifications: ->" +gatt.writeDescriptor(descriptor));
String deviceAddress = gatt.getDevice().getAddress();
Queue<Object> BleWriteQueue = writeQueueMap.get(deviceAddress);
Objects.requireNonNull(BleWriteQueue).add(descriptor);
writeQueueMap.put(deviceAddress, BleWriteQueue);
if (BleWriteQueue.size() == 1)
Log.d(TAG, "writeToDescriptorToEnableNotifications: ->" + gatt.writeDescriptor(descriptor));
}
}
}

private void writeToDescriptorToEnableIndicator(BluetoothGattCharacteristic characteristic,
BluetoothGatt gatt){
if (setCharacteristicNotification(gatt, characteristic, true)) {
BluetoothGattDescriptor descriptor = characteristic.getDescriptors().get(0);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
List<BluetoothGattDescriptor> descriptors = characteristic.getDescriptors();
if (descriptors != null && !descriptors.isEmpty()) {
BluetoothGattDescriptor descriptor = descriptors.get(0);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

String deviceAddress = gatt.getDevice().getAddress();
Queue<Object> BleWriteQueue = writeQueueMap.get(deviceAddress);
Objects.requireNonNull(BleWriteQueue).add(descriptor);
writeQueueMap.put(deviceAddress, BleWriteQueue);
if(BleWriteQueue.size()==1)
Log.d(TAG, "writeToDescriptorToEnableNotifications: ->" +gatt.writeDescriptor(descriptor));
String deviceAddress = gatt.getDevice().getAddress();
Queue<Object> BleWriteQueue = writeQueueMap.get(deviceAddress);
Objects.requireNonNull(BleWriteQueue).add(descriptor);
writeQueueMap.put(deviceAddress, BleWriteQueue);
if (BleWriteQueue.size() == 1)
Log.d(TAG, "writeToDescriptorToEnableNotifications: ->" + gatt.writeDescriptor(descriptor));
}
}
}

Expand Down

0 comments on commit 0917315

Please sign in to comment.