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

changing to fit new command scheme

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