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_modem_dce.h"
21 
22 /**
23  * @brief Indicate that processing current command has done
24  *
25  * @param dce Modem DCE object
26  * @param state Modem state after processing
27  * @return esp_err_t
28  *      - ESP_OK on success
29  *      - ESP_FAIL on error
30  */
esp_modem_process_command_done(modem_dce_t * dce,modem_state_t state)31 static inline esp_err_t esp_modem_process_command_done(modem_dce_t *dce, modem_state_t state)
32 {
33     dce->state = state;
34     return dce->dte->process_cmd_done(dce->dte);
35 }
36 
37 /**
38  * @brief Strip the tailed "\r\n"
39  *
40  * @param str string to strip
41  * @param len length of string
42  */
strip_cr_lf_tail(char * str,uint32_t len)43 static inline void strip_cr_lf_tail(char *str, uint32_t len)
44 {
45     if (str[len - 2] == '\r') {
46         str[len - 2] = '\0';
47     } else if (str[len - 1] == '\r') {
48         str[len - 1] = '\0';
49     }
50 }
51 
52 /**
53  * @brief Default handler for response
54  * Some responses for command are simple, commonly will return OK when succeed of ERROR when failed
55  *
56  * @param dce Modem DCE object
57  * @param line line string
58  * @return esp_err_t
59  *      - ESP_OK on success
60  *      - ESP_FAIL on error
61  */
62 esp_err_t esp_modem_dce_handle_response_default(modem_dce_t *dce, const char *line);
63 
64 /**
65  * @brief Handle response from +++ (Set Working Mode)
66  *
67  * @param dce Modem DCE object
68  * @param line line string
69  * @return esp_err_t
70  *      - ESP_OK on success
71  *      - ESP_FAIL on error
72  */
73 esp_err_t esp_modem_dce_handle_exit_data_mode(modem_dce_t *dce, const char *line);
74 
75 /**
76  * @brief Handle response from ATD*99# (Set Working Mode)
77  *
78  * @param dce Modem DCE object
79  * @param line line string
80  * @return esp_err_t
81  *      - ESP_OK on success
82  *      - ESP_FAIL on error
83  */
84 esp_err_t esp_modem_dce_handle_atd_ppp(modem_dce_t *dce, const char *line);
85 
86 /**
87  * @brief Syncronization
88  *
89  * @param dce Modem DCE object
90  * @return esp_err_t
91  *      - ESP_OK on success
92  *      - ESP_FAIL on error
93  */
94 esp_err_t esp_modem_dce_sync(modem_dce_t *dce);
95 
96 /**
97  * @brief Enable or not echo mode of DCE (V.25TER specification)
98  *
99  * @param dce Modem DCE object
100  * @param on true to enable echo mode, false to disable echo mode
101  * @return esp_err_t
102  *      - ESP_OK on success
103  *      - ESP_FAIL on error
104  */
105 esp_err_t esp_modem_dce_echo(modem_dce_t *dce, bool on);
106 
107 /**
108  * @brief Store current parameter setting in the user profile
109  *
110  * @param dce Modem DCE object
111  * @return esp_err_t
112  *      - ESP_OK on success
113  *      - ESP_FAIL on error
114  */
115 esp_err_t esp_modem_dce_store_profile(modem_dce_t *dce);
116 
117 /**
118  * @brief Set flow control mode of DCE in data mode (V.25TER specification)
119  *
120  * @param dce Modem DCE object
121  * @param flow_ctrl flow control mode
122  * @return esp_err_t
123  *      - ESP_OK on success
124  *      - ESP_FAIL on error
125  */
126 esp_err_t esp_modem_dce_set_flow_ctrl(modem_dce_t *dce, modem_flow_ctrl_t flow_ctrl);
127 
128 /**
129  * @brief Define PDP context (GPRS)
130  *
131  * @param dce Modem DCE object
132  * @param cid PDP context identifier
133  * @param type Protocol type
134  * @param apn Access point name
135  * @return esp_err_t
136  *      - ESP_OK on success
137  *      - ESP_FAIL on error
138  */
139 esp_err_t esp_modem_dce_define_pdp_context(modem_dce_t *dce, uint32_t cid, const char *type, const char *apn);
140 
141 /**
142  * @brief Get signal quality (3GPP TS 27.007 specification)
143  *
144  * @param dce Modem DCE object
145  * @param rssi received signal strength indication
146  * @param ber bit error ratio
147  * @return esp_err_t
148  *      - ESP_OK on success
149  *      - ESP_FAIL on error
150  */
151 esp_err_t esp_modem_dce_get_signal_quality(modem_dce_t *dce, uint32_t *rssi, uint32_t *ber);
152 
153 /**
154  * @brief Get battery status (3GPP TS 27.007 specification)
155  *
156  * @param dce Modem DCE object
157  * @param bcs Battery charge status
158  * @param bcl Battery connection level
159  * @param voltage Battery voltage
160  * @return esp_err_t
161  *      - ESP_OK on success
162  *      - ESP_FAIL on error
163  */
164 esp_err_t esp_modem_dce_get_battery_status(modem_dce_t *dce, uint32_t *bcs, uint32_t *bcl, uint32_t *voltage);
165 
166 /**
167  * @brief Get DCE module name (3GPP TS 27.007 specification)
168  *
169  * @param dce Modem DCE object
170  * @return esp_err_t
171  *      - ESP_OK on success
172  *      - ESP_FAIL on error
173  */
174 esp_err_t esp_modem_dce_get_module_name(modem_dce_t *dce);
175 
176 /**
177  * @brief Get DCE module IMEI number (3GPP TS 27.007 specification)
178  *
179  * @param dce Modem DCE object
180  * @return esp_err_t
181  *      - ESP_OK on success
182  *      - ESP_FAIL on error
183  */
184 esp_err_t esp_modem_dce_get_imei_number(modem_dce_t *dce);
185 
186 /**
187  * @brief Get DCE module IMSI number (3GPP TS 27.007 specification)
188  *
189  * @param dce Modem DCE object
190  * @return esp_err_t
191  *      - ESP_OK on success
192  *      - ESP_FAIL on error
193  */
194 esp_err_t esp_modem_dce_get_imsi_number(modem_dce_t *dce);
195 
196 /**
197  * @brief Get Operator's name (3GPP TS 27.007 specification)
198  *
199  * @param dce Modem DCE object
200  * @return esp_err_t
201  *      - ESP_OK on success
202  *      - ESP_FAIL on error
203  */
204 esp_err_t esp_modem_dce_get_operator_name(modem_dce_t *dce);
205 
206 /**
207  * @brief Hang up (V.25TER specification)
208  *
209  * @param dce Modem DCE object
210  * @return esp_err_t
211  *      - ESP_OK on success
212  *      - ESP_FAIL on error
213  */
214 esp_err_t esp_modem_dce_hang_up(modem_dce_t *dce);
215 
216 #ifdef __cplusplus
217 }
218 #endif
219