diff --git a/groundStation/src/cli/cli.c b/groundStation/src/cli/cli.c index 58fe14b8c9ac71026860ae4c7687ae31fa38ea26..de456c18e271fe6ddc8a30346b34a0e140acc2e9 100644 --- a/groundStation/src/cli/cli.c +++ b/groundStation/src/cli/cli.c @@ -2,6 +2,7 @@ #include <string.h> #include <err.h> #include <libgen.h> +#include <getopt.h> #include "cli.h" @@ -9,9 +10,20 @@ int main(int argc, char **argv) { int cmdID = -1; char * command; + int c; int i , useSymlink = 0; struct backend_conn *conn; + static int needHelp = 0; + static struct option long_options[] = { + /* These options don’t set a flag. We distinguish them by their indices. */ + {"help", no_argument, &needHelp, 1}, + {0, 0, 0, 0} + }; + int option_index = 0; + c = getopt_long(argc, argv, "", long_options, &option_index); + + // Determine if the cli was called using a symlink command = basename(argv[0]); for(i = 0; i < MAX_COMMANDS; ++i) { if (strncmp(command, commandNames[i], strlen(commandNames[i])) == 0) @@ -21,6 +33,28 @@ int main(int argc, char **argv) } } + // Verify the user has entered enough information to continue + if(argc < 2 && !useSymlink) { + printf("Incorrect usage :\n"); + printf("\n\tUsage : ./Cli command [options] \n"); + printf("\tFor a list of available commands run ./Cli --help\n\n"); + printf("\tFor a list of available options for a command run ./Cli command --help\n"); + return -1; + } + + // If the user runs './Cli help' , provide the user with a list of commands available. + if(needHelp) { + printf("Usage : ./Cli command [options]\n"); + printf("For a list of available options for a command run ./Cli command --help\n\n"); + printf("Available commands include the following\n"); + for(int i = 0; i < MAX_COMMANDS; ++i) { + printf("\t '%s'\n",commandNames[i]); + } + return 0; + } + + + // recognize which cli command the user has entered if(cmdID == -1) { command = argv[1]; for(i = 0; i < MAX_COMMANDS; ++i) { @@ -32,22 +66,41 @@ int main(int argc, char **argv) } if(cmdID == -1){ - printf("Could not match input with a command. Please try again...\n"); + printf("Could not match '%s' with a command. Please try again...\n", command); + printf("For help running the program, run ./Cli --help\n"); return -1; } printf("Parsed Command : %s\n", commandNames[cmdID]); - conn = ucart_backendConnect(); - if(conn == NULL) { - return -1; + + /** + * I the user has asked for help, and we have already found + * the command that they are trying to use. Then we need + * to be able to provide the help info wihtout the + * requirement of the backend + * + * It is important to note that this will only work if the + * command the user has asked for handles this help case + * + */ + + // Only require the backend if we will need to use it. + if(!needHelp) { + // Create the connection to the backend + conn = ucart_backendConnect(); + if(conn == NULL) { + return -1; + } } + // Call the appropriate function if(useSymlink) { (*cli_functions[cmdID]) (conn, argc, &argv[0]); }else { (*cli_functions[cmdID]) (conn, argc-1, &argv[1]); } + // Disconnect from the backend ucart_backendDisconnect(conn); return 0; -} +} \ No newline at end of file diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h index f4c2fe3f4783b9b4a4dd1e3482cdf3034cbaf269..924b33fe1a1b1d8c871d6ed679ec58f131181091 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -4,7 +4,8 @@ #include "cli_monitor.h" #include "cli_setpid.h" #include "cli_getpid.h" -// #include "cli_getimu.h" +#include "cli_getimu.h" + enum CommandNameIds{ CMD_MONITOR, CMD_GETPID, @@ -17,16 +18,14 @@ typedef int (*cli_function_ptr)(struct backend_conn *, int, char **); static cli_function_ptr cli_functions[] = { &cli_monitor, &cli_getpid, - &cli_setpid - //&cli_getimu + &cli_setpid, + &cli_getimu }; static char* commandNames[MAX_COMMANDS] = { "monitor", "getpid", "setpid", - "getImu" + "getimu" }; - - #endif diff --git a/groundStation/src/cli/cli_getimu.c b/groundStation/src/cli/cli_getimu.c new file mode 100644 index 0000000000000000000000000000000000000000..5825140af8c0d7e224b045c533d02ed61134a5f2 --- /dev/null +++ b/groundStation/src/cli/cli_getimu.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +#include "cli_getimu.h" + +int cli_getimu(struct backend_conn * conn, int argc, char ** argv) { + printf("This functionality has not been added yet\n"); + return 0; +} diff --git a/groundStation/src/cli/cli_getimu.h b/groundStation/src/cli/cli_getimu.h index 3f69e4b154b9678845b7604a7d91c6b83bf72ee5..59089a01722683324edd00e8811d4ac9876143e8 100644 --- a/groundStation/src/cli/cli_getimu.h +++ b/groundStation/src/cli/cli_getimu.h @@ -1,9 +1,8 @@ #ifndef CLI_GETIMU_H #define CLI_GETIMU_H + #include "frontend_getimu.h" -int cli_getimu( - struct backend_conn * conn, - struct frontend_pid_data * pid_data); +int cli_getimu(struct backend_conn * conn, int argc, char ** argv); #endif \ No newline at end of file diff --git a/groundStation/src/cli/cli_monitor.c b/groundStation/src/cli/cli_monitor.c index 4494e65b08320fb4831a733ff83d2bc53e803ae0..b9917d1df58c5bde4513fccd9ccccbc6ebd8fe72 100644 --- a/groundStation/src/cli/cli_monitor.c +++ b/groundStation/src/cli/cli_monitor.c @@ -17,7 +17,6 @@ int cli_monitor(struct backend_conn * conn, int argc, char **argv) { int count, rate = 10; int forever = 0; - while ((c = getopt(argc, argv, "fc:r:")) != -1) { switch(c) { case 'c' : diff --git a/groundStation/src/frontend/frontend_getimu.h b/groundStation/src/frontend/frontend_getimu.h new file mode 100644 index 0000000000000000000000000000000000000000..c95784a1d4aada157283aa40ca74cd0fb211d505 --- /dev/null +++ b/groundStation/src/frontend/frontend_getimu.h @@ -0,0 +1,6 @@ +#ifndef FRONTEND_GETIMU_H +#define FRONTEND_GETIMU_H + +#include "frontend_common.h" + +#endif \ No newline at end of file