mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-03 20:54:18 +00:00
hfp hf: emit events instead of printf
This commit is contained in:
parent
206ba3fb6a
commit
8d20c044a9
@ -753,12 +753,54 @@ extern "C" {
|
||||
#define HFP_SUBEVENT_CALL_ANSWERED 0x13
|
||||
#define HFP_SUBEVENT_CONFERENCE_CALL 0x14
|
||||
#define HFP_SUBEVENT_RING 0x15
|
||||
#define HFP_SUBEVENT_SPEAKER_VOLUME 0x16
|
||||
|
||||
/**
|
||||
* @format 111
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param gain
|
||||
*/
|
||||
#define HFP_SUBEVENT_SPEAKER_VOLUME 0x16
|
||||
|
||||
/**
|
||||
* @format 111
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param gain
|
||||
*/
|
||||
#define HFP_SUBEVENT_MICROPHONE_VOLUME 0x17
|
||||
#define HFP_SUBEVENT_CALL_WAITING_NOTIFICATION 0x18
|
||||
#define HFP_SUBEVENT_CALLING_LINE_INDETIFICATION_NOTIFICATION 0x19
|
||||
|
||||
/**
|
||||
* @format 1111111T
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param clcc_idx
|
||||
* @param clcc_dir
|
||||
* @param clcc_status
|
||||
* @param clcc_mpty
|
||||
* @param bnip_type
|
||||
* @param bnip_number
|
||||
*/
|
||||
#define HFP_SUBEVENT_ENHANCED_CALL_STATUS 0x1A
|
||||
#define HFP_SUBEVENT_SUBSCRIBER_NUMBER_INFORMATION 0x1B
|
||||
|
||||
/**
|
||||
* @format 111T
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param bnip_type
|
||||
* @param bnip_number
|
||||
*/
|
||||
#define HFP_SUBEVENT_SUBSCRIBER_NUMBER_INFORMATION 0x1B
|
||||
|
||||
/**
|
||||
* @format 11T
|
||||
* @param subevent_code
|
||||
* @param status
|
||||
* @param value
|
||||
*/
|
||||
#define HFP_SUBEVENT_RESPONSE_AND_HOLD_STATUS 0x1C
|
||||
|
||||
// ANCS Client
|
||||
#define ANCS_CLIENT_CONNECTED 0xF0
|
||||
|
50
src/hfp_hf.c
50
src/hfp_hf.c
@ -91,18 +91,35 @@ void hfp_hf_register_packet_handler(hfp_callback_t callback){
|
||||
hfp_callback = callback;
|
||||
}
|
||||
|
||||
static void hfp_hf_emit_subscriber_number(hfp_connection_t * hfp_connection){
|
||||
printf("Subscriber Number: number %s, type %u\n", hfp_connection->bnip_number, hfp_connection->bnip_type);
|
||||
static void hfp_hf_emit_subscriber_number(hfp_callback_t callback, uint8_t bnip_type, const char * bnip_number){
|
||||
if (!callback) return;
|
||||
uint8_t event[30];
|
||||
event[0] = HCI_EVENT_HFP_META;
|
||||
event[1] = sizeof(event) - 2;
|
||||
event[2] = HFP_SUBEVENT_SUBSCRIBER_NUMBER_INFORMATION;
|
||||
event[3] = bnip_type;
|
||||
int size = (strlen(bnip_number) < sizeof(event) - 5) ? strlen(bnip_number) : sizeof(event) - 5;
|
||||
strncpy((char*)&event[4], bnip_number, size);
|
||||
event[4 + size] = 0;
|
||||
(*callback)(event, sizeof(event));
|
||||
}
|
||||
|
||||
static void hfp_hf_emit_response_and_hold_status(hfp_connection_t * hfp_connection){
|
||||
printf("Response and Hold status: %s\n", hfp_connection->line_buffer);
|
||||
}
|
||||
|
||||
static void hfp_hf_emit_enhanced_call_status(hfp_connection_t * hfp_connection){
|
||||
printf("Enhanced Call Status: idx %u, dir %u, status %u, mpty %u, number %s, type %u\n",
|
||||
hfp_connection->clcc_idx, hfp_connection->clcc_dir, hfp_connection->clcc_status, hfp_connection->clcc_mpty,
|
||||
hfp_connection->bnip_number, hfp_connection->bnip_type);
|
||||
static void hfp_hf_emit_enhanced_call_status(hfp_callback_t callback, uint8_t clcc_idx, uint8_t clcc_dir,
|
||||
uint8_t clcc_status, uint8_t clcc_mpty, uint8_t bnip_type, const char * bnip_number){
|
||||
if (!callback) return;
|
||||
uint8_t event[35];
|
||||
event[0] = HCI_EVENT_HFP_META;
|
||||
event[1] = sizeof(event) - 2;
|
||||
event[2] = HFP_SUBEVENT_ENHANCED_CALL_STATUS;
|
||||
event[3] = clcc_idx;
|
||||
event[4] = clcc_dir;
|
||||
event[6] = clcc_status;
|
||||
event[7] = clcc_mpty;
|
||||
event[8] = bnip_type;
|
||||
int size = (strlen(bnip_number) < sizeof(event) - 10) ? strlen(bnip_number) : sizeof(event) - 10;
|
||||
strncpy((char*)&event[9], bnip_number, size);
|
||||
event[9 + size] = 0;
|
||||
(*callback)(event, sizeof(event));
|
||||
}
|
||||
|
||||
static int hfp_hf_supports_codec(uint8_t codec){
|
||||
@ -944,15 +961,22 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
switch (hfp_connection->command){
|
||||
case HFP_CMD_GET_SUBSCRIBER_NUMBER_INFORMATION:
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_hf_emit_subscriber_number(hfp_connection);
|
||||
// printf("Subscriber Number: number %s, type %u\n", hfp_connection->bnip_number, hfp_connection->bnip_type);
|
||||
hfp_hf_emit_subscriber_number(hfp_callback, hfp_connection->bnip_type, hfp_connection->bnip_number);
|
||||
break;
|
||||
case HFP_CMD_RESPONSE_AND_HOLD_STATUS:
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_hf_emit_response_and_hold_status(hfp_connection);
|
||||
// printf("Response and Hold status: %s\n", hfp_connection->line_buffer);
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_RESPONSE_AND_HOLD_STATUS, atoi((char *)&hfp_connection->line_buffer[0]));
|
||||
break;
|
||||
case HFP_CMD_LIST_CURRENT_CALLS:
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
hfp_hf_emit_enhanced_call_status(hfp_connection);
|
||||
// printf("Enhanced Call Status: idx %u, dir %u, status %u, mpty %u, number %s, type %u\n",
|
||||
// hfp_connection->clcc_idx, hfp_connection->clcc_dir, hfp_connection->clcc_status, hfp_connection->clcc_mpty,
|
||||
// hfp_connection->bnip_number, hfp_connection->bnip_type);
|
||||
hfp_hf_emit_enhanced_call_status(hfp_callback, hfp_connection->clcc_idx,
|
||||
hfp_connection->clcc_dir, hfp_connection->clcc_status, hfp_connection->clcc_mpty,
|
||||
hfp_connection->bnip_type, hfp_connection->bnip_number);
|
||||
break;
|
||||
case HFP_CMD_SET_SPEAKER_GAIN:
|
||||
hfp_connection->command = HFP_CMD_NONE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user