mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-29 10:17:30 +02:00
C API cleanup, add SMS support
This commit is contained in:
@ -109,9 +109,9 @@ private:
|
||||
*/
|
||||
enum class Modem {
|
||||
GenericModule, /*!< Default generic module with the most common commands */
|
||||
SIM800, /*!< Derived from the GenericModule with specifics applied to SIM800 model */
|
||||
SIM7600, /*!< Derived from the GenericModule, specifics applied to SIM7600 model */
|
||||
BG96, /*!< Derived from the GenericModule, specifics applied to BG69 model */
|
||||
SIM800, /*!< Derived from the GenericModule with specifics applied to SIM800 model */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -201,6 +201,24 @@ public:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
DCE* build(const config *cfg, Args&&... args)
|
||||
{
|
||||
switch (m) {
|
||||
case Modem::SIM800:
|
||||
return build<SIM800>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::SIM7600:
|
||||
return build<SIM7600>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::BG96:
|
||||
return build<BG96>(cfg, std::forward<Args>(args)...);
|
||||
case Modem::GenericModule:
|
||||
return build<GenericModule>(cfg, std::forward<Args>(args)...);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
Modem m;
|
||||
|
||||
|
@ -96,6 +96,7 @@ public:
|
||||
}
|
||||
|
||||
command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms) override;
|
||||
command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms, const char separator) override;
|
||||
|
||||
|
||||
private:
|
||||
|
@ -75,6 +75,7 @@ public:
|
||||
* @param time_ms timeout in milliseconds
|
||||
* @return OK, FAIL or TIMEOUT
|
||||
*/
|
||||
virtual command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms, const char separator) = 0;
|
||||
virtual command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms) = 0;
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,18 @@ typedef enum esp_modem_dce_mode
|
||||
} esp_modem_dce_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Create a DCE handle for new modem API
|
||||
* @brief DCE devices: Enum list of supported devices
|
||||
*/
|
||||
typedef enum esp_modem_dce_device
|
||||
{
|
||||
ESP_MODEM_DCE_GENETIC, /**< The most generic device */
|
||||
ESP_MODEM_DCE_SIM7600,
|
||||
ESP_MODEM_DCE_BG96,
|
||||
ESP_MODEM_DCE_SIM800,
|
||||
} esp_modem_dce_device_t;
|
||||
|
||||
/**
|
||||
* @brief Create a generic DCE handle for new modem API
|
||||
*
|
||||
* @param dte_config DTE configuration (UART config for now)
|
||||
* @param dce_config DCE configuration
|
||||
@ -53,6 +64,18 @@ typedef enum esp_modem_dce_mode
|
||||
*/
|
||||
esp_modem_dce_t *esp_modem_new(const esp_modem_dte_config_t *dte_config, const esp_modem_dce_config_t *dce_config, esp_netif_t *netif);
|
||||
|
||||
/**
|
||||
* @brief Create a DCE handle using the supplied device
|
||||
*
|
||||
* @param module Specific device for creating this DCE
|
||||
* @param dte_config DTE configuration (UART config for now)
|
||||
* @param dce_config DCE configuration
|
||||
* @param netif Network interface handle for the data mode
|
||||
*
|
||||
* @return DCE pointer on success, NULL on failure
|
||||
*/
|
||||
esp_modem_dce_t *esp_modem_new_dev(esp_modem_dce_device_t module, const esp_modem_dte_config_t *dte_config, const esp_modem_dce_config_t *dce_config, esp_netif_t *netif);
|
||||
|
||||
/**
|
||||
* @brief Destroys modem's DCE handle
|
||||
*
|
||||
|
@ -16,26 +16,26 @@
|
||||
#define _ESP_MODEM_COMMAND_DECLARE_INC_
|
||||
|
||||
#if GENERATE_DOCS
|
||||
#define _ARG(arg) arg
|
||||
#define _ARG(param, name) name
|
||||
#else
|
||||
#define _ARG(arg) x
|
||||
#define _ARG(param, name) param
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
#define STRING_IN(x) const std::string& _ARG(x)
|
||||
#define STRING_OUT(x) std::string& _ARG(x)
|
||||
#define BOOL_IN(x) const bool x
|
||||
#define BOOL_OUT(x) bool& _ARG(x)
|
||||
#define INT_OUT(x) int& x
|
||||
#define STRING_IN(param, name) const std::string& _ARG(param, name)
|
||||
#define STRING_OUT(param, name) std::string& _ARG(param, name)
|
||||
#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 STRUCT_OUT(struct_name, x) struct_name& x
|
||||
#else
|
||||
#define STRING_IN(x) const char* x
|
||||
#define STRING_OUT(x) char* x
|
||||
#define BOOL_IN(x) const bool x
|
||||
#define BOOL_OUT(x) bool* x
|
||||
#define INT_OUT(x) int* x
|
||||
#define STRING_IN(param, name) const 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_OUT(param, name) bool* _ARG(param, name)
|
||||
#define INT_OUT(param, name) int* _ARG(param, name)
|
||||
#define STRUCT_OUT(struct_name, x) struct struct_name* x
|
||||
#endif
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
*
|
||||
*/ \
|
||||
\
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(set_pin, command_result, 1, MUX_ARG, STRING_IN(pin)) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(set_pin, command_result, 1, MUX_ARG, STRING_IN(x, pin)) \
|
||||
\
|
||||
\
|
||||
/**
|
||||
@ -59,14 +59,18 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_pin, command_result, 1, MUX_ARG, STRING_IN(pi
|
||||
*
|
||||
* @param[out] pin_ok Pin
|
||||
*/ \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(read_pin, command_result, 1, MUX_ARG, BOOL_OUT(pin_ok)) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(read_pin, command_result, 1, MUX_ARG, BOOL_OUT(x, pin_ok)) \
|
||||
\
|
||||
/**
|
||||
* @brief Reads the module name
|
||||
*
|
||||
* @param[out] name module name
|
||||
*/ \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(set_echo, command_result, 1, MUX_ARG, BOOL_IN(x)) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(set_echo, command_result, 1, MUX_ARG, BOOL_IN(x, echo_on)) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(sms_txt_mode, command_result, 1, MUX_ARG, BOOL_IN(x, txt)) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(sms_character_set, command_result, 0, MUX_ARG) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(send_sms, command_result, 2, MUX_ARG, STRING_IN(x, number), STRING_IN(y, message)) \
|
||||
\
|
||||
\
|
||||
/**
|
||||
* @brief Reads the module name
|
||||
@ -101,21 +105,21 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_cmux, command_result, 0, MUX_ARG) \
|
||||
*
|
||||
* @param[out] name module name
|
||||
*/ \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(get_imsi, command_result, 1, MUX_ARG, STRING_OUT(x)) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(get_imsi, command_result, 1, MUX_ARG, STRING_OUT(x, imsi)) \
|
||||
\
|
||||
/**
|
||||
* @brief Reads the module name
|
||||
*
|
||||
* @param[out] name module name
|
||||
*/ \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(get_imei, command_result, 1, MUX_ARG, STRING_OUT(x)) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(get_imei, command_result, 1, MUX_ARG, STRING_OUT(x, name)) \
|
||||
\
|
||||
/**
|
||||
* @brief Reads the module name
|
||||
*
|
||||
* @param[out] name module name
|
||||
*/ \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(get_module_name, command_result, 1, MUX_ARG, STRING_OUT(name)) \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(get_module_name, command_result, 1, MUX_ARG, STRING_OUT(x, name)) \
|
||||
\
|
||||
/**
|
||||
* @brief Sets the modem to data mode
|
||||
@ -127,7 +131,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_data_mode, command_result, 0, MUX_ARG) \
|
||||
* @brief Get Signal quality
|
||||
*
|
||||
*/ \
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(get_signal_quality, command_result, 2, MUX_ARG, INT_OUT(x), INT_OUT(y))
|
||||
ESP_MODEM_DECLARE_DCE_COMMAND(get_signal_quality, command_result, 2, MUX_ARG, INT_OUT(x, rssi), INT_OUT(y, ber))
|
||||
|
||||
#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'
|
||||
|
Reference in New Issue
Block a user