Skip to content

Commit 16ab718

Browse files
authored
Merge pull request #6765 from mirelachirica/at_handler_read_fix
Cellular: Fix AT Handler compile warning
2 parents d08c819 + d4d3391 commit 16ab718

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -472,25 +472,23 @@ ssize_t ATHandler::read(char *buf, size_t size, bool read_even_stop_tag, bool he
472472
}
473473

474474
size_t match_pos = 0;
475-
size_t upper = 0, lower = 0;
476475
size_t read_size = hex ? size*2 : size;
477476

478-
uint8_t *pbuf = (uint8_t*)buf;
479-
480477
consume_char('\"');
481478

482479
size_t read_idx = 0;
483480
size_t buf_idx = 0;
481+
char hexbuf[2];
484482

485483
for (; read_idx < (read_size + match_pos); read_idx++) {
486-
char c = get_char();
484+
int c = get_char();
487485
buf_idx = hex ? read_idx/2 : read_idx;
488486
if (c == -1) {
489-
pbuf[buf_idx] = '\0';
487+
buf[buf_idx] = '\0';
490488
set_error(NSAPI_ERROR_DEVICE_ERROR);
491489
return -1;
492490
} else if (c == _delimiter) {
493-
pbuf[buf_idx] = '\0';
491+
buf[buf_idx] = '\0';
494492
break;
495493
} else if (c == '\"') {
496494
match_pos = 0;
@@ -504,26 +502,24 @@ ssize_t ATHandler::read(char *buf, size_t size, bool read_even_stop_tag, bool he
504502
_stop_tag->found = true;
505503
// remove tag from string if it was matched
506504
buf_idx -= (_stop_tag->len - 1);
507-
pbuf[buf_idx] = '\0';
505+
buf[buf_idx] = '\0';
508506
break;
509507
}
510508
} else if (match_pos) {
511509
match_pos = 0;
512510
}
513511

514512
if (!hex) {
515-
pbuf[buf_idx] = c;
513+
buf[buf_idx] = c;
516514
} else {
517-
if (read_idx % 2 == 0) {
518-
upper = hex_str_to_int(&c, 1);
519-
} else {
520-
lower = hex_str_to_int(&c, 1);
521-
pbuf[buf_idx] = ((upper<<4) & 0xF0) | (lower & 0x0F);
515+
hexbuf[read_idx % 2] = c;
516+
if (read_idx % 2 == 1) {
517+
hex_str_to_char_str(hexbuf, 2, buf+buf_idx);
522518
}
523519
}
524520
}
525521

526-
return buf_idx + 1;
522+
return buf_idx;
527523
}
528524

529525
ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)

0 commit comments

Comments
 (0)