Commit f3c30db2 authored by Michel Roelofs's avatar Michel Roelofs
Browse files

Merge remote-tracking branch 'origin/jeroen' into michel

parents de0a73c8 cc1c3ef7
......@@ -20,7 +20,7 @@
#define _INCLUDE_DYNARG_H_
#include <stdarg.h>
#include <malloc.h>
#include <stdlib.h>
......
......@@ -29,17 +29,20 @@ static bool init_done = false;
static int load_config(void)
{
GKeyFile *keyfile;
gboolean loaded;
gchar *keyfilename = "dt_host.ini";
gboolean loaded = false;
gchar *keyfilename[] ={ "/etc/dt/dt_host.ini", "dt_host.ini" };
int ret = 0;
int i;
keyfile = g_key_file_new();
loaded = g_key_file_load_from_file(
keyfile,
keyfilename,
G_KEY_FILE_NONE,
NULL);
for (i = 0; i < sizeof(keyfilename)/sizeof(keyfilename[0]) && !loaded; i++) {
loaded = g_key_file_load_from_file(
keyfile,
keyfilename[i],
G_KEY_FILE_NONE,
NULL);
}
if (loaded) {
gsize groups_nr;
......
......@@ -25,6 +25,8 @@
#include <netinet/in.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "tcp_listen.h"
......
......@@ -58,8 +58,8 @@ int cmd_port = CONSOLE_DT_MODEL_CMD_PORT;
static int load_ini(void)
{
GKeyFile *keyfile;
gboolean loaded;
gchar *keyfilename = "dt_model.ini";
gboolean loaded = false;
gchar *keyfilename[] = { "/etc/dt/dt_model.ini", "dt_model.ini" };
int ret = 0;
int i;
char *active_name = "none";
......@@ -67,11 +67,13 @@ static int load_ini(void)
keyfile = g_key_file_new();
loaded = g_key_file_load_from_file(
keyfile,
keyfilename,
G_KEY_FILE_KEEP_COMMENTS,
NULL);
for (i = 0; i < sizeof(keyfilename)/sizeof(keyfilename[0]) && !loaded; i++) {
loaded = g_key_file_load_from_file(
keyfile,
keyfilename[i],
G_KEY_FILE_KEEP_COMMENTS,
NULL);
}
if (loaded) {
gsize groups_nr;
......
......@@ -7,11 +7,16 @@ CFLAGS= -Wall -O3 \
-I../common/trace \
-I../common/include \
-Idt_azimuth -Idt_elevation -Iec -Ishell -Ilog
LDFLAGS= -lpthread -lrt -lm -ldl -Wl,-E -L../common/lib -L./lib
LDFLAGS= -lpthread -lrt -lm -Wl,-E -L../common/lib -L./lib
CFLAGS_SIM=-DUSE_AZ_SIM -DUSE_EL_SIM
OS= $(shell uname -s)
ifneq ($(OS), FreeBSD)
LDFLAGS+= -ldl
endif
dt_ctrl_LDFLAGS=`controller/block_list.sh lib/*.a` \
dt_ctrl_LDFLAGS=`./controller/block_list.sh lib/*.a` \
-lcontroller -lethercat -llog -lshell -ldt_azimuth -ldt_elevation
all: dt_ctrl \
......
......@@ -8,6 +8,13 @@ VPATH= /lib64 /usr/lib64 /usr/local/lib64 /lib /usr/lib /usr/local/lib
LIBTOOL=libtool
OS= $(shell uname -s)
ifneq ($(OS), FreeBSD)
FLEX=flex
else
FLEX=/usr/local/bin/flex
endif
%.o : %.c
@echo "LT CC $<"
@${LIBTOOL} --quiet --mode=compile --tag=CC $(CC) -MMD $(CFLAGS) -c $<
......@@ -22,7 +29,11 @@ LIBTOOL=libtool
%.lo: %.c
@echo "LT CC $<"
@${LIBTOOL} --quiet --mode=compile --tag=CC $(CC) -MMD $(CFLAGS) -c $<
@sed -i -e "s:\.libs/::" -e "s:\.o:\.lo:" .libs/$*.d
# compatibility hack: Linux's sed doesn't have a separate argument to '-i',
# while on FreeBSD, '-i' takes a non-optional extension argument. With
# '-i -i' we'll specify '-i' twice on Linux and let FreeBSD use '[filename]-i'
# as intermediate file for in-place editing.
@sed -e "s:\.libs/::" -e "s:\.o:\.lo:" -i -i .libs/$*.d
%.la:
@echo "LIBTOOL $@"
......@@ -38,7 +49,8 @@ LIBTOOL=libtool
%.yy.c %.yy.h: %.l %.tab.h
@echo " FLEX $<"
@flex --header-file=$*.yy.h -o $*.yy.c $<
@echo $(FLEX) --header-file=$*.yy.h -o $*.yy.c $<
@$(FLEX) --header-file=$*.yy.h -o $*.yy.c $<
# il2c: instruction list 2 c 'compiler'
%.c %.h: %.il
......
......@@ -14,7 +14,6 @@ BLOCKSRCS= \
block_friction.c \
block_gain.c \
block_gain_var.c \
block_joystick.c \
block_limit.c \
block_limit_dyn.c \
block_limit_2nd.c \
......@@ -43,6 +42,13 @@ BLOCKSRCS= \
block_value_bool.c \
block_value_uint32.c
OS= $(shell uname -s)
ifneq ($(OS), FreeBSD)
BLOCKSRCS+= \
block_joystick.c
endif
CONTROLLERSRCS= \
controller_block.c \
controller_block_param.c \
......@@ -52,6 +58,7 @@ CONTROLLERSRCS= \
controller_sample.c \
controller_dumpdot.c \
controller_load.c \
controller_load_variable.c \
controller_load_parser.tab.c \
controller_load_parser.yy.c
......
#!/bin/bash
#!/bin/sh
for lib in $@; do
SYMBOLS=`nm $lib |grep "block_.*_create" |cut -d' ' -f3`
......
......@@ -56,7 +56,7 @@ int controller_block_create(char *type, char *name, va_list ap)
handle = dlopen(NULL, RTLD_NOW);
if (!handle) {
log_send(LOG_T_ERROR,
"Error getting handle from dlopen(): %s", dlerror());
"Could not get handle from dlopen(): %s", dlerror());
return -1;
}
......@@ -67,12 +67,12 @@ int controller_block_create(char *type, char *name, va_list ap)
if (create_func) {
if(!create_func(name, ap)) {
log_send(LOG_T_ERROR, "Error: %s() failed", symbol);
log_send(LOG_T_ERROR, "%s() failed", symbol);
ret = -1;
}
} else {
log_send(LOG_T_ERROR,
"Error finding function %s for block %s", symbol, type);
"Could not find function %s for block %s", symbol, type);
ret = -1;
}
......
......@@ -25,7 +25,7 @@
*/
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include "controller_block.h"
#include "controller_sample.h"
......
......@@ -22,7 +22,7 @@
This module takes care of tracing block outputs.
*/
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include "controller_block.h"
......
......@@ -18,7 +18,7 @@
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <controller/controller_block.h>
#include <controller/controller_trace.h>
......
......@@ -19,7 +19,7 @@
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdbool.h>
#include "controller_load_parser.tab.h"
#include "controller_load_parser.yy.h"
......@@ -215,13 +215,15 @@ int controller_load_block_param_set(char *block, char *param, yyscan_t scanner)
return controller_block_param_set(block, param, extra->va_list);
}
void controller_load_include(char *file_name)
int controller_load_include(char *file_name)
{
int r;
log_send(LOG_T_DEBUG, "Include '%s'", file_name);
r = controller_load(file_name);
log_send(LOG_T_DEBUG, "End of include '%s': %d", file_name, r);
return r;
}
......
......@@ -23,7 +23,10 @@
#include <stdarg.h>
typedef void * yyscan_t;
#ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t;
#endif
int controller_load_shell_add(void);
......@@ -41,7 +44,12 @@ void controller_load_var_clear(yyscan_t scanner);
void controller_load_var_add_float_array_start(yyscan_t scanner);
void controller_load_var_add_float_array_end(yyscan_t scanner);
void controller_load_frequency(double frequency);
void controller_load_include(char *file_name);
int controller_load_include(char *file_name);
double controller_load_variable_double_get(char *varname);
void controller_load_variable_double_set(char *varname, double val);
char * controller_load_variable_string_get(char *varname);
void controller_load_variable_string_set(char *varname, char *val);
int controller_load_block_create(char *type, char *name, yyscan_t scanner);
int controller_load_block_param_set(char *block, char *param, yyscan_t scanner);
......
......@@ -38,16 +38,21 @@
string "\""[^"]*"\""
variablename [a-zA-Z\_][0-9a-zA-Z\-\_]*
doublevariable "\$("{variablename}")"
stringvariable "\${"{variablename}"}"
comment "/*".*"*/"
number [0-9]+
hexdigit [0-9a-fA-F]
doublesimple [+-]?{number}"."{number}
doubleexp [+-]?{number}"."?{number}?"e"[+-]*{number}
doublesimple {number}"."{number}
doubleexp {number}"."?{number}?"e"[+-]*{number}
double {doublesimple}|{doubleexp}
int [+-]?{number}+
int {number}+
unsignedlong ("0x"|"0X"){hexdigit}{5,}
......@@ -63,6 +68,10 @@ boolcast "("[ \t]*"bool"[ \t]*")"
"(" { return PARENTHESESOPENSYM; }
")" { return PARENTHESESCLOSESYM; }
"," { return COMMASYM; }
"*" { return STARSYM; }
"/" { return SLASHSYM; }
"+" { return PLUSSYM; }
"-" { return MINSYM; }
"frequency" { return FREQUENCYSYM; }
"blocks" { return BLOCKSSYM; }
......@@ -70,21 +79,39 @@ boolcast "("[ \t]*"bool"[ \t]*")"
"traces" { return TRACESSYM; }
"params" { return PARAMSSYM; }
"include" { return INCLUDESYM; }
"set" { return SETSYM; }
"deg2rad" { return FUNC_DEG2RAD_SYM; }
"rpm2rads" { return FUNC_RPM2RADS_SYM; }
"pi" { return CONST_PI_SYM; }
{floatcast} { return FLOATCASTSYM; }
{doublecast} { return DOUBLECASTSYM; }
{intcast} { return INTCASTSYM; }
{boolcast} { return BOOLCASTSYM; }
"true" { yylval->integer = 1; return BOOLSYM; }
"false" { yylval->integer = 0; return BOOLSYM; }
{string} {
yylval->string = strdup(yytext + 1);
yylval->string[strlen(yylval->string)-1] = 0;
return STRINGSYM;
}
{doublevariable} {
yylval->string = strdup(yytext + 2);
yylval->string[strlen(yylval->string)-1] = 0;
return DOUBLEVARIABLESYM;
}
{stringvariable} {
yylval->string = strdup(yytext + 2);
yylval->string[strlen(yylval->string)-1] = 0;
return STRINGVARIABLESYM;
}
{double} {
sscanf(yytext, "%lg", &yylval->dbl);
return DOUBLESYM;
......@@ -100,8 +127,12 @@ boolcast "("[ \t]*"bool"[ \t]*")"
return INTSYM;
}
"true" { yylval->integer = 1; return BOOLSYM; }
"false" { yylval->integer = 0; return BOOLSYM; }
{variablename} {
yylval->string = strdup(yytext);
return VARIABLENAMESYM;
}
{comment} /* skip */
[ \t\r] /* skip */
......
......@@ -45,6 +45,9 @@ void yyerror(yyscan_t *scanner, char const *s);
%token BRACECLOSESYM
%token COMMASYM
%token <string> STRINGSYM
%token <string> VARIABLENAMESYM
%token <string> DOUBLEVARIABLESYM
%token <string> STRINGVARIABLESYM
%token <integer> BOOLSYM
%token <integer> INTSYM
%token <dbl> DOUBLESYM
......@@ -54,17 +57,26 @@ void yyerror(yyscan_t *scanner, char const *s);
%token LINKSSYM
%token TRACESSYM
%token PARAMSSYM
%token SETSYM
%token PARENTHESESOPENSYM
%token PARENTHESESCLOSESYM
%token FLOATCASTSYM
%token DOUBLECASTSYM
%token INTCASTSYM
%token BOOLCASTSYM
%token INCLUDESYM
%token FUNC_DEG2RAD_SYM
%token FUNC_RPM2RADS_SYM
%token <dbl> CONST_PI_SYM
%left DUMMY_DOUBLEVAR
%left DUMMY_INTVAR
%left FLOATCASTSYM DOUBLECASTSYM INTCASTSYM BOOLCASTSYM
%left MINSYM
%left PLUSSYM
%left SLASHSYM
%left STARSYM
%left UMINUS
%union
{
char *string;
......@@ -73,8 +85,8 @@ void yyerror(yyscan_t *scanner, char const *s);
unsigned long ul;
}
%type <string> stringvar
%type <dbl> doublevar
%type <dbl> doublevar_casteable
%type <integer> intvar
%type <ul> unsignedlongvar
......@@ -93,6 +105,7 @@ ctrl : frequency
| traces
| params
| include
| set
;
frequency: FREQUENCYSYM DOUBLESYM
......@@ -102,7 +115,12 @@ frequency: FREQUENCYSYM DOUBLESYM
;
include: INCLUDESYM STRINGSYM
{ controller_load_include($2); }
{
if (controller_load_include($2)) {
yyerror(scanner, "Failed to parse include");
YYERROR;
}
}
;
blocks : BLOCKSSYM BRACEOPENSYM blocklist BRACECLOSESYM
......@@ -116,8 +134,10 @@ block : BRACEOPENSYM
STRINGSYM varlist
BRACECLOSESYM
{
if(controller_load_block_create($2, $4, scanner))
if(controller_load_block_create($2, $4, scanner)) {
yyerror(scanner, "Error creating block");
YYERROR;
}
free($2);
free($4);
controller_load_var_clear(scanner);
......@@ -136,8 +156,10 @@ param : BRACEOPENSYM
varlist
BRACECLOSESYM
{
if (controller_load_block_param_set($2, $4, scanner))
if (controller_load_block_param_set($2, $4, scanner)) {
yyerror(scanner, "Error setting parameter");
YYERROR;
}
controller_load_var_clear(scanner);
}
;
......@@ -146,11 +168,11 @@ varlist : /* varlist may be emtpy */
| COMMASYM var varlist
;
var : STRINGSYM
var : stringvar
{ controller_load_var_add_str($1, scanner); }
| doublevar
| doublevar %prec DUMMY_DOUBLEVAR
{ controller_load_var_add_dbl($1, scanner); }
| intvar
| intvar %prec DUMMY_INTVAR
{ controller_load_var_add_int($1, scanner); }
| unsignedlongvar
{ controller_load_var_add_ul($1, scanner); }
......@@ -160,41 +182,59 @@ var : STRINGSYM
{ controller_load_var_add_float_array_end(scanner); }
;
stringvar: STRINGSYM
| STRINGVARIABLESYM
{ controller_load_variable_string_get($1); }
;
floatlist: floatlistvar
| floatlistvar COMMASYM floatlist
;
floatlistvar: doublevar
{ controller_load_var_add_flt($1, scanner); }
| intvar
{ controller_load_var_add_flt($1, scanner); }
| unsignedlongvar
{ controller_load_var_add_flt($1, scanner); }
;
doublevar: DOUBLESYM
doublevar: DOUBLEVARIABLESYM
{ $$ = controller_load_variable_double_get($1); }
| DOUBLESYM
{ $$ = $1; }
| DOUBLECASTSYM doublevar_casteable
| FLOATCASTSYM doublevar
{ $$ = $2; }
| DOUBLECASTSYM doublevar
{ $$ = $2; }
| FLOATCASTSYM doublevar_casteable
| FLOATCASTSYM intvar
{ $$ = $2; }
| DOUBLECASTSYM intvar
{ $$ = $2; }
| FLOATCASTSYM unsignedlongvar
{ $$ = $2; }
| DOUBLECASTSYM unsignedlongvar
{ $$ = $2; }
| doublevar MINSYM doublevar
{ $$ = ($1) - ($3); }
| doublevar PLUSSYM doublevar
{ $$ = ($1) + ($3); }
| doublevar SLASHSYM doublevar
{ $$ = ($1) / ($3); }
| doublevar STARSYM doublevar
{ $$ = ($1) * ($3); }
| deg2rad
{ $$ = $1; }
| rpm2rads
{ $$ = $1; }
| CONST_PI_SYM
{ $$ = M_PI; }
| MINSYM doublevar %prec UMINUS
{ $$ = - $2 }
;
doublevar_casteable: doublevar
{ $$ = $1 }
| intvar
{ $$ = $1; }
;
deg2rad: FUNC_DEG2RAD_SYM PARENTHESESOPENSYM doublevar_casteable PARENTHESESCLOSESYM
deg2rad: FUNC_DEG2RAD_SYM PARENTHESESOPENSYM doublevar PARENTHESESCLOSESYM
{ $$ = ($3) * M_PI / 180.0; }
;
rpm2rads: FUNC_RPM2RADS_SYM PARENTHESESOPENSYM doublevar_casteable PARENTHESESCLOSESYM
rpm2rads: FUNC_RPM2RADS_SYM PARENTHESESOPENSYM doublevar PARENTHESESCLOSESYM
{ $$ = ($3) * 2.0 * M_PI / 60.0; }
;
......@@ -202,16 +242,26 @@ intvar: INTSYM
{ $$ = $1; }
| INTCASTSYM intvar
{ $$ = $2; }
| INTCASTSYM doublevar
{ $$ = $2; }
| BOOLSYM
{ $$ = $1; }
| BOOLCASTSYM intvar
{ $$ = $2; }
| MINSYM intvar %prec UMINUS
{ $$ = - $2 }
;
unsignedlongvar: UNSIGNEDLONGSYM
{ $$ = $1; }
;
set: SETSYM VARIABLENAMESYM doublevar
{ controller_load_variable_double_set($2, $3) }
| SETSYM VARIABLENAMESYM stringvar
{ controller_load_variable_string_set($2, $3) }
;
links : LINKSSYM BRACEOPENSYM linklist BRACECLOSESYM
linklist: link
......@@ -226,8 +276,10 @@ link : BRACEOPENSYM
BOOLSYM
BRACECLOSESYM
{
if (controller_block_connect($2, $4, $6, $8, $10))
if (controller_block_connect($2, $4, $6, $8, $10)) {
yyerror(scanner, "Error connecting blocks");
YYERROR;
}
free($2);
free($4);
free($6);
......
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2009
Copyright Stichting C.A. Muller Radioastronomiestation, 2009
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 <stdlib.h>
#include <string.h>
#include "controller_load.h"
enum variable_type {
VARIABLE_STRING,
VARIABLE_DOUBLE,
};
struct variable {
enum variable_type type;
char *name;
double doubleval;
char *stringval;
struct variable *next;
};
static struct variable *variables = NULL;
double controller_load_variable_double_get(char *varname)