From 503218b3bae1391c19e1577c50cafbdf61a127d8 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 10 May 2022 17:55:55 +0200 Subject: [PATCH] fix(esp_modem): Correction of switching to CMUX * BG96 needs a small pause between CMUX command reception and actual use of the CMUX mode * Correct CMUX payload reception to check FT_UIH message type (P/F flag could be cleared or set) Closes https://github.com/espressif/esp-protocols/issues/33 --- components/esp_modem/src/esp_modem_cmux.cpp | 2 +- components/esp_modem/src/esp_modem_dce.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/esp_modem/src/esp_modem_cmux.cpp b/components/esp_modem/src/esp_modem_cmux.cpp index 7597a6d31..f3e85f6ff 100644 --- a/components/esp_modem/src/esp_modem_cmux.cpp +++ b/components/esp_modem/src/esp_modem_cmux.cpp @@ -103,7 +103,7 @@ struct CMux::CMuxFrame { void CMux::data_available(uint8_t *data, size_t len) { - if (data && type == 0xFF && len > 0 && dlci > 0) { + if (data && (type&FT_UIH) == FT_UIH && len > 0 && dlci > 0) { // valid payload on a virtual term int virtual_term = dlci - 1; if (virtual_term < MAX_TERMINALS_NUM && read_cb[virtual_term]) { // Post partial data (or defragment to post on CMUX footer) diff --git a/components/esp_modem/src/esp_modem_dce.cpp b/components/esp_modem/src/esp_modem_dce.cpp index 626d0f9cb..197851135 100644 --- a/components/esp_modem/src/esp_modem_dce.cpp +++ b/components/esp_modem/src/esp_modem_dce.cpp @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "cxx_include/esp_modem_dte.hpp" #include "cxx_include/esp_modem_dce.hpp" #include "esp_log.h" @@ -63,7 +65,9 @@ bool DCE_Mode::set(DTE *dte, ModuleIf *device, Netif &netif, modem_mode m) if (mode == modem_mode::DATA_MODE || mode == modem_mode::CMUX_MODE) { return false; } - device->set_mode(modem_mode::CMUX_MODE); + device->set_mode(modem_mode::CMUX_MODE); // switch the device into CMUX mode + usleep(100'000); // some devices need a few ms to switch + if (!dte->set_mode(modem_mode::CMUX_MODE)) { return false; }