esp-modem(DCE-Factory): Minor corrections per code review

This commit is contained in:
David Čermák
2021-06-01 15:52:39 +08:00
committed by David Cermak
parent 3332c27978
commit dc64f862c4
8 changed files with 131 additions and 83 deletions

View File

@ -19,13 +19,14 @@ All the functionality is provided by the DCE factory
.. doxygengroup:: ESP_MODEM_DCE_FACTORY .. doxygengroup:: ESP_MODEM_DCE_FACTORY
:members: :members:
.. _create_custom_module:
Create custom module Create custom module
-------------------- --------------------
Creating a custom module is necessary if the application needs to use a specific device that is not supported Creating a custom module is necessary if the application needs to use a specific device that is not supported
and their commands differ from any of the supported devices. In this case it is recommended to define a new class and their commands differ from any of the supported devices. In this case it is recommended to define a new class
representing this specific device and derive from the :cpp:class:`GenericModule`. In order to instantiate representing this specific device and derive from the :cpp:class:`esp_modem::GenericModule`. In order to instantiate
the appropriate DCE of this module, application could use :ref:`the DCE factory<dce_factory>`, and build the DCE with the appropriate DCE of this module, application could use :ref:`the DCE factory<dce_factory>`, and build the DCE with
the specific module, using :cpp:func:`esp_modem::dce_factory::Factory::build`. the specific module, using :cpp:func:`esp_modem::dce_factory::Factory::build`.

View File

@ -9,6 +9,13 @@ The esp-modem actually implements the DCE class, which in turn aggregates these
- :ref:`Netif<netif_impl>` to provide the network connectivity - :ref:`Netif<netif_impl>` to provide the network connectivity
- :ref:`Module<module_impl>` to define the specific command library - :ref:`Module<module_impl>` to define the specific command library
Developers would typically have to
* Add support for a new module
* Implement a generic (common for all modules) AT command
This is explained in the :ref:`Module<module_impl>` section, as :ref:`Adding new module or command<module_addition>`
------------ ------------
.. doxygengroup:: ESP_MODEM_DCE .. doxygengroup:: ESP_MODEM_DCE
@ -63,6 +70,36 @@ Module abstraction
.. doxygengroup:: ESP_MODEM_MODULE .. doxygengroup:: ESP_MODEM_MODULE
:members: :members:
.. _module_addition:
Adding new devices
^^^^^^^^^^^^^^^^^^
To support a new module, developers would have to implement a new class derived from :cpp:class:`esp_modem::GenericModule` the same way
as it is described in the :ref:`Advanced user manual<create_custom_module>`. The only difference is that the new class (and factory extension)
would be available in the esp_modem code base.
Implement a new generic command
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Adding a generic command, i.e. the command that is shared for all modules and is included in the :cpp:class:`esp_modem::GenericModule`,
has to be declared first in the ``include/generate/esp_modem_command_declare.inc`` file, which is the single source
of supported command definitions, that is used in:
* public C API
* public CPP API
* generated documentation
* implementation of the command
Therefore, a care must be taken, to correctly specify all parameters and types, especially:
* Keep number of parameters low (<= 6, used in preprocessor's forwarding to the command library)
* Use macros to specify parameter types (as they are used both from C and C++ with different underlying types)
* Parameter names are used only for clarity and documentation, they get expanded to numbered arguments.
Please use the following pattern: ``INT_IN(p1, baud)``, meaning that the parameter is an input integer,
human readable argument name is ``baud``, it's the first argument, so expands to ``p1`` (second argument would be ``p2``, etc)
Command library Command library
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^

View File

@ -85,7 +85,7 @@ protected:
/** /**
* @brief Common abstraction of the modem DCE, specialized by the GenericModule which is a parent class for the supported * @brief Common abstraction of the modem DCE, specialized by the GenericModule which is a parent class for the supported
* defices and most common modems, as well. * devices and most common modems, as well.
*/ */
class DCE : public DCE_T<GenericModule> { class DCE : public DCE_T<GenericModule> {
public: public:

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "esp_log.h"
/** /**
* @defgroup ESP_MODEM_DCE_FACTORY * @defgroup ESP_MODEM_DCE_FACTORY
@ -30,62 +31,67 @@ using config = ::esp_modem_dce_config;
/** /**
* @brief Helper class for creating a uder define pointer in a specific way, either as a plain pointer, shared_ptr or unique_ptr * @brief Helper class for creating a user define pointer in a specific way, either as a plain pointer, shared_ptr or unique_ptr
*/ */
class FactoryHelper { class FactoryHelper {
public: public:
static std::unique_ptr<PdpContext> create_pdp_context(std::string &apn); static std::unique_ptr<PdpContext> create_pdp_context(std::string &apn);
template <typename T, typename Ptr, typename ...Args> template <typename T, typename T_Ptr, typename ...Args>
static auto make(Args&&... args) -> typename std::enable_if<std::is_same<Ptr, T*>::value, T*>::type static auto make(Args&&... args) -> typename std::enable_if<std::is_same<T_Ptr, T*>::value, T*>::type
{ {
return new T(std::forward<Args>(args)...); return new T(std::forward<Args>(args)...);
} }
template <typename T, typename Ptr, typename ...Args> template <typename T, typename T_Ptr, typename ...Args>
static auto make(Args&&... args) -> typename std::enable_if<std::is_same<Ptr, std::shared_ptr<T>>::value, std::shared_ptr<T>>::type static auto make(Args&&... args) -> typename std::enable_if<std::is_same<T_Ptr, std::shared_ptr<T>>::value, std::shared_ptr<T>>::type
{ {
return std::make_shared<T>(std::forward<Args>(args)...); return std::make_shared<T>(std::forward<Args>(args)...);
} }
template <typename T, typename Ptr = std::unique_ptr<T>, typename ...Args> template <typename T, typename T_Ptr = std::unique_ptr<T>, typename ...Args>
static auto make(Args&&... args) -> typename std::enable_if<std::is_same<Ptr, std::unique_ptr<T>>::value, std::unique_ptr<T>>::type static auto make(Args&&... args) -> typename std::enable_if<std::is_same<T_Ptr, std::unique_ptr<T>>::value, std::unique_ptr<T>>::type
{ {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
} }
}; };
/** /**
* @brief Builder class for building a DCE_T<Module> in a specific way, either form a Module object or by default from the DTE and netif * @brief Builder class for building a DCE_T<Module> in a specific way, either from a Module object or by default from the DTE and netif
*
* @throws
* - esp_modem::esp_err_exception on invalid arguments
* - std::bad_alloc if failed to allocate
*/ */
template<typename Module> template<typename T_Module>
class Builder { class Builder {
static_assert(std::is_base_of<ModuleIf, Module>::value, "Builder must be used only for Module classes"); static_assert(std::is_base_of<ModuleIf, T_Module>::value, "Builder must be used only for Module classes");
public: public:
Builder(std::shared_ptr<DTE> x, esp_netif_t* esp_netif): dte(std::move(x)), device(nullptr), netif(esp_netif) Builder(std::shared_ptr<DTE> dte, esp_netif_t* esp_netif): dte(std::move(dte)), device(nullptr), netif(esp_netif)
{ {
throw_if_false(netif != nullptr, "Null netif"); throw_if_false(netif != nullptr, "Null netif");
} }
Builder(std::shared_ptr<DTE> dte, esp_netif_t* esp_netif, std::shared_ptr<Module> dev): dte(std::move(dte)), device(std::move(dev)), netif(esp_netif) Builder(std::shared_ptr<DTE> dte, esp_netif_t* esp_netif, std::shared_ptr<T_Module> dev): dte(std::move(dte)), device(std::move(dev)), netif(esp_netif)
{ {
throw_if_false(netif != nullptr, "Null netif"); throw_if_false(netif != nullptr, "Null netif");
} }
~Builder() ~Builder()
{ {
throw_if_false(device == nullptr, "module was captured or created but never used"); if (device == nullptr) {
ESP_LOGE("dce_factory::~Builder", "module was captured or created but never used");
}
} }
template<typename Ptr> template<typename T_Ptr>
auto create_module(const esp_modem_dce_config *config) -> Ptr auto create_module(const esp_modem_dce_config *config) -> T_Ptr
{ {
return FactoryHelper::make<Module, Ptr>(dte, config); return FactoryHelper::make<T_Module, T_Ptr>(dte, config);
} }
template<typename DceT, typename Ptr> template<typename T_Dce, typename T_Ptr>
auto create(const esp_modem_dce_config *config) -> Ptr auto create(const esp_modem_dce_config *config) -> T_Ptr
{ {
if (dte == nullptr) if (dte == nullptr)
return nullptr; return nullptr;
@ -94,19 +100,19 @@ public:
if (device == nullptr) if (device == nullptr)
return nullptr; return nullptr;
} }
return FactoryHelper::make<DceT, Ptr>(std::move(dte), std::move(device), netif); return FactoryHelper::make<T_Dce, T_Ptr>(std::move(dte), std::move(device), netif);
} }
private: private:
std::shared_ptr<DTE> dte; std::shared_ptr<DTE> dte;
std::shared_ptr<Module> device; std::shared_ptr<T_Module> device;
esp_netif_t *netif; esp_netif_t *netif;
}; };
/** /**
* @brief Specific modem choice when creating by the Factory * @brief Specific modem choice when creating by the Factory
*/ */
enum class Modem { enum class ModemType {
GenericModule, /*!< Default generic module with the most common commands */ GenericModule, /*!< Default generic module with the most common commands */
SIM7600, /*!< Derived from the GenericModule, specifics applied to SIM7600 model */ SIM7600, /*!< Derived from the GenericModule, specifics applied to SIM7600 model */
BG96, /*!< Derived from the GenericModule, specifics applied to BG69 model */ BG96, /*!< Derived from the GenericModule, specifics applied to BG69 model */
@ -119,7 +125,7 @@ enum class Modem {
*/ */
class Factory { class Factory {
public: public:
explicit Factory(Modem modem): m(modem) {} explicit Factory(ModemType modem): m(modem) {}
/** /**
* @brief Create a default unique_ptr DCE in a specific way (from the module) * @brief Create a default unique_ptr DCE in a specific way (from the module)
@ -129,10 +135,10 @@ public:
* @param args typically a DTE object and a netif handle for PPP network * @param args typically a DTE object and a netif handle for PPP network
* @return unique_ptr DCE of the created DCE on success * @return unique_ptr DCE of the created DCE on success
*/ */
template <typename Module, typename ...Args> template <typename T_Module, typename ...Args>
static std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args) static std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args)
{ {
return build_generic_DCE<Module, DCE, std::unique_ptr<DCE>>(cfg, std::forward<Args>(args)...); return build_generic_DCE<T_Module, DCE, std::unique_ptr<DCE>>(cfg, std::forward<Args>(args)...);
} }
/** /**
@ -143,17 +149,17 @@ public:
* @param args typically a DTE object and a netif handle for PPP network * @param args typically a DTE object and a netif handle for PPP network
* @return DCE pointer the created DCE on success * @return DCE pointer the created DCE on success
*/ */
template <typename Module, typename ...Args> template <typename T_Module, typename ...Args>
static DCE* build(const config *cfg, Args&&... args) static DCE* build(const config *cfg, Args&&... args)
{ {
return build_generic_DCE<Module, DCE>(cfg, std::forward<Args>(args)...); return build_generic_DCE<T_Module, DCE>(cfg, std::forward<Args>(args)...);
} }
template <typename Module, typename ...Args> template <typename T_Module, typename ...Args>
static std::shared_ptr<Module> build_shared_module(const config *cfg, Args&&... args) static std::shared_ptr<T_Module> build_shared_module(const config *cfg, Args&&... args)
{ {
return build_module_T<Module>(cfg, std::forward<Args>(args)...); return build_module_T<T_Module>(cfg, std::forward<Args>(args)...);
} }
@ -161,13 +167,13 @@ public:
std::shared_ptr<GenericModule> build_shared_module(const config *cfg, Args&&... args) std::shared_ptr<GenericModule> build_shared_module(const config *cfg, Args&&... args)
{ {
switch (m) { switch (m) {
case Modem::SIM800: case ModemType::SIM800:
return build_shared_module<SIM800>(cfg, std::forward<Args>(args)...); return build_shared_module<SIM800>(cfg, std::forward<Args>(args)...);
case Modem::SIM7600: case ModemType::SIM7600:
return build_shared_module<SIM7600>(cfg, std::forward<Args>(args)...); return build_shared_module<SIM7600>(cfg, std::forward<Args>(args)...);
case Modem::BG96: case ModemType::BG96:
return build_shared_module<BG96>(cfg, std::forward<Args>(args)...); return build_shared_module<BG96>(cfg, std::forward<Args>(args)...);
case Modem::GenericModule: case ModemType::GenericModule:
return build_shared_module<GenericModule>(cfg, std::forward<Args>(args)...); return build_shared_module<GenericModule>(cfg, std::forward<Args>(args)...);
default: default:
break; break;
@ -186,13 +192,13 @@ public:
std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args) std::unique_ptr<DCE> build_unique(const config *cfg, Args&&... args)
{ {
switch (m) { switch (m) {
case Modem::SIM800: case ModemType::SIM800:
return build_unique<SIM800>(cfg, std::forward<Args>(args)...); return build_unique<SIM800>(cfg, std::forward<Args>(args)...);
case Modem::SIM7600: case ModemType::SIM7600:
return build_unique<SIM7600>(cfg, std::forward<Args>(args)...); return build_unique<SIM7600>(cfg, std::forward<Args>(args)...);
case Modem::BG96: case ModemType::BG96:
return build_unique<BG96>(cfg, std::forward<Args>(args)...); return build_unique<BG96>(cfg, std::forward<Args>(args)...);
case Modem::GenericModule: case ModemType::GenericModule:
return build_unique<GenericModule>(cfg, std::forward<Args>(args)...); return build_unique<GenericModule>(cfg, std::forward<Args>(args)...);
default: default:
break; break;
@ -204,13 +210,13 @@ public:
DCE* build(const config *cfg, Args&&... args) DCE* build(const config *cfg, Args&&... args)
{ {
switch (m) { switch (m) {
case Modem::SIM800: case ModemType::SIM800:
return build<SIM800>(cfg, std::forward<Args>(args)...); return build<SIM800>(cfg, std::forward<Args>(args)...);
case Modem::SIM7600: case ModemType::SIM7600:
return build<SIM7600>(cfg, std::forward<Args>(args)...); return build<SIM7600>(cfg, std::forward<Args>(args)...);
case Modem::BG96: case ModemType::BG96:
return build<BG96>(cfg, std::forward<Args>(args)...); return build<BG96>(cfg, std::forward<Args>(args)...);
case Modem::GenericModule: case ModemType::GenericModule:
return build<GenericModule>(cfg, std::forward<Args>(args)...); return build<GenericModule>(cfg, std::forward<Args>(args)...);
default: default:
break; break;
@ -219,22 +225,22 @@ public:
} }
private: private:
Modem m; ModemType m;
protected: protected:
template <typename Module, typename Ptr = std::shared_ptr<Module>, typename ...Args> template <typename T_Module, typename Ptr = std::shared_ptr<T_Module>, typename ...Args>
static Ptr build_module_T(const config *cfg, Args&&... args) static Ptr build_module_T(const config *cfg, Args&&... args)
{ {
Builder<Module> b(std::forward<Args>(args)...); Builder<T_Module> b(std::forward<Args>(args)...);
return b.template create_module<Ptr>(cfg); return b.template create_module<Ptr>(cfg);
} }
template <typename Module, typename Dce = DCE_T<Module>, typename DcePtr = Dce*, typename ...Args> template <typename T_Module, typename T_Dce = DCE_T<T_Module>, typename T_DcePtr = T_Dce*, typename ...Args>
static DcePtr build_generic_DCE(const config *cfg, Args&&... args) static auto build_generic_DCE(const config *cfg, Args&&... args) -> T_DcePtr
{ {
Builder<Module> b(std::forward<Args>(args)...); Builder<T_Module> b(std::forward<Args>(args)...);
return b.template create<Dce, DcePtr>(cfg); return b.template create<T_Dce, T_DcePtr>(cfg);
} }
}; };

View File

@ -29,14 +29,14 @@
#define BOOL_OUT(param, name) bool& _ARG(param, name) #define BOOL_OUT(param, name) bool& _ARG(param, name)
#define INT_OUT(param, name) int& _ARG(param, name) #define INT_OUT(param, name) int& _ARG(param, name)
#define STRUCT_OUT(struct_name, x) struct_name& x #define STRUCT_OUT(struct_name, p1) struct_name& p1
#else #else
#define STRING_IN(param, name) const char* _ARG(param, name) #define STRING_IN(param, name) const char* _ARG(param, name)
#define STRING_OUT(param, name) char* _ARG(param, name) #define STRING_OUT(param, name) char* _ARG(param, name)
#define BOOL_IN(param, name) const bool _ARG(param, name) #define BOOL_IN(param, name) const bool _ARG(param, name)
#define BOOL_OUT(param, name) bool* _ARG(param, name) #define BOOL_OUT(param, name) bool* _ARG(param, name)
#define INT_OUT(param, name) int* _ARG(param, name) #define INT_OUT(param, name) int* _ARG(param, name)
#define STRUCT_OUT(struct_name, x) struct struct_name* x #define STRUCT_OUT(struct_name, p1) struct struct_name* p1
#endif #endif
#define DECLARE_ALL_COMMAND_APIS(...) \ #define DECLARE_ALL_COMMAND_APIS(...) \
@ -50,7 +50,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(sync, command_result, 0) \
* @param[out] name module name * @param[out] name module name
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(get_operator_name, command_result, 1, STRING_OUT(x, name)) \ ESP_MODEM_DECLARE_DCE_COMMAND(get_operator_name, command_result, 1, STRING_OUT(p1, name)) \
\ \
/** /**
* @brief Stores current user profile * @brief Stores current user profile
@ -63,28 +63,28 @@ ESP_MODEM_DECLARE_DCE_COMMAND(store_profile, command_result, 0) \
* @param[in] pin Pin * @param[in] pin Pin
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/\ */\
ESP_MODEM_DECLARE_DCE_COMMAND(set_pin, command_result, 1, STRING_IN(x, pin)) \ ESP_MODEM_DECLARE_DCE_COMMAND(set_pin, command_result, 1, STRING_IN(p1, pin)) \
\ \
/** /**
* @brief Checks if the SIM needs a PIN * @brief Checks if the SIM needs a PIN
* @param[out] pin_ok true if the SIM card doesn't need a PIN to unlock * @param[out] pin_ok true if the SIM card doesn't need a PIN to unlock
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(read_pin, command_result, 1, BOOL_OUT(x, pin_ok)) \ ESP_MODEM_DECLARE_DCE_COMMAND(read_pin, command_result, 1, BOOL_OUT(p1, pin_ok)) \
\ \
/** /**
* @brief Sets echo mode * @brief Sets echo mode
* @param[in] echo_on true if echo mode on (repeats the commands) * @param[in] echo_on true if echo mode on (repeats the commands)
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(set_echo, command_result, 1, BOOL_IN(x, echo_on)) \ ESP_MODEM_DECLARE_DCE_COMMAND(set_echo, command_result, 1, BOOL_IN(p1, echo_on)) \
\ \
/** /**
* @brief Sets the Txt or Pdu mode for SMS (only txt is supported) * @brief Sets the Txt or Pdu mode for SMS (only txt is supported)
* @param[in] txt true if txt mode * @param[in] txt true if txt mode
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(sms_txt_mode, command_result, 1, BOOL_IN(x, txt)) \ ESP_MODEM_DECLARE_DCE_COMMAND(sms_txt_mode, command_result, 1, BOOL_IN(p1, txt)) \
\ \
/** /**
* @brief Sets the default (GSM) charater set * @brief Sets the default (GSM) charater set
@ -98,7 +98,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(sms_character_set, command_result, 0) \
* @param[in] message Text message to be sent * @param[in] message Text message to be sent
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(send_sms, command_result, 2, STRING_IN(x, number), STRING_IN(y, message)) \ ESP_MODEM_DECLARE_DCE_COMMAND(send_sms, command_result, 2, STRING_IN(p1, number), STRING_IN(p2, message)) \
\ \
/** /**
* @brief Resumes data mode (Switches back to th data mode, which was temporarily suspended) * @brief Resumes data mode (Switches back to th data mode, which was temporarily suspended)
@ -108,10 +108,10 @@ ESP_MODEM_DECLARE_DCE_COMMAND(resume_data_mode, command_result, 0) \
\ \
/** /**
* @brief Sets php context * @brief Sets php context
* @param[in] x PdP context struct to setup modem cellular connection * @param[in] p1 PdP context struct to setup modem cellular connection
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(set_pdp_context, command_result, 1, STRUCT_OUT(PdpContext, x)) \ ESP_MODEM_DECLARE_DCE_COMMAND(set_pdp_context, command_result, 1, STRUCT_OUT(PdpContext, p1)) \
\ \
/** /**
* @brief Switches to the command mode * @brief Switches to the command mode
@ -130,21 +130,21 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_cmux, command_result, 0) \
* @param[out] imsi Module's IMSI number * @param[out] imsi Module's IMSI number
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(get_imsi, command_result, 1, STRING_OUT(x, imsi)) \ ESP_MODEM_DECLARE_DCE_COMMAND(get_imsi, command_result, 1, STRING_OUT(p1, imsi)) \
\ \
/** /**
* @brief Reads the IMEI number * @brief Reads the IMEI number
* @param[out] imei Module's IMEI number * @param[out] imei Module's IMEI number
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(get_imei, command_result, 1, STRING_OUT(x, imei)) \ ESP_MODEM_DECLARE_DCE_COMMAND(get_imei, command_result, 1, STRING_OUT(p1, imei)) \
\ \
/** /**
* @brief Reads the module name * @brief Reads the module name
* @param[out] name module name * @param[out] name module name
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(get_module_name, command_result, 1, STRING_OUT(x, name)) \ ESP_MODEM_DECLARE_DCE_COMMAND(get_module_name, command_result, 1, STRING_OUT(p1, name)) \
\ \
/** /**
* @brief Sets the modem to data mode * @brief Sets the modem to data mode
@ -158,7 +158,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_data_mode, command_result, 0) \
* @param[out] ber channel bit error rate * @param[out] ber channel bit error rate
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(get_signal_quality, command_result, 2, INT_OUT(x, rssi), INT_OUT(y, ber)) \ ESP_MODEM_DECLARE_DCE_COMMAND(get_signal_quality, command_result, 2, INT_OUT(p1, rssi), INT_OUT(p2, ber)) \
\ \
/** /**
* @brief Sets HW control flow * @brief Sets HW control flow
@ -166,7 +166,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_signal_quality, command_result, 2, INT_OUT(x,
* @param[in] dte_flow 0=none, 2=CTS hw flow control of DTE * @param[in] dte_flow 0=none, 2=CTS hw flow control of DTE
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(set_flow_control, command_result, 2, INT_IN(x, dce_flow), INT_IN(y, dte_flow)) \ ESP_MODEM_DECLARE_DCE_COMMAND(set_flow_control, command_result, 2, INT_IN(p1, dce_flow), INT_IN(p2, dte_flow)) \
\ \
/** /**
* @brief Hangs up current data call * @brief Hangs up current data call
@ -181,7 +181,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(hang_up, command_result, 0) \
* @param[out] bcl 1-100% battery capacity, -1-Not available * @param[out] bcl 1-100% battery capacity, -1-Not available
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(get_battery_status, command_result, 3, INT_OUT(x, voltage), INT_OUT(y, bcs), INT_OUT(z, bcl)) \ ESP_MODEM_DECLARE_DCE_COMMAND(get_battery_status, command_result, 3, INT_OUT(p1, voltage), INT_OUT(p2, bcs), INT_OUT(p3, bcl)) \
\ \
/** /**
* @brief Power down the module * @brief Power down the module
@ -200,7 +200,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(reset, command_result, 0)\
* @param[in] baud Desired baud rate of the DTE * @param[in] baud Desired baud rate of the DTE
* @return OK, FAIL or TIMEOUT * @return OK, FAIL or TIMEOUT
*/ \ */ \
ESP_MODEM_DECLARE_DCE_COMMAND(set_baud, command_result, 1, INT_IN(x, baud)) ESP_MODEM_DECLARE_DCE_COMMAND(set_baud, command_result, 1, INT_IN(p1, baud))
#ifdef GENERATE_DOCS #ifdef GENERATE_DOCS

View File

@ -46,7 +46,7 @@ std::shared_ptr<DTE> create_vfs_dte(const dte_config *config) {
static inline std::unique_ptr<DCE> static inline std::unique_ptr<DCE>
create_modem_dce(dce_factory::Modem m, const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) { create_modem_dce(dce_factory::ModemType m, const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
dce_factory::Factory f(m); dce_factory::Factory f(m);
TRY_CATCH_RET_NULL( TRY_CATCH_RET_NULL(
return f.build_unique(config, std::move(dte), netif); return f.build_unique(config, std::move(dte), netif);
@ -54,19 +54,19 @@ create_modem_dce(dce_factory::Modem m, const dce_config *config, std::shared_ptr
} }
std::unique_ptr<DCE> create_SIM7600_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) { std::unique_ptr<DCE> create_SIM7600_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::Modem::SIM7600, config, std::move(dte), netif); return create_modem_dce(dce_factory::ModemType::SIM7600, config, std::move(dte), netif);
} }
std::unique_ptr<DCE> create_SIM800_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) { std::unique_ptr<DCE> create_SIM800_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::Modem::SIM800, config, std::move(dte), netif); return create_modem_dce(dce_factory::ModemType::SIM800, config, std::move(dte), netif);
} }
std::unique_ptr<DCE> create_BG96_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) { std::unique_ptr<DCE> create_BG96_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::Modem::BG96, config, std::move(dte), netif); return create_modem_dce(dce_factory::ModemType::BG96, config, std::move(dte), netif);
} }
std::unique_ptr<DCE> create_generic_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) { std::unique_ptr<DCE> create_generic_dce(const dce_config *config, std::shared_ptr<DTE> dte, esp_netif_t *netif) {
return create_modem_dce(dce_factory::Modem::GenericModule, config, std::move(dte), netif); return create_modem_dce(dce_factory::ModemType::GenericModule, config, std::move(dte), netif);
} }
} // namespace esp_modem } // namespace esp_modem

View File

@ -30,7 +30,7 @@ using namespace esp_modem;
struct esp_modem_dce_wrap // need to mimic the polymorphic dispatch as CPP uses templated dispatch struct esp_modem_dce_wrap // need to mimic the polymorphic dispatch as CPP uses templated dispatch
{ {
enum class modem_wrap_dte_type { UART, } dte_type; enum class modem_wrap_dte_type { UART, } dte_type;
dce_factory::Modem modem_type; dce_factory::ModemType modem_type;
DCE* dce; DCE* dce;
}; };
@ -47,18 +47,18 @@ static inline esp_err_t command_response_to_esp_err(command_result res)
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
static inline dce_factory::Modem convert_modem_enum(esp_modem_dce_device_t module) static inline dce_factory::ModemType convert_modem_enum(esp_modem_dce_device_t module)
{ {
switch (module) { switch (module) {
case ESP_MODEM_DCE_SIM7600: case ESP_MODEM_DCE_SIM7600:
return esp_modem::dce_factory::Modem::SIM7600; return esp_modem::dce_factory::ModemType::SIM7600;
case ESP_MODEM_DCE_BG96: case ESP_MODEM_DCE_BG96:
return esp_modem::dce_factory::Modem::BG96; return esp_modem::dce_factory::ModemType::BG96;
case ESP_MODEM_DCE_SIM800: case ESP_MODEM_DCE_SIM800:
return esp_modem::dce_factory::Modem::SIM800; return esp_modem::dce_factory::ModemType::SIM800;
default: default:
case ESP_MODEM_DCE_GENETIC: case ESP_MODEM_DCE_GENETIC:
return esp_modem::dce_factory::Modem::GenericModule; return esp_modem::dce_factory::ModemType::GenericModule;
} }
} }

View File

@ -27,9 +27,13 @@ GenericModule::GenericModule(std::shared_ptr<DTE> dte, const dce_config *config)
// Helper macros to handle multiple arguments of declared API // Helper macros to handle multiple arguments of declared API
#define ARGS0 #define ARGS0
#define ARGS1 , x #define ARGS1 , p1
#define ARGS2 , x , y #define ARGS2 , p1 , p2
#define ARGS3 , x , y , z #define ARGS3 , p1 , p2 , p3
#define ARGS4 , p1 , p2 , p3, p4
#define ARGS5 , p1 , p2 , p3, p4, p5
#define ARGS6 , p1 , p2 , p3, p4, p5, p6
#define _ARGS(x) ARGS ## x #define _ARGS(x) ARGS ## x
#define ARGS(x) _ARGS(x) #define ARGS(x) _ARGS(x)