diff --git a/groundStation/.gitignore b/groundStation/.gitignore index a22e4503492700a44a6e97382e46376868309b5c..129b670af25486e4818d221286346cec985a1f70 100644 --- a/groundStation/.gitignore +++ b/groundStation/.gitignore @@ -44,3 +44,4 @@ BackEnd obj cli monitorQuad +testClient diff --git a/groundStation/src/cli/cli.c b/groundStation/src/cli/cli.c index 39a12ebf45f2922c17605f44257faf85c18a8030..154352b6b65182d2db425518115f103eaec9bf15 100644 --- a/groundStation/src/cli/cli.c +++ b/groundStation/src/cli/cli.c @@ -6,36 +6,67 @@ #include <sys/socket.h> #include <sys/un.h> #include <unistd.h> -#include <getopt.h> +#include <string.h> #include <err.h> #include "cli.h" - -int parseInput(int argc, char **argv); int connectToBackEnd(); int main(int argc, char **argv) { int cmdID = -1; - if((cmdID = parseInput(argc, argv)) == -1) { - exit(1); + char * command; + int i , s, useSymlink = 0; + + command = argv[0]; + for(i = 0; i < MAX_COMMANDS; ++i) { + if (strncmp(command, commandNames[i], strlen(commandNames[i])) == 0) + { + cmdID = i; + useSymlink = 1; + } } - int s; + + if(cmdID == -1) { + command = argv[1]; + for(i = 0; i < MAX_COMMANDS; ++i) { + if (strncmp(command, commandNames[i], strlen(commandNames[i])) == 0) + { + cmdID = i; + } + } + } + + if(cmdID == -1){ + printf("Could not match input with a command. Please try again...\n"); + return -1; + } + + printf("Parsed Command : %s\n", commandNames[cmdID]); + if((s = connectToBackEnd()) == -1) { err(-1, "connectToBackEnd"); } + 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); return 0; } int connectToBackEnd() { - int s, t, len; struct sockaddr_un remote; char str[100]; @@ -57,35 +88,4 @@ int connectToBackEnd() { printf("Connected.\n"); return s; } -} - -int parseInput(int argc, char **argv) { - static int cmdID = -1; - int c; - static struct option long_options[] = - { - /* These options don’t set a flag. We distinguish them by their indices. */ - {"monitor", no_argument, &cmdID, CMD_MONITOR}, - {0, 0, 0, 0} - }; - - while (1) - { - - /* getopt_long stores the option index here. */ - int option_index = 0; - - c = getopt_long (argc, argv, "", - long_options, &option_index); - - /* Detect the end of the options. */ - if (c == -1) - break; - } - if(cmdID == -1) - { - printf("Invalid command\n"); - return cmdID; - } - return 0; } \ No newline at end of file diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h index 2e6654be1e5284e6cf601ec8c625c20939b9427c..9e58962c2fd395e45d319025fe423015be10feb1 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -5,11 +5,17 @@ enum CommandNameIds{ CMD_MONITOR, + CMD_SETPID, + CMD_GETPID, + CMD_GETImu, MAX_COMMANDS }; -char* commandNames[MAX_COMMANDS] = { +static char* commandNames[MAX_COMMANDS] = { "monitor", + "setPid", + "getPid", + "getImu" }; #endif \ No newline at end of file