diff --git a/CHANGELOG.md b/CHANGELOG.md index 150fb629a..5bcedf37c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Changes September 2020 ### Fixed +- HFP: fix parsing of ranges e.g. in +CIND responses ### Added - `btstack_ring_buffer`: add `btstack_ring_buffer_reset` to reset it to initial state/empty diff --git a/src/classic/hfp.c b/src/classic/hfp.c index 9803229c1..4bd15743f 100644 --- a/src/classic/hfp.c +++ b/src/classic/hfp.c @@ -1025,6 +1025,7 @@ static void hfp_parser_reset_line_buffer(hfp_connection_t *hfp_connection) { static void hfp_parser_store_if_token(hfp_connection_t * hfp_connection, uint8_t byte){ switch (byte){ case ',': + case '-': case ';': case '(': case ')': @@ -1040,6 +1041,7 @@ static void hfp_parser_store_if_token(hfp_connection_t * hfp_connection, uint8_t static bool hfp_parser_is_separator( uint8_t byte){ switch (byte){ case ',': + case '-': case ';': case '\n': case '\r': diff --git a/test/hfp/hfp_at_parser_test.c b/test/hfp/hfp_at_parser_test.c index 5d79a5a99..b628039d1 100644 --- a/test/hfp/hfp_at_parser_test.c +++ b/test/hfp/hfp_at_parser_test.c @@ -121,10 +121,13 @@ TEST(HFPParser, HFP_CMD_INDICATORS_RETRIEVE){ TEST(HFPParser, HFP_HF_INDICATORS){ offset = 0; offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR); - for (pos = 0; pos < hfp_ag_indicators_nr - 1; pos++){ - offset += snprintf(packet+offset, sizeof(packet)-offset, "(\"%s\", (%d, %d)),", hfp_ag_indicators[pos].name, hfp_ag_indicators[pos].min_range, hfp_ag_indicators[pos].max_range); + for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ + if (pos != 0) { + packet[offset++] = ','; + } + offset += snprintf(packet+offset, sizeof(packet)-offset, "(\"%s\", (%d, %d)),", hfp_ag_indicators[pos].name, hfp_ag_indicators[pos].min_range, hfp_ag_indicators[pos].max_range); } - offset += snprintf(packet+offset, sizeof(packet)-offset, "(\"%s\", (%d, %d))\r\n\r\nOK\r\n", hfp_ag_indicators[pos].name, hfp_ag_indicators[pos].min_range, hfp_ag_indicators[pos].max_range); + offset += snprintf(packet+offset, sizeof(packet)-offset, "\r\n\r\nOK\r\n"); context.state = HFP_W4_RETRIEVE_INDICATORS; parse_hf(packet); @@ -138,6 +141,29 @@ TEST(HFPParser, HFP_HF_INDICATORS){ } } +TEST(HFPParser, HFP_HF_INDICATORS_RANGE){ + offset = 0; + offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR); + for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ + if (pos != 0) { + packet[offset++] = ','; + } + offset += snprintf(packet+offset, sizeof(packet)-offset, "(\"%s\", (%d-%d)),", hfp_ag_indicators[pos].name, hfp_ag_indicators[pos].min_range, hfp_ag_indicators[pos].max_range); + } + offset += snprintf(packet+offset, sizeof(packet)-offset, "\r\n\r\nOK\r\n"); + context.state = HFP_W4_RETRIEVE_INDICATORS; + + parse_hf(packet); + CHECK_EQUAL(HFP_CMD_OK, context.command); + CHECK_EQUAL(hfp_ag_indicators_nr, context.ag_indicators_nr); + for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ + CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index); + STRCMP_EQUAL(hfp_ag_indicators[pos].name, context.ag_indicators[pos].name); + CHECK_EQUAL(hfp_ag_indicators[pos].min_range, context.ag_indicators[pos].min_range); + CHECK_EQUAL(hfp_ag_indicators[pos].max_range, context.ag_indicators[pos].max_range); + } +} + TEST(HFPParser, HFP_HF_INDICATOR_STATUS){ // send status offset = 0;