example: gatt_streamer_server and le_streamer_client report DLE and PHY changes

This commit is contained in:
Matthias Ringwald 2023-01-23 11:10:15 +01:00
parent 6bbe12ba1f
commit f4fc15d4ec
3 changed files with 51 additions and 17 deletions

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- HCI_ACL_CHUNK_SIZE_ALIGNMENT allows to keep HCI transport writes aligned - HCI_ACL_CHUNK_SIZE_ALIGNMENT allows to keep HCI transport writes aligned
- HFP: provide SCO packet types and rx/tx packet lengths in HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED - HFP: provide SCO packet types and rx/tx packet lengths in HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED
- Port for Renesas RA6M4 with DA14531 - Port for Renesas RA6M4 with DA14531
- example: gatt_streamer_server and le_streamer_client report DLE and PHY changes
## Fixed ## Fixed
- btstack_stdin_embedded: use timer to poll RTT input, fix for tickless RTOS - btstack_stdin_embedded: use timer to poll RTT input, fix for tickless RTOS

View File

@ -240,10 +240,13 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
UNUSED(channel); UNUSED(channel);
UNUSED(size); UNUSED(size);
if (packet_type != HCI_EVENT_PACKET) return;
uint16_t conn_interval; uint16_t conn_interval;
hci_con_handle_t con_handle; hci_con_handle_t con_handle;
static const char * const phy_names[] = {
if (packet_type != HCI_EVENT_PACKET) return; "1 M", "2 M", "Codec"
};
switch (hci_event_packet_get_type(packet)) { switch (hci_event_packet_get_type(packet)) {
case BTSTACK_EVENT_STATE: case BTSTACK_EVENT_STATE:
@ -276,6 +279,16 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
printf("- LE Connection 0x%04x: connection update - connection interval %u.%02u ms, latency %u\n", con_handle, conn_interval * 125 / 100, printf("- LE Connection 0x%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)); 25 * (conn_interval & 3), hci_subevent_le_connection_update_complete_get_conn_latency(packet));
break; break;
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE:
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,
hci_subevent_le_data_length_change_get_max_tx_octets(packet));
break;
case HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE:
con_handle = hci_subevent_le_phy_update_complete_get_connection_handle(packet);
printf("- LE Connection 0x%04x: PHY update - using LE %s PHY now\n", con_handle,
phy_names[hci_subevent_le_phy_update_complete_get_tx_phy(packet)]);
break;
default: default:
break; break;
} }

View File

@ -351,10 +351,15 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
UNUSED(size); UNUSED(size);
if (packet_type != HCI_EVENT_PACKET) return; if (packet_type != HCI_EVENT_PACKET) return;
static const char * const phy_names[] = {
"1 M", "2 M", "Codec"
};
uint16_t conn_interval; uint16_t conn_interval;
uint8_t event = hci_event_packet_get_type(packet); hci_con_handle_t con_handle;
switch (event) {
switch (hci_event_packet_get_type(packet)) {
case BTSTACK_EVENT_STATE: case BTSTACK_EVENT_STATE:
// BTstack activated, get started // BTstack activated, get started
if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING) { if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING) {
@ -378,18 +383,33 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
break; break;
case HCI_EVENT_LE_META: case HCI_EVENT_LE_META:
// wait for connection complete // wait for connection complete
if (hci_event_le_meta_get_subevent_code(packet) != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break; switch (hci_event_le_meta_get_subevent_code(packet)){
if (state != TC_W4_CONNECT) return; case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet); if (state != TC_W4_CONNECT) return;
// print connection parameters (without using float operations) connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet); // print connection parameters (without using float operations)
printf("Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3)); conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet);
printf("Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet)); printf("Connection Interval: %u.%02u ms\n", conn_interval * 125 / 100, 25 * (conn_interval & 3));
// initialize gatt client context with handle, and add it to the list of active clients printf("Connection Latency: %u\n", hci_subevent_le_connection_complete_get_conn_latency(packet));
// query primary services // initialize gatt client context with handle, and add it to the list of active clients
printf("Search for LE Streamer service.\n"); // query primary services
state = TC_W4_SERVICE_RESULT; printf("Search for LE Streamer service.\n");
gatt_client_discover_primary_services_by_uuid128(handle_gatt_client_event, connection_handle, le_streamer_service_uuid); state = TC_W4_SERVICE_RESULT;
gatt_client_discover_primary_services_by_uuid128(handle_gatt_client_event, connection_handle, le_streamer_service_uuid);
break;
case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE:
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,
hci_subevent_le_data_length_change_get_max_tx_octets(packet));
break;
case HCI_SUBEVENT_LE_PHY_UPDATE_COMPLETE:
con_handle = hci_subevent_le_phy_update_complete_get_connection_handle(packet);
printf("- LE Connection 0x%04x: PHY update - using LE %s PHY now\n", con_handle,
phy_names[hci_subevent_le_phy_update_complete_get_tx_phy(packet)]);
break;
default:
break;
}
break; break;
case HCI_EVENT_DISCONNECTION_COMPLETE: case HCI_EVENT_DISCONNECTION_COMPLETE:
// unregister listener // unregister listener