Browse Source

Add new import command for including a ctrl file only once.

This allows both the azimuth and the elevation control file to include the
ethercat device
controller_bus
Jeroen Vreeken 8 years ago
parent
commit
2322081cd6
8 changed files with 74 additions and 21 deletions
  1. +44
    -0
      controller/controller/controller_load.c
  2. +2
    -4
      controller/controller/controller_load.h
  3. +1
    -0
      controller/controller/controller_load_parser.l
  4. +11
    -0
      controller/controller/controller_load_parser.y
  5. +5
    -5
      controller/dt_ctrl.ctrl
  6. +2
    -6
      controller/dt_ctrl_az.ctrl
  7. +7
    -0
      controller/dt_ctrl_ec.ctrl
  8. +2
    -6
      controller/dt_ctrl_el.ctrl

+ 44
- 0
controller/controller/controller_load.c View File

@ -21,6 +21,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
#include "controller_load_parser.tab.h"
#include "controller_load_parser.yy.h"
#include "controller_load.h"
@ -224,6 +225,49 @@ int controller_load_include(char *file_name)
return r;
}
static int controller_load_import_nr;
static char **controller_load_imports;
int controller_load_import(char *file_name)
{
int r, i;
char *realname = realpath(file_name, NULL);
char **imports;
log_send(LOG_T_DEBUG, "Import '%s'", file_name);
if (!realname) {
log_send(LOG_T_ERROR, "Could not find realpath");
return -1;
}
for (i = 0; i < controller_load_import_nr; i++) {
if (!strcmp(realname, controller_load_imports[i])) {
log_send(LOG_T_DEBUG,
"'%s' ('%s') has already been imported",
file_name, realname);
free(realname);
return 0;
}
}
imports = realloc(controller_load_imports,
(controller_load_import_nr + 1) * sizeof(char *));
if (!imports) {
log_send(LOG_T_ERROR, "Could not allocate memory for import administration");
free(realname);
return -1;
}
imports[controller_load_import_nr] = realname;
controller_load_imports = imports;
controller_load_import_nr++;
r = controller_load(file_name);
log_send(LOG_T_DEBUG, "End of import '%s': %d", file_name, r);
return r;
}
int controller_load_yy_input(char *buf, int *readbytes, int sizebytes, yyscan_t scanner)
{


+ 2
- 4
controller/controller/controller_load.h View File

@ -21,12 +21,9 @@
#define _INCLUDE_CONTROLLER_LOAD_H_
#include <stdarg.h>
#include <controller/controller_load_parser.tab.h>
#ifndef YY_TYPEDEF_YY_SCANNER_T
#define YY_TYPEDEF_YY_SCANNER_T
typedef void* yyscan_t;
#endif
int controller_load_shell_add(void);
@ -45,6 +42,7 @@ 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);
int controller_load_include(char *file_name);
int controller_load_import(char *file_name);
double controller_load_variable_double_get(char *varname);
void controller_load_variable_double_set(char *varname, double val);


+ 1
- 0
controller/controller/controller_load_parser.l View File

@ -79,6 +79,7 @@ boolcast "("[ \t]*"bool"[ \t]*")"
"traces" { return TRACESSYM; }
"params" { return PARAMSSYM; }
"include" { return INCLUDESYM; }
"import" { return IMPORTSYM; }
"set" { return SETSYM; }
"deg2rad" { return FUNC_DEG2RAD_SYM; }


+ 11
- 0
controller/controller/controller_load_parser.y View File

@ -65,6 +65,7 @@ void yyerror(yyscan_t *scanner, char const *s);
%token PARENTHESESOPENSYM
%token PARENTHESESCLOSESYM
%token INCLUDESYM
%token IMPORTSYM
%token FUNC_DEG2RAD_SYM
%token FUNC_RPM2RADS_SYM
@ -109,6 +110,7 @@ ctrl : frequency
| traces
| params
| include
| import
| set
;
@ -127,6 +129,15 @@ include: INCLUDESYM STRINGSYM
}
;
import: IMPORTSYM STRINGSYM
{
if (controller_load_import($2)) {
yyerror(scanner, "Failed to parse import");
YYERROR;
}
}
;
blocks : BLOCKSSYM BRACEOPENSYM blocklist BRACECLOSESYM
blocklist: block


+ 5
- 5
controller/dt_ctrl.ctrl View File

@ -19,13 +19,13 @@ frequency 250
# Uncomment either the real network, or the sim network.
# But never both!
#include "dt_ctrl_el.ctrl"
include "dt_ctrl_el_sim.ctrl"
#import "dt_ctrl_el.ctrl"
import "dt_ctrl_el_sim.ctrl"
#include "dt_ctrl_az.ctrl"
include "dt_ctrl_az_sim.ctrl"
#import "dt_ctrl_az.ctrl"
import "dt_ctrl_az_sim.ctrl"
include "dt_ctrl_ec_sim.ctrl"
import "dt_ctrl_ec_sim.ctrl"
blocks {
{ "setpoint_generator", "azimuth_spg", "Azimuth_Setpoint", "rad" }


+ 2
- 6
controller/dt_ctrl_az.ctrl View File

@ -1,10 +1,6 @@
blocks {
{ "ec", "ethercat",
"eth0", # interface
3, # number of slaves
0 # combined rx/tx cycle?
}
import "dt_ctrl_ec.ctrl"
blocks {
{ "stoeber", "dt_az",
"ethercat", # bus name
2, # ethercat position


+ 7
- 0
controller/dt_ctrl_ec.ctrl View File

@ -0,0 +1,7 @@
blocks {
{ "ec", "ethercat",
"eth0", # interface
3, # number of slaves
0 # combined rx/tx PDO cycle?
}
}

+ 2
- 6
controller/dt_ctrl_el.ctrl View File

@ -1,10 +1,6 @@
blocks {
{ "ec", "ethercat",
"eth0", # interface
3, # number of slaves
0 # combined rx/tx PDO cycle?
}
import "dt_ctrl_ec.ctrl"
blocks {
{ "stoeber", "dt_el_r",
"ethercat", # bus name
0, # ethercat position


Loading…
Cancel
Save