Fix a few bugs and implement flags command further

This commit is contained in:
2020-07-30 20:29:41 +02:00
parent 6c4b698fd7
commit 464c247e32
3 changed files with 111 additions and 36 deletions

View File

@@ -295,6 +295,8 @@ static shellmatta_retCode_t shell_cmd_reset(const shellmatta_handle_t handle, co
static shellmatta_retCode_t shell_cmd_cat(const shellmatta_handle_t handle, const char *arguments,
uint32_t length)
{
#ifdef IMPLEMENT_SHELL_CAT
FIL file;
char path_buff[256];
const char *path;
@@ -331,29 +333,12 @@ static shellmatta_retCode_t shell_cmd_cat(const shellmatta_handle_t handle, cons
f_close(&file);
return SHELLMATTA_OK;
}
static shellmatta_retCode_t shell_cmd_safety_adc(const shellmatta_handle_t handle, const char *arguments,
uint32_t length)
{
#else
(void)length;
(void)arguments;
enum analog_monitor_status status_vref, status_temp;
float vref, uc_temp;
status_vref = safety_controller_get_analog_mon_value(ERR_AMON_VREF, &vref);
status_temp = safety_controller_get_analog_mon_value(ERR_AMON_UC_TEMP, &uc_temp);
shellmatta_printf(handle, "VREF:\t%8.2f\tmV\r\n", vref);
shellmatta_printf(handle, "TEMP:\t%8.2f\tdeg. Celsius\r\n", uc_temp);
if (status_temp != ANALOG_MONITOR_OK) {
shellmatta_printf(handle, "TEMP channel error!\r\n");
}
if (status_vref != ANALOG_MONITOR_OK) {
shellmatta_printf(handle, "VREF channel error!\r\n");
}
shellmatta_printf(handle, "cat not implemented!\r\n");
#endif
return SHELLMATTA_OK;
}
@@ -363,17 +348,18 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
{
(void)length;
(void)arguments;
uint32_t flag_count;
uint32_t count;
uint32_t i;
char name[64];
bool flag;
int status;
struct analog_monitor_info amon_info;
shellmatta_printf(handle, "Error flags\r\n"
"-----------\r\n");
flag_count = safety_controller_get_flag_count();
for (i = 0; i < flag_count; i++) {
count = safety_controller_get_flag_count();
for (i = 0; i < count; i++) {
status = safety_controller_get_flag_name_by_index(i, name, sizeof(name));
if (status) {
shellmatta_printf(handle, "Error getting flag name %lu\r\n", i);
@@ -386,7 +372,36 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
continue;
}
shellmatta_printf(handle, "%2lu) %-20s\t[%s]\r\n", i+1, name, (flag ? "\e[1;31mERR\e[m" : "\e[32mOK\e[m"));
shellmatta_printf(handle, "\t%2lu) %-20s\t[%s]\r\n", i+1, name, (flag ? "\e[1;31mERR\e[m" : "\e[32mOK\e[m"));
}
shellmatta_printf(handle, "\r\nAnalog Monitors\r\n"
"---------------\r\n");
count = safety_controller_get_analog_monitor_count();
for (i = 0; i < count; i++) {
status = safety_controller_get_analog_mon_name_by_index(i, name, sizeof(name));
if (status) {
shellmatta_printf(handle, "Error getting analog value monitor %lu name\r\n", i);
continue;
}
status = safety_controller_get_analog_mon_by_index(i, &amon_info);
if (status) {
shellmatta_printf(handle, "Error reading analog monitor status %lu\r\n", i);
continue;
}
shellmatta_printf(handle, "\t%2lu) %-20s\t[%s%8.2f%s]", i+1, name,
amon_info.status == ANALOG_MONITOR_OK ? "\e[32m" : "\e[1;31m",
amon_info.value,
"\e[m");
if (amon_info.status == ANALOG_MONITOR_INACTIVE) {
shellmatta_printf(handle, "Inactive\r\n");
} else {
shellmatta_printf(handle, " valid from %-8.2f to %-8.2f", amon_info.min, amon_info.max);
shellmatta_printf(handle, "\tchecked %llu ms ago\r\n", systick_get_global_tick() - amon_info.timestamp);
}
}
return SHELLMATTA_OK;
@@ -402,7 +417,7 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
//} shellmatta_cmd_t;
static shellmatta_cmd_t cmd[14] = {
static shellmatta_cmd_t cmd[13] = {
{
.cmd = "version",
.cmdAlias = "ver",
@@ -499,14 +514,6 @@ static shellmatta_cmd_t cmd[14] = {
.cmdFct = shell_cmd_cat,
.next = &cmd[12],
},
{
.cmd = "safety-adc",
.cmdAlias = NULL,
.helpText = "",
.usageText = "",
.cmdFct = shell_cmd_safety_adc,
.next = &cmd[13],
},
{
.cmd = "safety-flags",
.cmdAlias = "flags",
@@ -534,7 +541,7 @@ void shell_print_motd(shellmatta_handle_t shell)
{
/* Clear display and set cursor to home position */
shellmatta_printf(shell, "\e[2J\e[H");
shellmatta_printf(shell, "Shimatta 仕舞った Reflow Controller ready\r\n\r\n");
shellmatta_printf(shell, "Shimatta Reflow Controller ready\r\n\r\n");
shell_cmd_ver(shell, NULL, 0UL);
shell_handle_input(shell, "\r\n", 2UL);
}