mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-19 21:42:25 +02:00
fix(esp-modem): Improve PPP exit sequence
* Implement retry mechanism if escape PPP mode failed * Stop networking and checking for NO-CARRIER manually on PPP exit Closes https://github.com/espressif/esp-protocols/issues/47
This commit is contained in:
@ -79,8 +79,17 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (mode == modem_mode::COMMAND_MODE) {
|
} else if (mode == modem_mode::COMMAND_MODE) {
|
||||||
Task::Delay(1000); // Mandatory 1s pause
|
Task::Delay(1000); // Mandatory 1s pause before
|
||||||
return set_command_mode() == command_result::OK;
|
int retry = 0;
|
||||||
|
while (retry++ < 3) {
|
||||||
|
if (set_command_mode() == command_result::OK)
|
||||||
|
return true;
|
||||||
|
Task::Delay(1000); // Mandatory 1s pause after escape
|
||||||
|
if (sync() == command_result::OK)
|
||||||
|
return true;
|
||||||
|
Task::Delay(1000); // Mandatory 1s pause before escape
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} else if (mode == modem_mode::CMUX_MODE) {
|
} else if (mode == modem_mode::CMUX_MODE) {
|
||||||
return set_cmux() == command_result::OK;
|
return set_cmux() == command_result::OK;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "cxx_include/esp_modem_dte.hpp"
|
#include "cxx_include/esp_modem_dte.hpp"
|
||||||
#include "cxx_include/esp_modem_dce.hpp"
|
#include "cxx_include/esp_modem_dce.hpp"
|
||||||
@ -27,24 +29,41 @@ bool DCE_Mode::set(DTE *dte, ModuleIf *device, Netif &netif, modem_mode m)
|
|||||||
case modem_mode::UNDEF:
|
case modem_mode::UNDEF:
|
||||||
break;
|
break;
|
||||||
case modem_mode::COMMAND_MODE:
|
case modem_mode::COMMAND_MODE:
|
||||||
|
{
|
||||||
if (mode == modem_mode::COMMAND_MODE) {
|
if (mode == modem_mode::COMMAND_MODE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
netif.stop();
|
netif.stop();
|
||||||
if (!device->set_mode(modem_mode::COMMAND_MODE)) {
|
SignalGroup signal;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
dte->set_read_cb([&](uint8_t *data, size_t len) -> bool {
|
dte->set_read_cb([&](uint8_t *data, size_t len) -> bool {
|
||||||
ESP_LOG_BUFFER_HEXDUMP("esp-modem: debug_data", data, len, ESP_LOG_INFO);
|
if (memchr(data, '\n', len)) {
|
||||||
|
ESP_LOG_BUFFER_HEXDUMP("esp-modem: debug_data", data, len, ESP_LOG_DEBUG);
|
||||||
|
const auto pass = std::list<std::string_view>({"NO CARRIER", "DISCONNECTED"});
|
||||||
|
std::string_view response((char *) data, len);
|
||||||
|
for (auto &it : pass)
|
||||||
|
if (response.find(it) != std::string::npos) {
|
||||||
|
signal.set(1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
netif.wait_until_ppp_exits();
|
netif.wait_until_ppp_exits();
|
||||||
|
if (!signal.wait(1, 2000)) {
|
||||||
|
if (!device->set_mode(modem_mode::COMMAND_MODE)) {
|
||||||
|
mode = modem_mode::UNDEF;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
dte->set_read_cb(nullptr);
|
dte->set_read_cb(nullptr);
|
||||||
if (!dte->set_mode(modem_mode::COMMAND_MODE)) {
|
if (!dte->set_mode(modem_mode::COMMAND_MODE)) {
|
||||||
|
mode = modem_mode::UNDEF;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mode = m;
|
mode = m;
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case modem_mode::DATA_MODE:
|
case modem_mode::DATA_MODE:
|
||||||
if (mode == modem_mode::DATA_MODE) {
|
if (mode == modem_mode::DATA_MODE) {
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user