mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-19 05:22:21 +02:00
fix(modem): Fixed mode transitions between any state and UNDEF
Closes https://github.com/espressif/esp-protocols/issues/320
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -96,6 +96,11 @@ bool DCE_Mode::set_unsafe(DTE *dte, ModuleIf *device, Netif &netif, modem_mode m
|
||||
{
|
||||
switch (m) {
|
||||
case modem_mode::UNDEF:
|
||||
if (!dte->set_mode(m)) {
|
||||
return false;
|
||||
}
|
||||
mode = m;
|
||||
return true;
|
||||
case modem_mode::DUAL_MODE: // Only DTE can be in Dual mode
|
||||
break;
|
||||
case modem_mode::COMMAND_MODE:
|
||||
@ -151,7 +156,7 @@ bool DCE_Mode::set_unsafe(DTE *dte, ModuleIf *device, Netif &netif, modem_mode m
|
||||
mode = modem_mode::CMUX_MANUAL_MODE;
|
||||
return true;
|
||||
case modem_mode::CMUX_MANUAL_EXIT:
|
||||
if (mode != modem_mode::CMUX_MANUAL_MODE) {
|
||||
if (mode != modem_mode::CMUX_MANUAL_MODE && mode != modem_mode::UNDEF) {
|
||||
return false;
|
||||
}
|
||||
if (!dte->set_mode(m)) {
|
||||
@ -160,7 +165,7 @@ bool DCE_Mode::set_unsafe(DTE *dte, ModuleIf *device, Netif &netif, modem_mode m
|
||||
mode = modem_mode::COMMAND_MODE;
|
||||
return true;
|
||||
case modem_mode::CMUX_MANUAL_SWAP:
|
||||
if (mode != modem_mode::CMUX_MANUAL_MODE) {
|
||||
if (mode != modem_mode::CMUX_MANUAL_MODE && mode != modem_mode::UNDEF) {
|
||||
return false;
|
||||
}
|
||||
if (!dte->set_mode(m)) {
|
||||
@ -168,12 +173,12 @@ bool DCE_Mode::set_unsafe(DTE *dte, ModuleIf *device, Netif &netif, modem_mode m
|
||||
}
|
||||
return true;
|
||||
case modem_mode::CMUX_MANUAL_DATA:
|
||||
if (mode != modem_mode::CMUX_MANUAL_MODE) {
|
||||
if (mode != modem_mode::CMUX_MANUAL_MODE && mode != modem_mode::UNDEF) {
|
||||
return false;
|
||||
}
|
||||
return transitions::enter_data(*dte, *device, netif);
|
||||
case modem_mode::CMUX_MANUAL_COMMAND:
|
||||
if (mode != modem_mode::CMUX_MANUAL_MODE) {
|
||||
if (mode != modem_mode::CMUX_MANUAL_MODE && mode != modem_mode::UNDEF) {
|
||||
return false;
|
||||
}
|
||||
return transitions::exit_data(*dte, *device, netif);
|
||||
|
@ -151,10 +151,14 @@ command_result DTE::command(const std::string &cmd, got_line_cb got_line, uint32
|
||||
|
||||
bool DTE::exit_cmux()
|
||||
{
|
||||
if (!cmux_term) {
|
||||
return false;
|
||||
}
|
||||
if (!cmux_term->deinit()) {
|
||||
return false;
|
||||
}
|
||||
exit_cmux_internal();
|
||||
cmux_term.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -174,6 +178,10 @@ void DTE::exit_cmux_internal()
|
||||
|
||||
bool DTE::setup_cmux()
|
||||
{
|
||||
if (cmux_term) {
|
||||
ESP_LOGE("esp_modem_dte", "Cannot setup_cmux(), cmux_term already exists");
|
||||
return false;
|
||||
}
|
||||
cmux_term = std::make_shared<CMux>(primary_term, std::move(buffer));
|
||||
if (cmux_term == nullptr) {
|
||||
return false;
|
||||
@ -198,6 +206,11 @@ bool DTE::setup_cmux()
|
||||
|
||||
bool DTE::set_mode(modem_mode m)
|
||||
{
|
||||
// transitions (any) -> UNDEF
|
||||
if (m == modem_mode::UNDEF) {
|
||||
mode = m;
|
||||
return true;
|
||||
}
|
||||
// transitions (COMMAND|UNDEF) -> CMUX
|
||||
if (m == modem_mode::CMUX_MODE) {
|
||||
if (mode == modem_mode::UNDEF || mode == modem_mode::COMMAND_MODE) {
|
||||
@ -246,7 +259,7 @@ bool DTE::set_mode(modem_mode m)
|
||||
return false;
|
||||
}
|
||||
// manual CMUX transitions: Exit CMUX
|
||||
if (m == modem_mode::CMUX_MANUAL_EXIT && mode == modem_mode::CMUX_MANUAL_MODE) {
|
||||
if (m == modem_mode::CMUX_MANUAL_EXIT && (mode == modem_mode::CMUX_MANUAL_MODE || mode == modem_mode::UNDEF)) {
|
||||
if (exit_cmux()) {
|
||||
mode = modem_mode::COMMAND_MODE;
|
||||
return true;
|
||||
@ -255,7 +268,7 @@ bool DTE::set_mode(modem_mode m)
|
||||
return false;
|
||||
}
|
||||
// manual CMUX transitions: Swap terminals
|
||||
if (m == modem_mode::CMUX_MANUAL_SWAP && mode == modem_mode::CMUX_MANUAL_MODE) {
|
||||
if (m == modem_mode::CMUX_MANUAL_SWAP && (mode == modem_mode::CMUX_MANUAL_MODE || mode == modem_mode::UNDEF)) {
|
||||
secondary_term.swap(primary_term);
|
||||
set_command_callbacks();
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user