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

Fixed issues with cli and stringToCm function

parent d34bcf9e
No related branches found
No related tags found
No related merge requests found
......@@ -624,7 +624,6 @@ static void client_recv(int fd) {
break;
}
buffer[newline] = '\0';
printf("Client(%d) : '%s'\n",fd, buffer);
struct controller_message cm;
......@@ -668,7 +667,6 @@ static void client_recv(int fd) {
uint8_t data[128];
ssize_t result;
if (strncmp(buffer, "set", 3) == 0) {
result = EncodeSetparam(&m, data, 128, &cm);
} else if (strncmp(buffer, "get", 3) == 0) {
......@@ -696,6 +694,12 @@ static void client_recv(int fd) {
warnx("Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!\n");
}
}
// printf("packet = '");
// for(int i = 0; i < (int)psize; ++i) {
// printf(" %.2x ", packet[i]);
// }
// printf("'\n");
writeQuad(packet, psize);
......@@ -776,7 +780,6 @@ static void quad_recv() {
printf("(Backend): Command '%s' ignored\n", MessageTypes[m.msg_type].cmdText);
break;
case RESPPARAM_ID:
printf("(Backend): response param id found\n");
handleResponseParam(&m, data);
break;
default:
......
......@@ -108,20 +108,30 @@ const char * cmToString(int msgType, const struct controller_message *cm)
struct controller_message * stringToCm(const char * string, struct controller_message *cm)
{
char st[128];
strncpy(st, string, strlen(string));
size_t i;
int result;
size_t i;
char cmdString[strlen(string)];
strncpy(cmdString, string, strlen(string));
float cmdValue;
char * cmdString = strtok(st, " ");
cm->value = strtof(&string[strlen(cmdString)],NULL);
for (i = 0; i < strlen(string) + 1; ++i) {
if (string[i] == ' ' || string[i] == '\n' || string[i] == '\0') {
cmdString[i] = '\0';
break;
}
}
int index = -1;
for(i = 0; i < MAX_PARAM_COMMANDS; ++i) {
if((result = strncmp(cmdString, respParamStrings[i], strlen(respParamStrings[i]))) == 0) {
if((result = strncmp(cmdString, respParamStrings[i], strlen(respParamStrings[i]))) == 0 &&
strlen(cmdString) == strlen(respParamStrings[i])) {
index = i;
break;
} else if ((result = strncmp(cmdString, setParamStrings[i], strlen(setParamStrings[i]))) == 0) {
} else if ((result = strncmp(cmdString, setParamStrings[i], strlen(setParamStrings[i]))) == 0 &&
strlen(cmdString) == strlen(setParamStrings[i])) {
cm->value = strtof(&string[strlen(cmdString)],NULL);
index = i;
break;
}
......
......@@ -47,7 +47,6 @@ int DecodeGetparam(
return -1;
}
cm->id = data[CTRL_ID];
cm->value_id = data[CTRLVAL_ID];
......
......@@ -76,8 +76,6 @@ int main(int argc, char **argv)
needCommandHelp = 1;
}
}
printf("made it\n");
/**
* I the user has asked for help, and we have already found
......
......@@ -14,6 +14,7 @@
int rate = 10;
static int pidcounter = 0;
static int monitorcounter = 0;
int cli_monitor(struct backend_conn * conn, int argc, char **argv) {
int c, result;
......@@ -109,29 +110,42 @@ int monitor(struct backend_conn * conn) {
errx(1, "Error reading tracker data");
}
pid_data[pidcounter].controller = pidcounter;
if (frontend_getpid(conn, &pid_data[pidcounter % PID_NUM_PIDS])) {
errx(1, "Error reading pid values");
if (monitorcounter == 0) {
for(int i = 0; i < PID_NUM_PIDS; ++i) {
pid_data[i].controller = i;
if (frontend_getpid(conn, &pid_data[i])) {
errx(1, "Error reading pid values");
}
}
} else {
if ((monitorcounter % (rate * 5)) == 0) {
pid_data[pidcounter].controller = pidcounter;
if (frontend_getpid(conn, &pid_data[pidcounter])) {
errx(1, "Error reading pid values");
}
}
}
/* Print stuff on screen */
/* Assuming a tab width of 8 columns */
printf("\033[2J");
printf("STATUS: NA\n");
printf("CTRLR :\tP\tR\tY\tP_V\tR_V\tY_V\tH\tLAT\tLON\n");
printf(" P :\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\n",
printf("CTRLR : P R Y P_V R_V Y_V H LAT LON\n");
printf(" P :%10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf\n",
pid_data[0].p, pid_data[1].p, pid_data[2].p, pid_data[3].p, pid_data[4].p,
pid_data[5].p, pid_data[6].p, pid_data[7].p, pid_data[8].p);
printf(" I :\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\n",
printf(" I :%10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf\n",
pid_data[0].i, pid_data[1].i, pid_data[2].i, pid_data[3].i, pid_data[4].i,
pid_data[5].i, pid_data[6].i, pid_data[7].i, pid_data[8].i);
printf(" D :\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\n",
printf(" D :%10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf %10.3lf\n",
pid_data[0].d, pid_data[1].d, pid_data[2].d, pid_data[3].d, pid_data[4].d,
pid_data[5].d, pid_data[6].d, pid_data[7].d, pid_data[8].d);
printf("PosAtt:\tH\tLAT\tLON\tP\tR\tY\n");
printf(" :\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\t%6.3lf\n",
printf("PosAtt: H LAT LON P R Y\n");
printf(" :%10.3lf%10.3lf%10.3lf%10.3lf%10.3lf%10.3lf\n",
td.height, td.lateral, td.longitudinal,
td.pitch, td.roll, td.yaw);
pidcounter = ((pidcounter + 1) % PID_NUM_PIDS);
monitorcounter++;
pidcounter = ((pidcounter + 1) % PID_NUM_PIDS);
return 0;
}
}
\ No newline at end of file
......@@ -9,8 +9,8 @@ enum pid_controller {
PID_ROLL_RATE,
PID_YAW_RATE,
PID_HEIGHT, /* Z */
PID_LAT, /* X */
PID_LONG, /* Y */
PID_LAT, /* X */
PID_NUM_PIDS
};
......
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