diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c index e0b8b843400b2b5c8bca0230eeb351b19dc5c60a..db4ec5d7380a793658809d7b6547c028a1272632 100644 --- a/groundStation/src/backend/backend.c +++ b/groundStation/src/backend/backend.c @@ -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: diff --git a/groundStation/src/backend/cmHandler.c b/groundStation/src/backend/cmHandler.c index 36946112118494137a2e31866255c6a16268ff39..062cae960abc4d87595fe6fba828f51fadcc8c2e 100644 --- a/groundStation/src/backend/cmHandler.c +++ b/groundStation/src/backend/cmHandler.c @@ -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; } diff --git a/groundStation/src/backend/getparam.c b/groundStation/src/backend/getparam.c index 34c90fa289f35361d49a8b6e1920581b81b3b2a3..98580741766e6187596c4519b6a8f3e2d1c0d3f5 100644 --- a/groundStation/src/backend/getparam.c +++ b/groundStation/src/backend/getparam.c @@ -47,7 +47,6 @@ int DecodeGetparam( return -1; } - cm->id = data[CTRL_ID]; cm->value_id = data[CTRLVAL_ID]; diff --git a/groundStation/src/cli/cli.c b/groundStation/src/cli/cli.c index 8eed2381b6a8440635adbce3a5dcf78460f05cde..acec4dbc6352ca971b84289eb24cfc918da98bbd 100644 --- a/groundStation/src/cli/cli.c +++ b/groundStation/src/cli/cli.c @@ -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 diff --git a/groundStation/src/cli/cli_monitor.c b/groundStation/src/cli/cli_monitor.c index 8242c45a0a2801599df2d30d948e3341179b8dda..b435b9117a7fb778047628c508f19c81ee73ee3e 100644 --- a/groundStation/src/cli/cli_monitor.c +++ b/groundStation/src/cli/cli_monitor.c @@ -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 diff --git a/groundStation/src/frontend/pid_common.h b/groundStation/src/frontend/pid_common.h index b89e3b1cddc85bb8820520e91ea4fa1858becd3a..87e61255fa45f995ff73b212ff076436497e9cca 100644 --- a/groundStation/src/frontend/pid_common.h +++ b/groundStation/src/frontend/pid_common.h @@ -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 };