@@ -585,6 +585,12 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
585
585
}
586
586
587
587
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
+
588
594
size_t read_len = 0 ;
589
595
for (; read_len < len; read_len++) {
590
596
int c = get_char ();
@@ -594,10 +600,16 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
594
600
return -1 ;
595
601
}
596
602
buf[read_len] = c;
597
- if (_debug_on && read_len >= DEBUG_MAXLEN) {
598
- _debug_on = false ;
599
- }
600
603
}
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
+
601
613
_debug_on = debug_on;
602
614
return read_len;
603
615
}
@@ -690,13 +702,15 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
690
702
char hexbuf[2 ];
691
703
692
704
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
+
693
711
for (; read_idx < size * 2 + match_pos; read_idx++) {
694
712
int c = get_char ();
695
713
696
- if (_debug_on && read_idx >= DEBUG_MAXLEN) {
697
- _debug_on = false ;
698
- }
699
-
700
714
if (match_pos) {
701
715
buf_idx++;
702
716
} else {
@@ -737,12 +751,21 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
737
751
}
738
752
}
739
753
}
740
- _debug_on = debug_on;
741
754
742
755
if (read_idx && (read_idx == size * 2 + match_pos)) {
743
756
buf_idx++;
744
757
}
745
758
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
+
746
769
return buf_idx;
747
770
}
748
771
@@ -1460,30 +1483,37 @@ size_t ATHandler::write(const void *data, size_t len)
1460
1483
fhs.fh = _fileHandle;
1461
1484
fhs.events = POLLOUT;
1462
1485
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
+
1464
1491
for (; write_len < len;) {
1465
1492
int count = poll (&fhs, 1 , poll_timeout ());
1466
1493
if (count <= 0 || !(fhs.revents & POLLOUT)) {
1467
1494
set_error (NSAPI_ERROR_DEVICE_ERROR);
1468
- _debug_on = debug_on;
1469
1495
return 0 ;
1470
1496
}
1471
1497
ssize_t ret = _fileHandle->write ((uint8_t *)data + write_len, len - write_len);
1472
1498
if (ret < 0 ) {
1473
1499
set_error (NSAPI_ERROR_DEVICE_ERROR);
1474
- _debug_on = debug_on;
1475
1500
return 0 ;
1476
1501
}
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);
1482
1508
}
1509
+ suppress_traced = true ;
1510
+ } else {
1511
+ debug_print ((char *)data + write_len, ret, AT_TX);
1483
1512
}
1513
+ #endif
1514
+
1484
1515
write_len += (size_t )ret;
1485
1516
}
1486
- _debug_on = debug_on;
1487
1517
1488
1518
return write_len;
1489
1519
}
0 commit comments