blob: 41c5c97355a9b2e3395b2aee05eb8935786a2c71 [file] [log] [blame]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <pthread.h>
#include <unistd.h>
#include <dlfcn.h>
#include <stdint.h>
#include"lynq-qser-voice-demo.h"
typedef struct
{
int cmdIdx;
char *funcName;
} st_api_test_case;
//for server test
st_api_test_case at_api_testcases[] =
{
{0, "print_help"},
{1, "qser_voice_call_start"},
{2, "qser_voice_call_end"},
{3, "qser_voice_call_answer"},
{4, "qser_voice_set_speech_volume"},
{5, "qser_voice_get_speech_volume"},
{6, "qser_voice_set_dtmf"},
#ifdef ECALL_SUPPORT
{7, "qser_voice_set_test_num"},
{8, "qser_voice_fast_ecall"},
#endif
{-1, NULL}
};
typedef uint32_t voice_client_handle_type;
int (*qser_voice_call_client_init)(voice_client_handle_type *ph_voice);
int (*qser_voice_call_client_deinit)(voice_client_handle_type );
int (*qser_voice_call_addstatehandler)(voice_client_handle_type h_voice,
QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
void *contextPtr);
int (*qser_voice_call_removestatehandle)(voice_client_handle_type );
int (*qser_voice_call_start)(voice_client_handle_type h_voice,
E_QSER_VCALL_ID_T simId,
char *phone_number, int *call_id);
int (*qser_voice_call_end)(voice_client_handle_type ,int );
int (*qser_voice_call_answer)(voice_client_handle_type ,int );
int (*qser_voice_set_speech_volume)(const int volume);
int (*qser_voice_get_speech_volume)(int *volume);
int (*qser_voice_set_dtmf)(const char callnum);
#ifdef ECALL_SUPPORT
int (*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);
int (*qser_voice_fast_ecall)(voice_client_handle_type* h_voice,
int *call_id,
E_QSER_VOICE_ECALL_CATEGORY_T cat,
E_QSER_VOICE_ECALL_VARIANT_T variant,
const char *addr,
int addr_length,
const unsigned char *msd_data,
int msd_length); //msd_length should <= QSER_MSD_MAX_LENGTH
int (*qser_voice_set_msd)(int callid, const unsigned char *msd_data, int msd_length); //msd_length should <= QSER_MSD_MAX_LENGTH
int (*qser_voice_add_ecall_indhandler)(voice_client_handle_type* h_voice,
QSER_ECall_IndHandlerFunc_t handlerPtr,
void* contextPtr);
static void yk_voice_ecall_cb_func(int callid, E_QSER_VOICE_ECALL_INDICATION_T ind, void* contextPtr)
{
unsigned char msd_data[QSER_MSD_MAX_LENGTH]={1,1,2,2,3,3,4,4};
printf("######### Call id=%d, event=%d! ######\n", callid, ind);
if(ind == E_QSER_VOICE_ECALL_IND_SENDING_START_IN_VOICE || ind == E_QSER_VOICE_ECALL_IND_PSAP_CALLBACK_START)
{
/*customer should construct msd including GPS data, here use msd_data for illustrate,*/
qser_voice_set_msd(callid,msd_data,8);
}
}
#endif
void *dlHandle_call = NULL;
static void yk_voice_call_cb_func(int call_id,
char* phone_num,
qser_voice_call_state_t state,
void *contextPtr)
{
char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"};
printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n", call_id, phone_num, call_state[state]);
}
void print_help(void)
{
int i;
printf("Supported test cases:\n");
for(i = 0; ; i++)
{
if(at_api_testcases[i].cmdIdx == -1)
{
break;
}
printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName);
}
}
int main(int argc, char const *argv[])
{
int cmdIdx = 0;
int ret = 0;
int voice_call_id = 0;
voice_client_handle_type h_voice = 0;
const char *lynqLibPath_Call = "/lib/liblynq-qser-voice.so";
dlHandle_call = dlopen(lynqLibPath_Call, RTLD_NOW);
if (dlHandle_call == NULL)
{
printf("dlopen dlHandle_call failed: %s\n", dlerror());
exit(EXIT_FAILURE);
}
qser_voice_call_client_init = (int(*)(voice_client_handle_type *ph_voice))dlsym(dlHandle_call, "qser_voice_call_client_init");
if(qser_voice_call_client_init == NULL)
{
printf("qser_voice_call_client_init not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_call_addstatehandler = (int(*)(voice_client_handle_type h_voice,
QSER_VoiceCall_StateHandlerFunc_t handlerPtr,
void *contextPtr))dlsym(dlHandle_call,"qser_voice_call_addstatehandler");
if(qser_voice_call_addstatehandler == NULL)
{
printf("qser_voice_call_addstatehandler not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_call_answer = (int(*)(voice_client_handle_type,int ))dlsym(dlHandle_call,"qser_voice_call_answer");
if(qser_voice_call_answer == NULL)
{
printf("qser_voice_call_answer not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_call_start = (int(*)(voice_client_handle_type h_voice,E_QSER_VCALL_ID_T simId,
char *phone_number, int *call_id))dlsym(dlHandle_call,"qser_voice_call_start");
if(qser_voice_call_start == NULL)
{
printf("qser_voice_call_start not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_call_end = (int(*)(voice_client_handle_type ,int))dlsym(dlHandle_call,"qser_voice_call_end");
if(qser_voice_call_end == NULL)
{
printf("qser_voice_call_end not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_call_client_deinit = (int (*)(voice_client_handle_type h_voice))dlsym(dlHandle_call,"qser_voice_call_client_deinit");
if(qser_voice_call_client_deinit == NULL)
{
printf("qser_voice_call_client_deinit not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_call_removestatehandle = (int (*)(voice_client_handle_type))dlsym(dlHandle_call,"qser_voice_call_removestatehandle");
if(qser_voice_call_removestatehandle == NULL)
{
printf("qser_voice_call_removestatehandle not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_set_speech_volume = (int (*)(const int ))dlsym(dlHandle_call,"qser_voice_set_speech_volume");
if(qser_voice_set_speech_volume == NULL)
{
printf("qser_voice_set_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_get_speech_volume = (int (*)(int* ))dlsym(dlHandle_call,"qser_voice_get_speech_volume");
if(qser_voice_get_speech_volume == NULL)
{
printf("qser_voice_get_speech_volume not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_set_dtmf = (int (*)(const char ))dlsym(dlHandle_call,"qser_voice_set_dtmf");
if(qser_voice_set_dtmf == NULL)
{
printf("qser_voice_set_dtmf not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
#ifdef ECALL_SUPPORT
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");
if(qser_voice_fast_ecall == NULL)
{
printf("qser_voice_fast_ecall not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
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");
if(qser_voice_set_test_num == NULL)
{
printf("qser_voice_set_test_num not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
qser_voice_set_msd = (int (*)(int , const unsigned char *, int))dlsym(dlHandle_call,"qser_voice_set_msd");
if(qser_voice_set_msd == NULL)
{
printf("qser_voice_set_msd not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
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");
if(qser_voice_add_ecall_indhandler == NULL)
{
printf("qser_voice_add_ecall_indhandler not defined or exported in %s\n", lynqLibPath_Call);
return -1;
}
#endif
ret = qser_voice_call_client_init(&h_voice);
if(ret != 0 )
{
printf("qser_voice_call_client_init FAIL\n");
return -1;
}
ret = qser_voice_call_addstatehandler(h_voice, yk_voice_call_cb_func, &voice_call_id);
if(ret != 0)
{
printf("qser_voice_call_addstatehandler FAIL\n");
return -1;
}
#ifdef ECALL_SUPPORT
ret = qser_voice_add_ecall_indhandler(&h_voice, yk_voice_ecall_cb_func, NULL);
if(ret != 0)
{
printf("qser_voice_add_ecall_indhandler FAIL\n");
return -1;
}
#endif
print_help();
while(1)
{
printf("\nplease input cmd index(-1 exit): ");
scanf("%d", &cmdIdx);
if(cmdIdx == -1)
{
break;
}
switch(cmdIdx)
{
//"print_help
case 0:
print_help();
break;
//"qser_voice_call_start"
case 1:
{
char PhoneNum[32] = {0};
printf("please input dest phone number: \n");
scanf("%s", PhoneNum);
ret = qser_voice_call_start(h_voice, E_QSER_VCALL_EXTERNAL_SLOT_1, PhoneNum, &voice_call_id);
printf("qser_voice_call_start ret = %d, with voice_call_id=%d\n", ret, voice_call_id);
break;
}
//"qser_voice_call_end"
case 2:
{
int call_id = -1;
printf("please input end call id: \n");
scanf("%d", &call_id);
ret = qser_voice_call_end(h_voice, call_id);
printf(" ret = %d\n", ret);
break;
}
//"qser_voice_call_answer"
case 3:
{
int call_id = -1;
printf(" please input answer call id\n");
scanf("%d", &call_id);
ret = qser_voice_call_answer(h_voice, call_id);
printf(" ret = %d\n", ret);
break;
}
case 4:
{
int volume = 0;
printf("Please set speech volume:0-5 level\n");
scanf("%d",&volume);
ret = qser_voice_set_speech_volume(volume);
printf("ret is %d\n",ret);
break;
}
case 5:
{
int volume = -1;
printf("Enter get speech volume\n");
ret = qser_voice_get_speech_volume(&volume);
printf("ret is %d,get volume is %d\n",ret,volume);
break;
}
case 6:
{
int ret;
char inputChar;
printf("Enter set dtmf\n");
scanf(" %c", &inputChar);
printf("inputChar is %c\n", inputChar);
ret = qser_voice_set_dtmf(inputChar);
if (ret != 0)
{
printf("qser set voice dtmf failed\n");
return -1;
}
break;
}
#ifdef ECALL_SUPPORT
case 7:
{
char PhoneNum[32] = {0};
printf("please input test phone number: \n");
scanf("%s", PhoneNum);
ret = qser_voice_set_test_num(&h_voice, E_QSER_VOICE_ECALL_SET_NUMBER, PhoneNum, strlen(PhoneNum)+1);
printf("qser_voice_set_test_num ret = %d\n", ret);
break;
}
case 8:
{
int call_id = -1;
int cat;
int var;
int length;
unsigned char msd[QSER_MSD_MAX_LENGTH]={0};
printf("please input ecall cat: 0 manual, 1 auto\n");
scanf("%d", &cat);
printf("please input ecall type: 0 test, 1 emergency\n");
scanf("%d", &var);
printf("please input msd content length (max length is 140)\n");
scanf("%d", &length);
printf("please input %d unsigned char (0-255):\n", length);
for (int i = 0; i < length; i++) {
scanf("%hhu", &msd[i]);
}
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);
printf("qser_voice_fast_ecall ret = %d, call id is %d\n", ret, call_id);
break;
}
#endif
default:
print_help();
break;
}
}
ret = qser_voice_call_removestatehandle(h_voice);
if(ret != 0 && ret != 1)
{
printf("qser_voice_call_removestatehandle FAIL!!!\n");
return -1;
}
printf("qser_voice_call_removestatehandle ret = %d\n", ret);
ret = qser_voice_call_client_deinit(h_voice);
if(ret != 0)
{
printf("qser_voice_call_client_deinit FAIL\n");
return -1;
}
printf("qser_voice_call_client_deinit ret = %d, with h_voice=%d\n", ret, h_voice);
return 0;
}