Skip to content

Commit

Permalink
Merge pull request espressif#702 from david-cermak/fix/modem_data_cmd…
Browse files Browse the repository at this point in the history
…_mode_refine

[modem]: Refine data -> command transition
  • Loading branch information
david-cermak authored Dec 4, 2024
2 parents 8e55b93 + dbc3ea6 commit 32387f7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions components/esp_modem/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 8 additions & 3 deletions components/esp_modem/src/esp_modem_dce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace transitions {

static bool exit_data(DTE &dte, ModuleIf &device, Netif &netif)
{
netif.stop();
auto signal = std::make_shared<SignalGroup>();
std::weak_ptr<SignalGroup> weak_signal = signal;
dte.set_read_cb([&netif, weak_signal](uint8_t *data, size_t len) -> bool {
Expand All @@ -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<std::string_view>({"NO CARRIER", "DISCONNECTED"});
const auto pass = std::list<std::string_view>({"NO CARRIER", "DISCONNECTED", "OK"});
std::string_view response((char *) data, len);
for (auto &it : pass)
if (response.find(it) != std::string::npos) {
Expand All @@ -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<uint8_t, 3> 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;
Expand Down
1 change: 0 additions & 1 deletion components/esp_modem/src/esp_modem_netif_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void Netif::start()

void Netif::stop()
{
ppp_dte->set_read_cb(nullptr);
signal.clear(PPP_STARTED);
}

Expand Down

0 comments on commit 32387f7

Please sign in to comment.