Issue #6: Implement safety flag ack in shell command safety-flags
This commit is contained in:
parent
e8f59b6dc6
commit
42f6d0270d
@ -49,6 +49,27 @@ static shellmatta_instance_t shell;
|
||||
static char shell_buffer[512];
|
||||
static char IN_SECTION(.ccm.bss) history_buffer[600];
|
||||
|
||||
static bool check_opt(const char *args, uint32_t len, const char *opt_to_check)
|
||||
{
|
||||
char str[128];
|
||||
const char *ptr;
|
||||
static const char * const tokens = "\t ";
|
||||
|
||||
strncpy(str, args, sizeof(str));
|
||||
str[sizeof(str) - 1] = 0;
|
||||
|
||||
/* Tokenize the string */
|
||||
ptr = strtok(str, tokens);
|
||||
|
||||
while (ptr) {
|
||||
if (strcmp(ptr, opt_to_check) == 0)
|
||||
return true;
|
||||
ptr = strtok(NULL, tokens);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle,
|
||||
const char *arguments,
|
||||
uint32_t length)
|
||||
@ -354,10 +375,15 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
|
||||
uint32_t i;
|
||||
char name[64];
|
||||
bool flag;
|
||||
bool tryack;
|
||||
int status;
|
||||
enum safety_flag flag_enum;
|
||||
struct analog_monitor_info amon_info;
|
||||
struct timing_monitor_info timing_info;
|
||||
|
||||
/* Check for the --ack option */
|
||||
tryack = check_opt(arguments, length, "--ack");
|
||||
|
||||
shellmatta_printf(handle, "Error flags\r\n"
|
||||
"-----------\r\n");
|
||||
|
||||
@ -369,12 +395,15 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
|
||||
continue;
|
||||
}
|
||||
|
||||
status = safety_controller_get_flag_by_index(i, &flag, NULL);
|
||||
status = safety_controller_get_flag_by_index(i, &flag, &flag_enum);
|
||||
if (status) {
|
||||
shellmatta_printf(handle, "Error getting flag value %lu\r\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tryack)
|
||||
safety_controller_ack_flag(flag_enum);
|
||||
|
||||
shellmatta_printf(handle, "\t%2lu) %-20s\t[%s]\r\n", i+1, name, (flag ? "\e[1;31mERR\e[m" : "\e[32mOK\e[m"));
|
||||
}
|
||||
|
||||
@ -624,8 +653,8 @@ static shellmatta_cmd_t cmd[17] = {
|
||||
{
|
||||
.cmd = "safety-flags",
|
||||
.cmdAlias = "flags",
|
||||
.helpText = "",
|
||||
.usageText = "",
|
||||
.helpText = "Reads and may clear safety flags",
|
||||
.usageText = "flags [--ack]",
|
||||
.cmdFct = shell_cmd_read_flags,
|
||||
.next = &cmd[13],
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user