Merge branch 'master' into ble-api-cleanup

This commit is contained in:
Matthias Ringwald 2016-01-24 19:11:51 +01:00
commit 4af9a48d93
3 changed files with 32 additions and 10 deletions

View File

@ -171,19 +171,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:

View File

@ -139,7 +139,18 @@ static void emit_event(uint8_t event_subtype, uint8_t value){
(*hsp_ag_callback)(event, sizeof(event));
}
void hsp_ag_create_service(uint8_t * service, uint32_t service_record_handle, int rfcomm_channel_nr, const char * name){
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 (uint8_t packet_type, uint16_t channel, uint8_t *pack
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 (uint8_t packet_type, uint16_t channel, uint8_t *pack
}
hsp_state = HSP_ACTIVE;
emit_event(HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE, 0);
emit_event_audio_connected(status, sco_handle);
break;
}

View File

@ -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 (uint8_t packet_type, uint16_t channel, uint8_t *pack
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 (uint8_t packet_type, uint16_t channel, uint8_t *pack
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;
}