at_device.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * File : at_device.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2019-05-08 chenyong first version
  23. */
  24. #ifndef __AT_DEVICE_H__
  25. #define __AT_DEVICE_H__
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #include <at.h>
  30. #include <at_socket.h>
  31. #if !defined(RT_USING_NETDEV) || (!defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10300)
  32. #error "This RT-Thread version is older, please check and updata laster RT-Thread!"
  33. #else
  34. #include <arpa/inet.h>
  35. #include <netdev.h>
  36. #endif /* RT_USING_NETDEV */
  37. #define AT_DEVICE_SW_VERSION "2.0.3"
  38. #define AT_DEVICE_SW_VERSION_NUM 0x20003
  39. /* AT device class ID */
  40. #define AT_DEVICE_CLASS_ESP8266 0x01U
  41. #define AT_DEVICE_CLASS_M26_MC20 0x02U
  42. #define AT_DEVICE_CLASS_EC20 0x03U
  43. #define AT_DEVICE_CLASS_SIM800C 0x04U
  44. #define AT_DEVICE_CLASS_SIM76XX 0x05U
  45. #define AT_DEVICE_CLASS_RW007 0x06U
  46. #define AT_DEVICE_CLASS_MW31 0x07U
  47. #define AT_DEVICE_CLASS_ESP32 0x08U
  48. #define AT_DEVICE_CLASS_W60X 0x09U
  49. #define AT_DEVICE_CLASS_A9G 0x0AU
  50. #define AT_DEVICE_CLASS_BC26 0x0BU
  51. #define AT_DEVICE_CLASS_AIR720 0x0CU
  52. #define AT_DEVICE_CLASS_ME3616 0x0DU
  53. #define AT_DEVICE_CLASS_M6315 0x0EU
  54. #define AT_DEVICE_CLASS_BC28 0x0FU
  55. #define AT_DEVICE_CLASS_EC200X 0x10U
  56. #define AT_DEVICE_CLASS_N21 0x11U
  57. #define AT_DEVICE_CLASS_N58 0x12U
  58. /* Options and Commands for AT device control opreations */
  59. #define AT_DEVICE_CTRL_POWER_ON 0x01L
  60. #define AT_DEVICE_CTRL_POWER_OFF 0x02L
  61. #define AT_DEVICE_CTRL_RESET 0x03L
  62. #define AT_DEVICE_CTRL_LOW_POWER 0x04L
  63. #define AT_DEVICE_CTRL_SLEEP 0x05L
  64. #define AT_DEVICE_CTRL_WAKEUP 0x06L
  65. #define AT_DEVICE_CTRL_NET_CONN 0x07L
  66. #define AT_DEVICE_CTRL_NET_DISCONN 0x08L
  67. #define AT_DEVICE_CTRL_SET_WIFI_INFO 0x09L
  68. #define AT_DEVICE_CTRL_GET_SIGNAL 0x0AL
  69. #define AT_DEVICE_CTRL_GET_GPS 0x0BL
  70. #define AT_DEVICE_CTRL_GET_VER 0x0CL
  71. /* Name type */
  72. #define AT_DEVICE_NAMETYPE_DEVICE 0x01
  73. #define AT_DEVICE_NAMETYPE_NETDEV 0x02
  74. #define AT_DEVICE_NAMETYPE_CLIENT 0x03
  75. struct at_device;
  76. /* AT device wifi ssid and password information */
  77. struct at_device_ssid_pwd
  78. {
  79. char *ssid;
  80. char *password;
  81. };
  82. /* AT device operations */
  83. struct at_device_ops
  84. {
  85. int (*init)(struct at_device *device);
  86. int (*deinit)(struct at_device *device);
  87. int (*control)(struct at_device *device, int cmd, void *arg);
  88. };
  89. struct at_device_class
  90. {
  91. uint16_t class_id; /* AT device class ID */
  92. const struct at_device_ops *device_ops; /* AT device operaiotns */
  93. #ifdef AT_USING_SOCKET
  94. uint32_t socket_num; /* The maximum number of sockets support */
  95. const struct at_socket_ops *socket_ops; /* AT device socket operations */
  96. #endif
  97. rt_slist_t list; /* AT device class list */
  98. };
  99. struct at_device
  100. {
  101. char name[RT_NAME_MAX]; /* AT device name */
  102. rt_bool_t is_init; /* AT device initialization completed */
  103. struct at_device_class *class; /* AT device class object */
  104. struct at_client *client; /* AT Client object for AT device */
  105. struct netdev *netdev; /* Network interface device for AT device */
  106. #ifdef AT_USING_SOCKET
  107. rt_event_t socket_event; /* AT device socket event */
  108. struct at_socket *sockets; /* AT device sockets list */
  109. #endif
  110. rt_slist_t list; /* AT device list */
  111. void *user_data; /* User-specific data */
  112. };
  113. /* Get AT device object */
  114. struct at_device *at_device_get_first_initialized(void);
  115. struct at_device *at_device_get_by_name(int type, const char *name);
  116. #ifdef AT_USING_SOCKET
  117. struct at_device *at_device_get_by_socket(int at_socket);
  118. #endif
  119. /* AT device control operaions */
  120. int at_device_control(struct at_device *device, int cmd, void *arg);
  121. /* Register AT device class object */
  122. int at_device_class_register(struct at_device_class *class, uint16_t class_id);
  123. /* Register AT device object */
  124. int at_device_register(struct at_device *device, const char *device_name,
  125. const char *at_client_name, uint16_t class_id, void *user_data);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif /* __AT_DEVICE_H__ */