Add shell command to change filter alpha

This commit is contained in:
Mario Hüttel 2021-08-24 21:50:36 +02:00
parent 88a4bb97a5
commit 809c86a618
1 changed files with 132 additions and 3 deletions

View File

@ -45,6 +45,7 @@
#include <reflow-controller/temp-profile/temp-profile-executer.h>
#include <reflow-controller/updater/updater.h>
#include <reflow-controller/main-cycle-counter.h>
#include <stdio.h>
#ifndef GIT_VER
#define GIT_VER "VERSION NOT SET"
@ -792,7 +793,7 @@ shellmatta_retCode_t shell_cmd_execute(const shellmatta_handle_t handle, const c
return SHELLMATTA_CONTINUE;
}
shellmatta_retCode_t shell_cmd_cycle_count (const shellmatta_handle_t handle, const char *args, uint32_t len)
shellmatta_retCode_t shell_cmd_cycle_count(const shellmatta_handle_t handle, const char *args, uint32_t len)
{
uint64_t counter;
(void)args;
@ -829,6 +830,126 @@ shellmatta_retCode_t shell_cmd_cycle_count (const shellmatta_handle_t handle, co
return SHELLMATTA_OK;
}
shellmatta_retCode_t shell_cmd_filter_alpha(const shellmatta_handle_t handle, const char *args, uint32_t len)
{
shellmatta_retCode_t opt_stat;
char option;
char *argument;
uint32_t arg_len;
char *alpha_string = NULL;
float alpha;
(void)len;
(void)args;
const shellmatta_opt_long_t options[] = {
{NULL, '\0', SHELLMATTA_OPT_ARG_NONE},
};
while (1) {
opt_stat = shellmatta_opt_long(handle, options, &option, &argument, &arg_len);
if (opt_stat != SHELLMATTA_OK)
break;
switch (option) {
case '\0':
alpha_string = argument;
break;
default:
break;
}
}
if (!alpha_string) {
shellmatta_printf(handle, "Specify filter value!\r\n");
return SHELLMATTA_OK;
}
alpha = strtof(alpha_string, NULL);
if (alpha < 0.0f || alpha == 0.0f || alpha > 0.9f) {
shellmatta_printf(handle, "Filter param outside of valid range!\r\n");
return SHELLMATTA_OK;
}
adc_pt1000_set_moving_average_filter_param(alpha);
shellmatta_printf(handle, "Filter param set to %f\r\n", alpha);
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 */
@ -838,7 +959,7 @@ shellmatta_retCode_t shell_cmd_cycle_count (const shellmatta_handle_t handle, co
// shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
//} shellmatta_cmd_t;
static shellmatta_cmd_t cmd[23] = {
static shellmatta_cmd_t cmd[24] = {
{
.cmd = "version",
.cmdAlias = "ver",
@ -1014,8 +1135,16 @@ static shellmatta_cmd_t cmd[23] = {
.helpText = "Print out the cycle counter of the main loop",
.usageText = "cyclecount [--clear]",
.cmdFct = shell_cmd_cycle_count,
.next = NULL,
.next = &cmd[22],
},
{
.cmd = "filter-alpha",
.cmdAlias = "alpha",
.helpText = "Sets the filter constant",
.usageText = "filter-alpha <alpha>",
.cmdFct = shell_cmd_filter_alpha,
.next = NULL,
}
};
shellmatta_handle_t shell_init(shellmatta_write_t write_func)