Commit 85f7e50b authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Make .ctrl files independent of order

parent 174ac719
......@@ -378,14 +378,10 @@ int controller_block_link_nr(void)
return link_nr;
}
static void controller_block_link_add(char *outblock, char *outterm, char *inblock, char *interm, int chain, char *type)
int controller_block_connect(char *outblock, char *outterm, char *inblock, char *interm, int chain)
{
struct controller_block_link *tmp;
printf("Linking %s.%s to %s.%s%s\n",
outblock, outterm, inblock, interm,
chain ? " (chained)" : "");
link_nr++;
tmp = realloc(
links,
......@@ -397,12 +393,15 @@ static void controller_block_link_add(char *outblock, char *outterm, char *inblo
links[link_nr-1].inblock = strdup(inblock);
links[link_nr-1].interm = strdup(interm);
links[link_nr-1].chain = chain;
links[link_nr-1].type = type;
links[link_nr-1].type = NULL;
return 0;
} else {
return -1;
}
}
int controller_block_connect(char *outblock, char *outterm,
char *inblock, char *interm, int chain)
static int controller_block_resolve_link(struct controller_block_link *link)
{
struct controller_block *out = NULL;
struct controller_block *in = NULL;
......@@ -413,15 +412,15 @@ int controller_block_connect(char *outblock, char *outterm,
enum controller_block_term_type outtype = CONTROLLER_BLOCK_TERM_VOID;
for (i = 0; i < nr_blocks; i++) {
if (!strcmp(outblock, blocks[i]->name))
if (!strcmp(link->outblock, blocks[i]->name))
out = blocks[i];
if (!strcmp(inblock, blocks[i]->name))
if (!strcmp(link->inblock, blocks[i]->name))
in = blocks[i];
}
if (in && out) {
for (i = 0; i < out->outputs; i++) {
if (!strcmp(out->output[i].name, outterm)) {
if (!strcmp(out->output[i].name, link->outterm)) {
outptr = out->output[i].value.v;
outsource = out->output[i].source;
outtype = out->output[i].type;
......@@ -429,19 +428,25 @@ int controller_block_connect(char *outblock, char *outterm,
}
if (outptr) {
for (i = 0; i < in->inputs; i++) {
if (!strcmp(in->input[i].name, interm) &&
if (!strcmp(in->input[i].name, link->interm) &&
in->input[i].type == outtype) {
controller_block_link_add(outblock, outterm, inblock, interm, chain,
controller_block_term_str(in->input[i].type));
link->type = controller_block_term_str(in->input[i].type);
printf("Linking %s.%s to %s.%s%s\n",
link->outblock, link->outterm,
link->inblock, link->interm,
link->chain ? " (chained)" : "");
*in->input[i].value.v = outptr;
if (chain)
if (link->chain)
in->input[i].otherside = outsource;
else
in->input[i].otherside = NULL;
for (realin = &in->input[i];
realin->ghostof;
realin = realin->ghostof) {
if (chain)
if (link->chain)
realin->ghostof->otherside = outsource;
else
realin->ghostof->otherside = NULL;
......@@ -450,25 +455,47 @@ int controller_block_connect(char *outblock, char *outterm,
}
}
printf("Input terminal %s.%s not found\n",
inblock, interm);
link->inblock, link->interm);
} else {
printf("Output terminal %s.%s not found\n",
outblock, outterm);
link->outblock, link->outterm);
}
} else {
if (!in) {
printf("Input block %s not found\n",
inblock);
printf("Input block %s does not (yet) exist, will try to link later\n",
link->inblock);
}
if (!out) {
printf("Output block %s not found\n",
outblock);
printf("Output block %s does not (yet) exist, will try to link later\n",
link->outblock);
}
}
return -1;
}
int controller_block_link(void)
{
int i, r;
int ret = 0;
for (i = 0; i < controller_block_link_nr(); i++) {
struct controller_block_link *link;
link = controller_block_link_get(i);
if (!link->type) {
r = controller_block_resolve_link(link);
if (r) {
ret = r;
}
}
}
return ret;
}
static pthread_mutex_t trace_lock;
static sem_t trace_sync_sem;
static sem_t trace_waitsem;
......
......@@ -161,6 +161,7 @@ int controller_block_output_get_float(char *block, char *param, float *value);
int controller_block_connect(char *outblock, char *outterm,
char *inblock, char *interm, int chain);
int controller_block_link(void);
struct controller_block_link *controller_block_link_get(int nr);
int controller_block_link_nr(void);
......
......@@ -106,7 +106,7 @@ void controller_dumpdot(char *filename)
link->outblock, link->outterm,
link->inblock, link->interm,
link->chain ? "color=\"black\"" : "color=\"blue\",constraint=false",
link->type);
link->type ? link->type : "unknown" );
}
......
......@@ -25,6 +25,7 @@
#include "controller_load_parser.yy.h"
#include "controller_load.h"
#include "controller_sample.h"
#include "controller_block.h"
#include "../../common/include/dynarg.h"
#include <shell/shell.h>
......@@ -269,5 +270,7 @@ int controller_load(char *filename)
yylex_destroy(scanner);
fclose(controller_load_input_file);
controller_block_link();
return controller_load_ret;
}
......@@ -52,20 +52,6 @@ int controller_trace_nr(void)
void controller_trace_list_add(struct controller_trace_name *trace)
{
struct controller_trace_name *tmp;
struct controller_block *block;
struct controller_block_outterm *outterm;
block = controller_block_find(trace->blockname);
if (!block) {
printf("Block %s does not exist.\n", trace->blockname);
return;
}
outterm = controller_block_find_outterm(block, trace->termname);
if (!outterm) {
printf("Block %s does not have an output named %s.\n",
trace->blockname, trace->termname);
}
nr_traces++;
tmp = realloc(trace_list, sizeof(struct controller_trace) * nr_traces);
......
......@@ -89,6 +89,13 @@ int main(int argc, char **argv)
{
controller_block_param_init();
/* Create and link blocks */
if (controller_load("dt_ctrl.ctrl")) {
printf("Could not link blocks\n");
return 1;
}
#ifdef USE_EL_SIM
if (controller_load("dt_ctrl_el_sim.ctrl")) {
printf("Could not link blocks\n");
......@@ -113,14 +120,6 @@ int main(int argc, char **argv)
}
#endif /* USE_AZ_SIM */
/* Create and link blocks */
if (controller_load("dt_ctrl.ctrl")) {
printf("Could not link blocks\n");
return 1;
}
param_load();
......
......@@ -95,7 +95,7 @@ params {
{ "dt_el_cross_tension_r", "gain", (float)-50.0 }
{ "dt_el_cross_tension_l", "gain", (float)-50.0 }
{ "dt_el_safety_t", "value", (bool)1 }
{ "dt_el_safety_t", "value", true }
{ "dt_el_safety_b", "value", (bool)1 }
{ "dt_el_safety_r", "value", (bool)1 }
{ "dt_el_safety_l", "value", (bool)1 }
......
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