Commit 1ce6bcf9 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add BLOCK_CREATE macro to most blocks.

Fix some remaining parameter arguments
Add argument checking to il2c generated blocks.
parent 2f7a56f0
......@@ -469,7 +469,6 @@ void log_string(char *str, size_t len, enum log_type type, char *fmt, ...)
void log_flush_stdout(void)
{
while (msgs[msgs_rd].used) {
int i;
char time[100];
char *header;
struct tm gmt;
......
......@@ -60,7 +60,7 @@ static struct controller_block_outterm_list outterms[] = {
};
struct controller_block * block_add_create(char *name)
static struct controller_block * block_add_create(char *name, int argc, va_list val)
{
struct controller_block *add;
......@@ -84,3 +84,8 @@ err_block:
controller_block_free(add);
return NULL;
}
BLOCK_CREATE(add) = {
.create = block_add_create,
.args = { NULL },
};
......@@ -109,20 +109,12 @@ static void calculate(struct controller_block *bridge)
static int param_set_divider(struct controller_block *bridge, int argc, va_list val)
{
if (argc != 1) {
log_send(LOG_T_ERROR, "%s: parameter expects one argument", bridge->name);
return -1;
}
bridge->private->divider = va_arg(val, int);
return 0;
}
static int param_set_continuous(struct controller_block *bridge, int argc, va_list val)
{
if (argc != 1) {
log_send(LOG_T_ERROR, "%s: parameter expects one argument", bridge->name);
return -1;
}
bridge->private->continuous = va_arg(val, int);
return 0;
}
......@@ -131,12 +123,12 @@ 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, param_set_divider },
{ "divider", false, param_set_divider, .args = { "int", NULL } },
/* 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, param_set_continuous },
{ "continuous_on", false, param_set_continuous, .args = { "int", NULL } },
{ NULL },
};
......
......@@ -54,7 +54,7 @@ static struct controller_block_outterm_list outterms[] = {
};
struct controller_block * block_command_bool_create(char *name)
static struct controller_block * block_command_bool_create(char *name, int argc, va_list val)
{
struct controller_block *cmd;
......@@ -82,3 +82,8 @@ err_block:
controller_block_free(cmd);
return NULL;
}
BLOCK_CREATE(command_bool) = {
.create = block_command_bool_create,
.args = { NULL },
};
......@@ -57,10 +57,6 @@ static void calculate(struct controller_block *counter)
static int param_set_overflow(struct controller_block *counter, int argc, va_list val)
{
if (argc != 1) {
log_send(LOG_T_ERROR, "%s: parameter expects one argument", counter->name);
return -1;
}
counter->private->overflow = va_arg(val, int);
return 0;
}
......@@ -68,17 +64,13 @@ static int param_set_overflow(struct controller_block *counter, int argc, va_lis
static int param_set_value(struct controller_block *counter, int argc, va_list val)
{
if (argc != 1) {
log_send(LOG_T_ERROR, "%s: parameter expects one argument", counter->name);
return -1;
}
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 },
{ "overflow", false, param_set_overflow, .args = { "int", NULL } },
{ "value", false, param_set_value, .args = { "int", NULL } },
{ NULL },
};
......
......@@ -138,7 +138,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_filter_iir_create(char *name)
static struct controller_block * block_filter_iir_create(char *name, int argc, va_list val)
{
struct controller_block *iir;
......@@ -168,3 +168,8 @@ err_block:
controller_block_free(iir);
return NULL;
}
BLOCK_CREATE(filter_iir) = {
.create = block_filter_iir_create,
.args = { NULL },
};
......@@ -21,8 +21,6 @@
#include <controller/controller_block.h>
struct controller_block * block_filter_iir_create(char *name);
struct block_filter_iir_param {
int len;
float gain;
......
......@@ -84,7 +84,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_filter_lp_create(char *name)
static struct controller_block * block_filter_lp_create(char *name, int argc, va_list val)
{
struct controller_block *lp;
......@@ -114,3 +114,8 @@ err_block:
controller_block_free(lp);
return NULL;
}
BLOCK_CREATE(filter_lp) = {
.create = block_filter_lp_create,
.args = { NULL },
};
......@@ -148,7 +148,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_friction_create(char *name)
static struct controller_block * block_friction_create(char *name, int argc, va_list val)
{
struct controller_block *friction;
......@@ -179,3 +179,8 @@ err_block:
controller_block_free(friction);
return NULL;
}
BLOCK_CREATE(friction) = {
.create = block_friction_create,
.args = { NULL },
};
......@@ -70,7 +70,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_gain_create(char *name)
static struct controller_block * block_gain_create(char *name, int argc, va_list val)
{
struct controller_block *gain;
......@@ -98,3 +98,8 @@ err_block:
controller_block_free(gain);
return NULL;
}
BLOCK_CREATE(gain) = {
.create = block_gain_create,
.args = { NULL },
};
......@@ -55,38 +55,26 @@ static void calculate(struct controller_block *gain)
static int param_set_c0(struct controller_block *iprop, int argc, va_list val)
{
if (argc != 1) {
log_send(LOG_T_ERROR, "%s: parameter expects one argument", iprop->name);
return -1;
}
iprop->private->c0 = va_arg(val, double);
return 0;
}
static int param_set_c1(struct controller_block *iprop, int argc, va_list val)
{
if (argc != 1) {
log_send(LOG_T_ERROR, "%s: parameter expects one argument", iprop->name);
return -1;
}
iprop->private->c1 = va_arg(val, double);
return 0;
}
static int param_set_c2(struct controller_block *iprop, int argc, va_list val)
{
if (argc != 1) {
log_send(LOG_T_ERROR, "%s: parameter expects one argument", iprop->name);
return -1;
}
iprop->private->c2 = va_arg(val, double);
return 0;
}
static struct controller_block_param_list params[] = {
{ "c0", false, param_set_c0 },
{ "c1", false, param_set_c1 },
{ "c2", false, param_set_c2 },
{ "c0", false, param_set_c0, .args = { "double", NULL } },
{ "c1", false, param_set_c1, .args = { "double", NULL } },
{ "c2", false, param_set_c2, .args = { "double", NULL } },
{ NULL },
};
......
......@@ -89,7 +89,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_limit_create(char *name)
static struct controller_block * block_limit_create(char *name, int argc, va_list val)
{
struct controller_block *limit;
......@@ -118,3 +118,8 @@ err_block:
controller_block_free(limit);
return NULL;
}
BLOCK_CREATE(limit) = {
.create = block_limit_create,
.args = { NULL },
};
......@@ -171,7 +171,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_limit_2nd_create(char *name)
static struct controller_block * block_limit_2nd_create(char *name, int argc, va_list val)
{
struct controller_block *limit;
......@@ -205,3 +205,8 @@ err_block:
controller_block_free(limit);
return NULL;
}
BLOCK_CREATE(limit_2nd) = {
.create = block_limit_2nd_create,
.args = { NULL },
};
......@@ -71,7 +71,7 @@ static struct controller_block_outterm_list outterms[] = {
};
struct controller_block * block_limit_dyn_create(char *name)
static struct controller_block * block_limit_dyn_create(char *name, int argc, va_list val)
{
struct controller_block *limit;
......@@ -95,3 +95,8 @@ err_block:
controller_block_free(limit);
return NULL;
}
BLOCK_CREATE(limit_dyn) = {
.create = block_limit_dyn_create,
.args = { NULL },
};
......@@ -95,7 +95,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_limit_var_create(char *name)
static struct controller_block * block_limit_var_create(char *name, int argc, va_list val)
{
struct controller_block *limit;
......@@ -122,3 +122,8 @@ err_block:
controller_block_free(limit);
return NULL;
}
BLOCK_CREATE(limit_var) = {
.create = block_limit_var_create,
.args = { NULL },
};
......@@ -100,7 +100,7 @@ static struct controller_block_outterm_list outterms[] = {
};
struct controller_block * block_matrix_2x2_create(char *name)
static struct controller_block * block_matrix_2x2_create(char *name, int argc, va_list val)
{
struct controller_block *matrix;
struct block_matrix_2x2_param defaults = {{{ 0.0, 0.0 }, { 0.0, 0.0 }}};
......@@ -135,3 +135,8 @@ err_private:
controller_block_free(matrix);
return NULL;
}
BLOCK_CREATE(matrix_2x2) = {
.create = block_matrix_2x2_create,
.args = { NULL },
};
......@@ -21,8 +21,6 @@
#include <controller/controller_block.h>
struct controller_block * block_matrix_2x2_create(char *name);
struct block_matrix_2x2_param {
float c[2][2];
};
......
......@@ -148,7 +148,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL },
};
struct controller_block * block_pand_create(char *name)
static struct controller_block * block_pand_create(char *name, int argc, va_list val)
{
struct controller_block *sub;
struct controller_block_private *priv;
......@@ -215,4 +215,7 @@ err_sub:
return NULL;
}
BLOCK_CREATE(pand) = {
.create = block_pand_create,
.args = { NULL },
};
......@@ -164,7 +164,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_pid_create(char *name)
static struct controller_block * block_pid_create(char *name, int argc, va_list val)
{
struct controller_block *pid;
......@@ -202,3 +202,8 @@ err_block:
controller_block_free(pid);
return NULL;
}
BLOCK_CREATE(pid) = {
.create = block_pid_create,
.args = { NULL },
};
......@@ -191,7 +191,7 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
struct controller_block * block_pid_aw_create(char *name)
static struct controller_block * block_pid_aw_create(char *name, int argc, va_list val)
{
struct controller_block *pid;
......@@ -230,3 +230,8 @@ err_block:
controller_block_free(pid);
return NULL;
}
BLOCK_CREATE(pid_aw) = {
.create = block_pid_aw_create,
.args = { NULL },
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment