mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-10 22:13:37 +00:00
hfp: fix parser
This commit is contained in:
parent
63ffda6041
commit
bf26b831dd
24
src/hfp.c
24
src/hfp.c
@ -898,13 +898,15 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree){
|
||||
hfp_parser_store_byte(context, byte);
|
||||
return;
|
||||
}
|
||||
if (hfp_parser_is_end_of_line(byte)) {
|
||||
if (hfp_parser_is_buffer_empty(context)){
|
||||
context->parser_state = HFP_PARSER_CMD_HEADER;
|
||||
}
|
||||
}
|
||||
if (hfp_parser_is_buffer_empty(context)) return;
|
||||
|
||||
if (context->command != HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE){
|
||||
if (hfp_parser_is_end_of_line(byte)) {
|
||||
if (hfp_parser_is_buffer_empty(context)){
|
||||
context->parser_state = HFP_PARSER_CMD_HEADER;
|
||||
}
|
||||
}
|
||||
if (hfp_parser_is_buffer_empty(context)) return;
|
||||
}
|
||||
|
||||
switch (context->parser_state){
|
||||
case HFP_PARSER_CMD_HEADER: // header
|
||||
@ -950,7 +952,7 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree){
|
||||
}
|
||||
break;
|
||||
|
||||
case HFP_PARSER_CMD_SEQUENCE: // parse comma separated sequence, ignore breacktes
|
||||
case HFP_PARSER_CMD_SEQUENCE:
|
||||
switch (context->command){
|
||||
case HFP_CMD_SET_MICROPHONE_GAIN:
|
||||
value = atoi((char *)&context->line_buffer[0]);
|
||||
@ -1046,7 +1048,7 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree){
|
||||
case HFP_CMD_TRANSFER_AG_INDICATOR_STATUS:
|
||||
// indicators are indexed starting with 1
|
||||
context->parser_item_index = atoi((char *)&context->line_buffer[0]) - 1;
|
||||
printf("Parsed status of the AG indicator %d, status ", context->parser_item_index);
|
||||
log_info("Parsed status of the AG indicator %d, status ", context->parser_item_index);
|
||||
break;
|
||||
case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME:
|
||||
context->network_operator.mode = atoi((char *)&context->line_buffer[0]);
|
||||
@ -1078,11 +1080,11 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree){
|
||||
case HFP_PARSER_SECOND_ITEM:
|
||||
switch (context->command){
|
||||
case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME:
|
||||
printf("format %s, ", context->line_buffer);
|
||||
log_info("format %s, ", context->line_buffer);
|
||||
context->network_operator.format = atoi((char *)&context->line_buffer[0]);
|
||||
break;
|
||||
case HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT:
|
||||
printf("format %s \n", context->line_buffer);
|
||||
log_info("format %s \n", context->line_buffer);
|
||||
context->network_operator.format = atoi((char *)&context->line_buffer[0]);
|
||||
break;
|
||||
case HFP_CMD_LIST_GENERIC_STATUS_INDICATORS:
|
||||
@ -1092,7 +1094,7 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree){
|
||||
break;
|
||||
case HFP_CMD_TRANSFER_AG_INDICATOR_STATUS:
|
||||
context->ag_indicators[context->parser_item_index].status = (uint8_t)atoi((char*)context->line_buffer);
|
||||
printf("%d \n", context->ag_indicators[context->parser_item_index].status);
|
||||
log_info("%d \n", context->ag_indicators[context->parser_item_index].status);
|
||||
context->ag_indicators[context->parser_item_index].status_changed = 1;
|
||||
break;
|
||||
case HFP_CMD_RETRIEVE_AG_INDICATORS:
|
||||
|
@ -167,19 +167,32 @@ TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE){
|
||||
CHECK_EQUAL(context.ag_indicators[pos].enabled, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n",
|
||||
// HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
|
||||
// for (pos = 0; pos < strlen(packet); pos++){
|
||||
// hfp_parse(&context, packet[pos], 0);
|
||||
// }
|
||||
TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES){
|
||||
set_hfp_ag_indicators((hfp_ag_indicator_t *)&hfp_ag_indicators, hfp_ag_indicators_nr);
|
||||
context.ag_indicators_nr = hfp_ag_indicators_nr;
|
||||
memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
|
||||
|
||||
// CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
|
||||
for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
|
||||
CHECK_EQUAL(get_hfp_ag_indicators(&context)[pos].index, hfp_ag_indicators[pos].index);
|
||||
CHECK_EQUAL(get_hfp_ag_indicators(&context)[pos].enabled, hfp_ag_indicators[pos].enabled);
|
||||
CHECK_EQUAL(context.ag_indicators[pos].index, hfp_ag_indicators[pos].index);
|
||||
CHECK_EQUAL(context.ag_indicators[pos].enabled, hfp_ag_indicators[pos].enabled);
|
||||
}
|
||||
|
||||
// for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
|
||||
// CHECK_EQUAL(get_hfp_ag_indicators(&context)[pos].enabled, 1);
|
||||
// CHECK_EQUAL(context.ag_indicators[pos].enabled, 1);
|
||||
// }
|
||||
sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n",
|
||||
HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
|
||||
for (pos = 0; pos < strlen(packet); pos++){
|
||||
hfp_parse(&context, packet[pos], 0);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
|
||||
|
||||
for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
|
||||
CHECK_EQUAL(get_hfp_ag_indicators(&context)[pos].enabled, 1);
|
||||
CHECK_EQUAL(context.ag_indicators[pos].enabled, 1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(HFPParser, HFP_AG_HF_QUERY_OPERATOR_SELECTION){
|
||||
|
Loading…
x
Reference in New Issue
Block a user