mms_demo.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*================================================================
  2. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  3. Quectel Wireless Solution Proprietary and Confidential.
  4. =================================================================*/
  5. /*=================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ------------ ------- -------------------------------------------------------------------------------
  11. =================================================================*/
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include <stdint.h>
  16. #include <time.h>
  17. #include "ql_api_osi.h"
  18. #include "ql_api_nw.h"
  19. #include "ql_fs.h"
  20. #include "ql_log.h"
  21. #include "ql_api_datacall.h"
  22. #include "ql_mms_client.h"
  23. #define QL_MMS_LOG_LEVEL QL_LOG_LEVEL_INFO
  24. #define QL_MMS_LOG(msg, ...) QL_LOG(QL_MMS_LOG_LEVEL, "ql_MMS_DEMO", msg, ##__VA_ARGS__)
  25. #define QL_MMS_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_MMS_DEMO", msg, ##__VA_ARGS__)
  26. static ql_task_t mms_task = NULL;
  27. static ql_mms_client mms_cli_hndl = 0;
  28. static ql_sem_t mms_semp;
  29. static void mms_result_cb(ql_mms_client client_hndl, int mms_result, int http_code, char *mms_err_msg, void *arg)
  30. {
  31. if(mms_cli_hndl != client_hndl)
  32. return;
  33. QL_MMS_LOG("mms send result: %d,http_code:%d", mms_result, http_code);
  34. ql_rtos_semaphore_release(mms_semp);
  35. }
  36. static void mms_app_thread(void * arg)
  37. {
  38. int ret = 0;
  39. int i = 0, run_num = 1;
  40. int profile_idx = 2;
  41. ql_data_call_info_s info;
  42. char ip4_addr_str[16] = {0};
  43. uint8_t nSim = 0;
  44. QFILE fd;
  45. ql_rtos_task_sleep_s(20);
  46. QL_MMS_LOG("==========mms demo start ==========");
  47. QL_MMS_LOG("wait for network register done");
  48. ql_rtos_semaphore_create(&mms_semp, 0);
  49. while((ret = ql_network_register_wait(nSim, 120)) != 0 && i < 10){
  50. i++;
  51. ql_rtos_task_sleep_s(1);
  52. }
  53. if(ret == 0){
  54. i = 0;
  55. QL_MMS_LOG("====network registered!!!!====");
  56. }else{
  57. QL_MMS_LOG("====network register failure!!!!!====");
  58. goto exit;
  59. }
  60. ql_set_data_call_asyn_mode(nSim, profile_idx, 0);
  61. QL_MMS_LOG("===start data call====");
  62. ret=ql_start_data_call(nSim, profile_idx, QL_PDP_TYPE_IP, "ctwap", NULL, NULL, 0);
  63. QL_MMS_LOG("===data call result:%d", ret);
  64. if(ret != 0){
  65. QL_MMS_LOG("====data call failure!!!!=====");
  66. }
  67. memset(&info, 0x00, sizeof(ql_data_call_info_s));
  68. ret = ql_get_data_call_info(nSim, profile_idx, &info);
  69. if(ret != 0){
  70. QL_MMS_LOG("ql_get_data_call_info ret: %d", ret);
  71. ql_stop_data_call(nSim, profile_idx);
  72. goto exit;
  73. }
  74. QL_MMS_LOG("info->profile_idx: %d", info.profile_idx);
  75. QL_MMS_LOG("info->ip_version: %d", info.ip_version);
  76. QL_MMS_LOG("info->v4.state: %d", info.v4.state);
  77. inet_ntop(AF_INET, &info.v4.addr.ip, ip4_addr_str, sizeof(ip4_addr_str));
  78. QL_MMS_LOG("info.v4.addr.ip: %s\r\n", ip4_addr_str);
  79. inet_ntop(AF_INET, &info.v4.addr.pri_dns, ip4_addr_str, sizeof(ip4_addr_str));
  80. QL_MMS_LOG("info.v4.addr.pri_dns: %s\r\n", ip4_addr_str);
  81. inet_ntop(AF_INET, &info.v4.addr.sec_dns, ip4_addr_str, sizeof(ip4_addr_str));
  82. QL_MMS_LOG("info.v4.addr.sec_dns: %s\r\n", ip4_addr_str);
  83. fd = ql_fopen("UFS:test.txt","w+");
  84. ql_fwrite("123456789",9,1,fd);
  85. ql_fclose(fd);
  86. ret = ql_mms_client_new(&mms_cli_hndl, mms_result_cb, NULL);
  87. QL_MMS_LOG("creat mms client ret:%d",ret);
  88. if(ret != QL_MMS_OK){
  89. goto exit;
  90. }
  91. while(run_num <= 20){
  92. struct mms_option_t send_option;
  93. struct mms_info_t msg_info;
  94. struct mms_subject_t mms_subject;
  95. struct mms_addr_t to_addr[2];
  96. struct mms_addr_t cc_addr[2];
  97. struct mms_addr_t bcc_addr[2];
  98. struct mms_attachment_t attachment;
  99. QL_MMS_LOG("==============mms_test[%d]================\n",run_num);
  100. memset(&send_option, 0x00, sizeof(struct mms_option_t));
  101. memset(&msg_info, 0x00, sizeof(struct mms_info_t));
  102. memset(&mms_subject, 0x00, sizeof(struct mms_subject_t));
  103. memset(&to_addr[0], 0x00, sizeof(struct mms_addr_t)*2);
  104. memset(&cc_addr[0], 0x00, sizeof(struct mms_addr_t)*2);
  105. memset(&bcc_addr[0], 0x00, sizeof(struct mms_addr_t)*2);
  106. memset(&attachment, 0x00, sizeof(struct mms_attachment_t));
  107. send_option.charset = MMS_CHARSET_ASCII_VALUE;
  108. send_option.wait_timeout = 60;
  109. send_option.context_id = profile_idx;
  110. send_option.sim_id = 0;
  111. send_option.mmsc_url = "http://mmsc.vnet.mobi";
  112. send_option.proxy_addr = "10.0.0.200";
  113. send_option.proxy_port = 80;
  114. send_option.send_param.class = MMS_PARAM_CLASS_DEFAULT;
  115. send_option.send_param.validity_period = MMS_PARAM_VALID_DEFAULT;
  116. send_option.send_param.priority = MMS_PARAM_PRIORITY_HIGHEST;
  117. send_option.send_param.delivery_report = 0;
  118. send_option.send_param.read_report = 0;
  119. send_option.send_param.visible = MMS_PARAM_SENDERADDR_DEFAULT;
  120. send_option.supportfield = 0;
  121. mms_subject.subject = "test mms";
  122. mms_subject.length = strlen("test mms");
  123. msg_info.subject = &mms_subject;
  124. to_addr[0].address = "18225658934";
  125. to_addr[0].addr_len = strlen("18225658934");
  126. to_addr[0].next =NULL;
  127. msg_info.to_addr = &(to_addr[0]);
  128. attachment.file_path = "UFS:test.txt";
  129. attachment.next = NULL;
  130. msg_info.attachments = &attachment;
  131. if(ql_mms_client_send_msg(&mms_cli_hndl, &send_option, &msg_info) == QL_MMS_OK){
  132. QL_MMS_LOG("===wait mms send complete=====");
  133. ql_rtos_semaphore_wait(mms_semp, QL_WAIT_FOREVER);
  134. }
  135. QL_MMS_LOG("==============mms_test_end[%d]================\n",run_num);
  136. run_num++;
  137. ql_rtos_task_sleep_s(1);
  138. }
  139. ql_mms_client_release(&mms_cli_hndl);
  140. exit:
  141. ql_stop_data_call(nSim, profile_idx);
  142. ql_rtos_semaphore_delete(mms_semp);
  143. ql_rtos_task_delete(mms_task);
  144. return;
  145. }
  146. int ql_mms_app_init(void)
  147. {
  148. QlOSStatus err = QL_OSI_SUCCESS;
  149. err = ql_rtos_task_create(&mms_task, 16*1024, APP_PRIORITY_ABOVE_NORMAL, "QmmsApp", mms_app_thread, NULL, 5);
  150. if(err != QL_OSI_SUCCESS)
  151. {
  152. QL_MMS_LOG("mms_app init failed");
  153. }
  154. return err;
  155. }