Commit 3b95f7cc authored by Daan Vreeken's avatar Daan Vreeken
Browse files

Fix error reporting when connecting inputs/outputs of differt types together.

Untill now, connecting e.g. a 'bool' output to a 'float' input would give:

 ERROR: Input terminal x.y not found

.. although both the input and the output existed.
With this commit, the error will read :

 ERROR: Type mismatch. Can't connect output terminal a.b (of type 'bool') to
 input terminal x.y (of type 'float')

	modified:   controller/controller_block.c
	modified:   controller/controller_block.h
parent 680e0017
/*
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)
{
......@@ -482,8 +498,7 @@ static int controller_block_resolve_link(struct controller_block_link *link)
}
// Try to find the input.
for (i = 0; i < in->inputs; i++) {
if ((strcmp(in->input[i].name, link->interm) == 0) &&
(in->input[i].type == outtype))
if (strcmp(in->input[i].name, link->interm) == 0)
break;
}
if (i >= in->inputs) {
......@@ -492,6 +507,17 @@ static int controller_block_resolve_link(struct controller_block_link *link)
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);
......
......@@ -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,
......
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