diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h index aa24068cadaca62ff637da92390bfd363200c084..d9e77c27c8da96d6447e77ad7b94da649099b298 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -2,6 +2,7 @@ #define __CLI_H #include "cli_setsetpoint.h" +#include "cli_getsetpoint.h" #include "cli_monitor.h" #include "cli_setpid.h" #include "cli_getpid.h" @@ -13,6 +14,7 @@ enum CommandNameIds{ CMD_SETPID, CMD_GETIMU, CMD_SETSETPOINT, + CMD_GETSETPOINT, MAX_COMMANDS }; @@ -30,7 +32,8 @@ static char* commandNames[MAX_COMMANDS] = { "getpid", "setpid", "getimu", - "setsetpoint" + "setsetpoint", + "getsetpoint" }; #endif /* __CLI_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_getpid.c b/groundStation/src/cli/cli_getpid.c index 48c1e72055601df9b66e96ec1c2a3917c1f0fc15..4bf634e3e2e966ea59ac54d8510c3607815f462d 100644 --- a/groundStation/src/cli/cli_getpid.c +++ b/groundStation/src/cli/cli_getpid.c @@ -62,62 +62,62 @@ int cli_getpid(struct backend_conn * conn, int argc, char **argv) { if(getAll) { for(int i = 0; i < PID_NUM_PIDS; ++i) { pid_data.controller = i; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } } else { if(getPitch) { pid_data.controller = PID_PITCH; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getRoll) { pid_data.controller = PID_ROLL; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getYaw) { pid_data.controller = PID_YAW; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getPitchV) { pid_data.controller = PID_PITCH_RATE; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getRollV) { pid_data.controller = PID_ROLL_RATE; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getYawV) { pid_data.controller = PID_YAW_RATE; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getHeight) { pid_data.controller = PID_HEIGHT; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getLat) { pid_data.controller = PID_LAT; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getLong) { pid_data.controller = PID_LONG; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } @@ -127,7 +127,7 @@ int cli_getpid(struct backend_conn * conn, int argc, char **argv) { return 0; } -int getValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) { +int getPidValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) { if(frontend_getpid(conn, pid_data)) { return 1; } diff --git a/groundStation/src/cli/cli_getpid.h b/groundStation/src/cli/cli_getpid.h index 062c010546d45fa348593a6ea123a5e172d48cd3..799681f06d114602083e304f2cba321891155fbc 100644 --- a/groundStation/src/cli/cli_getpid.h +++ b/groundStation/src/cli/cli_getpid.h @@ -3,7 +3,7 @@ #include "frontend_getpid.h" -int getValues(struct backend_conn *, struct frontend_pid_data *); +int getPidValues(struct backend_conn *, struct frontend_pid_data *); int cli_getpid(struct backend_conn * conn, int argc, char ** argv); #endif /* __CLI_GETPID_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_getsetpoint.c b/groundStation/src/cli/cli_getsetpoint.c new file mode 100644 index 0000000000000000000000000000000000000000..c10f49d179bc7807c8213df8e5f0654ceb609d8a --- /dev/null +++ b/groundStation/src/cli/cli_getsetpoint.c @@ -0,0 +1,97 @@ +#include <stdio.h> +#include <unistd.h> +#include <getopt.h> + +#include "cli_getsetpoint.h" + +int cli_getsetpoint(struct backend_conn * conn, int argc, char **argv) { + int c; + static int getheight = 0, getlat = 0, getlong = 0; + struct frontend_setpoint_data setpoint_data; + static int needHelp = 0; + static int mask; + static struct option long_options[] = { + /* These options don’t set a flag. We distinguish them by their indices. */ + {"help", no_argument, &needHelp, 1}, + {"height", no_argument, &getheight, 1}, + {"long", no_argument, &getlong, 1}, + {"lat", no_argument, &getlat, 1}, + {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 (c == 'a') { + getheight = 1; + getlat = 1; + getlong = 1; + } + + } + + if (needHelp) { + printf("Getsetpoint gets the height, lat , and long set point values for the quad.\n"); + printf("Usage Syntax : \n\t./Cli getsetpoint [options...]\n"); + printf("Symlink Usage Syntax : \n\t./getsetpoint [options...]\n\n"); + printf("Available options include the following\n"); + printf("\t[--height] : Gets the height setpoint\n"); + printf("\t[--lat] : Gets the latitude setpoint\n"); + printf("\t[--long] : Gets the longitude setpoint\n"); + return 0; + } + + if (argc < 2) { + printf("Incorrect Usage, run './cli getsetpoint --help' for correct usage.\n"); + return 1; + } + int result; + if(getheight) { + if ((result = getSetPointValues(conn, &setpoint_data, HEIGHT))) { + return result; + } + } + if(getlat) { + if ((result = getSetPointValues(conn, &setpoint_data, LAT))) { + return result; + } + } + if(getlong) { + if ((result = getSetPointValues(conn, &setpoint_data, LONGG))) { + return result; + } + } + + return 0; +} + +int getSetPointValues(struct backend_conn * conn, struct frontend_setpoint_data * setpoint_data, int type) { + if(frontend_getsetpoint(conn, setpoint_data, type)) { + return 1; + } + + switch(type) { + case HEIGHT : + printf("Height: %f\n", + setpoint_data->height); + break; + case LAT : + printf("Latitude: %f\n", + setpoint_data->lat); + case LONGG : + printf("Longitude: %f\n", + setpoint_data->longg); + default : + break; + } + return 0; +} diff --git a/groundStation/src/cli/cli_getsetpoint.h b/groundStation/src/cli/cli_getsetpoint.h new file mode 100644 index 0000000000000000000000000000000000000000..c16d58fb25fa416dcf190e5b7d09dfe9fb74ead2 --- /dev/null +++ b/groundStation/src/cli/cli_getsetpoint.h @@ -0,0 +1,13 @@ +#ifndef __CLI_GETSETPOINT_H +#define __CLI_GETSETPOINT_H + +#include "frontend_getsetpoint.h" + +#define HEIGHT 0 +#define LAT 1 +#define LONGG 2 + +int getSetPointValues(struct backend_conn *, struct frontend_setpoint_data *, int type); +int cli_getsetpoint(struct backend_conn * conn, int argc, char ** argv); + +#endif /* __CLI_GETSETPOINT_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_setsetpoint.c b/groundStation/src/cli/cli_setsetpoint.c index 698aa35f3e73cf4df9aecdcf3cdc1df4859d139e..4e1eb6dd08d984bede153c04a4eeb7ed8586950a 100644 --- a/groundStation/src/cli/cli_setsetpoint.c +++ b/groundStation/src/cli/cli_setsetpoint.c @@ -50,13 +50,13 @@ int cli_setsetpoint(struct backend_conn * conn, int argc, char **argv) { } if (needHelp) { - printf("Setsetpoint sets the x, y , or z set point values for the quad.\n"); + printf("Setsetpoint sets the height, lat , or long set point values for the quad.\n"); printf("Usage Syntax : \n\t./Cli setsetpoint [options...]\n"); printf("Symlink Usage Syntax : \n\t./setsetpoint [options...]\n\n"); printf("Available options include the following\n"); - printf("\t[-x] 'val' : Sets the x setpoint value to 'val'\n"); - printf("\t[-z] 'val' : Sets the y setpoint value to 'val'\n"); - printf("\t[-z] 'val' : Sets the z setpoint value to 'val'\n"); + printf("\t[--height] 'val' : Sets the height setpoint value to 'val'\n"); + printf("\t[--lat] 'val' : Sets the latitude setpoint value to 'val'\n"); + printf("\t[--long] 'val' : Sets the longitude setpoint value to 'val'\n"); return 0; } diff --git a/groundStation/src/frontend/frontend_getsetpoint.c b/groundStation/src/frontend/frontend_getsetpoint.c new file mode 100644 index 0000000000000000000000000000000000000000..57bee3f8fe3bc5fee9c66f5512977959b10d92a6 --- /dev/null +++ b/groundStation/src/frontend/frontend_getsetpoint.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "frontend_getsetpoint.h" +#include "setpoint_common.h" +#include "cli_getsetpoint.h" + +/* Get a specified setpoint. + * + * Example: + * + * struct frontend_setpoint_data setpoint_data; + * if (frontend_getpid(conn, &pid_data)) { + * error + * } else { + * setpoint_data.height, setpoint_data.lat, and setpoint.long are filled + * } + * + * Returns 0 on success, 1 on error + */ +int frontend_getsetpoint( + struct backend_conn * conn, struct frontend_setpoint_data * setpoint_data, int type) { + + char line[25] = ""; + switch (type) { + case HEIGHT : + strncpy(line, "getheight\n", 10); + break; + case LAT : + strncpy(line, "getlat\n", 7); + break; + case LONGG : + strncpy(line, "getlong\n", 8); + break; + } + int size; + if((size = ucart_backendWrite(conn, line)) < 0 ) { + return 1; + } + + return 0; +} diff --git a/groundStation/src/frontend/frontend_getsetpoint.h b/groundStation/src/frontend/frontend_getsetpoint.h new file mode 100644 index 0000000000000000000000000000000000000000..f8dfdc87b3df057d5fd43714c5b81a52831ce763 --- /dev/null +++ b/groundStation/src/frontend/frontend_getsetpoint.h @@ -0,0 +1,25 @@ +#ifndef __FRONTEND_GETSETPOINT_H +#define __FRONTEND_GETSETPOINT_H + +#include "frontend_common.h" +#include "setpoint_common.h" + +/* Get a specified setpoint. + * + * Example: + * + * struct frontend_setpoint_data setpoint_data; + * if (frontend_getpid(conn, &pid_data)) { + * error + * } else { + * setpoint_data.height, setpoint_data.lat, and setpoint.long are filled + * } + * + * Returns 0 on success, 1 on error + */ +int frontend_getsetpoint( + struct backend_conn * conn, + struct frontend_setpoint_data * setpoint_data, + int type); + +#endif /* __FRONTEND_GETPID_H */ \ No newline at end of file