Commit 80caeb9d authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Merge branch 'jeroen' into controller_bus

parents 3c310966 c2663a6f
../../controller/controller/controller_setpoint_command.h
\ No newline at end of file
include ../build.mk
CFLAGS= -Wall -g -I../../common/utils \
CFLAGS= -Wall -O3 -I../../common/utils \
-I../controller \
-Iaalib -Ipredictlib \
-I../../common/trace \
......
......@@ -143,13 +143,19 @@ struct setpoint_command *setpoint_command_init(char *host, int port,
int setpoint_command_setpoint(struct setpoint_command *sp_cmd, float sp)
{
int ret;
unsigned char command[4];
unsigned char arg[4];
union {
unsigned char c[4];
uint32_t u32;
} command;
union {
unsigned char c[4];
uint32_t u32;
} arg;
f32_t f;
*(uint32_t*)command = htonl(BLOCK_SPG_SETPOINT);
command.u32 = htonl(BLOCK_SPG_SETPOINT);
f.f = sp;
*(uint32_t*)arg = htonl(f.u);
arg.u32 = htonl(f.u);
if (sp_cmd->fd < 0) {
sleep(1);
......@@ -160,13 +166,13 @@ int setpoint_command_setpoint(struct setpoint_command *sp_cmd, float sp)
return 1;
}
ret = write(sp_cmd->fd, command, 4);
ret = write(sp_cmd->fd, command.c, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 4);
ret = write(sp_cmd->fd, arg.c, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
......@@ -180,13 +186,19 @@ int setpoint_command_setpoint(struct setpoint_command *sp_cmd, float sp)
int setpoint_command_speed(struct setpoint_command *sp_cmd, float speed)
{
int ret;
unsigned char command[4];
unsigned char arg[4];
union {
unsigned char c[4];
uint32_t u32;
} command;
union {
unsigned char c[4];
uint32_t u32;
} arg;
f32_t f;
*(uint32_t*)command = htonl(BLOCK_SPG_SPEED);
command.u32 = htonl(BLOCK_SPG_SPEED);
f.f = speed;
*(uint32_t*)arg = htonl(f.u);
arg.u32 = htonl(f.u);
if (sp_cmd->fd < 0) {
sleep(1);
......@@ -197,13 +209,13 @@ int setpoint_command_speed(struct setpoint_command *sp_cmd, float speed)
return 1;
}
ret = write(sp_cmd->fd, command, 4);
ret = write(sp_cmd->fd, command.c, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 4);
ret = write(sp_cmd->fd, arg.c, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
......@@ -218,14 +230,20 @@ int setpoint_command_setpoint_time(struct setpoint_command *sp_cmd,
float sp, time_t sptime)
{
int ret;
unsigned char command[4];
unsigned char arg[8];
union {
unsigned char c[4];
uint32_t u32;
} command;
union {
unsigned char c[4];
uint32_t u32;
} arg[2];
f32_t f;
*(uint32_t*)command = htonl(BLOCK_SPG_SETPOINT_TIME);
command.u32 = htonl(BLOCK_SPG_SETPOINT_TIME);
f.f = sp;
*(uint32_t*)arg = htonl(f.u);
*(uint32_t*)&arg[4] = htonl(sptime);
arg[0].u32 = htonl(f.u);
arg[1].u32 = htonl(sptime);
if (sp_cmd->fd < 0) {
sleep(1);
......@@ -236,13 +254,13 @@ int setpoint_command_setpoint_time(struct setpoint_command *sp_cmd,
return 1;
}
ret = write(sp_cmd->fd, command, 4);
ret = write(sp_cmd->fd, command.c, 4);
if (ret != 4) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
sp_cmd->fd = -1;
} else {
ret = write(sp_cmd->fd, arg, 8);
ret = write(sp_cmd->fd, arg[0].c, 8);
if (ret != 8) {
printf("Connection to controller command socket lost.\n");
close(sp_cmd->fd);
......
......@@ -35,7 +35,7 @@ lib/libdt_elevation.la: lib/libcontroller.la
dt_ctrl: dt_ctrl.o
test: lib/libcontroller.la lib/libethercat.la
test: lib/libcontroller.la lib/libethercat.la lib/libblock.la
@echo " SUBDIR: $@"
@$(MAKE) -C test
......
......@@ -68,9 +68,10 @@ il2cdir:
.PHONY: il2cdir
$(BLOCKSRCS): il2cdir
libblock.la_LDFLAGS=-rpath ${CURDIR}/../lib
libblock.la: $(BLOCKS) il2cdir
libblock.la: $(BLOCKS)
libblock.la_install: libblock.la
@echo "CP $^ to libdir"
......
......@@ -50,8 +50,6 @@ struct controller_load_extra {
};
int yyparse(yyscan_t scanner, FILE *);
void yyerror(yyscan_t scanner, char const *s)
{
struct controller_load_extra *extra = yyget_extra(scanner);
......@@ -277,7 +275,7 @@ static int controller_load_shell(char *args, char *out, int *outlen)
safe_context = controller_block_context_get();
controller_block_context_set("shell");
ret = yyparse(scanner, NULL);
ret = yyparse(scanner);
controller_block_context_set(safe_context);
......@@ -367,7 +365,7 @@ int controller_load(char *filename)
safe_context = controller_block_context_get();
controller_block_context_set(filename);
extra.ret = yyparse(scanner, extra.input_file);
extra.ret = yyparse(scanner);
controller_block_context_set(safe_context);
......
......@@ -17,6 +17,10 @@
*/
%code requires {
typedef void* yyscan_t;
}
%{
#include <stdio.h>
......
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