mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-09 21:45:54 +00:00
examples: use btstack_event.h
getters instead of direct array access, use enum to compare status codes
This commit is contained in:
parent
d04d6ac3e2
commit
6058cb0da7
@ -57,7 +57,8 @@ Nordic SPP Service Server: use `GATTSERVICE_SUBEVENT_SPP_SERVICE_CONNECTED` and
|
||||
u-blox SPP Service Server: use `GATTSERVICE_SUBEVENT_SPP_SERVICE_CONNECTED` and `GATTSERVICE_SUBEVENT_SPP_SERVICE_CONNECTED`
|
||||
events instead of callback, and `RFCOMM_DATA_PACKET` for received data
|
||||
HSP AG: emit HSP_SUBEVENT_BUTTON_PRESSED instead of audio connection setup/release
|
||||
|
||||
Examples: use `btstack_event.h` getters instead of direct array access, use enum to compare status codes
|
||||
|
||||
## Release v1.3.2
|
||||
|
||||
### Added
|
||||
|
@ -488,7 +488,7 @@ static void handle_l2cap_media_data_packet(uint8_t seid, uint8_t *packet, uint16
|
||||
sbc_frame_size = (size-pos)/ sbc_header.num_frames;
|
||||
|
||||
int status = btstack_ring_buffer_write(&sbc_frame_ring_buffer, packet+pos, size-pos);
|
||||
if (status){
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("Error storing samples in SBC ring buffer!!!\n");
|
||||
}
|
||||
|
||||
@ -866,7 +866,7 @@ static void a2dp_sink_packet_handler(uint8_t packet_type, uint16_t channel, uint
|
||||
case A2DP_SUBEVENT_STREAM_ESTABLISHED:
|
||||
a2dp_subevent_stream_established_get_bd_addr(packet, address);
|
||||
status = a2dp_subevent_stream_established_get_status(packet);
|
||||
if (status){
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("A2DP Sink : Streaming connection failed, status 0x%02x\n", status);
|
||||
break;
|
||||
}
|
||||
|
@ -650,7 +650,7 @@ static void a2dp_source_packet_handler(uint8_t packet_type, uint16_t channel, ui
|
||||
case A2DP_SUBEVENT_STREAM_ESTABLISHED:
|
||||
a2dp_subevent_stream_established_get_bd_addr(packet, address);
|
||||
status = a2dp_subevent_stream_established_get_status(packet);
|
||||
if (status){
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("A2DP Source: Stream failed, status 0x%02x.\n", status);
|
||||
break;
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ static void a2dp_sink_packet_handler(uint8_t packet_type, uint16_t channel, uint
|
||||
a2dp_subevent_stream_established_get_bd_addr(packet, address);
|
||||
status = a2dp_subevent_stream_established_get_status(packet);
|
||||
|
||||
if (status){
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("A2DP Sink : Streaming connection failed, status 0x%02x\n", status);
|
||||
break;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
case HCI_EVENT_COMMAND_COMPLETE:
|
||||
if (hci_event_command_complete_get_command_opcode(packet) == hci_enable_device_under_test_mode.opcode){
|
||||
uint8_t status = hci_event_command_complete_get_return_parameters(packet)[0];
|
||||
printf("Enable Device Under Test Mode: %s\n", status ? "Failed" : "OK");
|
||||
printf("Enable Device Under Test Mode: %s\n", (status != ERROR_CODE_SUCCESS) ? "Failed" : "OK");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -63,6 +63,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
break;
|
||||
case GAP_EVENT_DEDICATED_BONDING_COMPLETED:
|
||||
printf("GAP Dedicated Bonding Complete, status %u\n", packet[2]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -136,6 +136,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
|
||||
uint16_t heart_rate;
|
||||
uint8_t sensor_contact;
|
||||
uint8_t att_status;
|
||||
|
||||
switch(state){
|
||||
case TC_W4_SERVICE_RESULT:
|
||||
@ -145,8 +146,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
gatt_event_service_query_result_get_service(packet, &heart_rate_service);
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (packet[4] != 0){
|
||||
printf("SERVICE_QUERY_RESULT - Error status %x.\n", packet[4]);
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS){
|
||||
printf("SERVICE_QUERY_RESULT - Error status %x.\n", att_status);
|
||||
gap_disconnect(connection_handle);
|
||||
break;
|
||||
}
|
||||
@ -165,8 +167,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
gatt_event_characteristic_query_result_get_characteristic(packet, &heart_rate_measurement_characteristic);
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (packet[4] != 0){
|
||||
printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", packet[4]);
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS){
|
||||
printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", att_status);
|
||||
gap_disconnect(connection_handle);
|
||||
break;
|
||||
}
|
||||
@ -205,7 +208,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
gatt_event_characteristic_query_result_get_characteristic(packet, &body_sensor_location_characteristic);
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (packet[4] != 0){
|
||||
if (gatt_event_query_complete_get_att_status(packet) != ATT_ERROR_SUCCESS){
|
||||
printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", packet[4]);
|
||||
state = TC_CONNECTED;
|
||||
break;
|
||||
|
@ -423,6 +423,7 @@ static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle,
|
||||
break;
|
||||
default:
|
||||
printf("Write to 0x%04x, len %u\n", att_handle, buffer_size);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
switch (hci_event_hfp_meta_get_subevent_code(event)) {
|
||||
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
|
||||
status = hfp_subevent_service_level_connection_established_get_status(event);
|
||||
if (status){
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("Connection failed, staus 0x%02x\n", status);
|
||||
break;
|
||||
}
|
||||
@ -482,7 +482,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
acl_handle = HCI_CON_HANDLE_INVALID;
|
||||
break;
|
||||
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
||||
if (hfp_subevent_audio_connection_established_get_status(event)){
|
||||
if (hfp_subevent_audio_connection_established_get_status(event) != ERROR_CODE_SUCCESS){
|
||||
printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event));
|
||||
} else {
|
||||
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
|
||||
|
@ -451,7 +451,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
break;
|
||||
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (event[0]){
|
||||
switch (hci_event_packet_get_type(event)){
|
||||
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
||||
sco_demo_send(sco_handle);
|
||||
break;
|
||||
@ -463,7 +463,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
break;
|
||||
|
||||
case HCI_EVENT_HFP_META:
|
||||
switch (event[2]) {
|
||||
switch (hci_event_hfp_meta_get_subevent_code(event)) {
|
||||
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
|
||||
acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
|
||||
hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr);
|
||||
@ -474,8 +474,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
printf("Service level connection released.\n\n");
|
||||
break;
|
||||
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
||||
if (hfp_subevent_audio_connection_established_get_status(event)){
|
||||
printf("Audio connection establishment failed with status 0x%02x\n", hfp_subevent_audio_connection_established_get_status(event));
|
||||
status = hfp_subevent_audio_connection_established_get_status(event);
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("Audio connection establishment failed with status 0x%02x\n", status);
|
||||
} else {
|
||||
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
@ -503,9 +504,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
case HFP_SUBEVENT_COMPLETE:
|
||||
status = hfp_subevent_complete_get_status(event);
|
||||
if (status == ERROR_CODE_SUCCESS){
|
||||
printf("Cmd \'%c\' succeded\n", cmd);
|
||||
printf("Cmd \'%c\' succeeded\n", cmd);
|
||||
} else {
|
||||
printf("Cmd \'%c\' failed with status 0x%02x\n", cmd, hfp_subevent_complete_get_status(event));
|
||||
printf("Cmd \'%c\' failed with status 0x%02x\n", cmd, status);
|
||||
}
|
||||
break;
|
||||
case HFP_SUBEVENT_AG_INDICATOR_STATUS_CHANGED:
|
||||
@ -523,7 +524,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
(char *) hfp_subevent_network_operator_changed_get_network_operator_name(event));
|
||||
break;
|
||||
case HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR:
|
||||
printf("EXTENDED_AUDIO_GATEWAY_ERROR_REPORT, status : %d\n",
|
||||
printf("EXTENDED_AUDIO_GATEWAY_ERROR_REPORT, status : 0x%02x\n",
|
||||
hfp_subevent_extended_audio_gateway_error_get_error(event));
|
||||
break;
|
||||
case HFP_SUBEVENT_RING:
|
||||
@ -555,7 +556,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
printf(" - number : %s \n", hfp_subevent_enhanced_call_status_get_bnip_number(event));
|
||||
break;
|
||||
default:
|
||||
printf("event not handled 0x%02x\n", event[2]);
|
||||
printf("event not handled 0x%02x\n", hci_event_hfp_meta_get_subevent_code(event));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -309,7 +309,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * pack
|
||||
uint8_t status;
|
||||
switch (packet_type){
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (packet[0]){
|
||||
switch (hci_event_packet_get_type(packet)){
|
||||
case BTSTACK_EVENT_STATE:
|
||||
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
|
||||
app_state = APP_NOT_CONNECTED;
|
||||
@ -325,7 +325,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * pack
|
||||
switch (hci_event_hid_meta_get_subevent_code(packet)){
|
||||
case HID_SUBEVENT_CONNECTION_OPENED:
|
||||
status = hid_subevent_connection_opened_get_status(packet);
|
||||
if (status) {
|
||||
if (status != ERROR_CODE_SUCCESS) {
|
||||
// outgoing connection failed
|
||||
printf("Connection failed, status 0x%x\n", status);
|
||||
app_state = APP_NOT_CONNECTED;
|
||||
|
@ -230,7 +230,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * pack
|
||||
UNUSED(packet_size);
|
||||
switch (packet_type){
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (packet[0]){
|
||||
switch (hci_event_packet_get_type(packet)){
|
||||
case HCI_EVENT_USER_CONFIRMATION_REQUEST:
|
||||
// ssp: inform about user confirmation request
|
||||
log_info("SSP User Confirmation Request with numeric value '%06"PRIu32"'\n", hci_event_user_confirmation_request_get_numeric_value(packet));
|
||||
@ -240,7 +240,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * pack
|
||||
case HCI_EVENT_HID_META:
|
||||
switch (hci_event_hid_meta_get_subevent_code(packet)){
|
||||
case HID_SUBEVENT_CONNECTION_OPENED:
|
||||
if (hid_subevent_connection_opened_get_status(packet)) return;
|
||||
if (hid_subevent_connection_opened_get_status(packet) != ERROR_CODE_SUCCESS) return;
|
||||
hid_cid = hid_subevent_connection_opened_get_hid_cid(packet);
|
||||
#ifdef HAVE_BTSTACK_STDIN
|
||||
printf("HID Connected, control mouse using 'a','s',''d', 'w' keys for movement and 'l' and 'r' for buttons...\n");
|
||||
|
@ -341,6 +341,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
UNUSED(channel);
|
||||
UNUSED(size);
|
||||
gatt_client_characteristic_t characteristic;
|
||||
uint8_t att_status;
|
||||
static uint8_t boot_protocol_mode = 0;
|
||||
|
||||
switch (app_state) {
|
||||
@ -351,8 +352,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
gatt_event_service_query_result_get_service(packet, &hid_service);
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (gatt_event_query_complete_get_att_status(packet) != ATT_ERROR_SUCCESS) {
|
||||
printf("ATT Error status %x.\n", gatt_event_query_complete_get_att_status(packet));
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS) {
|
||||
printf("ATT Error status %x.\n", att_status);
|
||||
handle_outgoing_connection_error();
|
||||
break;
|
||||
}
|
||||
@ -387,8 +389,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
}
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (gatt_event_query_complete_get_att_status(packet) != ATT_ERROR_SUCCESS) {
|
||||
printf("ATT Error status %x.\n", gatt_event_query_complete_get_att_status(packet));
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS) {
|
||||
printf("ATT Error status %x.\n", att_status);
|
||||
handle_outgoing_connection_error();
|
||||
break;
|
||||
}
|
||||
@ -403,8 +406,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
case W4_BOOT_KEYBOARD_ENABLED:
|
||||
switch (hci_event_packet_get_type(packet)){
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (gatt_event_query_complete_get_att_status(packet) != ATT_ERROR_SUCCESS) {
|
||||
printf("ATT Error status %x.\n", gatt_event_query_complete_get_att_status(packet));
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS) {
|
||||
printf("ATT Error status %x.\n", att_status);
|
||||
handle_outgoing_connection_error();
|
||||
break;
|
||||
}
|
||||
@ -422,8 +426,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
case W4_BOOT_MOUSE_ENABLED:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (gatt_event_query_complete_get_att_status(packet) != ATT_ERROR_SUCCESS) {
|
||||
printf("ATT Error status %x.\n", gatt_event_query_complete_get_att_status(packet));
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS) {
|
||||
printf("ATT Error status %x.\n", att_status);
|
||||
handle_outgoing_connection_error();
|
||||
break;
|
||||
}
|
||||
|
@ -182,6 +182,7 @@ static void stdin_process(char c){
|
||||
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
|
||||
UNUSED(channel);
|
||||
uint8_t status;
|
||||
|
||||
switch (packet_type){
|
||||
case HCI_SCO_DATA_PACKET:
|
||||
@ -202,10 +203,11 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
sco_demo_send(sco_handle);
|
||||
break;
|
||||
case HCI_EVENT_HSP_META:
|
||||
switch (event[2]) {
|
||||
switch (hci_event_hsp_meta_get_subevent_code(event)) {
|
||||
case HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE:
|
||||
if (hsp_subevent_rfcomm_connection_complete_get_status(event)){
|
||||
printf("RFCOMM connection establishement failed with status %u\n", hsp_subevent_rfcomm_connection_complete_get_status(event));
|
||||
status = hsp_subevent_rfcomm_connection_complete_get_status(event);
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("RFCOMM connection establishement failed with status %u\n", status);
|
||||
break;
|
||||
}
|
||||
printf("RFCOMM connection established.\n");
|
||||
@ -215,15 +217,17 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
#endif
|
||||
break;
|
||||
case HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE:
|
||||
if (hsp_subevent_rfcomm_disconnection_complete_get_status(event)){
|
||||
printf("RFCOMM disconnection failed with status %u.\n", hsp_subevent_rfcomm_disconnection_complete_get_status(event));
|
||||
status = hsp_subevent_rfcomm_disconnection_complete_get_status(event);
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("RFCOMM disconnection failed with status %u.\n", status);
|
||||
} else {
|
||||
printf("RFCOMM disconnected.\n");
|
||||
}
|
||||
break;
|
||||
case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE:
|
||||
if (hsp_subevent_audio_connection_complete_get_status(event)){
|
||||
printf("Audio connection establishment failed with status %u\n", hsp_subevent_audio_connection_complete_get_status(event));
|
||||
status = hsp_subevent_audio_connection_complete_get_status(event);
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("Audio connection establishment failed with status %u\n", status);
|
||||
} else {
|
||||
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
|
@ -177,13 +177,14 @@ static void stdin_process(char c){
|
||||
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
|
||||
UNUSED(channel);
|
||||
uint8_t status;
|
||||
|
||||
switch (packet_type){
|
||||
case HCI_SCO_DATA_PACKET:
|
||||
sco_demo_receive(event, event_size);
|
||||
break;
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (event[0]) {
|
||||
switch (hci_event_packet_get_type(event)) {
|
||||
case BTSTACK_EVENT_STATE:
|
||||
if (btstack_event_state_get_state(event) != HCI_STATE_WORKING) break;
|
||||
show_usage();
|
||||
@ -193,24 +194,27 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
sco_demo_send(sco_handle);
|
||||
break;
|
||||
case HCI_EVENT_HSP_META:
|
||||
switch (event[2]) {
|
||||
switch (hci_event_hsp_meta_get_subevent_code(event)) {
|
||||
case HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE:
|
||||
if (hsp_subevent_rfcomm_connection_complete_get_status(event)){
|
||||
printf("RFCOMM connection establishement failed with status %u\n", hsp_subevent_rfcomm_connection_complete_get_status(event));
|
||||
status = hsp_subevent_rfcomm_connection_complete_get_status(event);
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("RFCOMM connection establishement failed with status %u\n", status);
|
||||
} else {
|
||||
printf("RFCOMM connection established.\n");
|
||||
}
|
||||
break;
|
||||
case HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE:
|
||||
if (hsp_subevent_rfcomm_disconnection_complete_get_status(event)){
|
||||
printf("RFCOMM disconnection failed with status %u.\n", hsp_subevent_rfcomm_disconnection_complete_get_status(event));
|
||||
status = hsp_subevent_rfcomm_disconnection_complete_get_status(event);
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("RFCOMM disconnection failed with status %u.\n", status);
|
||||
} else {
|
||||
printf("RFCOMM disconnected.\n");
|
||||
}
|
||||
break;
|
||||
case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE:
|
||||
if (hsp_subevent_audio_connection_complete_get_status(event)){
|
||||
printf("Audio connection establishment failed with status %u\n", hsp_subevent_audio_connection_complete_get_status(event));
|
||||
status = hsp_subevent_audio_connection_complete_get_status(event);
|
||||
if (status != ERROR_CODE_SUCCESS){
|
||||
printf("Audio connection establishment failed with status %u\n", status);
|
||||
} else {
|
||||
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
@ -238,11 +242,10 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
}
|
||||
memcpy(hs_cmd_buffer, hsp_subevent_ag_indication_get_value(event), size);
|
||||
printf("Received custom indication: \"%s\". \nExit code or call hsp_hs_send_result.\n", hs_cmd_buffer);
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("event not handled %u\n", event[2]);
|
||||
printf("event not handled %u\n", hci_event_hsp_meta_get_subevent_code(event));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -206,6 +206,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
uint16_t cid;
|
||||
uint16_t conn_interval;
|
||||
hci_con_handle_t handle;
|
||||
uint8_t status;
|
||||
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
@ -262,7 +263,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
psm = l2cap_event_le_channel_opened_get_psm(packet);
|
||||
cid = l2cap_event_le_channel_opened_get_local_cid(packet);
|
||||
handle = l2cap_event_le_channel_opened_get_handle(packet);
|
||||
if (packet[2] == 0) {
|
||||
status = l2cap_event_le_channel_opened_get_status(packet);
|
||||
if (status == ERROR_CODE_SUCCESS) {
|
||||
printf("L2CAP: LE Data Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
bd_addr_to_str(event_address), handle, psm, cid, little_endian_read_16(packet, 15));
|
||||
le_data_channel_connection.cid = cid;
|
||||
@ -275,7 +277,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
l2cap_le_request_can_send_now_event(le_data_channel_connection.cid);
|
||||
#endif
|
||||
} else {
|
||||
printf("L2CAP: LE Data Channel connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), packet[2]);
|
||||
printf("L2CAP: LE Data Channel connection to device %s failed. status code 0x%02x\n", bd_addr_to_str(event_address), status);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -220,6 +220,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
uint16_t cid;
|
||||
uint16_t conn_interval;
|
||||
hci_con_handle_t handle;
|
||||
uint8_t status;
|
||||
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
@ -281,7 +282,8 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
psm = l2cap_event_le_channel_opened_get_psm(packet);
|
||||
cid = l2cap_event_le_channel_opened_get_local_cid(packet);
|
||||
handle = l2cap_event_le_channel_opened_get_handle(packet);
|
||||
if (packet[2] == 0) {
|
||||
status = l2cap_event_le_channel_opened_get_status(packet);
|
||||
if (status == ERROR_CODE_SUCCESS) {
|
||||
printf("L2CAP: LE Data Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
|
||||
bd_addr_to_str(event_address), handle, psm, cid, little_endian_read_16(packet, 15));
|
||||
// setup new
|
||||
@ -295,7 +297,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
l2cap_le_request_can_send_now_event(le_data_channel_connection.cid);
|
||||
#endif
|
||||
} else {
|
||||
printf("L2CAP: LE Data Channel connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), packet[2]);
|
||||
printf("L2CAP: LE Data Channel connection to device %s failed. status code %u\n", bd_addr_to_str(event_address), status);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -205,6 +205,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
UNUSED(size);
|
||||
|
||||
uint16_t mtu;
|
||||
uint8_t att_status;
|
||||
switch(state){
|
||||
case TC_W4_SERVICE_RESULT:
|
||||
switch(hci_event_packet_get_type(packet)){
|
||||
@ -213,8 +214,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
gatt_event_service_query_result_get_service(packet, &le_streamer_service);
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (packet[4] != 0){
|
||||
printf("SERVICE_QUERY_RESULT - Error status %x.\n", packet[4]);
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS){
|
||||
printf("SERVICE_QUERY_RESULT - Error status %x.\n", att_status);
|
||||
gap_disconnect(connection_handle);
|
||||
break;
|
||||
}
|
||||
@ -234,8 +236,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
gatt_event_characteristic_query_result_get_characteristic(packet, &le_streamer_characteristic_rx);
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (packet[4] != 0){
|
||||
printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", packet[4]);
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS){
|
||||
printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", att_status);
|
||||
gap_disconnect(connection_handle);
|
||||
break;
|
||||
}
|
||||
@ -255,8 +258,9 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
gatt_event_characteristic_query_result_get_characteristic(packet, &le_streamer_characteristic_tx);
|
||||
break;
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
if (packet[4] != 0){
|
||||
printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", packet[4]);
|
||||
att_status = gatt_event_query_complete_get_att_status(packet);
|
||||
if (att_status != ATT_ERROR_SUCCESS){
|
||||
printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", att_status);
|
||||
gap_disconnect(connection_handle);
|
||||
break;
|
||||
}
|
||||
|
@ -125,6 +125,7 @@ static void heartbeat_handler(struct btstack_timer_source *ts){
|
||||
/* LISTING_END */
|
||||
|
||||
static void nordic_spp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
UNUSED(channel);
|
||||
switch (packet_type){
|
||||
case HCI_EVENT_PACKET:
|
||||
if (hci_event_packet_get_type(packet) != HCI_EVENT_GATTSERVICE_META) break;
|
||||
|
@ -142,14 +142,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
|
||||
case HCI_EVENT_COMMAND_COMPLETE:
|
||||
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_bd_addr)){
|
||||
reverse_bd_addr(&packet[6], event_addr);
|
||||
printf("BD-ADDR: %s\n\r", bd_addr_to_str(event_addr));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_PIN_CODE_REQUEST:
|
||||
// inform about pin code request
|
||||
@ -159,8 +151,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_INCOMING_CONNECTION:
|
||||
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
||||
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
|
||||
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
|
||||
rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet);
|
||||
rfcomm_channel_id = rfcomm_event_incoming_connection_get_rfcomm_cid(packet);
|
||||
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr));
|
||||
@ -168,7 +159,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_CHANNEL_OPENED:
|
||||
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
|
||||
if (rfcomm_event_channel_opened_get_status(packet)) {
|
||||
printf("RFCOMM channel open failed, status %u\n", rfcomm_event_channel_opened_get_status(packet));
|
||||
} else {
|
||||
|
@ -204,8 +204,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_INCOMING_CONNECTION:
|
||||
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
||||
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
|
||||
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
|
||||
rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet);
|
||||
rfcomm_cid = rfcomm_event_incoming_connection_get_rfcomm_cid(packet);
|
||||
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr));
|
||||
@ -213,7 +212,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_CHANNEL_OPENED:
|
||||
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
|
||||
if (rfcomm_event_channel_opened_get_status(packet)) {
|
||||
printf("RFCOMM channel open failed, status %u\n", rfcomm_event_channel_opened_get_status(packet));
|
||||
} else {
|
||||
@ -256,6 +254,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
case RFCOMM_DATA_PACKET:
|
||||
test_track_transferred(size);
|
||||
#if 0
|
||||
// optional: print received data as ASCII text
|
||||
printf("RCV: '");
|
||||
for (i=0;i<size;i++){
|
||||
putchar(packet[i]);
|
||||
|
@ -303,8 +303,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_INCOMING_CONNECTION:
|
||||
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
||||
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
|
||||
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
|
||||
rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet);
|
||||
rfcomm_cid = rfcomm_event_incoming_connection_get_rfcomm_cid(packet);
|
||||
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr));
|
||||
@ -312,7 +311,6 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_CHANNEL_OPENED:
|
||||
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
|
||||
if (rfcomm_event_channel_opened_get_status(packet)) {
|
||||
printf("RFCOMM channel open failed, status %u\n", rfcomm_event_channel_opened_get_status(packet));
|
||||
} else {
|
||||
@ -365,6 +363,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
test_track_transferred(size);
|
||||
|
||||
#if 0
|
||||
// optional: print received data as ASCII text
|
||||
printf("RCV: '");
|
||||
for (i=0;i<size;i++){
|
||||
putchar(packet[i]);
|
||||
|
@ -127,6 +127,7 @@ static void heartbeat_handler(struct btstack_timer_source *ts){
|
||||
/* LISTING_END */
|
||||
|
||||
static void ublox_spp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
UNUSED(channel);
|
||||
switch (packet_type){
|
||||
case HCI_EVENT_PACKET:
|
||||
if (hci_event_packet_get_type(packet) != HCI_EVENT_GATTSERVICE_META) break;
|
||||
|
@ -113,7 +113,7 @@ int btstack_ring_buffer_write(btstack_ring_buffer_t * ring_buffer, uint8_t * dat
|
||||
if (ring_buffer->last_written_index == ring_buffer->last_read_index){
|
||||
ring_buffer->full = 1;
|
||||
}
|
||||
return 0;
|
||||
return ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// fetch data_length bytes from ring buffer
|
||||
|
Loading…
x
Reference in New Issue
Block a user