ql_dev_demo.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 "ql_api_osi.h"
  16. #include "ql_log.h"
  17. #include "ql_api_dev.h"
  18. #include "ql_dev_demo.h"
  19. #include "ql_fs.h"
  20. #define QL_DEV_LOG_LEVEL QL_LOG_LEVEL_INFO
  21. #define QL_DEV_LOG(msg, ...) QL_LOG(QL_DEV_LOG_LEVEL, "ql_DEV", msg, ##__VA_ARGS__)
  22. #define QL_DEV_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_DEV", msg, ##__VA_ARGS__)
  23. #define QL_DEV_TASK_STACK_SIZE 2048
  24. #define QL_DEV_TASK_PRIO APP_PRIORITY_NORMAL
  25. #define QL_DEV_TASK_EVENT_CNT 5
  26. #define QL_CUSTOM_API_FOR_HK 0
  27. #if !defined(dev_demo_err_exit)
  28. #define dev_demo_err_exit(x, action, str) \
  29. do \
  30. { \
  31. if(x) \
  32. { \
  33. QL_DEV_LOG(str); \
  34. {goto action;} \
  35. } \
  36. } while( 1==0 )
  37. #endif
  38. /**
  39. 通过at+qfaccustnvm指令可以在生产时将关键数据存储到factory分区,通过ql_fac_cust_nvm_fread函数可读取存储的数据,
  40. 此处为示例:
  41. 发送AT指令:at+qfaccustnvm="hw_version","sn2" //可以存储10个字符串,此处只用了2个
  42. ql_dev_get_hw_version读取at指令写入的hw_verison //此处将ql_fac_cust_nvm_fread映射为ql_dev_get_hw_version
  43. ql_dev_get_sn2读取at指令写入的sn2 //此处将ql_fac_cust_nvm_fread映射为ql_dev_get_sn2
  44. **/
  45. #define ql_dev_get_hw_version(a,b,c) ql_fac_cust_nvm_fread(0,a,b,c)
  46. #define ql_dev_get_sn2(a,b,c) ql_fac_cust_nvm_fread(1,a,b,c)
  47. /*
  48. ql_get_dump_cnt/ql_clean_dump_cnt/ql_get_dump_file/ql_del_dump_file
  49. Customized API for HengKe
  50. */
  51. #if QL_CUSTOM_API_FOR_HK
  52. //get dump file
  53. void ql_get_dump_file()
  54. {
  55. ql_dump_info_t dump_info = {0};
  56. dump_info.dump_buffer = NULL;
  57. dump_info.length = 0;
  58. //先获取dump数据的真实大小
  59. if(ql_dev_get_dump_info(&dump_info))
  60. {
  61. return;
  62. }
  63. //根据返回的length去合理的申请buffer大小,再去读取数据到dump buffer中
  64. dump_info.dump_buffer = malloc(dump_info.length);
  65. if(NULL == dump_info.dump_buffer)
  66. {
  67. return;
  68. }
  69. memset(dump_info.dump_buffer, 0, dump_info.length);
  70. ql_dev_get_dump_info(&dump_info);
  71. QL_DEV_LOG("buffer_len=%d, dump_cnt=%d",dump_info.length, dump_info.current_dump_cnt);
  72. free(dump_info.dump_buffer);
  73. }
  74. //delete dump file
  75. void ql_del_dump_file()
  76. {
  77. ql_dump_config_t dump_config = {0};
  78. dump_config.save_dump_info = true;
  79. dump_config.del_dump_file = true;
  80. dump_config.max_dump_cnt = 100;
  81. dump_config.clean_dump_cnt = false;
  82. ql_dev_config_dump(&dump_config);
  83. }
  84. //get dump cnt
  85. int ql_get_dump_cnt()
  86. {
  87. ql_dump_info_t dump_info = {0};
  88. ql_dev_get_dump_info(&dump_info);
  89. return dump_info.current_dump_cnt;
  90. }
  91. //clean dump cnt
  92. void ql_clean_dump_cnt()
  93. {
  94. ql_dump_config_t dump_config = {0};
  95. dump_config.save_dump_info = true;
  96. dump_config.del_dump_file = false;
  97. dump_config.max_dump_cnt = 100;
  98. dump_config.clean_dump_cnt = true;
  99. ql_dev_config_dump(&dump_config);
  100. }
  101. #endif
  102. static void ql_dev_demo_thread(void *param)
  103. {
  104. QlOSStatus err = QL_OSI_SUCCESS;
  105. ql_errcode_dev_e ret = QL_DEV_SUCCESS;
  106. QL_DEV_LOG("dev demo thread enter, param 0x%x", param);
  107. for (int n = 0; n < 10; n++)
  108. {
  109. QL_DEV_LOG("hello dev demo %d", n);
  110. ql_rtos_task_sleep_ms(500);
  111. }
  112. char devinfo[64] = {0};
  113. ret = ql_dev_get_imei(devinfo, 64, 0);
  114. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "get imei err");
  115. QL_DEV_LOG("IMEI: %s", devinfo);
  116. ret = ql_dev_get_sn(devinfo, 64, 0);
  117. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "get sn err");
  118. QL_DEV_LOG("SN: %s", devinfo);
  119. ret = ql_dev_get_product_id(devinfo, 64);
  120. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "get pid err");
  121. QL_DEV_LOG("Product: %s", devinfo);
  122. ret = ql_dev_get_model(devinfo, 64);
  123. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "get model err");
  124. QL_DEV_LOG("Model: %s", devinfo);
  125. ret = ql_dev_get_firmware_version(devinfo, 64);
  126. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "get fire ver err");
  127. QL_DEV_LOG("FW: %s", devinfo);
  128. ret = ql_dev_get_firmware_subversion(devinfo, 64);
  129. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "get fire subver err");
  130. QL_DEV_LOG("subVer: %s", devinfo);
  131. uint8_t cfun = 0;
  132. ret = ql_dev_get_modem_fun(&cfun, 0);
  133. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "get mod fun err");
  134. QL_DEV_LOG("cfun: %d", cfun);
  135. ret = ql_dev_set_modem_fun(QL_DEV_CFUN_FULL, 0, 0);
  136. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "set mod fun err");
  137. //ql_log_set_port(QL_LOG_PORT_USB);//set the log port as USB AP port
  138. int32_t ql_temp = 0;
  139. ret = ql_dev_get_temp_value(&ql_temp);
  140. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "get temp val err");
  141. QL_DEV_LOG("TEMP: %d", ql_temp);
  142. #if QL_CUSTOM_API_FOR_HK
  143. //factory nv example
  144. char hw_version[64] = {0};
  145. ql_dev_get_hw_version(hw_version, 64, 1);
  146. QL_DEV_LOG("hw_version: %s", hw_version);
  147. //factory nv example
  148. char sn2[64] = {0};
  149. ql_dev_get_sn2(sn2, 64, 1);
  150. QL_DEV_LOG("sn2: %s", sn2);
  151. ql_rtos_task_sleep_s(5);
  152. //enable save dump info to file system
  153. ql_dump_config_t dump_config = {0};
  154. dump_config.save_dump_info = true;
  155. dump_config.del_dump_file = false;
  156. dump_config.max_dump_cnt = 100;
  157. dump_config.clean_dump_cnt = false;
  158. ret = ql_dev_config_dump(&dump_config);
  159. dev_demo_err_exit(ret != QL_DEV_SUCCESS, QL_DEV_DEMO_EXIT, "cfg dump err");
  160. //get dump file
  161. ql_get_dump_file();
  162. //get dump cnt
  163. int dump_cnt = ql_get_dump_cnt();
  164. QL_DEV_LOG("dump_cnt=%d", dump_cnt);
  165. //delete dump file
  166. ql_del_dump_file();
  167. //clean dump cnt
  168. ql_clean_dump_cnt();
  169. #endif
  170. QL_DEV_DEMO_EXIT:
  171. err = ql_rtos_task_delete(NULL);
  172. if(err != QL_OSI_SUCCESS)
  173. {
  174. QL_DEV_LOG("task deleted failed");
  175. }
  176. }
  177. void ql_dev_app_init(void)
  178. {
  179. QlOSStatus err = QL_OSI_SUCCESS;
  180. ql_task_t dev_task = NULL;
  181. err = ql_rtos_task_create(&dev_task, QL_DEV_TASK_STACK_SIZE, QL_DEV_TASK_PRIO, "QDEVDEMO", ql_dev_demo_thread, NULL, QL_DEV_TASK_EVENT_CNT);
  182. if (err != QL_OSI_SUCCESS)
  183. {
  184. QL_DEV_LOG("dev demo task created failed");
  185. }
  186. }