module_wrapper.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef _MODULE_WRAPPER_H_
  2. #define _MODULE_WRAPPER_H_
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include "sys.h"
  6. #define SEND_SIZE 1024 //发送缓存大小
  7. #define CHANNEL_COUNT 2 //网络链接通道数量
  8. #define MIN_CHANNEL_NUM 1 //最小通道号
  9. /** 连接通道信息*/
  10. typedef struct module_channel_st {
  11. uint8_t proto;
  12. uint8_t connect_status;
  13. valid_data_t valid_data;
  14. } module_channel_t;
  15. extern uint8 tcp_connect_status;
  16. extern uint8_t module_start_status;
  17. extern uint8 module_init_status;
  18. extern module_channel_t module_channel[CHANNEL_COUNT];
  19. typedef void (*at_event_callback_t)(void);
  20. typedef struct at_event_st {
  21. const char *event_header;
  22. at_event_callback_t event_callback;
  23. } at_event_t;
  24. enum tcp_status_en
  25. {
  26. TCP_CLOSED, //tcp关闭
  27. TCP_OPEN, //tcp打开
  28. TCP_CONNECTING //tcp正在连接
  29. };
  30. enum module_proto_en
  31. {
  32. UDP, //UDP协议
  33. TCP, //TCP协议
  34. };
  35. enum module_status_en
  36. {
  37. MODULE_FAIL, //无效
  38. MODULE_OK, //有效
  39. };
  40. enum send_rai_en
  41. {
  42. KEPP_RRC, //不释放RRC
  43. NO_RRC, //立即释放RRC
  44. ONE_RRC //返回释放RRC
  45. };
  46. typedef struct at_module_st {
  47. void (*start)(void);
  48. int (*init)(void);
  49. void (*connect)(const char *ip, const char *port);
  50. void (*udpopen)(const char *ip, const char *port);
  51. void (*reconnect)(const char *ip, const char *port);
  52. void (*udpreopen)(const char *ip, const char *port);
  53. void (*channel_open)(const char *ip, const char *port,uint8_t proto, uint8_t channel);
  54. void (*channel_reopen)(const char *ip, const char *port,uint8_t proto, uint8_t channel);
  55. int (*tcpstate)(void);
  56. int (*channel_state)(uint8_t channel);
  57. int (*send)(const void *buf, int len);
  58. int (*send_rai)(const void *data, int len,int rai);
  59. int (*send_ch)(const void *data, int len,uint8_t channel,int rai);
  60. int (*recv_timeout)(void *buf, int len, int timeout);
  61. int (*close)(void);
  62. int (*channel_close)(uint8_t channel);
  63. void (*handle_event)(void);
  64. void (*cmd_back)(char *cmd, char *data, int size);
  65. void (*cmd)(char *cmd);
  66. int (*low_power)(void);
  67. } at_module_t;
  68. void channel_data_clear(uint8_t channel);
  69. int at_module_register(at_module_t *module);
  70. int at_module_register_default(void);
  71. void at_module_start(void);
  72. int at_module_init(void);
  73. void at_module_connect(const char *ip, const char *port);
  74. void at_module_udpopen(const char *ip, const char *port);
  75. void at_module_reconnect(const char *ip, const char *port);
  76. void at_module_udpreopen(const char *ip, const char *port);
  77. void at_module_channel_open(const char *ip, const char *port,uint8_t proto, uint8_t channel);
  78. void at_module_channel_reopen(const char *ip, const char *port,uint8_t proto, uint8_t channel);
  79. int at_module_close(void);
  80. int at_module_channel_close(uint8_t channel);
  81. int at_module_tcpstate(void);
  82. int at_module_channel_state(uint8_t channel);
  83. int at_module_send(const void *buf, size_t len);
  84. int at_module_send_rai(const void *buf, size_t len, int rai);
  85. int at_module_send_ch(const void *buf, size_t len,uint8_t channel, int rai);
  86. int at_module_recv_timeout(void *buf, int len, int timeout);
  87. void at_module_handle_event(void);
  88. void at_module_cmd_back(char *cmd, char *data, int size);
  89. void at_module_cmd(char *cmd);
  90. void at_module_low_power(void);
  91. #endif