1 // Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #pragma once 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #include "esp_types.h" 21 #include "esp_err.h" 22 #include "esp_modem_dte.h" 23 24 typedef struct modem_dce modem_dce_t; 25 typedef struct modem_dte modem_dte_t; 26 typedef struct esp_modem_dce esp_modem_dce_t; 27 28 /** 29 * @brief Result Code from DCE 30 * 31 */ 32 #define MODEM_RESULT_CODE_SUCCESS "OK" /*!< Acknowledges execution of a command */ 33 #define MODEM_RESULT_CODE_CONNECT "CONNECT" /*!< A connection has been established */ 34 #define MODEM_RESULT_CODE_RING "RING" /*!< Detect an incoming call signal from network */ 35 #define MODEM_RESULT_CODE_NO_CARRIER "NO CARRIER" /*!< Connection termincated or establish a connection failed */ 36 #define MODEM_RESULT_CODE_ERROR "ERROR" /*!< Command not recognized, command line maximum length exceeded, parameter value invalid */ 37 #define MODEM_RESULT_CODE_NO_DIALTONE "NO DIALTONE" /*!< No dial tone detected */ 38 #define MODEM_RESULT_CODE_BUSY "BUSY" /*!< Engaged signal detected */ 39 #define MODEM_RESULT_CODE_NO_ANSWER "NO ANSWER" /*!< Wait for quiet answer */ 40 41 /** 42 * @brief Specific Length Constraint 43 * 44 */ 45 #define MODEM_MAX_NAME_LENGTH (32) /*!< Max Module Name Length */ 46 #define MODEM_MAX_OPERATOR_LENGTH (32) /*!< Max Operator Name Length */ 47 #define MODEM_IMEI_LENGTH (15) /*!< IMEI Number Length */ 48 #define MODEM_IMSI_LENGTH (15) /*!< IMSI Number Length */ 49 50 /** 51 * @brief Specific Timeout Constraint, Unit: millisecond 52 * 53 */ 54 #define MODEM_COMMAND_TIMEOUT_DEFAULT (500) /*!< Default timeout value for most commands */ 55 #define MODEM_COMMAND_TIMEOUT_OPERATOR (75000) /*!< Timeout value for getting operator status */ 56 #define MODEM_COMMAND_TIMEOUT_MODE_CHANGE (5000) /*!< Timeout value for changing working mode */ 57 #define MODEM_COMMAND_TIMEOUT_HANG_UP (90000) /*!< Timeout value for hang up */ 58 #define MODEM_COMMAND_TIMEOUT_POWEROFF (1000) /*!< Timeout value for power down */ 59 60 /** 61 * @brief Working state of DCE 62 * 63 */ 64 typedef enum { 65 MODEM_STATE_PROCESSING, /*!< In processing */ 66 MODEM_STATE_SUCCESS, /*!< Process successfully */ 67 MODEM_STATE_FAIL /*!< Process failed */ 68 } modem_state_t; 69 70 /** 71 * @brief DCE(Data Communication Equipment) 72 * 73 */ 74 struct modem_dce { 75 char imei[MODEM_IMEI_LENGTH + 1]; /*!< IMEI number */ 76 char imsi[MODEM_IMSI_LENGTH + 1]; /*!< IMSI number */ 77 char name[MODEM_MAX_NAME_LENGTH]; /*!< Module name */ 78 char oper[MODEM_MAX_OPERATOR_LENGTH]; /*!< Operator name */ 79 uint8_t act; /*!< Access technology */ 80 const char *prompt; /*!< Modem prompt string */ 81 modem_state_t state; /*!< Modem working state */ 82 modem_mode_t mode; /*!< Working mode */ 83 modem_dte_t *dte; /*!< DTE which connect to DCE */ 84 esp_err_t (*handle_line)(modem_dce_t *dce, const char *line); /*!< Handle line strategy */ 85 esp_err_t (*sync)(modem_dce_t *dce); /*!< Synchronization */ 86 esp_err_t (*echo_mode)(modem_dce_t *dce, bool on); /*!< Echo command on or off */ 87 esp_err_t (*store_profile)(modem_dce_t *dce); /*!< Store user settings */ 88 esp_err_t (*set_flow_ctrl)(modem_dce_t *dce, modem_flow_ctrl_t flow_ctrl); /*!< Flow control on or off */ 89 esp_err_t (*get_signal_quality)(modem_dce_t *dce, uint32_t *rssi, uint32_t *ber); /*!< Get signal quality */ 90 esp_err_t (*get_battery_status)(modem_dce_t *dce, uint32_t *bcs, 91 uint32_t *bcl, uint32_t *voltage); /*!< Get battery status */ 92 esp_err_t (*get_operator_name)(modem_dce_t *dce); /*!< Get operator name */ 93 esp_err_t (*define_pdp_context)(modem_dce_t *dce, uint32_t cid, 94 const char *type, const char *apn); /*!< Set PDP Contex */ 95 esp_err_t (*set_working_mode)(modem_dce_t *dce, modem_mode_t mode); /*!< Set working mode */ 96 esp_err_t (*hang_up)(modem_dce_t *dce); /*!< Hang up */ 97 esp_err_t (*power_down)(modem_dce_t *dce); /*!< Normal power down */ 98 esp_err_t (*deinit)(modem_dce_t *dce); /*!< Deinitialize */ 99 }; 100 101 /** 102 * @brief ESP Modem with private resource 103 * 104 */ 105 struct esp_modem_dce { 106 void *priv_resource; /*!< Private resource */ 107 modem_dce_t parent; /*!< DCE parent class */ 108 }; 109 110 #ifdef __cplusplus 111 } 112 #endif 113