liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame^] | 1 | #include "mbtk_type.h" |
| 2 | #include "ql/ql_at.h" |
| 3 | #include "ql/ql_vcall.h" |
| 4 | #include "ql/ql_mcm_call.h" |
| 5 | |
| 6 | typedef struct |
| 7 | { |
| 8 | int cmdIdx; |
| 9 | char *funcName; |
| 10 | } st_api_test_case; |
| 11 | |
| 12 | //for server test |
| 13 | st_api_test_case at_api_testcases[] = |
| 14 | { |
| 15 | {0, "print_help"}, |
| 16 | {1, "QL_Voice_Call_Ecall"}, |
| 17 | {2, "QL_Voice_Call_Ecall_HangUp"}, |
| 18 | |
| 19 | {-1, NULL} |
| 20 | }; |
| 21 | |
| 22 | void print_help(void) |
| 23 | { |
| 24 | int i; |
| 25 | |
| 26 | printf("Supported test cases:\n"); |
| 27 | for(i = 0; ; i++) |
| 28 | { |
| 29 | if(at_api_testcases[i].cmdIdx == -1) |
| 30 | { |
| 31 | break; |
| 32 | } |
| 33 | printf("%d:\t%s\n", at_api_testcases[i].cmdIdx, at_api_testcases[i].funcName); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | static void ql_voice_call_ind_func(unsigned int ind_id, |
| 38 | void* ind_data, |
| 39 | uint32_t ind_data_len) |
| 40 | { |
| 41 | if(NULL == ind_data) |
| 42 | { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | switch(ind_id) |
| 47 | { |
| 48 | case E_QL_MCM_VOICE_CALL_IND: |
| 49 | { |
| 50 | if(ind_data_len != sizeof(ql_mcm_voice_call_ind)) |
| 51 | { |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | ql_mcm_voice_call_ind *pVoiceCallInd = (ql_mcm_voice_call_ind*)ind_data; |
| 56 | |
| 57 | char *call_state[] = {"INCOMING", "DIALING", "ALERTING", "ACTIVE", "HOLDING", "END", "WAITING"}; |
| 58 | |
| 59 | int i = 0; |
| 60 | for(i = 0; i < pVoiceCallInd->calls_len; i++) |
| 61 | { |
| 62 | printf("######### Call id=%d, PhoneNum:%s, event=%s! ######\n", |
| 63 | pVoiceCallInd->calls[i].call_id, pVoiceCallInd->calls[i].number, call_state[pVoiceCallInd->calls[i].state]); |
| 64 | } |
| 65 | |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | case E_QL_MCM_VOICE_ECALL_STATUE_IND: |
| 70 | { |
| 71 | if(ind_data_len != sizeof(ql_mcm_voice_ecall_status_ind)) |
| 72 | { |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | ql_mcm_voice_ecall_status_ind *pEcallStatusInd |
| 77 | = (ql_mcm_voice_ecall_status_ind*)ind_data; |
| 78 | |
| 79 | if (pEcallStatusInd->ecall_msd_tx_status_valid) |
| 80 | { |
| 81 | if (pEcallStatusInd->ecall_msd_tx_status == E_QL_MCM_VOICE_ECALL_MSD_TRANSMISSION_STATUS_SUCCESS) |
| 82 | { |
| 83 | printf("========== Ecall status call_id =%d , ecall msd tx success.\r\n", pEcallStatusInd->call_id); |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | printf("========== Ecall status call_id =%d , ecall msd tx failure.\r\n", pEcallStatusInd->call_id); |
| 88 | } |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | printf("========== Ecall status call_id =%d \r\n", pEcallStatusInd->call_id); |
| 93 | } |
| 94 | |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | case E_QL_MCM_VOICE_UNKOWN_IND: |
| 99 | default: |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | #if 0 |
| 105 | int main(int argc, char *argv[]) |
| 106 | { |
| 107 | int cmdIdx = 0; |
| 108 | int ret = E_QL_OK; |
| 109 | char phoneNum[32] = {0}; |
| 110 | voice_client_handle_type h_voice = 0; |
| 111 | int voice_call_id = 0; |
| 112 | |
| 113 | printf("QL_Voice_Call_Client_Init .....\n"); |
| 114 | ret = QL_Voice_Call_Client_Init(&h_voice); |
| 115 | if(ret < 0) |
| 116 | { |
| 117 | printf("QL_Voice_Call_Client_Init FAIL. ret:%d\n",ret); |
| 118 | return -1; |
| 119 | } |
| 120 | printf("QL_Voice_Call_Client_Init ret = %d, with h_voice=%d\n", ret, h_voice); |
| 121 | |
| 122 | ret = QL_Voice_Call_AddCommonStateHandler(h_voice, (QL_VoiceCall_CommonStateHandlerFunc_t)ql_voice_call_ind_func); |
| 123 | if(ret < 0) |
| 124 | { |
| 125 | printf("QL_Voice_Call_AddCommonStateHandler FAIL. ret:%d\n",ret); |
| 126 | return -1; |
| 127 | } |
| 128 | printf("QL_Voice_Call_AddCommonStateHandler ret = %d\n", ret); |
| 129 | |
| 130 | print_help(); |
| 131 | |
| 132 | while(1) |
| 133 | { |
| 134 | printf("please input cmd index(-1 exit): "); |
| 135 | scanf("%d", &cmdIdx); |
| 136 | if(cmdIdx == -1) |
| 137 | { |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | switch(cmdIdx) |
| 142 | { |
| 143 | case 0://"print_help" |
| 144 | { |
| 145 | print_help(); |
| 146 | break; |
| 147 | } |
| 148 | case 1://"QL_Voice_Call_Ecall" |
| 149 | { |
| 150 | char PhoneNum[32] = {0}; |
| 151 | printf("please input dest phone number: \n"); |
| 152 | scanf("%s", PhoneNum); |
| 153 | |
| 154 | char msd[140+1] = {0}; |
| 155 | printf("please input msd content: \n"); |
| 156 | scanf("%s", msd); |
| 157 | |
| 158 | E_QL_MCM_ECALL_VARIANT_T ecall_mode; |
| 159 | printf("please input ecall mode(1:test 2:emergency): \n"); |
| 160 | scanf("%d", &ecall_mode); |
| 161 | QL_Voice_Call_Start(h_voice, E_QL_VCALL_EXTERNAL_SLOT_1, PhoneNum, NULL); |
| 162 | // ret = QL_Voice_Call_Ecall(h_voice, E_QL_VCALL_EXTERNAL_SLOT_1, PhoneNum, |
| 163 | // ecall_mode, &voice_call_id); |
| 164 | printf(" voice_call_id = %d\n", voice_call_id); |
| 165 | printf(" ret = %d\n", ret); |
| 166 | break; |
| 167 | } |
| 168 | case 2://QL_Voice_Call_Ecall_HangUp |
| 169 | { |
| 170 | ret = QL_Voice_Call_Ecall_HangUp(h_voice); |
| 171 | printf(" ret = %d\n", ret); |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | default: |
| 176 | print_help(); |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | ret = QL_Voice_Call_RemoveCommonStateHandler(h_voice); |
| 182 | if(ret < 0) |
| 183 | { |
| 184 | printf("QL_Voice_Call_RemoveCommonStateHandler. ret:%d\n",ret); |
| 185 | return -1; |
| 186 | } |
| 187 | printf("QL_Voice_Call_RemoveCommonStateHandler ret = %d\n", ret); |
| 188 | |
| 189 | ret = QL_Voice_Call_Client_Deinit(h_voice); |
| 190 | if(ret < 0) |
| 191 | { |
| 192 | printf("QL_Voice_Call_Client_Deinit FAIL. ret:%d\n",ret); |
| 193 | return -1; |
| 194 | } |
| 195 | printf("QL_Voice_Call_Client_Deinit ret = %d, with h_voice=%d\n", ret, h_voice); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | #else |
| 200 | |
| 201 | int main(int argc, char *argv[]) |
| 202 | { |
| 203 | char operator[10]; |
| 204 | int opt; |
| 205 | int ret = E_QL_OK; |
| 206 | char phoneNum[32] = {0}; |
| 207 | voice_client_handle_type h_voice = 0; |
| 208 | |
| 209 | while(1) |
| 210 | { |
| 211 | printf("=========call main=========\n" |
| 212 | "\t0 exit\n" |
| 213 | "\t1 call init\n" |
| 214 | "\t2 call register handle\n" |
| 215 | "\t3 call start\n" |
| 216 | "\t4 call end\n" |
| 217 | "\t5 call answer\n" |
| 218 | "\t6 call set auto answer\n" |
| 219 | "\t7 call hold\n" |
| 220 | "\t8 call unhold\n" |
| 221 | "\t9 call deinit\n" |
| 222 | "operator: >> "); |
| 223 | |
| 224 | fgets(operator, sizeof(operator), stdin); |
| 225 | fflush(stdin); |
| 226 | opt = atoi(operator); |
| 227 | switch (opt) |
| 228 | { |
| 229 | case 0: |
| 230 | printf("main exit\n"); |
| 231 | return 0; |
| 232 | case 1: |
| 233 | ret = QL_Voice_Call_Client_Init(&h_voice); |
| 234 | if(ret < 0) |
| 235 | { |
| 236 | printf("QL_Voice_Call_Client_Init FAIL. ret:%d\n",ret); |
| 237 | return -1; |
| 238 | } |
| 239 | printf("QL_Voice_Call_Client_Init ret = %d, with h_voice=%d\n", ret, h_voice); |
| 240 | |
| 241 | break; |
| 242 | case 2: |
| 243 | ret = QL_Voice_Call_AddCommonStateHandler(h_voice, (QL_VoiceCall_CommonStateHandlerFunc_t)ql_voice_call_ind_func); |
| 244 | if(ret < 0) |
| 245 | { |
| 246 | printf("QL_Voice_Call_AddCommonStateHandler FAIL. ret:%d\n",ret); |
| 247 | return -1; |
| 248 | } |
| 249 | break; |
| 250 | case 3: |
| 251 | QL_Voice_Call_Start(h_voice, 0, "15982066434", NULL); |
| 252 | break; |
| 253 | case 4: |
| 254 | QL_Voice_Call_End(h_voice, 0); |
| 255 | break; |
| 256 | case 5: |
| 257 | QL_Voice_Call_Answer(h_voice, 0); |
| 258 | break; |
| 259 | case 6: |
| 260 | QL_Voice_Call_SetAutoAnswer(h_voice, E_QL_MCM_VOICE_AUTO_ANSWER_ENABLE, 6000); |
| 261 | break; |
| 262 | case 7: |
| 263 | QL_Voice_Call_Hold(h_voice); |
| 264 | break; |
| 265 | case 8: |
| 266 | QL_Voice_Call_UnHold(h_voice); |
| 267 | break; |
| 268 | case 9: |
| 269 | QL_Voice_Call_Client_Deinit(h_voice); |
| 270 | break; |
| 271 | case 10: |
| 272 | // QL_Voice_Call_UnHold; |
| 273 | break; |
| 274 | default: |
| 275 | break; |
| 276 | } |
| 277 | |
| 278 | sleep(1); |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | #endif |