Skip to content

Commit 8b6ea33

Browse files
committed
fix(modem): Refine mode switch data->command
* netif.stop() moved after setting the transition callback * send PPP escape sequence if enabled before waiting for transition to complete * add newline character before sync() command (after the "+++") Closes #692
1 parent 849fe7b commit 8b6ea33

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

components/esp_modem/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,13 @@ menu "esp-modem"
7676
help
7777
If enabled, APIs to add URC handler are available
7878

79+
config ESP_MODEM_PPP_ESCAPE_BEFORE_EXIT
80+
bool "Send escape sequence when switching PPP -> CMD"
81+
default n
82+
help
83+
If enabled, the library sends a PPP escape ("+++" command)
84+
to switch to command mode. This make switching from PPP to CMD
85+
mode more robust for some devices (e.g. Quectel), but might cause
86+
trouble for other devices (e.g. SIMCOM).
87+
7988
endmenu

components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class GenericModule: public ModuleIf {
7777
if (set_command_mode() == command_result::OK) {
7878
return true;
7979
}
80-
Task::Delay(1000); // Mandatory 1s pause after escape
80+
// send a newline to delimit the escape from the upcoming sync command
81+
uint8_t delim = '\n';
82+
dte->write(&delim, 1);
8183
if (sync() == command_result::OK) {
8284
return true;
8385
}

components/esp_modem/src/esp_modem_dce.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace transitions {
1818

1919
static bool exit_data(DTE &dte, ModuleIf &device, Netif &netif)
2020
{
21-
netif.stop();
2221
auto signal = std::make_shared<SignalGroup>();
2322
std::weak_ptr<SignalGroup> weak_signal = signal;
2423
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)
3231
if (memchr(data, '\n', len))
3332
{
3433
ESP_LOG_BUFFER_HEXDUMP("esp-modem: debug_data (CMD)", data, len, ESP_LOG_DEBUG);
35-
const auto pass = std::list<std::string_view>({"NO CARRIER", "DISCONNECTED"});
34+
const auto pass = std::list<std::string_view>({"NO CARRIER", "DISCONNECTED", "OK"});
3635
std::string_view response((char *) data, len);
3736
for (auto &it : pass)
3837
if (response.find(it) != std::string::npos) {
@@ -44,8 +43,14 @@ static bool exit_data(DTE &dte, ModuleIf &device, Netif &netif)
4443
}
4544
return false;
4645
});
46+
netif.stop();
4747
netif.wait_until_ppp_exits();
48-
if (!signal->wait(1, 2000)) {
48+
#ifdef ESP_MODEM_PPP_ESCAPE_BEFORE_EXIT
49+
std::array<uint8_t, 3> ppp_escape = {'+', '+', '+'};
50+
dte.write(ppp_escape.data(), ppp_escape.size());
51+
#endif
52+
if (!signal->wait(1, 2000)) { // wait for any of the disconnection messages
53+
// if no reply -> set device to command mode
4954
dte.set_read_cb(nullptr);
5055
if (!device.set_mode(modem_mode::COMMAND_MODE)) {
5156
return false;

components/esp_modem/src/esp_modem_netif_linux.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ void Netif::start()
5252

5353
void Netif::stop()
5454
{
55-
ppp_dte->set_read_cb(nullptr);
5655
signal.clear(PPP_STARTED);
5756
}
5857

0 commit comments

Comments
 (0)