mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 17:42:51 +00:00
example: use GAP_SUBEVENT_LE_CONNECTION_COMPLETE instead of HCI_SUBEVENT_LE_CONNECTION_COMPLETE
This commit is contained in:
parent
9d1eff910d
commit
bba4819655
@ -212,16 +212,16 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* LISTING_RESUME */
|
/* LISTING_RESUME */
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// Wait for connection complete
|
// Wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
|
|
||||||
/* LISTING_PAUSE */
|
/* LISTING_PAUSE */
|
||||||
if (app_state != APP_STATE_W4_CONNECT) return;
|
if (app_state != APP_STATE_W4_CONNECT) return;
|
||||||
|
|
||||||
/* LISTING_RESUME */
|
/* LISTING_RESUME */
|
||||||
// Get connection handle from event
|
// Get connection handle from event
|
||||||
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
connection_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
|
|
||||||
// Connect to remote Battery Service.
|
// Connect to remote Battery Service.
|
||||||
// On succesful connection, the client tries to register for notifications. If notifications
|
// On succesful connection, the client tries to register for notifications. If notifications
|
||||||
|
@ -200,11 +200,11 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
|||||||
gap_stop_scan();
|
gap_stop_scan();
|
||||||
gap_connect(report.address,report.address_type);
|
gap_connect(report.address,report.address_type);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
// wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
printf("\nGATT browser - CONNECTED\n");
|
printf("\nGATT browser - CONNECTED\n");
|
||||||
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
connection_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
// query primary services
|
// query primary services
|
||||||
gatt_client_discover_primary_services(handle_gatt_client_event, connection_handle);
|
gatt_client_discover_primary_services(handle_gatt_client_event, connection_handle);
|
||||||
break;
|
break;
|
||||||
|
@ -210,16 +210,16 @@ static void hci_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* LISTING_RESUME */
|
/* LISTING_RESUME */
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
// wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
|
|
||||||
/* LISTING_PAUSE */
|
/* LISTING_PAUSE */
|
||||||
if (app_state != APP_STATE_W4_CONNECT) return;
|
if (app_state != APP_STATE_W4_CONNECT) return;
|
||||||
|
|
||||||
/* LISTING_RESUME */
|
/* LISTING_RESUME */
|
||||||
// get connection handle from event
|
// get connection handle from event
|
||||||
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
connection_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
|
|
||||||
// Connect to remote Device Information Service. The client will query the remote service and emit events,
|
// Connect to remote Device Information Service. The client will query the remote service and emit events,
|
||||||
// that will be passed on to gatt_client_event_handler.
|
// that will be passed on to gatt_client_event_handler.
|
||||||
|
@ -312,15 +312,15 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
|||||||
printf("Stop scan. Connect to device with addr %s.\n", bd_addr_to_str(le_streamer_addr));
|
printf("Stop scan. Connect to device with addr %s.\n", bd_addr_to_str(le_streamer_addr));
|
||||||
gap_connect(le_streamer_addr,le_streamer_addr_type);
|
gap_connect(le_streamer_addr,le_streamer_addr_type);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
// wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
if (state != TC_W4_CONNECT) return;
|
if (state != TC_W4_CONNECT) return;
|
||||||
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
connection_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
conn_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
|
||||||
printf("Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
printf("Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||||
printf("Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet));
|
printf("Connection Latency: %u\n", gap_subevent_le_connection_complete_get_conn_latency(packet));
|
||||||
// initialize gatt client context with handle, and add it to the list of active clients
|
// initialize gatt client context with handle, and add it to the list of active clients
|
||||||
// query primary services
|
// query primary services
|
||||||
printf("Search for Heart Rate service.\n");
|
printf("Search for Heart Rate service.\n");
|
||||||
|
@ -259,19 +259,25 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
|||||||
con_handle = hci_event_disconnection_complete_get_connection_handle(packet);
|
con_handle = hci_event_disconnection_complete_get_connection_handle(packet);
|
||||||
printf("- LE Connection 0x%04x: disconnect, reason %02x\n", con_handle, hci_event_disconnection_complete_get_reason(packet));
|
printf("- LE Connection 0x%04x: disconnect, reason %02x\n", con_handle, hci_event_disconnection_complete_get_reason(packet));
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
con_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
conn_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
|
||||||
printf("- LE Connection 0x%04x: connected - connection interval %u.%02u ms, latency %u\n", con_handle, conn_interval * 125 / 100,
|
printf("- LE Connection 0x%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));
|
25 * (conn_interval & 3), gap_subevent_le_connection_complete_get_conn_latency(packet));
|
||||||
|
|
||||||
// request min con interval 15 ms for iOS 11+
|
// request min con interval 15 ms for iOS 11+
|
||||||
printf("- LE Connection 0x%04x: request 15 ms connection interval\n", con_handle);
|
printf("- LE Connection 0x%04x: request 15 ms connection interval\n", con_handle);
|
||||||
gap_request_connection_parameter_update(con_handle, 12, 12, 4, 0x0048);
|
gap_request_connection_parameter_update(con_handle, 12, 12, 4, 0x0048);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case HCI_EVENT_LE_META:
|
||||||
|
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
con_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
con_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
||||||
|
@ -503,12 +503,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
btstack_run_loop_set_timer_handler(&connection_timer, &hog_reconnect_timeout);
|
btstack_run_loop_set_timer_handler(&connection_timer, &hog_reconnect_timeout);
|
||||||
btstack_run_loop_add_timer(&connection_timer);
|
btstack_run_loop_add_timer(&connection_timer);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
// wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
if (app_state != W4_CONNECTED) return;
|
if (app_state != W4_CONNECTED) return;
|
||||||
btstack_run_loop_remove_timer(&connection_timer);
|
btstack_run_loop_remove_timer(&connection_timer);
|
||||||
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
connection_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
// request security
|
// request security
|
||||||
app_state = W4_ENCRYPTED;
|
app_state = W4_ENCRYPTED;
|
||||||
sm_request_pairing(connection_handle);
|
sm_request_pairing(connection_handle);
|
||||||
|
@ -421,12 +421,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
btstack_run_loop_set_timer_handler(&connection_timer, &hog_reconnect_timeout);
|
btstack_run_loop_set_timer_handler(&connection_timer, &hog_reconnect_timeout);
|
||||||
btstack_run_loop_add_timer(&connection_timer);
|
btstack_run_loop_add_timer(&connection_timer);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
// wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
if (app_state != W4_CONNECTED) return;
|
if (app_state != W4_CONNECTED) return;
|
||||||
btstack_run_loop_remove_timer(&connection_timer);
|
btstack_run_loop_remove_timer(&connection_timer);
|
||||||
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
connection_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
// request security
|
// request security
|
||||||
app_state = W4_ENCRYPTED;
|
app_state = W4_ENCRYPTED;
|
||||||
sm_request_pairing(connection_handle);
|
sm_request_pairing(connection_handle);
|
||||||
|
@ -331,15 +331,21 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
case L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE:
|
case L2CAP_EVENT_CONNECTION_PARAMETER_UPDATE_RESPONSE:
|
||||||
printf("L2CAP Connection Parameter Update Complete, response: %x\n", l2cap_event_connection_parameter_update_response_get_result(packet));
|
printf("L2CAP Connection Parameter Update Complete, response: %x\n", l2cap_event_connection_parameter_update_response_get_result(packet));
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
conn_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
|
||||||
printf("LE Connection Complete:\n");
|
printf("LE Connection Complete:\n");
|
||||||
printf("- Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
printf("- Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||||
printf("- Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet));
|
printf("- Connection Latency: %u\n", gap_subevent_le_connection_complete_get_conn_latency(packet));
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case HCI_EVENT_LE_META:
|
||||||
|
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
conn_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
conn_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
||||||
|
@ -232,15 +232,15 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
|||||||
printf("Stop scan. Connect to device with addr %s.\n", bd_addr_to_str(le_cbm_server_addr));
|
printf("Stop scan. Connect to device with addr %s.\n", bd_addr_to_str(le_cbm_server_addr));
|
||||||
gap_connect(le_cbm_server_addr, le_cbm_server_addr_type);
|
gap_connect(le_cbm_server_addr, le_cbm_server_addr_type);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
// wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
if (state != TC_W4_CONNECT) return;
|
if (state != TC_W4_CONNECT) return;
|
||||||
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
connection_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
conn_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
|
||||||
printf("Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
printf("Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||||
printf("Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet));
|
printf("Connection Latency: %u\n", gap_subevent_le_connection_complete_get_conn_latency(packet));
|
||||||
// initialize gatt client context with handle, and add it to the list of active clients
|
// initialize gatt client context with handle, and add it to the list of active clients
|
||||||
// query primary services
|
// query primary services
|
||||||
printf("Connect to performance test service.\n");
|
printf("Connect to performance test service.\n");
|
||||||
|
@ -189,13 +189,13 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
printf("%c: Disconnect, reason 0x%02x\n", le_cbm_connection.name, hci_event_disconnection_complete_get_reason(packet));
|
printf("%c: Disconnect, reason 0x%02x\n", le_cbm_connection.name, hci_event_disconnection_complete_get_reason(packet));
|
||||||
le_cbm_connection.connection_handle = HCI_CON_HANDLE_INVALID;
|
le_cbm_connection.connection_handle = HCI_CON_HANDLE_INVALID;
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
conn_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
|
||||||
printf("%c: Connection Interval: %u.%02u ms\n", le_cbm_connection.name, conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
printf("%c: Connection Interval: %u.%02u ms\n", le_cbm_connection.name, conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||||
printf("%c: Connection Latency: %u\n", le_cbm_connection.name, hci_subevent_le_connection_complete_get_conn_latency(packet));
|
printf("%c: Connection Latency: %u\n", le_cbm_connection.name, gap_subevent_le_connection_complete_get_conn_latency(packet));
|
||||||
|
|
||||||
// min con interval 15 ms - supported from iOS 11
|
// min con interval 15 ms - supported from iOS 11
|
||||||
gap_request_connection_parameter_update(le_cbm_connection.connection_handle, 12, 12, 4, 0x0048);
|
gap_request_connection_parameter_update(le_cbm_connection.connection_handle, 12, 12, 4, 0x0048);
|
||||||
@ -203,6 +203,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
//
|
//
|
||||||
test_reset(&le_cbm_connection);
|
test_reset(&le_cbm_connection);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case HCI_EVENT_LE_META:
|
||||||
|
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
conn_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
conn_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet);
|
||||||
|
@ -398,13 +398,13 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
|||||||
if (hci_event_command_complete_get_return_parameters(packet)[0] == ERROR_CODE_SUCCESS) break;
|
if (hci_event_command_complete_get_return_parameters(packet)[0] == ERROR_CODE_SUCCESS) break;
|
||||||
printf("%s", adv_failed_warning);
|
printf("%s", adv_failed_warning);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
// wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
switch (state){
|
switch (state){
|
||||||
case TC_W4_CONNECT:
|
case TC_W4_CONNECT:
|
||||||
state = TC_CONNECTED;
|
state = TC_CONNECTED;
|
||||||
remote_peripheral_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
remote_peripheral_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
printf("[-] Peripheral connected\n");
|
printf("[-] Peripheral connected\n");
|
||||||
mitm_start_advertising();
|
mitm_start_advertising();
|
||||||
printf ("You can connect now!\n");
|
printf ("You can connect now!\n");
|
||||||
@ -412,7 +412,7 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
|||||||
mitm_console_connected_menu();
|
mitm_console_connected_menu();
|
||||||
break;
|
break;
|
||||||
case TC_CONNECTED:
|
case TC_CONNECTED:
|
||||||
remote_central_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
remote_central_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
printf("[-] Central connected!\n");
|
printf("[-] Central connected!\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -419,22 +419,34 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
|||||||
le_stream_server_found();
|
le_stream_server_found();
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
switch (hci_event_le_meta_get_subevent_code(packet)){
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
if (state != TC_W4_CONNECT) return;
|
if (state != TC_W4_CONNECT) return;
|
||||||
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
connection_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
conn_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
|
||||||
printf("Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
printf("Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||||
printf("Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet));
|
printf("Connection Latency: %u\n", gap_subevent_le_connection_complete_get_conn_latency(packet));
|
||||||
// initialize gatt client context with handle, and add it to the list of active clients
|
// initialize gatt client context with handle, and add it to the list of active clients
|
||||||
// query primary services
|
// query primary services
|
||||||
printf("Search for LE Streamer service.\n");
|
printf("Search for LE Streamer service.\n");
|
||||||
state = TC_W4_SERVICE_RESULT;
|
state = TC_W4_SERVICE_RESULT;
|
||||||
gatt_client_discover_primary_services_by_uuid128(handle_gatt_client_event, connection_handle, le_streamer_service_uuid);
|
gatt_client_discover_primary_services_by_uuid128(handle_gatt_client_event, connection_handle, le_streamer_service_uuid);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case HCI_EVENT_LE_META:
|
||||||
|
// wait for connection complete
|
||||||
|
switch (hci_event_le_meta_get_subevent_code(packet)){
|
||||||
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE:
|
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE:
|
||||||
con_handle = hci_subevent_le_data_length_change_get_connection_handle(packet);
|
con_handle = hci_subevent_le_data_length_change_get_connection_handle(packet);
|
||||||
printf("- LE Connection 0x%04x: data length change - max %u bytes per packet\n", con_handle,
|
printf("- LE Connection 0x%04x: data length change - max %u bytes per packet\n", con_handle,
|
||||||
|
@ -179,19 +179,32 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
|||||||
printf("To start the streaming, please run nRF Toolbox -> UART to connect.\n");
|
printf("To start the streaming, please run nRF Toolbox -> UART to connect.\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
con_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
conn_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
|
||||||
printf("LE Connection - Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
printf("LE Connection - Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||||
printf("LE Connection - Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet));
|
printf("LE Connection - Connection Latency: %u\n", gap_subevent_le_connection_complete_get_conn_latency(packet));
|
||||||
|
|
||||||
// request min con interval 15 ms for iOS 11+
|
// request min con interval 15 ms for iOS 11+
|
||||||
printf("LE Connection - Request 15 ms connection interval\n");
|
printf("LE Connection - Request 15 ms connection interval\n");
|
||||||
gap_request_connection_parameter_update(con_handle, 12, 12, 4, 0x0048);
|
gap_request_connection_parameter_update(con_handle, 12, 12, 4, 0x0048);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HCI_EVENT_LE_META:
|
||||||
|
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
con_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
con_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
||||||
|
@ -196,10 +196,10 @@ static void hci_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
|||||||
gap_connect(address,address_type);
|
gap_connect(address,address_type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
// wait for connection complete
|
// wait for connection complete
|
||||||
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
if (hci_event_gap_meta_get_subevent_code(packet) != GAP_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||||
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
con_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
printf("Connection complete\n");
|
printf("Connection complete\n");
|
||||||
|
|
||||||
// for testing, choose one of the following actions
|
// for testing, choose one of the following actions
|
||||||
|
@ -181,11 +181,11 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
|
||||||
switch (hci_event_packet_get_type(packet)) {
|
switch (hci_event_packet_get_type(packet)) {
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
printf("Connection complete\n");
|
printf("Connection complete\n");
|
||||||
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
con_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
UNUSED(con_handle);
|
UNUSED(con_handle);
|
||||||
|
|
||||||
// for testing, choose one of the following actions
|
// for testing, choose one of the following actions
|
||||||
|
@ -221,20 +221,26 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
|||||||
printf("SSP User Confirmation Auto accept\n");
|
printf("SSP User Confirmation Auto accept\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_LE_META:
|
case HCI_EVENT_META_GAP:
|
||||||
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
switch (hci_event_gap_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
case GAP_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
|
con_handle = gap_subevent_le_connection_complete_get_connection_handle(packet);
|
||||||
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
|
conn_interval = gap_subevent_le_connection_complete_get_conn_interval(packet);
|
||||||
printf("LE Connection - Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
printf("LE Connection - Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
|
||||||
printf("LE Connection - Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet));
|
printf("LE Connection - Connection Latency: %u\n", gap_subevent_le_connection_complete_get_conn_latency(packet));
|
||||||
|
|
||||||
// request min con interval 15 ms for iOS 11+
|
// request min con interval 15 ms for iOS 11+
|
||||||
printf("LE Connection - Request 15 ms connection interval\n");
|
printf("LE Connection - Request 15 ms connection interval\n");
|
||||||
gap_request_connection_parameter_update(con_handle, 12, 12, 4, 0x0048);
|
gap_request_connection_parameter_update(con_handle, 12, 12, 4, 0x0048);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HCI_EVENT_LE_META:
|
||||||
|
switch (hci_event_le_meta_get_subevent_code(packet)) {
|
||||||
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE:
|
||||||
// print connection parameters (without using float operations)
|
// print connection parameters (without using float operations)
|
||||||
con_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
con_handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user