diff --git a/groundStation/Makefile b/groundStation/Makefile index f0d6737fbe1159f47ffd25a55f839f40cf2e6e04..d00c5d4ce7a8ac04c3f33a0eeded2e839140bea1 100644 --- a/groundStation/Makefile +++ b/groundStation/Makefile @@ -6,8 +6,8 @@ GXX=g++ CFLAGS= -Wall -pedantic -Wextra -Werror -std=gnu99 -g -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-but-set-variable CXXFLAGS= -Wall -pedantic -Wextra -Werror -Wno-reorder -Wno-unused-variable -std=c++0x -g INCLUDES = $(foreach dir, $(INCDIR), -I$(dir)) -INCDIR=../quad/inc src/vrpn src/vrpn/quat src/vrpn/build $(BESRCDIR) $(CLISRCDIR) $(FESRCDIR) -LIBS= -lpthread -lbluetooth -lvrpn -lquat -Lsrc/vrpn/build -Lsrc/vrpn/build/quat -lcomputation_graph -L../quad/lib -lcommands +INCDIR= src/vrpn src/vrpn/quat src/vrpn/build $(BESRCDIR) $(CLISRCDIR) $(FESRCDIR) ../quad/inc +LIBS= -lpthread -lbluetooth -lvrpn -lquat -Lsrc/vrpn/build -Lsrc/vrpn/build/quat -L../quad/lib -lquad_app -lcommands -lgraph_blocks -lcomputation_graph OBJDIR=obj # Backend Specific Variables @@ -50,7 +50,6 @@ cli: $(CLIOBJECTS) $(FECOBJECTS) $(CLIOBJECTS) : $(OBJDIR)/%.o : $(CLISRCDIR)/%.c $(GCC) $(CFLAGS) -c $^ -o $@ $(INCLUDES) $(LIBS) - backend: $(BECPPOBJECTS) $(BECOBJECTS) $(GXX) $(CXXFLAGS) $^ -o $(BEBINARY) $(INCLUDES) $(LIBS) @@ -79,5 +78,4 @@ clean_logs: clean: rm -rf $(OBJDIR)/ $(BEBINARY) $(CLIBINARY) $(SYMLINKS) -debug: - @echo $(COMOBJECTS) +debug: \ No newline at end of file diff --git a/groundStation/src/cli/cli_nodes.c b/groundStation/src/cli/cli_nodes.c index af51d9cb2c3c3d2954547dc102f88d682e5ff13c..341a8f05933369847150a9b97d6715a07e454ab9 100644 --- a/groundStation/src/cli/cli_nodes.c +++ b/groundStation/src/cli/cli_nodes.c @@ -6,6 +6,8 @@ #include "cli.h" #include "cli_nodes.h" #include "frontend_nodes.h" +#include "graph_blocks.h" + int cli_getnodes(struct backend_conn * conn, int argc, char ** argv) { size_t num_nodes = 0; @@ -13,6 +15,9 @@ int cli_getnodes(struct backend_conn * conn, int argc, char ** argv) { int needHelp = 0; + size_t i, n; + + if ((needHelp = help_check(argc, argv))) { printf("getnodes gets the number of nodes along with the block_id, type_id and name of each node\n"); printf("Usage Syntax : \n\t./Cli getnodes\n"); @@ -37,9 +42,35 @@ int cli_getnodes(struct backend_conn * conn, int argc, char ** argv) { printf("------------------------------------------------\n"); printf("\tBLOCK\t\tTYPE\t\tNAME\n"); printf("------------------------------------------------\n"); - for(size_t i = 0; i < num_nodes; ++i) { - printf("\t%3d\t\t%3d\t\t%s\n", node_data[i].block, node_data[i].type, node_data[i].name); + for(i = 0; i < num_nodes; ++i) { + printf("\t%3d\t\t%3d\t\t%s\t", node_data[i].block, node_data[i].type, node_data[i].name); + + const struct graph_node_type * node_definition = blockDefs[node_data[i].type]; + printf(" {"); + + for(n = 0; n < (size_t)node_definition->n_inputs; ++n) { + printf(" %-5s ", node_definition->input_names[n]); + } + printf("} "); + + printf(" {"); + + for(n = 0; n < (size_t)node_definition->n_params; ++n) { + printf(" %s ", node_definition->param_names[n]); + } + printf("} "); + + printf(" {"); + + for(n = 0; n < (size_t)node_definition->n_outputs; ++n) { + printf(" %s ", node_definition->output_names[n]); + } + printf("}\n"); + + + free(node_data[i].name); } + free(node_data); return 0; } diff --git a/groundStation/src/cli/cli_param.c b/groundStation/src/cli/cli_param.c index f509ed092e0ee50233c56291dea995d28db93d2d..4cc50b3f6b968181c56cc5ab6d36295e90b52273 100644 --- a/groundStation/src/cli/cli_param.c +++ b/groundStation/src/cli/cli_param.c @@ -4,12 +4,12 @@ #include "cli.h" #include "cli_param.h" -#include "frontend_param.h" int cli_getparam(struct backend_conn * conn, int argc, char ** argv) { int needHelp = 0; struct frontend_param_data param_data; - + + if ((needHelp = help_check(argc, argv))) { printf("getparam gets the param_val for a specified block_id and param_id\n"); printf("Usage Syntax : \n\t./Cli getparam block_id param_id\n"); @@ -22,8 +22,9 @@ int cli_getparam(struct backend_conn * conn, int argc, char ** argv) { return 1; } - param_data.block = atoi(argv[1]); - param_data.param = atoi(argv[2]); + if (convert_to_id(conn, argv, ¶m_data)) { + return 1; + } if (frontend_getparam(conn, ¶m_data)) { return 1; @@ -53,8 +54,11 @@ int cli_setparam(struct backend_conn * conn, int argc, char ** argv) { return 1; } - param_data.block = atoi(argv[1]); - param_data.param = atoi(argv[2]); + + if (convert_to_id(conn, argv, ¶m_data)) { + return 1; + } + param_data.value = atoi(argv[3]); if (frontend_setparam(conn, ¶m_data)) { diff --git a/groundStation/src/cli/cli_param.h b/groundStation/src/cli/cli_param.h index 2ded347749c77d0f5d6d85e5c28a7371f2da46f5..f80b7829257c8ff9a3ea8517fa5a5f6227b604f5 100644 --- a/groundStation/src/cli/cli_param.h +++ b/groundStation/src/cli/cli_param.h @@ -1,7 +1,92 @@ #ifndef _CLI_PARAM_H #define _CLI_PARAM_H +#include <ctype.h> +#include <string.h> + #include "frontend_param.h" +#include "frontend_nodes.h" +#include "graph_blocks.h" + + +static int isNumber(char *number) +{ + int i = 0; + //checking for negative numbers + if (number[0] == '-') + i = 1; + for (; number[i] != 0; i++) + { + //if (number[i] > '9' || number[i] < '0') + if (!isdigit(number[i])) + return 0; + } + return 1; +} + +static int convert_to_id(struct backend_conn * conn, char **argv, struct frontend_param_data * param_data) { + /* variables used to search for id values */ + size_t num_nodes = 0, i; + struct frontend_node_data* search_data; + int search_for_block = 0, search_for_param = 0; + const struct graph_node_type * node_definition; + + + if (!isNumber(argv[1])) { + search_for_block = 1; + } else { + param_data->block = atoi(argv[1]); + } + + if (!isNumber(argv[2])) { + search_for_param = 1; + } else { + param_data->param = atoi(argv[2]); + } + + if (!search_for_block && !search_for_param) { + return 0; + } + + search_data = malloc(sizeof((*search_data)) * num_nodes); + + if (frontend_getnodes(conn, &search_data, &num_nodes)) { + return 1; + } + + if (search_for_block) { + for (i = 0; i < num_nodes; ++i) { + if (strncmp(search_data[i].name, argv[1], strlen(search_data[i].name)) == 0) { + param_data->block = search_data[i].block; + node_definition = blockDefs[search_data[i].type]; + break; + } + } + } + + if (i == num_nodes) + return 1; + + if (search_for_param) { + if (!search_for_block) { + node_definition = blockDefs[search_data[param_data->block].type]; + } + for (i = 0; i < (size_t)node_definition->n_params; ++i) { + if (strncmp(node_definition->param_names[i], + argv[2], + strlen(node_definition->param_names[i])) == 0) { + param_data->param = i; + search_for_param = 0; + break; + } + } + } + for(i = 0; i < num_nodes; ++i) { + free(search_data[i].name); + } + free(search_data); + return search_for_param; +} int cli_getparam(struct backend_conn * conn, int argc, char ** argv); int cli_setparam(struct backend_conn * conn, int argc, char ** argv); diff --git a/groundStation/src/frontend/frontend_common.h b/groundStation/src/frontend/frontend_common.h index f4ed6b740fd63017615484fb1e85f1f79a37b551..9b2bbdeaf5b81a6621c6ba1c98930e3145e99b88 100644 --- a/groundStation/src/frontend/frontend_common.h +++ b/groundStation/src/frontend/frontend_common.h @@ -41,7 +41,7 @@ struct frontend_source_data { struct frontend_node_data { int16_t block; int16_t type; - char name[512]; /* This should be more than enough room for a node name */ + char *name; }; #endif /* __FRONTEND_COMMON_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_nodes.c b/groundStation/src/frontend/frontend_nodes.c index 26a45c60a609df3e4725a834f26061b898385949..6f2ef72e9c6bedda79d88be8ce9f997730fa35e8 100644 --- a/groundStation/src/frontend/frontend_nodes.c +++ b/groundStation/src/frontend/frontend_nodes.c @@ -10,6 +10,10 @@ * all of the nodes in the current comp_graph. * * Returns 0 on success, 1 on error + * + * + * Note : node_data may be resized inside this function. + * That is why you must pass in a strcut ... ** */ int frontend_getnodes( struct backend_conn * conn, @@ -68,11 +72,13 @@ int frontend_getnodes( } for (size_t i = 0; i < *num_nodes; ++i) { - sscanf(response, " '%[^\t\n']' %n", (char *)&arr[i].name, (int *)&offset); + char tmp_name[512]; + sscanf(response, " '%[^\t\n']' %n", (char *)&tmp_name, (int *)&offset); + arr[i].name = malloc(sizeof(*arr[i].name) * strlen(tmp_name) + 1); + strcpy((char*)arr[i].name, tmp_name); // printf("found name '%s'\n", arr[i].name); response += offset; } - pendingResponses--; } diff --git a/groundStation/src/frontend/frontend_nodes.h b/groundStation/src/frontend/frontend_nodes.h index 538a7cad6b132f42083f13fd6129a3b061c34b76..8410d12decb915d23e77e9c71263065177ecb58b 100644 --- a/groundStation/src/frontend/frontend_nodes.h +++ b/groundStation/src/frontend/frontend_nodes.h @@ -7,6 +7,9 @@ * all of the nodes in the current comp_graph. * * Returns 0 on success, 1 on error + * + * Note : node_data may be resized inside this function. + * That is why you must pass in a strcut ... ** */ int frontend_getnodes( struct backend_conn * conn, diff --git a/quad/src/graph_blocks/graph_blocks.h b/quad/src/graph_blocks/graph_blocks.h index 12382fda407c98694a7c799170feba12e824ddb6..812e2a844a15ed0afba19d7fd3f2b78b8a5ea997 100644 --- a/quad/src/graph_blocks/graph_blocks.h +++ b/quad/src/graph_blocks/graph_blocks.h @@ -22,7 +22,6 @@ */ - /* * Enumerates all the types of different block types. * Must match blockDefs diff --git a/quad/src/quad_app/Makefile b/quad/src/quad_app/Makefile index ffe41ddcba74e67aad0dacc4b28ff9788d1034d2..02cc8d007386acd8b03e61623248cd1e75059829 100644 --- a/quad/src/quad_app/Makefile +++ b/quad/src/quad_app/Makefile @@ -2,6 +2,5 @@ TOP=../.. NAME = quad_app REQLIBS = -ltest -lcomputation_graph -lm -lqueue -lgraph_blocks -lcommands -REQLIBS = -ltest -lcomputation_graph -lm -lqueue -lcommands include $(TOP)/library.mk