esp_ping.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef ESP_PING_H_
  14. #define ESP_PING_H_
  15. #include "esp_err.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. // gen_esp_err_to_name.py: include this as "esp_ping.h" because "components/lwip/include/apps/" is in the compiler path
  20. // and not "components/lwip/include"
  21. #define ESP_ERR_PING_BASE 0xa000
  22. #define ESP_ERR_PING_INVALID_PARAMS ESP_ERR_PING_BASE + 0x01
  23. #define ESP_ERR_PING_NO_MEM ESP_ERR_PING_BASE + 0x02
  24. #define ESP_PING_CHECK_OPTLEN(optlen, opttype) do { if ((optlen) < sizeof(opttype)) { return ESP_ERR_PING_INVALID_PARAMS; }}while(0)
  25. typedef struct _ping_found {
  26. uint32_t resp_time;
  27. uint32_t timeout_count;
  28. uint32_t send_count;
  29. uint32_t recv_count;
  30. uint32_t err_count;
  31. uint32_t bytes;
  32. uint32_t total_bytes;
  33. uint32_t total_time;
  34. uint32_t min_time;
  35. uint32_t max_time;
  36. int8_t ping_err;
  37. } esp_ping_found;
  38. typedef enum {
  39. PING_TARGET_IP_ADDRESS = 50, /**< target IP address */
  40. PING_TARGET_IP_ADDRESS_COUNT = 51, /**< target IP address total counter */
  41. PING_TARGET_RCV_TIMEO = 52, /**< receive timeout in milliseconds */
  42. PING_TARGET_DELAY_TIME = 53, /**< delay time in milliseconds */
  43. PING_TARGET_ID = 54, /**< identifier */
  44. PING_TARGET_RES_FN = 55, /**< ping result callback function */
  45. PING_TARGET_RES_RESET = 56, /**< ping result statistic reset */
  46. PING_TARGET_DATA_LEN = 57, /**< ping data length*/
  47. PING_TARGET_IP_TOS = 58, /**< ping QOS*/
  48. PING_TARGET_IF_INDEX = 59 /**< ping if index*/
  49. } ping_target_id_t;
  50. typedef enum {
  51. PING_RES_TIMEOUT = 0,
  52. PING_RES_OK = 1,
  53. PING_RES_FINISH = 2,
  54. } ping_res_t;
  55. typedef void (* esp_ping_found_fn)(ping_target_id_t found_id, esp_ping_found *found_val);
  56. /**
  57. * @brief Set PING function option
  58. *
  59. * @param[in] opt_id: option index, 50 for IP, 51 for COUNT, 52 for RCV TIMEOUT, 53 for DELAY TIME, 54 for ID
  60. * @param[in] opt_val: option parameter
  61. * @param[in] opt_len: option length
  62. *
  63. * @return
  64. * - ESP_OK
  65. * - ESP_ERR_PING_INVALID_PARAMS
  66. */
  67. esp_err_t esp_ping_set_target(ping_target_id_t opt_id, void *opt_val, uint32_t opt_len);
  68. /**
  69. * @brief Get PING function option
  70. *
  71. * @param[in] opt_id: option index, 50 for IP, 51 for COUNT, 52 for RCV TIMEOUT, 53 for DELAY TIME, 54 for ID
  72. * @param[in] opt_val: option parameter
  73. * @param[in] opt_len: option length
  74. *
  75. * @return
  76. * - ESP_OK
  77. * - ESP_ERR_PING_INVALID_PARAMS
  78. */
  79. esp_err_t esp_ping_get_target(ping_target_id_t opt_id, void *opt_val, uint32_t opt_len);
  80. /**
  81. * @brief Get PING function result action
  82. *
  83. * @param[in] res_val: ping function action, 1 for successful, 0 for fail.
  84. * res_len: response bytes
  85. * res_time: response time
  86. *
  87. * @return
  88. * - ESP_OK
  89. * - ESP_ERR_PING_INVALID_PARAMS
  90. */
  91. esp_err_t esp_ping_result(uint8_t res_val, uint16_t res_len, uint32_t res_time);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* ESP_PING_H_ */