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