lbs_demo.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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_lbs_client.h"
  22. #define QL_LBS_LOG_LEVEL QL_LOG_LEVEL_INFO
  23. #define QL_LBS_LOG(msg, ...) QL_LOG(QL_LBS_LOG_LEVEL, "ql_LBS_DEMO", msg, ##__VA_ARGS__)
  24. #define QL_LBS_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_LBS_DEMO", msg, ##__VA_ARGS__)
  25. static ql_task_t lbs_task = NULL;
  26. static lbs_client_hndl lbs_cli = 0;
  27. static ql_sem_t lbs_semp;
  28. static lbs_basic_info_t basic_info = {
  29. .type = 1,
  30. .encrypt = 1,
  31. .key_index = 1,
  32. .pos_format = 1,
  33. .loc_method = 4
  34. };
  35. static lbs_auth_info_t auth_info = {
  36. .user_name = "quectel",
  37. .user_pwd = "123456",
  38. .token = "1111111122222222",//"A693EDC90C42E624",
  39. .imei = "861687000001091",
  40. .rand = 2346
  41. };
  42. static lbs_cell_info_t lbs_cell_info[] = {
  43. {
  44. .radio = 3,
  45. .mcc = 460,
  46. .mnc = 0,
  47. .lac_id = 0x550B,
  48. .cell_id = 0xF2D4A48,
  49. .signal = 0,
  50. .tac = 3,
  51. .bcch = 0,
  52. .bsic = 0,
  53. .uarfcndl = 0,
  54. .psc = 0,
  55. .rsrq = 0,
  56. .pci = 0,
  57. .earfcn = 0
  58. }
  59. };
  60. static void lbs_result_cb(lbs_response_data_t *response_data)
  61. {
  62. int i = 0;
  63. if(NULL == response_data || lbs_cli != response_data->hndl)
  64. {
  65. return;
  66. }
  67. QL_LBS_LOG("lbs result: %08X", response_data->result);
  68. if(response_data->result == QL_LBS_OK){
  69. for(i = 0; i < response_data->pos_num; i++){
  70. QL_LBS_LOG("Location[%d]: %f, %f, %d\n", i, response_data->pos_info[i].longitude,
  71. response_data->pos_info[i].latitude, response_data->pos_info[i].accuracy);
  72. }
  73. }
  74. ql_rtos_semaphore_release(lbs_semp);
  75. }
  76. static void lbs_app_thread(void * arg)
  77. {
  78. int ret = 0;
  79. int i = 0, run_num = 1;
  80. int profile_idx = 1;
  81. ql_data_call_info_s info;
  82. char ip4_addr_str[16] = {0};
  83. uint8_t nSim = 0;
  84. ql_nw_cell_info_s cell_info;
  85. ql_nw_seclection_info_s select_info;
  86. ql_rtos_task_sleep_s(10);
  87. QL_LBS_LOG("==========lbs demo start ==========");
  88. QL_LBS_LOG("wait for network register done");
  89. ql_rtos_semaphore_create(&lbs_semp, 0);
  90. while((ret = ql_network_register_wait(nSim, 120)) != 0 && i < 10){
  91. i++;
  92. ql_rtos_task_sleep_s(1);
  93. }
  94. if(ret == 0){
  95. i = 0;
  96. QL_LBS_LOG("====network registered!!!!====");
  97. }else{
  98. QL_LBS_LOG("====network register failure!!!!!====");
  99. goto exit;
  100. }
  101. ql_set_data_call_asyn_mode(nSim, profile_idx, 0);
  102. QL_LBS_LOG("===start data call====");
  103. ret=ql_start_data_call(nSim, profile_idx, QL_PDP_TYPE_IP, "uninet", NULL, NULL, 0);
  104. QL_LBS_LOG("===data call result:%d", ret);
  105. if(ret != 0){
  106. QL_LBS_LOG("====data call failure!!!!=====");
  107. }
  108. memset(&info, 0x00, sizeof(ql_data_call_info_s));
  109. ret = ql_get_data_call_info(nSim, profile_idx, &info);
  110. if(ret != 0){
  111. QL_LBS_LOG("ql_get_data_call_info ret: %d", ret);
  112. ql_stop_data_call(nSim, profile_idx);
  113. goto exit;
  114. }
  115. QL_LBS_LOG("info->profile_idx: %d", info.profile_idx);
  116. QL_LBS_LOG("info->ip_version: %d", info.ip_version);
  117. QL_LBS_LOG("info->v4.state: %d", info.v4.state);
  118. inet_ntop(AF_INET, &info.v4.addr.ip, ip4_addr_str, sizeof(ip4_addr_str));
  119. QL_LBS_LOG("info.v4.addr.ip: %s\r\n", ip4_addr_str);
  120. inet_ntop(AF_INET, &info.v4.addr.pri_dns, ip4_addr_str, sizeof(ip4_addr_str));
  121. QL_LBS_LOG("info.v4.addr.pri_dns: %s\r\n", ip4_addr_str);
  122. inet_ntop(AF_INET, &info.v4.addr.sec_dns, ip4_addr_str, sizeof(ip4_addr_str));
  123. QL_LBS_LOG("info.v4.addr.sec_dns: %s\r\n", ip4_addr_str);
  124. while(run_num <= 100){
  125. lbs_option_t user_option;
  126. QL_LBS_LOG("==============lbs_test[%d]================\n",run_num);
  127. if(ql_nw_get_cell_info(nSim, &cell_info)!=QL_NW_SUCCESS)
  128. {
  129. QL_LBS_LOG("===============lbs get cell info fail===============\n");
  130. continue;
  131. }
  132. ret = ql_nw_get_selection(nSim, &select_info);
  133. if(ret != 0){
  134. QL_LBS_LOG("ql_nw_get_selection ret: %d", ret);
  135. goto exit;
  136. }
  137. QL_LBS_LOG("nw_act_type=%d",select_info.act);
  138. if(select_info.act==QL_NW_ACCESS_TECH_GSM)
  139. {
  140. lbs_cell_info[0].radio=1;
  141. lbs_cell_info[0].mcc = cell_info.gsm_info[0].mcc;
  142. lbs_cell_info[0].mnc = cell_info.gsm_info[0].mnc;
  143. lbs_cell_info[0].cell_id = cell_info.gsm_info[0].cid;
  144. lbs_cell_info[0].lac_id = cell_info.gsm_info[0].lac;
  145. lbs_cell_info[0].bsic = cell_info.gsm_info[0].bsic;
  146. lbs_cell_info[0].uarfcndl = cell_info.gsm_info[0].arfcn;
  147. lbs_cell_info[0].bcch = cell_info.gsm_info[0].arfcn;
  148. lbs_cell_info[0].signal=cell_info.gsm_info[0].rssi;
  149. }
  150. else if(select_info.act==QL_NW_ACCESS_TECH_E_UTRAN)
  151. {
  152. lbs_cell_info[0].radio=3;
  153. lbs_cell_info[0].mcc = cell_info.lte_info[0].mcc;
  154. lbs_cell_info[0].mnc = cell_info.lte_info[0].mnc;
  155. lbs_cell_info[0].cell_id = cell_info.lte_info[0].cid;
  156. lbs_cell_info[0].lac_id = cell_info.lte_info[0].tac;
  157. lbs_cell_info[0].tac = cell_info.lte_info[0].tac;
  158. lbs_cell_info[0].pci = cell_info.lte_info[0].pci;
  159. lbs_cell_info[0].earfcn = cell_info.lte_info[0].earfcn;
  160. lbs_cell_info[0].bcch = cell_info.lte_info[0].earfcn;
  161. lbs_cell_info[0].signal=cell_info.lte_info[0].rssi;
  162. }
  163. else
  164. {
  165. goto exit;
  166. }
  167. QL_LBS_LOG("cell infoinfo: radio=%d,mcc=%d,mnc=%d,lac_id=%x,cell_id=%x,signal=%d,tac =%x,bcch=%d,bsic=%d,uarfcndl=%d,psc=%d,rsrq=%d,pci=%d,earfcn=%d",\
  168. lbs_cell_info[0].radio,lbs_cell_info[0].mcc,lbs_cell_info[0].mnc,lbs_cell_info[0].lac_id,lbs_cell_info[0].cell_id,lbs_cell_info[0].signal,lbs_cell_info[0].tac,\
  169. lbs_cell_info[0].bcch,lbs_cell_info[0].bsic,lbs_cell_info[0].uarfcndl,lbs_cell_info[0].psc,lbs_cell_info[0].rsrq,lbs_cell_info[0].pci,lbs_cell_info[0].earfcn);
  170. memset(&user_option, 0x00, sizeof(lbs_option_t));
  171. user_option.pdp_cid = profile_idx;
  172. user_option.sim_id = 0;
  173. user_option.req_timeout = 60;
  174. user_option.basic_info = &basic_info;
  175. user_option.auth_info = &auth_info;
  176. user_option.cell_num = 1;
  177. user_option.cell_info = &lbs_cell_info[0];
  178. if(QL_LBS_OK == ql_lbs_get_position(&lbs_cli, "www.queclocator.com", &user_option, lbs_result_cb, NULL)){
  179. ql_rtos_semaphore_wait(lbs_semp, QL_WAIT_FOREVER);
  180. }else{
  181. QL_LBS_LOG("lbs failed");
  182. }
  183. QL_LBS_LOG("==============lbs_test_end[%d]================\n",run_num);
  184. run_num++;
  185. ql_rtos_task_sleep_s(1);
  186. }
  187. exit:
  188. ql_rtos_semaphore_delete(lbs_semp);
  189. ql_rtos_task_delete(lbs_task);
  190. return;
  191. }
  192. int ql_lbs_app_init(void)
  193. {
  194. QlOSStatus err = QL_OSI_SUCCESS;
  195. err = ql_rtos_task_create(&lbs_task, 16*1024, APP_PRIORITY_ABOVE_NORMAL, "QlbsApp", lbs_app_thread, NULL, 5);
  196. if(err != QL_OSI_SUCCESS)
  197. {
  198. QL_LBS_LOG("lbs_app init failed");
  199. }
  200. return err;
  201. }