blob: 9df40533df12bc2c8bdbceb4bd452e4a1a407e7f [file] [log] [blame]
b.liu1c74d692024-08-14 17:43:59 +08001#include "mbtk_type.h"
2#include "ql/ql_at.h"
3#include "ql/ql_vcall.h"
4#include "ql/ql_mcm_call.h"
5#include "ql/ql_voice.h"
6
7typedef struct
8{
9 int cmdIdx;
10 char *funcName;
11} st_api_test_case;
12
13//for server test
14st_api_test_case at_api_testcases[] =
15{
16 {0, "print_help"},
17 {1, "QL_Voice_Call_Ecall"},
18 {2, "QL_Voice_Call_Ecall_HangUp"},
19
20 {-1, NULL}
21};
22
23
24voice_client_handle_type h_voice = 0;
25
26
27void print_help(void)
28{
29 int i;
30
31 printf("Supported test cases:\n");
32 for(i = 0; ; i++)
33 {
34 if(at_api_testcases[i].cmdIdx == -1)
35 {
36 break;
37 }
38 printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
39 }
40}
41
42static void ql_voice_call_ind_func(unsigned int ind_id,
43 void* ind_data,
44 uint32_t ind_data_len)
45{
46 if(NULL == ind_data)
47 {
48 return;
49 }
50
51 switch(ind_id)
52 {
53 case E_QL_MCM_VOICE_CALL_IND:
54 {
55 if(ind_data_len != sizeof(ql_mcm_voice_call_ind))
56 {
57 break;
58 }
59
60 ql_mcm_voice_call_ind *pVoiceCallInd = (ql_mcm_voice_call_ind*)ind_data;
61
62 char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
63
64 int i = 0;
65 for(i = 0; i < pVoiceCallInd->calls_len; i++)
66 {
67 printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n",
68 pVoiceCallInd->calls[i].call_id, pVoiceCallInd->calls[i].number, call_state[pVoiceCallInd->calls[i].state]);
69 }
70
71 break;
72 }
73
74 case E_QL_MCM_VOICE_ECALL_STATUE_IND:
75 {
76 if(ind_data_len != sizeof(ql_mcm_voice_ecall_status_ind))
77 {
78 break;
79 }
80
81 ql_mcm_voice_ecall_status_ind *pEcallStatusInd
82 = (ql_mcm_voice_ecall_status_ind*)ind_data;
83
84 if (pEcallStatusInd->ecall_msd_tx_status_valid)
85 {
86 if (pEcallStatusInd->ecall_msd_tx_status == E_QL_MCM_VOICE_ECALL_MSD_TRANSMISSION_STATUS_SUCCESS)
87 {
88 printf("========== Ecall status call_id =%d , ecall msd tx success.\r\n", pEcallStatusInd->call_id);
89 }
90 else
91 {
92 printf("========== Ecall status call_id =%d , ecall msd tx failure.\r\n", pEcallStatusInd->call_id);
93 }
94 }
95 else
96 {
97 printf("========== Ecall status call_id =%d \r\n", pEcallStatusInd->call_id);
98 }
99
100 break;
101 }
102
103 case E_QL_MCM_VOICE_UNKOWN_IND:
104 default:
105 break;
106 }
107}
108
109//"\t1 call init\n"
110QL_VOICE_ERROR_CODE ql_voice_call_init()
111{
112 int ret = 0;
113 ret = QL_Voice_Call_Client_Init(&h_voice);
114 if(ret < 0)
115 {
116 printf("QL_Voice_Call_Client_Init FAIL. ret:%d\n",ret);
117 ret = QL_VOICE_GENERIC_FAILURE;
118 }
119 else{
120 printf("QL_Voice_Call_Client_Init ret = %d, with h_voice=%d\n", ret, h_voice);
121 }
122
123 return ret;
124}
125
126//"\t9 call deinit\n"
127QL_VOICE_ERROR_CODE ql_voice_call_release()
128{
129 int ret = 0;
130 ret = QL_Voice_Call_Client_Deinit(h_voice);
131 if(ret)
132 {
133 ret = QL_VOICE_GENERIC_FAILURE;
134 }
135
136 return ret;
137}
138
139//\t2 call register handle\n"
140QL_VOICE_ERROR_CODE ql_voice_call_event_register(QL_VOICE_EventHandlerFunc_t handlerPtr, void* contextPtr)
141{
142 int ret = 0;
143 ret = QL_Voice_Call_AddCommonStateHandler(h_voice, (QL_VoiceCall_CommonStateHandlerFunc_t)ql_voice_call_ind_func);
144 if(ret < 0)
145 {
146 printf("QL_Voice_Call_AddCommonStateHandler FAIL. ret:%d\n",ret);
147 ret = QL_VOICE_GENERIC_FAILURE;
148 }
149
150 return ret;
151}
152
153/*
154 Phone call.
155 -call_num : dst phone number
156*/
157QL_VOICE_ERROR_CODE ql_voice_call_start(char* call_num)
158{
159 int ret = 0;
160
161 ret = QL_Voice_Call_Start(h_voice, 0, call_num, NULL);
162 if(ret)
163 {
164 ret = QL_VOICE_GENERIC_FAILURE;
165 }
166 return ret;
167}
168
169
170/*
171 Put through.
172*/
173QL_VOICE_ERROR_CODE ql_voice_call_answer()
174{
175 int ret = 0;
176 ret = QL_Voice_Call_Answer(h_voice, 0);
177 if(ret)
178 {
179 ret = QL_VOICE_GENERIC_FAILURE;
180 }
181 return ret;
182}
183QL_VOICE_ERROR_CODE ql_voice_auto_answer(int seconds)
184{
185 int ret = 0;
186
187 ret = QL_Voice_Call_SetAutoAnswer(h_voice, E_QL_MCM_VOICE_AUTO_ANSWER_ENABLE, 6000);
188 if(ret)
189 {
190 ret = QL_VOICE_GENERIC_FAILURE;
191 }
192 return ret;
193}
194
195/*
196 Hang up.
197*/
198QL_VOICE_ERROR_CODE ql_voice_call_end()
199{
200 int ret = 0;
201 ret = QL_Voice_Call_End(h_voice, 0);
202 if(ret)
203 {
204 ret = QL_VOICE_GENERIC_FAILURE;
205 }
206
207 return ret;
208}
209
210
211/* hold the voice */
212QL_VOICE_ERROR_CODE ql_voice_call_hold()
213{
214 int ret = 0;
215 QL_Voice_Call_Hold(h_voice);
216
217 return ret;
218}
219
220/* unhold the voice */
221QL_VOICE_ERROR_CODE ql_voice_call_unhold()
222{
223 int ret = 0;
224
225 QL_Voice_Call_UnHold(h_voice);
226
227 return ret;
228}
229