2021-03-29 19:34:45 +02:00
|
|
|
/*
|
2025-03-19 15:46:04 +01:00
|
|
|
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
2022-10-11 16:31:57 +02:00
|
|
|
*
|
2021-03-29 19:34:45 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "cxx_include/esp_modem_api.hpp"
|
2021-03-07 19:43:45 +01:00
|
|
|
#include "cxx_include/esp_modem_dce_module.hpp"
|
2025-03-19 15:46:04 +01:00
|
|
|
#include "cxx17_include/esp_modem_command_library_17.hpp"
|
2024-11-01 17:32:02 +01:00
|
|
|
#include "cxx_include/esp_modem_dte.hpp"
|
2021-03-07 19:43:45 +01:00
|
|
|
|
2024-11-01 17:32:02 +01:00
|
|
|
// --- ESP-MODEM command module starts here ---
|
2021-03-29 19:34:45 +02:00
|
|
|
namespace esp_modem {
|
|
|
|
|
|
|
|
|
|
GenericModule::GenericModule(std::shared_ptr<DTE> dte, const dce_config *config) :
|
2021-06-01 10:21:51 +02:00
|
|
|
dte(std::move(dte)), pdp(std::make_unique<PdpContext>(config->apn)) {}
|
2021-03-28 13:38:20 +02:00
|
|
|
|
|
|
|
|
|
2024-11-01 17:32:02 +01:00
|
|
|
#include "esp_modem_command_declare_helper.inc"
|
2021-06-01 15:52:39 +08:00
|
|
|
|
2024-11-01 17:32:02 +01:00
|
|
|
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, type, ...) \
|
|
|
|
|
type GenericModule::name(ESP_MODEM_COMMAND_PARAMS(__VA_ARGS__)) { \
|
|
|
|
|
return esp_modem::dce_commands::name(dte.get() ESP_MODEM_COMMAND_FORWARD_AFTER(__VA_ARGS__)); }
|
|
|
|
|
|
|
|
|
|
#include "esp_modem_command_declare.inc"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Usage examples:
|
|
|
|
|
// Zero arguments
|
|
|
|
|
|
|
|
|
|
// Helper to apply the correct macro to each parameter
|
2021-04-19 11:28:53 +02:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Repeat all declarations and forward to the AT commands defined in esp_modem::dce_commands:: namespace
|
|
|
|
|
//
|
2021-03-24 21:06:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef ESP_MODEM_DECLARE_DCE_COMMAND
|
|
|
|
|
|
2021-04-19 11:28:53 +02:00
|
|
|
//
|
|
|
|
|
// Handle specific commands for specific supported modems
|
|
|
|
|
//
|
2021-06-01 10:21:51 +02:00
|
|
|
command_result SIM7600::get_battery_status(int &voltage, int &bcs, int &bcl)
|
|
|
|
|
{
|
2021-04-19 11:28:53 +02:00
|
|
|
return dce_commands::get_battery_status_sim7xxx(dte.get(), voltage, bcs, bcl);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 16:23:22 +02:00
|
|
|
command_result SIM7600::set_network_bands(const std::string &mode, const int *bands, int size)
|
|
|
|
|
{
|
|
|
|
|
return dce_commands::set_network_bands_sim76xx(dte.get(), mode, bands, size);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-20 09:37:39 +02:00
|
|
|
command_result SIM7600::set_gnss_power_mode(int mode)
|
|
|
|
|
{
|
|
|
|
|
return dce_commands::set_gnss_power_mode_sim76xx(dte.get(), mode);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 16:23:22 +02:00
|
|
|
command_result SIM7600::power_down()
|
|
|
|
|
{
|
|
|
|
|
return dce_commands::power_down_sim76xx(dte.get());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 13:42:57 +02:00
|
|
|
command_result SIM7070::power_down()
|
|
|
|
|
{
|
2022-04-13 15:36:15 +02:00
|
|
|
return dce_commands::power_down_sim70xx(dte.get());
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 11:13:17 +01:00
|
|
|
command_result SIM7070::set_data_mode()
|
|
|
|
|
{
|
|
|
|
|
return dce_commands::set_data_mode_alt(dte.get());
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-13 15:36:15 +02:00
|
|
|
command_result SIM7000::power_down()
|
|
|
|
|
{
|
|
|
|
|
return dce_commands::power_down_sim70xx(dte.get());
|
2021-04-19 11:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 10:21:51 +02:00
|
|
|
command_result SIM800::power_down()
|
|
|
|
|
{
|
2021-04-19 11:28:53 +02:00
|
|
|
return dce_commands::power_down_sim8xx(dte.get());
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-08 09:11:00 +01:00
|
|
|
command_result BG96::set_pdp_context(esp_modem::PdpContext &pdp)
|
|
|
|
|
{
|
|
|
|
|
return dce_commands::set_pdp_context(dte.get(), pdp, 300);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 15:46:04 +01:00
|
|
|
bool SQNGM02S::setup_data_mode()
|
2025-03-19 14:45:32 +01:00
|
|
|
{
|
2025-03-19 15:46:04 +01:00
|
|
|
return true;
|
2025-03-19 14:45:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command_result SQNGM02S::connect(PdpContext &pdp)
|
|
|
|
|
{
|
|
|
|
|
command_result res;
|
2025-03-19 15:46:04 +01:00
|
|
|
configure_pdp_context(std::make_unique<PdpContext>(pdp));
|
|
|
|
|
set_pdp_context(*this->pdp);
|
2025-03-19 14:45:32 +01:00
|
|
|
res = config_network_registration_urc(1);
|
2025-03-19 15:46:04 +01:00
|
|
|
if (res != command_result::OK) {
|
2025-03-19 14:45:32 +01:00
|
|
|
return res;
|
2025-03-19 15:46:04 +01:00
|
|
|
}
|
2025-03-19 14:45:32 +01:00
|
|
|
|
|
|
|
|
res = set_radio_state(1);
|
2025-03-19 15:46:04 +01:00
|
|
|
if (res != command_result::OK) {
|
2025-03-19 14:45:32 +01:00
|
|
|
return res;
|
2025-03-19 15:46:04 +01:00
|
|
|
}
|
2025-03-19 14:45:32 +01:00
|
|
|
|
|
|
|
|
//wait for +CEREG: 5 or +CEREG: 1.
|
2025-03-19 15:46:04 +01:00
|
|
|
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);
|
2025-03-19 14:45:32 +01:00
|
|
|
|
2025-03-19 15:46:04 +01:00
|
|
|
if (res != command_result::OK) {
|
|
|
|
|
config_network_registration_urc(0);
|
2025-03-19 14:45:32 +01:00
|
|
|
return res;
|
2025-03-19 15:46:04 +01:00
|
|
|
}
|
2025-03-19 14:45:32 +01:00
|
|
|
|
|
|
|
|
res = config_network_registration_urc(0);
|
2025-03-19 15:46:04 +01:00
|
|
|
if (res != command_result::OK) {
|
2025-03-19 14:45:32 +01:00
|
|
|
return res;
|
2025-03-19 15:46:04 +01:00
|
|
|
}
|
2025-03-19 14:45:32 +01:00
|
|
|
|
|
|
|
|
return command_result::OK;
|
|
|
|
|
}
|
2021-03-29 19:34:45 +02:00
|
|
|
}
|