Skip to content
Snippets Groups Projects
Commit a10415b3 authored by burneykb's avatar burneykb
Browse files

Merge branch 'groundStation-dev-cli-setpoint' into groundStation-dev-cli

parents b5d709aa 21e4c59a
No related branches found
No related tags found
No related merge requests found
Showing
with 1384 additions and 629 deletions
......@@ -42,3 +42,10 @@ logs
BackEnd
obj
Cli
#symlinks
getpid
monitor
setpid
setsetpoint
getsetpoint
......@@ -23,7 +23,7 @@ CLIBINARY=Cli
CLISRCDIR=src/cli
CLISOURCES := $(wildcard $(CLISRCDIR)/*.c)
CLIOBJECTS = $(CLISOURCES:$(CLISRCDIR)/%.c=$(OBJDIR)/%.o)
SYMLINKS=monitor setpid getpid
SYMLINKS=monitor setpid getpid setsetpoint getsetpoint
# Frontend-common stuff
FESRCDIR=src/frontend
......
#include "commands.h"
/* New stuff - this is nice and clean */
/* Override any callbacks here */
/****** LEGACY CODE BE VERY AFRAID ********/
// TAKE THESE OUT WHEN IMPLEMENTING ON THE QUAD SIDE
float getFloat(unsigned char* str, int pos) {
union {
float f;
int i;
} x;
x.i = ((str[pos+3] << 24) | (str[pos+2] << 16) | (str[pos+1] << 8) | (str[pos]));
return x.f;
}
int getInt(unsigned char* str, int pos) {
int i = ((str[pos+3] << 24) | (str[pos+2] << 16) | (str[pos+1] << 8) | (str[pos]));
return i;
}
//------------------------------------------------
int cb_debug(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for debug\n");
return 0;
}
int cb_update(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
unsigned char update[28];
memcpy(update, ((float *)packet), 28);
int packetId = getInt(update, 0);
float y_pos = getFloat(update, 4);
float x_pos = getFloat(update, 8);
float alt_pos = getFloat(update, 12);
float roll = getFloat(update, 16);
float pitch = getFloat(update, 20);
float yaw = getFloat(update, 24);
structs->log_struct.currentQuadPosition.packetId = packetId;
structs->log_struct.currentQuadPosition.y_pos = y_pos;
structs->log_struct.currentQuadPosition.x_pos = x_pos;
structs->log_struct.currentQuadPosition.alt_pos = alt_pos;
structs->log_struct.currentQuadPosition.roll = roll;
structs->log_struct.currentQuadPosition.pitch = pitch;
structs->log_struct.currentQuadPosition.yaw = yaw;
printf("QUAD: VRPN Packet:");
printf("Packet ID: %d\n", packetId);
printf("Y Position: %f\n", y_pos);
printf("X Position: %f\n", x_pos);
printf("Altitude Position: %f\n", alt_pos);
printf("Roll: %f\n", roll);
printf("Pitch: %f\n", pitch);
printf("Yaw: %f\n", yaw);
printf("function for update\n");
return 0;
}
// Why is this here?
// This should be on the ground station side
int logdata(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("Logging: %s\n", packet);
return 0;
}
int response(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("This is the response: %s\n", packet);
return 0;
}
// ------------------------------------------------------------------
int setyaw(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
printf("%f\n", value);
structs->setpoint_struct.desiredQuadPosition.yaw = value;
printf("function for setyaw: %f\n", structs->setpoint_struct.desiredQuadPosition.yaw);
return 0;
}
int setyawp(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.yaw_angle_pid.Kp = value;
printf("function for setyawp: %f\n", structs->parameter_struct.yaw_angle_pid.Kp);
return 0;
}
int setyawd(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.yaw_angle_pid.Kd = value;
printf("function for setyawd: %f\n", structs->parameter_struct.yaw_angle_pid.Kd);
return 0;
}
int setroll(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->setpoint_struct.desiredQuadPosition.roll = value;
printf("function for setroll: %f\n", structs->setpoint_struct.desiredQuadPosition.roll);
return 0;
}
int setrollp(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.local_y_pid.Kp = value;
printf("function for setrollp: %f\n", structs->parameter_struct.local_y_pid.Kp);
return 0;
}
int setrolld(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.local_y_pid.Kd = value;
printf("function for setrolld: %f\n", structs->parameter_struct.local_y_pid.Kd);
return 0;
}
int setpitch(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->setpoint_struct.desiredQuadPosition.pitch = value;
printf("function for setpitch: %f\n", structs->setpoint_struct.desiredQuadPosition.pitch);
return 0;
}
int setpitchp(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.local_x_pid.Kp = value;
printf("function for setpitchp: %f\n", structs->parameter_struct.local_x_pid.Kp);
return 0;
}
int setpitchd(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.local_x_pid.Kd = value;
printf("function for setpitchd: %f\n", structs->parameter_struct.local_x_pid.Kd);
return 0;
}
// ------------------------------------------------------------
// These should be renamed to altitude!
int setthrottle(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->setpoint_struct.desiredQuadPosition.alt_pos = value;
printf("function for setthrottle: %f\n", structs->setpoint_struct.desiredQuadPosition.alt_pos);
return 0;
}
int setthrottlep(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.alt_pid.Kp = value;
printf("function for setthrottlep: %f\n", structs->parameter_struct.alt_pid.Kp);
return 0;
}
int setthrottlei(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.alt_pid.Ki = value;
printf("function for setthrottlei: %f\n", structs->parameter_struct.alt_pid.Ki);
return 0;
}
int setthrottled(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
float value;
memcpy(&value, ((float *)packet), dataLen);
structs->parameter_struct.alt_pid.Kd = value;
printf("function for setthrottled: %f\n", structs->parameter_struct.alt_pid.Kd);
return 0;
}
int getyaw(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getyawp(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getyawd(unsigned char *packet, int dataLen, modular_structs_t *structs) {
return 0;
}
int getroll(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getrollp(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getrolld(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getpitch(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getpitchp(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getpitchd(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getthrottle(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getthrottlep(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getthrottlei(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int getthrottled(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
// These should be renamed to altitude!
// ------------------------------------------------------------
int getgyro(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for getgyro\n");
return 0;
}
int getpitchangle(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for getpitchangle\n");
return 0;
}
int getrollangle(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for getrollangle\n");
return 0;
}
int getaccel(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for getaccel\n");
return 0;
}
int respgyro(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for respgyro\n");
return 0;
}
int resppitchangle(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for resppitchangle\n");
return 0;
}
int resprollangle(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for resprollangle\n");
return 0;
}
int respaccel(unsigned char *packet, int dataLen, modular_structs_t *structs)
{
printf("function for respaccel\n");
return 0;
}
int respyaw(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int respyawp(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int respyawd(unsigned char *packet, int dataLen, modular_structs_t *structs) {
return 0;
}
int resproll(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int resprollp(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int resprolld(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int resppitch(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int resppitchp(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int resppitchd(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int respthrottle(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int respthrottlep(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int respthrottlei(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
int respthrottled(unsigned char *packet, int dataLen, modular_structs_t *structs){
return 0;
}
#ifndef __CALLBACKS_H
#define __CALLBACKS_H
/* Grab some stupid stuff from legacy code */
#include "type_def.h"
/* Make commands.c happy */
typedef void (command_cb)(unsigned char *command,
int dataLen, modular_structs_t *structs);
#endif /* __CALLBACKS_H */
#ifndef __CB_DEFAULT_H
#define __CB_DEFAULT_H
#include "commands.h"
/* The cb_default used on the groundStation. This file MUST NOT BE INCLUDED
* by anything except for commands.c */
/* cb_default used by portable commands.c */
int cb_default(unsigned char * command, int dataLen, modular_structs_t *structs)
{
return 0;
}
#endif /* __CB_DEFAULT_H */
\ No newline at end of file
This diff is collapsed.
#ifndef _COMMANDS_H
#define _COMMANDS_H
#ifndef __COMMANDS_H
#define __COMMANDS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "type_def.h"
#include "callbacks.h"
// ----------------------
// Helper stuff
......@@ -31,7 +31,7 @@ struct MessageSubtype{
char ID;
char cmdText[100];
char cmdDataType;
int (*functionPtr)(unsigned char *command, int dataLen, modular_structs_t *structs);
command_cb * functionPtr;
};
// MESSAGE TYPES
......@@ -40,66 +40,12 @@ struct MessageType{
struct MessageSubtype subtypes[MAX_SUBTYPE];
};
int debug(unsigned char *c, int dataLen, modular_structs_t *structs);
int update(unsigned char *c, int dataLen, modular_structs_t *structs);
int logdata(unsigned char *c, int dataLen, modular_structs_t *structs);
int response(unsigned char *packet, int dataLen, modular_structs_t *structs);
int setyaw(unsigned char *c, int dataLen, modular_structs_t *structs);
int setyawp(unsigned char *c, int dataLen, modular_structs_t *structs);
int setyawd(unsigned char *c, int dataLen, modular_structs_t *structs);
int setroll(unsigned char *c, int dataLen, modular_structs_t *structs);
int setrollp(unsigned char *c, int dataLen, modular_structs_t *structs);
int setrolld(unsigned char *c, int dataLen, modular_structs_t *structs);
int setpitch(unsigned char *c, int dataLen, modular_structs_t *structs);
int setpitchp(unsigned char *c, int dataLen, modular_structs_t *structs);
int setpitchd(unsigned char *c, int dataLen, modular_structs_t *structs);
int setthrottle(unsigned char *c, int dataLen, modular_structs_t *structs);
int setthrottlep(unsigned char *c, int dataLen, modular_structs_t *structs);
int setthrottlei(unsigned char *c, int dataLen, modular_structs_t *structs);
int setthrottled(unsigned char *c, int dataLen, modular_structs_t *structs);
int getyaw(unsigned char *c, int dataLen, modular_structs_t *structs);
int getyawp(unsigned char *c, int dataLen, modular_structs_t *structs);
int getyawd(unsigned char *c, int dataLen, modular_structs_t *structs);
int getroll(unsigned char *c, int dataLen, modular_structs_t *structs);
int getrollp(unsigned char *c, int dataLen, modular_structs_t *structs);
int getrolld(unsigned char *c, int dataLen, modular_structs_t *structs);
int getpitch(unsigned char *c, int dataLen, modular_structs_t *structs);
int getpitchp(unsigned char *c, int dataLen, modular_structs_t *structs);
int getpitchd(unsigned char *c, int dataLen, modular_structs_t *structs);
int getthrottle(unsigned char *c, int dataLen, modular_structs_t *structs);
int getthrottlep(unsigned char *c, int dataLen, modular_structs_t *structs);
int getthrottlei(unsigned char *c, int dataLen, modular_structs_t *structs);
int getthrottled(unsigned char *c, int dataLen, modular_structs_t *structs);
int getaccel(unsigned char *c, int dataLen, modular_structs_t *structs);
int getgyro(unsigned char *c, int dataLen, modular_structs_t *structs);
int getpitchangle(unsigned char *c, int dataLen, modular_structs_t *structs);
int getrollangle(unsigned char *c, int dataLen, modular_structs_t *structs);
int respaccel(unsigned char *c, int dataLen, modular_structs_t *structs);
int respgyro(unsigned char *c, int dataLen, modular_structs_t *structs);
int resppitchangle(unsigned char *c, int dataLen, modular_structs_t *structs);
int resprollangle(unsigned char *c, int dataLen, modular_structs_t *structs);
int respyaw(unsigned char *c, int dataLen, modular_structs_t *structs);
int respyawp(unsigned char *c, int dataLen, modular_structs_t *structs);
int respyawd(unsigned char *c, int dataLen, modular_structs_t *structs);
int resproll(unsigned char *c, int dataLen, modular_structs_t *structs);
int resprollp(unsigned char *c, int dataLen, modular_structs_t *structs);
int resprolld(unsigned char *c, int dataLen, modular_structs_t *structs);
int resppitch(unsigned char *c, int dataLen, modular_structs_t *structs);
int resppitchp(unsigned char *c, int dataLen, modular_structs_t *structs);
int resppitchd(unsigned char *c, int dataLen, modular_structs_t *structs);
int respthrottle(unsigned char *c, int dataLen, modular_structs_t *structs);
int respthrottlep(unsigned char *c, int dataLen, modular_structs_t *structs);
int respthrottlei(unsigned char *c, int dataLen, modular_structs_t *structs);
int respthrottled(unsigned char *c, int dataLen, modular_structs_t *structs);
int respaccel(unsigned char *c, int dataLen, modular_structs_t *structs);
int respgyro(unsigned char *c, int dataLen, modular_structs_t *structs);
int resppitchangle(unsigned char *c, int dataLen, modular_structs_t *structs);
int resprollangle(unsigned char *c, int dataLen, modular_structs_t *structs);
/* Defined in commands.c */
extern struct MessageType MessageTypes[MAX_TYPE];
/* Legacy functions - no idea what uses these. Please do not delete. */
float getFloat(unsigned char* str, int pos);
int getInt(unsigned char* str, int pos);
/* end legacy crap */
// TODO add in string to be read from the command line when sending a subtype of message
extern struct MessageType MessageTypes[MAX_TYPE];
#endif
\ No newline at end of file
#endif /* __COMMANDS_H */
\ No newline at end of file
#ifndef _COMMUNICATION_H
#define _COMMUNICATION_H
#ifndef __COMMUNICATION_H
#define __COMMUNICATION_H
#include <stdio.h>
#include <string.h>
......@@ -16,4 +16,4 @@ int parse_packet(unsigned char * packet, unsigned char ** data, metadata_t * met
int processCommand(unsigned char *command, modular_structs_t *structs);
int logData(unsigned char *log_msg, unsigned char *formattedCommand);
#endif
\ No newline at end of file
#endif /* __COMMUNICATION_H */
\ No newline at end of file
......@@ -17,4 +17,4 @@
#define QUAD_PORT_ENV "UCART_QUAD_PORT"
#define QUAD_PORT_DEFAULT 8080
#endif
#endif /* __CONFIG_H */
\ No newline at end of file
......@@ -2,8 +2,8 @@
*
* Logger header file for holding info pertaining to loging to a file.
*/
#ifndef _LOGGER_H
#define _LOGGER_H
#ifndef __LOGGER_H
#define __LOGGER_H
#include <fcntl.h>
#include <time.h>
......@@ -18,4 +18,4 @@ int updateLogFile(const struct ucart_vrpn_TrackerData* );
void closeLogFile();
#endif
#endif /* __LOGGER_H */
\ No newline at end of file
......@@ -5,8 +5,8 @@
* Author: ucart
*/
#ifndef TYPE_DEF_H_
#define TYPE_DEF_H_
#ifndef __TYPE_DEF_H
#define __TYPE_DEF_H
/**
* @brief
......@@ -358,4 +358,4 @@ typedef struct {
//////// END MAIN MODULAR STRUCTS
#endif /* TYPE_DEF_H_ */
#endif /* __TYPE_DEF_H */
......@@ -76,6 +76,8 @@ int main(int argc, char **argv)
needCommandHelp = 1;
}
}
printf("made it\n");
/**
* I the user has asked for help, and we have already found
......
#ifndef __CLI_H
#define __CLI_H
#include "cli_setsetpoint.h"
#include "cli_getsetpoint.h"
#include "cli_monitor.h"
#include "cli_setpid.h"
#include "cli_getpid.h"
......@@ -11,6 +13,8 @@ enum CommandNameIds{
CMD_GETPID,
CMD_SETPID,
CMD_GETIMU,
CMD_SETSETPOINT,
CMD_GETSETPOINT,
MAX_COMMANDS
};
......@@ -19,13 +23,18 @@ static cli_function_ptr cli_functions[] = {
&cli_monitor,
&cli_getpid,
&cli_setpid,
&cli_getimu
&cli_getimu,
&cli_setsetpoint,
&cli_getsetpoint
};
static char* commandNames[MAX_COMMANDS] = {
"monitor",
"getpid",
"setpid",
"getimu"
"getimu",
"setsetpoint",
"getsetpoint"
};
#endif
#endif /* __CLI_H */
\ No newline at end of file
#ifndef CLI_GETIMU_H
#define CLI_GETIMU_H
#ifndef __CLI_GETIMU_H
#define __CLI_GETIMU_H
#include "frontend_getimu.h"
int cli_getimu(struct backend_conn * conn, int argc, char ** argv);
#endif
\ No newline at end of file
#endif /* __CLI_GETIMU_H */
\ No newline at end of file
......@@ -43,17 +43,13 @@ int cli_getpid(struct backend_conn * conn, int argc, char **argv) {
}
if (needHelp) {
printf("Getpid gets the p, i , or d constant values of any single controller\n");
printf("Getpid gets the p, i , and 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;
}
......@@ -66,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;
}
}
......@@ -131,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;
}
......
#ifndef CLI_GETPID_H
#define CLI_GETPID_H
#ifndef __CLI_GETPID_H
#define __CLI_GETPID_H
#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
\ No newline at end of file
#endif /* __CLI_GETPID_H */
\ No newline at end of file
#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;
static int getpitch = 0, getroll = 0, getyaw = 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},
{"pitch", no_argument, &getpitch, 1},
{"roll", no_argument, &getroll, 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') {
getheight = 1;
getlat = 1;
getlong = 1;
getpitch = 1;
getroll = 1;
getyaw = 1;
}
}
if (needHelp) {
printf("Getsetpoint gets the height, lat, long, pitch, roll and yaw 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[-a] : Gets all of the following setpoints\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");
printf("\t[--pitch] : Gets the pitch setpoint\n");
printf("\t[--roll] : Gets the roll setpoint\n");
printf("\t[--yaw] : Gets the yaw 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;
}
}
if(getpitch) {
if ((result = getSetPointValues(conn, &setpoint_data, PITCH))) {
return result;
}
}
if(getroll) {
if ((result = getSetPointValues(conn, &setpoint_data, ROLL))) {
return result;
}
}
if(getyaw) {
if ((result = getSetPointValues(conn, &setpoint_data, YAW))) {
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);
case PITCH :
printf("Pitch: %f\n",
setpoint_data->pitch);
break;
case ROLL :
printf("Roll: %f\n",
setpoint_data->roll);
case YAW :
printf("Yaw: %f\n",
setpoint_data->yaw);
default :
break;
}
return 0;
}
#ifndef __CLI_GETSETPOINT_H
#define __CLI_GETSETPOINT_H
#include "frontend_getsetpoint.h"
enum {
HEIGHT,
LAT,
LONGG,
PITCH,
ROLL,
YAW
};
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
#ifndef CLI_MONITOR_H
#define CLI_MONITOR_H
#ifndef __CLI_MONITOR_H
#define __CLI_MONITOR_H
#include <time.h>
......@@ -11,4 +11,4 @@ int cli_monitor(struct backend_conn * conn, int argc, char **argv);
// Return 0 on success and 1 otherwise
int monitor(struct backend_conn * conn);
#endif
\ No newline at end of file
#endif /* __CLI_MONITOR_H */
\ No newline at end of file
#ifndef _CLI_SETPID_H
#define _CLI_SETPID_H
#ifndef __CLI_SETPID_H
#define __CLI_SETPID_H
#include "frontend_setpid.h"
int cli_setpid(struct backend_conn * conn, int argc, char ** argv);
#endif
#endif /* __CLI_SETPID_H */
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment