remove all remaining C implementation

This commit is contained in:
David Cermak
2021-03-08 15:10:15 +01:00
parent 904cf94648
commit 2907eb9836
35 changed files with 114 additions and 4123 deletions

View File

@ -9,10 +9,10 @@ class GenericModule;
class SIM7600;
class SIM800;
class BG96;
struct dte_config;
struct esp_modem_dte_config;
typedef struct esp_netif_obj esp_netif_t;
std::shared_ptr<DTE> create_uart_dte(const dte_config *config);
std::shared_ptr<DTE> create_uart_dte(const esp_modem_dte_config *config);
std::shared_ptr<GenericModule> create_generic_module(const std::shared_ptr<DTE>& dte, std::string &apn);

View File

@ -16,7 +16,7 @@ namespace dce_commands {
#define ESP_MODEM_DECLARE_DCE_COMMAND(name, return_type, TEMPLATE_ARG, MUX_ARG, ...) \
return_type name(CommandableIf *t, ## __VA_ARGS__);
DECLARE_ALL_COMMAND_APIS(forwards name(...) { device->name(...); } )
DECLARE_ALL_COMMAND_APIS(declare name(Commandable *p, ...);)
#undef ESP_MODEM_DECLARE_DCE_COMMAND

View File

@ -1,331 +0,0 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_event.h"
#include "driver/uart.h"
#include "esp_modem_dte_config.h"
/**
* @brief Forward declare DTE and DCE objects
*
*/
typedef struct esp_modem_dte esp_modem_dte_t;
typedef struct esp_modem_dce esp_modem_dce_t;
/**
* @brief Declare Event Base for ESP Modem
*
*/
ESP_EVENT_DECLARE_BASE(ESP_MODEM_EVENT);
/**
* @brief ESP Modem Event
*
*/
typedef enum {
ESP_MODEM_EVENT_PPP_START = 0, /*!< ESP Modem Start PPP Session */
ESP_MODEM_EVENT_PPP_STOP = 3, /*!< ESP Modem Stop PPP Session*/
ESP_MODEM_EVENT_UNKNOWN = 4 /*!< ESP Modem Unknown Response */
} esp_modem_event_t;
/**
* @defgroup ESP_MODEM_DTE_TYPES DTE Types
* @brief Configuration and related types used to init and setup a new DTE object
*/
/** @addtogroup ESP_MODEM_DTE_TYPES
* @{
*/
/**
* @brief ESP Modem DTE Configuration
*
*/
typedef struct dte_config
#if 0
{
uart_port_t port_num; /*!< UART port number */
uart_word_length_t data_bits; /*!< Data bits of UART */
uart_stop_bits_t stop_bits; /*!< Stop bits of UART */
uart_parity_t parity; /*!< Parity type */
esp_modem_flow_ctrl_t flow_control; /*!< Flow control type */
uint32_t baud_rate; /*!< Communication baud rate */
int tx_io_num; /*!< TXD Pin Number */
int rx_io_num; /*!< RXD Pin Number */
int rts_io_num; /*!< RTS Pin Number */
int cts_io_num; /*!< CTS Pin Number */
int rx_buffer_size; /*!< UART RX Buffer Size */
int tx_buffer_size; /*!< UART TX Buffer Size */
int pattern_queue_size; /*!< UART Pattern Queue Size */
int event_queue_size; /*!< UART Event Queue Size */
uint32_t event_task_stack_size; /*!< UART Event Task Stack size */
int event_task_priority; /*!< UART Event Task Priority */
int line_buffer_size; /*!< Line buffer size for command mode */
}
#endif
esp_modem_dte_config_t;
/**
* @brief ESP Modem DTE Default Configuration
*
*/
#define ESP_MODEM_DTE_DEFAULT_CONFIG() \
{ \
.port_num = UART_NUM_1, \
.data_bits = UART_DATA_8_BITS, \
.stop_bits = UART_STOP_BITS_1, \
.parity = UART_PARITY_DISABLE, \
.flow_control = ESP_MODEM_FLOW_CONTROL_NONE,\
.baud_rate = 115200, \
.tx_io_num = 25, \
.rx_io_num = 26, \
.rts_io_num = 27, \
.cts_io_num = 23, \
.rx_buffer_size = 1024, \
.tx_buffer_size = 512, \
.pattern_queue_size = 20, \
.event_queue_size = 30, \
.event_task_stack_size = 4096, \
.event_task_priority = 5, \
.line_buffer_size = 512 \
}
/**
* @}
*/
/**
* @defgroup ESP_MODEM_DCE_TYPES DCE Types
* @brief Configuration and related types used to init and setup a new DCE object
*/
/** @addtogroup ESP_MODEM_DCE_TYPES
* @{
*/
/**
* @brief PDP context type used as an input parameter to esp_modem_dce_set_pdp_context
* also used as a part of configuration structure
*/
typedef struct esp_modem_dce_pdp_ctx_s {
size_t cid; /*!< PDP context identifier */
const char *type; /*!< Protocol type */
const char *apn; /*!< Modem APN (Access Point Name, a logical name to choose data network) */
} esp_modem_dce_pdp_ctx_t;
/**
* @brief Devices that the DCE will act as
*
*/
typedef enum esp_modem_dce_device_e {
ESP_MODEM_DEVICE_UNSPECIFIED,
ESP_MODEM_DEVICE_SIM800,
ESP_MODEM_DEVICE_SIM7600,
ESP_MODEM_DEVICE_BG96,
} esp_modem_dce_device_t;
/**
* @brief DCE's configuration structure
*/
typedef struct esp_modem_dce_config_s {
esp_modem_dce_pdp_ctx_t pdp_context; /*!< modem PDP context including APN */
bool populate_command_list; /*!< use command list interface: Setting this to true creates
a list of supported AT commands enabling sending
these commands, but will occupy data memory */
esp_modem_dce_device_t device; /*!< predefined device enum that the DCE will initialise as */
} esp_modem_dce_config_t;
/**
* @brief Default configuration of DCE unit of ESP-MODEM
*
*/
#define ESP_MODEM_DCE_DEFAULT_CONFIG(APN) \
{ \
.pdp_context = { \
.cid = 1, \
.type = "IP", \
.apn = APN }, \
.populate_command_list = false,\
.device = ESP_MODEM_DEVICE_UNSPECIFIED \
}
/**
* @}
*/
/**
* @defgroup ESP_MODEM_DTE_DCE DCE and DCE object init and setup API
* @brief Creating and init objects of DTE and DCE
*/
/** @addtogroup ESP_MODEM_DTE_DCE
* @{
*/
/**
* @brief Create and initialize Modem DTE object
*
* @param config configuration of ESP Modem DTE object
* @return modem_dte_t*
* - Modem DTE object
*/
esp_modem_dte_t *esp_modem_dte_new(const esp_modem_dte_config_t *config);
/**
* @brief Create and initialize Modem DCE object
*
* @param config configuration of ESP Modem DTE object
* @return modem_dce_t* Modem DCE object
*/
esp_modem_dce_t *esp_modem_dce_new(esp_modem_dce_config_t *config);
/**
* @brief Initialize the DCE object that has already been created
*
* This API is typically used to initialize extended DCE object,
* "sub-class" of esp_modem_dce_t
*
* @param config Configuration for DCE object
* @return
* - ESP_OK on success
* - ESP_FAIL on error (init issue, set specific command issue)
* - ESP_ERR_INVALID_ARG on invalid parameters
*/
esp_err_t esp_modem_dce_init(esp_modem_dce_t *dce, esp_modem_dce_config_t *config);
/**
* @}
*/
/**
* @defgroup ESP_MODEM_EVENTS Event handling API
*/
/** @addtogroup ESP_MODEM_EVENTS
* @{
*/
/**
* @brief Register event handler for ESP Modem event loop
*
* @param dte modem_dte_t type object
* @param handler event handler to register
* @param handler_args arguments for registered handler
* @return esp_err_t
* - ESP_OK on success
* - ESP_ERR_NO_MEM on allocating memory for the handler failed
* - ESP_ERR_INVALID_ARG on invalid combination of event base and event id
*/
esp_err_t esp_modem_set_event_handler(esp_modem_dte_t *dte, esp_event_handler_t handler, int32_t event_id, void *handler_args);
/**
* @brief Unregister event handler for ESP Modem event loop
*
* @param dte modem_dte_t type object
* @param handler event handler to unregister
* @return esp_err_t
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG on invalid combination of event base and event id
*/
esp_err_t esp_modem_remove_event_handler(esp_modem_dte_t *dte, esp_event_handler_t handler);
/**
* @}
*/
/**
* @defgroup ESP_MODEM_LIFECYCLE Modem lifecycle API
* @brief Basic modem API to start/stop the PPP mode
*/
/** @addtogroup ESP_MODEM_LIFECYCLE
* @{
*/
/**
* @brief Setup PPP Session
*
* @param dte Modem DTE object
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_start_ppp(esp_modem_dte_t *dte);
/**
* @brief Exit PPP Session
*
* @param dte Modem DTE Object
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_stop_ppp(esp_modem_dte_t *dte);
/**
* @brief Basic start of the modem. This API performs default dce's start_up() function
*
* @param dte Modem DTE Object
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_INVALID_ARG on invalid arguments
*/
esp_err_t esp_modem_default_start(esp_modem_dte_t *dte);
/**
* @brief Basic attach operation of modem sub-elements
*
* This API binds the supplied DCE and netif to the modem's DTE and initializes the modem
*
* @param dte Modem DTE Object
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_default_attach(esp_modem_dte_t *dte, esp_modem_dce_t *dce, esp_netif_t* ppp_netif);
/**
* @brief Basic destroy operation of the modem DTE and all the sub-elements bound to it
*
* This API deletes the DCE, modem netif adapter as well as the esp_netif supplied to
* esp_modem_default_attach(). Then it deletes the DTE itself.
*
* @param dte Modem DTE Object
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_INVALID_ARG on invalid arguments
*/
esp_err_t esp_modem_default_destroy(esp_modem_dte_t *dte);
/**
* @}
*/
#ifdef __cplusplus
}
#endif

View File

@ -12,7 +12,7 @@ extern "C" {
typedef struct esp_modem_dce_wrap esp_modem_t;
esp_modem_t *esp_modem_new(const dte_config *config, esp_netif_t *netif, const char* apn);
esp_modem_t *esp_modem_new(const esp_modem_dte_config *config, esp_netif_t *netif, const char* apn);
void esp_modem_destroy(esp_modem_t * dce);

View File

@ -0,0 +1,77 @@
//
// Created by david on 2/24/21.
//
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_CONFIG_H
#define SIMPLE_CXX_CLIENT_ESP_MODEM_CONFIG_H
#include "driver/uart.h"
/**
* @brief Modem flow control type
*
*/
typedef enum {
ESP_MODEM_FLOW_CONTROL_NONE = 0,
ESP_MODEM_FLOW_CONTROL_SW,
ESP_MODEM_FLOW_CONTROL_HW
} esp_modem_flow_ctrl_t;
struct esp_modem_dte_config {
uart_port_t port_num; /*!< UART port number */
uart_word_length_t data_bits; /*!< Data bits of UART */
uart_stop_bits_t stop_bits; /*!< Stop bits of UART */
uart_parity_t parity; /*!< Parity type */
esp_modem_flow_ctrl_t flow_control; /*!< Flow control type */
int baud_rate; /*!< Communication baud rate */
int tx_io_num; /*!< TXD Pin Number */
int rx_io_num; /*!< RXD Pin Number */
int rts_io_num; /*!< RTS Pin Number */
int cts_io_num; /*!< CTS Pin Number */
int rx_buffer_size; /*!< UART RX Buffer Size */
int tx_buffer_size; /*!< UART TX Buffer Size */
int pattern_queue_size; /*!< UART Pattern Queue Size */
int event_queue_size; /*!< UART Event Queue Size */
uint32_t event_task_stack_size; /*!< UART Event Task Stack size */
int event_task_priority; /*!< UART Event Task Priority */
int line_buffer_size; /*!< Line buffer size for command mode */
};
/**
* @brief ESP Modem DTE Default Configuration
*
*/
#define ESP_MODEM_DTE_DEFAULT_CONFIG() \
{ \
.port_num = UART_NUM_1, \
.data_bits = UART_DATA_8_BITS, \
.stop_bits = UART_STOP_BITS_1, \
.parity = UART_PARITY_DISABLE, \
.flow_control = ESP_MODEM_FLOW_CONTROL_NONE,\
.baud_rate = 115200, \
.tx_io_num = 25, \
.rx_io_num = 26, \
.rts_io_num = 27, \
.cts_io_num = 23, \
.rx_buffer_size = 1024, \
.tx_buffer_size = 512, \
.pattern_queue_size = 20, \
.event_queue_size = 30, \
.event_task_stack_size = 4096, \
.event_task_priority = 5, \
.line_buffer_size = 512 \
}
struct esp_modem_dce_config {
const char* apn;
};
#define ESP_MODEM_DCE_DEFAULT_CONFIG(APN) \
{ \
.apn = APN \
}
typedef struct esp_modem_dte_config esp_modem_dte_config_t;
typedef struct esp_modem_dce_config esp_modem_dce_config_t;
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_CONFIG_H

View File

@ -1,236 +0,0 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_types.h"
#include "esp_err.h"
#include "esp_modem.h"
#include "esp_modem_dte.h"
/**
* @brief Forward declaration of the command list object, which (if enabled) is used
* to populate a command palette and access commands by its symbolic name
*/
struct esp_modem_dce_cmd_list;
/**
* @brief Working state of DCE
*
*/
typedef enum {
ESP_MODEM_STATE_PROCESSING, /*!< In processing */
ESP_MODEM_STATE_SUCCESS, /*!< Process successfully */
ESP_MODEM_STATE_FAIL /*!< Process failed */
} esp_modem_state_t;
/**
* @brief Generic command type used in DCE unit
*/
typedef esp_err_t (*dce_command_t)(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Type of line handlers called fro DTE upon line response reception
*/
typedef esp_err_t (*esp_modem_dce_handle_line_t)(esp_modem_dce_t *dce, const char *line);
/**
* @brief DCE(Data Communication Equipment)
*
*/
struct esp_modem_dce {
esp_modem_state_t state; /*!< Modem working state */
esp_modem_mode_t mode; /*!< Working mode */
esp_modem_dte_t *dte; /*!< DTE which connect to DCE */
struct esp_modem_dce_cmd_list *dce_cmd_list;
esp_modem_dce_config_t config;
esp_modem_dce_handle_line_t handle_line; /*!< Handle line strategy */
void *handle_line_ctx; /*!< DCE context reserved for handle_line
processing */
// higher level actions DCE unit can take
esp_err_t (*set_working_mode)(esp_modem_dce_t *dce, esp_modem_mode_t mode); /*!< Set working mode */
esp_err_t (*deinit)(esp_modem_dce_t *dce); /*!< Destroys the DCE */
esp_err_t (*start_up)(esp_modem_dce_t *dce); /*!< Start-up sequence */
// list of essential commands for esp-modem basic work
dce_command_t hang_up; /*!< generic command for hang-up */
dce_command_t set_pdp_context; /*!< generic command for pdp context */
dce_command_t set_data_mode; /*!< generic command for data mode */
dce_command_t resume_data_mode; /*!< generic command to resume already dialed data mode */
dce_command_t set_command_mode; /*!< generic command for command mode */
dce_command_t set_echo; /*!< generic command for echo mode */
dce_command_t sync; /*!< generic command for sync */
dce_command_t set_flow_ctrl; /*!< generic command for flow-ctrl */
dce_command_t store_profile; /*!< generic command for store-profile */
};
// DCE commands building blocks
/**
* @brief Sending generic command to DCE
*
* @param[in] dce Modem DCE object
* @param[in] command String command
* @param[in] timeout Command timeout in ms
* @param[in] handle_line Function ptr which processes the command response
* @param[in] ctx Function ptr context
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_generic_command(esp_modem_dce_t *dce, const char * command, uint32_t timeout, esp_modem_dce_handle_line_t handle_line, void *ctx);
/**
* @brief Indicate that processing current command has done
*
* @param dce Modem DCE object
* @param state Modem state after processing
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_process_command_done(esp_modem_dce_t *dce, esp_modem_state_t state);
/**
* @brief Default handler for response
* Some responses for command are simple, commonly will return OK when succeed of ERROR when failed
*
* @param dce Modem DCE object
* @param line line string
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_handle_response_default(esp_modem_dce_t *dce, const char *line);
// DCE higher level commands
/**
* @brief Set Working Mode
*
* @param dce Modem DCE object
* @param mode working mode
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_set_working_mode(esp_modem_dce_t *dce, esp_modem_mode_t mode);
/**
* @brief Default start-up sequence, which sets the modem into an operational mode
*
* @param dce Modem DCE object
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_default_start_up(esp_modem_dce_t *dce);
/**
* @brief Destroys the DCE
*
* @param dce Modem DCE object
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_default_destroy(esp_modem_dce_t *dce);
/**
* @brief Initializes the DCE
*
* @param dce Modem DCE object
* @param config DCE configuration structure
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_default_init(esp_modem_dce_t *dce, esp_modem_dce_config_t* config);
/**
* @brief Sets the DCE parameters. This API updates runtime DCE config parameters,
* typically used to update PDP context data.
*
* @param dce Modem DCE object
* @param config DCE configuration structure
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
*/
esp_err_t esp_modem_dce_set_params(esp_modem_dce_t *dce, esp_modem_dce_config_t* config);
// list command operations
/**
* @brief Executes a specific command from the list
*
* @param dce Modem DCE object
* @param command Symbolic name of the command to execute
* @param param Generic parameter to the command
* @param result Generic output parameter
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_command_list_run(esp_modem_dce_t *dce, const char * command, void * param, void* result);
/**
* @brief Deinitialize the command list
*
* @param dce Modem DCE object
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_command_list_deinit(esp_modem_dce_t *dce);
/**
* @brief Initializes default command list with predefined command palette
*
* @param dce Modem DCE object
*
* @return ESP_OK on success, ESP_FAIL on error
*/
esp_err_t esp_modem_set_default_command_list(esp_modem_dce_t *dce);
/**
* @brief Add or set specific command to the command list
*
* @param dce Modem DCE object
* @param command_id Command symbolic name
* @param command Generic command function pointer
*
* @return ESP_OK on success, ESP_FAIL on error
*/
esp_err_t esp_modem_command_list_set_cmd(esp_modem_dce_t *dce, const char * command_id, dce_command_t command);
#ifdef __cplusplus
}
#endif

View File

@ -1,359 +0,0 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_modem_dce.h"
/**
* @brief Result Code from DCE
*
*/
#define MODEM_RESULT_CODE_SUCCESS "OK" /*!< Acknowledges execution of a command */
#define MODEM_RESULT_CODE_CONNECT "CONNECT" /*!< A connection has been established */
#define MODEM_RESULT_CODE_RING "RING" /*!< Detect an incoming call signal from network */
#define MODEM_RESULT_CODE_NO_CARRIER "NO CARRIER" /*!< Connection termincated or establish a connection failed */
#define MODEM_RESULT_CODE_ERROR "ERROR" /*!< Command not recognized, command line maximum length exceeded, parameter value invalid */
#define MODEM_RESULT_CODE_NO_DIALTONE "NO DIALTONE" /*!< No dial tone detected */
#define MODEM_RESULT_CODE_BUSY "BUSY" /*!< Engaged signal detected */
#define MODEM_RESULT_CODE_NO_ANSWER "NO ANSWER" /*!< Wait for quiet answer */
/**
* @brief Specific Timeout Constraint, Unit: millisecond
*
*/
#define MODEM_COMMAND_TIMEOUT_DEFAULT (500) /*!< Default timeout value for most commands */
#define MODEM_COMMAND_TIMEOUT_OPERATOR (75000) /*!< Timeout value for getting operator status */
#define MODEM_COMMAND_TIMEOUT_RESET (60000) /*!< Timeout value for reset command */
#define MODEM_COMMAND_TIMEOUT_MODE_CHANGE (5000) /*!< Timeout value for changing working mode */
#define MODEM_COMMAND_TIMEOUT_POWEROFF (1000) /*!< Timeout value for power down */
/**
* @brief Strip the tailed "\r\n"
*
* @param str string to strip
* @param len length of string
*/
static inline void strip_cr_lf_tail(char *str, uint32_t len)
{
if (str[len - 2] == '\r') {
str[len - 2] = '\0';
} else if (str[len - 1] == '\r') {
str[len - 1] = '\0';
}
}
/**
* @brief Synchronization
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_sync(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Enable or not echo mode of DCE
*
* @param dce Modem DCE object
* @param[in] param bool casted to (void*): true to enable echo mode, false to disable echo mode
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_set_echo(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Store current parameter setting in the user profile
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_store_profile(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Set flow control mode of DCE in data mode
*
* @param[in] dce Modem DCE object
* @param[in] param esp_modem_flow_ctrl_t casted to (void*): flow control mode
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_set_flow_ctrl(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Define PDP context
*
* @param[in] dce Modem DCE object
* @param[in] param esp_modem_dce_pdp_ctx_t type defining PDP context
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_set_pdp_context(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Hang up
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_hang_up(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Signal strength structure used as a result to esp_modem_dce_get_signal_quality() API
*/
typedef struct esp_modem_dce_csq_ctx_s {
int rssi; //!< Signal strength indication
int ber; //!< Channel bit error rate
} esp_modem_dce_csq_ctx_t;
/**
* @brief Get signal quality
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result esp_modem_dce_csq_ctx_t type returning rssi and ber values
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_get_signal_quality(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Voltage status structure used as a result to esp_modem_dce_get_battery_status() API
*/
typedef struct esp_modem_dce_cbc_ctx_s {
int battery_status; //!< current status in mV
int bcs; //!< charge status (-1-Not available, 0-Not charging, 1-Charging, 2-Charging done)
int bcl; //!< 1-100% battery capacity, -1-Not available
} esp_modem_dce_cbc_ctx_t;
/**
* @brief Get battery status
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result esp_modem_dce_cbc_ctx_t type returning battery status and other fields if available
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_get_battery_status(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Get DCE module IMEI number
*
* @param[in] dce Modem DCE object
* @param[in] param size_t of output string length (casted to void*), max size the resultant string
* @param[out] result pointer to the string where the resultant IMEI number gets copied (if size param fits)
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_get_imei_number(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Get DCE module IMSI number
*
* @param[in] dce Modem DCE object
* @param[in] param size_t of output string length (casted to void*), max size the resultant string
* @param[out] result pointer to the string where the resultant IMSI number gets copied (if size param fits)
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_get_imsi_number(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Get DCE module name
*
* @param[in] dce Modem DCE object
* @param[in] param size_t of output string length (casted to void*), max size the resultant string
* @param[out] result pointer to the string where the resultant module name gets copied (if size param fits)
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_get_module_name(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Get operator name
*
* @param[in] dce Modem DCE object
* @param[in] param size_t of output string length (casted to void*), max size the resultant string
* @param[out] result pointer to the string where the resultant operator name gets copied (if size param fits)
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_get_operator_name(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Switch to data mode
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_set_data_mode(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Resume the data mode when PPP has already been started, but switched back to command
* mode (typically using the `+++` PPP escape sequence)
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_resume_data_mode(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Switch to command mode
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_set_command_mode(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Power-down the module
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_power_down(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Reset the module
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_reset(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Checks if the module waits for entering the PIN
*
* @param[in] dce Modem DCE object
* @param[in] param None
* @param[out] result pointer to bool indicating READY if set to true
* or the module is waiting for PIN if set to false
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_read_pin(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Enters the PIN number
*
* @param[in] dce Modem DCE object
* @param[in] param 4 character string pointer to the PIN
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_set_pin(esp_modem_dce_t *dce, void *param, void *result);
/**
* @brief Sets the DCE to temporarily use the baudrate specified
*
* @param[in] dce Modem DCE object
* @param[in] param string pointer to char representation of the baudrate
* @param[out] result None
*
* @return esp_err_t
* - ESP_OK on success
* - ESP_FAIL on error
* - ESP_ERR_TIMEOUT if timeout while waiting for expected response
*/
esp_err_t esp_modem_dce_set_baud_temp(esp_modem_dce_t *dce, void *param, void *result);

View File

@ -1,101 +0,0 @@
// Copyright 2018-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_types.h"
#include "esp_err.h"
#include "esp_event.h"
/**
* @brief Working mode of Modem
*
*/
typedef enum {
ESP_MODEM_COMMAND_MODE = 0, /*!< Command Mode */
ESP_MODEM_PPP_MODE, /*!< PPP Mode */
ESP_MODEM_TRANSITION_MODE /*!< Transition Mode between data and command mode indicating that
the modem is not yet ready for sending commands nor data */
} esp_modem_mode_t;
/**
* @brief DTE(Data Terminal Equipment)
*
*/
struct esp_modem_dte {
esp_modem_flow_ctrl_t flow_ctrl; /*!< Flow control of DTE */
esp_modem_dce_t *dce; /*!< DCE which connected to the DTE */
struct esp_modem_netif_driver_s *netif_adapter;
esp_err_t (*send_cmd)(esp_modem_dte_t *dte, const char *command, uint32_t timeout); /*!< Send command to DCE */
int (*send_data)(esp_modem_dte_t *dte, const char *data, uint32_t length); /*!< Send data to DCE */
esp_err_t (*send_wait)(esp_modem_dte_t *dte, const char *data, uint32_t length,
const char *prompt, uint32_t timeout); /*!< Wait for specific prompt */
esp_err_t (*change_mode)(esp_modem_dte_t *dte, esp_modem_mode_t new_mode); /*!< Changing working mode */
esp_err_t (*process_cmd_done)(esp_modem_dte_t *dte); /*!< Callback when DCE process command done */
esp_err_t (*deinit)(esp_modem_dte_t *dte); /*!< Deinitialize */
};
/**
* @brief Type used for reception callback
*
*/
typedef esp_err_t (*esp_modem_on_receive)(void *buffer, size_t len, void *context);
/**
* @brief Setup on reception callback
*
* @param dte ESP Modem DTE object
* @param receive_cb Function pointer to the reception callback
* @param receive_cb_ctx Contextual pointer to be passed to the reception callback
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_set_rx_cb(esp_modem_dte_t *dte, esp_modem_on_receive receive_cb, void *receive_cb_ctx);
/**
* @brief Notify the modem, that ppp netif has closed
*
* @note This API should only be used internally by the modem-netif layer
*
* @param dte ESP Modem DTE object
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_notify_ppp_netif_closed(esp_modem_dte_t *dte);
/**
* @brief Notify the modem, that all the modem units (DTE, DCE, PPP) has
* been properly initialized and DTE loop can safely start
*
* @param dte ESP Modem DTE object
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_notify_initialized(esp_modem_dte_t *dte);
/**
* @brief Configure runtime parameters for the DTE. Currently supports only the baud rate to be set
*
* @param dte ESP Modem DTE object
*
* @return ESP_OK on success
*/
esp_err_t esp_modem_dte_set_params(esp_modem_dte_t *dte, const esp_modem_dte_config_t *config);
#ifdef __cplusplus
}
#endif

View File

@ -1,39 +0,0 @@
//
// Created by david on 2/24/21.
//
#ifndef SIMPLE_CXX_CLIENT_ESP_MODEM_DTE_CONFIG_H
#define SIMPLE_CXX_CLIENT_ESP_MODEM_DTE_CONFIG_H
/**
* @brief Modem flow control type
*
*/
typedef enum {
ESP_MODEM_FLOW_CONTROL_NONE = 0,
ESP_MODEM_FLOW_CONTROL_SW,
ESP_MODEM_FLOW_CONTROL_HW
} esp_modem_flow_ctrl_t;
struct dte_config {
uart_port_t port_num; /*!< UART port number */
uart_word_length_t data_bits; /*!< Data bits of UART */
uart_stop_bits_t stop_bits; /*!< Stop bits of UART */
uart_parity_t parity; /*!< Parity type */
esp_modem_flow_ctrl_t flow_control; /*!< Flow control type */
int baud_rate; /*!< Communication baud rate */
int tx_io_num; /*!< TXD Pin Number */
int rx_io_num; /*!< RXD Pin Number */
int rts_io_num; /*!< RTS Pin Number */
int cts_io_num; /*!< CTS Pin Number */
int rx_buffer_size; /*!< UART RX Buffer Size */
int tx_buffer_size; /*!< UART TX Buffer Size */
int pattern_queue_size; /*!< UART Pattern Queue Size */
int event_queue_size; /*!< UART Event Queue Size */
uint32_t event_task_stack_size; /*!< UART Event Task Stack size */
int event_task_priority; /*!< UART Event Task Priority */
int line_buffer_size; /*!< Line buffer size for command mode */
};
#endif //SIMPLE_CXX_CLIENT_ESP_MODEM_DTE_CONFIG_H

View File

@ -1,103 +0,0 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief modem netif adapter type
*
*/
typedef struct esp_modem_netif_driver_s esp_modem_netif_driver_t;
/**
* @defgroup ESP_MODEM_NETIF Modem netif adapter API
* @brief network interface adapter for esp-modem
*/
/** @addtogroup ESP_MODEM_NETIF
* @{
*/
/**
* @brief Creates handle to esp_modem used as an esp-netif driver
*
* @param dte ESP Modem DTE object
*
* @return opaque pointer to esp-modem IO driver used to attach to esp-netif
*/
esp_modem_netif_driver_t *esp_modem_netif_new(esp_modem_dte_t *dte);
/**
* @brief Destroys the esp-netif driver handle as well as the internal netif
* object attached to it
*
* @param h pointer to the esp-netif adapter for esp-modem
*/
void esp_modem_netif_destroy(esp_modem_netif_driver_t *h);
/**
* @brief Clears default handlers for esp-modem lifecycle
*
* @param h pointer to the esp-netif adapter for esp-modem
*/
esp_err_t esp_modem_netif_clear_default_handlers(esp_modem_netif_driver_t *h);
/**
* @brief Setups default handlers for esp-modem lifecycle
*
* @param h pointer to the esp-netif adapter for esp-modem
* @param esp_netif pointer corresponding esp-netif instance
*/
esp_err_t esp_modem_netif_set_default_handlers(esp_modem_netif_driver_t *h, esp_netif_t * esp_netif);
/**
* @}
*/
/**
* @defgroup ESP_MODEM_NETIF_LEGACY Modem netif adapter legacy API
* @brief Legacy API for modem netif
*/
/** @addtogroup ESP_MODEM_NETIF_LEGACY
* @{
*/
/**
* @brief Destroys the esp-netif driver handle the same way
* as esp_modem_netif_destroy()
*
* @note This API is only provided for legacy API
*/
void esp_modem_netif_teardown(esp_modem_netif_driver_t *h);
/**
* @brief The same as `esp_modem_netif_new()`, but autostarts the netif
* on esp_netif_attach().
*
* @note This API is only provided for legacy API
*/
esp_modem_netif_driver_t *esp_modem_netif_setup(esp_modem_dte_t *dte);
/**
* @}
*/
#ifdef __cplusplus
}
#endif

View File

@ -1,87 +0,0 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_err.h"
#include "esp_modem_dce.h"
/**
* @brief Utility macro to define a retry method
*
*/
#define DEFINE_RETRY_CMD(name, retry, super_type) \
esp_err_t name(esp_modem_dce_t *dce, void *param, void *result) \
{ \
super_type *super = __containerof(dce, super_type, parent); \
return super->retry->run(super->retry, param, result); \
}
/**
* @brief GPIO helper object used to pull modem IOs
*
*/
typedef struct esp_modem_gpio_s {
int gpio_num;
int inactive_level;
int active_width_ms;
int inactive_width_ms;
void (*pulse)(struct esp_modem_gpio_s *pin);
void (*pulse_special)(struct esp_modem_gpio_s *pin, int active_width_ms, int inactive_width_ms);
void (*destroy)(struct esp_modem_gpio_s *pin);
} esp_modem_recov_gpio_t;
/**
* @brief Recovery helper object used to resend commands if failed or timeouted
*
*/
typedef struct esp_modem_retry_s esp_modem_recov_resend_t;
/**
* @brief User recovery function to be called upon modem command failed
*
*/
typedef esp_err_t (*esp_modem_retry_fn_t)(esp_modem_recov_resend_t *retry_cmd, esp_err_t current_err, int timeouts, int errors);
/**
* @brief Recovery helper object
*
*/
struct esp_modem_retry_s {
const char *command;
esp_err_t (*run)(struct esp_modem_retry_s *retry, void *param, void *result);
dce_command_t orig_cmd;
esp_modem_retry_fn_t recover;
esp_modem_dce_t *dce;
int retries_after_timeout; //!< Retry strategy: numbers of resending the same command on timeout
int retries_after_error; //!< Retry strategy: numbers of resending the same command on error
void (*destroy)(struct esp_modem_retry_s *this_recov);
};
/**
* @brief Create new resend object
*
*/
esp_modem_recov_resend_t *esp_modem_recov_resend_new(esp_modem_dce_t *dce, dce_command_t orig_cmd, esp_modem_retry_fn_t recover, int max_timeouts, int max_errors);
/**
* @brief Create new gpio object
*
*/
esp_modem_recov_gpio_t *esp_modem_recov_gpio_new(int gpio_num, int inactive_level, int active_width_ms, int inactive_width_ms);