Skip to content
Snippets Groups Projects
Unverified Commit 0a0dabdd authored by Jake Drahos's avatar Jake Drahos
Browse files

Merge remote-tracking branch 'origin/groundStation-dev-cli-setpoint' into new-commands

parents 2bf6d5da 3a4911d8
No related branches found
No related tags found
1 merge request!2WIP: use a circular buffer
...@@ -23,7 +23,7 @@ CLIBINARY=Cli ...@@ -23,7 +23,7 @@ CLIBINARY=Cli
CLISRCDIR=src/cli CLISRCDIR=src/cli
CLISOURCES := $(wildcard $(CLISRCDIR)/*.c) CLISOURCES := $(wildcard $(CLISRCDIR)/*.c)
CLIOBJECTS = $(CLISOURCES:$(CLISRCDIR)/%.c=$(OBJDIR)/%.o) CLIOBJECTS = $(CLISOURCES:$(CLISRCDIR)/%.c=$(OBJDIR)/%.o)
SYMLINKS=monitor setpid getpid SYMLINKS=monitor setpid getpid setsetpoint
# Frontend-common stuff # Frontend-common stuff
FESRCDIR=src/frontend FESRCDIR=src/frontend
......
#ifndef __CLI_H #ifndef __CLI_H
#define __CLI_H #define __CLI_H
#include "cli_setsetpoint.h"
#include "cli_monitor.h" #include "cli_monitor.h"
#include "cli_setpid.h" #include "cli_setpid.h"
#include "cli_getpid.h" #include "cli_getpid.h"
...@@ -11,6 +12,7 @@ enum CommandNameIds{ ...@@ -11,6 +12,7 @@ enum CommandNameIds{
CMD_GETPID, CMD_GETPID,
CMD_SETPID, CMD_SETPID,
CMD_GETIMU, CMD_GETIMU,
CMD_SETSETPOINT,
MAX_COMMANDS MAX_COMMANDS
}; };
...@@ -19,13 +21,16 @@ static cli_function_ptr cli_functions[] = { ...@@ -19,13 +21,16 @@ static cli_function_ptr cli_functions[] = {
&cli_monitor, &cli_monitor,
&cli_getpid, &cli_getpid,
&cli_setpid, &cli_setpid,
&cli_getimu &cli_getimu,
&cli_setsetpoint
}; };
static char* commandNames[MAX_COMMANDS] = { static char* commandNames[MAX_COMMANDS] = {
"monitor", "monitor",
"getpid", "getpid",
"setpid", "setpid",
"getimu" "getimu",
"setsetpoint"
}; };
#endif #endif
#ifndef _CLI_SETPID_H #ifndef CLI_SETPID_H
#define _CLI_SETPID_H #define CLI_SETPID_H
#include "frontend_setpid.h" #include "frontend_setpid.h"
......
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include "cli_setsetpoint.h"
int cli_set(struct backend_conn * conn, int argc, char **argv) {
int c;
static int setX = 0, setY = 0, setZ = 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},
{0, 0, 0, 0}
};
while (1)
{
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long(argc, argv, "x:y:z:", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
break;
switch(c) {
case 'x' :
setpoint_data.x = atof(optarg);
mask |= SET_X;
break;
case 'y' :
setpoint_data.y = atof(optarg);
mask |= SET_Y;
break;
case 'z' :
setpoint_data.z = atof(optarg);
mask |= SET_Z;
break;
default :
break;
}
}
if (needHelp) {
printf("Setsetpoint sets the x, y , or z 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");
return 0;
}
if (argc < 2) {
printf("Incorrect Usage, run './cli setpid --help' for correct usage.\n");
return 1;
}
frontend_setsetpoint(conn, &setpoint_data, mask);
return 0;
}
#ifndef CLI_SETSETPOINT_H
#define CLI_SETSETPOINT_H
#include "frontend_setsetpoint.h"
int cli_setsetpoint(struct backend_conn * conn, int argc, char ** argv);
#endif /* CLI_SETSETPOINT_H */
#ifndef _FRONTEND_SETPID_H #ifndef FRONTEND_SETPID_H
#define _FRONTEND_SETPID_H #define FRONTEND_SETPID_H
#include "pid_common.h" #include "pid_common.h"
#include "frontend_common.h" #include "frontend_common.h"
...@@ -12,6 +12,9 @@ int frontend_setpid( ...@@ -12,6 +12,9 @@ int frontend_setpid(
#define SET_P 0x01 #define SET_P 0x01
#define SET_I 0x02 #define SET_I 0x02
#define SET_D 0x04 #define SET_D 0x04
#ifndef SET_ALL
#define SET_ALL (SET_P | SET_I | SET_D) #define SET_ALL (SET_P | SET_I | SET_D)
#endif /* SET_ALL */
#endif #endif /* FRONTEND_SETPID_H */
\ No newline at end of file
#include <err.h>
#include <stdio.h>
#include "frontend_setsetpoint.h"
#include "setpoint_common.h"
#include "frontend_common.h"
int frontend_setsetpoint(
struct backend_conn * conn,
struct frontend_setpoint_data * setpoint_data,
int mask)
{
if (conn == NULL) {
return -1;
}
char buffer[2048];
/* Set the P, I, and D */
if (mask & SET_X) {
if (snprintf(buffer, 2048,
"setsetpointx %f\n",
setpoint_data->x) >= 2048) {
errx(0, "Buffer to small to format!");
}
ucart_backendWrite(conn, buffer);
}
if (mask & SET_Y) {
if (snprintf(buffer, 2048,
"setsetpointy %f\n",
setpoint_data->y) >= 2048) {
errx(0, "Buffer to small to format!");
}
ucart_backendWrite(conn, buffer);
}
if (mask & SET_Z) {
if (snprintf(buffer, 2048,
"setsetpointz %f\n",
setpoint_data->z) >= 2048) {
errx(0, "Buffer to small to format!");
}
ucart_backendWrite(conn, buffer);
}
return 0;
}
#ifndef FRONTEND_SETSETPOINT_H
#define FRONTEND_SETSETPOINT_H
#include "setpoint_common.h"
#include "frontend_common.h"
int frontend_setsetpoint(
struct backend_conn * conn,
struct frontend_setpoint_data * setpoint_data,
int mask);
#define SET_X 0x01
#define SET_Y 0x02
#define SET_Z 0x04
#ifndef SET_ALL
#define SET_ALL (SET_X | SET_Y | SET_Z)
#endif /* SET_ALL */
#endif /* FRONTEND_SETSETPOINT_H */
\ No newline at end of file
#ifndef SETPOINT_COMMON_H
#define SETPOINT_COMMON_H
struct frontend_setpoint_data {
float x;
float y;
float z;
};
#endif /* SETPOINT_COMMON_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