diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 1da167032a..d9683783e7 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -24,6 +24,7 @@ jobs: chmod +x clang-tidy-sarif curl -sSL https://raw.githubusercontent.com/espressif/idf-extra-components/master/.github/filter_sarif.py -o filter_sarif.py - name: Install pyclang + shell: bash run: | . ${IDF_PATH}/export.sh pip install pyclang~=0.2.0 diff --git a/components/esp_modem/Kconfig b/components/esp_modem/Kconfig index d5b54a8fb8..f4b47fb787 100644 --- a/components/esp_modem/Kconfig +++ b/components/esp_modem/Kconfig @@ -76,4 +76,13 @@ menu "esp-modem" help If enabled, APIs to add URC handler are available + config ESP_MODEM_PPP_ESCAPE_BEFORE_EXIT + bool "Send escape sequence when switching PPP -> CMD" + default n + help + If enabled, the library sends a PPP escape ("+++" command) + to switch to command mode. This make switching from PPP to CMD + mode more robust for some devices (e.g. Quectel), but might cause + trouble for other devices (e.g. SIMCOM). + endmenu diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp index 6ae36e63ec..ad32bd601a 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp @@ -77,7 +77,9 @@ class GenericModule: public ModuleIf { if (set_command_mode() == command_result::OK) { return true; } - Task::Delay(1000); // Mandatory 1s pause after escape + // send a newline to delimit the escape from the upcoming sync command + uint8_t delim = '\n'; + dte->write(&delim, 1); if (sync() == command_result::OK) { return true; } diff --git a/components/esp_modem/src/esp_modem_dce.cpp b/components/esp_modem/src/esp_modem_dce.cpp index f178eea7d5..0a0ca14acd 100644 --- a/components/esp_modem/src/esp_modem_dce.cpp +++ b/components/esp_modem/src/esp_modem_dce.cpp @@ -18,7 +18,6 @@ namespace transitions { static bool exit_data(DTE &dte, ModuleIf &device, Netif &netif) { - netif.stop(); auto signal = std::make_shared(); std::weak_ptr weak_signal = signal; dte.set_read_cb([&netif, weak_signal](uint8_t *data, size_t len) -> bool { @@ -32,7 +31,7 @@ static bool exit_data(DTE &dte, ModuleIf &device, Netif &netif) if (memchr(data, '\n', len)) { ESP_LOG_BUFFER_HEXDUMP("esp-modem: debug_data (CMD)", data, len, ESP_LOG_DEBUG); - const auto pass = std::list({"NO CARRIER", "DISCONNECTED"}); + const auto pass = std::list({"NO CARRIER", "DISCONNECTED", "OK"}); std::string_view response((char *) data, len); for (auto &it : pass) if (response.find(it) != std::string::npos) { @@ -44,8 +43,14 @@ static bool exit_data(DTE &dte, ModuleIf &device, Netif &netif) } return false; }); + netif.stop(); netif.wait_until_ppp_exits(); - if (!signal->wait(1, 2000)) { +#ifdef ESP_MODEM_PPP_ESCAPE_BEFORE_EXIT + std::array ppp_escape = {'+', '+', '+'}; + dte.write(ppp_escape.data(), ppp_escape.size()); +#endif + if (!signal->wait(1, 2000)) { // wait for any of the disconnection messages + // if no reply -> set device to command mode dte.set_read_cb(nullptr); if (!device.set_mode(modem_mode::COMMAND_MODE)) { return false; diff --git a/components/esp_modem/src/esp_modem_netif_linux.cpp b/components/esp_modem/src/esp_modem_netif_linux.cpp index f17592ce5b..9917bfa309 100644 --- a/components/esp_modem/src/esp_modem_netif_linux.cpp +++ b/components/esp_modem/src/esp_modem_netif_linux.cpp @@ -52,7 +52,6 @@ void Netif::start() void Netif::stop() { - ppp_dte->set_read_cb(nullptr); signal.clear(PPP_STARTED); }