@@ -585,6 +585,12 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
585585 }
586586
587587 bool debug_on = _debug_on;
588+ bool disabled_debug = false ;
589+ if (len > DEBUG_MAXLEN) {
590+ _debug_on = false ;
591+ disabled_debug = true ;
592+ }
593+
588594 size_t read_len = 0 ;
589595 for (; read_len < len; read_len++) {
590596 int c = get_char ();
@@ -594,10 +600,16 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
594600 return -1 ;
595601 }
596602 buf[read_len] = c;
597- if (_debug_on && read_len >= DEBUG_MAXLEN) {
598- _debug_on = false ;
599- }
600603 }
604+
605+ #if MBED_CONF_CELLULAR_DEBUG_AT
606+ if (debug_on && disabled_debug) {
607+ tr_info (" read_bytes trace suppressed (total length %d)" , read_len);
608+ }
609+ #else
610+ (void )disabled_debug; // Remove compiler warning
611+ #endif
612+
601613 _debug_on = debug_on;
602614 return read_len;
603615}
@@ -690,13 +702,15 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
690702 char hexbuf[2 ];
691703
692704 bool debug_on = _debug_on;
705+ bool disabled_debug = false ;
706+ if (size > DEBUG_MAXLEN) {
707+ _debug_on = false ;
708+ disabled_debug = true ;
709+ }
710+
693711 for (; read_idx < size * 2 + match_pos; read_idx++) {
694712 int c = get_char ();
695713
696- if (_debug_on && read_idx >= DEBUG_MAXLEN) {
697- _debug_on = false ;
698- }
699-
700714 if (match_pos) {
701715 buf_idx++;
702716 } else {
@@ -737,12 +751,21 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
737751 }
738752 }
739753 }
740- _debug_on = debug_on;
741754
742755 if (read_idx && (read_idx == size * 2 + match_pos)) {
743756 buf_idx++;
744757 }
745758
759+ #if MBED_CONF_CELLULAR_DEBUG_AT
760+ if (debug_on && disabled_debug) {
761+ tr_info (" read_hex_string trace suppressed (total length %d)" , buf_idx);
762+ }
763+ #else
764+ (void )disabled_debug; // Remove compiler warning
765+ #endif
766+
767+ _debug_on = debug_on;
768+
746769 return buf_idx;
747770}
748771
@@ -1460,30 +1483,37 @@ size_t ATHandler::write(const void *data, size_t len)
14601483 fhs.fh = _fileHandle;
14611484 fhs.events = POLLOUT;
14621485 size_t write_len = 0 ;
1463- bool debug_on = _debug_on;
1486+
1487+ #if MBED_CONF_CELLULAR_DEBUG_AT
1488+ bool suppress_traced = false ;
1489+ #endif
1490+
14641491 for (; write_len < len;) {
14651492 int count = poll (&fhs, 1 , poll_timeout ());
14661493 if (count <= 0 || !(fhs.revents & POLLOUT)) {
14671494 set_error (NSAPI_ERROR_DEVICE_ERROR);
1468- _debug_on = debug_on;
14691495 return 0 ;
14701496 }
14711497 ssize_t ret = _fileHandle->write ((uint8_t *)data + write_len, len - write_len);
14721498 if (ret < 0 ) {
14731499 set_error (NSAPI_ERROR_DEVICE_ERROR);
1474- _debug_on = debug_on;
14751500 return 0 ;
14761501 }
1477- if (_debug_on && write_len < DEBUG_MAXLEN) {
1478- if (write_len + ret < DEBUG_MAXLEN) {
1479- debug_print ((char *)data + write_len, ret, AT_TX);
1480- } else {
1481- _debug_on = false ;
1502+
1503+ #if MBED_CONF_CELLULAR_DEBUG_AT
1504+ if (write_len + ret > DEBUG_MAXLEN) {
1505+ if (_debug_on && !suppress_traced) {
1506+ debug_print ((char *)data + write_len, DEBUG_MAXLEN, AT_TX);
1507+ tr_debug (" write trace suppressed (total length %d)" , len);
14821508 }
1509+ suppress_traced = true ;
1510+ } else {
1511+ debug_print ((char *)data + write_len, ret, AT_TX);
14831512 }
1513+ #endif
1514+
14841515 write_len += (size_t )ret;
14851516 }
1486- _debug_on = debug_on;
14871517
14881518 return write_len;
14891519}
0 commit comments