From 9e52632dc7867b711b5eb1c044c8c53cb5984b27 Mon Sep 17 00:00:00 2001 From: Kris Burney <burneykb@iastate.edu> Date: Thu, 10 Nov 2016 14:10:21 -0600 Subject: [PATCH] Further skeleton and cli structure implementation --- groundStation/Makefile | 13 +++---- groundStation/src/cli/cli.c | 5 +-- groundStation/src/cli/cli.h | 16 +++++++-- groundStation/src/cli/testClient.c | 55 ------------------------------ 4 files changed, 21 insertions(+), 68 deletions(-) delete mode 100644 groundStation/src/cli/testClient.c diff --git a/groundStation/Makefile b/groundStation/Makefile index a8ed46cfb..00c3383c6 100644 --- a/groundStation/Makefile +++ b/groundStation/Makefile @@ -19,10 +19,10 @@ BECPPSOURCES := $(wildcard $(BESRCDIR)/*.cpp ) BECPPOBJECTS = $(BECPPSOURCES:$(BESRCDIR)/%.cpp=$(OBJDIR)/%.o) # CLI Specific Variables +CLIBINARY=cli CLISRCDIR=src/cli -CLISOURCES := $(wildcard $(CLISRCDIR)/*.c ) +CLISOURCES := $(wildcard $(CLISRCDIR)/*.c) CLIOBJECTS = $(CLISOURCES:$(CLISRCDIR)/%.c=$(OBJDIR)/%.o) -CLIBINARIES = $(notdir $(patsubst %.c,%,$(CLISOURCES))) # Frontend-common stuff FESRCDIR=src/frontend @@ -37,10 +37,11 @@ all: logs objdir backend cli vrpn: vrpn/build -cli: $(CLIBINARIES) +cli: $(CLIOBJECTS) $(FECOBJECTS) + $(GCC) $(CFLAGS) $^ -o $@ $(INCLUDES) $(LIBS) -$(CLIBINARIES): % : $(CLISRCDIR)/%.c $(FECOBJECTS) - $(GCC) $(CFLAGS) $< -o $@ $(INCLUDES) $(LIBS) $(FECOBJECTS) +$(CLIOBJECTS) : $(OBJDIR)/%.o : $(CLISRCDIR)/%.c + $(GCC) $(CFLAGS) -c $^ -o $@ $(INCLUDES) $(LIBS) backend: $(BECPPOBJECTS) $(BECOBJECTS) @@ -72,4 +73,4 @@ clean: rm -rf $(OBJDIR)/ $(BEBINARY) $(CLIBINARIES) debug: - @echo $(CLIBINARIES) + @echo $(OBJECTS) diff --git a/groundStation/src/cli/cli.c b/groundStation/src/cli/cli.c index ddd27cec8..49bb75b16 100644 --- a/groundStation/src/cli/cli.c +++ b/groundStation/src/cli/cli.c @@ -3,7 +3,6 @@ #include <err.h> #include "cli.h" -#include "frontend_common.h" int connectToBackEnd(); @@ -40,13 +39,11 @@ int main(int argc, char **argv) printf("Parsed Command : %s\n", commandNames[cmdID]); conn = ucart_backendConnect(); - - printf("connection to backend Successful\n"); if(useSymlink) { //TODO Call correct command function pointer with (argv[1] ... argc[argc]) }else { - //TODO Call correct command function pointer with (argv[2] ... argv[argc]) + (*cli_functions[0]) (conn, &argv[2]); } ucart_backendDisconnect(conn); diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h index 468518ec4..ff43f1c1a 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -1,9 +1,11 @@ #ifndef __CLI_H #define __CLI_H - - - +#include "frontend_getpid.h" +// #include "cli_monitor.h" +// #include "cli_setpid.h" +#include "cli_getpid.h" +// #include "cli_getimu.h" enum CommandNameIds{ CMD_MONITOR, @@ -13,6 +15,14 @@ enum CommandNameIds{ MAX_COMMANDS }; +typedef int (*cli_function_ptr)(struct backend_conn *, char **); +static cli_function_ptr cli_functions[1] = { + // &cli_monitor, + // &cli_setpid, + &cli_getpid + // &cli_getimu +}; + static char* commandNames[MAX_COMMANDS] = { "monitor", "setPid", diff --git a/groundStation/src/cli/testClient.c b/groundStation/src/cli/testClient.c deleted file mode 100644 index c6db27cd2..000000000 --- a/groundStation/src/cli/testClient.c +++ /dev/null @@ -1,55 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <unistd.h> - -#define SOCK_PATH "/var/run/ucart.socket" - -int main(void) -{ - int s, t, len; - struct sockaddr_un remote; - char str[100]; - - if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - perror("socket"); - exit(1); - } - - printf("Trying to connect...\n"); - - remote.sun_family = AF_UNIX; - strcpy(remote.sun_path, SOCK_PATH); - len = strlen(remote.sun_path) + sizeof(remote.sun_family); - if (connect(s, (struct sockaddr *)&remote, sizeof(remote)) == -1) { - perror("connect"); - exit(1); - } - - printf("Connected.\n"); - - while(printf("> "), fgets(str, 100, stdin), !feof(stdin)) { - if (send(s, str, strlen(str), 0) == -1) { - perror("send"); - exit(1); - } - /* - if ((t=recv(s, str, 100, 0)) > 0) { - str[t] = '\0'; - printf("echo> %s", str); - } else { - if (t < 0) perror("recv"); - else printf("Server closed connection\n"); - exit(1); - } -*/ - } - - close(s); - - return 0; -} -- GitLab