From 6bc213d6a4d1526dfb0dad0c2e272b1e86dc93ed Mon Sep 17 00:00:00 2001 From: Kris Burney <burneykb@iastate.edu> Date: Thu, 10 Nov 2016 13:01:19 -0600 Subject: [PATCH] modified to use frontend_common functions --- groundStation/src/cli/cli.c | 50 ++++++------------------------------- groundStation/src/cli/cli.h | 4 +-- 2 files changed, 9 insertions(+), 45 deletions(-) diff --git a/groundStation/src/cli/cli.c b/groundStation/src/cli/cli.c index 154352b6b..e38966edd 100644 --- a/groundStation/src/cli/cli.c +++ b/groundStation/src/cli/cli.c @@ -1,16 +1,10 @@ #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> #include <string.h> #include <err.h> #include "cli.h" +#include "frontend_common.h" int connectToBackEnd(); @@ -18,7 +12,8 @@ int main(int argc, char **argv) { int cmdID = -1; char * command; - int i , s, useSymlink = 0; + int i , useSymlink = 0; + struct backend_conn *conn; command = argv[0]; for(i = 0; i < MAX_COMMANDS; ++i) { @@ -26,7 +21,7 @@ int main(int argc, char **argv) { cmdID = i; useSymlink = 1; - } + } } if(cmdID == -1) { @@ -45,47 +40,16 @@ int main(int argc, char **argv) } printf("Parsed Command : %s\n", commandNames[cmdID]); - - if((s = connectToBackEnd()) == -1) { - err(-1, "connectToBackEnd"); - } - - - + 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]) } - close(s); - + ucart_backendDisconnect(conn); return 0; -} - -int connectToBackEnd() { - 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); - } else { - printf("Connected.\n"); - return s; - } } \ No newline at end of file diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h index 9e58962c2..e193b5142 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -1,8 +1,6 @@ #ifndef __CLI_H #define __CLI_H -#define SOCK_PATH "/var/run/ucart.socket" - enum CommandNameIds{ CMD_MONITOR, CMD_SETPID, @@ -18,4 +16,6 @@ static char* commandNames[MAX_COMMANDS] = { "getImu" }; +static + #endif \ No newline at end of file -- GitLab