mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-17 02:42:33 +00:00
hfp: fix set status of individual ag indicators
This commit is contained in:
parent
2bd0c9beb6
commit
84565b87d8
@ -615,7 +615,7 @@ extern "C" {
|
||||
|
||||
#define HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED 0x01
|
||||
#define HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED 0x02
|
||||
#define HFP_SUBEVENT_OK 0x03
|
||||
#define HFP_SUBEVENT_COMPLETE 0x03
|
||||
|
||||
// ANCS Client
|
||||
#define ANCS_CLIENT_CONNECTED 0xF0
|
||||
|
12
src/hfp.c
12
src/hfp.c
@ -177,11 +177,13 @@ int join(char * buffer, int buffer_size, uint8_t * values, int values_nr){
|
||||
|
||||
int join_bitmap(char * buffer, int buffer_size, uint32_t values, int values_nr){
|
||||
if (buffer_size < values_nr * 3) return 0;
|
||||
|
||||
int i;
|
||||
int offset = 0;
|
||||
for (i = 0; i < values_nr-1; i++) {
|
||||
offset += snprintf(buffer+offset, buffer_size-offset, "%d,", get_bit(values,i)); // puts string into buffer
|
||||
}
|
||||
|
||||
if (i<values_nr){
|
||||
offset += snprintf(buffer+offset, buffer_size-offset, "%d", get_bit(values,i));
|
||||
}
|
||||
@ -251,7 +253,6 @@ static hfp_connection_t * create_hfp_connection_context(){
|
||||
context->negotiated_codec = HFP_CODEC_CVSD;
|
||||
|
||||
context->enable_status_update_for_ag_indicators = 0xFF;
|
||||
context->change_enable_status_update_for_individual_ag_indicators = 0xFF;
|
||||
|
||||
context->generic_status_indicators_nr = hfp_generic_status_indicators_nr;
|
||||
memcpy(context->generic_status_indicators, hfp_generic_status_indicators, hfp_generic_status_indicators_nr * sizeof(hfp_generic_status_indicators_t));
|
||||
@ -524,14 +525,6 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
|
||||
context->line_buffer[context->line_size] = 0;
|
||||
|
||||
switch (context->command){
|
||||
case HFP_CMD_INDICATOR:
|
||||
if (byte == ')'){
|
||||
context->parser_state = HFP_PARSER_CMD_SEQUENCE;
|
||||
context->parser_item_index = 0;
|
||||
context->line_size = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case HFP_CMD_SUPPORTED_FEATURES:
|
||||
context->remote_supported_features = 0;
|
||||
for (i=0; i<16; i++){
|
||||
@ -661,6 +654,7 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
|
||||
context->line_size = 0;
|
||||
context->parser_item_index++;
|
||||
context->ag_indicators_nr = context->parser_item_index;
|
||||
printf("parser ag nr %d \n", context->ag_indicators_nr);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,7 @@ extern "C" {
|
||||
#define HFP_GENERIC_STATUS_INDICATOR "+BIND"
|
||||
|
||||
#define HFP_OK "OK"
|
||||
#define HFP_ERROR "ERROR"
|
||||
|
||||
// Codecs
|
||||
#define HFP_CODEC_CVSD 0x01
|
||||
@ -117,6 +118,7 @@ extern "C" {
|
||||
|
||||
typedef enum {
|
||||
HFP_CMD_NONE = 0,
|
||||
HFP_CMD_ERROR,
|
||||
HFP_CMD_OK,
|
||||
HFP_CMD_SUPPORTED_FEATURES,
|
||||
HFP_CMD_AVAILABLE_CODECS,
|
||||
@ -235,7 +237,7 @@ typedef struct hfp_connection {
|
||||
// 0 = deactivate, 1 = activate, 0xff = do nothing
|
||||
uint8_t wait_ok;
|
||||
hfp_command_t sent_command;
|
||||
uint8_t change_enable_status_update_for_individual_ag_indicators;
|
||||
uint8_t change_status_update_for_individual_ag_indicators;
|
||||
|
||||
uint32_t ag_indicators_status_update_bitmap;
|
||||
|
||||
|
34
src/hfp_hf.c
34
src/hfp_hf.c
@ -149,8 +149,8 @@ int hfp_hs_activate_status_update_for_all_ag_indicators_cmd(uint16_t cid, uint8_
|
||||
return send_str_over_rfcomm(cid, buffer);
|
||||
}
|
||||
|
||||
int hfp_hs_activate_status_update_for_ag_indicator_cmd(uint16_t cid, uint32_t indicators_status, int indicators_nr, uint8_t activate){
|
||||
char buffer[20];
|
||||
int hfp_hs_activate_status_update_for_ag_indicator_cmd(uint16_t cid, uint32_t indicators_status, int indicators_nr){
|
||||
char buffer[50];
|
||||
int offset = snprintf(buffer, sizeof(buffer), "AT%s=", HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
|
||||
offset += join_bitmap(buffer+offset, sizeof(buffer)-offset, indicators_status, indicators_nr);
|
||||
offset += snprintf(buffer+offset, sizeof(buffer)-offset, "\r\n");
|
||||
@ -245,14 +245,15 @@ static void hfp_run_for_context(hfp_connection_t * context){
|
||||
if (context->enable_status_update_for_ag_indicators != 0xFF){
|
||||
hfp_hs_activate_status_update_for_all_ag_indicators_cmd(context->rfcomm_cid, context->enable_status_update_for_ag_indicators);
|
||||
context->wait_ok = 1;
|
||||
context->enable_status_update_for_ag_indicators = 0xFF;
|
||||
break;
|
||||
};
|
||||
if (context->change_enable_status_update_for_individual_ag_indicators != 0xFF){
|
||||
if (context->change_status_update_for_individual_ag_indicators == 1){
|
||||
hfp_hs_activate_status_update_for_ag_indicator_cmd(context->rfcomm_cid,
|
||||
context->ag_indicators_status_update_bitmap,
|
||||
context->ag_indicators_nr,
|
||||
context->change_enable_status_update_for_individual_ag_indicators);
|
||||
context->ag_indicators_nr);
|
||||
context->wait_ok = 1;
|
||||
context->change_status_update_for_individual_ag_indicators = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@ -263,6 +264,11 @@ static void hfp_run_for_context(hfp_connection_t * context){
|
||||
|
||||
void update_command(hfp_connection_t * context){
|
||||
context->command = HFP_CMD_NONE;
|
||||
if (strncmp((char *)context->line_buffer, HFP_ERROR, strlen(HFP_ERROR)) == 0){
|
||||
context->command = HFP_CMD_ERROR;
|
||||
printf("Received ERROR\n");
|
||||
}
|
||||
|
||||
if (strncmp((char *)context->line_buffer, HFP_OK, strlen(HFP_OK)) == 0){
|
||||
context->command = HFP_CMD_OK;
|
||||
printf("Received OK\n");
|
||||
@ -377,7 +383,7 @@ void handle_switch_on_ok(hfp_connection_t *context){
|
||||
|
||||
case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
|
||||
context->wait_ok = 0;
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_OK, 0);
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 0);
|
||||
|
||||
break;
|
||||
default:
|
||||
@ -394,11 +400,21 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
|
||||
packet[size] = 0;
|
||||
int pos;
|
||||
// printf("parse command: %s, state: %d\n", packet, context->parser_state);
|
||||
printf("parse command: %s, state: %d\n", packet, context->parser_state);
|
||||
for (pos = 0; pos < size ; pos++){
|
||||
hfp_parse(context, packet[pos]);
|
||||
|
||||
// trigger next action after CMD received
|
||||
if (context->command == HFP_CMD_ERROR){
|
||||
if (context->state == HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED){
|
||||
context->wait_ok = 0;
|
||||
// TODO: reset state? repeat commands? restore bitmaps? get ERROR codes.
|
||||
|
||||
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 1);
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
if (context->command != HFP_CMD_OK) continue;
|
||||
handle_switch_on_ok(context);
|
||||
}
|
||||
@ -469,13 +485,13 @@ void hfp_hf_enable_status_update_for_all_ag_indicators(bd_addr_t bd_addr, uint8_
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
||||
void hfp_hf_enable_status_update_for_ag_indicator(bd_addr_t bd_addr, uint32_t indicators_status_bitmap, uint8_t enable){
|
||||
void hfp_hf_enable_status_update_for_individual_ag_indicators(bd_addr_t bd_addr, uint32_t indicators_status_bitmap){
|
||||
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
|
||||
if (!connection){
|
||||
log_error("HFP HF: connection doesn't exist.");
|
||||
return;
|
||||
}
|
||||
connection->change_enable_status_update_for_individual_ag_indicators = 1;
|
||||
connection->change_status_update_for_individual_ag_indicators = 1;
|
||||
connection->ag_indicators_status_update_bitmap = indicators_status_bitmap;
|
||||
hfp_run_for_context(connection);
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ void hfp_hf_enable_status_update_for_all_ag_indicators(bd_addr_t bd_addr, uint8_
|
||||
/**
|
||||
* @brief Deactivate/reactivate status update for the individual indicators in the AG using bitmap.
|
||||
*/
|
||||
void hfp_hf_enable_status_update_for_ag_indicator(bd_addr_t bd_addr, uint32_t indicators_status_bitmap, uint8_t enable);
|
||||
void hfp_hf_enable_status_update_for_individual_ag_indicators(bd_addr_t bd_addr, uint32_t indicators_status_bitmap);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -119,6 +119,11 @@ static int stdin_process(struct data_source *ds){
|
||||
case 'r':
|
||||
printf("Enabling HFP AG registration status update.\n");
|
||||
hfp_hf_enable_status_update_for_all_ag_indicators(device_addr, 1);
|
||||
break;
|
||||
case 'i':
|
||||
printf("Enabling HFP AG registration status update for individual indicators.\n");
|
||||
hfp_hf_enable_status_update_for_individual_ag_indicators(device_addr, 63);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
break;
|
||||
@ -141,7 +146,7 @@ void packet_handler(uint8_t * event, uint16_t event_size){
|
||||
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
|
||||
printf("Service level connection released.\n\n");
|
||||
break;
|
||||
case HFP_SUBEVENT_OK:
|
||||
case HFP_SUBEVENT_COMPLETE:
|
||||
switch (cmd){
|
||||
case 'r':
|
||||
printf("HFP AG registration status update enabled.\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user