cmd_misc.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. *
  3. * Copyright (c) 2020 Project CHIP Authors
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #include <lib/shell/Engine.h>
  18. #include <crypto/RandUtils.h>
  19. #include <lib/core/CHIPCore.h>
  20. #include <lib/support/Base64.h>
  21. #include <lib/support/CHIPArgParser.hpp>
  22. #include <lib/support/CodeUtils.h>
  23. #include <inttypes.h>
  24. #include <stdarg.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <ChipShellCollection.h>
  29. using namespace chip;
  30. using namespace chip::Shell;
  31. using namespace chip::Logging;
  32. CHIP_ERROR cmd_echo(int argc, char ** argv)
  33. {
  34. for (int i = 0; i < argc; i++)
  35. {
  36. streamer_printf(streamer_get(), "%s ", argv[i]);
  37. }
  38. streamer_printf(streamer_get(), "\n\r");
  39. return CHIP_NO_ERROR;
  40. }
  41. CHIP_ERROR cmd_log(int argc, char ** argv)
  42. {
  43. for (int i = 0; i < argc; i++)
  44. {
  45. ChipLogProgress(chipTool, "%s", argv[i]);
  46. }
  47. return CHIP_NO_ERROR;
  48. }
  49. CHIP_ERROR cmd_rand(int argc, char ** argv)
  50. {
  51. streamer_printf(streamer_get(), "%d\n\r", static_cast<int>(chip::Crypto::GetRandU8()));
  52. return CHIP_NO_ERROR;
  53. }
  54. static shell_command_t cmds_misc[] = {
  55. { &cmd_echo, "echo", "Echo back provided inputs" },
  56. { &cmd_log, "log", "Logging utilities" },
  57. { &cmd_rand, "rand", "Random number utilities" },
  58. };
  59. void cmd_misc_init()
  60. {
  61. Engine::Root().RegisterCommands(cmds_misc, ArraySize(cmds_misc));
  62. }