mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-08 12:50:52 +00:00
le_streamer: use new ATT connect/disconnect events
This commit is contained in:
parent
6187ad4c7c
commit
036861b773
@ -218,7 +218,7 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
UNUSED(size);
|
||||
|
||||
uint16_t conn_interval;
|
||||
le_streamer_connection_t * context;
|
||||
hci_con_handle_t con_handle;
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
@ -229,36 +229,27 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
}
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
context = connection_for_conn_handle(hci_event_disconnection_complete_get_connection_handle(packet));
|
||||
if (!context) break;
|
||||
// free connection
|
||||
printf("%c: Disconnect, reason %02x\n", context->name, hci_event_disconnection_complete_get_reason(packet));
|
||||
context->le_notification_enabled = 0;
|
||||
context->connection_handle = HCI_CON_HANDLE_INVALID;
|
||||
con_handle = hci_event_disconnection_complete_get_connection_handle(packet);
|
||||
printf("- LE Connection %04x: disconnect, reason %02x\n", con_handle, hci_event_disconnection_complete_get_reason(packet));
|
||||
break;
|
||||
case HCI_EVENT_LE_META:
|
||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||
// setup new
|
||||
context = connection_for_conn_handle(HCI_CON_HANDLE_INVALID);
|
||||
if (!context) break;
|
||||
context->counter = 'A';
|
||||
context->test_data_len = ATT_DEFAULT_MTU - 3;
|
||||
context->connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
||||
// print connection parameters (without using float operations)
|
||||
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
||||
printf("%c: Connection Interval: %u.%02u ms, latency %u\n", context->name, conn_interval * 125 / 100,
|
||||
printf("- LE Connection %04x: connected - connection interval %u.%02u ms, latency %u\n", con_handle, conn_interval * 125 / 100,
|
||||
25 * (conn_interval & 3), hci_subevent_le_connection_complete_get_conn_latency(packet));
|
||||
|
||||
// request min con interval 15 ms for iOS 11+
|
||||
// gap_request_connection_parameter_update(context->connection_handle, 12, 12, 0, 0x0048);
|
||||
printf("- LE Connection %04x: request 15 ms connection interval\n", con_handle);
|
||||
gap_request_connection_parameter_update(con_handle, 12, 12, 0, 0x0048);
|
||||
break;
|
||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||
// print connection parameters (without using float operations)
|
||||
context = connection_for_conn_handle(hci_subevent_le_connection_update_complete_get_connection_handle(packet));
|
||||
if (!context) break;
|
||||
con_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
||||
conn_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
||||
printf("%c: Connection Interval: %u.%02u ms, latency %u\n", context->name, conn_interval * 125 / 100,
|
||||
printf("- LE Connection %04x: connection update - connection interval %u.%02u ms, latency %u\n", con_handle, conn_interval * 125 / 100,
|
||||
25 * (conn_interval & 3), hci_subevent_le_connection_update_complete_get_conn_latency(packet));
|
||||
break;
|
||||
default:
|
||||
@ -289,6 +280,15 @@ static void att_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
case ATT_EVENT_CONNECTED:
|
||||
// setup new
|
||||
context = connection_for_conn_handle(HCI_CON_HANDLE_INVALID);
|
||||
if (!context) break;
|
||||
context->counter = 'A';
|
||||
context->test_data_len = ATT_DEFAULT_MTU - 3;
|
||||
context->connection_handle = att_event_connected_get_handle(packet);
|
||||
printf("%c: ATT connected, handle %04x, test data len %u\n", context->name, context->connection_handle, context->test_data_len);
|
||||
break;
|
||||
case ATT_EVENT_MTU_EXCHANGE_COMPLETE:
|
||||
mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3;
|
||||
context = connection_for_conn_handle(att_event_mtu_exchange_complete_get_handle(packet));
|
||||
@ -299,6 +299,14 @@ static void att_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
case ATT_EVENT_CAN_SEND_NOW:
|
||||
streamer();
|
||||
break;
|
||||
case ATT_EVENT_DISCONNECTED:
|
||||
context = connection_for_conn_handle(att_event_disconnected_get_handle(packet));
|
||||
if (!context) break;
|
||||
// free connection
|
||||
printf("%c: ATT disconnected, handle %04x\n", context->name, context->connection_handle);
|
||||
context->le_notification_enabled = 0;
|
||||
context->connection_handle = HCI_CON_HANDLE_INVALID;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user