OnServicesDiscovered () не называется if requestMtu () и deciplyServices (), объединенные при подключении к периферийнымAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 OnServicesDiscovered () не называется if requestMtu () и deciplyServices (), объединенные при подключении к периферийным

Сообщение Anonymous »

Я сталкиваюсь с проблемой взаимодействия BLE между Android Central/Client (CompilesDK = 35), подключенной к периферическому/серверу, который инициирует его собственное переговоры о MTU: обнаружение услуг, по -видимому, застряло, а OnservicesDiscovered () никогда не называется. Bluetoothgatt.requestmtu () после подключения устройства. В случае этого конкретного устройства BLE, даже когда он номинально настроен в качестве периферического/сервера, оно также выступает в качестве центрального/клиента и инициирует согласование MTU. override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
// initiate MTU negotiation and service discovery
gatt.requestMtu(512)
gatt.discoverServices()
}
BluetoothProfile.STATE_DISCONNECTED -> {
// Disconnected from device
}
}
}
}

override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// Services discovered, enable notifications if needed
.
.
.
}
}
< /code>
Если я удалю вызов в Bluetoothgatt.requestmtu (), то без проблем, но, очевидно, это не будет работать с другими устройствами BLE, которые не инициируют переговоры MTU. Если я отключаю переговоры MTU, инициированное периферическим, то без проблем. />
date /time < /th>
pid-tid < /th>
Tag < /th>
Level < /th>
message < /th>
< /tr>
< /thead>


< /tr>
< /thead>


< /tr>
< /thead>

/>2025-07-11 17:47:49.116
8165-8165
BluetoothAdapter
D
getBleEnabledArray(): ON


2025-07-11 17: 47: 49.118 < /td>
8165-8165 < /td>
bluetoothgatt < /td>
d < /td>
Xx: xx: xx: xx: 77: 30, Auto: false < /td>
< /tr>

2025-07-11 17: 47: 49.118 < /td>
8165-8165 < /td>
blootlegtgggggggggggggt> ald> < /td>
bloothgggggggggggG /> d < /td>
registerApp () < /td>
< /tr>

2025-07-11 17: 47: 49.119 < /td>
8165-8165 < /td>
8165-8165 < /td>
8165-8165 < /td> /> d < /td>
RegisterApp ()-uuid = a616f277-dd9b-4d9c-87c9-199cafe1cfc8 < /td>
< /tr>

2025-07-11 17: 49.11 < />
2025-07-11: 49.1 < />
2025-07-11: 49.11 < />
2025-07-11: 49. /> 8165-9333 < /td>
Bluetoothgatt < /td>
d < /td>
onclientRegistered ()-Состояние = 0 Clientif = 12 < /td>
< /tr>

201111111. 17: 47: 49.126 < /td>
8165-9333 < /td>
bluetoothAdapter < /td>
d < /td>
getbleenabledarray (): On < /td>
< /br />

/> 2025-07-11 17: 47: 50.596 < /td>
8165-9333 < /td>
bluetoothgatt < /td>
d < /td>
onclientConc Device = xx: xx: xx: xx: 77: 30 < /td>
< /tr>

2025-07-11 17: 47: 50.600 < /td>
8165-9333 < /td>
bluetOthGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTOOTHGGGT />D
configureMTU() - device: XX:XX:XX:XX:77:30 mtu: 512


2025-07-11 17:47:50.603
8165-9333 < /td>
bluetoothgatt < /td>
d < /td>
DiscoverServices () - XX: xx: xx: xx: 77: 30 < /td>
< /tr>

/> 2025-07-11 17: 47: 51.120 < /td>
8165-9333 < /td>
bluetoothgatt < /td>
d < /td>
OnConnectionUpdated ()- Device = XX: XX: XX: XX: 77: 30 Интервал = 6 Latency = 0 Timeout = 500 Status = 0 < /td>
< /tr>

2025-07-11 17: 47: 51.494 < /td>
8165-933333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333. /> Bluetoothgatt < /td>
d < /td>
OnConfigUreMtu ()-Device = xx: xx: xx: xx: 77: 30 mtu = 247 status = 0 < /td>
< /tr>

2011111111111111 17: 47: 51.569 < /td>
8165-9333 < /td>
Bluetoothgatt < /td>
d < /td>
onConnectionUpdated () - device = xx: xx: xx: xx: 77: 77: 77: 77: 307: 307: 307: 307: 307: 77: 307: 77: 307: 77: 307: 307: 77: 307: 77: 307: 77: 307: 307: 77: 77: 307: 307: 77: 307: 30: 77: 307: 77: 307: 77: 77: 307: 307: 77: 77: 30: 77: 307: 77: 77: 307: 77: 77: 77: 77: 307: 30 timeout=500 status=0



And the same thing but with the peripheral initiated MTU negotiation disabled:



date /time < /th>
pid-tid < /th>
Tag < /th>
Level < /th>
message < /th>
< /tr>
< /thead>


< /tr>
< /thead>


< /tr>
< /thead>

/> 2025-07-11 17: 52: 18.055 < /td>
8165-8165 < /td>
bluetoothAdapter < /td>
d < /td>
getbleenArdabled () < /td>
getbleenarray (): на < /td>
getbleenarray (): On < /td>
/>
2025-07-11 17: 52: 18.058 < /td>
8165-8165 < /td>
bluetoothgatt < /td>
d < /td>
Xx: xx: xx: xx: 77: 30, Auto: false < /td>
< /tr>

2025-07-11 17: 52: 18.058 < /td>
8165-8165 < /td>
blid> blTOTHGGGT> BlTOTHGG> < /td>
blid> alt att> br /td> alt att> 8165-8165 < /td> /> d < /td>
registerApp () < /td>
< /tr>

2025-07-11 17: 52: 18.058 < /td>
8165-8165 < /td>




. /> d < /td>
RegisterApp ()-uuid = c055ae54-e1d1-4f45-a276-9281537e3e2f < /td>
< /tr>

2025-07-11 17: 52: 18.063. /> 8165-8181 < /td>
bluetoothgatt < /td>
d < /td>
onclientRegistered ()-Состояние = 0 Clientif = 13 < /td>
< /tr>

20111111111 < /td>
< /tr>
2011 < /td>
< /tr>
201 < /td>
< /tr>
201 < /td>
< /tr>

8165-8181 < /td>
bluetoothAdapter < /td>
d < /td>
getbleenabledarray (): On < /td>
< /br />

/> 2025-07-11 17: 52: 18.480 < /td>
8165-8181 < /td>
bluetoothgatt < /td>
d < /td>
onclientConc Device = xx: xx: xx: xx: 77: 30 < /td>
< /tr>

2025-07-11 17: 52: 18,482 < /td>
8165-8181 < /td>
bluetOthGGGGGT> Bl />D
configureMTU() - device: XX:XX:XX:XX:77:30 mtu: 512


2025-07-11 17:52:18.484
8165-8181 < /td>
bluetoothgatt < /td>
d < /td>
DiscoverServices () - устройство: xx: xx: xx: xx: 77: 30 < /td>
< /tr>

/> 2025-07-11 17: 52: 19.001 < /td>
8165-8181 < /td>
bluetoothgatt < /td>
d < /td>
OnConnectionUpdated () Device=XX:XX:XX:XX:77:30 interval=6 latency=0 timeout=500 status=0


2025-07-11 17:52:19.423
8165-8181
Bluetoothgatt < /td>
d < /td>
OnConfigUreMtu ()-Device = xx: xx: xx: xx: 77: 30 mtu = 247 status = 0 < /td>
< /tr>

2011111111111111 17: 52: 19.425
8165-8181
bluetoothgatt
d
onsearchcomplete () = xx: xx: xx: xx: 77: 30: 30: 30: 30: 0. /> < /tr>

2025-07-11 17: 52: 19.425 < /td>
8165-8181 < /td>
bluetoothgatt < /td>
d < /td>

d < /td> UUID: 85FC567E-31D9-4185-87C6-339924D1C5BE Включение: true < /td>
< /tr>

2025-07-11 17: 52: 19.496 < /td>
816666661818: 19.496 < /td>
8166: 19.496 < /td>
8166: 19.496 < /td> /> Bluetoothgatt < /td>
d < /td>
onConnectionUpdated () - Device = xx: xx: xx: xx: 77: 30 Интервал = 36 Latency = 0 Timeout = 500 Статус = 0 < /td>
< /tr>
< /tbody>
/> < /table> < /div>
После захвата этих трассов я узнал, что если я ставлю вызов requestmtu () из onservicesdiscovered (), то нет проблем: < /p>
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
// initiate service discovery
gatt.discoverServices()
}
BluetoothProfile.STATE_DISCONNECTED -> {
// Disconnected from device
}
}
}
}
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// now initiate MTU negotiation
gatt.requestMtu(512)
}
}
override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// services discovered and MTU negotiated, enable notifications if needed
.
.
.
}
}
< /code>
Я также узнал, что обратные вызовы Discoverservices (), затем requestMtu () в порядке: < /p>
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
// initiate MTU negotiation and service discovery
gatt.discoverServices()
gatt.requestMtu(512)
}
BluetoothProfile.STATE_DISCONNECTED -> {
// Disconnected from device
}
}
}
}

override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// Services discovered, enable notifications if needed
.
.
.
}
}
< /code>
С учетом журнала отладки для включения стека Bluetooth Я думаю, что ясно, куда идут дела вбок. Поскольку вызовы выпускаются обратно к спине, команда для обнаружения услуг в очередь в очереди на потом: < /p>



date /tham < /th>
< /th> < /br /> < /br /> < /br /> < /br /> < /br /> < /br /br /> < /br /br /> < /br /> < /br /> < /br /> < /br /> < /br /> < /br /> < /br /> < /br /> < /br /> < /br /> < /br /br /> < /br /tht th> /> Уровень журнала < /th>
Сообщение < /th>
< /tr>
< /thead>


2025-07-14 09: 50: 22.846 < /td>
1110-11125 < /22.846 < /td>
1110-1125 < /td>
1110-1125 < /td>
1110-1125 < /td>
1110-1125 < /td>
/> Bluetoothgatt < /td>
d < /td>
onclientConnectionState ()-Status = 0 Clientif = 5 Connected = xx = xx: xx: xx: 77: 30 < /td>
< /tr>

204-04. 09: 50: 22,855
1110-1125
bluetoothgatt
d
ConfigurUremtu () - устройство: xx: xx: xx: xx: 77: 30 MT /> < /tr>

2025-07-14 09: 50: 22.863 < /td>
3180-3986 < /td>
bt_btif_gattc < /td>
d < /td> system/btif/src/btif_gatt_client.cc:780 btif_gattc_configure_mtu:


2025-07-14 09: 50: 22.865
2025-07-14 09: 50: 22. /> 1110-1125 < /td>
bluetoothgatt < /td>
d < /td>
discoverservices () - xx: xx: xx: xx: 77: 30 < /td>
< /tr>
/> 2025-07-14 09: 50: 22.867 < /td>
3180-3986 < /td>
bt_btif_gattc < /td>
d < /td>
system/btif/src/btif_gatt_client.cc:561 btif_gattc_search_service:


2025-07-14 09: 50: 22.880 2025-07-14: 50: 22.880 /> 3180-3328
bt_bta_gattc
i
функциональный Очередь для более позднего XX: xx: xx: xx: 77: 30 conn id = 0x0005



и позже, когда обнаружение службы завершено, обратный вызов) callback to onSearchComplete() is not (BTA_GATTC_SEARCH_CMPL_EVT), even though the Gatt client thinks it's done:



Date/Time
pid-tid < /th>
Tag < /th>
Level < /th>
Сообщение < /th>
< /tr>
< /thead>


2025-07-14 09: 50: 23.71 < />
2025-07-14 09: 50: 50: 7.71 < />
2025-07-14 09: 50: 50: 7. /> 3180-3328
bt_bta_gattc
d
prostemsem/bta/gatt/bta_gattc_cache.cc:337 bta_gattc_explore_srviniredired: restempery_srvine_finediredired: restemporty_srvin Чтобы ноль, conn_id = 0x0005 < /td>
< /tr>

...
< /td>
< /td>
< /td>
< /td>

< /td>
< /td>
< /td> /> 2025-07-14 09: 50: 23.721
3180-3328
GATT_API
I
XAPI
I
td> system/stack/gatt_api.78. GATTC_TryMtuRequest: xx:xx:xx:xx:77:30 conn_id=0x0005


2025-07-14 09:50:23.721
3180-3328
GATT_API
i
system/stack/gatt/gatt_api.cc:831 gattc_updateuserattmtuifneded: xx: xx: xx: xx: 77: 30, mtu = 517 xx> xx> xx: xx: xx: 77: 30, mtu = 517 517
51 51 . />
2025-07-14 09: 50: 23.721 < /td>
3180-3328 < /td>
gatt_api < /td>
i < /td>
system/stack/gatt/gatt_api.cc:838 gattc_updateuserattmtuifneededed: xx: xx: xx: xx: 77: 30, текущий Mtu: 247, max_user_mtu: 0, user_mtu: 517

/> 2025-07-14 09: 50: 23.721
3180-3328
GATT_API
I
XAPI
I
td>system/stack/gatt_api.8444444444444444. GATTC_UPDATEUSERATTMTUIFNEDEDEDED: пользователь запросил больше, чем Gatt может справиться. Обрезать. />system/stack/btm/btm_ble_sec.cc:581 btm_setbletalgene: bd_addr: xx: xx: xx: xx: 77: 30, tx_pdu_length: 247

202-04-04-04-04
202-07
202-04
207 = 247 < /td>
< /tr>

2025-07-14 09: 50: 23.721 < /td>
3180-3328 < /td>
bt_btif_gattc < /td>

bt_btif_gattc < /td>
bt_btif_gattc < /td> />system/btif/src/btif_gatt_client.cc:331 bta_gattc_cback: Gatt Client Callback Событие: BTA_GATTC_CFG_MTU_EVT [18]


2025-07-14. 09: 50: 23.721
3180-3328
bt_btif_gattc
d
функциональный Событие обратного вызова клиента: BTA_GATTC_SRVC_DISC_DONE_EVT [8]



Для справки, нормальная отделка для обслуживания. Похоже на это:



Подробнее здесь: https://stackoverflow.com/questions/796 ... ces-called
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»