Commit 6ea41c1a authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add 'context' to each block.

The controller_load functions will set it to the .ctrl filename.
Modifiy dumpdot to use it to make subgraphs. This way we get a nice
grouping of blocks per file.
parent 22de9fb3
......@@ -42,6 +42,8 @@ static int nr_traces = 0;
static struct controller_trace **traces;
static int max_traces = 0;
static char *controller_block_context = "unknown";
#define BLOCK_PREFIX "block_"
#define BLOCK_POSTFIX "_create"
......@@ -107,8 +109,10 @@ void controller_block_add(struct controller_block *newblock)
{
void *tmp;
printf("Adding a new block: %s (%s)\n",
newblock->name, newblock->type);
newblock->context = strdup(controller_block_context);
printf("Adding a new block: %s (%s) in context %s\n",
newblock->name, newblock->type, newblock->context);
tmp = realloc(blocks, sizeof(struct controller_block *) * (nr_blocks+1));
if (tmp) {
......@@ -180,6 +184,21 @@ struct controller_block_outterm *controller_block_find_outterm(
return NULL;
}
char *controller_block_context_get(void)
{
return controller_block_context;
}
void controller_block_context_set(char *new_context)
{
controller_block_context = new_context;
}
/*
Sample processing
*/
static int sample_running = 0;
void controller_block_sample_init(void)
......
......@@ -128,8 +128,9 @@ struct controller_block_param_list {
Additional data a block might need can be pointed to by the private pointer.
*/
struct controller_block {
char *name;
char *type;
char *name; /* instance name this block */
char *type; /* generic type of the block */
char *context; /* Which context 'owns' this block */
/* List of inputs */
int inputs;
......@@ -217,6 +218,8 @@ void controller_block_calculate(void);
void controller_block_trace(void);
void controller_block_param_handle(void);
char *controller_block_context_get(void);
void controller_block_context_set(char *new_context);
#define RPM2RADS(val) ((val)*2.0*M_PI/60.0)
#define RADS2RPM(val) ((val)*60.0/(2.0*M_PI))
......
......@@ -17,6 +17,8 @@
*/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <controller/controller_block.h>
#include <controller/controller_trace.h>
......@@ -24,7 +26,9 @@
void controller_dumpdot(char *filename)
{
FILE *fddot;
int i;
int i, j, contextnr;
char **contextlist = NULL;
int contextlist_size = 0;
fddot = fopen(filename, "w");
if (!fddot)
......@@ -37,65 +41,107 @@ void controller_dumpdot(char *filename)
fprintf(fddot, "\tranksep=1.5;\n");
fprintf(fddot, "\n");
/* Find all contexts */
for (i = 0; i < controller_block_nr(); i++) {
struct controller_block *block;
int rows = 1, j;
block = controller_block_get(i);
if (block->inputs > rows)
rows = block->inputs;
if (block->outputs > rows)
rows = block->outputs;
struct controller_block *block = controller_block_get(i);
bool newcontext = true;
fprintf(fddot, "\t%s [label=<\n", block->name);
fprintf(fddot, "\t\t<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">\n");
for (j = 0; j < contextlist_size; j++) {
if (!strcmp(contextlist[j], block->context)) {
newcontext = false;
break;
}
}
for (j = 0; j < rows; j++) {
fprintf(fddot, "\t\t<TR>\n");
if (newcontext) {
contextlist_size++;
if (block->inputs > j) {
fprintf(fddot, "\t\t\t<TD PORT=\"in_%s\" BGCOLOR=\"lightblue\">%s</TD>\n",
block->input[j].name, block->input[j].name);
} else if (block->outputs > j) {
fprintf(fddot, "\t\t\t<TD BORDER=\"0\"></TD>\n");
}
contextlist = realloc(contextlist, sizeof(char *) * contextlist_size);
contextlist[contextlist_size-1] = block->context;
}
}
for (contextnr = 0; contextnr < contextlist_size; contextnr++) {
fprintf(fddot, "\tsubgraph cluster_%d {\n", contextnr);
fprintf(fddot, "\t\tlabel=\"%s\";\n", contextlist[contextnr]);
fprintf(fddot, "\n");
for (i = 0; i < controller_block_nr(); i++) {
struct controller_block *block;
int rows = 1;
block = controller_block_get(i);
if (strcmp(block->context, contextlist[contextnr]))
continue;
if (block->inputs > rows)
rows = block->inputs;
if (block->outputs > rows)
rows = block->outputs;
fprintf(fddot, "\t\t%s [label=<\n", block->name);
fprintf(fddot,
"\t\t\t<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">\n");
if (j == 0) {
fprintf(fddot, "\t\t\t<TD ROWSPAN=\"%d\" BGCOLOR=\"yellow\">%s<BR/>%s</TD>\n",
rows, block->name, block->type);
for (j = 0; j < rows; j++) {
fprintf(fddot, "\t\t\t<TR>\n");
if (block->inputs > j) {
fprintf(fddot,
"\t\t\t\t<TD PORT=\"in_%s\" BGCOLOR=\"lightblue\">%s</TD>\n",
block->input[j].name, block->input[j].name);
} else if (block->outputs > j) {
fprintf(fddot, "\t\t\t\t<TD BORDER=\"0\"></TD>\n");
}
if (j == 0) {
fprintf(fddot,
"\t\t\t\t<TD ROWSPAN=\"%d\" BGCOLOR=\"yellow\">%s<BR/>%s</TD>\n",
rows, block->name, block->type);
}
if (block->outputs > j) {
fprintf(fddot,
"\t\t\t\t<TD PORT=\"out_%s\" BGCOLOR=\"lightblue\">%s</TD>\n",
block->output[j].name, block->output[j].name);
}
fprintf(fddot, "\t\t\t\t</TR>\n");
}
if (block->outputs > j) {
fprintf(fddot, "\t\t\t<TD PORT=\"out_%s\" BGCOLOR=\"lightblue\">%s</TD>\n",
block->output[j].name, block->output[j].name);
fprintf(fddot, "\t\t\t</TABLE>>];\n");
fprintf(fddot, "\n");
for (j = 0; j < block->inputs; j++) {
if (block->input[j].ghostof) {
fprintf(fddot,
"\t\t%s:in_%s:e -> %s:in_%s:w [color=\"grey\"]\n",
block->name, block->input[j].name,
block->input[j].ghostof->block->name,
block->input[j].ghostof->name);
}
}
fprintf(fddot, "\t\t</TR>\n");
}
fprintf(fddot, "\t</TABLE>>];\n");
for (j = 0; j < block->inputs; j++) {
if (block->input[j].ghostof) {
fprintf(fddot, "\t%s:in_%s:e -> %s:in_%s:w [color=\"grey\"]\n",
block->name, block->input[j].name,
block->input[j].ghostof->block->name,
block->input[j].ghostof->name);
for (j = 0; j < block->outputs; j++) {
if (block->output[j].source != block) {
fprintf(fddot,
"\t\t%s:out_%s:e -> %s:out_%s:w [color=\"grey\"]\n",
block->output[j].source->name,
block->output[j].sourceterm->name,
block->name, block->output[j].name);
}
}
}
for (j = 0; j < block->outputs; j++) {
if (block->output[j].source != block) {
fprintf(fddot, "\t%s:out_%s:e -> %s:out_%s:w [color=\"grey\"]\n",
block->output[j].source->name,
block->output[j].sourceterm->name,
block->name, block->output[j].name);
}
}
fprintf(fddot, "\n");
fprintf(fddot, "\t};\n");
fprintf(fddot, "\n");
}
fprintf(fddot, "\n");
for (i = 0; i < controller_block_link_nr(); i++) {
struct controller_block_link *link = controller_block_link_get(i);
......@@ -124,5 +170,7 @@ void controller_dumpdot(char *filename)
fclose(fddot);
free(contextlist);
return;
}
......@@ -244,6 +244,7 @@ static int controller_load_shell(char *args, char *out, int *outlen)
{
int ret;
struct controller_load_extra extra;
char *safe_context;
yyscan_t scanner;
if (!args) {
......@@ -264,8 +265,13 @@ static int controller_load_shell(char *args, char *out, int *outlen)
yylex_init_extra(&extra, &scanner);
safe_context = controller_block_context_get();
controller_block_context_set("shell");
ret = yyparse(scanner, NULL);
controller_block_context_set(safe_context);
yylex_destroy(scanner);
if (ret) {
......@@ -329,6 +335,8 @@ int controller_load_shell_add(void)
int controller_load(char *filename)
{
struct controller_load_extra extra;
char *safe_context;
yyscan_t scanner;
extra.filename = filename;
extra.ret = 0;
......@@ -338,20 +346,27 @@ int controller_load(char *filename)
extra.use_string = false;
extra.stringlen = 0;
yyscan_t scanner;
extra.input_file = fopen(filename, "r");
if (!extra.input_file)
return -1;
if (!extra.input_file) {
extra.ret = -1;
goto err_nofile;
}
yylex_init_extra(&extra, &scanner);
safe_context = controller_block_context_get();
controller_block_context_set(filename);
extra.ret = yyparse(scanner, extra.input_file);
controller_block_context_set(safe_context);
yylex_destroy(scanner);
fclose(extra.input_file);
controller_block_link();
err_nofile:
return extra.ret;
}
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