Newer
Older
#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;
static int getRollV = 0, getPitchV = 0, getYawV = 0;
static int getHeight = 0, getLat = 0, getLong = 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},
{"rollv", no_argument, &getYawV, 1},
{"pitchv", no_argument, &getYawV, 1},
{"yawv", no_argument, &getYawV, 1},
{"height", no_argument, &getHeight, 1},
{"lat", no_argument, &getLat, 1},
{"long", no_argument, &getLong, 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;
}
}
printf("Getpid gets the p, i , or d constant values of any single controller\n");
printf("Usage Syntax : \n\t./Cli getpid controller [options...]\n");
printf("Symlink Usage Syntax : \n\t./getpid controller [options...]\n\n");
printf("Available 'controllers' include the following\n");
printf("\t[--pitch] : Pitch\n\t[--roll] : Roll\n\t[--yaw] : Yaw\n");
printf("\t[--pitchv] : Pitch Velocity\n\t[--rollv] : Roll Velocity\n\t[--yawv] : Yaw Velocity\n");
printf("\t[--height] : Z\n\t[--lat] : X\n\t[--long] : Y\n\n");
printf("Available 'controller' options include the following\n");
printf("\t[-p] 'val' : Gets the p constant of the 'controller\n");
printf("\t[-i] 'val' : Gets the i constant of the 'controller'\n");
printf("\t[-d] 'val' : Gets the d constant of the 'controller'\n");
return 0;
}
if (argc < 2) {
printf("Incorrect Usage, run './cli getpid --help' for correct usage.\n");
return 1;
}
int result;
if(getAll) {
if ((result = getValues(conn, &pid_data))) {
return result;
}
if ((result = getValues(conn, &pid_data))) {
return result;
}
if ((result = getValues(conn, &pid_data))) {
return result;
}
} else {
if(getPitch) {
if ((result = getValues(conn, &pid_data))) {
return result;
}
}
if(getRoll) {
if ((result = getValues(conn, &pid_data))) {
return result;
}
}
if(getYaw) {
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;
}
printf("Pitch Constants: P = %f\tI = %f\tD = %f\n",
pid_data->p, pid_data->i, pid_data->d);
break;
printf("Roll Constants: P = %f\tI = %f\tD = %f\n",
pid_data->p, pid_data->i, pid_data->d);
break;
printf("Yaw Constants: P = %f\tI = %f\tD = %f\n",
pid_data->p, pid_data->i, pid_data->d);
break;
default :
break;
}
return 0;