cli_utils_cmds.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * Copyright (c) 2018, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "nrf_cli.h"
  41. #include "nrf_log.h"
  42. static void cmd_reset(nrf_cli_t const * p_cli, size_t argc, char **argv)
  43. {
  44. UNUSED_PARAMETER(argc);
  45. UNUSED_PARAMETER(argv);
  46. if (nrf_cli_help_requested(p_cli))
  47. {
  48. nrf_cli_help_print(p_cli, NULL, 0);
  49. return;
  50. }
  51. NVIC_SystemReset();
  52. }
  53. static void cmd_error(nrf_cli_t const * p_cli, size_t argc, char **argv)
  54. {
  55. UNUSED_PARAMETER(argc);
  56. UNUSED_PARAMETER(argv);
  57. if (nrf_cli_help_requested(p_cli))
  58. {
  59. nrf_cli_help_print(p_cli, NULL, 0);
  60. return;
  61. }
  62. APP_ERROR_CHECK(NRF_ERROR_INTERNAL);
  63. }
  64. static void cmd_app_size(nrf_cli_t const * p_cli, size_t argc, char **argv)
  65. {
  66. UNUSED_PARAMETER(argc);
  67. UNUSED_PARAMETER(argv);
  68. if (nrf_cli_help_requested(p_cli))
  69. {
  70. nrf_cli_help_print(p_cli, NULL, 0);
  71. return;
  72. }
  73. nrf_cli_fprintf(p_cli,
  74. NRF_CLI_NORMAL,
  75. "Application address:%d (0x%08X), size: %d (0x%08X)\r\n",
  76. CODE_START,
  77. CODE_START,
  78. CODE_SIZE,
  79. CODE_SIZE);
  80. }
  81. static void cmd_log_msg_error(nrf_cli_t const * p_cli, size_t argc, char **argv)
  82. {
  83. if (nrf_cli_help_requested(p_cli))
  84. {
  85. nrf_cli_help_print(p_cli, NULL, 0);
  86. return;
  87. }
  88. switch (argc-1)
  89. {
  90. case 0:
  91. NRF_LOG_ERROR("test error message");
  92. break;
  93. case 1:
  94. NRF_LOG_ERROR("test error message: %d", strtol(argv[1], NULL, 10));
  95. break;
  96. case 2:
  97. NRF_LOG_ERROR("test error message: %d %d", strtol(argv[1], NULL, 10),
  98. strtol(argv[2], NULL, 10));
  99. break;
  100. default:
  101. NRF_LOG_ERROR("test error message with more than 3 arguments");
  102. break;
  103. }
  104. }
  105. static void cmd_log_msg_warning(nrf_cli_t const * p_cli, size_t argc, char **argv)
  106. {
  107. if (nrf_cli_help_requested(p_cli))
  108. {
  109. nrf_cli_help_print(p_cli, NULL, 0);
  110. return;
  111. }
  112. switch (argc-1)
  113. {
  114. case 0:
  115. NRF_LOG_WARNING("test warning message");
  116. break;
  117. case 1:
  118. NRF_LOG_WARNING("test warning message: %d", strtol(argv[1], NULL, 10));
  119. break;
  120. case 2:
  121. NRF_LOG_WARNING("test warning message: %d %d", strtol(argv[1], NULL, 10),
  122. strtol(argv[2], NULL, 10));
  123. break;
  124. default:
  125. NRF_LOG_WARNING("test warning message with more than 3 arguments");
  126. break;
  127. }
  128. }
  129. /**
  130. * @brief Command set array
  131. * */
  132. NRF_CLI_CMD_REGISTER(reset, NULL, "System reset.", cmd_reset);
  133. NRF_CLI_CMD_REGISTER(error, NULL, "Trigger error.", cmd_error);
  134. NRF_CLI_CMD_REGISTER(app_size, NULL, "Print application size.", cmd_app_size);
  135. NRF_CLI_CREATE_STATIC_SUBCMD_SET(m_sub_log_msg)
  136. {
  137. NRF_CLI_CMD(error, NULL, "Error log message with parameters", cmd_log_msg_error),
  138. NRF_CLI_CMD(warning, NULL, "Warning log message with parameters", cmd_log_msg_warning),
  139. NRF_CLI_SUBCMD_SET_END
  140. };
  141. NRF_CLI_CMD_REGISTER(log_msg, &m_sub_log_msg, "Trigger log message with decimal arguments", NULL);