module_wrapper.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. int at_module_register(at_module_t *module)
  12. {
  13. if (!g_at_module) {
  14. g_at_module = module;
  15. return 0;
  16. }
  17. return -1;
  18. }
  19. int at_module_register_default()
  20. {
  21. g_at_module = NULL;
  22. return 0;
  23. }
  24. void at_module_start(void)
  25. {
  26. if (g_at_module && g_at_module->start) {
  27. g_at_module->start();
  28. }
  29. }
  30. int at_module_init(void)
  31. {
  32. if (g_at_module && g_at_module->init) {
  33. return g_at_module->init();
  34. }
  35. return -1;
  36. }
  37. void at_module_connect(const char *ip, const char *port)
  38. {
  39. if (g_at_module && g_at_module->connect) {
  40. g_at_module->connect(ip, port);
  41. }
  42. }
  43. void at_module_udpopen(const char *ip, const char *port)
  44. {
  45. if (g_at_module && g_at_module->udpopen) {
  46. g_at_module->udpopen(ip, port);
  47. }
  48. }
  49. void at_module_reconnect(const char *ip, const char *port)
  50. {
  51. if (g_at_module && g_at_module->reconnect) {
  52. g_at_module->reconnect(ip, port);
  53. }
  54. }
  55. void at_module_udpreopen(const char *ip, const char *port)
  56. {
  57. if (g_at_module && g_at_module->udpreopen) {
  58. g_at_module->udpreopen(ip, port);
  59. }
  60. }
  61. void at_module_close(void)
  62. {
  63. if (g_at_module && g_at_module->close) {
  64. g_at_module->close();
  65. }
  66. }
  67. int at_module_tcpstate(void)
  68. {
  69. if (g_at_module && g_at_module->tcpstate) {
  70. return g_at_module->tcpstate();
  71. }
  72. return -1;
  73. }
  74. int at_module_send(const void *buf, size_t len)
  75. {
  76. if (g_at_module && g_at_module->send) {
  77. return g_at_module->send(buf, len);
  78. }
  79. return -1;
  80. }
  81. int at_module_send_rai(const void *buf, size_t len, int rai)
  82. {
  83. if (g_at_module && g_at_module->send_rai) {
  84. return g_at_module->send_rai(buf, len, rai);
  85. }
  86. return -1;
  87. }
  88. int at_module_recv_timeout(void *buf, int len, int timeout)
  89. {
  90. if (g_at_module && g_at_module->recv_timeout) {
  91. return g_at_module->recv_timeout(buf, len ,timeout);
  92. }
  93. return -1;
  94. }
  95. void at_module_handle_event(void)
  96. {
  97. if (g_at_module && g_at_module->handle_event) {
  98. g_at_module->handle_event();
  99. }
  100. }
  101. void at_module_cmd_back(char *cmd, char *data, int size)
  102. {
  103. if (g_at_module && g_at_module->cmd_back) {
  104. g_at_module->cmd_back(cmd,data,size);
  105. }
  106. }
  107. void at_module_cmd(char *cmd)
  108. {
  109. if (g_at_module && g_at_module->cmd) {
  110. g_at_module->cmd(cmd);
  111. }
  112. }
  113. void at_module_low_power(void)
  114. {
  115. if (g_at_module && g_at_module->low_power) {
  116. g_at_module->low_power();
  117. }
  118. }