Commit 967b7dd5 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Introduce new param set functions.

Now it is possible to add parameters multiple times and we no longer depend
on the location of the parameter in the list.
parent 5b42506c
...@@ -15,7 +15,7 @@ sleep 1 ...@@ -15,7 +15,7 @@ sleep 1
screen -S console -X screen -t console_idle console_idle screen -S console -X screen -t console_idle console_idle
screen -S console -X screen -t console_dt_model console_dt_model screen -S console -X screen -t console_dt_model console_dt_model
screen -S console -X screen -t console_j2000tracker console_j2000tracker screen -S console -X screen -t console_j2000tracker console_j2000tracker
screen -S console -X screen -t console_j2000_indi indiserver console_j2000_indi #screen -S console -X screen -t console_j2000_indi indiserver console_j2000_indi
screen -S console -X screen -t console_moontracker console_moontracker screen -S console -X screen -t console_moontracker console_moontracker
screen -S console -X screen -t console_suntracker console_suntracker screen -S console -X screen -t console_suntracker console_suntracker
screen -S console -X screen -t console_azel console_azel screen -S console -X screen -t console_azel console_azel
......
/var/log/dt/traces/
\ No newline at end of file
...@@ -76,10 +76,6 @@ struct controller_block * block_add_create(char *name) ...@@ -76,10 +76,6 @@ struct controller_block * block_add_create(char *name)
goto err_block; goto err_block;
add->calculate = add_calculate; add->calculate = add_calculate;
add->params = 0;
add->param = NULL;
add->param_get = NULL;
add->param_set = NULL;
controller_block_add(add); controller_block_add(add);
return add; return add;
......
...@@ -105,42 +105,33 @@ static void calculate(struct controller_block *bridge) ...@@ -105,42 +105,33 @@ static void calculate(struct controller_block *bridge)
priv->b = b & pwm; priv->b = b & pwm;
} }
static int param_set_divider(struct controller_block *bridge, va_list val)
{
bridge->private->divider = va_arg(val, int);
return 0;
}
static int param_set_continuous(struct controller_block *bridge, va_list val)
{
bridge->private->continuous = va_arg(val, int);
return 0;
}
static struct controller_block_param_list params[] = { static struct controller_block_param_list params[] = {
/* Divider between sample frequency and PWM frequency. /* Divider between sample frequency and PWM frequency.
This also influences the available number of PWM steps. This also influences the available number of PWM steps.
*/ */
{ "divider", false }, { "divider", false, param_set_divider },
/* Are we allowed to switch an output continuously on? /* Are we allowed to switch an output continuously on?
Set this to false if the driver needs a switching output Set this to false if the driver needs a switching output
for generating proper gate voltage. for generating proper gate voltage.
*/ */
{ "continuous_on", false }, { "continuous_on", false, param_set_continuous },
{ NULL }, { NULL },
}; };
static void param_get(struct controller_block *bridge, int param, void *val)
{
switch (param) {
case 0:
*(int*)val = bridge->private->divider;
break;
case 1:
*(int*)val = bridge->private->continuous;
break;
}
}
static void param_set(struct controller_block *bridge, int param, va_list val)
{
switch (param) {
case 0:
bridge->private->divider = va_arg(val, int);
break;
case 1:
bridge->private->continuous = va_arg(val, int);
break;
}
}
static struct controller_block_interm_list interms[] = { static struct controller_block_interm_list interms[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, in) }, { "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, in) },
...@@ -176,12 +167,9 @@ struct controller_block * block_bridge_pwm_create(char *name) ...@@ -176,12 +167,9 @@ struct controller_block * block_bridge_pwm_create(char *name)
bridge->calculate = calculate; bridge->calculate = calculate;
if (controller_block_param_list_init(bridge, params)) if (controller_block_param_list_add(bridge, params))
goto err_params; goto err_params;
bridge->param_get = param_get;
bridge->param_set = param_set;
controller_block_add(bridge); controller_block_add(bridge);
return bridge; return bridge;
......
...@@ -54,35 +54,26 @@ static void calculate(struct controller_block *counter) ...@@ -54,35 +54,26 @@ static void calculate(struct controller_block *counter)
} }
static struct controller_block_param_list params[] = { static int param_set_overflow(struct controller_block *counter, va_list val)
{ "overflow", false },
{ "value", false },
{ NULL },
};
static void param_get(struct controller_block *counter, int param, void *val)
{ {
switch (param) { counter->private->overflow = va_arg(val, int);
case 0: return 0;
*(int*)val = counter->private->overflow;
break;
case 1:
*(int*)val = counter->private->count;
break;
}
} }
static void param_set(struct controller_block *counter, int param, va_list val)
static int param_set_value(struct controller_block *counter, va_list val)
{ {
switch (param) { counter->private->count = va_arg(val, int);
case 0: return 0;
counter->private->overflow = va_arg(val, int);
break;
case 1:
counter->private->count = va_arg(val, int);
break;
}
} }
static struct controller_block_param_list params[] = {
{ "overflow", false, param_set_overflow },
{ "value", false, param_set_value },
{ NULL },
};
struct controller_block * block_counter_create(char *name) struct controller_block * block_counter_create(char *name)
{ {
struct controller_block *counter; struct controller_block *counter;
...@@ -122,12 +113,9 @@ struct controller_block * block_counter_create(char *name) ...@@ -122,12 +113,9 @@ struct controller_block * block_counter_create(char *name)
counter->calculate = calculate; counter->calculate = calculate;
if (controller_block_param_list_init(counter, params)) if (controller_block_param_list_add(counter, params))
goto err_paramlist; goto err_paramlist;
counter->param_get = param_get;
counter->param_set = param_set;
controller_block_add(counter); controller_block_add(counter);
return counter; return counter;
......
...@@ -73,9 +73,6 @@ struct controller_block * block_debug_create(char *name) ...@@ -73,9 +73,6 @@ struct controller_block * block_debug_create(char *name)
debug->calculate = calculate; debug->calculate = calculate;
debug->params = 0; debug->params = 0;
debug->param = NULL;
debug->param_get = NULL;
debug->param_set = NULL;
controller_block_add(debug); controller_block_add(debug);
return debug; return debug;
......
...@@ -108,9 +108,6 @@ struct controller_block * block_decoder_uint32_bool_create(char *name, va_list a ...@@ -108,9 +108,6 @@ struct controller_block * block_decoder_uint32_bool_create(char *name, va_list a
dec->calculate = calculate; dec->calculate = calculate;
dec->params = 0; dec->params = 0;
dec->param = NULL;
dec->param_get = NULL;
dec->param_set = NULL;
controller_block_add(dec); controller_block_add(dec);
return dec; return dec;
......
...@@ -76,82 +76,57 @@ static void filter_iir_calculate(struct controller_block *iir) ...@@ -76,82 +76,57 @@ static void filter_iir_calculate(struct controller_block *iir)
priv->out = out; priv->out = out;
} }
static struct controller_block_param_list params[] = { static int param_set(struct controller_block *iir, va_list ap)
{ "transfer", true },
{ "reset", true },
{ NULL },
};
static void param_get(struct controller_block *iir, int param, void *val)
{
switch (param) {
case 0:
memcpy(val, &iir->private->param,
sizeof(struct block_filter_iir_param));
break;
case 1:
break;
}
}
static void param_set(struct controller_block *iir, int param, va_list ap)
{ {
int i; int i;
int new_param = 0; int len;
float gain;
switch (param) { float *poles;
case 0: { float *zeros;
int len;
float gain;
float *poles;
float *zeros;
len = va_arg(ap, int); len = va_arg(ap, int);
gain = va_arg(ap, double); gain = va_arg(ap, double);
poles = va_arg(ap, float *); poles = va_arg(ap, float *);
zeros = va_arg(ap, float *); zeros = va_arg(ap, float *);
iir->private->param.len = len; iir->private->param.len = len;
iir->private->param.gain = gain; iir->private->param.gain = gain;
iir->private->param.poles = poles; iir->private->param.poles = poles;
iir->private->param.zeros = zeros; iir->private->param.zeros = zeros;
new_param = 1; if (iir->private->transfer)
break; free(iir->private->transfer);
}
case 1:
break;
}
if (new_param) {
if (iir->private->transfer)
free(iir->private->transfer);
iir->private->len = iir->private->param.len + 1; iir->private->len = iir->private->param.len + 1;
iir->private->transfer = malloc(sizeof(float[4]) * iir->private->transfer = malloc(sizeof(float[4]) *
iir->private->len); iir->private->len);
if (!iir->private->transfer) { if (!iir->private->transfer) {
iir->private->len = 0; iir->private->len = 0;
return; return -1;
} }
iir->private->transfer[0][0] = 0; iir->private->transfer[0][0] = 0;
iir->private->transfer[iir->private->param.len ][1] = iir->private->transfer[iir->private->param.len ][1] =
1.0 / iir->private->param.gain; 1.0 / iir->private->param.gain;
for (i = 0; i < iir->private->param.len; i++) { for (i = 0; i < iir->private->param.len; i++) {
iir->private->transfer[i + 1][0] = iir->private->transfer[i + 1][0] =
iir->private->param.poles[i]; iir->private->param.poles[i];
iir->private->transfer[i][1] = iir->private->transfer[i][1] =
iir->private->param.zeros[i] / iir->private->param.gain; iir->private->param.zeros[i] / iir->private->param.gain;
}
for (i = 0; i < iir->private->len; i++) {
iir->private->transfer[i][2] = 0;
iir->private->transfer[i][3] = 0;
}
iir->private->ind = 0;
iir->private->out = 0;
} }
for (i = 0; i < iir->private->len; i++) {
iir->private->transfer[i][2] = 0;
iir->private->transfer[i][3] = 0;
}
iir->private->ind = 0;
iir->private->out = 0;
return 0;
} }
static struct controller_block_param_list params[] = {
{ "transfer", true, param_set },
{ NULL },
};
static struct controller_block_interm_list interms[] = { static struct controller_block_interm_list interms[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) }, { "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) },
{ NULL } { NULL }
...@@ -182,12 +157,9 @@ struct controller_block * block_filter_iir_create(char *name) ...@@ -182,12 +157,9 @@ struct controller_block * block_filter_iir_create(char *name)
iir->calculate = filter_iir_calculate; iir->calculate = filter_iir_calculate;
if (controller_block_param_list_init(iir, params)) if (controller_block_param_list_add(iir, params))
goto err_block; goto err_block;
iir->param_get = param_get;
iir->param_set = param_set;
controller_block_add(iir); controller_block_add(iir);
return iir; return iir;
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <string.h> #include <string.h>
#include <controller/controller_block.h> #include <controller/controller_block.h>
#include <controller/controller_sample.h>
/* /*
inputs outputs inputs outputs
...@@ -56,42 +56,21 @@ static void filter_lp_calculate(struct controller_block *lp) ...@@ -56,42 +56,21 @@ static void filter_lp_calculate(struct controller_block *lp)
priv->out = out; priv->out = out;
} }
static struct controller_block_param_list params[] = { static int param_set(struct controller_block *lp, va_list val)
{ "tau", true },
{ "t", true },
{ NULL },
};
static void param_get(struct controller_block *lp, int param, void *val)
{
switch (param) {
case 0:
*(float*)val = lp->private->tau;
break;
case 1:
*(float*)val = lp->private->t;
break;
}
}
static void param_set(struct controller_block *lp, int param, va_list val)
{ {
switch (param) { lp->private->tau = va_arg(val, double);
case 0:
lp->private->tau = va_arg(val, double);
break;
case 1:
lp->private->t = va_arg(val, double);
break;
}
if (lp->private->t == 0.0)
lp->private->t = 1.0;
lp->private->alpha = lp->private->alpha =
lp->private->t / (lp->private->t + lp->private->tau); controller_sample_period() / (controller_sample_period() + lp->private->tau);
return 0;
} }
static struct controller_block_param_list params[] = {
{ "tau", true, param_set },
{ NULL },
};
static struct controller_block_interm_list interms[] = { static struct controller_block_interm_list interms[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) }, { "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) },
{ NULL } { NULL }
...@@ -122,12 +101,9 @@ struct controller_block * block_filter_lp_create(char *name) ...@@ -122,12 +101,9 @@ struct controller_block * block_filter_lp_create(char *name)
lp->calculate = filter_lp_calculate; lp->calculate = filter_lp_calculate;
if (controller_block_param_list_init(lp, params)) if (controller_block_param_list_add(lp, params))
goto err_block; goto err_block;
lp->param_get = param_get;
lp->param_set = param_set;
controller_block_add(lp); controller_block_add(lp);
return lp; return lp;
......
...@@ -96,54 +96,46 @@ static void friction_calculate(struct controller_block *friction) ...@@ -96,54 +96,46 @@ static void friction_calculate(struct controller_block *friction)
} }
} }
static struct controller_block_param_list params[] = { static int param_set_friction_static(struct controller_block *friction, va_list val)
{ "friction_static", false }, {
{ "friction_dynamic", false }, struct controller_block_private *priv = friction->private;
{ "deadzone_max", false },
{ "deadzone_min", false },
{ NULL },
};
static void param_get(struct controller_block *friction, int param, void *val) priv->friction_static = va_arg(val, double);
return 0;
}
static int param_set_friction_dynamic(struct controller_block *friction, va_list val)
{ {
struct controller_block_private *priv = friction->private; struct controller_block_private *priv = friction->private;
switch (param) { priv->friction_dynamic = va_arg(val, double);
case 0: return 0;
*(float*)val = priv->friction_static;
break;
case 1:
*(float*)val = priv->friction_dynamic;
break;
case 2:
*(float*)val = priv->deadzone_max;
break;
case 3:
*(float*)val = priv->deadzone_min;
break;
}
} }
static void param_set(struct controller_block *friction, int param, va_list val) static int param_set_deadzone_max(struct controller_block *friction, va_list val)
{ {
struct controller_block_private *priv = friction->private; struct controller_block_private *priv = friction->private;
switch (param) { priv->deadzone_max = va_arg(val, double);
case 0: return 0;
priv->friction_static = va_arg(val, double);
break;
case 1:
priv->friction_dynamic = va_arg(val, double);
break;
case 2:
priv->deadzone_max = va_arg(val, double);
break;
case 3:
priv->deadzone_min = va_arg(val, double);
break;
}
} }
static int param_set_deadzone_min(struct controller_block *friction, va_list val)
{
struct controller_block_private *priv = friction->private;
priv->deadzone_min = va_arg(val, double);
return 0;
}
static struct controller_block_param_list params[] = {
{ "friction_static", false, param_set_friction_static },
{ "friction_dynamic", false, param_set_friction_dynamic },
{ "deadzone_max", false, param_set_deadzone_max },
{ "deadzone_min", false, param_set_deadzone_min },
{ NULL },
};
static struct controller_block_interm_list interms[] = { static struct controller_block_interm_list interms[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) }, { "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) },
{ "speed", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input1) }, { "speed", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input1) },
...@@ -176,12 +168,9 @@ struct controller_block * block_friction_create(char *name) ...@@ -176,12 +168,9 @@ struct controller_block * block_friction_create(char *name)
friction->calculate = friction_calculate; friction->calculate = friction_calculate;
if (controller_block_param_list_init(friction, params)) if (controller_block_param_list_add(friction, params))
goto err_block; goto err_block;
friction->param_get = param_get;
friction->param_set = param_set;
controller_block_add(friction); controller_block_add(friction);
return friction; return friction;
......
...@@ -48,28 +48,16 @@ static void gain_calculate(struct controller_block *gain) ...@@ -48,28 +48,16 @@ static void gain_calculate(struct controller_block *gain)
priv->out = *priv->input0 * priv->gain; priv->out = *priv->input0 * priv->gain;
} }
static struct controller_block_param_list params[] = {