esp_modem_dce.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "esp_types.h"
  19. #include "esp_err.h"
  20. #include "esp_modem_dte.h"
  21. typedef struct modem_dce modem_dce_t;
  22. typedef struct modem_dte modem_dte_t;
  23. /**
  24. * @brief Result Code from DCE
  25. *
  26. */
  27. #define MODEM_RESULT_CODE_SUCCESS "OK" /*!< Acknowledges execution of a command */
  28. #define MODEM_RESULT_CODE_CONNECT "CONNECT" /*!< A connection has been established */
  29. #define MODEM_RESULT_CODE_RING "RING" /*!< Detect an incoming call signal from network */
  30. #define MODEM_RESULT_CODE_NO_CARRIER "NO CARRIER" /*!< Connection termincated or establish a connection failed */
  31. #define MODEM_RESULT_CODE_ERROR "ERROR" /*!< Command not recognized, command line maximum length exceeded, parameter value invalid */
  32. #define MODEM_RESULT_CODE_NO_DIALTONE "NO DIALTONE" /*!< No dial tone detected */
  33. #define MODEM_RESULT_CODE_BUSY "BUSY" /*!< Engaged signal detected */
  34. #define MODEM_RESULT_CODE_NO_ANSWER "NO ANSWER" /*!< Wait for quiet answer */
  35. /**
  36. * @brief Specific Length Constraint
  37. *
  38. */
  39. #define MODEM_MAX_NAME_LENGTH (32) /*!< Max Module Name Length */
  40. #define MODEM_MAX_OPERATOR_LENGTH (32) /*!< Max Operator Name Length */
  41. #define MODEM_IMEI_LENGTH (15) /*!< IMEI Number Length */
  42. #define MODEM_IMSI_LENGTH (15) /*!< IMSI Number Length */
  43. /**
  44. * @brief Specific Timeout Constraint, Unit: millisecond
  45. *
  46. */
  47. #define MODEM_COMMAND_TIMEOUT_DEFAULT (500) /*!< Default timeout value for most commands */
  48. #define MODEM_COMMAND_TIMEOUT_OPERATOR (75000) /*!< Timeout value for getting operator status */
  49. #define MODEM_COMMAND_TIMEOUT_MODE_CHANGE (5000) /*!< Timeout value for changing working mode */
  50. #define MODEM_COMMAND_TIMEOUT_HANG_UP (90000) /*!< Timeout value for hang up */
  51. #define MODEM_COMMAND_TIMEOUT_POWEROFF (1000) /*!< Timeout value for power down */
  52. /**
  53. * @brief Working state of DCE
  54. *
  55. */
  56. typedef enum {
  57. MODEM_STATE_PROCESSING, /*!< In processing */
  58. MODEM_STATE_SUCCESS, /*!< Process successfully */
  59. MODEM_STATE_FAIL /*!< Process failed */
  60. } modem_state_t;
  61. /**
  62. * @brief DCE(Data Communication Equipment)
  63. *
  64. */
  65. struct modem_dce {
  66. char imei[MODEM_IMEI_LENGTH + 1]; /*!< IMEI number */
  67. char imsi[MODEM_IMSI_LENGTH + 1]; /*!< IMSI number */
  68. char name[MODEM_MAX_NAME_LENGTH]; /*!< Module name */
  69. char oper[MODEM_MAX_OPERATOR_LENGTH]; /*!< Operator name */
  70. modem_state_t state; /*!< Modem working state */
  71. modem_mode_t mode; /*!< Working mode */
  72. modem_dte_t *dte; /*!< DTE which connect to DCE */
  73. esp_err_t (*handle_line)(modem_dce_t *dce, const char *line); /*!< Handle line strategy */
  74. esp_err_t (*sync)(modem_dce_t *dce); /*!< Synchronization */
  75. esp_err_t (*echo_mode)(modem_dce_t *dce, bool on); /*!< Echo command on or off */
  76. esp_err_t (*store_profile)(modem_dce_t *dce); /*!< Store user settings */
  77. esp_err_t (*set_flow_ctrl)(modem_dce_t *dce, modem_flow_ctrl_t flow_ctrl); /*!< Flow control on or off */
  78. esp_err_t (*get_signal_quality)(modem_dce_t *dce, uint32_t *rssi, uint32_t *ber); /*!< Get signal quality */
  79. esp_err_t (*get_battery_status)(modem_dce_t *dce, uint32_t *bcs,
  80. uint32_t *bcl, uint32_t *voltage); /*!< Get battery status */
  81. esp_err_t (*define_pdp_context)(modem_dce_t *dce, uint32_t cid,
  82. const char *type, const char *apn); /*!< Set PDP Contex */
  83. esp_err_t (*set_working_mode)(modem_dce_t *dce, modem_mode_t mode); /*!< Set working mode */
  84. esp_err_t (*hang_up)(modem_dce_t *dce); /*!< Hang up */
  85. esp_err_t (*power_down)(modem_dce_t *dce); /*!< Normal power down */
  86. esp_err_t (*deinit)(modem_dce_t *dce); /*!< Deinitialize */
  87. };
  88. #ifdef __cplusplus
  89. }
  90. #endif