diff --git a/example/embedded/hsp_hs_test.c b/example/embedded/hsp_hs_test.c index 8abc5b948..1cf61bb22 100644 --- a/example/embedded/hsp_hs_test.c +++ b/example/embedded/hsp_hs_test.c @@ -172,19 +172,16 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ // printf("DAEMON_EVENT_HCI_PACKET_SENT\n"); // try_send_sco(); break; - case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE: - // printf("HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE status %u, %x\n", event[2], READ_BT_16(event, 3)); - if (event[2]) break; - sco_handle = READ_BT_16(event, 3); - break; case HCI_EVENT_HSP_META: switch (event[2]) { case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE: if (event[3] == 0){ + sco_handle = READ_BT_16(event, 4); printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); // try_send_sco(); } else { printf("Audio connection establishment failed with status %u\n", event[3]); + sco_handle = 0; } break; case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE: diff --git a/src/hsp_ag.c b/src/hsp_ag.c index b771c9b67..961f705a2 100644 --- a/src/hsp_ag.c +++ b/src/hsp_ag.c @@ -139,6 +139,17 @@ static void emit_event(uint8_t event_subtype, uint8_t value){ (*hsp_ag_callback)(event, sizeof(event)); } +static void emit_event_audio_connected(uint8_t status, uint16_t handle){ + if (!hsp_hs_callback) return; + uint8_t event[6]; + event[0] = HCI_EVENT_HSP_META; + event[1] = sizeof(event) - 2; + event[2] = HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE; + event[3] = status; + bt_store_16(event, 4, handle); + (*hsp_hs_callback)(event, sizeof(event)); +} + void hsp_ag_create_service(uint8_t * service, int rfcomm_channel_nr, const char * name){ uint8_t* attribute; de_create_sequence(service); @@ -510,7 +521,8 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha uint8_t air_mode = packet[index]; if (status != 0){ - log_error("(e)SCO Connection is not established, status %u", status); + log_error("(e)SCO Connection failed, status %u", status); + emit_event_audio_connected(status, sco_handle); break; } switch (link_type){ @@ -538,7 +550,7 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha } hsp_state = HSP_ACTIVE; - emit_event(HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE, 0); + emit_event_audio_connected(status, sco_handle); break; } diff --git a/src/hsp_hs.c b/src/hsp_hs.c index 4b413e78d..af11eba12 100644 --- a/src/hsp_hs.c +++ b/src/hsp_hs.c @@ -131,6 +131,18 @@ static void emit_event(uint8_t event_subtype, uint8_t value){ event[3] = value; // status 0 == OK (*hsp_hs_callback)(event, sizeof(event)); } + +static void emit_event_audio_connected(uint8_t status, uint16_t handle){ + if (!hsp_hs_callback) return; + uint8_t event[6]; + event[0] = HCI_EVENT_HSP_META; + event[1] = sizeof(event) - 2; + event[2] = HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE; + event[3] = status; + bt_store_16(event, 4, handle); + (*hsp_hs_callback)(event, sizeof(event)); +} + // remote audio volume control // AG +VGM=13 [0..15] ; HS AT+VGM=6 | AG OK @@ -448,7 +460,8 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha uint8_t air_mode = packet[index]; if (status != 0){ - log_error("(e)SCO Connection is not established, status %u", status); + log_error("(e)SCO Connection failed, status %u", status); + emit_event_audio_connected(status, sco_handle); break; } switch (link_type){ @@ -479,7 +492,7 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha hsp_hs_callback(packet, size); hsp_state = HSP_ACTIVE; - emit_event(HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE, 0); + emit_event_audio_connected(0, sco_handle); break; }