Skip to content

Commit

Permalink
Examples/pppos_client: Fix manual parsing to accept unexpected lines
Browse files Browse the repository at this point in the history
Regression from a90817c that caused
parsing exit in case of an unexpected result found (line handler
reported ESP_FAIL). Prevously if any error found in the line handler we
just posted an unexpected event, but continued with parsing. Fixed by
allowing for further parsing.

Related: #7176
  • Loading branch information
david-cermak committed Oct 4, 2021
1 parent e35a87f commit 336de29
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
38 changes: 19 additions & 19 deletions examples/protocols/pppos_client/components/modem/src/esp_modem.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
Expand Down Expand Up @@ -83,6 +75,13 @@ static inline bool is_only_cr_lf(const char *str, uint32_t len)
return true;
}

static inline void report_unknown_line(esp_modem_dte_t *esp_dte, char *line)
{
/* Send ESP_MODEM_EVENT_UNKNOWN signal to event loop */
esp_event_post_to(esp_dte->event_loop_hdl, ESP_MODEM_EVENT, ESP_MODEM_EVENT_UNKNOWN,
(void *)line, strlen(line) + 1, pdMS_TO_TICKS(100));
}

esp_err_t esp_modem_set_rx_cb(modem_dte_t *dte, esp_modem_on_receive receive_cb, void *receive_cb_ctx)
{
esp_modem_dte_t *esp_dte = __containerof(dte, esp_modem_dte_t, parent);
Expand Down Expand Up @@ -118,18 +117,19 @@ static esp_err_t esp_dte_handle_line(esp_modem_dte_t *esp_dte, char * line, size
if (dce->handle_line == NULL) {
/* Received an asynchronous line, but no handler waiting this this */
ESP_LOGD(MODEM_TAG, "No handler for line: %s", p);
err = ESP_OK; /* Not an error, just propagate the line to user handler */
goto post_event_unknown;
report_unknown_line(esp_dte, line);
return ESP_OK; /* Not an error, just propagate the line to user handler */
}
if (dce->handle_line(dce, p) != ESP_OK) {
ESP_LOGE(MODEM_TAG, "handle line failed");
report_unknown_line(esp_dte, line);
}
MODEM_CHECK(dce->handle_line(dce, p) == ESP_OK, "handle line failed", post_event_unknown);
}
p = strtok_r(NULL, "\n", &str_ptr);
}
return ESP_OK;
post_event_unknown:
/* Send ESP_MODEM_EVENT_UNKNOWN signal to event loop */
esp_event_post_to(esp_dte->event_loop_hdl, ESP_MODEM_EVENT, ESP_MODEM_EVENT_UNKNOWN,
(void *)line, strlen(line) + 1, pdMS_TO_TICKS(100));
report_unknown_line(esp_dte, line);
err:
return err;
}
Expand Down
1 change: 0 additions & 1 deletion tools/ci/check_copyright_ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3821,7 +3821,6 @@ examples/protocols/pppos_client/components/modem/include/esp_modem_netif.h
examples/protocols/pppos_client/components/modem/include/sim7600.h
examples/protocols/pppos_client/components/modem/include/sim800.h
examples/protocols/pppos_client/components/modem/src/bg96.c
examples/protocols/pppos_client/components/modem/src/esp_modem.c
examples/protocols/pppos_client/components/modem/src/esp_modem_compat.c
examples/protocols/pppos_client/components/modem/src/esp_modem_dce_service.c
examples/protocols/pppos_client/components/modem/src/esp_modem_netif.c
Expand Down

0 comments on commit 336de29

Please sign in to comment.