Commit 66e580bd authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Merge ../dt_ctrl-pand into beaglebone

parents 6ef3df60 8cd6afe9
......@@ -147,7 +147,8 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL },
};
struct controller_block * block_bridge_pwm_create(char *name)
struct controller_block * block_bridge_pwm_create(char *name, int argc,
va_list val)
{
struct controller_block *bridge;
......@@ -189,3 +190,9 @@ err_inputs:
free(bridge);
return NULL;
}
BLOCK_CREATE(bridge_pwm) = {
.create = block_bridge_pwm_create,
.args = { NULL },
};
......@@ -57,14 +57,18 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
static struct controller_block * block_value_float_create(char *name, int argc, va_list ap)
static struct controller_block * block_value_float_create(char *name,
int argc, va_list ap)
{
struct controller_block *value;
if (!(value = controller_block_alloc("value_float", name, sizeof(struct controller_block_private))))
return NULL;
value->private->value = 0.0;
if (argc == 0)
value->private->value = 0.0;
else
value->private->value = va_arg(ap, double);
if (controller_block_outterm_list_init(value, outterms))
goto err_block;
......@@ -86,10 +90,10 @@ err_block:
BLOCK_CREATE(value_float) = {
.create = block_value_float_create,
.args = { NULL },
.args = { "", "double", NULL },
};
BLOCK_CREATE(value) = {
.create = block_value_float_create,
.args = { NULL },
.args = { "", "double", NULL },
};
......@@ -56,7 +56,8 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
static struct controller_block * block_value_bool_create(char *name, int argc, va_list val)
static struct controller_block * block_value_bool_create(char *name, int argc,
va_list val)
{
struct controller_block *value;
......@@ -64,7 +65,10 @@ static struct controller_block * block_value_bool_create(char *name, int argc, v
if (!value)
return NULL;
value->private->value = 0.0;
if (argc == 0)
value->private->value = false;
else
value->private->value = va_arg(val, int);
if (controller_block_outterm_list_init(value, outterms))
goto err_block;
......@@ -85,5 +89,5 @@ err_block:
BLOCK_CREATE(value_bool) = {
.create = block_value_bool_create,
.args = { NULL },
.args = { "", "int", NULL },
};
......@@ -57,14 +57,18 @@ static struct controller_block_outterm_list outterms[] = {
{ NULL }
};
static struct controller_block * block_value_uint32_create(char *name, int argc, va_list val)
static struct controller_block * block_value_uint32_create(char *name,
int argc, va_list val)
{
struct controller_block *value;
if (!(value = controller_block_alloc("value_uint32", name, sizeof(struct controller_block_private))))
return NULL;
value->private->value = 0.0;
if (argc == 0)
value->private->value = 0;
else
value->private->value = va_arg(val, int);
if (controller_block_outterm_list_init(value, outterms))
goto err_block;
......@@ -85,6 +89,6 @@ err_block:
BLOCK_CREATE(value_uint32) = {
.create = block_value_uint32_create,
.args = { NULL },
.args = { "", "int", NULL },
};
......@@ -78,8 +78,11 @@ int controller_block_create(char *type, char *name, int argc, va_list ap,
free(symbol);
if (!create) {
create = calloc(sizeof(struct controller_block_create) + sizeof(char *) * 2, 1);
if (!create)
if (create == NULL) {
log_send(LOG_T_ERROR, "Out of memory");
ret = -1;
goto err;
}
create_alloc = true;
......
/*
Copyright (c) 2015,
Daan Vreeken <Daan @ Vitsch . nl> - Vitsch Electronics
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2009
Copyright Stichting C.A. Muller Radioastronomiestation, 2009
......@@ -284,21 +286,23 @@ static char *rel2file(yyscan_t scanner, char *rel_name)
char *tmp;
char *slash;
if (!stat(rel_name, &stattmp))
if ((stat(rel_name, &stattmp) == 0) && (!(stattmp.st_mode & S_IFDIR)))
return strdup(rel_name);
if (!extra->filename)
return NULL;
tmp = strdup(extra->filename);
for (ret = tmp; *ret; ret++)
if (*ret == '/')
slash = ret;
*slash = 0;
slash = strrchr(tmp, '/');
if (slash == NULL) {
free(tmp);
return NULL;
}
*slash = '\0';
asprintf(&ret, "%s/%s", tmp, rel_name);
free(tmp);
if (!stat(ret, &stattmp))
if ((stat(ret, &stattmp) == 0) && (!(stattmp.st_mode & S_IFDIR)))
return ret;
free(ret);
......@@ -323,8 +327,7 @@ int controller_load_block_create(char *type, char *name, yyscan_t scanner)
if (!file_name) {
log_send(LOG_T_ERROR,
"Could not find create function or struct for block %s",
type);
"Could not load or create block '%s'", type);
return -1;
}
......@@ -369,7 +372,7 @@ static char *get_next_type(char **str)
}
static int check_one_argument_type_list(char *expected_types,
int supplied_argc, char **supplied_types)
int supplied_argc, char **supplied_types, bool show_errs)
{
char *supplied_type, *expected_type, *iter;
int idx;
......@@ -391,6 +394,11 @@ static int check_one_argument_type_list(char *expected_types,
if (expected_type == NULL) {
// Too many arguments supplied.
if (show_errs)
log_send(LOG_T_ERROR, "Invalid number of "
"arguments! Expecting %d argument%s "
"instead of %d.", idx,
(idx > 1) ? "s" : "", supplied_argc);
return -1;
}
......@@ -402,14 +410,30 @@ static int check_one_argument_type_list(char *expected_types,
}
if (strcmp(supplied_type, expected_type) != 0) {
if (show_errs)
log_send(LOG_T_ERROR, "Argument mismatch in "
"argument %d. Expected argument of type "
"'%s' instead of '%s'", idx + 1,
expected_type, supplied_type);
free(expected_type);
return -1;
}
free(expected_type);
}
if (*iter != '\0') {
// Not enough arguments.
// Not enough arguments.
if (show_errs) {
// See how many are missing..
while (expected_type != NULL) {
expected_type = get_next_type(&iter);
if (expected_type != NULL)
free(expected_type);
idx++;
}
log_send(LOG_T_ERROR, "Invalid number of arguments! "
"Expecting %d argument%s instead of %d.", idx,
(idx > 1) ? "s" : "", supplied_argc);
}
return -1;
}
......@@ -420,6 +444,8 @@ int controller_load_check_arg(char **expected_types, int supplied_argc,
char **supplied_types)
{
char **first;
char *str;
bool show_errs;
int ret;
if (expected_types[0] == NULL) {
......@@ -432,10 +458,12 @@ int controller_load_check_arg(char **expected_types, int supplied_argc,
return 0;
}
show_errs = (expected_types[1] == NULL);
first = expected_types;
while (*expected_types != NULL) {
ret = check_one_argument_type_list(*expected_types,
supplied_argc, supplied_types);
supplied_argc, supplied_types, show_errs);
if (ret == 0)
// Found a match. We're done.
return 0;
......@@ -448,10 +476,14 @@ int controller_load_check_arg(char **expected_types, int supplied_argc,
// there are too many / not enough of them).
// List the possible options to the user to help out the best we can..
log_send(LOG_T_ERROR,
"Invalid arguments! This function accepts any of the following:");
"Invalid arguments! This function accepts %sthe following:",
(expected_types[1] != NULL) ? "any of " : "");
expected_types = first;
while (*expected_types != NULL)
log_send(LOG_T_ERROR, "\t%s", *expected_types++);
while (*expected_types != NULL) {
str = *expected_types++;
log_send(LOG_T_ERROR, "\t%s", (*str != '\0') ?
str : "(no arguments)");
}
if (supplied_argc) {
log_send(LOG_T_ERROR, "The given arguments are:");
int i;
......
......@@ -349,7 +349,8 @@ static struct controller_block * block_dt_az_safety_create(char *name, int argc,
if (controller_block_param_list_add(safety, params))
goto err_output;
controller_block_add(safety);
if (controller_block_add(safety) != 0)
goto err_add;
safety->private->command = controller_command_create(
safety, name, "Recover");
......@@ -358,6 +359,7 @@ static struct controller_block * block_dt_az_safety_create(char *name, int argc,
return safety;
err_add:
err_output:
free(safety->output);
err_input:
......
......@@ -573,7 +573,8 @@ static struct controller_block * block_dt_el_safety_create(char *name, int argc,
if (controller_block_param_list_add(safety, params))
goto err_output;
controller_block_add(safety);
if (controller_block_add(safety) != 0)
goto err_add;
safety->private->command = controller_command_create(
safety, name, "Recover");
......@@ -582,6 +583,7 @@ static struct controller_block * block_dt_el_safety_create(char *name, int argc,
return safety;
err_add:
err_output:
free(safety->output);
err_input:
......
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