at_device.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2022, 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. #define AT_DEVICE_SW_VERSION "2.1.0"
  24. #define AT_DEVICE_SW_VERSION_NUM 0x20100
  25. /* AT device class ID */
  26. #define AT_DEVICE_CLASS_ESP8266 0x01U
  27. #define AT_DEVICE_CLASS_M26_MC20 0x02U
  28. #define AT_DEVICE_CLASS_EC20 0x03U
  29. #define AT_DEVICE_CLASS_SIM800C 0x04U
  30. #define AT_DEVICE_CLASS_SIM76XX 0x05U
  31. #define AT_DEVICE_CLASS_RW007 0x06U
  32. #define AT_DEVICE_CLASS_MW31 0x07U
  33. #define AT_DEVICE_CLASS_ESP32 0x08U
  34. #define AT_DEVICE_CLASS_W60X 0x09U
  35. #define AT_DEVICE_CLASS_A9G 0x0AU
  36. #define AT_DEVICE_CLASS_BC26 0x0BU
  37. #define AT_DEVICE_CLASS_AIR720 0x0CU
  38. #define AT_DEVICE_CLASS_ME3616 0x0DU
  39. #define AT_DEVICE_CLASS_M6315 0x0EU
  40. #define AT_DEVICE_CLASS_BC28 0x0FU
  41. #define AT_DEVICE_CLASS_EC200X 0x10U
  42. #define AT_DEVICE_CLASS_N21 0x11U
  43. #define AT_DEVICE_CLASS_N58 0x12U
  44. #define AT_DEVICE_CLASS_M5311 0X13U
  45. #define AT_DEVICE_CLASS_N720 0X14U
  46. #define AT_DEVICE_CLASS_L610 0X15U
  47. #define AT_DEVICE_CLASS_ML305 0X16U
  48. /* Options and Commands for AT device control opreations */
  49. #define AT_DEVICE_CTRL_POWER_ON 0x01L
  50. #define AT_DEVICE_CTRL_POWER_OFF 0x02L
  51. #define AT_DEVICE_CTRL_RESET 0x03L
  52. #define AT_DEVICE_CTRL_LOW_POWER 0x04L
  53. #define AT_DEVICE_CTRL_SLEEP 0x05L
  54. #define AT_DEVICE_CTRL_WAKEUP 0x06L
  55. #define AT_DEVICE_CTRL_NET_CONN 0x07L
  56. #define AT_DEVICE_CTRL_NET_DISCONN 0x08L
  57. #define AT_DEVICE_CTRL_SET_WIFI_INFO 0x09L
  58. #define AT_DEVICE_CTRL_GET_SIGNAL 0x0AL
  59. #define AT_DEVICE_CTRL_GET_GPS 0x0BL
  60. #define AT_DEVICE_CTRL_GET_VER 0x0CL
  61. /* Name type */
  62. #define AT_DEVICE_NAMETYPE_DEVICE 0x01
  63. #define AT_DEVICE_NAMETYPE_NETDEV 0x02
  64. #define AT_DEVICE_NAMETYPE_CLIENT 0x03
  65. struct at_device;
  66. /* AT device wifi ssid and password information */
  67. struct at_device_ssid_pwd
  68. {
  69. char *ssid;
  70. char *password;
  71. };
  72. /* AT device operations */
  73. struct at_device_ops
  74. {
  75. int (*init)(struct at_device *device);
  76. int (*deinit)(struct at_device *device);
  77. int (*control)(struct at_device *device, int cmd, void *arg);
  78. };
  79. struct at_device_class
  80. {
  81. uint16_t class_id; /* AT device class ID */
  82. const struct at_device_ops *device_ops; /* AT device operaiotns */
  83. #ifdef AT_USING_SOCKET
  84. uint32_t socket_num; /* The maximum number of sockets support */
  85. const struct at_socket_ops *socket_ops; /* AT device socket operations */
  86. #endif
  87. rt_slist_t list; /* AT device class list */
  88. };
  89. struct at_device
  90. {
  91. char name[RT_NAME_MAX]; /* AT device name */
  92. rt_bool_t is_init; /* AT device initialization completed */
  93. struct at_device_class *class; /* AT device class object */
  94. struct at_client *client; /* AT Client object for AT device */
  95. struct netdev *netdev; /* Network interface device for AT device */
  96. #ifdef AT_USING_SOCKET
  97. rt_event_t socket_event; /* AT device socket event */
  98. struct at_socket *sockets; /* AT device sockets list */
  99. #endif
  100. rt_slist_t list; /* AT device list */
  101. void *user_data; /* User-specific data */
  102. };
  103. /* Get AT device object */
  104. struct at_device *at_device_get_first_initialized(void);
  105. struct at_device *at_device_get_by_name(int type, const char *name);
  106. #ifdef AT_USING_SOCKET
  107. struct at_device *at_device_get_by_socket(int at_socket);
  108. #endif
  109. /* AT device control operaions */
  110. int at_device_control(struct at_device *device, int cmd, void *arg);
  111. /* Register AT device class object */
  112. int at_device_class_register(struct at_device_class *class, uint16_t class_id);
  113. /* Register AT device object */
  114. int at_device_register(struct at_device *device, const char *device_name,
  115. const char *at_client_name, uint16_t class_id, void *user_data);
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif /* __AT_DEVICE_H__ */