ctsreg_demo.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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_log.h"
  20. #include "ql_api_datacall.h"
  21. #include "ql_ctsreg.h"
  22. #define QL_CTSREG_LOG_LEVEL QL_LOG_LEVEL_INFO
  23. #define QL_CTSREG_LOG(msg, ...) QL_LOG(QL_CTSREG_LOG_LEVEL, "ql_ctsreg_DEMO", msg, ##__VA_ARGS__)
  24. #define QL_CTSREG_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_ctsreg_DEMO", msg, ##__VA_ARGS__)
  25. static ql_task_t ctsreg_task = NULL;
  26. static ql_ctsreg_hndl ctsreg_cli = 0;
  27. static ql_sem_t ctsreg_semp;
  28. static ql_ctsreg_param_t reg_param = {
  29. {"EC200U\0"},
  30. {"EC200UR01A01M2G\0"},
  31. {"89860318145512192783\0"},
  32. {"861687000001091\0"},
  33. {"460110934876073\0"},
  34. {"DD8A30B\0"},
  35. {"2020 11 20 14:15:15\0"}
  36. };
  37. static ql_ctsreg_option_t reg_option = {
  38. 1, 0, "zzhc.vnet.cn",9999, "\0", 1, 3, 60, 1
  39. };
  40. static void ctsreg_state_cb_fcn(ql_ctsreg_hndl cli_hndl, int state_code, int finished, void *arg)
  41. {
  42. QL_CTSREG_LOG("ctsreg state: %d, finished:%d", state_code, finished);
  43. if(finished){
  44. ql_rtos_semaphore_release(ctsreg_semp);
  45. ctsreg_cli = 0;
  46. }
  47. }
  48. static void ctsreg_app_thread(void * arg)
  49. {
  50. int ret = 0;
  51. int i = 0, run_num = 1;
  52. int profile_idx = 1;
  53. ql_data_call_info_s info;
  54. char ip4_addr_str[16] = {0};
  55. uint8_t sim_id = 0;
  56. ql_rtos_task_sleep_s(10);
  57. QL_CTSREG_LOG("==========lbs demo start ==========");
  58. QL_CTSREG_LOG("wait for network register done");
  59. ql_rtos_semaphore_create(&ctsreg_semp, 0);
  60. while((ret = ql_network_register_wait(sim_id, 120)) != 0 && i < 10){
  61. i++;
  62. ql_rtos_task_sleep_s(1);
  63. }
  64. if(ret == 0){
  65. i = 0;
  66. QL_CTSREG_LOG("====network registered!!!!====");
  67. }else{
  68. QL_CTSREG_LOG("====network register failure!!!!!====");
  69. goto exit;
  70. }
  71. ql_set_data_call_asyn_mode(sim_id, profile_idx, 0);
  72. QL_CTSREG_LOG("===start data call====");
  73. ret=ql_start_data_call(sim_id, profile_idx, QL_PDP_TYPE_IP, "uninet", NULL, NULL, 0);
  74. QL_CTSREG_LOG("===data call result:%d", ret);
  75. if(ret != 0){
  76. QL_CTSREG_LOG("====data call failure!!!!=====");
  77. }
  78. memset(&info, 0x00, sizeof(ql_data_call_info_s));
  79. ret = ql_get_data_call_info(sim_id, profile_idx, &info);
  80. if(ret != 0){
  81. QL_CTSREG_LOG("ql_get_data_call_info ret: %d", ret);
  82. ql_stop_data_call(sim_id, profile_idx);
  83. goto exit;
  84. }
  85. QL_CTSREG_LOG("info->profile_idx: %d", info.profile_idx);
  86. QL_CTSREG_LOG("info->ip_version: %d", info.ip_version);
  87. QL_CTSREG_LOG("info->v4.state: %d", info.v4.state);
  88. inet_ntop(AF_INET, &info.v4.addr.ip, ip4_addr_str, sizeof(ip4_addr_str));
  89. QL_CTSREG_LOG("info.v4.addr.ip: %s\r\n", ip4_addr_str);
  90. inet_ntop(AF_INET, &info.v4.addr.pri_dns, ip4_addr_str, sizeof(ip4_addr_str));
  91. QL_CTSREG_LOG("info.v4.addr.pri_dns: %s\r\n", ip4_addr_str);
  92. inet_ntop(AF_INET, &info.v4.addr.sec_dns, ip4_addr_str, sizeof(ip4_addr_str));
  93. QL_CTSREG_LOG("info.v4.addr.sec_dns: %s\r\n", ip4_addr_str);
  94. while(run_num <= 200){
  95. int error_num = 0;
  96. QL_CTSREG_LOG("==============ctsreg_test[%d]================\n",run_num);
  97. reg_option.contextid = profile_idx;
  98. ctsreg_cli = ql_ctsreg_perform(&reg_option, &reg_param, ctsreg_state_cb_fcn, NULL, &error_num);
  99. if(ctsreg_cli != 0){
  100. ql_rtos_semaphore_wait(ctsreg_semp, QL_WAIT_FOREVER);
  101. }else{
  102. QL_CTSREG_LOG("ctsreg failed");
  103. }
  104. QL_CTSREG_LOG("==============ctsreg_test_end[%d]================\n",run_num);
  105. run_num++;
  106. //ql_rtos_task_sleep_s(1);
  107. }
  108. exit:
  109. ql_rtos_semaphore_delete(ctsreg_semp);
  110. ql_rtos_task_delete(ctsreg_task);
  111. return;
  112. }
  113. int ql_ctsreg_app_init(void)
  114. {
  115. QlOSStatus err = QL_OSI_SUCCESS;
  116. err = ql_rtos_task_create(&ctsreg_task, 5*1024, APP_PRIORITY_ABOVE_NORMAL, "ctsreg_app", ctsreg_app_thread, NULL, 5);
  117. if(err != QL_OSI_SUCCESS)
  118. {
  119. QL_CTSREG_LOG("ctsreg_app init failed");
  120. }
  121. return err;
  122. }