blob: e7eebc39d2611a98ae1dd992da7d80cc8e2d7a55 [file] [log] [blame]
xf.li3dd53742024-09-27 00:06:23 -07001#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <sys/types.h>
5#include <pthread.h>
6#include <unistd.h>
7#include <dlfcn.h>
8#include <stdint.h>
9
10#include"lynq-qser-voice-demo.h"
11
12typedef struct
13{
14 int cmdIdx;
15 char *funcName;
16} st_api_test_case;
17
18//for server test
19st_api_test_case at_api_testcases[] =
20{
21 {0, "print_help"},
22 {1, "qser_voice_call_start"},
23 {2, "qser_voice_call_end"},
24 {3, "qser_voice_call_answer"},
25 {4, "qser_voice_set_speech_volume"},
26 {5, "qser_voice_get_speech_volume"},
27 {6, "qser_voice_set_dtmf"},
28#ifdef ECALL_SUPPORT
29 {7, "qser_voice_set_test_num"},
30 {8, "qser_voice_fast_ecall"},
31#endif
xf.li39d99112024-09-28 04:05:58 -070032 {9, "qser_voice_set_audio_mode"},
33 {10, "qser_voice_get_audio_mode"},
xf.li3dd53742024-09-27 00:06:23 -070034 {-1, NULL}
35};
36
37typedef uint32_t voice_client_handle_type;
38
39
40int (*qser_voice_call_client_init)(voice_client_handle_type *ph_voice);
41int (*qser_voice_call_client_deinit)(voice_client_handle_type );
42int (*qser_voice_call_addstatehandler)(voice_client_handle_type h_voice,
43 QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
44 void *contextPtr);
45
46int (*qser_voice_call_removestatehandle)(voice_client_handle_type );
47int (*qser_voice_call_start)(voice_client_handle_type h_voice,
48 E_QSER_VCALL_ID_T simId,
49 char *phone_number, int *call_id);
50
51int (*qser_voice_call_end)(voice_client_handle_type ,int );
52int (*qser_voice_call_answer)(voice_client_handle_type ,int );
53int (*qser_voice_set_speech_volume)(const int volume);
54int (*qser_voice_get_speech_volume)(int *volume);
55int (*qser_voice_set_dtmf)(const char callnum);
xf.li39d99112024-09-28 04:05:58 -070056int (*qser_voice_set_audio_mode)(const int audio_mode);
57int (*qser_voice_get_audio_mode)(int* audio_mode);
58
xf.li3dd53742024-09-27 00:06:23 -070059
60#ifdef ECALL_SUPPORT
61int (*qser_voice_set_test_num)(voice_client_handle_type* h_voice,E_QSER_VOICE_ECALL_SET_TYPE_T type, const char *test_num, int test_num_length);
62int (*qser_voice_fast_ecall)(voice_client_handle_type* h_voice,
63 int *call_id,
64 E_QSER_VOICE_ECALL_CATEGORY_T cat,
65 E_QSER_VOICE_ECALL_VARIANT_T variant,
66 const char *addr,
67 int addr_length,
68 const unsigned char *msd_data,
69 int msd_length); //msd_length should <= QSER_MSD_MAX_LENGTH
70int (*qser_voice_set_msd)(int callid, const unsigned char *msd_data, int msd_length); //msd_length should <= QSER_MSD_MAX_LENGTH
71int (*qser_voice_add_ecall_indhandler)(voice_client_handle_type* h_voice,
72 QSER_ECall_IndHandlerFunc_t handlerPtr,
73 void* contextPtr);
74
75static void yk_voice_ecall_cb_func(int callid, E_QSER_VOICE_ECALL_INDICATION_T ind, void* contextPtr)
76{
77 unsigned char msd_data[QSER_MSD_MAX_LENGTH]={1,1,2,2,3,3,4,4};
78
79 printf("######### Call id=%d, event=%d! ######\n", callid, ind);
80
81 if(ind == E_QSER_VOICE_ECALL_IND_SENDING_START_IN_VOICE || ind == E_QSER_VOICE_ECALL_IND_PSAP_CALLBACK_START)
82 {
83 /*customer should construct msd including GPS data, here use msd_data for illustrate,*/
84 qser_voice_set_msd(callid,msd_data,8);
85 }
86}
87
88#endif
89
90
91void *dlHandle_call = NULL;
92
93static void yk_voice_call_cb_func(int call_id,
94 char* phone_num,
95 qser_voice_call_state_t state,
96 void *contextPtr)
97{
98 char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
99
100 printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n", call_id, phone_num, call_state[state]);
101}
102
103
104
105void print_help(void)
106{
107 int i;
108 printf("Supported test cases:\n");
109 for(i = 0; ; i++)
110 {
111 if(at_api_testcases[i].cmdIdx == -1)
112 {
113 break;
114 }
115 printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
116 }
117}
118
119
120
121int main(int argc, char const *argv[])
122{
123 int cmdIdx = 0;
124 int ret = 0;
125 int voice_call_id = 0;
126 voice_client_handle_type h_voice = 0;
xf.li39d99112024-09-28 04:05:58 -0700127 int audio_mode = 0;
xf.li3dd53742024-09-27 00:06:23 -0700128
129 const char *lynqLibPath_Call = "/lib/liblynq-qser-voice.so";
130 dlHandle_call = dlopen(lynqLibPath_Call, RTLD_NOW);
131 if (dlHandle_call == NULL)
132 {
133 printf("dlopen dlHandle_call failed: %s\n", dlerror());
134 exit(EXIT_FAILURE);
135 }
136
137 qser_voice_call_client_init = (int(*)(voice_client_handle_type *ph_voice))dlsym(dlHandle_call, "qser_voice_call_client_init");
138 if(qser_voice_call_client_init == NULL)
139 {
140 printf("qser_voice_call_client_init not defined or exported in %s\n", lynqLibPath_Call);
141 return -1;
142 }
143
144 qser_voice_call_addstatehandler = (int(*)(voice_client_handle_type h_voice,
145 QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
146 void *contextPtr))dlsym(dlHandle_call,"qser_voice_call_addstatehandler");
147 if(qser_voice_call_addstatehandler == NULL)
148 {
149 printf("qser_voice_call_addstatehandler not defined or exported in %s\n", lynqLibPath_Call);
150 return -1;
151 }
152
153 qser_voice_call_answer = (int(*)(voice_client_handle_type,int ))dlsym(dlHandle_call,"qser_voice_call_answer");
154 if(qser_voice_call_answer == NULL)
155 {
156 printf("qser_voice_call_answer not defined or exported in %s\n", lynqLibPath_Call);
157 return -1;
158 }
159
160 qser_voice_call_start = (int(*)(voice_client_handle_type h_voice,E_QSER_VCALL_ID_T simId,
161 char *phone_number, int *call_id))dlsym(dlHandle_call,"qser_voice_call_start");
162 if(qser_voice_call_start == NULL)
163 {
164 printf("qser_voice_call_start not defined or exported in %s\n", lynqLibPath_Call);
165 return -1;
166 }
167
168 qser_voice_call_end = (int(*)(voice_client_handle_type ,int))dlsym(dlHandle_call,"qser_voice_call_end");
169 if(qser_voice_call_end == NULL)
170 {
171 printf("qser_voice_call_end not defined or exported in %s\n", lynqLibPath_Call);
172 return -1;
173 }
174
175
176 qser_voice_call_client_deinit = (int (*)(voice_client_handle_type h_voice))dlsym(dlHandle_call,"qser_voice_call_client_deinit");
177 if(qser_voice_call_client_deinit == NULL)
178 {
179 printf("qser_voice_call_client_deinit not defined or exported in %s\n", lynqLibPath_Call);
180 return -1;
181 }
182
183 qser_voice_call_removestatehandle = (int (*)(voice_client_handle_type))dlsym(dlHandle_call,"qser_voice_call_removestatehandle");
184 if(qser_voice_call_removestatehandle == NULL)
185 {
186 printf("qser_voice_call_removestatehandle not defined or exported in %s\n", lynqLibPath_Call);
187 return -1;
188 }
189
190 qser_voice_set_speech_volume = (int (*)(const int ))dlsym(dlHandle_call,"qser_voice_set_speech_volume");
191 if(qser_voice_set_speech_volume == NULL)
192 {
193 printf("qser_voice_set_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
194 return -1;
195 }
196
197 qser_voice_get_speech_volume = (int (*)(int* ))dlsym(dlHandle_call,"qser_voice_get_speech_volume");
198 if(qser_voice_get_speech_volume == NULL)
199 {
200 printf("qser_voice_get_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
201 return -1;
202 }
203
204 qser_voice_set_dtmf = (int (*)(const char ))dlsym(dlHandle_call,"qser_voice_set_dtmf");
205 if(qser_voice_set_dtmf == NULL)
206 {
207 printf("qser_voice_set_dtmf not defined or exported in %s\n", lynqLibPath_Call);
208 return -1;
209 }
210
211#ifdef ECALL_SUPPORT
212 qser_voice_fast_ecall = (int (*)(voice_client_handle_type*, int*, E_QSER_VOICE_ECALL_CATEGORY_T, E_QSER_VOICE_ECALL_VARIANT_T, const char*, int, const unsigned char*, int))dlsym(dlHandle_call,"qser_voice_fast_ecall");
213 if(qser_voice_fast_ecall == NULL)
214 {
215 printf("qser_voice_fast_ecall not defined or exported in %s\n", lynqLibPath_Call);
216 return -1;
217 }
218
219 qser_voice_set_test_num = (int (*)(voice_client_handle_type*, E_QSER_VOICE_ECALL_SET_TYPE_T, const char* , int))dlsym(dlHandle_call,"qser_voice_set_test_num");
220 if(qser_voice_set_test_num == NULL)
221 {
222 printf("qser_voice_set_test_num not defined or exported in %s\n", lynqLibPath_Call);
223 return -1;
224 }
225
226 qser_voice_set_msd = (int (*)(int , const unsigned char *, int))dlsym(dlHandle_call,"qser_voice_set_msd");
227 if(qser_voice_set_msd == NULL)
228 {
229 printf("qser_voice_set_msd not defined or exported in %s\n", lynqLibPath_Call);
230 return -1;
231 }
232
233 qser_voice_add_ecall_indhandler = (int (*)(voice_client_handle_type* h_voice, QSER_ECall_IndHandlerFunc_t, void*))dlsym(dlHandle_call,"qser_voice_add_ecall_indhandler");
234 if(qser_voice_add_ecall_indhandler == NULL)
235 {
236 printf("qser_voice_add_ecall_indhandler not defined or exported in %s\n", lynqLibPath_Call);
237 return -1;
238 }
xf.li39d99112024-09-28 04:05:58 -0700239#endif
240
241 qser_voice_set_audio_mode = (int(*)(const int audio_mode))dlsym(dlHandle_call, "qser_voice_set_audio_mode");
242 if(qser_voice_set_audio_mode == NULL)
243 {
244 printf("qser_voice_set_audio_mode not defined or exported in %s\n", lynqLibPath_Call);
245 return -1;
246 }
247
248
249 qser_voice_get_audio_mode = (int(*)(int* audio_mode))dlsym(dlHandle_call, "qser_voice_get_audio_mode");
250 if(qser_voice_get_audio_mode == NULL)
251 {
252 printf("qser_voice_get_audio_mode not defined or exported in %s\n", lynqLibPath_Call);
253 return -1;
254 }
255
xf.li3dd53742024-09-27 00:06:23 -0700256
257 ret = qser_voice_call_client_init(&h_voice);
258 if(ret != 0 )
259 {
260 printf("qser_voice_call_client_init FAIL\n");
261 return -1;
262 }
263
264 ret = qser_voice_call_addstatehandler(h_voice, yk_voice_call_cb_func, &voice_call_id);
265 if(ret != 0)
266 {
267 printf("qser_voice_call_addstatehandler FAIL\n");
268 return -1;
269 }
270
271#ifdef ECALL_SUPPORT
272 ret = qser_voice_add_ecall_indhandler(&h_voice, yk_voice_ecall_cb_func, NULL);
273 if(ret != 0)
274 {
275 printf("qser_voice_add_ecall_indhandler FAIL\n");
276 return -1;
277 }
278#endif
279
280 print_help();
281 while(1)
282 {
283 printf("\nplease input cmd index(-1 exit): ");
284 scanf("%d", &cmdIdx);
285 if(cmdIdx == -1)
286 {
287 break;
288 }
289
290 switch(cmdIdx)
291 {
292 //"print_help
293 case 0:
294 print_help();
295 break;
296
297 //"qser_voice_call_start"
298 case 1:
299 {
300 char PhoneNum[32] = {0};
301
302 printf("please input dest phone number: \n");
303 scanf("%s", PhoneNum);
304
305 ret = qser_voice_call_start(h_voice, E_QSER_VCALL_EXTERNAL_SLOT_1, PhoneNum, &voice_call_id);
306 printf("qser_voice_call_start ret = %d, with voice_call_id=%d\n", ret, voice_call_id);
307 break;
308 }
309
310 //"qser_voice_call_end"
311 case 2:
312 {
313 int call_id = -1;
314 printf("please input end call id: \n");
315 scanf("%d", &call_id);
316 ret = qser_voice_call_end(h_voice, call_id);
317 printf(" ret = %d\n", ret);
318 break;
319 }
320
321 //"qser_voice_call_answer"
322 case 3:
323 {
324 int call_id = -1;
325 printf(" please input answer call id\n");
326 scanf("%d", &call_id);
327 ret = qser_voice_call_answer(h_voice, call_id);
328 printf(" ret = %d\n", ret);
329 break;
330 }
331
332 case 4:
333 {
334 int volume = 0;
335 printf("Please set speech volume:0-5 level\n");
336 scanf("%d",&volume);
337 ret = qser_voice_set_speech_volume(volume);
338 printf("ret is %d\n",ret);
339 break;
340
341 }
342
343 case 5:
344 {
345 int volume = -1;
346 printf("Enter get speech volume\n");
347 ret = qser_voice_get_speech_volume(&volume);
348 printf("ret is %d,get volume is %d\n",ret,volume);
349 break;
350
351 }
352 case 6:
353 {
354
355 int ret;
356 char inputChar;
357
358 printf("Enter set dtmf\n");
359 scanf(" %c", &inputChar);
360 printf("inputChar is %c\n", inputChar);
361 ret = qser_voice_set_dtmf(inputChar);
362
363 if (ret != 0)
364 {
365 printf("qser set voice dtmf failed\n");
366 return -1;
367 }
368 break;
369 }
370#ifdef ECALL_SUPPORT
371 case 7:
372 {
373 char PhoneNum[32] = {0};
xf.li39d99112024-09-28 04:05:58 -0700374 printf("please input test phone number(input null means \"\"): \n");
375 scanf("%s", PhoneNum);
376 if(0 == strcmp(PhoneNum, "null"))
377 {
378 PhoneNum[0]='\0';
379 }
xf.li3dd53742024-09-27 00:06:23 -0700380 ret = qser_voice_set_test_num(&h_voice, E_QSER_VOICE_ECALL_SET_NUMBER, PhoneNum, strlen(PhoneNum)+1);
381 printf("qser_voice_set_test_num ret = %d\n", ret);
382 break;
383 }
384 case 8:
385 {
386 int call_id = -1;
387 int cat;
388 int var;
389 int length;
390 unsigned char msd[QSER_MSD_MAX_LENGTH]={0};
391
392 printf("please input ecall cat: 0 manual, 1 auto\n");
393 scanf("%d", &cat);
394 printf("please input ecall type: 0 test, 1 emergency\n");
395 scanf("%d", &var);
396 printf("please input msd content length (max length is 140)\n");
397 scanf("%d", &length);
398 printf("please input %d unsigned char (0-255):\n", length);
399 for (int i = 0; i < length; i++) {
400 scanf("%hhu", &msd[i]);
401 }
402 ret = qser_voice_fast_ecall(&h_voice, &call_id, (E_QSER_VOICE_ECALL_CATEGORY_T) cat, (E_QSER_VOICE_ECALL_VARIANT_T) var, "null",5,msd,length);
403 printf("qser_voice_fast_ecall ret = %d, call id is %d\n", ret, call_id);
404 break;
405 }
406#endif
xf.li39d99112024-09-28 04:05:58 -0700407 case 9:
408 {
409
410 printf("please input voice audio mode: 0 codec, 1 rtp\n");
411 scanf("%d", &audio_mode);
412 ret = qser_voice_set_audio_mode(audio_mode);
413 printf("qser_voice_set_audio_mode ret = %d, audio_mode is %d\n", ret, audio_mode);
414 break;
415 }
416 case 10:
417 {
418 ret = qser_voice_get_audio_mode(&audio_mode);
419 printf("qser_voice_get_audio_mode ret = %d, audio_mode is %d\n", ret, audio_mode);
420 break;
421 }
422
xf.li3dd53742024-09-27 00:06:23 -0700423 default:
424 print_help();
425 break;
426 }
427
428 }
429
430 ret = qser_voice_call_removestatehandle(h_voice);
431 if(ret != 0 && ret != 1)
432 {
433 printf("qser_voice_call_removestatehandle FAIL!!!\n");
434 return -1;
435 }
436 printf("qser_voice_call_removestatehandle ret = %d\n", ret);
437
438
439 ret = qser_voice_call_client_deinit(h_voice);
440 if(ret != 0)
441 {
442 printf("qser_voice_call_client_deinit FAIL\n");
443 return -1;
444 }
445 printf("qser_voice_call_client_deinit ret = %d, with h_voice=%d\n", ret, h_voice);
446
447 return 0;
448
449
450}
451
452