Skip to content

Commit b574ff5

Browse files
authored
Merge pull request #12817 from kivaisan/improve_at_debug_flags
Cellular: Disable AT traces when mbed-trace is disabled
2 parents dcd863b + 738f9fb commit b574ff5

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

features/cellular/framework/device/ATHandler.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ using namespace mbed_cellular_util;
3535

3636
#include "CellularLog.h"
3737

38-
#ifndef MBED_CONF_CELLULAR_DEBUG_AT
39-
#define MBED_CONF_CELLULAR_DEBUG_AT 0
38+
#if defined(MBED_CONF_CELLULAR_DEBUG_AT) && (MBED_CONF_CELLULAR_DEBUG_AT) && defined(MBED_CONF_MBED_TRACE_ENABLE) && MBED_CONF_MBED_TRACE_ENABLE
39+
#define DEBUG_AT_ENABLED 1
40+
#else
41+
#define DEBUG_AT_ENABLED 0
4042
#endif
4143

4244
// URCs should be handled fast, if you add debug traces within URC processing then you also need to increase this time
@@ -89,7 +91,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const
8991
_urc_matched(false),
9092
_error_found(false),
9193
_max_resp_length(MAX_RESP_LENGTH),
92-
_debug_on(MBED_CONF_CELLULAR_DEBUG_AT),
94+
_debug_on(DEBUG_AT_ENABLED),
9395
_cmd_start(false),
9496
_use_delimiter(true),
9597
_start_time(0),
@@ -495,7 +497,7 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
495497
buf[read_len] = c;
496498
}
497499

498-
#if MBED_CONF_CELLULAR_DEBUG_AT
500+
#if DEBUG_AT_ENABLED
499501
if (debug_on && disabled_debug) {
500502
tr_info("read_bytes trace suppressed (total length %d)", read_len);
501503
}
@@ -651,7 +653,7 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
651653
buf_idx++;
652654
}
653655

654-
#if MBED_CONF_CELLULAR_DEBUG_AT
656+
#if DEBUG_AT_ENABLED
655657
if (debug_on && disabled_debug) {
656658
tr_info("read_hex_string trace suppressed (total length %d)", buf_idx);
657659
}
@@ -1379,8 +1381,8 @@ size_t ATHandler::write(const void *data, size_t len)
13791381
fhs.events = POLLOUT;
13801382
size_t write_len = 0;
13811383

1382-
#if MBED_CONF_CELLULAR_DEBUG_AT
1383-
bool suppress_traced = false;
1384+
#if DEBUG_AT_ENABLED
1385+
bool suppress_traces = false;
13841386
#endif
13851387

13861388
for (; write_len < len;) {
@@ -1395,13 +1397,13 @@ size_t ATHandler::write(const void *data, size_t len)
13951397
return 0;
13961398
}
13971399

1398-
#if MBED_CONF_CELLULAR_DEBUG_AT
1400+
#if DEBUG_AT_ENABLED
13991401
if (write_len + ret > DEBUG_MAXLEN) {
1400-
if (_debug_on && !suppress_traced) {
1402+
if (_debug_on && !suppress_traces) {
14011403
debug_print((char *)data + write_len, DEBUG_MAXLEN, AT_TX);
14021404
tr_debug("write trace suppressed (total length %d)", len);
14031405
}
1404-
suppress_traced = true;
1406+
suppress_traces = true;
14051407
} else {
14061408
debug_print((char *)data + write_len, ret, AT_TX);
14071409
}
@@ -1451,7 +1453,7 @@ void ATHandler::flush()
14511453

14521454
void ATHandler::debug_print(const char *p, int len, ATType type)
14531455
{
1454-
#if MBED_CONF_CELLULAR_DEBUG_AT
1456+
#if DEBUG_AT_ENABLED
14551457
if (_debug_on) {
14561458
const int buf_size = len * 4 + 1; // x4 -> reserve space for extra characters, +1 -> terminating null
14571459
char *buffer = new char [buf_size];
@@ -1489,7 +1491,7 @@ void ATHandler::debug_print(const char *p, int len, ATType type)
14891491
tr_error("AT trace unable to allocate buffer!");
14901492
}
14911493
}
1492-
#endif // MBED_CONF_CELLULAR_DEBUG_AT
1494+
#endif // DEBUG_AT_ENABLED
14931495
}
14941496

14951497
bool ATHandler::sync(int timeout_ms)

0 commit comments

Comments
 (0)