From d3f7ea67fb1a62f92a187521ec36701eeb23ff1b Mon Sep 17 00:00:00 2001 From: "Sjur G. Wroldsen" Date: Wed, 13 Apr 2022 13:41:56 +0200 Subject: [PATCH 01/10] Add: Expanded modem_command_library with more "standard" commands --- .../generate/esp_modem_command_declare.inc | 90 +++++++++++++- components/esp_modem/src/esp_modem_c_api.cpp | 97 +++++++++++++++ .../src/esp_modem_command_library.cpp | 112 ++++++++++++++++++ 3 files changed, 298 insertions(+), 1 deletion(-) diff --git a/components/esp_modem/include/generate/esp_modem_command_declare.inc b/components/esp_modem/include/generate/esp_modem_command_declare.inc index 0c1a6bdbb..20862594d 100644 --- a/components/esp_modem/include/generate/esp_modem_command_declare.inc +++ b/components/esp_modem/include/generate/esp_modem_command_declare.inc @@ -28,6 +28,7 @@ #define BOOL_IN(param, name) const bool _ARG(param, name) #define BOOL_OUT(param, name) bool& _ARG(param, name) #define INT_OUT(param, name) int& _ARG(param, name) +#define LIST_IN(param, name) const int* _ARG(param, name) #define STRUCT_OUT(struct_name, p1) struct_name& p1 #else @@ -36,6 +37,7 @@ #define BOOL_IN(param, name) const bool _ARG(param, name) #define BOOL_OUT(param, name) bool* _ARG(param, name) #define INT_OUT(param, name) int* _ARG(param, name) +#define LIST_IN(param, name) const int* _ARG(param, name) #define STRUCT_OUT(struct_name, p1) struct struct_name* p1 #endif @@ -200,7 +202,93 @@ ESP_MODEM_DECLARE_DCE_COMMAND(reset, command_result, 0) \ * @param[in] baud Desired baud rate of the DTE * @return OK, FAIL or TIMEOUT */ \ -ESP_MODEM_DECLARE_DCE_COMMAND(set_baud, command_result, 1, INT_IN(p1, baud)) +ESP_MODEM_DECLARE_DCE_COMMAND(set_baud, command_result, 1, INT_IN(p1, baud)) \ + \ +/** + * @brief Force an attempt to connect to a specific operator + * @param[in] mode mode of attempt + * mode=0 - automatic + * mode=1 - manual + * mode=2 - deregister + * mode=3 - set format for read operation + * mode=4 - manual with fallback to automatic + * @param[in] format what format the operator is given in + * format=0 - long format + * format=1 - short format + * format=2 - numeric + * @param[in] oper the operator to connect to + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_operator, command_result, 3, INT_IN(p1, mode), INT_IN(p2, format), STRING_IN(p3, oper)) \ + \ +/** + * @brief Attach or detach from the GPRS service + * @param[in] state 1-attach 0-detach + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_network_attachment_state, command_result, 1, INT_IN(p1, state)) \ + \ +/** + * @brief Get network attachment state + * @param[out] state 1-attached 0-detached + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(get_network_attachment_state, command_result, 1, INT_OUT(p1, state)) \ + \ +/** + * @brief What mode the radio should be set to + * @param[in] state state 1-full 0-minimum ... + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_radio_state, command_result, 1, INT_IN(p1, state)) \ + \ +/** + * @brief Get current radio state + * @param[out] state 1-full 0-minimum ... + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(get_radio_state, command_result, 1, INT_OUT(p1, state)) \ + \ +/** + * @brief Set network mode + * @param[in] mode preferred mode + * -- SIM7xxx -- + * mode=2 - Automatic + * mode=13 - GSM only + * mode=38 - LTE only + * mode=51 - GSM and LTE only + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_network_mode, command_result, 1, INT_IN(p1, mode)) \ + \ +/** + * @brief Preferred network mode (CAT-M and/or NB-IoT) + * @param[in] mode preferred selection + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_preferred_mode, command_result, 1, INT_IN(p1, mode)) \ + \ +/** + * @brief Set network bands for CAT-M or NB-IoT + * @param[in] mode CAT-M or NB-IoT + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_network_bands, command_result, 3, STRING_IN(p1, mode), LIST_IN(p2, bands), INT_IN(p3, size)) \ + \ +/** + * @brief Show network system mode + * @param[out] mode current network mode + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(get_network_system_mode, command_result, 1, INT_OUT(p1, mode)) \ + \ +/** + * @brief GNSS power control + * @param[out] mode power mode (0 - off, 1 - on) + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_gnss_power_mode, command_result, 1, INT_IN(p1, mode)) \ + \ #ifdef GENERATE_DOCS diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index 0753c7f30..afe90616d 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -271,3 +271,100 @@ extern "C" esp_err_t esp_modem_power_down(esp_modem_dce_t *dce_wrap) } return command_response_to_esp_err(dce_wrap->dce->power_down()); } + +extern "C" esp_err_t esp_modem_set_operator(esp_modem_dce_t *dce_wrap, int mode, int format, const char* oper) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + std::string operator_str = std::string(oper); + return command_response_to_esp_err(dce_wrap->dce->set_operator(mode, format, operator_str)); +} + +extern "C" esp_err_t esp_modem_set_network_attachment_state(esp_modem_dce_t *dce_wrap, int state) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + return command_response_to_esp_err(dce_wrap->dce->set_network_attachment_state(state)); +} + +extern "C" esp_err_t esp_modem_get_network_attachment_state(esp_modem_dce_t *dce_wrap, int *p_state) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + int state; + auto ret = command_response_to_esp_err(dce_wrap->dce->get_network_attachment_state(state)); + if (ret == ESP_OK) { + *p_state = state; + } + return ret; +} + +extern "C" esp_err_t esp_modem_set_radio_state(esp_modem_dce_t *dce_wrap, int state) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + return command_response_to_esp_err(dce_wrap->dce->set_radio_state(state)); +} + +extern "C" esp_err_t esp_modem_get_radio_state(esp_modem_dce_t *dce_wrap, int *p_state) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + int state; + auto ret = command_response_to_esp_err(dce_wrap->dce->get_radio_state(state)); + if (ret == ESP_OK) { + *p_state = state; + } + return ret; +} + +extern "C" esp_err_t esp_modem_set_network_mode(esp_modem_dce_t *dce_wrap, int mode) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + return command_response_to_esp_err(dce_wrap->dce->set_network_mode(mode)); +} + +extern "C" esp_err_t esp_modem_set_preferred_mode(esp_modem_dce_t *dce_wrap, int mode) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + return command_response_to_esp_err(dce_wrap->dce->set_preferred_mode(mode)); +} + +extern "C" esp_err_t esp_modem_set_network_bands(esp_modem_dce_t *dce_wrap, const char* mode, const int* bands, int size) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + std::string mode_str = std::string(mode); + return command_response_to_esp_err(dce_wrap->dce->set_network_bands(mode, bands, size)); +} + +extern "C" esp_err_t esp_modem_get_network_system_mode(esp_modem_dce_t *dce_wrap, int* p_mode) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + int mode; + auto ret = command_response_to_esp_err(dce_wrap->dce->get_network_system_mode(mode)); + if (ret == ESP_OK) { + *p_mode = mode; + } + return ret; +} + +extern "C" esp_err_t esp_modem_set_gnss_power_mode(esp_modem_dce_t *dce_wrap, int mode) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + return command_response_to_esp_err(dce_wrap->dce->set_gnss_power_mode(mode)); +} diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 450ede273..2c67d14d6 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -399,4 +399,116 @@ command_result get_signal_quality(CommandableIf *t, int &rssi, int &ber) return command_result::OK; } +command_result set_operator(CommandableIf *t, int mode, int format, const std::string& oper) +{ + ESP_LOGV(TAG, "%s", __func__ ); + return generic_command_common(t, "AT+COPS=" + std::to_string(mode) + "," + std::to_string(format) + ",\"" + oper + "\"\r", 90000); +} + +command_result set_network_attachment_state(CommandableIf *t, int state) +{ + ESP_LOGV(TAG, "%s", __func__ ); + return generic_command_common(t, "AT+CGATT=" + std::to_string(state) + "\r"); +} + +command_result get_network_attachment_state(CommandableIf *t, int &state) +{ + ESP_LOGV(TAG, "%s", __func__ ); + std::string_view out; + auto ret = generic_get_string(t, "AT+CGATT?\r", out); + if (ret != command_result::OK) { + return ret; + } + constexpr std::string_view pattern = "+CGATT: "; + constexpr int pos = pattern.size(); + if (out.find(pattern) == std::string::npos) { + return command_result::FAIL; + } + + if (std::from_chars(out.data() + pos, out.data() + out.size(), state).ec == std::errc::invalid_argument) { + return command_result::FAIL; + } + + return command_result::OK; +} + +command_result set_radio_state(CommandableIf *t, int state) +{ + ESP_LOGV(TAG, "%s", __func__ ); + return generic_command_common(t, "AT+CFUN=" + std::to_string(state) + "\r"); +} + +command_result get_radio_state(CommandableIf *t, int &state) +{ + ESP_LOGV(TAG, "%s", __func__ ); + std::string_view out; + auto ret = generic_get_string(t, "AT+CFUN?\r", out); + if (ret != command_result::OK) { + return ret; + } + constexpr std::string_view pattern = "+CFUN: "; + constexpr int pos = pattern.size(); + if (out.find(pattern) == std::string::npos) { + return command_result::FAIL; + } + + if (std::from_chars(out.data() + pos, out.data() + out.size(), state).ec == std::errc::invalid_argument) { + return command_result::FAIL; + } + + return command_result::OK; +} + +command_result set_network_mode(CommandableIf *t, int mode) +{ + ESP_LOGV(TAG, "%s", __func__ ); + return generic_command_common(t, "AT+CNMP=" + std::to_string(mode) + "\r"); +} + +command_result set_preferred_mode(CommandableIf *t, int mode) +{ + ESP_LOGV(TAG, "%s", __func__ ); + return generic_command_common(t, "AT+CMNB=" + std::to_string(mode) + "\r"); +} + +command_result set_network_bands(CommandableIf *t, const std::string& mode, const int* bands, int size) +{ + ESP_LOGV(TAG, "%s", __func__ ); + std::string band_string = ""; + for (int i = 0; i," + if (out.find(pattern) == std::string::npos) { + return command_result::FAIL; + } + + if (std::from_chars(out.data() + mode_pos, out.data() + out.size(), mode).ec == std::errc::invalid_argument) { + return command_result::FAIL; + } + + return command_result::OK; +} + +command_result set_gnss_power_mode(CommandableIf *t, int mode) +{ + ESP_LOGV(TAG, "%s", __func__ ); + return generic_command_common(t, "AT+CGNSPWR=" + std::to_string(mode) + "\r"); +} + } // esp_modem::dce_commands \ No newline at end of file From bb7f198bea8bb8a964cac521c37582c14ab5b330 Mon Sep 17 00:00:00 2001 From: "Sjur G. Wroldsen" Date: Wed, 13 Apr 2022 13:42:57 +0200 Subject: [PATCH 02/10] Add: sim7070 support --- .../esp_modem/include/cxx_include/esp_modem_api.hpp | 5 +++++ .../include/cxx_include/esp_modem_command_library.hpp | 3 ++- .../include/cxx_include/esp_modem_dce_factory.hpp | 7 +++++++ .../include/cxx_include/esp_modem_dce_module.hpp | 9 +++++++++ components/esp_modem/include/esp_modem_c_api_types.h | 1 + components/esp_modem/src/esp_modem_api.cpp | 5 +++++ components/esp_modem/src/esp_modem_c_api.cpp | 2 ++ components/esp_modem/src/esp_modem_command_library.cpp | 8 +++++++- components/esp_modem/src/esp_modem_modules.cpp | 7 ++++++- 9 files changed, 44 insertions(+), 3 deletions(-) diff --git a/components/esp_modem/include/cxx_include/esp_modem_api.hpp b/components/esp_modem/include/cxx_include/esp_modem_api.hpp index 7e9626e98..57299bd17 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_api.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_api.hpp @@ -82,6 +82,11 @@ std::shared_ptr create_vfs_dte(const dte_config *config); */ std::unique_ptr create_SIM7600_dce(const dce_config *config, std::shared_ptr dte, esp_netif_t *netif); +/** + * @brief Create DCE based on SIM7070 module + */ +std::unique_ptr create_SIM7070_dce(const dce_config *config, std::shared_ptr dte, esp_netif_t *netif); + /** * @brief Create DCE based on SIM800 module */ diff --git a/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp b/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp index 6af7a4ed0..46f5707a2 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp @@ -44,7 +44,8 @@ DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);) * @brief Following commands that are different for some specific modules */ command_result get_battery_status_sim7xxx(CommandableIf *t, int &voltage, int &bcs, int &bcl); -command_result power_down_sim7xxx(CommandableIf *t); +command_result power_down_sim7600(CommandableIf *t); +command_result power_down_sim7070(CommandableIf *t); command_result power_down_sim8xx(CommandableIf *t); command_result set_data_mode_sim8xx(CommandableIf *t); diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp index 0050df278..61b8cd7e9 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp @@ -117,6 +117,7 @@ private: enum class ModemType { GenericModule, /*!< Default generic module with the most common commands */ SIM7600, /*!< Derived from the GenericModule, specifics applied to SIM7600 model */ + SIM7070, /*!< Derived from the GenericModule, specifics applied to SIM7070 model */ BG96, /*!< Derived from the GenericModule, specifics applied to BG69 model */ SIM800, /*!< Derived from the GenericModule with specifics applied to SIM800 model */ }; @@ -173,6 +174,8 @@ public: return build_shared_module(cfg, std::forward(args)...); case ModemType::SIM7600: return build_shared_module(cfg, std::forward(args)...); + case ModemType::SIM7070: + return build_shared_module(cfg, std::forward(args)...); case ModemType::BG96: return build_shared_module(cfg, std::forward(args)...); case ModemType::GenericModule: @@ -198,6 +201,8 @@ public: return build_unique(cfg, std::forward(args)...); case ModemType::SIM7600: return build_unique(cfg, std::forward(args)...); + case ModemType::SIM7070: + return build_unique(cfg, std::forward(args)...); case ModemType::BG96: return build_unique(cfg, std::forward(args)...); case ModemType::GenericModule: @@ -216,6 +221,8 @@ public: return build(cfg, std::forward(args)...); case ModemType::SIM7600: return build(cfg, std::forward(args)...); + case ModemType::SIM7070: + return build(cfg, std::forward(args)...); case ModemType::BG96: return build(cfg, std::forward(args)...); case ModemType::GenericModule: diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp index b80f2d156..fdbe5a890 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp @@ -123,6 +123,15 @@ public: command_result power_down() override; }; +/** + * @brief Specific definition of the SIM7070 module + */ +class SIM7070: public GenericModule { + using GenericModule::GenericModule; +public: + command_result power_down() override; +}; + /** * @brief Specific definition of the SIM800 module */ diff --git a/components/esp_modem/include/esp_modem_c_api_types.h b/components/esp_modem/include/esp_modem_c_api_types.h index d02cf2f8e..91ef9f00e 100644 --- a/components/esp_modem/include/esp_modem_c_api_types.h +++ b/components/esp_modem/include/esp_modem_c_api_types.h @@ -47,6 +47,7 @@ typedef enum esp_modem_dce_mode typedef enum esp_modem_dce_device { ESP_MODEM_DCE_GENETIC, /**< The most generic device */ + ESP_MODEM_DCE_SIM7070, ESP_MODEM_DCE_SIM7600, ESP_MODEM_DCE_BG96, ESP_MODEM_DCE_SIM800, diff --git a/components/esp_modem/src/esp_modem_api.cpp b/components/esp_modem/src/esp_modem_api.cpp index f2c118f26..6390139cc 100644 --- a/components/esp_modem/src/esp_modem_api.cpp +++ b/components/esp_modem/src/esp_modem_api.cpp @@ -54,6 +54,11 @@ std::unique_ptr create_SIM7600_dce(const dce_config *config, std::shared_pt return create_modem_dce(dce_factory::ModemType::SIM7600, config, std::move(dte), netif); } +std::unique_ptr create_SIM7070_dce(const dce_config *config, std::shared_ptr dte, esp_netif_t *netif) +{ + return create_modem_dce(dce_factory::ModemType::SIM7070, config, std::move(dte), netif); +} + std::unique_ptr create_SIM800_dce(const dce_config *config, std::shared_ptr dte, esp_netif_t *netif) { return create_modem_dce(dce_factory::ModemType::SIM800, config, std::move(dte), netif); diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index afe90616d..a6ca9c7d5 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -59,6 +59,8 @@ static inline dce_factory::ModemType convert_modem_enum(esp_modem_dce_device_t m switch (module) { case ESP_MODEM_DCE_SIM7600: return esp_modem::dce_factory::ModemType::SIM7600; + case ESP_MODEM_DCE_SIM7070: + return esp_modem::dce_factory::ModemType::SIM7070; case ESP_MODEM_DCE_BG96: return esp_modem::dce_factory::ModemType::BG96; case ESP_MODEM_DCE_SIM800: diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 2c67d14d6..d9ce32a92 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -121,12 +121,18 @@ command_result power_down(CommandableIf *t) return generic_command(t, "AT+QPOWD=1\r", "POWERED DOWN", "ERROR", 1000); } -command_result power_down_sim7xxx(CommandableIf *t) +command_result power_down_sim7600(CommandableIf *t) { ESP_LOGV(TAG, "%s", __func__ ); return generic_command_common(t, "AT+CPOF\r", 1000); } +command_result power_down_sim7070(CommandableIf *t) +{ + ESP_LOGV(TAG, "%s", __func__ ); + return generic_command(t, "AT+CPOWD=1\r", "POWER DOWN", "ERROR", 1000); +} + command_result power_down_sim8xx(CommandableIf *t) { ESP_LOGV(TAG, "%s", __func__ ); diff --git a/components/esp_modem/src/esp_modem_modules.cpp b/components/esp_modem/src/esp_modem_modules.cpp index fd9307b1d..ef0c770f8 100644 --- a/components/esp_modem/src/esp_modem_modules.cpp +++ b/components/esp_modem/src/esp_modem_modules.cpp @@ -57,7 +57,12 @@ command_result SIM7600::get_battery_status(int &voltage, int &bcs, int &bcl) command_result SIM7600::power_down() { - return dce_commands::power_down_sim7xxx(dte.get()); + return dce_commands::power_down_sim7600(dte.get()); +} + +command_result SIM7070::power_down() +{ + return dce_commands::power_down_sim7070(dte.get()); } command_result SIM800::power_down() From 15cbc9bd509e0208495dd41c9cae3511ef7b379b Mon Sep 17 00:00:00 2001 From: "Sjur G. Wroldsen" Date: Wed, 13 Apr 2022 13:44:11 +0200 Subject: [PATCH 03/10] Update: modem_mode::UNDEF initially --- components/esp_modem/include/cxx_include/esp_modem_dce.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce.hpp index 3757b12d2..7d080bf10 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce.hpp @@ -34,7 +34,7 @@ namespace esp_modem { */ class DCE_Mode { public: - DCE_Mode(): mode(modem_mode::COMMAND_MODE) {} + DCE_Mode(): mode(modem_mode::UNDEF) {} ~DCE_Mode() = default; bool set(DTE *dte, ModuleIf *module, Netif &netif, modem_mode m); modem_mode get(); From 0733ea8ff48096d8824d6c6d079b9623a91bc0ab Mon Sep 17 00:00:00 2001 From: "Sjur G. Wroldsen" Date: Wed, 13 Apr 2022 15:36:15 +0200 Subject: [PATCH 04/10] Add: Support for SIM7000 modules --- .../esp_modem/include/cxx_include/esp_modem_api.hpp | 6 ++++++ .../include/cxx_include/esp_modem_command_library.hpp | 4 ++-- .../include/cxx_include/esp_modem_dce_factory.hpp | 7 +++++++ .../include/cxx_include/esp_modem_dce_module.hpp | 9 +++++++++ components/esp_modem/include/esp_modem_c_api_types.h | 3 ++- components/esp_modem/src/esp_modem_api.cpp | 5 +++++ components/esp_modem/src/esp_modem_c_api.cpp | 2 ++ components/esp_modem/src/esp_modem_command_library.cpp | 4 ++-- components/esp_modem/src/esp_modem_modules.cpp | 9 +++++++-- 9 files changed, 42 insertions(+), 7 deletions(-) diff --git a/components/esp_modem/include/cxx_include/esp_modem_api.hpp b/components/esp_modem/include/cxx_include/esp_modem_api.hpp index 57299bd17..b74ea8b36 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_api.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_api.hpp @@ -87,6 +87,12 @@ std::unique_ptr create_SIM7600_dce(const dce_config *config, std::shared_pt */ std::unique_ptr create_SIM7070_dce(const dce_config *config, std::shared_ptr dte, esp_netif_t *netif); +/** + * @brief Create DCE based on SIM7000 module + */ +std::unique_ptr create_SIM7000_dce(const dce_config *config, std::shared_ptr dte, esp_netif_t *netif); + + /** * @brief Create DCE based on SIM800 module */ diff --git a/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp b/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp index 46f5707a2..0a92afd9d 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp @@ -44,8 +44,8 @@ DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);) * @brief Following commands that are different for some specific modules */ command_result get_battery_status_sim7xxx(CommandableIf *t, int &voltage, int &bcs, int &bcl); -command_result power_down_sim7600(CommandableIf *t); -command_result power_down_sim7070(CommandableIf *t); +command_result power_down_sim76xx(CommandableIf *t); +command_result power_down_sim70xx(CommandableIf *t); command_result power_down_sim8xx(CommandableIf *t); command_result set_data_mode_sim8xx(CommandableIf *t); diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp index 61b8cd7e9..17d51516d 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp @@ -118,6 +118,7 @@ enum class ModemType { GenericModule, /*!< Default generic module with the most common commands */ SIM7600, /*!< Derived from the GenericModule, specifics applied to SIM7600 model */ SIM7070, /*!< Derived from the GenericModule, specifics applied to SIM7070 model */ + SIM7000, /*!< Derived from the GenericModule, specifics applied to SIM7000 model */ BG96, /*!< Derived from the GenericModule, specifics applied to BG69 model */ SIM800, /*!< Derived from the GenericModule with specifics applied to SIM800 model */ }; @@ -176,6 +177,8 @@ public: return build_shared_module(cfg, std::forward(args)...); case ModemType::SIM7070: return build_shared_module(cfg, std::forward(args)...); + case ModemType::SIM7000: + return build_shared_module(cfg, std::forward(args)...); case ModemType::BG96: return build_shared_module(cfg, std::forward(args)...); case ModemType::GenericModule: @@ -203,6 +206,8 @@ public: return build_unique(cfg, std::forward(args)...); case ModemType::SIM7070: return build_unique(cfg, std::forward(args)...); + case ModemType::SIM7000: + return build_unique(cfg, std::forward(args)...); case ModemType::BG96: return build_unique(cfg, std::forward(args)...); case ModemType::GenericModule: @@ -223,6 +228,8 @@ public: return build(cfg, std::forward(args)...); case ModemType::SIM7070: return build(cfg, std::forward(args)...); + case ModemType::SIM7000: + return build(cfg, std::forward(args)...); case ModemType::BG96: return build(cfg, std::forward(args)...); case ModemType::GenericModule: diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp index fdbe5a890..435893bca 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp @@ -132,6 +132,15 @@ public: command_result power_down() override; }; +/** + * @brief Specific definition of the SIM7000 module + */ +class SIM7000: public GenericModule { + using GenericModule::GenericModule; +public: + command_result power_down() override; +}; + /** * @brief Specific definition of the SIM800 module */ diff --git a/components/esp_modem/include/esp_modem_c_api_types.h b/components/esp_modem/include/esp_modem_c_api_types.h index 91ef9f00e..577b4ce03 100644 --- a/components/esp_modem/include/esp_modem_c_api_types.h +++ b/components/esp_modem/include/esp_modem_c_api_types.h @@ -47,8 +47,9 @@ typedef enum esp_modem_dce_mode typedef enum esp_modem_dce_device { ESP_MODEM_DCE_GENETIC, /**< The most generic device */ - ESP_MODEM_DCE_SIM7070, ESP_MODEM_DCE_SIM7600, + ESP_MODEM_DCE_SIM7070, + ESP_MODEM_DCE_SIM7000, ESP_MODEM_DCE_BG96, ESP_MODEM_DCE_SIM800, } esp_modem_dce_device_t; diff --git a/components/esp_modem/src/esp_modem_api.cpp b/components/esp_modem/src/esp_modem_api.cpp index 6390139cc..116213ff9 100644 --- a/components/esp_modem/src/esp_modem_api.cpp +++ b/components/esp_modem/src/esp_modem_api.cpp @@ -59,6 +59,11 @@ std::unique_ptr create_SIM7070_dce(const dce_config *config, std::shared_pt return create_modem_dce(dce_factory::ModemType::SIM7070, config, std::move(dte), netif); } +std::unique_ptr create_SIM7000_dce(const dce_config *config, std::shared_ptr dte, esp_netif_t *netif) +{ + return create_modem_dce(dce_factory::ModemType::SIM7000, config, std::move(dte), netif); +} + std::unique_ptr create_SIM800_dce(const dce_config *config, std::shared_ptr dte, esp_netif_t *netif) { return create_modem_dce(dce_factory::ModemType::SIM800, config, std::move(dte), netif); diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index a6ca9c7d5..9a927b416 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -61,6 +61,8 @@ static inline dce_factory::ModemType convert_modem_enum(esp_modem_dce_device_t m return esp_modem::dce_factory::ModemType::SIM7600; case ESP_MODEM_DCE_SIM7070: return esp_modem::dce_factory::ModemType::SIM7070; + case ESP_MODEM_DCE_SIM7000: + return esp_modem::dce_factory::ModemType::SIM7000; case ESP_MODEM_DCE_BG96: return esp_modem::dce_factory::ModemType::BG96; case ESP_MODEM_DCE_SIM800: diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index d9ce32a92..cfb60d52c 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -121,13 +121,13 @@ command_result power_down(CommandableIf *t) return generic_command(t, "AT+QPOWD=1\r", "POWERED DOWN", "ERROR", 1000); } -command_result power_down_sim7600(CommandableIf *t) +command_result power_down_sim76xx(CommandableIf *t) { ESP_LOGV(TAG, "%s", __func__ ); return generic_command_common(t, "AT+CPOF\r", 1000); } -command_result power_down_sim7070(CommandableIf *t) +command_result power_down_sim70xx(CommandableIf *t) { ESP_LOGV(TAG, "%s", __func__ ); return generic_command(t, "AT+CPOWD=1\r", "POWER DOWN", "ERROR", 1000); diff --git a/components/esp_modem/src/esp_modem_modules.cpp b/components/esp_modem/src/esp_modem_modules.cpp index ef0c770f8..91c893c03 100644 --- a/components/esp_modem/src/esp_modem_modules.cpp +++ b/components/esp_modem/src/esp_modem_modules.cpp @@ -57,12 +57,17 @@ command_result SIM7600::get_battery_status(int &voltage, int &bcs, int &bcl) command_result SIM7600::power_down() { - return dce_commands::power_down_sim7600(dte.get()); + return dce_commands::power_down_sim76xx(dte.get()); } command_result SIM7070::power_down() { - return dce_commands::power_down_sim7070(dte.get()); + return dce_commands::power_down_sim70xx(dte.get()); +} + +command_result SIM7000::power_down() +{ + return dce_commands::power_down_sim70xx(dte.get()); } command_result SIM800::power_down() From 15ed885035b759a415c87636689ef33ea9cee81c Mon Sep 17 00:00:00 2001 From: "Sjur G. Wroldsen" Date: Tue, 19 Apr 2022 16:23:22 +0200 Subject: [PATCH 05/10] Add: Sim7600 extended support --- .../cxx_include/esp_modem_command_library.hpp | 2 ++ .../cxx_include/esp_modem_dce_module.hpp | 2 ++ .../src/esp_modem_command_library.cpp | 22 +++++++++++++++++++ .../esp_modem/src/esp_modem_modules.cpp | 10 +++++++++ 4 files changed, 36 insertions(+) diff --git a/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp b/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp index 0a92afd9d..1952d44f1 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_command_library.hpp @@ -44,8 +44,10 @@ DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);) * @brief Following commands that are different for some specific modules */ command_result get_battery_status_sim7xxx(CommandableIf *t, int &voltage, int &bcs, int &bcl); +command_result set_gnss_power_mode_sim76xx(CommandableIf *t, int mode); command_result power_down_sim76xx(CommandableIf *t); command_result power_down_sim70xx(CommandableIf *t); +command_result set_network_bands_sim76xx(CommandableIf *t, const std::string& mode, const int* bands, int size); command_result power_down_sim8xx(CommandableIf *t); command_result set_data_mode_sim8xx(CommandableIf *t); diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp index 435893bca..628d2e877 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce_module.hpp @@ -121,6 +121,8 @@ class SIM7600: public GenericModule { public: command_result get_battery_status(int &voltage, int &bcs, int &bcl) override; command_result power_down() override; + command_result set_gnss_power_mode(int mode) override; + command_result set_network_bands(const std::string& mode, const int* bands, int size) override; }; /** diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index cfb60d52c..9b6be6691 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -18,6 +18,7 @@ #include "cxx_include/esp_modem_dte.hpp" #include "cxx_include/esp_modem_dce_module.hpp" #include "cxx_include/esp_modem_command_library.hpp" +#include namespace esp_modem::dce_commands { @@ -489,6 +490,21 @@ command_result set_network_bands(CommandableIf *t, const std::string& mode, cons return generic_command_common(t, "AT+CBANDCFG=\"" + mode + "\"," + band_string + "\r"); } +command_result set_network_bands_sim76xx(CommandableIf *t, const std::string& mode, const int* bands, int size) +{ + ESP_LOGV(TAG, "%s", __func__ ); + std::string any_mode = "0xFFFFFFFF7FFFFFFF"; + uint64_t band_bits = 0; + for (int i = 0; i Date: Wed, 20 Apr 2022 09:16:05 +0200 Subject: [PATCH 06/10] Update: Formatting --- components/esp_modem/src/esp_modem_c_api.cpp | 4 ++-- components/esp_modem/src/esp_modem_command_library.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index 9a927b416..6f5a6ad7f 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -281,7 +281,7 @@ extern "C" esp_err_t esp_modem_set_operator(esp_modem_dce_t *dce_wrap, int mode, if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { return ESP_ERR_INVALID_ARG; } - std::string operator_str = std::string(oper); + std::string operator_str(oper); return command_response_to_esp_err(dce_wrap->dce->set_operator(mode, format, operator_str)); } @@ -348,7 +348,7 @@ extern "C" esp_err_t esp_modem_set_network_bands(esp_modem_dce_t *dce_wrap, cons if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { return ESP_ERR_INVALID_ARG; } - std::string mode_str = std::string(mode); + std::string mode_str(mode); return command_response_to_esp_err(dce_wrap->dce->set_network_bands(mode, bands, size)); } diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 9b6be6691..8509e8b77 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -482,7 +482,7 @@ command_result set_network_bands(CommandableIf *t, const std::string& mode, cons { ESP_LOGV(TAG, "%s", __func__ ); std::string band_string = ""; - for (int i = 0; i Date: Wed, 20 Apr 2022 09:37:39 +0200 Subject: [PATCH 07/10] Update: Removed duplicate power down function Add: gnss power mode function --- components/esp_modem/src/esp_modem_command_library.cpp | 3 ++- components/esp_modem/src/esp_modem_modules.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 8509e8b77..7b3a0dbaa 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -490,10 +490,11 @@ command_result set_network_bands(CommandableIf *t, const std::string& mode, cons return generic_command_common(t, "AT+CBANDCFG=\"" + mode + "\"," + band_string + "\r"); } +// mode is expected to be 64bit string (in hex) +// any_mode = "0xFFFFFFFF7FFFFFFF"; command_result set_network_bands_sim76xx(CommandableIf *t, const std::string& mode, const int* bands, int size) { ESP_LOGV(TAG, "%s", __func__ ); - //std::string any_mode = "0xFFFFFFFF7FFFFFFF"; uint64_t band_bits = 0; for (int i = 0; i Date: Tue, 24 May 2022 14:53:11 +0200 Subject: [PATCH 08/10] Update: Changed tests to coincide with new initial esp_modem mode --- components/esp_modem/test/host_test/main/test_modem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/esp_modem/test/host_test/main/test_modem.cpp b/components/esp_modem/test/host_test/main/test_modem.cpp index f2305e9e0..d8c4c9746 100644 --- a/components/esp_modem/test/host_test/main/test_modem.cpp +++ b/components/esp_modem/test/host_test/main/test_modem.cpp @@ -128,6 +128,7 @@ TEST_CASE("DCE modes", "[esp_modem]") auto dce = create_SIM7600_dce(&dce_config, dte, &netif); CHECK(dce != nullptr); + CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true); CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == false); CHECK(dce->set_mode(esp_modem::modem_mode::DATA_MODE) == true); CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true); From ba88d7fdbc382cd867db5982faaa87eb4b1deccb Mon Sep 17 00:00:00 2001 From: sjurgw Date: Tue, 24 May 2022 14:53:58 +0200 Subject: [PATCH 09/10] Update: Renamed list_in to be type-specific Update: Removed modem-specific comment --- .../include/generate/esp_modem_command_declare.inc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/components/esp_modem/include/generate/esp_modem_command_declare.inc b/components/esp_modem/include/generate/esp_modem_command_declare.inc index 20862594d..58d85a575 100644 --- a/components/esp_modem/include/generate/esp_modem_command_declare.inc +++ b/components/esp_modem/include/generate/esp_modem_command_declare.inc @@ -28,7 +28,7 @@ #define BOOL_IN(param, name) const bool _ARG(param, name) #define BOOL_OUT(param, name) bool& _ARG(param, name) #define INT_OUT(param, name) int& _ARG(param, name) -#define LIST_IN(param, name) const int* _ARG(param, name) +#define INTEGER_LIST_IN(param, name) const int* _ARG(param, name) #define STRUCT_OUT(struct_name, p1) struct_name& p1 #else @@ -37,7 +37,7 @@ #define BOOL_IN(param, name) const bool _ARG(param, name) #define BOOL_OUT(param, name) bool* _ARG(param, name) #define INT_OUT(param, name) int* _ARG(param, name) -#define LIST_IN(param, name) const int* _ARG(param, name) +#define INTEGER_LIST_IN(param, name) const int* _ARG(param, name) #define STRUCT_OUT(struct_name, p1) struct struct_name* p1 #endif @@ -252,11 +252,6 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_radio_state, command_result, 1, INT_OUT(p1, st /** * @brief Set network mode * @param[in] mode preferred mode - * -- SIM7xxx -- - * mode=2 - Automatic - * mode=13 - GSM only - * mode=38 - LTE only - * mode=51 - GSM and LTE only * @return OK, FAIL or TIMEOUT */ \ ESP_MODEM_DECLARE_DCE_COMMAND(set_network_mode, command_result, 1, INT_IN(p1, mode)) \ @@ -273,7 +268,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_preferred_mode, command_result, 1, INT_IN(p1, * @param[in] mode CAT-M or NB-IoT * @return OK, FAIL or TIMEOUT */ \ -ESP_MODEM_DECLARE_DCE_COMMAND(set_network_bands, command_result, 3, STRING_IN(p1, mode), LIST_IN(p2, bands), INT_IN(p3, size)) \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_network_bands, command_result, 3, STRING_IN(p1, mode), INTEGER_LIST_IN(p2, bands), INT_IN(p3, size)) \ \ /** * @brief Show network system mode From 3ced2d970961b94911ca303e7578de220516f811 Mon Sep 17 00:00:00 2001 From: sjurgw Date: Tue, 24 May 2022 14:54:24 +0200 Subject: [PATCH 10/10] Update: Removed stringstream to decrease static sizes --- .../esp_modem/src/esp_modem_command_library.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 7b3a0dbaa..39a3b6176 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -18,7 +18,6 @@ #include "cxx_include/esp_modem_dte.hpp" #include "cxx_include/esp_modem_dce_module.hpp" #include "cxx_include/esp_modem_command_library.hpp" -#include namespace esp_modem::dce_commands { @@ -495,15 +494,19 @@ command_result set_network_bands(CommandableIf *t, const std::string& mode, cons command_result set_network_bands_sim76xx(CommandableIf *t, const std::string& mode, const int* bands, int size) { ESP_LOGV(TAG, "%s", __func__ ); + static const char *hexDigits = "0123456789ABCDEF"; uint64_t band_bits = 0; + int hex_len = 16; + std::string band_string(hex_len, '0'); for (int i = 0; i0; i--){ + band_string[i-1] = hexDigits[(band_bits >> ((hex_len-i)*4)) & 0xF]; + } + return generic_command_common(t, "AT+CNBP=" + mode + ",0x" + band_string + "\r"); } command_result get_network_system_mode(CommandableIf *t, int &mode)