|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#pragma once |
| 8 | + |
| 9 | +#include "esp_err.h" |
| 10 | +//#include "generate/esp_modem_command_declare.inc" |
| 11 | +#include "esp_modem_c_api_types.h" |
| 12 | + |
| 13 | +#ifdef __cplusplus |
| 14 | +extern "C" { |
| 15 | +#endif |
| 16 | + |
| 17 | +// --- ESP-MODEM command module starts here --- |
| 18 | + |
| 19 | +// |
| 20 | +//#define INT_IN(name) int name |
| 21 | +//#ifdef __cplusplus |
| 22 | +//#define STRING_IN(name) const std::string& name |
| 23 | +//#define STRING_OUT(name) std::string& name |
| 24 | +//#define BOOL_IN(name) const bool name |
| 25 | +//#define BOOL_OUT(name) bool& name |
| 26 | +//#define INT_OUT(name) int& name |
| 27 | +//#define INTEGER_LIST_IN(name) const int* name |
| 28 | +//#define STRUCT_OUT(struct_name, name) struct_name& name |
| 29 | +//#else |
| 30 | +//#define STRING_IN(name) const char* name |
| 31 | +//#define STRING_OUT(name) char* name |
| 32 | +//#define BOOL_IN(name) const bool name |
| 33 | +//#define BOOL_OUT(name) bool* name |
| 34 | +//#define INT_OUT(name) int* name |
| 35 | +//#define INTEGER_LIST_IN(name) const int* name |
| 36 | +//#define STRUCT_OUT(struct_name, name) esp_modem_ ## struct_name ## _t* name |
| 37 | +//#endif |
| 38 | +// |
| 39 | +//#define FORWARD_INT_IN(name) name |
| 40 | +//#define FORWARD_STRING_IN(name) name |
| 41 | +//#define FORWARD_STRING_OUT(name) name |
| 42 | +//#define FORWARD_BOOL_IN(name) name |
| 43 | +//#define FORWARD_BOOL_OUT(name) name |
| 44 | +//#define FORWARD_INT_OUT(name) name |
| 45 | +//#define FORWARD_INTEGER_LIST_IN(name) name |
| 46 | +//#define FORWARD_STRUCT_OUT(struct_name, name) name |
| 47 | + |
| 48 | +// Utility to count arguments (works for up to two parameters here) |
| 49 | +//#define STRING_IN(name) const char* name |
| 50 | +//#define STRING_OUT(name) char* name |
| 51 | +//#define BOOL_IN(name) const bool name |
| 52 | +//#define BOOL_OUT(name) bool* name |
| 53 | +//#define INT_OUT(name) int* name |
| 54 | +//#define INTEGER_LIST_IN(name) const int* name |
| 55 | +//#define STRUCT_OUT(struct_name, name) esp_modem_ ## struct_name ## _t* name |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +/** |
| 61 | + * @brief Sends the initial AT sequence to sync up with the device |
| 62 | + * @return OK, FAIL or TIMEOUT |
| 63 | + */ |
| 64 | +esp_err_t esp_modem_sync(esp_modem_dce_t *dce ); |
| 65 | + |
| 66 | +/** |
| 67 | + * @brief Reads the operator name |
| 68 | + * @param[out] name operator name |
| 69 | + * @param[out] act access technology |
| 70 | + * @return OK, FAIL or TIMEOUT |
| 71 | + */ |
| 72 | +esp_err_t esp_modem_get_operator_name(esp_modem_dce_t *dce, char *name, int *act ); |
| 73 | + |
| 74 | +/** |
| 75 | + * @brief Stores current user profile |
| 76 | + * @return OK, FAIL or TIMEOUT |
| 77 | + */ |
| 78 | +esp_err_t esp_modem_store_profile(esp_modem_dce_t *dce ); |
| 79 | + |
| 80 | +/** |
| 81 | + * @brief Sets the supplied PIN code |
| 82 | + * @param[in] pin Pin |
| 83 | + * @return OK, FAIL or TIMEOUT |
| 84 | + */ |
| 85 | +esp_err_t esp_modem_set_pin(esp_modem_dce_t *dce, const char *pin ); |
| 86 | + |
| 87 | +/** |
| 88 | + * @brief Execute the supplied AT command in raw mode (doesn't append '\r' to command, returns everything) |
| 89 | + * @param[in] cmd String command that's send to DTE |
| 90 | + * @param[out] out Raw output from DTE |
| 91 | + * @param[in] pass Pattern in response for the API to return OK |
| 92 | + * @param[in] fail Pattern in response for the API to return FAIL |
| 93 | + * @param[in] timeout AT command timeout in milliseconds |
| 94 | + * @return OK, FAIL or TIMEOUT |
| 95 | + */ |
| 96 | +esp_err_t esp_modem_at_raw(esp_modem_dce_t *dce, const char *cmd, char *out, const char *pass, const char *fail, int timeout ); |
| 97 | + |
| 98 | +/** |
| 99 | + * @brief Execute the supplied AT command |
| 100 | + * @param[in] cmd AT command |
| 101 | + * @param[out] out Command output string |
| 102 | + * @param[in] timeout AT command timeout in milliseconds |
| 103 | + * @return OK, FAIL or TIMEOUT |
| 104 | + */ |
| 105 | +esp_err_t esp_modem_at(esp_modem_dce_t *dce, const char *cmd, char *out, int timeout ); |
| 106 | + |
| 107 | +/** |
| 108 | + * @brief Checks if the SIM needs a PIN |
| 109 | + * @param[out] pin_ok true if the SIM card doesn't need a PIN to unlock |
| 110 | + * @return OK, FAIL or TIMEOUT |
| 111 | + */ |
| 112 | +esp_err_t esp_modem_read_pin(esp_modem_dce_t *dce, bool *pin_ok ); |
| 113 | + |
| 114 | +/** |
| 115 | + * @brief Sets echo mode |
| 116 | + * @param[in] echo_on true if echo mode on (repeats the commands) |
| 117 | + * @return OK, FAIL or TIMEOUT |
| 118 | + */ |
| 119 | +esp_err_t esp_modem_set_echo(esp_modem_dce_t *dce, const bool echo_on ); |
| 120 | + |
| 121 | +/** |
| 122 | + * @brief Sets the Txt or Pdu mode for SMS (only txt is supported) |
| 123 | + * @param[in] txt true if txt mode |
| 124 | + * @return OK, FAIL or TIMEOUT |
| 125 | + */ |
| 126 | +esp_err_t esp_modem_sms_txt_mode(esp_modem_dce_t *dce, const bool txt ); |
| 127 | + |
| 128 | +/** |
| 129 | + * @brief Sets the default (GSM) character set |
| 130 | + * @return OK, FAIL or TIMEOUT |
| 131 | + */ |
| 132 | +esp_err_t esp_modem_sms_character_set(esp_modem_dce_t *dce ); |
| 133 | + |
| 134 | +/** |
| 135 | + * @brief Sends SMS message in txt mode |
| 136 | + * @param[in] number Phone number to send the message to |
| 137 | + * @param[in] message Text message to be sent |
| 138 | + * @return OK, FAIL or TIMEOUT |
| 139 | + */ |
| 140 | +esp_err_t esp_modem_send_sms(esp_modem_dce_t *dce, const char *number, const char *message ); |
| 141 | + |
| 142 | +/** |
| 143 | + * @brief Resumes data mode (Switches back to the data mode, which was temporarily suspended) |
| 144 | + * @return OK, FAIL or TIMEOUT |
| 145 | + */ |
| 146 | +esp_err_t esp_modem_resume_data_mode(esp_modem_dce_t *dce ); |
| 147 | + |
| 148 | +/** |
| 149 | + * @brief Sets php context |
| 150 | + * @param[in] p1 PdP context struct to setup modem cellular connection |
| 151 | + * @return OK, FAIL or TIMEOUT |
| 152 | + */ |
| 153 | +esp_err_t esp_modem_set_pdp_context(esp_modem_dce_t *dce, esp_modem_PdpContext_t *pdp ); |
| 154 | + |
| 155 | +/** |
| 156 | + * @brief Switches to the command mode |
| 157 | + * @return OK, FAIL or TIMEOUT |
| 158 | + */ |
| 159 | +esp_err_t esp_modem_set_command_mode(esp_modem_dce_t *dce ); |
| 160 | + |
| 161 | +/** |
| 162 | + * @brief Switches to the CMUX mode |
| 163 | + * @return OK, FAIL or TIMEOUT |
| 164 | + */ |
| 165 | +esp_err_t esp_modem_set_cmux(esp_modem_dce_t *dce ); |
| 166 | + |
| 167 | +/** |
| 168 | + * @brief Reads the IMSI number |
| 169 | + * @param[out] imsi Module's IMSI number |
| 170 | + * @return OK, FAIL or TIMEOUT |
| 171 | + */ |
| 172 | +esp_err_t esp_modem_get_imsi(esp_modem_dce_t *dce, char *imsi ); |
| 173 | + |
| 174 | +/** |
| 175 | + * @brief Reads the IMEI number |
| 176 | + * @param[out] imei Module's IMEI number |
| 177 | + * @return OK, FAIL or TIMEOUT |
| 178 | + */ |
| 179 | +esp_err_t esp_modem_get_imei(esp_modem_dce_t *dce, char *imei ); |
| 180 | + |
| 181 | +/** |
| 182 | + * @brief Reads the module name |
| 183 | + * @param[out] name module name |
| 184 | + * @return OK, FAIL or TIMEOUT |
| 185 | + */ |
| 186 | +esp_err_t esp_modem_get_module_name(esp_modem_dce_t *dce, char *name ); |
| 187 | + |
| 188 | +/** |
| 189 | + * @brief Sets the modem to data mode |
| 190 | + * @return OK, FAIL or TIMEOUT |
| 191 | + */ |
| 192 | +esp_err_t esp_modem_set_data_mode(esp_modem_dce_t *dce ); |
| 193 | + |
| 194 | +/** |
| 195 | + * @brief Get Signal quality |
| 196 | + * @param[out] rssi signal strength indication |
| 197 | + * @param[out] ber channel bit error rate |
| 198 | + * @return OK, FAIL or TIMEOUT |
| 199 | + */ |
| 200 | +esp_err_t esp_modem_get_signal_quality(esp_modem_dce_t *dce, int *rssi, int *ber ); |
| 201 | + |
| 202 | +/** |
| 203 | + * @brief Sets HW control flow |
| 204 | + * @param[in] dce_flow 0=none, 2=RTS hw flow control of DCE |
| 205 | + * @param[in] dte_flow 0=none, 2=CTS hw flow control of DTE |
| 206 | + * @return OK, FAIL or TIMEOUT |
| 207 | + */ |
| 208 | +esp_err_t esp_modem_set_flow_control(esp_modem_dce_t *dce, int dce_flow, int dte_flow ); |
| 209 | + |
| 210 | +/** |
| 211 | + * @brief Hangs up current data call |
| 212 | + * @return OK, FAIL or TIMEOUT |
| 213 | + */ |
| 214 | +esp_err_t esp_modem_hang_up(esp_modem_dce_t *dce ); |
| 215 | + |
| 216 | +/** |
| 217 | + * @brief Get voltage levels of modem power up circuitry |
| 218 | + * @param[out] voltage Current status in mV |
| 219 | + * @param[out] bcs charge status (-1-Not available, 0-Not charging, 1-Charging, 2-Charging done) |
| 220 | + * @param[out] bcl 1-100% battery capacity, -1-Not available |
| 221 | + * @return OK, FAIL or TIMEOUT |
| 222 | + */ |
| 223 | +esp_err_t esp_modem_get_battery_status(esp_modem_dce_t *dce, int *voltage, int *bcs, int *bcl ); |
| 224 | + |
| 225 | +/** |
| 226 | + * @brief Power down the module |
| 227 | + * @return OK, FAIL or TIMEOUT |
| 228 | + */ |
| 229 | +esp_err_t esp_modem_power_down(esp_modem_dce_t *dce ); |
| 230 | + |
| 231 | +/** |
| 232 | + * @brief Reset the module |
| 233 | + * @return OK, FAIL or TIMEOUT |
| 234 | + */ |
| 235 | +esp_err_t esp_modem_reset(esp_modem_dce_t *dce ); |
| 236 | + |
| 237 | +/** |
| 238 | + * @brief Configures the baudrate |
| 239 | + * @param[in] baud Desired baud rate of the DTE |
| 240 | + * @return OK, FAIL or TIMEOUT |
| 241 | + */ |
| 242 | +esp_err_t esp_modem_set_baud(esp_modem_dce_t *dce, int baud ); |
| 243 | + |
| 244 | +/** |
| 245 | + * @brief Force an attempt to connect to a specific operator |
| 246 | + * @param[in] mode mode of attempt |
| 247 | + * mode=0 - automatic |
| 248 | + * mode=1 - manual |
| 249 | + * mode=2 - deregister |
| 250 | + * mode=3 - set format for read operation |
| 251 | + * mode=4 - manual with fallback to automatic |
| 252 | + * @param[in] format what format the operator is given in |
| 253 | + * format=0 - long format |
| 254 | + * format=1 - short format |
| 255 | + * format=2 - numeric |
| 256 | + * @param[in] oper the operator to connect to |
| 257 | + * @return OK, FAIL or TIMEOUT |
| 258 | + */ |
| 259 | +esp_err_t esp_modem_set_operator(esp_modem_dce_t *dce, int mode, int format, const char *oper ); |
| 260 | + |
| 261 | +/** |
| 262 | + * @brief Attach or detach from the GPRS service |
| 263 | + * @param[in] state 1-attach 0-detach |
| 264 | + * @return OK, FAIL or TIMEOUT |
| 265 | + */ |
| 266 | +esp_err_t esp_modem_set_network_attachment_state(esp_modem_dce_t *dce, int state ); |
| 267 | + |
| 268 | +/** |
| 269 | + * @brief Get network attachment state |
| 270 | + * @param[out] state 1-attached 0-detached |
| 271 | + * @return OK, FAIL or TIMEOUT |
| 272 | + */ |
| 273 | +esp_err_t esp_modem_get_network_attachment_state(esp_modem_dce_t *dce, int *state ); |
| 274 | + |
| 275 | +/** |
| 276 | + * @brief What mode the radio should be set to |
| 277 | + * @param[in] state state 1-full 0-minimum ... |
| 278 | + * @return OK, FAIL or TIMEOUT |
| 279 | + */ |
| 280 | +esp_err_t esp_modem_set_radio_state(esp_modem_dce_t *dce, int state ); |
| 281 | + |
| 282 | +/** |
| 283 | + * @brief Get current radio state |
| 284 | + * @param[out] state 1-full 0-minimum ... |
| 285 | + * @return OK, FAIL or TIMEOUT |
| 286 | + */ |
| 287 | +esp_err_t esp_modem_get_radio_state(esp_modem_dce_t *dce, int *state ); |
| 288 | + |
| 289 | +/** |
| 290 | + * @brief Set network mode |
| 291 | + * @param[in] mode preferred mode |
| 292 | + * @return OK, FAIL or TIMEOUT |
| 293 | + */ |
| 294 | +esp_err_t esp_modem_set_network_mode(esp_modem_dce_t *dce, int mode ); |
| 295 | + |
| 296 | +/** |
| 297 | + * @brief Preferred network mode (CAT-M and/or NB-IoT) |
| 298 | + * @param[in] mode preferred selection |
| 299 | + * @return OK, FAIL or TIMEOUT |
| 300 | + */ |
| 301 | +esp_err_t esp_modem_set_preferred_mode(esp_modem_dce_t *dce, int mode ); |
| 302 | + |
| 303 | +/** |
| 304 | + * @brief Set network bands for CAT-M or NB-IoT |
| 305 | + * @param[in] mode CAT-M or NB-IoT |
| 306 | + * @param[in] bands bitmap in hex representing bands |
| 307 | + * @param[in] size size of teh bands bitmap |
| 308 | + * @return OK, FAIL or TIMEOUT |
| 309 | + */ |
| 310 | +esp_err_t esp_modem_set_network_bands(esp_modem_dce_t *dce, const char *mode, const int *bands, int size ); |
| 311 | + |
| 312 | +/** |
| 313 | + * @brief Show network system mode |
| 314 | + * @param[out] mode current network mode |
| 315 | + * @return OK, FAIL or TIMEOUT |
| 316 | + */ |
| 317 | +esp_err_t esp_modem_get_network_system_mode(esp_modem_dce_t *dce, int *mode ); |
| 318 | + |
| 319 | +/** |
| 320 | + * @brief GNSS power control |
| 321 | + * @param[out] mode power mode (0 - off, 1 - on) |
| 322 | + * @return OK, FAIL or TIMEOUT |
| 323 | + */ |
| 324 | +esp_err_t esp_modem_set_gnss_power_mode(esp_modem_dce_t *dce, int mode ); |
| 325 | + |
| 326 | +/** |
| 327 | + * @brief GNSS power control |
| 328 | + * @param[out] mode power mode (0 - off, 1 - on) |
| 329 | + * @return OK, FAIL or TIMEOUT |
| 330 | + */ |
| 331 | +esp_err_t esp_modem_get_gnss_power_mode(esp_modem_dce_t *dce, int *mode ); |
| 332 | + |
| 333 | + |
| 334 | +// --- ESP-MODEM command module ends here --- |
| 335 | + |
| 336 | +#ifdef __cplusplus |
| 337 | +} |
| 338 | +#endif |
0 commit comments