Commit 6a75b662 authored by Daan Vreeken's avatar Daan Vreeken
Browse files

Merge remote-tracking branch 'origin/beaglebone' into beaglebone

parents 98a05aa4 f7902967
/*
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2007
......@@ -26,9 +26,10 @@
#include <netinet/in.h>
#include <trace/trace.h>
#include <dt_port_numbers.h>
static char *host = "localhost";
static int port = 10000;
static int port = CONSOLE_TRACE_PORT;
static void handler_interval(struct trace *trace,
struct timespec *interval, enum trace_interval_type type)
......@@ -73,6 +74,13 @@ int main(int argc, char **argv)
trace_handle(trace, &fdrx);
}
if (trace_state_get(trace) == TRACE_STATE_DISCONNECTED) {
printf("Not connected.\n");
printf("Usage: %s <host> <port>\n", argv[0]);
printf("Typical ports: %d, %d\n",
CONSOLE_TRACE_PORT, CTRL_TRACE_PORT);
}
return 0;
}
......@@ -57,6 +57,13 @@ static struct controller_block_outterm_list outterms[] = {
static struct controller_block * block_command_bool_create(char *name, int argc, va_list val)
{
struct controller_block *cmd;
char *cmd_name = name;
char *cmd_unit = "Boolean";
if (argc >= 1)
cmd_name = va_arg(val, char *);
if (argc >= 2)
cmd_unit = va_arg(val, char *);
if (!(cmd = controller_block_alloc("command_bool", name, sizeof(struct controller_block_private))))
return NULL;
......@@ -72,7 +79,7 @@ static struct controller_block * block_command_bool_create(char *name, int argc,
if (controller_block_add(cmd))
goto err_block;
cmd->private->command = controller_command_create(cmd, name, "Boolean");
cmd->private->command = controller_command_create(cmd, cmd_name, cmd_unit);
cmd->private->command->value_type = COMMAND_VALUE_TYPE_BOOL;
cmd->private->command->command_types[0] = COMMAND_PTYPE_SETPOINT;
......@@ -85,5 +92,5 @@ err_block:
BLOCK_CREATE(command_bool) = {
.create = block_command_bool_create,
.args = { NULL },
.args = { "", "char*", "char*,char*", NULL },
};
......@@ -5,6 +5,8 @@ trigger {
blocks (10.0, 0.0) {
{ "command_bool", "command_bool" }
{ "command_bool", "command_bool_named", "aname" }
{ "command_bool", "command_bool_named_unit", "anothername", "aunit" }
{ "test_output_bool", "value" }
{ "test_output_uint32", "id" }
......@@ -29,6 +31,8 @@ params {
{ "command", "command", "command_bool", $[SETPOINT], 567, false }
{ "command", "command", "command_bool", $[SETPOINT], 666, true }
{ "command", "command", "command_bool", $[SETPOINT], 777, false }
{ "command", "command", "aname", $[SETPOINT], 1888, false }
{ "command", "command", "anothername", $[SETPOINT], 2888, false }
{ "value", "value", 10,
(int) { false, true, true, false, true, false, false, false, false, false }
......
/*
Copyright Jeroen Vreeken (jeroen@vreken.net), 2015
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <log/log.h>
#include <controller/controller_block.h>
#include <controller/controller_command.h>
struct controller_block_private {
float value;
uint32_t id;
struct controller_command *command;
};
static void command_calculate(struct controller_block *cmd)
{
struct controller_block_private *priv = cmd->private;
struct command_entry c_entry;
if (!controller_command_queue_read(priv->command, &c_entry)) {
priv->value = c_entry.value.f;
priv->id = c_entry.id;
} else {
priv->id = COMMAND_ID_NONE;
}
}
static struct controller_block_outterm_list outterms[] = {
{ "value", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, value) },
{ "id", CONTROLLER_BLOCK_TERM_UINT32, offsetof(struct controller_block_private, id) },
{ NULL },
};
static struct controller_block * block_command_float_create(char *name, int argc, va_list val)
{
struct controller_block *cmd;
char *cmd_name = name;
char *cmd_unit = "Float";
if (argc >= 1)
cmd_name = va_arg(val, char *);
if (argc >= 2)
cmd_unit = va_arg(val, char *);
if (!(cmd = controller_block_alloc("command_float", name, sizeof(struct controller_block_private))))
return NULL;
cmd->private->value = false;
cmd->private->id = COMMAND_ID_NONE;
if (controller_block_outterm_list_init(cmd, outterms))
goto err_block;
cmd->calculate = command_calculate;
if (controller_block_add(cmd))
goto err_block;
cmd->private->command = controller_command_create(cmd, cmd_name, cmd_unit);
cmd->private->command->value_type = COMMAND_VALUE_TYPE_FLOAT;
cmd->private->command->command_types[0] = COMMAND_PTYPE_SETPOINT;
return cmd;
err_block:
controller_block_free(cmd);
return NULL;
}
BLOCK_CREATE(command_float) = {
.create = block_command_float_create,
.args = { "", "char*", "char*,char*", NULL },
};
trigger {
{ "immediate" }
}
blocks (10.0, 0.0) {
{ "command_float", "command_float" }
{ "command_float", "command_float_named", "aname" }
{ "command_float", "command_float_named_unit", "anothername", "aunit" }
{ "test_output_float", "value" }
{ "test_output_uint32", "id" }
{ "test_command", "command" }
}
links {
{ "command_float", "value", "value", "value", true }
{ "command_float", "id", "id", "value", true }
}
set SETPOINT 4
set SPEED 5
set SETPOINT_TIME 6
set COMMAND_ID_NONE (int)0xffffffff
params {
{ "command", "command", "command_float", $[SETPOINT_TIME], 123, 1.0, 0, 500000000 }
{ "command", "command", "command_float", $[SETPOINT], 234, 2.0 }
{ "command", "command", "command_float", $[SETPOINT], 567, -1.0 }
{ "command", "command", "command_float", $[SETPOINT], 666, 0.0 }
{ "command", "command", "command_float", $[SETPOINT], 777, -10.0 }
{ "command", "command", "aname", $[SETPOINT], 1888, 1.234 }
{ "command", "command", "anothername", $[SETPOINT], 2888, 2.468 }
{ "value", "value", 10,
(float) { 0.0, 1.0, 2.0, -1.0, 0.0, -10.0, -10.0, -10.0, -10.0, -10.0 },
(float) { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }
}
{ "id", "value", 10,
(int) { $[COMMAND_ID_NONE], 123, 234, 567, 666, 777, $[COMMAND_ID_NONE], $[COMMAND_ID_NONE], $[COMMAND_ID_NONE], $[COMMAND_ID_NONE] }
}
}
......@@ -7,6 +7,7 @@ BLOCKS := \
add \
bridge_pwm \
command_bool \
command_float \
counter \
debug \
decoder_uint32_bool \
......@@ -86,6 +87,7 @@ SRCS += $(BLOCK_SRCS)
CTRL_TESTS += \
$(DIR)/block_bridge_pwm.test.ctrl \
$(DIR)/block_command_bool.test.ctrl \
$(DIR)/block_command_float.test.ctrl \
$(DIR)/block_gain.test.ctrl \
$(DIR)/block_limit.test.ctrl \
$(DIR)/block_limit_var.test.ctrl \
......
......@@ -458,7 +458,8 @@ void controller_trace_server_start(int portnr, int max)
double period;
struct timespec interval;
log_send(LOG_T_DEBUG, "Starting trace server on port %d", portnr);
log_send(LOG_T_DEBUG, "Starting trace server on port %d, max %d clients",
portnr, max);
trace_hdl = controller_mem_calloc(CONTROLLER_MEM_PERIODIC_WRITE,
max, sizeof(struct trace_hdl));
......
......@@ -55,6 +55,9 @@ int main(int argc, char **argv)
char *ctrl_filename;
char *dot_filename;
sigset_t sigset;
int blocks;
int outputs;
int i;
sigemptyset (&sigset);
sigaddset(&sigset, SIGALRM);
......@@ -85,7 +88,12 @@ int main(int argc, char **argv)
goto err_init;
}
controller_trace_server_start(CTRL_TRACE_PORT, 100);
blocks = controller_block_nr();
outputs = 0;
for (i = 0; i < blocks; i++) {
outputs += controller_block_get(i)->inputs;
}
controller_trace_server_start(CTRL_TRACE_PORT, outputs);
/* Start command shell */
......
......@@ -89,6 +89,10 @@ static int param_set(struct controller_block *block, char *param, int argc,
struct controller_command *command =
controller_command_find_by_name(name);
if (!command) {
log_send(LOG_T_ERROR, "command '%s' not found", name);
return -2;
}
priv->commands = realloc(priv->commands,
sizeof(struct controller_command *) * (priv->entries_nr));
......@@ -107,7 +111,7 @@ static int param_set(struct controller_block *block, char *param, int argc,
log_send(LOG_T_ERROR, "%s not yet supported",
enum_command_value_type2str(command->value_type));
log_server_flush();
exit(3);
return -3;
}
if (type == COMMAND_PTYPE_SETPOINT_TIME) {
......
......@@ -3,6 +3,9 @@ trigger {
{ "immediate" }
}
#empty trigger
trigger{}
blocks (100.0, 0.0) {
{ "test_input_bool", "input_bool" }
{ "test_input_uint32", "input_uint32" }
......@@ -13,10 +16,16 @@ blocks (100.0, 0.0) {
{ "test_output_float", "output_float" }
}
#empty blocks
blocks(100.0, 0.0){}
alias {
{ "input_bool", "input_bool", "value" }
}
#empty alias
alias{}
links {
{ $<input_bool>, "output_bool", "value", true }
{ "input_uint32", "value", "output_uint32", "value", true }
......@@ -36,3 +45,6 @@ params {
{ "input_uint32", "value", 4, (int) { 0, 1, (int)0xdeadbeef, 123456789 } }
{ "output_uint32", "value", 4, (int) { 0, 1, (int)0xdeadbeef, 123456789 } }
}
#empty params
params{}
......@@ -22,5 +22,5 @@ links {
{ "in", "value", "n0", "input", true }
}
#empty links
links{}
......@@ -20,6 +20,29 @@ blocks (100.0, 0.0) {
}
}
{ "gain", "gain_only_input" }
module ("only_input") {
{
{ "in", "gain_only_input", "in" }
}
{}
}
{ "value_float", "value_only_output" }
module ("only_output") {
{}
{
{ "out", "value_only_output", "value" }
}
}
module ("empty") {
{}
{}
}
{ "test_module_gg.ctrl", "gg1" }
{ "test_module_gg.ctrl", "gg2" }
......@@ -44,6 +67,8 @@ links {
{ "gg1", "out", "out_gg1", "value", true }
{ "gg2", "out", "out_gg2", "value", true }
{ "ggn", "out", "out_ggn", "value", true }
{ "ggn", "out", "only_input", "in", true }
}
params {
......
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