b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 1 | #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"
|
r.xiao | d5764fb | 2024-04-07 00:30:29 -0700 | [diff] [blame] | 11 | #include "mbtk_log.h"
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 12 |
|
| 13 | typedef struct
|
| 14 | {
|
| 15 | int cmdIdx;
|
| 16 | char *funcName;
|
| 17 | } st_api_test_case;
|
| 18 |
|
| 19 | //for server test
|
| 20 | st_api_test_case at_api_testcases[] =
|
| 21 | {
|
| 22 | {0, "print_help"},
|
| 23 | {1, "qser_voice_call_start"},
|
| 24 | {2, "qser_voice_call_end"},
|
| 25 | {3, "qser_voice_call_answer"},
|
| 26 | {4, "qser_voice_set_speech_volume"},
|
| 27 | {5, "qser_voice_get_speech_volume"},
|
| 28 | {6, "qser_voice_set_dtmf"},
|
| 29 | {-1, NULL}
|
| 30 | };
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 | typedef uint32_t voice_client_handle_type;
|
| 35 |
|
| 36 |
|
| 37 | int (*qser_voice_call_client_init)(voice_client_handle_type *ph_voice);
|
| 38 | int (*qser_voice_call_client_deinit)(voice_client_handle_type );
|
| 39 | int (*qser_voice_call_addstatehandler)(voice_client_handle_type h_voice,
|
| 40 | QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
|
| 41 | void *contextPtr);
|
| 42 |
|
| 43 | int (*qser_voice_call_removestatehandle)(voice_client_handle_type );
|
| 44 | int (*qser_voice_call_start)(voice_client_handle_type h_voice,
|
| 45 | E_QSER_VCALL_ID_T simId,
|
| 46 | char *phone_number, int *call_id);
|
| 47 |
|
| 48 | int (*qser_voice_call_end)(voice_client_handle_type ,int );
|
| 49 | int (*qser_voice_call_answer)(voice_client_handle_type ,int );
|
| 50 | int (*qser_voice_set_speech_volume)(const int volume);
|
| 51 | int (*qser_voice_get_speech_volume)(int *volume);
|
| 52 | int (*qser_voice_set_dtmf)(const char callnum);
|
| 53 |
|
| 54 | void *dlHandle_call = NULL;
|
| 55 |
|
| 56 | static void yk_voice_call_cb_func(int call_id,
|
| 57 | char* phone_num,
|
| 58 | qser_voice_call_state_t state,
|
| 59 | void *contextPtr)
|
| 60 | {
|
| 61 | char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
|
| 62 |
|
| 63 | printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n", call_id, phone_num, call_state[state]);
|
| 64 | }
|
| 65 |
|
| 66 | void print_help(void)
|
| 67 | {
|
| 68 | int i;
|
| 69 | printf("Supported test cases:\n");
|
| 70 | for(i = 0; ; i++)
|
| 71 | {
|
| 72 | if(at_api_testcases[i].cmdIdx == -1)
|
| 73 | {
|
| 74 | break;
|
| 75 | }
|
| 76 | printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
|
| 77 | }
|
| 78 | }
|
| 79 |
|
| 80 | int main(int argc, char const *argv[])
|
| 81 | {
|
| 82 | int cmdIdx = 0;
|
| 83 | int ret = 0;
|
| 84 | int voice_call_id = 0;
|
| 85 | voice_client_handle_type h_voice = 0;
|
r.xiao | d5764fb | 2024-04-07 00:30:29 -0700 | [diff] [blame] | 86 |
|
| 87 | mbtk_log_init("radio", "MBTK");
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 88 |
|
| 89 | const char *lynqLibPath_Call = "/lib/liblynq-qser-voice.so";
|
| 90 | dlHandle_call = dlopen(lynqLibPath_Call, RTLD_NOW);
|
| 91 | if (dlHandle_call == NULL)
|
| 92 | {
|
| 93 | printf("dlopen dlHandle_call failed: %s\n", dlerror());
|
| 94 | exit(EXIT_FAILURE);
|
| 95 | }
|
| 96 |
|
r.xiao | d5764fb | 2024-04-07 00:30:29 -0700 | [diff] [blame] | 97 | qser_voice_call_client_init = (int(*)(voice_client_handle_type *h_voice))dlsym(dlHandle_call, "qser_voice_call_client_init");
|
b.liu | 8583dce | 2024-04-03 13:30:08 +0800 | [diff] [blame] | 98 | if(qser_voice_call_client_init == NULL)
|
| 99 | {
|
| 100 | printf("qser_voice_call_client_init not defined or exported in %s\n", lynqLibPath_Call);
|
| 101 | return -1;
|
| 102 | }
|
| 103 |
|
| 104 | qser_voice_call_addstatehandler = (int(*)(voice_client_handle_type h_voice,
|
| 105 | QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
|
| 106 | void *contextPtr))dlsym(dlHandle_call,"qser_voice_call_addstatehandler");
|
| 107 | if(qser_voice_call_addstatehandler == NULL)
|
| 108 | {
|
| 109 | printf("qser_voice_call_addstatehandler not defined or exported in %s\n", lynqLibPath_Call);
|
| 110 | return -1;
|
| 111 | }
|
| 112 |
|
| 113 | qser_voice_call_answer = (int(*)(voice_client_handle_type,int ))dlsym(dlHandle_call,"qser_voice_call_answer");
|
| 114 | if(qser_voice_call_answer == NULL)
|
| 115 | {
|
| 116 | printf("qser_voice_call_answer not defined or exported in %s\n", lynqLibPath_Call);
|
| 117 | return -1;
|
| 118 | }
|
| 119 |
|
| 120 | qser_voice_call_start = (int(*)(voice_client_handle_type h_voice,E_QSER_VCALL_ID_T simId,
|
| 121 | char *phone_number, int *call_id))dlsym(dlHandle_call,"qser_voice_call_start");
|
| 122 | if(qser_voice_call_start == NULL)
|
| 123 | {
|
| 124 | printf("qser_voice_call_start not defined or exported in %s\n", lynqLibPath_Call);
|
| 125 | return -1;
|
| 126 | }
|
| 127 |
|
| 128 | qser_voice_call_end = (int(*)(voice_client_handle_type ,int))dlsym(dlHandle_call,"qser_voice_call_end");
|
| 129 | if(qser_voice_call_end == NULL)
|
| 130 | {
|
| 131 | printf("qser_voice_call_end not defined or exported in %s\n", lynqLibPath_Call);
|
| 132 | return -1;
|
| 133 | }
|
| 134 |
|
| 135 |
|
| 136 | qser_voice_call_client_deinit = (int (*)(voice_client_handle_type h_voice))dlsym(dlHandle_call,"qser_voice_call_client_deinit");
|
| 137 | if(qser_voice_call_client_deinit == NULL)
|
| 138 | {
|
| 139 | printf("qser_voice_call_client_deinit not defined or exported in %s\n", lynqLibPath_Call);
|
| 140 | return -1;
|
| 141 | }
|
| 142 |
|
| 143 | qser_voice_call_removestatehandle = (int (*)(voice_client_handle_type))dlsym(dlHandle_call,"qser_voice_call_removestatehandle");
|
| 144 | if(qser_voice_call_removestatehandle == NULL)
|
| 145 | {
|
| 146 | printf("qser_voice_call_removestatehandle not defined or exported in %s\n", lynqLibPath_Call);
|
| 147 | return -1;
|
| 148 | }
|
| 149 |
|
| 150 | qser_voice_set_speech_volume = (int (*)(const int ))dlsym(dlHandle_call,"qser_voice_set_speech_volume");
|
| 151 | if(qser_voice_set_speech_volume == NULL)
|
| 152 | {
|
| 153 | printf("qser_voice_set_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
|
| 154 | return -1;
|
| 155 | }
|
| 156 |
|
| 157 | qser_voice_get_speech_volume = (int (*)(int* ))dlsym(dlHandle_call,"qser_voice_get_speech_volume");
|
| 158 | if(qser_voice_get_speech_volume == NULL)
|
| 159 | {
|
| 160 | printf("qser_voice_get_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
|
| 161 | return -1;
|
| 162 | }
|
| 163 |
|
| 164 | qser_voice_set_dtmf = (int (*)(const char ))dlsym(dlHandle_call,"qser_voice_set_dtmf");
|
| 165 | if(qser_voice_set_dtmf == NULL)
|
| 166 | {
|
| 167 | printf("qser_voice_set_dtmf not defined or exported in %s\n", lynqLibPath_Call);
|
| 168 | return -1;
|
| 169 | }
|
| 170 |
|
| 171 | ret = qser_voice_call_client_init(&h_voice);
|
| 172 | if(ret != 0 )
|
| 173 | {
|
| 174 | printf("qser_voice_call_client_init FAIL\n");
|
| 175 | return -1;
|
| 176 | }
|
| 177 |
|
| 178 | ret = qser_voice_call_addstatehandler(h_voice, yk_voice_call_cb_func, &voice_call_id);
|
| 179 | if(ret != 0)
|
| 180 | {
|
| 181 | printf("qser_voice_call_addstatehandler FAIL\n");
|
| 182 | return -1;
|
| 183 | }
|
| 184 |
|
| 185 |
|
| 186 | print_help();
|
| 187 | while(1)
|
| 188 | {
|
| 189 | printf("\nplease input cmd index(-1 exit): ");
|
| 190 | scanf("%d", &cmdIdx);
|
| 191 | if(cmdIdx == -1)
|
| 192 | {
|
| 193 | break;
|
| 194 | }
|
| 195 |
|
| 196 | switch(cmdIdx)
|
| 197 | {
|
| 198 | //"print_help
|
| 199 | case 0:
|
| 200 | print_help();
|
| 201 | break;
|
| 202 |
|
| 203 | //"qser_voice_call_start"
|
| 204 | case 1:
|
| 205 | {
|
| 206 | char PhoneNum[32] = {0};
|
| 207 |
|
| 208 | printf("please input dest phone number: \n");
|
| 209 | scanf("%s", PhoneNum);
|
| 210 |
|
| 211 | ret = qser_voice_call_start(h_voice, E_QSER_VCALL_EXTERNAL_SLOT_1, PhoneNum, &voice_call_id);
|
| 212 | printf("qser_voice_call_start ret = %d, with voice_call_id=%d\n", ret, voice_call_id);
|
| 213 | break;
|
| 214 | }
|
| 215 |
|
| 216 | //"qser_voice_call_end"
|
| 217 | case 2:
|
| 218 | {
|
| 219 | int call_id = -1;
|
| 220 | printf("please input end call id: \n");
|
| 221 | scanf("%d", &call_id);
|
| 222 | ret = qser_voice_call_end(h_voice, call_id);
|
| 223 | printf(" ret = %d\n", ret);
|
| 224 | break;
|
| 225 | }
|
| 226 |
|
| 227 | //"qser_voice_call_answer"
|
| 228 | case 3:
|
| 229 | {
|
| 230 | int call_id = -1;
|
| 231 | printf(" please input answer call id\n");
|
| 232 | scanf("%d", &call_id);
|
| 233 | ret = qser_voice_call_answer(h_voice, call_id);
|
| 234 | printf(" ret = %d\n", ret);
|
| 235 | break;
|
| 236 | }
|
| 237 |
|
| 238 | case 4:
|
| 239 | {
|
| 240 | int volume = 0;
|
| 241 | printf("Please set speech volume:0-5 level\n");
|
| 242 | scanf("%d",&volume);
|
| 243 | ret = qser_voice_set_speech_volume(volume);
|
| 244 | printf("ret is %d\n",ret);
|
| 245 | break;
|
| 246 |
|
| 247 | }
|
| 248 |
|
| 249 | case 5:
|
| 250 | {
|
| 251 | int volume = -1;
|
| 252 | printf("Enter get speech volume\n");
|
| 253 | ret = qser_voice_get_speech_volume(&volume);
|
| 254 | printf("ret is %d,get volume is %d\n",ret,volume);
|
| 255 | break;
|
| 256 |
|
| 257 | }
|
| 258 | case 6:
|
| 259 | {
|
| 260 |
|
| 261 | int ret;
|
| 262 | char inputChar;
|
| 263 |
|
| 264 | printf("Enter set dtmf\n");
|
| 265 | scanf(" %c", &inputChar);
|
| 266 | printf("inputChar is %c\n", inputChar);
|
| 267 | ret = qser_voice_set_dtmf(inputChar);
|
| 268 |
|
| 269 | if (ret != 0)
|
| 270 | {
|
| 271 | printf("qser set voice dtmf failed\n");
|
| 272 | return -1;
|
| 273 | }
|
| 274 | break;
|
| 275 | }
|
| 276 |
|
| 277 | default:
|
| 278 | print_help();
|
| 279 | break;
|
| 280 | }
|
| 281 |
|
| 282 | }
|
| 283 |
|
| 284 | ret = qser_voice_call_removestatehandle(h_voice);
|
| 285 | if(ret != 0 && ret != 1)
|
| 286 | {
|
| 287 | printf("qser_voice_call_removestatehandle FAIL!!!\n");
|
| 288 | return -1;
|
| 289 | }
|
| 290 | printf("qser_voice_call_removestatehandle ret = %d\n", ret);
|
| 291 |
|
| 292 |
|
| 293 | ret = qser_voice_call_client_deinit(h_voice);
|
| 294 | if(ret != 0)
|
| 295 | {
|
| 296 | printf("qser_voice_call_client_deinit FAIL\n");
|
| 297 | return -1;
|
| 298 | }
|
| 299 | printf("qser_voice_call_client_deinit ret = %d, with h_voice=%d\n", ret, h_voice);
|
| 300 |
|
| 301 | return 0;
|
| 302 |
|
| 303 |
|
| 304 | }
|
| 305 |
|
| 306 |
|