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

changing to fit new command scheme

parent e62052cc
No related branches found
No related tags found
No related merge requests found
...@@ -6,13 +6,16 @@ ...@@ -6,13 +6,16 @@
int cli_set(struct backend_conn * conn, int argc, char **argv) { int cli_set(struct backend_conn * conn, int argc, char **argv) {
int c; int c;
static int setX = 0, setY = 0, setZ = 0; static int setheight = 0, setlat = 0, setlong = 0;
struct frontend_setpoint_data setpoint_data; struct frontend_setpoint_data setpoint_data;
static int needHelp = 0; static int needHelp = 0;
static int mask; static int mask;
static struct option long_options[] = { static struct option long_options[] = {
/* These options don’t set a flag. We distinguish them by their indices. */ /* These options don’t set a flag. We distinguish them by their indices. */
{"help", no_argument, &needHelp, 1}, {"help", no_argument, &needHelp, 1},
{"height", required_argument, 0, 'h'},
{"long", required_argument, 0, 't'},
{"lat", required_argument, 0, 'l'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
...@@ -21,28 +24,29 @@ int cli_set(struct backend_conn * conn, int argc, char **argv) { ...@@ -21,28 +24,29 @@ int cli_set(struct backend_conn * conn, int argc, char **argv) {
/* getopt_long stores the option index here. */ /* getopt_long stores the option index here. */
int option_index = 0; int option_index = 0;
c = getopt_long(argc, argv, "x:y:z:", long_options, &option_index); c = getopt_long(argc, argv, "", long_options, &option_index);
/* Detect the end of the options. */ /* Detect the end of the options. */
if (c == -1) if (c == -1)
break; break;
switch(c) { switch(c) {
case 'x' : case 'h' :
setpoint_data.x = atof(optarg); setpoint_data.height = atof(optarg);
mask |= SET_X; mask |= SET_HEIGHT;
break; break;
case 'y' : case 't' :
setpoint_data.y = atof(optarg); setpoint_data.lat = atof(optarg);
mask |= SET_Y; mask |= SET_LAT;
break; break;
case 'z' : case 'l' :
setpoint_data.z = atof(optarg); setpoint_data.longg = atof(optarg);
mask |= SET_Z; mask |= SET_LONG;
break; break;
default : default :
break; break;
} }
} }
if (needHelp) { if (needHelp) {
......
...@@ -16,26 +16,26 @@ int frontend_setsetpoint( ...@@ -16,26 +16,26 @@ int frontend_setsetpoint(
char buffer[2048]; char buffer[2048];
/* Set the P, I, and D */ /* Set the P, I, and D */
if (mask & SET_X) { if (mask & SET_HEIGHT) {
if (snprintf(buffer, 2048, if (snprintf(buffer, 2048,
"setsetpointx %f\n", "setheight %f\n",
setpoint_data->x) >= 2048) { setpoint_data->height) >= 2048) {
errx(0, "Buffer to small to format!"); errx(0, "Buffer to small to format!");
} }
ucart_backendWrite(conn, buffer); ucart_backendWrite(conn, buffer);
} }
if (mask & SET_Y) { if (mask & SET_LAT) {
if (snprintf(buffer, 2048, if (snprintf(buffer, 2048,
"setsetpointy %f\n", "setlat %f\n",
setpoint_data->y) >= 2048) { setpoint_data->lat) >= 2048) {
errx(0, "Buffer to small to format!"); errx(0, "Buffer to small to format!");
} }
ucart_backendWrite(conn, buffer); ucart_backendWrite(conn, buffer);
} }
if (mask & SET_Z) { if (mask & SET_LONG) {
if (snprintf(buffer, 2048, if (snprintf(buffer, 2048,
"setsetpointz %f\n", "setlong %f\n",
setpoint_data->z) >= 2048) { setpoint_data->longg) >= 2048) {
errx(0, "Buffer to small to format!"); errx(0, "Buffer to small to format!");
} }
ucart_backendWrite(conn, buffer); ucart_backendWrite(conn, buffer);
......
...@@ -9,12 +9,12 @@ int frontend_setsetpoint( ...@@ -9,12 +9,12 @@ int frontend_setsetpoint(
struct frontend_setpoint_data * setpoint_data, struct frontend_setpoint_data * setpoint_data,
int mask); int mask);
#define SET_X 0x01 #define SET_LAT 0x01
#define SET_Y 0x02 #define SET_LONG 0x02
#define SET_Z 0x04 #define SET_HEIGHT 0x04
#ifndef SET_ALL #ifndef SET_ALL
#define SET_ALL (SET_X | SET_Y | SET_Z) #define SET_ALL (SET_LAT | SET_LONG | SET_HEIGHT)
#endif /* SET_ALL */ #endif /* SET_ALL */
#endif /* FRONTEND_SETSETPOINT_H */ #endif /* FRONTEND_SETSETPOINT_H */
\ No newline at end of file
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
#define SETPOINT_COMMON_H #define SETPOINT_COMMON_H
struct frontend_setpoint_data { struct frontend_setpoint_data {
float x; float height;
float y; float lat;
float z; /* names with two g's due to long type name */
float longg;
}; };
......
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