ef_cmd.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is part of the EasyFlash Library.
  3. *
  4. * Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * 'Software'), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Function: RT-Thread Finsh/MSH command for EasyFlash.
  26. * Created on: 2018-05-19
  27. */
  28. #include <easyflash.h>
  29. #include <rtthread.h>
  30. #if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(EF_USING_ENV)
  31. #include <finsh.h>
  32. #if defined(EF_USING_ENV)
  33. static void __setenv(uint8_t argc, char **argv) {
  34. uint8_t i;
  35. if (argc > 3) {
  36. /* environment variable value string together */
  37. for (i = 0; i < argc - 2; i++) {
  38. argv[2 + i][rt_strlen(argv[2 + i])] = ' ';
  39. }
  40. }
  41. if (argc == 1) {
  42. rt_kprintf("Please input: setenv <key> [value]\n");
  43. } else if (argc == 2) {
  44. ef_set_env(argv[1], NULL);
  45. } else {
  46. ef_set_env(argv[1], argv[2]);
  47. }
  48. }
  49. MSH_CMD_EXPORT_ALIAS(__setenv, setenv, Set an envrionment variable.);
  50. static void printenv(uint8_t argc, char **argv) {
  51. ef_print_env();
  52. }
  53. MSH_CMD_EXPORT(printenv, Print all envrionment variables.);
  54. static void saveenv(uint8_t argc, char **argv) {
  55. ef_save_env();
  56. }
  57. MSH_CMD_EXPORT(saveenv, Save all envrionment variables to flash.);
  58. static void getvalue(uint8_t argc, char **argv) {
  59. char *value = NULL;
  60. value = ef_get_env(argv[1]);
  61. if (value) {
  62. rt_kprintf("The %s value is %s.\n", argv[1], value);
  63. } else {
  64. rt_kprintf("Can't find %s.\n", argv[1]);
  65. }
  66. }
  67. MSH_CMD_EXPORT(getvalue, Get an envrionment variable by name.);
  68. static void resetenv(uint8_t argc, char **argv) {
  69. ef_env_set_default();
  70. }
  71. MSH_CMD_EXPORT(resetenv, Reset all envrionment variable to default.);
  72. #endif /* defined(EF_USING_ENV) */
  73. #endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */