Commit 55cf9cbc authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Make setpoint generator block dependant on controller and not the other

way around.
parent 089a60e7
......@@ -669,12 +669,12 @@ static void calculate(struct controller_block *spg)
priv->cmd_x_out = priv->cmd_x;
}
bool block_setpoint_generator_queue_space(struct controller_block *spg)
static bool block_setpoint_generator_queue_space(struct controller_block *spg)
{
return spg->private->next_command.done;
}
void block_setpoint_generator_command(struct controller_block *spg,
static void block_setpoint_generator_command(struct controller_block *spg,
int type, float setpoint, float speed, uint32_t time)
{
struct controller_block_private *priv = spg->private;
......@@ -844,6 +844,8 @@ struct controller_block * block_setpoint_generator_create(char *name, va_list ap
spg_name.name = server_name;
spg_name.unit = spg_unit;
spg_name.blockname = name;
spg_name.command = block_setpoint_generator_command;
spg_name.queue_space = block_setpoint_generator_queue_space;
spg = malloc(sizeof(struct controller_block));
if (!spg)
......
......@@ -23,16 +23,4 @@
struct controller_block * block_setpoint_generator_create(char *name, va_list ap);
enum {
BLOCK_SPG_SETPOINT,
BLOCK_SPG_SPEED,
BLOCK_SPG_SETPOINT_TIME,
BLOCK_SPG_SPEED_DIRECT,
};
void block_setpoint_generator_command(struct controller_block *spg,
int type, float setpoint, float speed, uint32_t time);
bool block_setpoint_generator_queue_space(struct controller_block *spg);
#endif /* _INCLUDE_BLOCK_SETPOINT_GENERATOR_ */
......@@ -34,7 +34,6 @@
#include <limits.h>
#include "controller_block.h"
#include "../block/block_setpoint_generator.h"
#include "controller_setpoint_command.h"
#include "controller_sample.h"
#include "dt_port_numbers.h"
......@@ -62,7 +61,7 @@ struct command_hdl {
int sock;
int state;
struct controller_block *spg;
struct controller_spg_name *spg;
char buffer[COMMAND_MAXLEN];
int buflen;
char spg_name[100];
......@@ -92,7 +91,7 @@ static void *controller_setpoint_command_handle(void *arg)
for (i = 0; i < nr_command_hdl; i++) {
if (!command_hdl[i].free &&
(!command_hdl[i].spg ||
block_setpoint_generator_queue_space(command_hdl[i].spg)) ) {
command_hdl[i].spg->queue_space(command_hdl[i].spg->block)) ) {
FD_SET(command_hdl[i].sock, &fdset_r);
if (command_hdl[i].sock > high + 1)
high = command_hdl[i].sock + 1;
......@@ -180,13 +179,7 @@ static void *controller_setpoint_command_handle(void *arg)
command_hdl[i].free = 1;
break;
}
command_hdl[i].spg =
controller_block_find(spg_list[j].blockname);
if (!command_hdl[i].spg) {
close(command_hdl[i].sock);
command_hdl[i].free = 1;
break;
}
command_hdl[i].spg = &spg_list[j];
command_hdl[i].state =
CMD_ST_GETID;
}
......@@ -226,7 +219,7 @@ static void *controller_setpoint_command_handle(void *arg)
int remove = 0;
char *buffer = command_hdl[i].buffer;
if (!block_setpoint_generator_queue_space(command_hdl[i].spg))
if (!command_hdl[i].spg->queue_space(command_hdl[i].spg->block))
break;
ret = read(command_hdl[i].sock,
......@@ -241,8 +234,8 @@ static void *controller_setpoint_command_handle(void *arg)
setpoint.u =
ntohl(*(uint32_t*)(buffer + 4));
block_setpoint_generator_command(
command_hdl[i].spg,
command_hdl[i].spg->command(
command_hdl[i].spg->block,
BLOCK_SPG_SETPOINT,
setpoint.f, 0.0, 0.0);
......@@ -255,8 +248,8 @@ static void *controller_setpoint_command_handle(void *arg)
speed.u =
ntohl(*(uint32_t*)(buffer + 4));
block_setpoint_generator_command(
command_hdl[i].spg,
command_hdl[i].spg->command(
command_hdl[i].spg->block,
BLOCK_SPG_SPEED,
0.0, speed.f, 0.0);
......@@ -272,8 +265,8 @@ static void *controller_setpoint_command_handle(void *arg)
deadline =
ntohl(*(uint32_t*)(buffer + 8));
block_setpoint_generator_command(
command_hdl[i].spg,
command_hdl[i].spg->command(
command_hdl[i].spg->block,
BLOCK_SPG_SETPOINT_TIME,
setpoint.f, 0.0, deadline);
......
......@@ -19,11 +19,25 @@
#ifndef _INCLUDE_CONTROLLER_SETPOINT_COMMAND_H_
#define _INCLUDE_CONTROLLER_SETPOINT_COMMAND_H_
enum {
BLOCK_SPG_SETPOINT,
BLOCK_SPG_SPEED,
BLOCK_SPG_SETPOINT_TIME,
BLOCK_SPG_SPEED_DIRECT,
};
struct controller_spg_name {
char *name;
char *unit;
char *blockname;
struct controller_block *block;
void (*command)(
struct controller_block *spg,
int type, float setpoint, float speed, uint32_t time);
bool (*queue_space)(struct controller_block *spg);
};
void controller_setpoint_command_server_add(struct controller_spg_name *name);
......
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