Skip to content

Cellular: Suppress long AT traces #12133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 47 additions & 17 deletions features/cellular/framework/AT/ATHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
}

bool debug_on = _debug_on;
bool disabled_debug = false;
if (len > DEBUG_MAXLEN) {
_debug_on = false;
disabled_debug = true;
}

size_t read_len = 0;
for (; read_len < len; read_len++) {
int c = get_char();
Expand All @@ -594,10 +600,16 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
return -1;
}
buf[read_len] = c;
if (_debug_on && read_len >= DEBUG_MAXLEN) {
_debug_on = false;
}
}

#if MBED_CONF_CELLULAR_DEBUG_AT
if (debug_on && disabled_debug) {
tr_info("read_bytes trace suppressed (total length %d)", read_len);
}
#else
(void)disabled_debug; // Remove compiler warning
#endif

_debug_on = debug_on;
return read_len;
}
Expand Down Expand Up @@ -690,13 +702,15 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
char hexbuf[2];

bool debug_on = _debug_on;
bool disabled_debug = false;
if (size > DEBUG_MAXLEN) {
_debug_on = false;
disabled_debug = true;
}

for (; read_idx < size * 2 + match_pos; read_idx++) {
int c = get_char();

if (_debug_on && read_idx >= DEBUG_MAXLEN) {
_debug_on = false;
}

if (match_pos) {
buf_idx++;
} else {
Expand Down Expand Up @@ -737,12 +751,21 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
}
}
}
_debug_on = debug_on;

if (read_idx && (read_idx == size * 2 + match_pos)) {
buf_idx++;
}

#if MBED_CONF_CELLULAR_DEBUG_AT
if (debug_on && disabled_debug) {
tr_info("read_hex_string trace suppressed (total length %d)", buf_idx);
}
#else
(void)disabled_debug; // Remove compiler warning
#endif

_debug_on = debug_on;

return buf_idx;
}

Expand Down Expand Up @@ -1460,30 +1483,37 @@ size_t ATHandler::write(const void *data, size_t len)
fhs.fh = _fileHandle;
fhs.events = POLLOUT;
size_t write_len = 0;
bool debug_on = _debug_on;

#if MBED_CONF_CELLULAR_DEBUG_AT
bool suppress_traced = false;
#endif

for (; write_len < len;) {
int count = poll(&fhs, 1, poll_timeout());
if (count <= 0 || !(fhs.revents & POLLOUT)) {
set_error(NSAPI_ERROR_DEVICE_ERROR);
_debug_on = debug_on;
return 0;
}
ssize_t ret = _fileHandle->write((uint8_t *)data + write_len, len - write_len);
if (ret < 0) {
set_error(NSAPI_ERROR_DEVICE_ERROR);
_debug_on = debug_on;
return 0;
}
if (_debug_on && write_len < DEBUG_MAXLEN) {
if (write_len + ret < DEBUG_MAXLEN) {
debug_print((char *)data + write_len, ret, AT_TX);
} else {
_debug_on = false;

#if MBED_CONF_CELLULAR_DEBUG_AT
if (write_len + ret > DEBUG_MAXLEN) {
if (_debug_on && !suppress_traced) {
debug_print((char *)data + write_len, DEBUG_MAXLEN, AT_TX);
tr_debug("write trace suppressed (total length %d)", len);
}
suppress_traced = true;
} else {
debug_print((char *)data + write_len, ret, AT_TX);
}
#endif

write_len += (size_t)ret;
}
_debug_on = debug_on;

return write_len;
}
Expand Down
2 changes: 1 addition & 1 deletion features/cellular/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"value": 0
},
"debug-at": {
"help": "Enable AT debug prints",
"help": "Enable AT debug prints. Note! This can have impact on UART performance and might need increasing of drivers.uart-serial-rxbuf-size",
"value": false
},
"radio-access-technology": {
Expand Down