Merge branch 'fix/gatt-status-logging': add GATT status code logging

This commit is contained in:
eddy 2026-07-26 16:44:57 +02:00
commit 3802b5b07d

View file

@ -71,6 +71,9 @@ class MainActivity : AppCompatActivity() {
private val gattCallback = object : BluetoothGattCallback() { private val gattCallback = object : BluetoothGattCallback() {
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
if (status != BluetoothGatt.GATT_SUCCESS) {
Log.w(TAG, "GATT connection state change error: status=$status newState=$newState")
}
if (newState == BluetoothProfile.STATE_CONNECTED) { if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.d(TAG, "GATT connected") Log.d(TAG, "GATT connected")
bluetoothGatt = gatt bluetoothGatt = gatt
@ -92,12 +95,20 @@ class MainActivity : AppCompatActivity() {
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) { override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
if (status != BluetoothGatt.GATT_SUCCESS) {
Log.w(TAG, "Service discovery failed (status=$status)")
runOnUiThread { statusText.text = "Servicefout" }
return
}
Log.d(TAG, "Services discovered, requesting MTU...") Log.d(TAG, "Services discovered, requesting MTU...")
gatt.requestMtu(256) gatt.requestMtu(256)
} }
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) { override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) {
if (status != BluetoothGatt.GATT_SUCCESS) {
Log.w(TAG, "MTU negotiation failed (status=$status)")
}
Log.d(TAG, "MTU changed to $mtu") Log.d(TAG, "MTU changed to $mtu")
val service = gatt.getService(SERVICE_UUID) val service = gatt.getService(SERVICE_UUID)
if (service != null) { if (service != null) {