ql_virt_at_demo.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. @file
  3. ql_virt_at_demo.c
  4. @brief
  5. quectel virt at demo.
  6. */
  7. /*================================================================
  8. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  9. Quectel Wireless Solution Proprietary and Confidential.
  10. =================================================================*/
  11. /*=================================================================
  12. EDIT HISTORY FOR MODULE
  13. This section contains comments describing changes made to the module.
  14. Notice that changes are listed in reverse chronological order.
  15. WHEN WHO WHAT, WHERE, WHY
  16. ------------ ------- -------------------------------------------------------------------------------
  17. 27/01/2021 Neo Init version
  18. =================================================================*/
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include "ql_api_osi.h"
  23. #include "ql_log.h"
  24. #include "ql_api_virt_at.h"
  25. #include "ql_virt_at_demo.h"
  26. /*===========================================================================
  27. * Macro Definition
  28. ===========================================================================*/
  29. #define QL_VIRTAT_DEMO_LOG_LEVEL QL_LOG_LEVEL_INFO
  30. #define QL_VIRTAT_DEMO_LOG(msg, ...) QL_LOG(QL_VIRTAT_DEMO_LOG_LEVEL, "ql_VIRTATDEMO", msg, ##__VA_ARGS__)
  31. #define QL_VIRTAT_DEMO_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_VIRTATDEMO", msg, ##__VA_ARGS__)
  32. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  33. #define QL_VIRT_AT_RX_BUFF_SIZE 1024
  34. /*========================================================================
  35. * function Definition
  36. *========================================================================*/
  37. void ql_virt_at0_notify_cb(unsigned int ind_type, unsigned int size)
  38. {
  39. unsigned char *recv_buff = calloc(1, QL_VIRT_AT_RX_BUFF_SIZE+1);
  40. unsigned int real_size = 0;
  41. if(QUEC_VIRT_AT_RX_RECV_DATA_IND == ind_type)
  42. {
  43. memset(recv_buff, 0, QL_VIRT_AT_RX_BUFF_SIZE+1);
  44. real_size= MIN(size, QL_VIRT_AT_RX_BUFF_SIZE);
  45. ql_virt_at_read(QL_VIRT_AT_PORT_0, recv_buff, real_size);
  46. QL_VIRTAT_DEMO_LOG("VAT0 <--: %s", recv_buff);
  47. }
  48. free(recv_buff);
  49. recv_buff = NULL;
  50. }
  51. void ql_virt_at1_notify_cb(unsigned int ind_type, unsigned int size)
  52. {
  53. unsigned char *recv_buff = calloc(1, QL_VIRT_AT_RX_BUFF_SIZE+1);
  54. unsigned int real_size = 0;
  55. if(QUEC_VIRT_AT_RX_RECV_DATA_IND == ind_type)
  56. {
  57. memset(recv_buff, 0, QL_VIRT_AT_RX_BUFF_SIZE+1);
  58. real_size= MIN(size, QL_VIRT_AT_RX_BUFF_SIZE);
  59. ql_virt_at_read(QL_VIRT_AT_PORT_1, recv_buff, real_size);
  60. QL_VIRTAT_DEMO_LOG("VAT1 <--: %s", recv_buff);
  61. }
  62. free(recv_buff);
  63. recv_buff = NULL;
  64. }
  65. void ql_virt_at2_notify_cb(unsigned int ind_type, unsigned int size)
  66. {
  67. unsigned char *recv_buff = calloc(1, QL_VIRT_AT_RX_BUFF_SIZE+1);
  68. unsigned int real_size = 0;
  69. if(QUEC_VIRT_AT_RX_RECV_DATA_IND == ind_type)
  70. {
  71. memset(recv_buff, 0, QL_VIRT_AT_RX_BUFF_SIZE+1);
  72. real_size= MIN(size, QL_VIRT_AT_RX_BUFF_SIZE);
  73. ql_virt_at_read(QL_VIRT_AT_PORT_2, recv_buff, real_size);
  74. QL_VIRTAT_DEMO_LOG("VAT2 <--: %s", recv_buff);
  75. }
  76. free(recv_buff);
  77. recv_buff = NULL;
  78. }
  79. static void ql_virt_at_demo_thread(void *param)
  80. {
  81. int ret = 0;
  82. QlOSStatus err = 0;
  83. char *cmd0 = "ATI\r\n";
  84. char *cmd1 = "AT+QDBGCFG=\"memory\"\r\n";
  85. char *cmd2 = "at+qdbgcfg=\"oem\"\r\n";
  86. ret = ql_virt_at_open(QL_VIRT_AT_PORT_0,ql_virt_at0_notify_cb);
  87. if(QL_VIRT_AT_SUCCESS != ret)
  88. {
  89. QL_VIRTAT_DEMO_LOG("virt at0 open error,ret: 0x%x", ret);
  90. goto exit;
  91. }
  92. QL_VIRTAT_DEMO_LOG("virt at0 open success");
  93. ret = ql_virt_at_open(QL_VIRT_AT_PORT_1,ql_virt_at1_notify_cb);
  94. if(QL_VIRT_AT_SUCCESS != ret)
  95. {
  96. QL_VIRTAT_DEMO_LOG("virt at1 open error,ret: 0x%x", ret);
  97. goto exit;
  98. }
  99. QL_VIRTAT_DEMO_LOG("virt at1 open success");
  100. ret = ql_virt_at_open(QL_VIRT_AT_PORT_2,ql_virt_at2_notify_cb);
  101. if(QL_VIRT_AT_SUCCESS != ret)
  102. {
  103. QL_VIRTAT_DEMO_LOG("virt at2 open error,ret: 0x%x", ret);
  104. goto exit;
  105. }
  106. QL_VIRTAT_DEMO_LOG("virt at2 open success");
  107. while(1)
  108. {
  109. QL_VIRTAT_DEMO_LOG("VAT0 -->: %s", cmd0);
  110. ql_virt_at_write(QL_VIRT_AT_PORT_0, (unsigned char*)cmd0, strlen((char *)cmd0));
  111. ql_rtos_task_sleep_ms(5000);
  112. QL_VIRTAT_DEMO_LOG("VAT1 -->: %s", cmd1);
  113. ql_virt_at_write(QL_VIRT_AT_PORT_1, (unsigned char*)cmd1, strlen((char *)cmd1));
  114. ql_rtos_task_sleep_ms(5000);
  115. QL_VIRTAT_DEMO_LOG("VAT2 -->: %s", cmd2);
  116. ql_virt_at_write(QL_VIRT_AT_PORT_2, (unsigned char*)cmd2, strlen((char *)cmd2));
  117. ql_rtos_task_sleep_ms(5000);
  118. }
  119. exit:
  120. err = ql_rtos_task_delete(NULL);
  121. if(err != QL_OSI_SUCCESS)
  122. {
  123. QL_VIRTAT_DEMO_LOG("task deleted failed");
  124. }
  125. }
  126. void ql_virt_at_app_init()
  127. {
  128. QlOSStatus err = QL_OSI_SUCCESS;
  129. ql_task_t virt_at_task = NULL;
  130. err = ql_rtos_task_create(&virt_at_task, 1024, APP_PRIORITY_NORMAL, "ql_virtatdemo", ql_virt_at_demo_thread, NULL, 1);
  131. if( err != QL_OSI_SUCCESS )
  132. {
  133. QL_VIRTAT_DEMO_LOG("virt at demo task created failed");
  134. return;
  135. }
  136. }