hfp: fix parsing of ranges e.g. in +CIND responses

This commit is contained in:
Matthias Ringwald 2020-09-29 12:20:41 +02:00
parent 184da38c1a
commit f8301d4687
3 changed files with 32 additions and 3 deletions

View File

@ -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

View File

@ -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':

View File

@ -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;