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