Commit 2a57221a authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Make registration of terminals simpler for most blocks

Ghost terminals still need special attention, but most blocks don't
use them and use the same malloc + initialize pattern.
parent f3e1ff7a
il2c/il2c
block_and2.c
block_not.c
block_or2.c
block_or3.c
block_or4.c
block_register.c
block_setreset.c
/* Automaticly generated block 'and2' */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <controller/controller_block.h>
struct controller_block_private {
/* Input variables: */
bool *a;
bool *b;
/* Output variables: */
bool q;
/* Local variables: */
/* Param variables: */
};
static void calculate(struct controller_block *block)
{
bool a = *block->private->a;
bool b = *block->private->b;
bool q = block->private->q;
uint32_t _il2c_acc_ui32 __attribute__ ((__unused__));
double _il2c_acc_double __attribute__ ((__unused__));
_il2c_acc_ui32 = a;
_il2c_acc_ui32 = ((bool)_il2c_acc_ui32) & b;
q = (bool)(_il2c_acc_ui32 & 0x1);
block->private->q = q;
}
struct controller_block * block_and2_create(char *name)
{
struct controller_block *block;
if (!(block = malloc(sizeof(struct controller_block))))
return NULL;
block->type = "and2";
if (!(block->name = strdup(name)))
return NULL;
if (!(block->private = malloc(sizeof(struct controller_block_private))))
return NULL;
block->inputs = 2;
if (!(block->input = malloc(sizeof(struct controller_block_interm) * 2)))
return NULL;
block->input[0].name = "a";
block->input[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[0].value.v = (void*)&block->private->a;
block->input[0].ghostof = NULL;
block->input[1].name = "b";
block->input[1].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[1].value.v = (void*)&block->private->b;
block->input[1].ghostof = NULL;
block->outputs = 1;
if (!(block->output = malloc(sizeof(struct controller_block_outterm) * 1)))
return NULL;
block->output[0].name = "q";
block->output[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->output[0].value.v = (void*)&block->private->q;
block->output[0].source = block;
block->calculate = calculate;
block->params = 0;
block->param = NULL;
block->param_get = NULL;
block->param_set = NULL;
controller_block_add(block);
return block;
}
/* Automaticly generated block 'not' */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <controller/controller_block.h>
struct controller_block_private {
/* Input variables: */
bool *input;
/* Output variables: */
bool output;
/* Local variables: */
/* Param variables: */
};
static void calculate(struct controller_block *block)
{
bool input = *block->private->input;
bool output = block->private->output;
uint32_t _il2c_acc_ui32 __attribute__ ((__unused__));
double _il2c_acc_double __attribute__ ((__unused__));
_il2c_acc_ui32 = input;
_il2c_acc_ui32 = ~ _il2c_acc_ui32;
output = (bool)(_il2c_acc_ui32 & 0x1);
block->private->output = output;
}
struct controller_block * block_not_create(char *name)
{
struct controller_block *block;
if (!(block = malloc(sizeof(struct controller_block))))
return NULL;
block->type = "not";
if (!(block->name = strdup(name)))
return NULL;
if (!(block->private = malloc(sizeof(struct controller_block_private))))
return NULL;
block->inputs = 1;
if (!(block->input = malloc(sizeof(struct controller_block_interm) * 1)))
return NULL;
block->input[0].name = "input";
block->input[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[0].value.v = (void*)&block->private->input;
block->input[0].ghostof = NULL;
block->outputs = 1;
if (!(block->output = malloc(sizeof(struct controller_block_outterm) * 1)))
return NULL;
block->output[0].name = "output";
block->output[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->output[0].value.v = (void*)&block->private->output;
block->output[0].source = block;
block->calculate = calculate;
block->params = 0;
block->param = NULL;
block->param_get = NULL;
block->param_set = NULL;
controller_block_add(block);
return block;
}
/* Automaticly generated block 'or2' */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <controller/controller_block.h>
struct controller_block_private {
/* Input variables: */
bool *a;
bool *b;
/* Output variables: */
bool q;
/* Local variables: */
/* Param variables: */
};
static void calculate(struct controller_block *block)
{
bool a = *block->private->a;
bool b = *block->private->b;
bool q = block->private->q;
uint32_t _il2c_acc_ui32 __attribute__ ((__unused__));
double _il2c_acc_double __attribute__ ((__unused__));
_il2c_acc_ui32 = a;
_il2c_acc_ui32 = ((bool)_il2c_acc_ui32) | b;
q = (bool)(_il2c_acc_ui32 & 0x1);
block->private->q = q;
}
struct controller_block * block_or2_create(char *name)
{
struct controller_block *block;
if (!(block = malloc(sizeof(struct controller_block))))
return NULL;
block->type = "or2";
if (!(block->name = strdup(name)))
return NULL;
if (!(block->private = malloc(sizeof(struct controller_block_private))))
return NULL;
block->inputs = 2;
if (!(block->input = malloc(sizeof(struct controller_block_interm) * 2)))
return NULL;
block->input[0].name = "a";
block->input[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[0].value.v = (void*)&block->private->a;
block->input[0].ghostof = NULL;
block->input[1].name = "b";
block->input[1].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[1].value.v = (void*)&block->private->b;
block->input[1].ghostof = NULL;
block->outputs = 1;
if (!(block->output = malloc(sizeof(struct controller_block_outterm) * 1)))
return NULL;
block->output[0].name = "q";
block->output[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->output[0].value.v = (void*)&block->private->q;
block->output[0].source = block;
block->calculate = calculate;
block->params = 0;
block->param = NULL;
block->param_get = NULL;
block->param_set = NULL;
controller_block_add(block);
return block;
}
/* Automaticly generated block 'or3' */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <controller/controller_block.h>
struct controller_block_private {
/* Input variables: */
bool *a;
bool *b;
bool *c;
/* Output variables: */
bool q;
/* Local variables: */
/* Param variables: */
};
static void calculate(struct controller_block *block)
{
bool a = *block->private->a;
bool b = *block->private->b;
bool c = *block->private->c;
bool q = block->private->q;
uint32_t _il2c_acc_ui32 __attribute__ ((__unused__));
double _il2c_acc_double __attribute__ ((__unused__));
_il2c_acc_ui32 = a;
_il2c_acc_ui32 = ((bool)_il2c_acc_ui32) | b;
_il2c_acc_ui32 = ((bool)_il2c_acc_ui32) | c;
q = (bool)(_il2c_acc_ui32 & 0x1);
block->private->q = q;
}
struct controller_block * block_or3_create(char *name)
{
struct controller_block *block;
if (!(block = malloc(sizeof(struct controller_block))))
return NULL;
block->type = "or3";
if (!(block->name = strdup(name)))
return NULL;
if (!(block->private = malloc(sizeof(struct controller_block_private))))
return NULL;
block->inputs = 3;
if (!(block->input = malloc(sizeof(struct controller_block_interm) * 3)))
return NULL;
block->input[0].name = "a";
block->input[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[0].value.v = (void*)&block->private->a;
block->input[0].ghostof = NULL;
block->input[1].name = "b";
block->input[1].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[1].value.v = (void*)&block->private->b;
block->input[1].ghostof = NULL;
block->input[2].name = "c";
block->input[2].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[2].value.v = (void*)&block->private->c;
block->input[2].ghostof = NULL;
block->outputs = 1;
if (!(block->output = malloc(sizeof(struct controller_block_outterm) * 1)))
return NULL;
block->output[0].name = "q";
block->output[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->output[0].value.v = (void*)&block->private->q;
block->output[0].source = block;
block->calculate = calculate;
block->params = 0;
block->param = NULL;
block->param_get = NULL;
block->param_set = NULL;
controller_block_add(block);
return block;
}
/* Automaticly generated block 'or4' */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <controller/controller_block.h>
struct controller_block_private {
/* Input variables: */
bool *a;
bool *b;
bool *c;
bool *d;
/* Output variables: */
bool q;
/* Local variables: */
/* Param variables: */
};
static void calculate(struct controller_block *block)
{
bool a = *block->private->a;
bool b = *block->private->b;
bool c = *block->private->c;
bool d = *block->private->d;
bool q = block->private->q;
uint32_t _il2c_acc_ui32 __attribute__ ((__unused__));
double _il2c_acc_double __attribute__ ((__unused__));
_il2c_acc_ui32 = a;
_il2c_acc_ui32 = ((bool)_il2c_acc_ui32) | b;
_il2c_acc_ui32 = ((bool)_il2c_acc_ui32) | c;
_il2c_acc_ui32 = ((bool)_il2c_acc_ui32) | d;
q = (bool)(_il2c_acc_ui32 & 0x1);
block->private->q = q;
}
struct controller_block * block_or4_create(char *name)
{
struct controller_block *block;
if (!(block = malloc(sizeof(struct controller_block))))
return NULL;
block->type = "or4";
if (!(block->name = strdup(name)))
return NULL;
if (!(block->private = malloc(sizeof(struct controller_block_private))))
return NULL;
block->inputs = 4;
if (!(block->input = malloc(sizeof(struct controller_block_interm) * 4)))
return NULL;
block->input[0].name = "a";
block->input[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[0].value.v = (void*)&block->private->a;
block->input[0].ghostof = NULL;
block->input[1].name = "b";
block->input[1].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[1].value.v = (void*)&block->private->b;
block->input[1].ghostof = NULL;
block->input[2].name = "c";
block->input[2].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[2].value.v = (void*)&block->private->c;
block->input[2].ghostof = NULL;
block->input[3].name = "d";
block->input[3].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[3].value.v = (void*)&block->private->d;
block->input[3].ghostof = NULL;
block->outputs = 1;
if (!(block->output = malloc(sizeof(struct controller_block_outterm) * 1)))
return NULL;
block->output[0].name = "q";
block->output[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->output[0].value.v = (void*)&block->private->q;
block->output[0].source = block;
block->calculate = calculate;
block->params = 0;
block->param = NULL;
block->param_get = NULL;
block->param_set = NULL;
controller_block_add(block);
return block;
}
/* Automaticly generated block 'register' */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <controller/controller_block.h>
struct controller_block_private {
/* Input variables: */
bool *input;
/* Output variables: */
bool output;
/* Local variables: */
/* Param variables: */
};
static void calculate(struct controller_block *block)
{
bool input = *block->private->input;
bool output = block->private->output;
uint32_t _il2c_acc_ui32 __attribute__ ((__unused__));
double _il2c_acc_double __attribute__ ((__unused__));
_il2c_acc_ui32 = input;
output = (bool)(_il2c_acc_ui32 & 0x1);
block->private->output = output;
}
struct controller_block * block_register_create(char *name)
{
struct controller_block *block;
if (!(block = malloc(sizeof(struct controller_block))))
return NULL;
block->type = "register";
if (!(block->name = strdup(name)))
return NULL;
if (!(block->private = malloc(sizeof(struct controller_block_private))))
return NULL;
block->inputs = 1;
if (!(block->input = malloc(sizeof(struct controller_block_interm) * 1)))
return NULL;
block->input[0].name = "input";
block->input[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->input[0].value.v = (void*)&block->private->input;
block->input[0].ghostof = NULL;
block->outputs = 1;
if (!(block->output = malloc(sizeof(struct controller_block_outterm) * 1)))
return NULL;
block->output[0].name = "output";
block->output[0].type = CONTROLLER_BLOCK_TERM_BOOL;
block->output[0].value.v = (void*)&block->private->output;
block->output[0].source = block;
block->calculate = calculate;
block->params = 0;
block->param = NULL;
block->param_get = NULL;
block->param_set = NULL;
controller_block_add(block);
return block;
}
......@@ -216,6 +216,23 @@ static struct controller_block_param_list params[] = {
{ NULL },
};
static struct controller_block_interm_list interms[] = {
{ "spg_x", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, spg_x) },
{ "spg_v", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, spg_v) },
{ "spg_a", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, spg_a) },
{ "safe", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, safe) },
{ NULL },
};
static struct controller_block_outterm_list outterms[] = {
{ "out_x", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, out_x) },
{ "out_v", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, out_v) },
{ "out_a", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, out_a) },
{ "reset", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, reset) },
{ "enable", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, enable) },
{ NULL },
};
static void param_get(struct controller_block *servo_state, int param, void *val)
{
switch (param) {
......@@ -309,51 +326,11 @@ struct controller_block * block_servo_state_create(char *name)
servo_state->private->state = SERVO_STATE_DISABLED;
servo_state->private->override = false;
servo_state->inputs = 4;
servo_state->input = malloc(sizeof(struct controller_block_interm) * 4);
if (!servo_state->input)
if (controller_block_interm_list_init(servo_state, interms))
goto err_private;
servo_state->input[0].name = "spg_x";
servo_state->input[0].type = CONTROLLER_BLOCK_TERM_FLOAT;
servo_state->input[0].value.f = &servo_state->private->spg_x;
servo_state->input[0].ghostof = NULL;
servo_state->input[1].name = "spg_v";
servo_state->input[1].type = CONTROLLER_BLOCK_TERM_FLOAT;
servo_state->input[1].value.f = &servo_state->private->spg_v;
servo_state->input[1].ghostof = NULL;
servo_state->input[2].name = "spg_a";
servo_state->input[2].type = CONTROLLER_BLOCK_TERM_FLOAT;
servo_state->input[2].value.f = &servo_state->private->spg_a;
servo_state->input[2].ghostof = NULL;
servo_state->input[3].name = "safe";
servo_state->input[3].type = CONTROLLER_BLOCK_TERM_BOOL;
servo_state->input[3].value.b = &servo_state->private->safe;
servo_state->input[3].ghostof = NULL;
servo_state->outputs = 5;
servo_state->output = malloc(sizeof(struct controller_block_outterm) * 5);
if (!servo_state->output)
if (controller_block_outterm_list_init(servo_state, outterms))
goto err_input;
servo_state->output[0].name = "out_x";
servo_state->output[0].type = CONTROLLER_BLOCK_TERM_FLOAT;
servo_state->output[0].value.f = &servo_state->private->out_x;
servo_state->output[0].source = servo_state;
servo_state->output[1].name = "out_v";
servo_state->output[1].type = CONTROLLER_BLOCK_TERM_FLOAT;
servo_state->output[1].value.f = &servo_state->private->out_v;
servo_state->output[1].source = servo_state;
servo_state->output[2].name = "out_a";
servo_state->output[2].type = CONTROLLER_BLOCK_TERM_FLOAT;