vsim_img_init.c 5.1 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 "ql_log.h"
  16. #include "ql_api_osi.h"
  17. #include "ql_api_vsim_adapt.h"
  18. #include "quec_at_engine.h"
  19. #include "quec_at_param.h"
  20. #include "quec_atresp.h"
  21. #define QL_VSIM_IMG_LOG_LEVEL QL_LOG_LEVEL_INFO
  22. #define QL_VSIM_IMG_LOG(msg, ...) QL_LOG(QL_VSIM_IMG_LOG_LEVEL, "ql_vsim_img", msg, ##__VA_ARGS__)
  23. #define QL_VSIM_IMG_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_vsim_img", msg, ##__VA_ARGS__)
  24. static ql_task_t vsim_task = NULL;
  25. static void prvInvokeGlobalCtors(void)
  26. {
  27. extern void (*__init_array_start[])();
  28. extern void (*__init_array_end[])();
  29. size_t count = __init_array_end - __init_array_start;
  30. for (size_t i = 0; i < count; ++i)
  31. __init_array_start[i]();
  32. }
  33. static void vsim_app_thread(void *arg)
  34. {
  35. QlOSStatus err = 0;
  36. QL_VSIM_IMG_LOG("==============vsim adapt demo start==============");
  37. ql_rtos_task_sleep_s(10);
  38. QL_VSIM_IMG_LOG("==============vsim adapt demo end================");
  39. err = ql_rtos_task_delete(NULL);
  40. if (err != QL_OSI_SUCCESS)
  41. {
  42. QL_VSIM_IMG_LOG("task deleted failed");
  43. }
  44. }
  45. void ql_exec_vsimdemo_cmd(ql_at_cmd_t *cmd)
  46. {
  47. if (cmd->type == AT_CMD_SET)
  48. {
  49. // how to extract parameter, please refer to at_param.h
  50. // eg:
  51. // quec_atParamUintInList: to extract uint parameter, and check in list
  52. // quec_atParamUintInRange: to extract uint parameter, and check range
  53. // quec_atParamStr: to extract string parameter
  54. // quec_atParamInt: to extract int parameter
  55. // quec_atParamDefInt: to extract optional int parameter with default value
  56. //......
  57. // ========================= parameter extract demo ==============================
  58. // bool paramok = true;
  59. // const char *data_str = quec_atParamStr(cmd->params[0], &paramok);
  60. // unsigned short major = quec_atParamUintInRange(cmd->params[1], 0, 65535, &paramok);
  61. // int temp_val =quec_atParamInt(cmd->params[2],&paramok);
  62. // int scheme = quec_atParamDefInt(cmd->params[3], 0x04, &paramok);
  63. // const uint32_t list[] = {4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600};
  64. // uint32_t baud = quec_atParamUintInList(cmd->params[4], list, sizeof(list) / sizeof(list[0]), &paramok);
  65. // ......
  66. // =================================================================================
  67. bool paramok = true;
  68. const char *input_str = quec_atParamStr(cmd->params[0], &paramok);
  69. if ((cmd->param_count != 1) || !paramok)
  70. {
  71. quec_atCmdResp(cmd->engine, ATCI_RESULT_CODE_CME_ERROR, ERR_AT_CME_PARAM_INVALID);
  72. }
  73. quec_atCmdRespInfoNText(cmd->engine, input_str, strlen(input_str), 1);
  74. quec_atCmdResp(cmd->engine, ATCI_RESULT_CODE_OK, CMD_RC_OK);
  75. }
  76. else if (cmd->type == AT_CMD_READ)
  77. {
  78. quec_atResp(cmd->engine, ATCI_RESULT_CODE_OK, CMD_RC_OK, "vsimdemo read resp", 1);
  79. }
  80. else if (cmd->type == AT_CMD_TEST)
  81. {
  82. quec_atCmdResp(cmd->engine, ATCI_RESULT_CODE_OK, CMD_RC_OK);
  83. }
  84. else
  85. {
  86. quec_atCmdResp(cmd->engine, ATCI_RESULT_CODE_CME_ERROR, ERR_AT_CME_OPTION_NOT_SURPORT);
  87. }
  88. }
  89. int vsim_poweron_enter(uint32_t ind_type, void *ctx)
  90. {
  91. switch (ind_type)
  92. {
  93. case QUEC_VSIM_ADAPT_POWERON_IND:
  94. QL_VSIM_IMG_LOG( "set sim:%d to physical sim", 0);
  95. ql_vsim_adapt_set_sim_type(QL_VSIM_ADAPT_SIM_TYPE_TSIM, NULL, 0);
  96. break;
  97. case QUEC_VSIM_ADAPT_RDY_IND: {
  98. QlOSStatus err = QL_OSI_SUCCESS;
  99. err = ql_rtos_task_create(&vsim_task, 4 * 1024, APP_PRIORITY_NORMAL, "VSIM", vsim_app_thread, NULL, 5);
  100. if (err != QL_OSI_SUCCESS)
  101. {
  102. QL_VSIM_IMG_LOG( "vsim_adapt_app init failed");
  103. }
  104. }
  105. break;
  106. default:
  107. break;
  108. }
  109. return 0;
  110. }
  111. ql_at_desc_t app_at_desc[] = {
  112. {"+VSIMDEMO", ql_exec_vsimdemo_cmd, 0},
  113. //==>Warning: Please add new vsim AT cmd upper this line!!
  114. {NULL, NULL, 0}};
  115. int appimg_enter(void *param)
  116. {
  117. QL_VSIM_IMG_LOG("vsim image demo enter");
  118. prvInvokeGlobalCtors();
  119. /* register AT lookup table */
  120. quec_app_at_add((const ql_at_desc_t *)app_at_desc, sizeof(app_at_desc)/sizeof(app_at_desc[0]));
  121. /* register VSIM event handler */
  122. ql_vsim_adapt_register_callback(vsim_poweron_enter);
  123. return 0;
  124. }
  125. void appimg_exit(void)
  126. {
  127. QL_VSIM_IMG_LOG("init demo exit");
  128. }