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

make setpoint generator registration application independant

parent e6b6625a
/* /*
setpoint.c setpoint.c
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2008 Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2008, 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2008 Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2008, 2013
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -82,6 +82,7 @@ static int setpoint_command_init_spg( ...@@ -82,6 +82,7 @@ static int setpoint_command_init_spg(
} while (ret == 1); } while (ret == 1);
if (cmd->fd >= 0) { if (cmd->fd >= 0) {
if (!found) { if (!found) {
printf("Spg %s not found\n", spg_name);
close(cmd->fd); close(cmd->fd);
cmd->fd = -1; cmd->fd = -1;
} else { } else {
...@@ -134,7 +135,6 @@ struct setpoint_command *setpoint_command_init(char *host, int port, ...@@ -134,7 +135,6 @@ struct setpoint_command *setpoint_command_init(char *host, int port,
if (cmd->fd >= 0) { if (cmd->fd >= 0) {
r = setpoint_command_init_spg(cmd); r = setpoint_command_init_spg(cmd);
if (r) { if (r) {
setpoint_command_clean(cmd);
close(cmd->fd); close(cmd->fd);
cmd->fd = -1; cmd->fd = -1;
} }
......
...@@ -5,6 +5,7 @@ CFLAGS= -Wall -O3 \ ...@@ -5,6 +5,7 @@ CFLAGS= -Wall -O3 \
-Icontroller \ -Icontroller \
-I../common/utils \ -I../common/utils \
-I../common/trace \ -I../common/trace \
-I../common/include \
-Idt_azimuth -Idt_elevation -Iec -Ishell -Ilog -Idt_azimuth -Idt_elevation -Iec -Ishell -Ilog
LDFLAGS= -lpthread -lrt -lm -ldl -Wl,-E -L../common/lib -L./lib LDFLAGS= -lpthread -lrt -lm -ldl -Wl,-E -L../common/lib -L./lib
CFLAGS_SIM=-DUSE_AZ_SIM -DUSE_EL_SIM CFLAGS_SIM=-DUSE_AZ_SIM -DUSE_EL_SIM
......
IL2C=il2c/il2c IL2C=il2c/il2c
CFLAGS= -O3 -Wall -I../log/ -I.. CFLAGS= -O3 -Wall -I../log/ -I.. -I../../common/include
BLOCKSRCS= \ BLOCKSRCS= \
block_add.c \ block_add.c \
block_and2.c \ block_and2.c \
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "controller_block.h" #include "controller_block.h"
#include "block_setpoint_generator.h" #include "block_setpoint_generator.h"
#include "controller_setpoint_command.h"
#include "log.h" #include "log.h"
/* /*
...@@ -808,9 +809,19 @@ static void param_set(struct controller_block *spg, int param, va_list val) ...@@ -808,9 +809,19 @@ static void param_set(struct controller_block *spg, int param, va_list val)
spg->private->imindd = 1.0 / spg->private->mindd; spg->private->imindd = 1.0 / spg->private->mindd;
} }
struct controller_block * block_setpoint_generator_create(char *name) struct controller_block * block_setpoint_generator_create(char *name, va_list ap)
{ {
struct controller_block *spg; struct controller_block *spg;
char *server_name;
char *spg_unit;
struct controller_spg_name spg_name;
server_name = va_arg(ap, char *);
spg_unit = va_arg(ap, char *);
spg_name.name = server_name;
spg_name.unit = spg_unit;
spg_name.blockname = name;
spg = malloc(sizeof(struct controller_block)); spg = malloc(sizeof(struct controller_block));
if (!spg) if (!spg)
...@@ -911,6 +922,9 @@ struct controller_block * block_setpoint_generator_create(char *name) ...@@ -911,6 +922,9 @@ struct controller_block * block_setpoint_generator_create(char *name)
pthread_mutex_init(&spg->private->mutex, NULL); pthread_mutex_init(&spg->private->mutex, NULL);
controller_block_add(spg); controller_block_add(spg);
controller_setpoint_command_server_add(&spg_name);
return spg; return spg;
err_output: err_output:
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "controller_block.h" #include "controller_block.h"
struct controller_block * block_setpoint_generator_create(char *name); struct controller_block * block_setpoint_generator_create(char *name, va_list ap);
enum { enum {
BLOCK_SPG_SETPOINT, BLOCK_SPG_SETPOINT,
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include "controller_block.h" #include "controller_block.h"
#include "block_setpoint_generator.h" #include "block_setpoint_generator.h"
#include "controller_setpoint_command.h" #include "controller_setpoint_command.h"
#include "controller_sample.h"
#include "dt_port_numbers.h"
static int nr_spgs = 0; static int nr_spgs = 0;
static struct controller_spg_name *spg_list = NULL; static struct controller_spg_name *spg_list = NULL;
...@@ -369,6 +371,13 @@ static void *controller_setpoint_command_server(void *arg) ...@@ -369,6 +371,13 @@ static void *controller_setpoint_command_server(void *arg)
return NULL; return NULL;
} }
static bool sample_hook_installed = false;
static void controller_setpoint_sample_hook(void *arg)
{
controller_setpoint_command_server_start(CTRL_COMMAND_PORT, nr_spgs * 2);
}
void controller_setpoint_command_server_add(struct controller_spg_name *name) void controller_setpoint_command_server_add(struct controller_spg_name *name)
{ {
struct controller_spg_name *tmp; struct controller_spg_name *tmp;
...@@ -377,14 +386,22 @@ void controller_setpoint_command_server_add(struct controller_spg_name *name) ...@@ -377,14 +386,22 @@ void controller_setpoint_command_server_add(struct controller_spg_name *name)
tmp = realloc(spg_list, sizeof(struct controller_spg_name) * nr_spgs); tmp = realloc(spg_list, sizeof(struct controller_spg_name) * nr_spgs);
if (tmp) { if (tmp) {
spg_list = tmp; spg_list = tmp;
memcpy(&spg_list[nr_spgs-1], name, spg_list[nr_spgs-1].name = strdup(name->name);
sizeof(struct controller_spg_name)); spg_list[nr_spgs-1].unit = strdup(name->unit);
spg_list[nr_spgs-1].blockname = strdup(name->blockname);
printf("Added spg %s [%s] to command server using %s\n", printf("Added spg %s [%s] to command server using %s\n",
name->name, name->unit, name->blockname); name->name, name->unit, name->blockname);
} else } else
nr_spgs--; nr_spgs--;
if (!sample_hook_installed) {
controller_sample_start_hook(
controller_setpoint_sample_hook, NULL);
sample_hook_installed = true;
}
} }
void controller_setpoint_command_server_start(int portnr, int max) void controller_setpoint_command_server_start(int portnr, int max)
{ {
struct spg_command_server *srv; struct spg_command_server *srv;
......
...@@ -23,11 +23,10 @@ ...@@ -23,11 +23,10 @@
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#include "../common/include/dynarg.h" #include "dynarg.h"
#include "controller_block.h" #include "controller_block.h"
#include "controller_trace.h" #include "controller_trace.h"
#include "controller_setpoint_command.h"
#include "controller_sample.h" #include "controller_sample.h"
#include "controller_dumpdot.h" #include "controller_dumpdot.h"
#include "controller_load.h" #include "controller_load.h"
...@@ -35,21 +34,7 @@ ...@@ -35,21 +34,7 @@
#include "ec.h" #include "ec.h"
#include "log.h" #include "log.h"
#include "../common/include/dt_port_numbers.h" #include "dt_port_numbers.h"
#if !defined(USE_AZ_SIM) || !defined(USE_EL_SIM)
#define USE_ETHERCAT
#endif
static struct controller_spg_name dt_spg_list[] = {
{ "Azimuth_Setpoint", "rad", "azimuth_spg" },
{ "Elevation_Setpoint", "rad", "elevation_spg" },
{ "Elevation_Torsion_Setpoint", "rad", "elevation_torsion_spg" },
{ NULL, NULL, NULL },
};
/******************************************** /********************************************
...@@ -102,8 +87,6 @@ int param_reload(char *argc, char *out, int *outlen) ...@@ -102,8 +87,6 @@ int param_reload(char *argc, char *out, int *outlen)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int i;
controller_block_param_init(); controller_block_param_init();
#ifdef USE_EL_SIM #ifdef USE_EL_SIM
...@@ -159,13 +142,6 @@ int main(int argc, char **argv) ...@@ -159,13 +142,6 @@ int main(int argc, char **argv)
controller_trace_server_start(CTRL_TRACE_PORT, 100); controller_trace_server_start(CTRL_TRACE_PORT, 100);
/* Add spg command handlers */
for (i = 0; dt_spg_list[i].name; i++)
controller_setpoint_command_server_add(&dt_spg_list[i]);
controller_setpoint_command_server_start(CTRL_COMMAND_PORT, i * 2);
/* Start command shell */ /* Start command shell */
shell_cmd_add(&(struct shell_cmd){"timing", "reset/print sample timing", sample_timing }); shell_cmd_add(&(struct shell_cmd){"timing", "reset/print sample timing", sample_timing });
......
frequency 250 frequency 250
blocks { blocks {
{ "setpoint_generator", "azimuth_spg" } { "setpoint_generator", "azimuth_spg", "Azimuth_Setpoint", "rad" }
{ "servo_state", "azimuth_servo_state" } { "servo_state", "azimuth_servo_state" }
{ "subtract", "azimuth_setpoint_error" } { "subtract", "azimuth_setpoint_error" }
{ "subtract", "azimuth_error" } { "subtract", "azimuth_error" }
...@@ -18,9 +18,9 @@ blocks { ...@@ -18,9 +18,9 @@ blocks {
{ "gain", "azimuth_position_gain" } { "gain", "azimuth_position_gain" }
{ "matrix_2x2", "elevation_input_matrix" } { "matrix_2x2", "elevation_input_matrix" }
{ "setpoint_generator", "elevation_spg" } { "setpoint_generator", "elevation_spg", "Elevation_Setpoint", "rad" }
{ "servo_state", "elevation_servo_state" } { "servo_state", "elevation_servo_state" }
{ "setpoint_generator", "elevation_torsion_spg" } { "setpoint_generator", "elevation_torsion_spg", "Elevation_Torsion_Setpoint", "rad" }
{ "subtract", "elevation_setpoint_error" } { "subtract", "elevation_setpoint_error" }
{ "subtract", "elevation_error" } { "subtract", "elevation_error" }
{ "subtract", "elevation_torsion_error" } { "subtract", "elevation_torsion_error" }
......
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