Clean up shell.c

This commit is contained in:
Mario Hüttel 2021-10-10 21:00:28 +02:00
parent 7a44a383ff
commit 1722ba7e5d
1 changed files with 31 additions and 97 deletions

View File

@ -51,7 +51,6 @@
#define GIT_VER "VERSION NOT SET"
#endif
extern struct stm_uart shell_uart;
static shellmatta_instance_t shell;
static char shell_buffer[512];
static char IN_SECTION(.ccm.bss) history_buffer[512];
@ -71,7 +70,7 @@ static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle,
unique_id_get(&high_id, &mid_id, &low_id);
shellmatta_printf(handle, "Reflow Oven Controller Firmware " xstr(GIT_VER) "\r\n"
"Compiled: " __DATE__ " at " __TIME__ "\r\n");
"Compiled: " __DATE__ " at " __TIME__ "\r\n");
shellmatta_printf(handle, "Serial: %08X-%08X-%08X\r\n", high_id, mid_id, low_id);
pcb_rev = get_pcb_hardware_version();
@ -163,13 +162,12 @@ static shellmatta_retCode_t shell_cmd_pt1000_res(const shellmatta_handle_t han
pt1000_status = adc_pt1000_get_current_resistance(&resistance);
if (pt1000_status == 2) {
if (pt1000_status == 2)
strcat(display_status, "UNSTABLE");
} else if (pt1000_status) {
else if (pt1000_status)
strcpy(display_status, "ERROR");
} else {
else
strcpy(display_status, "VALID");
}
temp_conv_status = temp_converter_convert_resistance_to_temp(resistance, &temp);
switch (temp_conv_status) {
@ -186,7 +184,8 @@ static shellmatta_retCode_t shell_cmd_pt1000_res(const shellmatta_handle_t han
break;
}
shellmatta_printf(handle, "PT1000 resistance: %.2f Ohm (%s%.1f °C) [%s]\r\n", resistance, temp_prefix,temp, display_status);
shellmatta_printf(handle, "PT1000 resistance: %.2f Ohm (%s%.1f °C) [%s]\r\n",
resistance, temp_prefix, temp, display_status);
return SHELLMATTA_OK;
}
@ -342,9 +341,8 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
do {
opt_ret = shellmatta_opt_long(handle, options, &option, &argument, &len);
if (opt_ret != SHELLMATTA_OK) {
if (opt_ret != SHELLMATTA_OK)
break;
}
switch (option) {
case 'a':
@ -353,7 +351,7 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
default:
break;
}
} while(1);
} while (1);
@ -377,7 +375,11 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
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"));
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"
@ -421,7 +423,7 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
shellmatta_printf(handle, "\t%2lu) %-20s\t", i+1, name);
if (timing_info.enabled)
shellmatta_printf(handle, "last tick: %lu ms\r\n", (unsigned long int)timing_info.delta);
shellmatta_printf(handle, "last tick: %lu ms\r\n", (unsigned long)timing_info.delta);
else
shellmatta_printf(handle, "\e[1;31mDISABLED\e[m\r\n");
}
@ -442,11 +444,10 @@ static shellmatta_retCode_t shell_cmd_save_cal(const shellmatta_handle_t handle,
adc_pt1000_get_resistance_calibration(&offset, &sens_dev, &active);
res = settings_save_calibration(sens_dev, offset, active);
if (res) {
if (res)
shellmatta_printf(handle, "Error saving %d\r\n", res);
} else {
else
shellmatta_printf(handle, "Saved!\r\n");
}
return SHELLMATTA_OK;
}
@ -458,7 +459,8 @@ static shellmatta_retCode_t shell_cmd_hang(const shellmatta_handle_t handle, con
(void)arguments;
(void)length;
while (1337);
while (1337)
;
return SHELLMATTA_OK;
}
@ -577,9 +579,9 @@ static shellmatta_retCode_t shell_cmd_dump_safety_mem(const shellmatta_handle_t
}
fres = f_write(&file, buffer, used_bytes - 1, &bw);
if (fres != FR_OK) {
if (fres != FR_OK)
shellmatta_printf(handle, "Error writing to file %s\r\n", token);
}
free(buffer);
f_close(&file);
return SHELLMATTA_OK;
@ -777,9 +779,9 @@ shellmatta_retCode_t shell_cmd_execute(const shellmatta_handle_t handle, const c
if (state->status != TPE_RUNNING) {
shellmatta_printf(handle, "Profile executed.\r\n");
running = false;
if(state->status == TPE_ABORT) {
if (state->status == TPE_ABORT)
shellmatta_printf(handle, "Profile execution aborted!\r\n");
}
return SHELLMATTA_OK;
}
@ -875,81 +877,6 @@ shellmatta_retCode_t shell_cmd_filter_alpha(const shellmatta_handle_t handle, co
return SHELLMATTA_OK;
}
#if 0
shellmatta_retCode_t shell_cmd_hf_stream(const shellmatta_handle_t handle, const char *args, uint32_t len)
{
float *data1;
volatile int flag;
FRESULT fres;
char *strbuff;
FIL f;
const size_t buff_size = 2000UL;
uint32_t idx;
uint32_t blocks;
uint32_t remainder;
int cnt;
UINT bw;
data1 = (float *)malloc(buff_size*sizeof(float));
strbuff = (char *)malloc(1024);
if (!data1 || !strbuff) {
shellmatta_printf(handle, "Allocating memory failed!\r\n");
goto free_data;
}
fres = f_open(&f, "pt1000_hf.dat", FA_CREATE_ALWAYS | FA_WRITE);
if (fres != FR_OK) {
shellmatta_printf(handle, "Cannot open file.\r\n");
goto free_data;
}
shellmatta_printf(handle, "Acquire data...\r\n");
flag = 0;
adc_pt1000_stream_raw_value_to_memory(data1, buff_size, &flag);
while (!flag) {
safety_controller_handle();
}
shellmatta_printf(handle, "Finished. Writing file...\r\n");
blocks = buff_size / 10UL;
remainder = buff_size % 10UL;
for (idx = 0; idx < blocks; idx++) {
cnt = snprintf(strbuff, 1024, "%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n",
data1[idx * 10+0],
data1[idx * 10+1],
data1[idx * 10+2],
data1[idx * 10+3],
data1[idx * 10+4],
data1[idx * 10+5],
data1[idx * 10+6],
data1[idx * 10+7],
data1[idx * 10+8],
data1[idx * 10+9]);
f_write(&f, strbuff, (UINT)cnt, &bw);
safety_controller_handle();
}
for (idx = 0; idx < remainder; idx++) {
cnt = snprintf(strbuff, 1024, "%.2f\n", data1[blocks * 10 + idx]);
f_write(&f, strbuff, (UINT)cnt, &bw);
}
f_close(&f);
shellmatta_printf(handle, "Completed!\r\n");
free_data:
if (data1)
free(data1);
if (strbuff)
free(strbuff);
return SHELLMATTA_OK;
}
#endif
//typedef struct shellmatta_cmd
//{
// char *cmd; /**< command name */
@ -1152,8 +1079,15 @@ shellmatta_handle_t shell_init(shellmatta_write_t write_func)
shellmatta_handle_t handle;
shellmatta_retCode_t ret;
ret = shellmatta_doInit(&shell, &handle, shell_buffer, sizeof(shell_buffer), history_buffer, sizeof(history_buffer),
"\e[1;32mReflow Controller>\e[m ", cmd, write_func);
ret = shellmatta_doInit(&shell,
&handle,
shell_buffer,
sizeof(shell_buffer),
history_buffer,
sizeof(history_buffer),
"\e[1;32mReflow Controller>\e[m ",
cmd,
write_func);
if (ret != SHELLMATTA_OK)
handle = NULL;