fix(modem): fixed minor code mistakes.

This commit is contained in:
robbedptechnics
2025-03-19 15:46:04 +01:00
parent b97dfc08b8
commit 317faf89ff
8 changed files with 123 additions and 123 deletions

View File

@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks # See https://pre-commit.com/hooks.html for more hooks
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0 rev: v5.0.0
hooks: hooks:
- id: check-yaml - id: check-yaml
- id: check-added-large-files - id: check-added-large-files
@ -13,12 +13,12 @@ repos:
- id: mixed-line-ending - id: mixed-line-ending
- id: debug-statements - id: debug-statements
- repo: https://github.com/pycqa/flake8 - repo: https://github.com/pycqa/flake8
rev: 5.0.4 rev: 7.1.2
hooks: hooks:
- id: flake8 - id: flake8
args: ['--config=.flake8', '--tee', '--benchmark'] args: ['--config=.flake8', '--tee', '--benchmark']
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.981 rev: v1.14.1
hooks: hooks:
- id: mypy - id: mypy
exclude: > exclude: >
@ -39,25 +39,25 @@ repos:
hooks: hooks:
- id: isort - id: isort
- repo: https://github.com/myint/eradicate/ - repo: https://github.com/myint/eradicate/
rev: v2.1.0 rev: 2.3.0
hooks: hooks:
- id: eradicate - id: eradicate
- repo: https://github.com/espressif/check-copyright/ - repo: https://github.com/espressif/check-copyright/
rev: v1.0.3 rev: v1.1.0
hooks: hooks:
- id: check-copyright - id: check-copyright
args: ['--ignore', 'ci/check_copyright_ignore.txt', '--config', 'ci/check_copyright_config.yaml'] args: ['--ignore', 'ci/check_copyright_ignore.txt', '--config', 'ci/check_copyright_config.yaml']
- repo: https://github.com/igrr/astyle_py.git - repo: https://github.com/igrr/astyle_py.git
rev: v1.0.5 rev: v1.1.0
hooks: hooks:
- id: astyle_py - id: astyle_py
args: ['--style=otbs', '--attach-namespaces', '--attach-classes', '--indent=spaces=4', '--convert-tabs', '--align-reference=name', '--keep-one-line-statements', '--pad-header', '--pad-oper', '--unpad-paren', '--max-continuation-indent=120', '--exclude-list=ci/ignore_astyle.txt'] args: ['--style=otbs', '--attach-namespaces', '--attach-classes', '--indent=spaces=4', '--convert-tabs', '--align-reference=name', '--keep-one-line-statements', '--pad-header', '--pad-oper', '--unpad-paren', '--max-continuation-indent=120', '--exclude-list=ci/ignore_astyle.txt']
- repo: https://github.com/commitizen-tools/commitizen - repo: https://github.com/commitizen-tools/commitizen
rev: v2.42.1 rev: v4.4.1
hooks: hooks:
- id: commitizen - id: commitizen
- id: commitizen-branch - id: commitizen-branch
stages: [push, manual] stages: [pre-push, manual]
- repo: local - repo: local
hooks: hooks:
- id: commit message scopes - id: commit message scopes

View File

@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string>
#include <list>
#include "esp_log.h"
#include "cxx_include/esp_modem_dte.hpp"
#include "cxx_include/esp_modem_dce_module.hpp"
static const char *TAG = "command_lib";
namespace esp_modem::dce_commands {
command_result generic_command(CommandableIf *t, const std::string &command,
const std::list<std::string_view> &pass_phrase,
const std::list<std::string_view> &fail_phrase,
uint32_t timeout_ms);
}

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -177,8 +177,7 @@ public:
command_result set_pdp_context(PdpContext &pdp) override; command_result set_pdp_context(PdpContext &pdp) override;
}; };
class SQNGM02S : public GenericModule class SQNGM02S : public GenericModule {
{
using GenericModule::GenericModule; using GenericModule::GenericModule;
public: public:

View File

@ -43,6 +43,8 @@ inline dce_factory::ModemType convert_modem_enum(esp_modem_dce_device_t module)
return esp_modem::dce_factory::ModemType::BG96; return esp_modem::dce_factory::ModemType::BG96;
case ESP_MODEM_DCE_SIM800: case ESP_MODEM_DCE_SIM800:
return esp_modem::dce_factory::ModemType::SIM800; return esp_modem::dce_factory::ModemType::SIM800;
case ESP_MODEM_DCE_SQNGM02S:
return esp_modem::dce_factory::ModemType::SQNGM02S;
default: default:
case ESP_MODEM_DCE_GENERIC: case ESP_MODEM_DCE_GENERIC:
return esp_modem::dce_factory::ModemType::GenericModule; return esp_modem::dce_factory::ModemType::GenericModule;

View File

@ -352,7 +352,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(config_mobile_termination_error, command_result, 1
* @param[in] edrx_value nible string containing encoded eDRX time * @param[in] edrx_value nible string containing encoded eDRX time
* @param[in] ptw_value nible string containing encoded Paging Time Window * @param[in] ptw_value nible string containing encoded Paging Time Window
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(config_edrx, command_result, 3, INT_IN(p1, mode), INT_IN(p2, access_technology), STRING_IN(p3, edrx_value), STRING_IN(p4, ptw_value)) \ ESP_MODEM_DECLARE_DCE_COMMAND(config_edrx, command_result, 3, INT_IN(p1, mode), INT_IN(p2, access_technology), STRING_IN(p3, edrx_value)) \
#ifdef GENERATE_DOCS #ifdef GENERATE_DOCS
// cat ../include/generate/esp_modem_command_declare.inc | clang++ -E -P -CC -xc++ -I../include -DGENERATE_DOCS - | sed -n '1,/DCE command documentation/!p' // cat ../include/generate/esp_modem_command_declare.inc | clang++ -E -P -CC -xc++ -I../include -DGENERATE_DOCS - | sed -n '1,/DCE command documentation/!p'

View File

@ -486,7 +486,7 @@ extern "C" esp_err_t esp_modem_config_mobile_termination_error(esp_modem_dce_t *
return command_response_to_esp_err(dce_wrap->dce->config_mobile_termination_error(mode)); return command_response_to_esp_err(dce_wrap->dce->config_mobile_termination_error(mode));
} }
extern "C" esp_err_t esp_modem_config_edrx(esp_modem_dce_t *dce, int mode, int access_technology, const char *edrx_value, const char *ptw_value) extern "C" esp_err_t esp_modem_config_edrx(esp_modem_dce_t *dce_wrap, int mode, int access_technology, const char *edrx_value, const char *ptw_value)
{ {
if (dce_wrap == nullptr || dce_wrap->dce == nullptr || mode > 3 || access_technology > 5) { if (dce_wrap == nullptr || dce_wrap->dce == nullptr || mode > 3 || access_technology > 5) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -12,11 +12,12 @@
#include "cxx_include/esp_modem_command_library.hpp" #include "cxx_include/esp_modem_command_library.hpp"
#include "cxx_include/esp_modem_command_library_utils.hpp" #include "cxx_include/esp_modem_command_library_utils.hpp"
#include "cxx17_include/esp_modem_command_library_17.hpp"
namespace esp_modem::dce_commands { namespace esp_modem::dce_commands {
static const char *TAG = "command_lib";
static command_result generic_command(CommandableIf *t, const std::string &command, command_result generic_command(CommandableIf *t, const std::string &command,
const std::list<std::string_view> &pass_phrase, const std::list<std::string_view> &pass_phrase,
const std::list<std::string_view> &fail_phrase, const std::list<std::string_view> &fail_phrase,
uint32_t timeout_ms) uint32_t timeout_ms)
@ -610,17 +611,16 @@ command_result get_gnss_power_mode(CommandableIf *t, int &mode)
command_result config_psm(CommandableIf *t, int enabled, const std::string &TAU, const std::string &activeTime) command_result config_psm(CommandableIf *t, int enabled, const std::string &TAU, const std::string &activeTime)
{ {
ESP_LOGV(TAG, "%s", __func__); ESP_LOGV(TAG, "%s", __func__);
if (enabled == true) if (enabled == true) {
{ return generic_command_common(t, "AT+CPSMS=1,,,\"" + TAU + "\"" + ",\"" + activeTime + "\"\r", 5000);
return generic_command_common(t, "AT+CPSMS=1,,,\"" + TAU + "\"" + ",\"" + activeTime + "\"\r", 500);
} }
return generic_command_common(t, "AT+CPSMS=" + std::to_string(enabled), 500); return generic_command_common(t, "AT+CPSMS=" + std::to_string(enabled) + "\r", 5000);
} }
command_result config_network_registration_urc(CommandableIf *t, int value) command_result config_network_registration_urc(CommandableIf *t, int value)
{ {
ESP_LOGV(TAG, "%s", __func__); ESP_LOGV(TAG, "%s", __func__);
return generic_command_common(t,"AT+CEREG=" + std::to_string(state) + "\r", 500); return generic_command_common(t, "AT+CEREG=" + std::to_string(value) + "\r", 500);
} }
command_result get_network_registration_state(CommandableIf *t, int &state) command_result get_network_registration_state(CommandableIf *t, int &state)
@ -656,21 +656,18 @@ command_result config_mobile_termination_error(CommandableIf *t, int value)
ESP_LOGV(TAG, "%s", __func__); ESP_LOGV(TAG, "%s", __func__);
return generic_command_common(t, "AT+CMEE=" + std::to_string(value) + "\r"); return generic_command_common(t, "AT+CMEE=" + std::to_string(value) + "\r");
} }
command_result config_edrx(int mode, int access_technology, const std::string &edrx_value, const std::string &ptw_value) command_result config_edrx(CommandableIf *t, int mode, int access_technology, const std::string &edrx_value)
{ {
if (mode == 1 || enabled == 2) if (mode == 1 || mode == 2) {
{ return dce_commands::generic_command_common(t,
return dce_commands::generic_command_common(dte.get(), "AT+CEDRXS=" +
"AT+SQNEDRX=" +
std::to_string(mode) + std::to_string(mode) +
"," + "," +
std::to_string(access_technology) + std::to_string(access_technology) +
",\"" + ",\"" +
edrx_value + edrx_value + "\"\r");
"\",\"" +
ptw_value + "\"\r");
} }
return dce_commands::generic_command_common(dte.get(), "AT+SQNEDRX=" + std::to_string(mode), 500); return dce_commands::generic_command_common(t, "AT+SQNEDRX=" + std::to_string(mode), 500);
} }
command_result set_gnss_power_mode_sim76xx(CommandableIf *t, int mode) command_result set_gnss_power_mode_sim76xx(CommandableIf *t, int mode)
{ {

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -7,6 +7,7 @@
#include "cxx_include/esp_modem_api.hpp" #include "cxx_include/esp_modem_api.hpp"
#include "cxx_include/esp_modem_dce_module.hpp" #include "cxx_include/esp_modem_dce_module.hpp"
#include "generate/esp_modem_command_declare.inc" #include "generate/esp_modem_command_declare.inc"
#include "cxx17_include/esp_modem_command_library_17.hpp"
namespace esp_modem { namespace esp_modem {
@ -87,59 +88,41 @@ command_result BG96::set_pdp_context(esp_modem::PdpContext &pdp)
return dce_commands::set_pdp_context(dte.get(), pdp, 300); return dce_commands::set_pdp_context(dte.get(), pdp, 300);
} }
command_result urc_callback(uint8_t *line, size_t len) bool SQNGM02S::setup_data_mode()
{ {
ESP_LOGI("WalterModem", "Received: %s", line); return true;
if (strstr((const char *)line, "+CEREG: 1"))
{
return command_result::OK; // Succesfully registered
}
else if (strstr((const char *)line, "+CEREG: 5"))
{
return command_result::OK; // Succesfully registered
}
else if (strstr((const char *)line, "+CEREG: 3"))
{
return command_result::FAIL; // Permission denied
}
return command_result::TIMEOUT;
} }
command_result SQNGM02S::connect(PdpContext &pdp) command_result SQNGM02S::connect(PdpContext &pdp)
{ {
command_result res; command_result res;
res = set_pdp_context(pdp); configure_pdp_context(std::make_unique<PdpContext>(pdp));
if (res != command_result::OK) set_pdp_context(*this->pdp);
return res;
res = config_network_registration_urc(1); res = config_network_registration_urc(1);
if (res != command_result::OK) if (res != command_result::OK) {
return res; return res;
}
res = set_radio_state(1); res = set_radio_state(1);
if (res != command_result::OK) if (res != command_result::OK) {
return res; return res;
}
//wait for +CEREG: 5 or +CEREG: 1. //wait for +CEREG: 5 or +CEREG: 1.
const auto pass = std::list<std::string_view>({"+CEREG: 1", "+CEREG: 5"});
const auto fail = std::list<std::string_view>({"ERROR"});
res = esp_modem::dce_commands::generic_command(dte.get(), "", pass, fail, 1200000);
do if (res != command_result::OK) {
{ config_network_registration_urc(0);
res = dte->command("", urc_callback, 20000, '\r');
} while (res == command_result::TIMEOUT);
if (res != command_result::OK)
return res; return res;
}
res = config_network_registration_urc(0); res = config_network_registration_urc(0);
if (res != command_result::OK) if (res != command_result::OK) {
return res; return res;
}
return command_result::OK; return command_result::OK;
} }
bool SQNGM02S::setup_data_mode()
{
ESP_LOGI("SQNGM02S", "setyp data mode");
return set_echo(false) == command_result::OK;
// PDP context has already been set before hand because SEQUANS modem must have already been connected/registered before setting up cmux
}
} }