module_wrapper.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. * author wulianwei
  3. * title 通信模块驱动封装
  4. */
  5. #include "module_wrapper.h"
  6. #include "string.h"
  7. static at_module_t *g_at_module = NULL;
  8. uint8 tcp_connect_status = TCP_CLOSED; //tcp连接状态 0:断开,1:连接,2 连接中
  9. uint8_t module_start_status = MODULE_FAIL; //模块启动
  10. uint8 module_init_status = MODULE_FAIL; // 模块初始化
  11. module_channel_t module_channel[CHANNEL_COUNT]={0};
  12. void channel_data_clear(uint8_t channel)
  13. {
  14. module_channel[channel].valid_data.len = 0;
  15. memset(module_channel[channel].valid_data.buf,0,sizeof(module_channel[channel].valid_data.buf));
  16. }
  17. int at_module_register(at_module_t *module)
  18. {
  19. if (!g_at_module) {
  20. g_at_module = module;
  21. return 0;
  22. }
  23. return -1;
  24. }
  25. int at_module_register_default()
  26. {
  27. g_at_module = NULL;
  28. return 0;
  29. }
  30. void at_module_start(void)
  31. {
  32. if (g_at_module && g_at_module->start) {
  33. g_at_module->start();
  34. }
  35. }
  36. int at_module_init(void)
  37. {
  38. if (g_at_module && g_at_module->init) {
  39. return g_at_module->init();
  40. }
  41. return -1;
  42. }
  43. void at_module_connect(const char *ip, const char *port)
  44. {
  45. if (g_at_module && g_at_module->connect) {
  46. g_at_module->connect(ip, port);
  47. }
  48. }
  49. void at_module_udpopen(const char *ip, const char *port)
  50. {
  51. if (g_at_module && g_at_module->udpopen) {
  52. g_at_module->udpopen(ip, port);
  53. }
  54. }
  55. void at_module_reconnect(const char *ip, const char *port)
  56. {
  57. if (g_at_module && g_at_module->reconnect) {
  58. g_at_module->reconnect(ip, port);
  59. }
  60. }
  61. void at_module_udpreopen(const char *ip, const char *port)
  62. {
  63. if (g_at_module && g_at_module->udpreopen) {
  64. g_at_module->udpreopen(ip, port);
  65. }
  66. }
  67. void at_module_channel_open(const char *ip, const char *port,uint8_t proto, uint8_t channel)
  68. {
  69. if (g_at_module && g_at_module->channel_open) {
  70. g_at_module->channel_open(ip, port,proto,channel);
  71. }
  72. }
  73. void at_module_channel_reopen(const char *ip, const char *port,uint8_t proto, uint8_t channel)
  74. {
  75. if (g_at_module && g_at_module->channel_reopen) {
  76. g_at_module->channel_reopen(ip, port,proto,channel);
  77. }
  78. }
  79. int at_module_close(void)
  80. {
  81. if (g_at_module && g_at_module->close) {
  82. g_at_module->close();
  83. }
  84. }
  85. int at_module_channel_close(uint8_t channel)
  86. {
  87. if (g_at_module && g_at_module->channel_close) {
  88. g_at_module->channel_close(channel);
  89. }
  90. }
  91. int at_module_tcpstate(void)
  92. {
  93. if (g_at_module && g_at_module->tcpstate) {
  94. return g_at_module->tcpstate();
  95. }
  96. return -1;
  97. }
  98. int at_module_channel_state(uint8_t channel)
  99. {
  100. if (g_at_module && g_at_module->channel_state) {
  101. return g_at_module->channel_state(channel);
  102. }
  103. return -1;
  104. }
  105. int at_module_send(const void *buf, size_t len)
  106. {
  107. if (g_at_module && g_at_module->send) {
  108. return g_at_module->send(buf, len);
  109. }
  110. return -1;
  111. }
  112. int at_module_send_rai(const void *buf, size_t len, int rai)
  113. {
  114. if (g_at_module && g_at_module->send_rai) {
  115. return g_at_module->send_rai(buf, len, rai);
  116. }
  117. return -1;
  118. }
  119. int at_module_send_ch(const void *buf, size_t len,uint8_t channel, int rai)
  120. {
  121. if (g_at_module && g_at_module->send_ch) {
  122. return g_at_module->send_ch(buf, len,channel, rai);
  123. }
  124. return -1;
  125. }
  126. int at_module_recv_timeout(void *buf, int len, int timeout)
  127. {
  128. if (g_at_module && g_at_module->recv_timeout) {
  129. return g_at_module->recv_timeout(buf, len ,timeout);
  130. }
  131. return -1;
  132. }
  133. void at_module_handle_event(void)
  134. {
  135. if (g_at_module && g_at_module->handle_event) {
  136. g_at_module->handle_event();
  137. }
  138. }
  139. void at_module_cmd_back(char *cmd, char *data, int size)
  140. {
  141. if (g_at_module && g_at_module->cmd_back) {
  142. g_at_module->cmd_back(cmd,data,size);
  143. }
  144. }
  145. void at_module_cmd(char *cmd)
  146. {
  147. if (g_at_module && g_at_module->cmd) {
  148. g_at_module->cmd(cmd);
  149. }
  150. }
  151. void at_module_low_power(void)
  152. {
  153. if (g_at_module && g_at_module->low_power) {
  154. g_at_module->low_power();
  155. }
  156. }