From ed8a5a8f2a71e90e33d4bb33847b12916b2175b1 Mon Sep 17 00:00:00 2001 From: Kris Burney <burneykb@iastate.edu> Date: Thu, 10 Nov 2016 18:16:05 -0600 Subject: [PATCH] Implemented cli_getPid and modified makefile/gitignore --- groundStation/.gitignore | 5 +- groundStation/Makefile | 2 +- groundStation/src/cli/cli.c | 2 +- groundStation/src/cli/cli.h | 2 +- groundStation/src/cli/cli_getimu.h | 9 +++ groundStation/src/cli/cli_getpid.c | 95 +++++++++++++++++++++++++++++ groundStation/src/cli/cli_getpid.h | 9 +++ groundStation/src/cli/cli_monitor.h | 9 +++ groundStation/src/cli/cli_setpid.h | 0 9 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 groundStation/src/cli/cli_getimu.h create mode 100644 groundStation/src/cli/cli_getpid.c create mode 100644 groundStation/src/cli/cli_getpid.h create mode 100644 groundStation/src/cli/cli_monitor.h create mode 100644 groundStation/src/cli/cli_setpid.h diff --git a/groundStation/.gitignore b/groundStation/.gitignore index 129b670af..eedef6d30 100644 --- a/groundStation/.gitignore +++ b/groundStation/.gitignore @@ -39,9 +39,6 @@ src/vrpn/pc_linux64/* #Exacutables logs -client BackEnd obj -cli -monitorQuad -testClient +CLI diff --git a/groundStation/Makefile b/groundStation/Makefile index 00c3383c6..5f285d6b4 100644 --- a/groundStation/Makefile +++ b/groundStation/Makefile @@ -19,7 +19,7 @@ BECPPSOURCES := $(wildcard $(BESRCDIR)/*.cpp ) BECPPOBJECTS = $(BECPPSOURCES:$(BESRCDIR)/%.cpp=$(OBJDIR)/%.o) # CLI Specific Variables -CLIBINARY=cli +CLIBINARY=CLI CLISRCDIR=src/cli CLISOURCES := $(wildcard $(CLISRCDIR)/*.c) CLIOBJECTS = $(CLISOURCES:$(CLISRCDIR)/%.c=$(OBJDIR)/%.o) diff --git a/groundStation/src/cli/cli.c b/groundStation/src/cli/cli.c index 49bb75b16..b8ad2f738 100644 --- a/groundStation/src/cli/cli.c +++ b/groundStation/src/cli/cli.c @@ -43,7 +43,7 @@ int main(int argc, char **argv) if(useSymlink) { //TODO Call correct command function pointer with (argv[1] ... argc[argc]) }else { - (*cli_functions[0]) (conn, &argv[2]); + (*cli_functions[0]) (conn, argc - 1, &argv[2]); } ucart_backendDisconnect(conn); diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h index ff43f1c1a..4b98962d6 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -15,7 +15,7 @@ enum CommandNameIds{ MAX_COMMANDS }; -typedef int (*cli_function_ptr)(struct backend_conn *, char **); +typedef int (*cli_function_ptr)(struct backend_conn *, int, char **); static cli_function_ptr cli_functions[1] = { // &cli_monitor, // &cli_setpid, diff --git a/groundStation/src/cli/cli_getimu.h b/groundStation/src/cli/cli_getimu.h new file mode 100644 index 000000000..3f69e4b15 --- /dev/null +++ b/groundStation/src/cli/cli_getimu.h @@ -0,0 +1,9 @@ +#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); + +#endif \ No newline at end of file diff --git a/groundStation/src/cli/cli_getpid.c b/groundStation/src/cli/cli_getpid.c new file mode 100644 index 000000000..fb1c627c8 --- /dev/null +++ b/groundStation/src/cli/cli_getpid.c @@ -0,0 +1,95 @@ +#include <stdio.h> +#include <unistd.h> +#include <getopt.h> + +#include "cli_getpid.h" + +int cli_getpid(struct backend_conn * conn, int argc, char **argv) { + int c; + static int getRoll = 0, getPitch = 0, getYaw = 0, getAll = 0; + struct frontend_pid_data pid_data; + static struct option long_options[] = { + /* These options don’t set a flag. We distinguish them by their indices. */ + {"roll", no_argument, &getRoll, 1}, + {"pitch", no_argument, &getPitch, 1}, + {"yaw", no_argument, &getYaw, 1}, + {0, 0, 0, 0} + }; + + while (1) + { + /* getopt_long stores the option index here. */ + int option_index = 0; + + c = getopt_long(argc, argv, "a", long_options, &option_index); + + /* Detect the end of the options. */ + if (c == -1) + break; + + if (c == 'a') { + getAll = 1; + } + } + + int result; + if(getAll) { + pid_data.pid = ROLL; + if ((result = getValues(conn, &pid_data))) { + return result; + } + pid_data.pid = PITCH; + if ((result = getValues(conn, &pid_data))) { + return result; + } + pid_data.pid = YAW; + if ((result = getValues(conn, &pid_data))) { + return result; + } + } else { + if(getPitch) { + pid_data.pid = PITCH; + if ((result = getValues(conn, &pid_data))) { + return result; + } + } + if(getRoll) { + pid_data.pid = ROLL; + if ((result = getValues(conn, &pid_data))) { + return result; + } + } + if(getYaw) { + pid_data.pid = YAW; + if ((result = getValues(conn, &pid_data))) { + return result; + } + } + } + + return 0; +} + +int getValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) { + if(frontend_getpid(conn, pid_data)) { + return 1; + } + + switch(pid_data->pid) { + case PITCH : + printf("Pitch Constants: P = %f\tI = %f\tD = %f\n", + pid_data->p, pid_data->i, pid_data->d); + break; + case ROLL : + printf("Roll Constants: P = %f\tI = %f\tD = %f\n", + pid_data->p, pid_data->i, pid_data->d); + break; + case YAW : + printf("Yaw Constants: P = %f\tI = %f\tD = %f\n", + pid_data->p, pid_data->i, pid_data->d); + break; + default : + break; + } + return 0; +} \ No newline at end of file diff --git a/groundStation/src/cli/cli_getpid.h b/groundStation/src/cli/cli_getpid.h new file mode 100644 index 000000000..f5c0b15e4 --- /dev/null +++ b/groundStation/src/cli/cli_getpid.h @@ -0,0 +1,9 @@ +#ifndef CLI_GETPID_H +#define CLI_GETPID_H + +#include "frontend_getpid.h" + +int getValues(struct backend_conn *, struct frontend_pid_data *); +int cli_getpid(struct backend_conn * conn, int argc, char ** argv); + +#endif \ No newline at end of file diff --git a/groundStation/src/cli/cli_monitor.h b/groundStation/src/cli/cli_monitor.h new file mode 100644 index 000000000..2509cc256 --- /dev/null +++ b/groundStation/src/cli/cli_monitor.h @@ -0,0 +1,9 @@ +#ifndef CLI_MONITOR_H +#define CLI_MONITOR_H +#include "frontend_getpid.h" + +int cli_getpid( + struct backend_conn * conn, + struct frontend_pid_data * pid_data); + +#endif \ No newline at end of file diff --git a/groundStation/src/cli/cli_setpid.h b/groundStation/src/cli/cli_setpid.h new file mode 100644 index 000000000..e69de29bb -- GitLab