mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-11-11 21:10:04 +01:00
fix(modem): Use generated AT command definitions for IDE navigation
BREAKING CHANGE: inc headers for AT command definitions are no longer used directly, but pregenerated into *.h(pp)
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cxx_include/esp_modem_dte.hpp"
|
||||
#include "cxx_include/esp_modem_dce_module.hpp"
|
||||
#include "cxx_include/esp_modem_types.hpp"
|
||||
|
||||
// --- ESP-MODEM command module starts here ---
|
||||
namespace esp_modem {
|
||||
namespace dce_commands {
|
||||
|
||||
/**
|
||||
* @defgroup ESP_MODEM_DCE_COMMAND ESP_MODEM DCE command library
|
||||
* @brief Library of the most useful DCE commands
|
||||
*/
|
||||
/** @addtogroup ESP_MODEM_DCE_COMMAND
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Generic AT command to be send with pass and fail phrases
|
||||
*
|
||||
* @param t Commandable object (anything that can accept commands)
|
||||
* @param command Command to be sent do the commandable object
|
||||
* @param pass_phrase String to be present in the reply to pass this command
|
||||
* @param fail_phrase String to be present in the reply to fail this command
|
||||
* @param timeout_ms Timeout in ms
|
||||
*/
|
||||
command_result generic_command(CommandableIf *t, const std::string &command,
|
||||
const std::string &pass_phrase,
|
||||
const std::string &fail_phrase, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Declaration of all commands is generated from esp_modem_command_declare.inc
|
||||
*/
|
||||
#include "esp_modem_command_declare_helper.inc"
|
||||
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, ...) \
|
||||
return_type name(CommandableIf *t ESP_MODEM_COMMAND_PARAMS_AFTER(__VA_ARGS__));
|
||||
|
||||
#include "esp_modem_command_declare.inc"
|
||||
|
||||
#undef ESP_MODEM_DECLARE_DCE_COMMAND
|
||||
|
||||
/**
|
||||
* @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_alt(CommandableIf *t);
|
||||
command_result set_pdp_context(CommandableIf *t, PdpContext &pdp, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // dce_commands
|
||||
} // esp_modem
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// --- ESP-MODEM command module starts here ---
|
||||
namespace esp_modem {
|
||||
|
||||
/**
|
||||
* @defgroup ESP_MODEM_DCE
|
||||
* @brief Definition of DCE abstraction
|
||||
*/
|
||||
|
||||
/** @addtogroup ESP_MODEM_DCE
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Common abstraction of the modem DCE, specialized by the GenericModule which is a parent class for the supported
|
||||
* devices and most common modems, as well.
|
||||
*/
|
||||
class DCE : public DCE_T<GenericModule> {
|
||||
public:
|
||||
|
||||
command_result get_operator_name(std::string &name)
|
||||
{
|
||||
return device->get_operator_name(name);
|
||||
}
|
||||
|
||||
using DCE_T<GenericModule>::DCE_T;
|
||||
#include "esp_modem_command_declare_helper.inc"
|
||||
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, ...) \
|
||||
return_type name(ESP_MODEM_COMMAND_PARAMS(__VA_ARGS__)) \
|
||||
{ \
|
||||
return device->name(ESP_MODEM_COMMAND_FORWARD(__VA_ARGS__)); \
|
||||
}
|
||||
#include "esp_modem_command_declare.inc"
|
||||
|
||||
#undef ESP_MODEM_DECLARE_DCE_COMMAND
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // esp_modem
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
//#include "generate/esp_modem_command_declare.inc"
|
||||
#include "cxx_include/esp_modem_command_library.hpp"
|
||||
#include "cxx_include/esp_modem_types.hpp"
|
||||
#include "esp_modem_dce_config.h"
|
||||
|
||||
|
||||
// --- ESP-MODEM command module starts here ---
|
||||
namespace esp_modem {
|
||||
|
||||
/**
|
||||
* @defgroup ESP_MODEM_MODULE
|
||||
* @brief Definition of modules representing specific modem devices
|
||||
*/
|
||||
|
||||
/** @addtogroup ESP_MODEM_MODULE
|
||||
* @{
|
||||
*/
|
||||
|
||||
enum class command_result;
|
||||
class DTE;
|
||||
struct PdpContext;
|
||||
|
||||
/**
|
||||
* @brief This is a basic building block for custom modules as well as for the supported modules in the esp-modem component
|
||||
* It derives from the ModuleIf.
|
||||
*/
|
||||
class GenericModule: public ModuleIf {
|
||||
public:
|
||||
/**
|
||||
* @brief We can construct a generic device with an existent DTE and it's configuration
|
||||
* The configuration could be either the dce-config struct or just a pdp context
|
||||
*/
|
||||
explicit GenericModule(std::shared_ptr<DTE> dte, std::unique_ptr<PdpContext> pdp):
|
||||
dte(std::move(dte)), pdp(std::move(pdp)) {}
|
||||
explicit GenericModule(std::shared_ptr<DTE> dte, const esp_modem_dce_config *config);
|
||||
|
||||
/**
|
||||
* @brief This is a mandatory method for ModuleIf class, which sets up the device
|
||||
* to be able to connect to the network. This typically consists of setting basic
|
||||
* communication parameters and setting the PDP (defining logical access point
|
||||
* to cellular network)
|
||||
*/
|
||||
bool setup_data_mode() override
|
||||
{
|
||||
if (set_echo(false) != command_result::OK) {
|
||||
return false;
|
||||
}
|
||||
if (set_pdp_context(*pdp) != command_result::OK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This is a mandatory method of ModuleIf class, which defines
|
||||
* basic commands for switching between DATA, COMMAND and CMUX modes
|
||||
*/
|
||||
bool set_mode(modem_mode mode) override
|
||||
{
|
||||
if (mode == modem_mode::DATA_MODE) {
|
||||
if (set_data_mode() != command_result::OK) {
|
||||
return resume_data_mode() == command_result::OK;
|
||||
}
|
||||
return true;
|
||||
} else if (mode == modem_mode::COMMAND_MODE) {
|
||||
Task::Delay(1000); // Mandatory 1s pause before
|
||||
int retry = 0;
|
||||
while (retry++ < 3) {
|
||||
if (set_command_mode() == command_result::OK) {
|
||||
return true;
|
||||
}
|
||||
// send a newline to delimit the escape from the upcoming sync command
|
||||
uint8_t delim = '\n';
|
||||
dte->write(&delim, 1);
|
||||
if (sync() == command_result::OK) {
|
||||
return true;
|
||||
}
|
||||
Task::Delay(1000); // Mandatory 1s pause before escape
|
||||
}
|
||||
return false;
|
||||
} else if (mode == modem_mode::CMUX_MODE) {
|
||||
return set_cmux() == command_result::OK;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Additional method providing runtime configuration of PDP context
|
||||
*/
|
||||
void configure_pdp_context(std::unique_ptr<PdpContext> new_pdp)
|
||||
{
|
||||
pdp = std::move(new_pdp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Simplified version of operator name (without the ACT, which is included in the command library)
|
||||
*/
|
||||
command_result get_operator_name(std::string &name)
|
||||
{
|
||||
int dummy_act;
|
||||
return get_operator_name(name, dummy_act);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Common DCE commands generated from the API AT list
|
||||
*/
|
||||
#include "esp_modem_command_declare_helper.inc"
|
||||
|
||||
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, ...) \
|
||||
virtual return_type name(ESP_MODEM_COMMAND_PARAMS(__VA_ARGS__));
|
||||
|
||||
// DECLARE_ALL_COMMAND_APIS(virtual return_type name(...); )
|
||||
|
||||
#include "esp_modem_command_declare.inc"
|
||||
|
||||
|
||||
#undef ESP_MODEM_DECLARE_DCE_COMMAND
|
||||
|
||||
|
||||
protected:
|
||||
std::shared_ptr<DTE> dte; /*!< Generic device needs the DTE as a channel talk to the module using AT commands */
|
||||
std::unique_ptr<PdpContext> pdp; /*!< It also needs a PDP data, const information used for setting up cellular network */
|
||||
};
|
||||
|
||||
// Definitions of other supported modules with some specific commands overwritten
|
||||
|
||||
/**
|
||||
* @brief Specific definition of the SIM7600 module
|
||||
*/
|
||||
class SIM7600: public GenericModule {
|
||||
using GenericModule::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;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Specific definition of the SIM7070 module
|
||||
*/
|
||||
class SIM7070: public GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
public:
|
||||
command_result power_down() override;
|
||||
command_result set_data_mode() 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
|
||||
*/
|
||||
class SIM800: public GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
public:
|
||||
command_result power_down() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Specific definition of the BG96 module
|
||||
*/
|
||||
class BG96: public GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
public:
|
||||
command_result set_pdp_context(PdpContext &pdp) override;
|
||||
};
|
||||
|
||||
class SQNGM02S : public GenericModule {
|
||||
using GenericModule::GenericModule;
|
||||
|
||||
public:
|
||||
command_result connect(PdpContext &pdp);
|
||||
bool setup_data_mode() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace esp_modem
|
||||
Reference in New Issue
Block a user