mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-22 14:57:30 +02:00
esp_modem: Refactor the modem to a standalone managed component
This commit is contained in:
@ -1,33 +0,0 @@
|
||||
// Copyright 2015-2018 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_service.h"
|
||||
#include "esp_modem.h"
|
||||
|
||||
/**
|
||||
* @brief Create and initialize BG96 object
|
||||
*
|
||||
* @param dte Modem DTE object
|
||||
* @return modem_dce_t* Modem DCE object
|
||||
*/
|
||||
modem_dce_t *bg96_init(modem_dte_t *dte);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
||||
// 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.
|
||||
@ -17,11 +17,15 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "esp_modem_dce.h"
|
||||
#include "esp_modem_dte.h"
|
||||
#include "esp_event.h"
|
||||
#include "driver/uart.h"
|
||||
#include "esp_modem_compat.h"
|
||||
|
||||
/**
|
||||
* @brief Fowrard 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
|
||||
@ -39,6 +43,25 @@ typedef enum {
|
||||
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 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;
|
||||
|
||||
/**
|
||||
* @brief ESP Modem DTE Configuration
|
||||
*
|
||||
@ -48,7 +71,7 @@ typedef struct {
|
||||
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 */
|
||||
modem_flow_ctrl_t flow_control; /*!< Flow control 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 */
|
||||
@ -63,12 +86,6 @@ typedef struct {
|
||||
int line_buffer_size; /*!< Line buffer size for command mode */
|
||||
} esp_modem_dte_config_t;
|
||||
|
||||
/**
|
||||
* @brief Type used for reception callback
|
||||
*
|
||||
*/
|
||||
typedef esp_err_t (*esp_modem_on_receive)(void *buffer, size_t len, void *context);
|
||||
|
||||
/**
|
||||
* @brief ESP Modem DTE Default Configuration
|
||||
*
|
||||
@ -80,7 +97,7 @@ typedef esp_err_t (*esp_modem_on_receive)(void *buffer, size_t len, void *contex
|
||||
.stop_bits = UART_STOP_BITS_1, \
|
||||
.parity = UART_PARITY_DISABLE, \
|
||||
.baud_rate = 115200, \
|
||||
.flow_control = MODEM_FLOW_CONTROL_NONE,\
|
||||
.flow_control = ESP_MODEM_FLOW_CONTROL_NONE,\
|
||||
.tx_io_num = 25, \
|
||||
.rx_io_num = 26, \
|
||||
.rts_io_num = 27, \
|
||||
@ -94,6 +111,80 @@ typedef esp_err_t (*esp_modem_on_receive)(void *buffer, size_t len, void *contex
|
||||
.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
|
||||
*
|
||||
@ -101,7 +192,42 @@ typedef esp_err_t (*esp_modem_on_receive)(void *buffer, size_t len, void *contex
|
||||
* @return modem_dte_t*
|
||||
* - Modem DTE object
|
||||
*/
|
||||
modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config);
|
||||
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
|
||||
@ -114,7 +240,7 @@ modem_dte_t *esp_modem_dte_init(const esp_modem_dte_config_t *config);
|
||||
* - 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(modem_dte_t *dte, esp_event_handler_t handler, int32_t event_id, void *handler_args);
|
||||
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
|
||||
@ -125,7 +251,21 @@ esp_err_t esp_modem_set_event_handler(modem_dte_t *dte, esp_event_handler_t hand
|
||||
* - 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(modem_dte_t *dte, esp_event_handler_t handler);
|
||||
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
|
||||
@ -135,7 +275,7 @@ esp_err_t esp_modem_remove_event_handler(modem_dte_t *dte, esp_event_handler_t h
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_start_ppp(modem_dte_t *dte);
|
||||
esp_err_t esp_modem_start_ppp(esp_modem_dte_t *dte);
|
||||
|
||||
/**
|
||||
* @brief Exit PPP Session
|
||||
@ -145,29 +285,49 @@ esp_err_t esp_modem_start_ppp(modem_dte_t *dte);
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_stop_ppp(modem_dte_t *dte);
|
||||
esp_err_t esp_modem_stop_ppp(esp_modem_dte_t *dte);
|
||||
|
||||
/**
|
||||
* @brief Setup on reception callback
|
||||
* @brief Basic start of the modem. This API performs default dce's start_up() function
|
||||
*
|
||||
* @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
|
||||
* @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_set_rx_cb(modem_dte_t *dte, esp_modem_on_receive receive_cb, void *receive_cb_ctx);
|
||||
esp_err_t esp_modem_default_start(esp_modem_dte_t *dte);
|
||||
|
||||
/**
|
||||
* @brief Notify the modem, that ppp netif has closed
|
||||
* @brief Basic attach operation of modem sub-elements
|
||||
*
|
||||
* @note This API should only be used internally by the modem-netif layer
|
||||
* This API binds the supplied DCE and netif to the modem's DTE and initializes the modem
|
||||
*
|
||||
* @param dte ESP Modem DTE object
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
* @param dte Modem DTE Object
|
||||
* @return esp_err_t
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_notify_ppp_netif_closed(modem_dte_t *dte);
|
||||
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
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
// Copyright 2019 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 "lwip/ip.h"
|
||||
|
||||
/**
|
||||
* @brief ESP Modem Event backward compatible version
|
||||
*/
|
||||
typedef enum {
|
||||
MODEM_EVENT_PPP_START = 0x100,
|
||||
MODEM_EVENT_PPP_CONNECT = 0x101,
|
||||
MODEM_EVENT_PPP_DISCONNECT = 0x102,
|
||||
MODEM_EVENT_PPP_STOP = 0x103,
|
||||
MODEM_EVENT_UNKNOWN = 0x104,
|
||||
} esp_modem_compat_event_t;
|
||||
|
||||
/**
|
||||
* @brief PPPoS Client IP Information backward compatible version
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
ip4_addr_t ip; /*!< IP Address */
|
||||
ip4_addr_t netmask; /*!< Net Mask */
|
||||
ip4_addr_t gw; /*!< Gateway */
|
||||
ip4_addr_t ns1; /*!< Name Server1 */
|
||||
ip4_addr_t ns2; /*!< Name Server2 */
|
||||
} ppp_client_ip_info_t;
|
||||
|
||||
/**
|
||||
* @brief Backward compatible version of esp_modem_set_event_handler()
|
||||
*/
|
||||
esp_err_t esp_modem_add_event_handler(modem_dte_t *dte, esp_event_handler_t handler, void *handler_args) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Backward compatible version of creating esp-netif(PPP) and attaching to esp_modem_start_ppp()
|
||||
*/
|
||||
esp_err_t esp_modem_setup_ppp(modem_dte_t *dte) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Backward compatible version of deleting esp-netif and esp_modem_stop_ppp()
|
||||
*/
|
||||
esp_err_t esp_modem_exit_ppp(modem_dte_t *dte) __attribute__ ((deprecated));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
||||
// 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.
|
||||
@ -19,81 +19,218 @@ extern "C" {
|
||||
|
||||
#include "esp_types.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_modem.h"
|
||||
#include "esp_modem_dte.h"
|
||||
|
||||
typedef struct modem_dce modem_dce_t;
|
||||
typedef struct modem_dte modem_dte_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Result Code from DCE
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
#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 Length Constraint
|
||||
*
|
||||
*/
|
||||
#define MODEM_MAX_NAME_LENGTH (32) /*!< Max Module Name Length */
|
||||
#define MODEM_MAX_OPERATOR_LENGTH (32) /*!< Max Operator Name Length */
|
||||
#define MODEM_IMEI_LENGTH (15) /*!< IMEI Number Length */
|
||||
#define MODEM_IMSI_LENGTH (15) /*!< IMSI Number Length */
|
||||
|
||||
/**
|
||||
* @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_MODE_CHANGE (5000) /*!< Timeout value for changing working mode */
|
||||
#define MODEM_COMMAND_TIMEOUT_HANG_UP (90000) /*!< Timeout value for hang up */
|
||||
#define MODEM_COMMAND_TIMEOUT_POWEROFF (1000) /*!< Timeout value for power down */
|
||||
struct esp_modem_dce_cmd_list;
|
||||
|
||||
/**
|
||||
* @brief Working state of DCE
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
MODEM_STATE_PROCESSING, /*!< In processing */
|
||||
MODEM_STATE_SUCCESS, /*!< Process successfully */
|
||||
MODEM_STATE_FAIL /*!< Process failed */
|
||||
} modem_state_t;
|
||||
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 modem_dce {
|
||||
char imei[MODEM_IMEI_LENGTH + 1]; /*!< IMEI number */
|
||||
char imsi[MODEM_IMSI_LENGTH + 1]; /*!< IMSI number */
|
||||
char name[MODEM_MAX_NAME_LENGTH]; /*!< Module name */
|
||||
char oper[MODEM_MAX_OPERATOR_LENGTH]; /*!< Operator name */
|
||||
modem_state_t state; /*!< Modem working state */
|
||||
modem_mode_t mode; /*!< Working mode */
|
||||
modem_dte_t *dte; /*!< DTE which connect to DCE */
|
||||
esp_err_t (*handle_line)(modem_dce_t *dce, const char *line); /*!< Handle line strategy */
|
||||
esp_err_t (*sync)(modem_dce_t *dce); /*!< Synchronization */
|
||||
esp_err_t (*echo_mode)(modem_dce_t *dce, bool on); /*!< Echo command on or off */
|
||||
esp_err_t (*store_profile)(modem_dce_t *dce); /*!< Store user settings */
|
||||
esp_err_t (*set_flow_ctrl)(modem_dce_t *dce, modem_flow_ctrl_t flow_ctrl); /*!< Flow control on or off */
|
||||
esp_err_t (*get_signal_quality)(modem_dce_t *dce, uint32_t *rssi, uint32_t *ber); /*!< Get signal quality */
|
||||
esp_err_t (*get_battery_status)(modem_dce_t *dce, uint32_t *bcs,
|
||||
uint32_t *bcl, uint32_t *voltage); /*!< Get battery status */
|
||||
esp_err_t (*define_pdp_context)(modem_dce_t *dce, uint32_t cid,
|
||||
const char *type, const char *apn); /*!< Set PDP Contex */
|
||||
esp_err_t (*set_working_mode)(modem_dce_t *dce, modem_mode_t mode); /*!< Set working mode */
|
||||
esp_err_t (*hang_up)(modem_dce_t *dce); /*!< Hang up */
|
||||
esp_err_t (*power_down)(modem_dce_t *dce); /*!< Normal power down */
|
||||
esp_err_t (*deinit)(modem_dce_t *dce); /*!< Deinitialize */
|
||||
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
|
||||
|
359
esp_modem/include/esp_modem_dce_common_commands.h
Normal file
359
esp_modem/include/esp_modem_dce_common_commands.h
Normal file
@ -0,0 +1,359 @@
|
||||
// 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);
|
@ -1,131 +0,0 @@
|
||||
// Copyright 2015-2018 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 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
|
||||
*/
|
||||
static inline esp_err_t esp_modem_process_command_done(modem_dce_t *dce, modem_state_t state)
|
||||
{
|
||||
dce->state = state;
|
||||
return dce->dte->process_cmd_done(dce->dte);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 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(modem_dce_t *dce, const char *line);
|
||||
|
||||
/**
|
||||
* @brief Syncronization
|
||||
*
|
||||
* @param dce Modem DCE object
|
||||
* @return esp_err_t
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_dce_sync(modem_dce_t *dce);
|
||||
|
||||
/**
|
||||
* @brief Enable or not echo mode of DCE
|
||||
*
|
||||
* @param dce Modem DCE object
|
||||
* @param on true to enable echo mode, false to disable echo mode
|
||||
* @return esp_err_t
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_dce_echo(modem_dce_t *dce, bool on);
|
||||
|
||||
/**
|
||||
* @brief Store current parameter setting in the user profile
|
||||
*
|
||||
* @param dce Modem DCE object
|
||||
* @return esp_err_t
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_dce_store_profile(modem_dce_t *dce);
|
||||
|
||||
/**
|
||||
* @brief Set flow control mode of DCE in data mode
|
||||
*
|
||||
* @param dce Modem DCE object
|
||||
* @param flow_ctrl flow control mode
|
||||
* @return esp_err_t
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_dce_set_flow_ctrl(modem_dce_t *dce, modem_flow_ctrl_t flow_ctrl);
|
||||
|
||||
/**
|
||||
* @brief Define PDP context
|
||||
*
|
||||
* @param dce Modem DCE object
|
||||
* @param cid PDP context identifier
|
||||
* @param type Protocol type
|
||||
* @param apn Access point name
|
||||
* @return esp_err_t
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_dce_define_pdp_context(modem_dce_t *dce, uint32_t cid, const char *type, const char *apn);
|
||||
|
||||
/**
|
||||
* @brief Hang up
|
||||
*
|
||||
* @param dce Modem DCE object
|
||||
* @return esp_err_t
|
||||
* - ESP_OK on success
|
||||
* - ESP_FAIL on error
|
||||
*/
|
||||
esp_err_t esp_modem_dce_hang_up(modem_dce_t *dce);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
// 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.
|
||||
@ -21,46 +21,81 @@ extern "C" {
|
||||
#include "esp_err.h"
|
||||
#include "esp_event.h"
|
||||
|
||||
typedef struct modem_dte modem_dte_t;
|
||||
typedef struct modem_dce modem_dce_t;
|
||||
|
||||
/**
|
||||
* @brief Working mode of Modem
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
MODEM_COMMAND_MODE = 0, /*!< Command Mode */
|
||||
MODEM_PPP_MODE, /*!< PPP Mode */
|
||||
MODEM_TRANSITION_MODE /*!< Transition Mode betwen data and command mode indicating that
|
||||
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 */
|
||||
} modem_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Modem flow control type
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
MODEM_FLOW_CONTROL_NONE = 0,
|
||||
MODEM_FLOW_CONTROL_SW,
|
||||
MODEM_FLOW_CONTROL_HW
|
||||
} modem_flow_ctrl_t;
|
||||
} esp_modem_mode_t;
|
||||
|
||||
/**
|
||||
* @brief DTE(Data Terminal Equipment)
|
||||
*
|
||||
*/
|
||||
struct modem_dte {
|
||||
modem_flow_ctrl_t flow_ctrl; /*!< Flow control of DTE */
|
||||
modem_dce_t *dce; /*!< DCE which connected to the DTE */
|
||||
esp_err_t (*send_cmd)(modem_dte_t *dte, const char *command, uint32_t timeout); /*!< Send command to DCE */
|
||||
int (*send_data)(modem_dte_t *dte, const char *data, uint32_t length); /*!< Send data to DCE */
|
||||
esp_err_t (*send_wait)(modem_dte_t *dte, const char *data, uint32_t length,
|
||||
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)(modem_dte_t *dte, modem_mode_t new_mode); /*!< Changing working mode */
|
||||
esp_err_t (*process_cmd_done)(modem_dte_t *dte); /*!< Callback when DCE process command done */
|
||||
esp_err_t (*deinit)(modem_dte_t *dte); /*!< Deinitialize */
|
||||
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
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
||||
// 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.
|
||||
@ -17,6 +17,21 @@
|
||||
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
|
||||
*
|
||||
@ -24,21 +39,22 @@ extern "C" {
|
||||
*
|
||||
* @return opaque pointer to esp-modem IO driver used to attach to esp-netif
|
||||
*/
|
||||
void *esp_modem_netif_setup(modem_dte_t *dte);
|
||||
esp_modem_netif_driver_t *esp_modem_netif_new(esp_modem_dte_t *dte);
|
||||
|
||||
/**
|
||||
* @brief Destroys the esp-netif driver handle
|
||||
* @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_teardown(void *h);
|
||||
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(void *h);
|
||||
esp_err_t esp_modem_netif_clear_default_handlers(esp_modem_netif_driver_t *h);
|
||||
|
||||
/**
|
||||
* @brief Setups default handlers for esp-modem lifecycle
|
||||
@ -46,7 +62,41 @@ esp_err_t esp_modem_netif_clear_default_handlers(void *h);
|
||||
* @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(void *h, esp_netif_t * esp_netif);
|
||||
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
|
||||
}
|
||||
|
89
esp_modem/include/esp_modem_recov_helper.h
Normal file
89
esp_modem/include/esp_modem_recov_helper.h
Normal file
@ -0,0 +1,89 @@
|
||||
// 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);
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
// Copyright 2015-2018 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_service.h"
|
||||
#include "esp_modem.h"
|
||||
|
||||
/**
|
||||
* @brief Create and initialize SIM7600 object
|
||||
*
|
||||
* @param dte Modem DTE object
|
||||
* @return modem_dce_t* Modem DCE object
|
||||
*/
|
||||
modem_dce_t *sim7600_init(modem_dte_t *dte);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -1,33 +0,0 @@
|
||||
// Copyright 2015-2018 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_service.h"
|
||||
#include "esp_modem.h"
|
||||
|
||||
/**
|
||||
* @brief Create and initialize SIM800 object
|
||||
*
|
||||
* @param dte Modem DTE object
|
||||
* @return modem_dce_t* Modem DCE object
|
||||
*/
|
||||
modem_dce_t *sim800_init(modem_dte_t *dte);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user