voice_call_demo.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*================================================================
  2. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  3. Quectel Wireless Solution Proprietary and Confidential.
  4. =================================================================*/
  5. /*=================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ------------ ------- -------------------------------------------------------------------------------
  11. 20/10/2020 marvin create
  12. =================================================================*/
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include "ql_api_common.h"
  17. #include "ql_api_osi.h"
  18. #include "ql_api_voice_call.h"
  19. #include "ql_log.h"
  20. ql_task_t vc_task = NULL;
  21. void user_voice_call_event_callback(uint8_t sim, int event_id, void *ctx)
  22. {
  23. ql_event_t vc_event = {0};
  24. switch(event_id)
  25. {
  26. case QL_VC_RING_IND:
  27. //ctx will be destroyed when exit.
  28. QL_VC_LOG("nSim=%d, RING TEL = %s",sim, (char *)ctx);
  29. break;
  30. case QL_VC_CCWA_IND:
  31. //ctx will be destroyed when exit.
  32. QL_VC_LOG("nSim=%d, QL_VC_CCWA_IND : %s",sim, (char *)ctx);
  33. break;
  34. default:
  35. break;
  36. }
  37. vc_event.id = event_id;
  38. vc_event.param1 = sim;
  39. if(NULL != ctx)//The value of the ctx->msg may be NULL
  40. {
  41. vc_event.param2 = *(uint32 *)ctx;
  42. }
  43. ql_rtos_event_send(vc_task, &vc_event);
  44. }
  45. void voice_call_demo_task(void * param)
  46. {
  47. QL_VC_LOG("enter");
  48. ql_vc_errcode_e err = QL_VC_SUCCESS;
  49. ql_event_t vc_event = {0};
  50. uint8_t nSim = 0;
  51. ql_voice_call_callback_register(user_voice_call_event_callback);
  52. //wait init ok;
  53. ql_rtos_task_sleep_s(10);
  54. #if 0
  55. //0 : Disable automatic answer
  56. //x : x>0, answer automatically after x rings
  57. err = ql_voice_auto_answer(nSim,0);
  58. if(err != QL_VC_SUCCESS){
  59. QL_VC_LOG("ql_voice_auto_answer FAIL");
  60. }else {
  61. QL_VC_LOG("ql_voice_auto_answer OK");
  62. }
  63. #endif
  64. #if 0
  65. //Enable call waiting
  66. err = ql_voice_call_wait_set(nSim,0);
  67. if(err != QL_VC_SUCCESS){
  68. QL_VC_LOG("ql_voice_call_wait_set FAIL");
  69. }else {
  70. QL_VC_LOG("ql_voice_call_wait_set OK");
  71. }
  72. //Get call waiting status
  73. uint8_t result = 0;
  74. err = ql_voice_call_wait_get(nSim,&result);
  75. if(err != QL_VC_SUCCESS){
  76. QL_VC_LOG("ql_voice_call_wait_get FAIL,result=%d",result);
  77. }else {
  78. QL_VC_LOG("ql_voice_call_wait_get OK,result=%d",result);
  79. }
  80. #endif
  81. #if 0
  82. //Set call forwarding
  83. ql_rtos_task_sleep_s(3);
  84. err = ql_voice_call_fw(nSim,0,3,"18924012349");
  85. if(err != QL_VC_SUCCESS){
  86. QL_VC_LOG("ql_voice_call_fw register FAIL");
  87. }else{
  88. QL_VC_LOG("ql_voice_call_fw register OK");
  89. }
  90. //Get call forwarding
  91. ql_rtos_task_sleep_s(3);
  92. char telNum[32] = {0};
  93. err = ql_voice_call_fw(nSim,0,2, telNum);
  94. if(err != QL_VC_SUCCESS){
  95. QL_VC_LOG("ql_voice_call_fw get FAIL");
  96. }else{
  97. QL_VC_LOG("ql_voice_call_fw get OK, telNum = %s",telNum);
  98. }
  99. //Cancel call forwarding
  100. ql_rtos_task_sleep_s(5);
  101. err = ql_voice_call_fw(nSim,0,4,"18924012349");
  102. if(err != QL_VC_SUCCESS){
  103. QL_VC_LOG("ql_voice_call_fw erasure FAIL");
  104. }else{
  105. QL_VC_LOG("ql_voice_call_fw erasure OK");
  106. }
  107. //Get call forwarding
  108. ql_rtos_task_sleep_s(3);
  109. memset(telNum, 0, sizeof(telNum));
  110. err = ql_voice_call_fw(nSim,0,2, telNum);
  111. if(err != QL_VC_SUCCESS){
  112. QL_VC_LOG("ql_voice_call_fw get FAIL");
  113. }else{
  114. QL_VC_LOG("ql_voice_call_fw get OK, telNum = %s",telNum);
  115. }
  116. #endif
  117. #if 0
  118. //demo for ql_voice_call_start_dtmf
  119. QL_VC_LOG("start call");
  120. err = ql_voice_call_start(nSim,"18924012349");
  121. if(err != QL_VC_SUCCESS){
  122. QL_VC_LOG("ql_voice_call_start FAIL");
  123. }else{
  124. QL_VC_LOG("ql_voice_call_start OK");
  125. }
  126. ql_event_wait(&vc_event, QL_WAIT_FOREVER);
  127. if(vc_event.id == QL_VC_NOCARRIER_IND)
  128. {
  129. QL_VC_LOG("NOCARRIER, reson = %d", vc_event.param2);
  130. }
  131. else if(vc_event.id == QL_VC_CONNECT_IND)
  132. {
  133. QL_VC_LOG("CONNECT");
  134. ql_rtos_task_sleep_s(2);
  135. err = ql_voice_call_start_dtmf(nSim,"123456789*#ABCD", 0);
  136. if(err != QL_VC_SUCCESS){
  137. QL_VC_LOG("ql_voice_call_start_dtmf FAIL");
  138. }else{
  139. QL_VC_LOG("ql_voice_call_start_dtmf OK");
  140. }
  141. ql_rtos_task_sleep_s(10);
  142. err = ql_voice_call_end(nSim);
  143. if(err != QL_VC_SUCCESS){
  144. QL_VC_LOG("ql_voice_call_end FAIL");
  145. }else{
  146. QL_VC_LOG("ql_voice_call_end OK");
  147. }
  148. }
  149. #endif
  150. #if 0
  151. //demo for ql_voice_call_clcc
  152. ql_voice_call_start(nSim,"10086");
  153. ql_rtos_task_sleep_s(15);
  154. uint8_t total;
  155. ql_vc_info_s vc_info[QL_VC_MAX_NUM];
  156. err = ql_voice_call_clcc(nSim,&total, vc_info);
  157. if(err != QL_VC_SUCCESS){
  158. QL_VC_LOG("ql_voice_call_clcc FAIL");
  159. }else {
  160. QL_VC_LOG("total number = %d",total);
  161. for(uint8_t i = 0; i<total; i++){
  162. QL_VC_LOG("index:%d direction:%d status:%d mpty:%d number:%s",
  163. vc_info[i].idx,vc_info[i].direction,vc_info[i].status,vc_info[i].multiparty,vc_info[i].number);
  164. }
  165. }
  166. #endif
  167. QL_VC_LOG("wait call");
  168. while(1){
  169. ql_event_wait(&vc_event, QL_WAIT_FOREVER);
  170. switch(vc_event.id)
  171. {
  172. case QL_VC_RING_IND:
  173. ql_rtos_task_sleep_s(10);//
  174. err = ql_voice_call_answer(nSim);
  175. if(err != QL_VC_SUCCESS){
  176. QL_VC_LOG("ql_voice_call_answer FAIL");
  177. }else{
  178. QL_VC_LOG("ql_voice_call_answer OK");
  179. }
  180. break;
  181. case QL_VC_CONNECT_IND:
  182. QL_VC_LOG("CONNECT");
  183. ql_rtos_task_sleep_s(10);
  184. err = ql_voice_call_end(nSim);
  185. if(err != QL_VC_SUCCESS){
  186. QL_VC_LOG("ql_voice_call_end FAIL");
  187. }else{
  188. QL_VC_LOG("ql_voice_call_end OK");
  189. }
  190. break;
  191. case QL_VC_NOCARRIER_IND:
  192. QL_VC_LOG("NOCARRIER");
  193. break;
  194. default:
  195. QL_VC_LOG("event id = 0x%x",vc_event.id);
  196. break;
  197. }
  198. }
  199. ql_rtos_task_delete(NULL);
  200. }
  201. QlOSStatus ql_voice_call_app_init(void)
  202. {
  203. QlOSStatus err = QL_OSI_SUCCESS;
  204. err = ql_rtos_task_create(&vc_task, 4096, APP_PRIORITY_NORMAL, "vc_task", voice_call_demo_task, NULL, 10);
  205. if(err != QL_OSI_SUCCESS)
  206. {
  207. QL_VC_LOG("voice_call_demo_task created failed, ret = 0x%x", err);
  208. }
  209. return err;
  210. }