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

Modify trace_list to give some extra info if nothing was found.

Trace server capacity is now based on actuall number of outputs,
not on some magic number.
Add name and unit option to command_bool and command_float.
Modify tests to test this.
parent 0a25cc90
/*
/*
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 }
......
......@@ -57,6 +57,13 @@ static struct controller_block_outterm_list outterms[] = {
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;
......@@ -72,7 +79,7 @@ static struct controller_block * block_command_float_create(char *name, int argc
if (controller_block_add(cmd))
goto err_block;
cmd->private->command = controller_command_create(cmd, name, "Float");
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;
......@@ -85,5 +92,5 @@ err_block:
BLOCK_CREATE(command_float) = {
.create = block_command_float_create,
.args = { NULL },
.args = { "", "char*", "char*,char*", NULL },
};
......@@ -5,6 +5,8 @@ trigger {
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" }
......@@ -29,6 +31,8 @@ params {
{ "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 },
......
......@@ -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) {
......
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