Fix a few bugs and implement flags command further
This commit is contained in:
parent
6c4b698fd7
commit
464c247e32
@ -38,6 +38,14 @@ enum analog_monitor_status {ANALOG_MONITOR_OK = 0,
|
||||
ANALOG_MONITOR_OVER,
|
||||
ANALOG_MONITOR_UNDER};
|
||||
|
||||
struct analog_monitor_info {
|
||||
float value;
|
||||
float min;
|
||||
float max;
|
||||
enum analog_monitor_status status;
|
||||
uint64_t timestamp;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize the safety controller
|
||||
*
|
||||
@ -76,10 +84,16 @@ bool safety_controller_get_flags_by_mask(enum safety_flag mask);
|
||||
|
||||
uint32_t safety_controller_get_flag_count();
|
||||
|
||||
uint32_t safety_controller_get_analog_monitor_count();
|
||||
|
||||
int safety_controller_get_flag_name_by_index(uint32_t index, char *buffer, size_t buffsize);
|
||||
|
||||
int safety_controller_get_flag_by_index(uint32_t index, bool *status, enum safety_flag *flag_enum);
|
||||
|
||||
int safety_controller_get_analog_mon_by_index(uint32_t index, struct analog_monitor_info *info);
|
||||
|
||||
int safety_controller_get_analog_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize);
|
||||
|
||||
#endif /* __SAFETY_CONTROLLER_H__ */
|
||||
|
||||
/** @} */
|
||||
|
@ -59,6 +59,7 @@ struct analog_mon {
|
||||
float max;
|
||||
float value;
|
||||
bool valid;
|
||||
uint64_t timestamp;
|
||||
};
|
||||
|
||||
#ifdef COUNT_OF
|
||||
@ -91,7 +92,7 @@ static volatile struct error_flag flags[] = {
|
||||
static volatile struct timing_mon timings[] = {
|
||||
TIM_MON_ENTRY(ERR_TIMING_PID, 2, 1000, ERR_FLAG_TIMING_PID),
|
||||
TIM_MON_ENTRY(ERR_TIMING_MEAS_ADC, 0, 50, ERR_FLAG_TIMING_MEAS_ADC),
|
||||
TIM_MON_ENTRY(ERR_TIMING_SAFETY_ADC, 10, SAFETY_CONTROLLER_ADC_DELAY_MS + 70, ERR_FLAG_SAFETY_ADC),
|
||||
TIM_MON_ENTRY(ERR_TIMING_SAFETY_ADC, 10, SAFETY_CONTROLLER_ADC_DELAY_MS + 500, ERR_FLAG_SAFETY_ADC),
|
||||
};
|
||||
|
||||
static volatile struct analog_mon analog_mons[] = {
|
||||
@ -233,6 +234,7 @@ void safety_controller_report_analog_value(enum analog_value_monitor monitor, fl
|
||||
if (ana) {
|
||||
ana->valid = true;
|
||||
ana->value = value;
|
||||
ana->timestamp = systick_get_global_tick();
|
||||
}
|
||||
|
||||
}
|
||||
@ -442,7 +444,7 @@ bool safety_controller_get_flags_by_mask(enum safety_flag mask)
|
||||
bool ret = false;
|
||||
|
||||
for (i = 0; i < COUNT_OF(flags); i++) {
|
||||
if (flags[i].flag & mask) {
|
||||
if ((flags[i].flag & mask) && flags[i].error_state) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
@ -456,6 +458,25 @@ uint32_t safety_controller_get_flag_count()
|
||||
return COUNT_OF(flags);
|
||||
}
|
||||
|
||||
uint32_t safety_controller_get_analog_monitor_count()
|
||||
{
|
||||
return COUNT_OF(analog_mons);
|
||||
}
|
||||
|
||||
int safety_controller_get_analog_mon_name_by_index(uint32_t index, char *buffer, size_t buffsize)
|
||||
{
|
||||
if (index >= COUNT_OF(analog_mons))
|
||||
return -1;
|
||||
|
||||
if (buffsize == 0 || !buffer)
|
||||
return -1000;
|
||||
|
||||
strncpy(buffer, analog_mons[index].name, buffsize);
|
||||
buffer[buffsize - 1] = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safety_controller_get_flag_name_by_index(uint32_t index, char *buffer, size_t buffsize)
|
||||
{
|
||||
if (index >= COUNT_OF(flags))
|
||||
@ -489,4 +510,37 @@ int safety_controller_get_flag_by_index(uint32_t index, bool *status, enum safet
|
||||
return ret;
|
||||
}
|
||||
|
||||
int safety_controller_get_analog_mon_by_index(uint32_t index, struct analog_monitor_info *info)
|
||||
{
|
||||
volatile struct analog_mon *mon;
|
||||
|
||||
if (!info)
|
||||
return -1002;
|
||||
|
||||
if (index >= COUNT_OF(analog_mons)) {
|
||||
info->status = ANALOG_MONITOR_ERROR;
|
||||
return -1001;
|
||||
}
|
||||
|
||||
mon = &analog_mons[index];
|
||||
|
||||
info->max = mon->max;
|
||||
info->min = mon->min;
|
||||
info->value = mon->value;
|
||||
info->timestamp = mon->timestamp;
|
||||
|
||||
if (!mon->valid) {
|
||||
info->status = ANALOG_MONITOR_INACTIVE;
|
||||
} else {
|
||||
if (mon->value > mon->max)
|
||||
info->status = ANALOG_MONITOR_OVER;
|
||||
else if (mon->value < mon->min)
|
||||
info->status = ANALOG_MONITOR_UNDER;
|
||||
else
|
||||
info->status = ANALOG_MONITOR_OK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user