Skip to content

Commit 9302994

Browse files
committed
fix(modem): Fix URC handling in DTE data callback
This partially revert 6eceb28 and fixes URC handling and passing full buffer to higher layers
1 parent e5787e3 commit 9302994

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

components/esp_modem/src/esp_modem_dte.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,24 +367,21 @@ void DTE::on_read(got_line_cb on_read_cb)
367367

368368
bool DTE::command_cb::process_line(uint8_t *data, size_t consumed, size_t len)
369369
{
370+
// returning true indicates that the processing finished and lower layers can destroy the accumulated buffer
370371
#ifdef CONFIG_ESP_MODEM_URC_HANDLER
371-
command_result commandResult = command_result::FAIL;
372+
bool consume_buffer = false;
372373
if (urc_handler) {
373-
commandResult = urc_handler(data, consumed + len);
374+
consume_buffer = urc_handler(data, consumed + len) != command_result::TIMEOUT;
374375
}
375-
if (result != command_result::TIMEOUT && got_line == nullptr) {
376-
return false; // this line has been processed already (got OK or FAIL previously)
376+
if (result != command_result::TIMEOUT || got_line == nullptr) {
377+
return consume_buffer; // this line has been processed already (got OK or FAIL previously)
377378
}
378379
#endif
379380
if (memchr(data + consumed, separator, len)) {
380-
result = got_line(data + consumed, consumed + len);
381+
result = got_line(data, consumed + len);
381382
if (result == command_result::OK || result == command_result::FAIL) {
382383
signal.set(GOT_LINE);
383-
#ifdef CONFIG_ESP_MODEM_URC_HANDLER
384-
return commandResult == command_result::OK;
385-
#else
386384
return true;
387-
#endif
388385
}
389386
}
390387
return false;

0 commit comments

Comments
 (0)