at_device.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.4"
  38. #define AT_DEVICE_SW_VERSION_NUM 0x20004
  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. #define AT_DEVICE_CLASS_M5311 0X13U
  59. #define AT_DEVICE_CLASS_N720 0X14U
  60. #define AT_DEVICE_CLASS_L610 0X15U
  61. /* Options and Commands for AT device control opreations */
  62. #define AT_DEVICE_CTRL_POWER_ON 0x01L
  63. #define AT_DEVICE_CTRL_POWER_OFF 0x02L
  64. #define AT_DEVICE_CTRL_RESET 0x03L
  65. #define AT_DEVICE_CTRL_LOW_POWER 0x04L
  66. #define AT_DEVICE_CTRL_SLEEP 0x05L
  67. #define AT_DEVICE_CTRL_WAKEUP 0x06L
  68. #define AT_DEVICE_CTRL_NET_CONN 0x07L
  69. #define AT_DEVICE_CTRL_NET_DISCONN 0x08L
  70. #define AT_DEVICE_CTRL_SET_WIFI_INFO 0x09L
  71. #define AT_DEVICE_CTRL_GET_SIGNAL 0x0AL
  72. #define AT_DEVICE_CTRL_GET_GPS 0x0BL
  73. #define AT_DEVICE_CTRL_GET_VER 0x0CL
  74. /* Name type */
  75. #define AT_DEVICE_NAMETYPE_DEVICE 0x01
  76. #define AT_DEVICE_NAMETYPE_NETDEV 0x02
  77. #define AT_DEVICE_NAMETYPE_CLIENT 0x03
  78. struct at_device;
  79. /* AT device wifi ssid and password information */
  80. struct at_device_ssid_pwd
  81. {
  82. char *ssid;
  83. char *password;
  84. };
  85. /* AT device operations */
  86. struct at_device_ops
  87. {
  88. int (*init)(struct at_device *device);
  89. int (*deinit)(struct at_device *device);
  90. int (*control)(struct at_device *device, int cmd, void *arg);
  91. };
  92. struct at_device_class
  93. {
  94. uint16_t class_id; /* AT device class ID */
  95. const struct at_device_ops *device_ops; /* AT device operaiotns */
  96. #ifdef AT_USING_SOCKET
  97. uint32_t socket_num; /* The maximum number of sockets support */
  98. const struct at_socket_ops *socket_ops; /* AT device socket operations */
  99. #endif
  100. rt_slist_t list; /* AT device class list */
  101. };
  102. struct at_device
  103. {
  104. char name[RT_NAME_MAX]; /* AT device name */
  105. rt_bool_t is_init; /* AT device initialization completed */
  106. struct at_device_class *class; /* AT device class object */
  107. struct at_client *client; /* AT Client object for AT device */
  108. struct netdev *netdev; /* Network interface device for AT device */
  109. #ifdef AT_USING_SOCKET
  110. rt_event_t socket_event; /* AT device socket event */
  111. struct at_socket *sockets; /* AT device sockets list */
  112. #endif
  113. rt_slist_t list; /* AT device list */
  114. void *user_data; /* User-specific data */
  115. };
  116. /* Get AT device object */
  117. struct at_device *at_device_get_first_initialized(void);
  118. struct at_device *at_device_get_by_name(int type, const char *name);
  119. #ifdef AT_USING_SOCKET
  120. struct at_device *at_device_get_by_socket(int at_socket);
  121. #endif
  122. /* AT device control operaions */
  123. int at_device_control(struct at_device *device, int cmd, void *arg);
  124. /* Register AT device class object */
  125. int at_device_class_register(struct at_device_class *class, uint16_t class_id);
  126. /* Register AT device object */
  127. int at_device_register(struct at_device *device, const char *device_name,
  128. const char *at_client_name, uint16_t class_id, void *user_data);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif /* __AT_DEVICE_H__ */