test_cli.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "includes.h"
  2. #include <stdarg.h>
  3. #include <ctype.h>
  4. #include "macro_common.h"
  5. #include "trace.h"
  6. #include "console.h"
  7. extern S_CLI_CMD_LIST g_cli_cmd_list;
  8. int g_db_on;
  9. /*lint -save -e715*/
  10. /*extern int enable_show_cmd_cmd(u8 argc,const char **argv);*/
  11. /*lint -restore*/
  12. DEFCLICMD(enable_show_cmd_cmd,enable_show_cmd_struct,
  13. "list","List all command string")
  14. {
  15. u8 i = 0;
  16. NO_USE(argc);
  17. NO_USE(argv);
  18. for( i = 0; i < g_cli_cmd_list.num;i++ )
  19. {
  20. (void)cmd_out("%s"NEWLINE,((PS_CLI_CMD)(g_cli_cmd_list.cmd[i]))->cmd);
  21. (void)cmd_out(" %s"NEWLINE,((PS_CLI_CMD)(g_cli_cmd_list.cmd[i]))->description);
  22. }
  23. return 0;
  24. }
  25. /*extern int enable_cmd_help_cmd(u8 argc,const char **argv);*/
  26. /*lint -save -e818*/
  27. DEFCLICMD(enable_cmd_help_cmd,enable_cmd_help_struct,
  28. "help CMDSTRING", "show help")
  29. {
  30. u8 i = 0;
  31. if(argc < 2)
  32. {
  33. (void)cmd_out("Argument -1!"NEWLINE);
  34. return -1;
  35. }
  36. for( i = 0; i < g_cli_cmd_list.num;i++ )
  37. {
  38. if(strncmp(((PS_CLI_CMD)(g_cli_cmd_list.cmd[i]))->cmd, argv[1], strlen(argv[1])) == 0)
  39. {
  40. (void)cmd_out("%s"NEWLINE,((PS_CLI_CMD)(g_cli_cmd_list.cmd[i]))->description);
  41. return 0;
  42. }
  43. }
  44. (void)cmd_out("%s",UNKNOWNCMD);
  45. return 0;
  46. }
  47. /*lint -restore*/
  48. /*lint -save -e818*/
  49. DEFCLICMD(enable_cmd_debug_cmd,enable_cmd_debug_struct,
  50. "debug (on|off)","turn on/off debug infomation")
  51. {
  52. NO_USE(argc);
  53. if(strncmp("on",argv[1], strlen(argv[1])) == 0)
  54. {
  55. g_db_on = TRUE;
  56. (void)cmd_out("open the debug msg"NEWLINE);
  57. }
  58. else if(strncmp("off",argv[1], strlen(argv[1])) == 0)
  59. {
  60. g_db_on = FALSE;
  61. (void)cmd_out("shutdown the debug msg"NEWLINE);
  62. }
  63. else
  64. {
  65. return -1;
  66. }
  67. return 0;
  68. }
  69. /*lint -restore*/
  70. #define SOFTWARE_VERSION "1.1.2"
  71. /*打印本版本软件信息*/
  72. static void cli_print_softinfo(void)
  73. {
  74. (void)cmd_out("\r\n 编译时间: %s %s",__TIME__,__DATE__);
  75. (void)cmd_out("\r\n 软件版本: ");
  76. (void)cmd_out(SOFTWARE_VERSION);
  77. }
  78. DEFCLICMD(enable_cmd_show_cmd,enable_cmd_show_struct,
  79. "show","show all int")
  80. {
  81. NO_USE(argc);
  82. NO_USE(argv);
  83. if(strncmp("",argv[1], strlen(argv[1])) == 0)
  84. {
  85. (void)cmd_out("\r\n 缺少参数:");
  86. (void)cmd_out("\r\n version: 查看版本");
  87. (void)cmd_out("\r\n softinfo: 查看软件版本信息");
  88. }
  89. else if(strncmp("softinfo",argv[1], strlen(argv[1])) == 0)
  90. {
  91. cli_print_softinfo();
  92. }
  93. else
  94. {
  95. (void)cmd_out("\r\n 缺少参数:");
  96. (void)cmd_out("\r\n version: 查看版本");
  97. (void)cmd_out("\r\n softinfo: 查看软件版本信息");
  98. }
  99. (void)cmd_out(NEWLINE);
  100. return 0;
  101. }
  102. DEFCLICMD(enable_cpu_usage_cmd,enable_cpu_usage_struct,
  103. "cpu usage","cpu")
  104. {
  105. NO_USE(argc);
  106. NO_USE(argv);
  107. (void)cmd_out("\r\n CPU 利用率 : %d %%", OSStatTaskCPUUsage);
  108. (void)cmd_out(NEWLINE);
  109. return 0;
  110. }
  111. extern int maqtt_check_connect_status(uint8_t type);
  112. DEFCLICMD(enable_cmd_mqtt_cmd,enable_cmd_mqtt_struct,
  113. "mqtt","mqtt_status")
  114. {
  115. NO_USE(argc);
  116. NO_USE(argv);
  117. if(strncmp("",argv[1], strlen(argv[1])) == 0)
  118. {
  119. (void)cmd_out("\r\n 缺少参数:");
  120. }
  121. else if(strncmp("connect",argv[1], strlen(argv[1])) == 0)
  122. {
  123. maqtt_check_connect_status(1);
  124. }
  125. else
  126. {
  127. (void)cmd_out("\r\n 缺少参数:");
  128. }
  129. (void)cmd_out(NEWLINE);
  130. return 0;
  131. }
  132. void cmd_test_install(void)
  133. {
  134. (void)cmd_install(&enable_show_cmd_struct);
  135. (void)cmd_install(&enable_cmd_help_struct);
  136. (void)cmd_install(&enable_cmd_debug_struct);
  137. (void)cmd_install(&enable_cmd_show_struct);
  138. (void)cmd_install(&enable_cpu_usage_struct);
  139. (void)cmd_install(&enable_cmd_mqtt_struct);
  140. }