1、【完善】ENV 中 RT-Thread 平台相关 Demo 中的 Finsh 命令。

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2016-12-08 10:26:54 +08:00
parent 15e8c63bbe
commit 12e0b5fce5
4 changed files with 102 additions and 82 deletions

View File

@ -20,44 +20,3 @@ void get_cpuusage(void) {
rt_kprintf("The CPU usage is %d.%d% now.\n", cpu_usage_major, cpu_usage_minor);
}
MSH_CMD_EXPORT(get_cpuusage, Get control board cpu usage);
void setenv(uint8_t argc, char **argv) {
uint8_t i;
char c_value = NULL;
char *value = &c_value;
if (argc > 3) {
/* environment variable value string together */
for (i = 0; i < argc - 2; i++) {
argv[2 + i][rt_strlen(argv[2 + i])] = ' ';
}
}
if (argc == 1) {
ef_set_env(value, value);
} else if (argc == 2) {
ef_set_env(argv[1], value);
} else {
ef_set_env(argv[1], argv[2]);
}
}
MSH_CMD_EXPORT(setenv, Set an envrionment variable.);
void printenv(uint8_t argc, char **argv) {
ef_print_env();
}
MSH_CMD_EXPORT(printenv, Print all envrionment variables.);
void saveenv(uint8_t argc, char **argv) {
ef_save_env();
}
MSH_CMD_EXPORT(saveenv, Save all envrionment variables to flash.);
void getvalue(uint8_t argc, char **argv) {
char *value = NULL;
value = ef_get_env(argv[1]);
if (value) {
rt_kprintf("The %s value is %s.\n", argv[1], value);
} else {
rt_kprintf("Can't find %s.\n", argv[1]);
}
}
MSH_CMD_EXPORT(getvalue, Get an envrionment variable by name.);

View File

@ -233,3 +233,54 @@ void ef_print(const char *format, ...) {
rt_kprintf("%s", log_buf);
va_end(args);
}
#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
#include <finsh.h>
#if defined(EF_USING_ENV)
void setenv(uint8_t argc, char **argv) {
uint8_t i;
char c_value = NULL;
char *value = &c_value;
if (argc > 3) {
/* environment variable value string together */
for (i = 0; i < argc - 2; i++) {
argv[2 + i][rt_strlen(argv[2 + i])] = ' ';
}
}
if (argc == 1) {
ef_set_env(value, value);
} else if (argc == 2) {
ef_set_env(argv[1], value);
} else {
ef_set_env(argv[1], argv[2]);
}
}
MSH_CMD_EXPORT(setenv, Set an envrionment variable.);
void printenv(uint8_t argc, char **argv) {
ef_print_env();
}
MSH_CMD_EXPORT(printenv, Print all envrionment variables.);
void saveenv(uint8_t argc, char **argv) {
ef_save_env();
}
MSH_CMD_EXPORT(saveenv, Save all envrionment variables to flash.);
void getvalue(uint8_t argc, char **argv) {
char *value = NULL;
value = ef_get_env(argv[1]);
if (value) {
rt_kprintf("The %s value is %s.\n", argv[1], value);
} else {
rt_kprintf("Can't find %s.\n", argv[1]);
}
}
MSH_CMD_EXPORT(getvalue, Get an envrionment variable by name.);
void resetenv(uint8_t argc, char **argv) {
ef_env_set_default();
}
MSH_CMD_EXPORT(resetenv, Reset all envrionment variable to default.);
#endif /* defined(EF_USING_ENV) */
#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */

View File

@ -20,44 +20,3 @@ void get_cpuusage(void) {
rt_kprintf("The CPU usage is %d.%d% now.\n", cpu_usage_major, cpu_usage_minor);
}
MSH_CMD_EXPORT(get_cpuusage, Get control board cpu usage);
void setenv(uint8_t argc, char **argv) {
uint8_t i;
char c_value = NULL;
char *value = &c_value;
if (argc > 3) {
/* environment variable value string together */
for (i = 0; i < argc - 2; i++) {
argv[2 + i][rt_strlen(argv[2 + i])] = ' ';
}
}
if (argc == 1) {
ef_set_env(value, value);
} else if (argc == 2) {
ef_set_env(argv[1], value);
} else {
ef_set_env(argv[1], argv[2]);
}
}
MSH_CMD_EXPORT(setenv, Set an envrionment variable.);
void printenv(uint8_t argc, char **argv) {
ef_print_env();
}
MSH_CMD_EXPORT(printenv, Print all envrionment variables.);
void saveenv(uint8_t argc, char **argv) {
ef_save_env();
}
MSH_CMD_EXPORT(saveenv, Save all envrionment variables to flash.);
void getvalue(uint8_t argc, char **argv) {
char *value = NULL;
value = ef_get_env(argv[1]);
if (value) {
rt_kprintf("The %s value is %s.\n", argv[1], value);
} else {
rt_kprintf("Can't find %s.\n", argv[1]);
}
}
MSH_CMD_EXPORT(getvalue, Get an envrionment variable by name.);

View File

@ -364,3 +364,54 @@ void ef_print(const char *format, ...) {
rt_kprintf("%s", log_buf);
va_end(args);
}
#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH)
#include <finsh.h>
#if defined(EF_USING_ENV)
void setenv(uint8_t argc, char **argv) {
uint8_t i;
char c_value = NULL;
char *value = &c_value;
if (argc > 3) {
/* environment variable value string together */
for (i = 0; i < argc - 2; i++) {
argv[2 + i][rt_strlen(argv[2 + i])] = ' ';
}
}
if (argc == 1) {
ef_set_env(value, value);
} else if (argc == 2) {
ef_set_env(argv[1], value);
} else {
ef_set_env(argv[1], argv[2]);
}
}
MSH_CMD_EXPORT(setenv, Set an envrionment variable.);
void printenv(uint8_t argc, char **argv) {
ef_print_env();
}
MSH_CMD_EXPORT(printenv, Print all envrionment variables.);
void saveenv(uint8_t argc, char **argv) {
ef_save_env();
}
MSH_CMD_EXPORT(saveenv, Save all envrionment variables to flash.);
void getvalue(uint8_t argc, char **argv) {
char *value = NULL;
value = ef_get_env(argv[1]);
if (value) {
rt_kprintf("The %s value is %s.\n", argv[1], value);
} else {
rt_kprintf("Can't find %s.\n", argv[1]);
}
}
MSH_CMD_EXPORT(getvalue, Get an envrionment variable by name.);
void resetenv(uint8_t argc, char **argv) {
ef_env_set_default();
}
MSH_CMD_EXPORT(resetenv, Reset all envrionment variable to default.);
#endif /* defined(EF_USING_ENV) */
#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */