at_device.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-05-08 chenyong first version
  9. */
  10. #ifndef __AT_DEVICE_H__
  11. #define __AT_DEVICE_H__
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <at.h>
  16. #include <at_socket.h>
  17. #if !defined(RT_USING_NETDEV) || (!defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10300)
  18. #error "This RT-Thread version is older, please check and updata laster RT-Thread!"
  19. #else
  20. #include <arpa/inet.h>
  21. #include <netdev.h>
  22. #endif /* RT_USING_NETDEV */
  23. #if RT_VER_NUM < 0x50200
  24. #define rt_sscanf sscanf
  25. #endif
  26. #define AT_DEVICE_SW_VERSION "2.1.0"
  27. #define AT_DEVICE_SW_VERSION_NUM 0x20100
  28. /* AT device class ID */
  29. #define AT_DEVICE_CLASS_ESP8266 0x01U
  30. #define AT_DEVICE_CLASS_M26_MC20 0x02U
  31. #define AT_DEVICE_CLASS_EC20 0x03U
  32. #define AT_DEVICE_CLASS_SIM800C 0x04U
  33. #define AT_DEVICE_CLASS_SIM76XX 0x05U
  34. #define AT_DEVICE_CLASS_RW007 0x06U
  35. #define AT_DEVICE_CLASS_MW31 0x07U
  36. #define AT_DEVICE_CLASS_ESP32 0x08U
  37. #define AT_DEVICE_CLASS_W60X 0x09U
  38. #define AT_DEVICE_CLASS_A9G 0x0AU
  39. #define AT_DEVICE_CLASS_BC26 0x0BU
  40. #define AT_DEVICE_CLASS_AIR720 0x0CU
  41. #define AT_DEVICE_CLASS_ME3616 0x0DU
  42. #define AT_DEVICE_CLASS_M6315 0x0EU
  43. #define AT_DEVICE_CLASS_BC28 0x0FU
  44. #define AT_DEVICE_CLASS_EC200X 0x10U
  45. #define AT_DEVICE_CLASS_N21 0x11U
  46. #define AT_DEVICE_CLASS_N58 0x12U
  47. #define AT_DEVICE_CLASS_M5311 0X13U
  48. #define AT_DEVICE_CLASS_N720 0X14U
  49. #define AT_DEVICE_CLASS_L610 0X15U
  50. #define AT_DEVICE_CLASS_ML305 0X16U
  51. #define AT_DEVICE_CLASS_ML307 0X17U
  52. /* Options and Commands for AT device control opreations */
  53. #define AT_DEVICE_CTRL_POWER_ON 0x01L
  54. #define AT_DEVICE_CTRL_POWER_OFF 0x02L
  55. #define AT_DEVICE_CTRL_RESET 0x03L
  56. #define AT_DEVICE_CTRL_LOW_POWER 0x04L
  57. #define AT_DEVICE_CTRL_SLEEP 0x05L
  58. #define AT_DEVICE_CTRL_WAKEUP 0x06L
  59. #define AT_DEVICE_CTRL_NET_CONN 0x07L
  60. #define AT_DEVICE_CTRL_NET_DISCONN 0x08L
  61. #define AT_DEVICE_CTRL_SET_WIFI_INFO 0x09L
  62. #define AT_DEVICE_CTRL_GET_SIGNAL 0x0AL
  63. #define AT_DEVICE_CTRL_GET_GPS 0x0BL
  64. #define AT_DEVICE_CTRL_GET_VER 0x0CL
  65. #define AT_DEVICE_CTRL_SET_HOST_NAME 0x0DL
  66. /* Name type */
  67. #define AT_DEVICE_NAMETYPE_DEVICE 0x01
  68. #define AT_DEVICE_NAMETYPE_NETDEV 0x02
  69. #define AT_DEVICE_NAMETYPE_CLIENT 0x03
  70. struct at_device;
  71. /* AT device wifi ssid and password information */
  72. struct at_device_ssid_pwd
  73. {
  74. char *ssid;
  75. char *password;
  76. };
  77. /* AT device operations */
  78. struct at_device_ops
  79. {
  80. int (*init)(struct at_device *device);
  81. int (*deinit)(struct at_device *device);
  82. int (*control)(struct at_device *device, int cmd, void *arg);
  83. };
  84. struct at_device_class
  85. {
  86. uint16_t class_id; /* AT device class ID */
  87. const struct at_device_ops *device_ops; /* AT device operaiotns */
  88. #ifdef AT_USING_SOCKET
  89. uint32_t socket_num; /* The maximum number of sockets support */
  90. const struct at_socket_ops *socket_ops; /* AT device socket operations */
  91. #endif
  92. rt_slist_t list; /* AT device class list */
  93. };
  94. struct at_device
  95. {
  96. char name[RT_NAME_MAX]; /* AT device name */
  97. rt_bool_t is_init; /* AT device initialization completed */
  98. struct at_device_class *class; /* AT device class object */
  99. struct at_client *client; /* AT Client object for AT device */
  100. struct netdev *netdev; /* Network interface device for AT device */
  101. #ifdef AT_USING_SOCKET
  102. rt_event_t socket_event; /* AT device socket event */
  103. struct at_socket *sockets; /* AT device sockets list */
  104. #endif
  105. rt_slist_t list; /* AT device list */
  106. void *user_data; /* User-specific data */
  107. };
  108. /* Get AT device object */
  109. struct at_device *at_device_get_first_initialized(void);
  110. struct at_device *at_device_get_by_name(int type, const char *name);
  111. #ifdef AT_USING_SOCKET
  112. struct at_device *at_device_get_by_socket(int at_socket);
  113. #endif
  114. /* Get the client lock (mutex) of the specified AT device. */
  115. rt_mutex_t at_device_get_client_lock(struct at_device *device);
  116. /* AT device control operaions */
  117. int at_device_control(struct at_device *device, int cmd, void *arg);
  118. /* Register AT device class object */
  119. int at_device_class_register(struct at_device_class *class, uint16_t class_id);
  120. /* Register AT device object */
  121. int at_device_register(struct at_device *device, const char *device_name,
  122. const char *at_client_name, uint16_t class_id, void *user_data);
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif /* __AT_DEVICE_H__ */