Commit ab83cffc authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Merge ../dt_ctrl-pand into beaglebone

parents feb47c82 ba967183
/*
Copyright (c) 2015,
Daan Vreeken <Daan @ Vitsch . nl> - Vitsch Electronics
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2008, 2009
Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2008, 2009
......@@ -435,6 +437,20 @@ int controller_block_connect(char *outblock, char *outterm, char *inblock, char
}
}
// Keep this list in sync with the controller_block_term_type enum in
// controller_block.h !
static const char *term_type_str[] = {
"(unknown)",
"float",
"bool",
"uint8",
"uint16",
"uint32",
"sint8",
"sint16",
"sint32",
};
static void set_ghost_otherside(struct controller_block_interm *input,
struct controller_block *otherside, void *outptr)
{
......@@ -466,6 +482,7 @@ static int controller_block_resolve_link(struct controller_block_link *link)
}
if (in && out) {
// Try to find the output.
for (i = 0; i < out->outputs; i++) {
if (!strcmp(out->output[i].name, link->outterm)) {
outptr = out->output[i].value.v;
......@@ -473,37 +490,52 @@ static int controller_block_resolve_link(struct controller_block_link *link)
outtype = out->output[i].type;
}
}
if (outptr) {
for (i = 0; i < in->inputs; i++) {
if (strcmp(in->input[i].name, link->interm) ||
in->input[i].type != outtype)
continue;
link->type = controller_block_term_str(in->input[i].type);
log_send(LOG_T_DEBUG,
"Linking %s.%s to %s.%s%s",
link->outblock, link->outterm,
link->inblock, link->interm,
link->chain ? " (chained)" : "");
*in->input[i].value.v = outptr;
if (link->chain)
in->input[i].otherside = outsource;
else
in->input[i].otherside = NULL;
set_ghost_otherside(&in->input[i],
link->chain ? outsource : NULL, outptr);
return 0;
}
log_send(LOG_T_ERROR,
"Input terminal %s.%s not found",
link->inblock, link->interm);
} else {
if (outptr == NULL) {
log_send(LOG_T_ERROR,
"Output terminal %s.%s not found",
link->outblock, link->outterm);
return -1;
}
// Try to find the input.
for (i = 0; i < in->inputs; i++) {
if (strcmp(in->input[i].name, link->interm) == 0)
break;
}
if (i >= in->inputs) {
log_send(LOG_T_ERROR,
"Input terminal %s.%s not found", link->inblock,
link->interm);
return -1;
}
if (in->input[i].type != outtype) {
log_send(LOG_T_ERROR,
"Type mismatch. Can't connect output terminal "
"%s.%s (of type '%s') to input terminal %s.%s "
"(of type '%s')",
link->outblock, link->outterm,
term_type_str[outtype],
link->inblock, link->interm,
term_type_str[in->input[i].type]);
return -1;
}
// Found both. Let's link them..
link->type = controller_block_term_str(in->input[i].type);
log_send(LOG_T_DEBUG,
"Linking %s.%s to %s.%s%s",
link->outblock, link->outterm,
link->inblock, link->interm,
link->chain ? " (chained)" : "");
*in->input[i].value.v = outptr;
if (link->chain)
in->input[i].otherside = outsource;
else
in->input[i].otherside = NULL;
set_ghost_otherside(&in->input[i],
link->chain ? outsource : NULL, outptr);
return 0;
} else {
if (!in) {
log_send(LOG_T_DEBUG,
......
......@@ -27,8 +27,9 @@
#include <semaphore.h>
#include <stdarg.h>
// Keep this enum in sync with the term_type_str array in controller_block.c !
enum controller_block_term_type {
CONTROLLER_BLOCK_TERM_VOID, /* Special case for checks... do NOT use! */
CONTROLLER_BLOCK_TERM_VOID = 0, /* Special case for checks... do NOT use! */
CONTROLLER_BLOCK_TERM_FLOAT,
CONTROLLER_BLOCK_TERM_BOOL,
CONTROLLER_BLOCK_TERM_UINT8,
......
......@@ -726,6 +726,7 @@ int controller_load(char *filename)
struct controller_load_extra extra;
char *saved_context;
yyscan_t scanner;
int ret;
extra.filename = filename;
extra.ret = 0;
......@@ -756,7 +757,11 @@ int controller_load(char *filename)
yylex_destroy(scanner);
fclose(extra.input_file);
controller_block_link();
ret = controller_block_link();
if (ret != 0) {
log_send(LOG_T_ERROR, "Failed to link controller!");
return ret;
}
err_nofile:
return extra.ret;
......
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