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
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_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_suntracker console_suntracker
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)
goto err_block;
add->calculate = add_calculate;
add->params = 0;
add->param = NULL;
add->param_get = NULL;
add->param_set = NULL;
controller_block_add(add);
return add;
......
......@@ -105,42 +105,33 @@ static void calculate(struct controller_block *bridge)
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[] = {
/* Divider between sample frequency and PWM frequency.
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?
Set this to false if the driver needs a switching output
for generating proper gate voltage.
*/
{ "continuous_on", false },
{ "continuous_on", false, param_set_continuous },
{ 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[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, in) },
......@@ -176,12 +167,9 @@ struct controller_block * block_bridge_pwm_create(char *name)
bridge->calculate = calculate;
if (controller_block_param_list_init(bridge, params))
if (controller_block_param_list_add(bridge, params))
goto err_params;
bridge->param_get = param_get;
bridge->param_set = param_set;
controller_block_add(bridge);
return bridge;
......
......@@ -54,35 +54,26 @@ static void calculate(struct controller_block *counter)
}
static struct controller_block_param_list params[] = {
{ "overflow", false },
{ "value", false },
{ NULL },
};
static void param_get(struct controller_block *counter, int param, void *val)
static int param_set_overflow(struct controller_block *counter, va_list val)
{
switch (param) {
case 0:
*(int*)val = counter->private->overflow;
break;
case 1:
*(int*)val = counter->private->count;
break;
}
counter->private->overflow = va_arg(val, int);
return 0;
}
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) {
case 0:
counter->private->overflow = va_arg(val, int);
break;
case 1:
counter->private->count = va_arg(val, int);
break;
}
counter->private->count = va_arg(val, int);
return 0;
}
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 *counter;
......@@ -122,12 +113,9 @@ struct controller_block * block_counter_create(char *name)
counter->calculate = calculate;
if (controller_block_param_list_init(counter, params))
if (controller_block_param_list_add(counter, params))
goto err_paramlist;
counter->param_get = param_get;
counter->param_set = param_set;
controller_block_add(counter);
return counter;
......
......@@ -73,9 +73,6 @@ struct controller_block * block_debug_create(char *name)
debug->calculate = calculate;
debug->params = 0;
debug->param = NULL;
debug->param_get = NULL;
debug->param_set = NULL;
controller_block_add(debug);
return debug;
......
......@@ -108,9 +108,6 @@ struct controller_block * block_decoder_uint32_bool_create(char *name, va_list a
dec->calculate = calculate;
dec->params = 0;
dec->param = NULL;
dec->param_get = NULL;
dec->param_set = NULL;
controller_block_add(dec);
return dec;
......
......@@ -76,82 +76,57 @@ static void filter_iir_calculate(struct controller_block *iir)
priv->out = out;
}
static struct controller_block_param_list params[] = {
{ "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)
static int param_set(struct controller_block *iir, va_list ap)
{
int i;
int new_param = 0;
switch (param) {
case 0: {
int len;
float gain;
float *poles;
float *zeros;
int len;
float gain;
float *poles;
float *zeros;
len = va_arg(ap, int);
gain = va_arg(ap, double);
poles = va_arg(ap, float *);
zeros = va_arg(ap, float *);
len = va_arg(ap, int);
gain = va_arg(ap, double);
poles = va_arg(ap, float *);
zeros = va_arg(ap, float *);
iir->private->param.len = len;
iir->private->param.gain = gain;
iir->private->param.poles = poles;
iir->private->param.zeros = zeros;
iir->private->param.len = len;
iir->private->param.gain = gain;
iir->private->param.poles = poles;
iir->private->param.zeros = zeros;
new_param = 1;
break;
}
case 1:
break;
}
if (new_param) {
if (iir->private->transfer)
free(iir->private->transfer);
if (iir->private->transfer)
free(iir->private->transfer);
iir->private->len = iir->private->param.len + 1;
iir->private->transfer = malloc(sizeof(float[4]) *
iir->private->len);
if (!iir->private->transfer) {
iir->private->len = 0;
return;
}
iir->private->transfer[0][0] = 0;
iir->private->transfer[iir->private->param.len ][1] =
1.0 / iir->private->param.gain;
for (i = 0; i < iir->private->param.len; i++) {
iir->private->transfer[i + 1][0] =
iir->private->param.poles[i];
iir->private->transfer[i][1] =
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;
iir->private->len = iir->private->param.len + 1;
iir->private->transfer = malloc(sizeof(float[4]) *
iir->private->len);
if (!iir->private->transfer) {
iir->private->len = 0;
return -1;
}
iir->private->transfer[0][0] = 0;
iir->private->transfer[iir->private->param.len ][1] =
1.0 / iir->private->param.gain;
for (i = 0; i < iir->private->param.len; i++) {
iir->private->transfer[i + 1][0] =
iir->private->param.poles[i];
iir->private->transfer[i][1] =
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;
return 0;
}
static struct controller_block_param_list params[] = {
{ "transfer", true, param_set },
{ NULL },
};
static struct controller_block_interm_list interms[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) },
{ NULL }
......@@ -182,12 +157,9 @@ struct controller_block * block_filter_iir_create(char *name)
iir->calculate = filter_iir_calculate;
if (controller_block_param_list_init(iir, params))
if (controller_block_param_list_add(iir, params))
goto err_block;
iir->param_get = param_get;
iir->param_set = param_set;
controller_block_add(iir);
return iir;
......
......@@ -22,7 +22,7 @@
#include <string.h>
#include <controller/controller_block.h>
#include <controller/controller_sample.h>
/*
inputs outputs
......@@ -56,42 +56,21 @@ static void filter_lp_calculate(struct controller_block *lp)
priv->out = out;
}
static struct controller_block_param_list params[] = {
{ "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)
static int param_set(struct controller_block *lp, va_list val)
{
switch (param) {
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->tau = va_arg(val, double);
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[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) },
{ NULL }
......@@ -122,12 +101,9 @@ struct controller_block * block_filter_lp_create(char *name)
lp->calculate = filter_lp_calculate;
if (controller_block_param_list_init(lp, params))
if (controller_block_param_list_add(lp, params))
goto err_block;
lp->param_get = param_get;
lp->param_set = param_set;
controller_block_add(lp);
return lp;
......
......@@ -96,54 +96,46 @@ static void friction_calculate(struct controller_block *friction)
}
}
static struct controller_block_param_list params[] = {
{ "friction_static", false },
{ "friction_dynamic", false },
{ "deadzone_max", false },
{ "deadzone_min", false },
{ NULL },
};
static int param_set_friction_static(struct controller_block *friction, va_list val)
{
struct controller_block_private *priv = friction->private;
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;
switch (param) {
case 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;
}
priv->friction_dynamic = va_arg(val, double);
return 0;
}
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;
switch (param) {
case 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;
}
priv->deadzone_max = va_arg(val, double);
return 0;
}
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[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) },
{ "speed", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input1) },
......@@ -176,12 +168,9 @@ struct controller_block * block_friction_create(char *name)
friction->calculate = friction_calculate;
if (controller_block_param_list_init(friction, params))
if (controller_block_param_list_add(friction, params))
goto err_block;
friction->param_get = param_get;
friction->param_set = param_set;
controller_block_add(friction);
return friction;
......
......@@ -48,28 +48,16 @@ static void gain_calculate(struct controller_block *gain)
priv->out = *priv->input0 * priv->gain;
}
static struct controller_block_param_list params[] = {
{ "gain", false },
{ NULL },
};
static void param_get(struct controller_block *gain, int param, void *val)
static int param_set(struct controller_block *gain, va_list val)
{
switch (param) {
case 0:
*(float*)val = gain->private->gain;
break;
}
gain->private->gain = va_arg(val, double);
return 0;
}
static void param_set(struct controller_block *gain, int param, va_list val)
{
switch (param) {
case 0:
gain->private->gain = va_arg(val, double);
break;
}
}
static struct controller_block_param_list params[] = {
{ "gain", false, param_set },
{ NULL },
};
static struct controller_block_interm_list interms[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, input0) },
......@@ -99,12 +87,9 @@ struct controller_block * block_gain_create(char *name)
gain->calculate = gain_calculate;
if (controller_block_param_list_init(gain, params))
if (controller_block_param_list_add(gain, params))
goto err_block;
gain->param_get = param_get;
gain->param_set = param_set;
controller_block_add(gain);
return gain;
......
......@@ -76,11 +76,6 @@ struct controller_block * block_gain_var_create(char *name)
gain->calculate = gain_var_calculate;
gain->params = 0;
gain->param = NULL;
gain->param_get = NULL;
gain->param_set = NULL;
controller_block_add(gain);
return gain;
......
......@@ -52,43 +52,31 @@ static void calculate(struct controller_block *gain)
priv->out = priv->c0 + priv->c1 / (*priv->in + priv->c2);
}
static struct controller_block_param_list params[] = {
{ "c0", false },
{ "c1", false },
{ "c2", false },
{ NULL },
};
static int param_set_c0(struct controller_block *iprop, va_list val)
{
iprop->private->c0 = va_arg(val, double);
return 0;
}
static void param_get(struct controller_block *iprop, int param, void *val)
static int param_set_c1(struct controller_block *iprop, va_list val)
{
switch (param) {
case 0:
*(float*)val = iprop->private->c0;
break;
case 1:
*(float*)val = iprop->private->c1;
break;
case 2:
*(float*)val = iprop->private->c2;
break;
}
iprop->private->c1 = va_arg(val, double);
return 0;
}
static void param_set(struct controller_block *iprop, int param, va_list val)
static int param_set_c2(struct controller_block *iprop, va_list val)
{
switch (param) {
case 0:
iprop->private->c0 = va_arg(val, double);
break;
case 1:
iprop->private->c1 = va_arg(val, double);
break;
case 2: