diff --git a/groundStation/.gitignore b/groundStation/.gitignore index 508a8f243429591a76f612c87353c847358052e0..3c404365ac685a5329202185291efb21aefa35b1 100644 --- a/groundStation/.gitignore +++ b/groundStation/.gitignore @@ -42,3 +42,10 @@ logs BackEnd obj Cli + +#symlinks +getpid +monitor +setpid +setsetpoint +getsetpoint diff --git a/groundStation/Makefile b/groundStation/Makefile index 32c9062ef683a66deef45a0cf04334bf016d9e17..052f6bf8af89e079a93dd4c77711609316aead99 100644 --- a/groundStation/Makefile +++ b/groundStation/Makefile @@ -23,7 +23,7 @@ CLIBINARY=Cli CLISRCDIR=src/cli CLISOURCES := $(wildcard $(CLISRCDIR)/*.c) CLIOBJECTS = $(CLISOURCES:$(CLISRCDIR)/%.c=$(OBJDIR)/%.o) -SYMLINKS=monitor setpid getpid setsetpoint +SYMLINKS=monitor setpid getpid setsetpoint getsetpoint # Frontend-common stuff FESRCDIR=src/frontend diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c index f521cf732807359df10b4e607111c360d9f26a0d..7efcbc855495ddda5661de6627d3b005372cfd79 100644 --- a/groundStation/src/backend/backend.c +++ b/groundStation/src/backend/backend.c @@ -195,7 +195,6 @@ int main(int argc, char **argv) perror("Error creating log file..."); exit(1); } - // writeStringToLog(logHeader); // watch for input from stdin (fd 0) to see when it has input safe_fd_set(fileno(stdin), &rfds_master, &max_fd); @@ -328,8 +327,8 @@ void sendVrpnPacket(struct ucart_vrpn_TrackerData *info) { memcpy(&packet[11], &(info->y), 4); memcpy(&packet[15], &(info->x), 4); memcpy(&packet[19], &(info->z), 4); - memcpy(&packet[23], &(info->pitch), 4); - memcpy(&packet[27], &(info->roll), 4); + memcpy(&packet[23], &(info->roll), 4); + memcpy(&packet[27], &(info->pitch), 4); memcpy(&packet[31], &(info->yaw), 4); char checksum = 0; @@ -482,6 +481,9 @@ static ssize_t writeQuad(const char * buf, size_t count) { static ssize_t readQuad(char * buf, size_t count) { ssize_t retval; + if (getenv(NOQUAD_ENV)) { + return count; + } if (pthread_mutex_lock(&quadSocketMutex)) { err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); } @@ -626,7 +628,7 @@ static void client_recv(int fd) { if (tracker == NULL) { char * dummy = TD_MAGIC " 1.0 2.0 3.0 4.0 5.0 6.0\n"; write(fd, dummy, strlen(dummy)); - }else if (ucart_vrpn_tracker_getData(tracker, &td)) { + } else if (ucart_vrpn_tracker_getData(tracker, &td)) { write(fd, TD_MAGIC " ERROR\n", strlen(TD_MAGIC " ERROR\n")); } else { /* more than sufficient buffer */ @@ -651,17 +653,19 @@ static void client_recv(int fd) { } } } else { - if(clientAddPendResponses(fd, packet) == -1) { - warnx("Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!\n"); - } else { - int datalen = (packet[6] << 8) | (packet[5]); - printf("sending %lf '", getFloat(packet, 7)); - for(int i = 0; i < datalen + 8; ++i) { - printf(" 0x%x", (signed) packet[i]); + if (packet[1] == 0x02) { + if (clientAddPendResponses(fd, packet) == -1) { + warnx("Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!\n"); } - printf("'\n"); - writeQuad((char *) packet, datalen +8); } + + int datalen = (packet[6] << 8) | (packet[5]); + printf("sending %lf '", getFloat(packet, 7)); + for(int i = 0; i < datalen + 8; ++i) { + printf(" 0x%.2x", (signed) packet[i]); + } + printf("'\n"); + writeQuad((char *) packet, datalen +8); } char * rest = &buffer[newline] + 1; @@ -707,17 +711,23 @@ static void quad_recv() { respBufLen = 0; return; } - + /* Get datalen */ size_t datalen = metadata.data_len; + if (respBufLen < datalen + 8) { + /* Packet not yet fully read */ + return; + } + if (datalen > CMD_MAX_LENGTH - 8) { /* Very invalid packet. Nuke that shit */ + warnx("data len is over the maximum packet length. Try reducing the data in the packet sent to the groundstation.\n"); respBufLen = 0; return; } - - if (respBufLen < datalen + 8) { - /* Packet not yet fully read */ + + if(validPacket == -2) { + fprintf(stderr, "Checksums did not match (Parse Packet)\n"); return; } @@ -726,10 +736,18 @@ static void quad_recv() { char * cmdText = MessageTypes[(int)metadata.msg_type].subtypes[(int)metadata.msg_subtype].cmdText; float value = getFloat((unsigned char *)respBuf, 7); //printf("Quad : %s, %lf\n", cmdText, value); + /* Assuming the quad sends the correct info.. This hasn't been tested yet due to a lack of quad software. We can check how to format by the cmdText and pass to every client. */ + if(strncmp(cmdText, "log", strlen(cmdText)) == 0) { + char log_text[datalen+1]; + strncpy(log_text, (char *) data, datalen); + log_text[datalen] = '\0'; + printf("log='%s'\n", log_text); + } + char buffer[1048]; sprintf(buffer, "%s %lf\n", cmdText, value); @@ -738,8 +756,6 @@ static void quad_recv() { write(fd, buffer, datalen + 8); } } - } else { - warnx("Checksum mismatch!"); } memmove(respBuf, respBuf + datalen + 8, respBufLen - (datalen + 8)); respBufLen -= datalen + 8; diff --git a/groundStation/src/backend/callbacks.h b/groundStation/src/backend/callbacks.h index 57d6fbbbbab784744714340ddc943ee3a91dccf2..d04d4fda5dd8c23a2df61cc00594755652a14f89 100644 --- a/groundStation/src/backend/callbacks.h +++ b/groundStation/src/backend/callbacks.h @@ -1,5 +1,5 @@ -#ifndef __callbacks_h -#define __callbacks_h +#ifndef __CALLBACKS_H +#define __CALLBACKS_H /* Grab some stupid stuff from legacy code */ #include "type_def.h" @@ -8,4 +8,4 @@ typedef void (command_cb)(unsigned char *command, int dataLen, modular_structs_t *structs); -#endif +#endif /* __CALLBACKS_H */ diff --git a/groundStation/src/backend/cb_default.h b/groundStation/src/backend/cb_default.h index 2deeb4756b3d708ed617209330fab36f5d1c208b..45485767cc34d1619090014bc2f1428f146b1c71 100644 --- a/groundStation/src/backend/cb_default.h +++ b/groundStation/src/backend/cb_default.h @@ -1,3 +1,6 @@ +#ifndef __CB_DEFAULT_H +#define __CB_DEFAULT_H + #include "commands.h" /* The cb_default used on the groundStation. This file MUST NOT BE INCLUDED @@ -8,3 +11,5 @@ int cb_default(unsigned char * command, int dataLen, modular_structs_t *structs) { return 0; } + +#endif /* __CB_DEFAULT_H */ \ No newline at end of file diff --git a/groundStation/src/backend/commands.h b/groundStation/src/backend/commands.h index 9e57ae11a5b9ddf114114e22894e147c6667fb44..30935eb44d3aced5ba2ac0b949447a14fd4d839b 100644 --- a/groundStation/src/backend/commands.h +++ b/groundStation/src/backend/commands.h @@ -1,5 +1,5 @@ -#ifndef _COMMANDS_H -#define _COMMANDS_H +#ifndef __COMMANDS_H +#define __COMMANDS_H #include <stdio.h> #include <stdlib.h> @@ -48,4 +48,4 @@ float getFloat(unsigned char* str, int pos); int getInt(unsigned char* str, int pos); /* end legacy crap */ -#endif +#endif /* __COMMANDS_H */ \ No newline at end of file diff --git a/groundStation/src/backend/communication.c b/groundStation/src/backend/communication.c index 19ea73ae4cf7c8f7f8a35bf8b316bf28e19e7903..ca4e82632ce36c0b381eb3dd49c42777cdd84942 100644 --- a/groundStation/src/backend/communication.c +++ b/groundStation/src/backend/communication.c @@ -177,7 +177,7 @@ int formatPacket(metadata_t *metadata, void *data, unsigned char **formattedComm // Checksum // receive data and calculate checksum int i; - char data_checksum; + char data_checksum = 0; for(i = 0; i < 7 + metadata->data_len; i++) { data_checksum ^= (*formattedCommand)[i]; @@ -230,14 +230,13 @@ int parse_packet(unsigned char * packet, unsigned char ** data, metadata_t * met // calculate checksum unsigned char calculated_checksum = 0; - for(i = 0; i < meta_data->data_len + 7; i++) + for(i = 0; i < meta_data->data_len + 7 - 1; i++) { calculated_checksum ^= packet[i]; } // compare checksum if(packet_checksum != calculated_checksum) { - fprintf(stderr, "Checksums did not match (Parse Packet): 0x%02x\t0x%02x\n", packet_checksum, calculated_checksum); return -2; } diff --git a/groundStation/src/backend/communication.h b/groundStation/src/backend/communication.h index 746b9f5d45ce9199588ff45b58f5bdaa5d669ad3..364814e3674b25a868e5e516e0bc626dd976b295 100644 --- a/groundStation/src/backend/communication.h +++ b/groundStation/src/backend/communication.h @@ -1,5 +1,5 @@ -#ifndef _COMMUNICATION_H -#define _COMMUNICATION_H +#ifndef __COMMUNICATION_H +#define __COMMUNICATION_H #include <stdio.h> #include <string.h> @@ -16,4 +16,4 @@ int parse_packet(unsigned char * packet, unsigned char ** data, metadata_t * met int processCommand(unsigned char *command, modular_structs_t *structs); int logData(unsigned char *log_msg, unsigned char *formattedCommand); -#endif \ No newline at end of file +#endif /* __COMMUNICATION_H */ \ No newline at end of file diff --git a/groundStation/src/backend/config.h b/groundStation/src/backend/config.h index bf88e6e2b7cf09db273dba3ecc5bcf3cee7d2211..64691610dbfd8282fec14d3706db4219e06dfbc1 100644 --- a/groundStation/src/backend/config.h +++ b/groundStation/src/backend/config.h @@ -17,4 +17,4 @@ #define QUAD_PORT_ENV "UCART_QUAD_PORT" #define QUAD_PORT_DEFAULT 8080 -#endif +#endif /* __CONFIG_H */ \ No newline at end of file diff --git a/groundStation/src/backend/logger.h b/groundStation/src/backend/logger.h index edfb365ffce6606e7b5bd8d1f4305c5f697180a9..9bbd068116482e4d693fdb519f27dffd7bc2fff7 100644 --- a/groundStation/src/backend/logger.h +++ b/groundStation/src/backend/logger.h @@ -2,8 +2,8 @@ * * Logger header file for holding info pertaining to loging to a file. */ -#ifndef _LOGGER_H -#define _LOGGER_H +#ifndef __LOGGER_H +#define __LOGGER_H #include <fcntl.h> #include <time.h> @@ -18,4 +18,4 @@ int updateLogFile(const struct ucart_vrpn_TrackerData* ); void closeLogFile(); -#endif +#endif /* __LOGGER_H */ \ No newline at end of file diff --git a/groundStation/src/backend/type_def.h b/groundStation/src/backend/type_def.h index 55dca9e8fb27c26397b00961b7dbec8bbe0d4136..2a2b8249a4c62cb035a38a6c4b6f3abfe96edd89 100644 --- a/groundStation/src/backend/type_def.h +++ b/groundStation/src/backend/type_def.h @@ -5,8 +5,8 @@ * Author: ucart */ -#ifndef TYPE_DEF_H_ -#define TYPE_DEF_H_ +#ifndef __TYPE_DEF_H +#define __TYPE_DEF_H /** * @brief @@ -358,4 +358,4 @@ typedef struct { //////// END MAIN MODULAR STRUCTS -#endif /* TYPE_DEF_H_ */ +#endif /* __TYPE_DEF_H */ diff --git a/groundStation/src/cli/cli.c b/groundStation/src/cli/cli.c index acec4dbc6352ca971b84289eb24cfc918da98bbd..8eed2381b6a8440635adbce3a5dcf78460f05cde 100644 --- a/groundStation/src/cli/cli.c +++ b/groundStation/src/cli/cli.c @@ -76,6 +76,8 @@ 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.h b/groundStation/src/cli/cli.h index 1d0cf6951488872906ac99447fda3b7b5e9e5b7c..e82bd5cda7e1d31d2aa31dffee2ac30a2fa372f1 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -2,6 +2,7 @@ #define __CLI_H #include "cli_setsetpoint.h" +#include "cli_getsetpoint.h" #include "cli_monitor.h" #include "cli_setpid.h" #include "cli_getpid.h" @@ -13,6 +14,7 @@ enum CommandNameIds{ CMD_SETPID, CMD_GETIMU, CMD_SETSETPOINT, + CMD_GETSETPOINT, MAX_COMMANDS }; @@ -22,7 +24,8 @@ static cli_function_ptr cli_functions[] = { &cli_getpid, &cli_setpid, &cli_getimu, - &cli_setsetpoint + &cli_setsetpoint, + &cli_getsetpoint }; static char* commandNames[MAX_COMMANDS] = { @@ -30,7 +33,8 @@ static char* commandNames[MAX_COMMANDS] = { "getpid", "setpid", "getimu", - "setsetpoint" + "setsetpoint", + "getsetpoint" }; -#endif +#endif /* __CLI_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_getimu.h b/groundStation/src/cli/cli_getimu.h index 59089a01722683324edd00e8811d4ac9876143e8..2535f1ae87dfba4cb616adb0aa72e686c2cd4fe7 100644 --- a/groundStation/src/cli/cli_getimu.h +++ b/groundStation/src/cli/cli_getimu.h @@ -1,8 +1,8 @@ -#ifndef CLI_GETIMU_H -#define CLI_GETIMU_H +#ifndef __CLI_GETIMU_H +#define __CLI_GETIMU_H #include "frontend_getimu.h" int cli_getimu(struct backend_conn * conn, int argc, char ** argv); -#endif \ No newline at end of file +#endif /* __CLI_GETIMU_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_getpid.c b/groundStation/src/cli/cli_getpid.c index 48c1e72055601df9b66e96ec1c2a3917c1f0fc15..4bf634e3e2e966ea59ac54d8510c3607815f462d 100644 --- a/groundStation/src/cli/cli_getpid.c +++ b/groundStation/src/cli/cli_getpid.c @@ -62,62 +62,62 @@ int cli_getpid(struct backend_conn * conn, int argc, char **argv) { if(getAll) { for(int i = 0; i < PID_NUM_PIDS; ++i) { pid_data.controller = i; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } } else { if(getPitch) { pid_data.controller = PID_PITCH; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getRoll) { pid_data.controller = PID_ROLL; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getYaw) { pid_data.controller = PID_YAW; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getPitchV) { pid_data.controller = PID_PITCH_RATE; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getRollV) { pid_data.controller = PID_ROLL_RATE; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getYawV) { pid_data.controller = PID_YAW_RATE; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getHeight) { pid_data.controller = PID_HEIGHT; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getLat) { pid_data.controller = PID_LAT; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } if(getLong) { pid_data.controller = PID_LONG; - if ((result = getValues(conn, &pid_data))) { + if ((result = getPidValues(conn, &pid_data))) { return result; } } @@ -127,7 +127,7 @@ int cli_getpid(struct backend_conn * conn, int argc, char **argv) { return 0; } -int getValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) { +int getPidValues(struct backend_conn * conn, struct frontend_pid_data * pid_data) { if(frontend_getpid(conn, pid_data)) { return 1; } diff --git a/groundStation/src/cli/cli_getpid.h b/groundStation/src/cli/cli_getpid.h index f5c0b15e4a2f2c7c5ad605a389b0c1b52a1344a6..799681f06d114602083e304f2cba321891155fbc 100644 --- a/groundStation/src/cli/cli_getpid.h +++ b/groundStation/src/cli/cli_getpid.h @@ -1,9 +1,9 @@ -#ifndef CLI_GETPID_H -#define CLI_GETPID_H +#ifndef __CLI_GETPID_H +#define __CLI_GETPID_H #include "frontend_getpid.h" -int getValues(struct backend_conn *, struct frontend_pid_data *); +int getPidValues(struct backend_conn *, struct frontend_pid_data *); int cli_getpid(struct backend_conn * conn, int argc, char ** argv); -#endif \ No newline at end of file +#endif /* __CLI_GETPID_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_getsetpoint.c b/groundStation/src/cli/cli_getsetpoint.c new file mode 100644 index 0000000000000000000000000000000000000000..be9766139e002fb2687bab6fc76a54bb8d96b29b --- /dev/null +++ b/groundStation/src/cli/cli_getsetpoint.c @@ -0,0 +1,131 @@ +#include <stdio.h> +#include <unistd.h> +#include <getopt.h> + +#include "cli_getsetpoint.h" + +int cli_getsetpoint(struct backend_conn * conn, int argc, char **argv) { + int c; + static int getheight = 0, getlat = 0, getlong = 0; + static int getpitch = 0, getroll = 0, getyaw = 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", no_argument, &getheight, 1}, + {"long", no_argument, &getlong, 1}, + {"lat", no_argument, &getlat, 1}, + {"pitch", no_argument, &getpitch, 1}, + {"roll", no_argument, &getroll, 1}, + {"yaw", no_argument, &getyaw, 1}, + {0, 0, 0, 0} + }; + + while (1) + { + /* getopt_long stores the option index here. */ + int option_index = 0; + + c = getopt_long(argc, argv, "a", long_options, &option_index); + + /* Detect the end of the options. */ + if (c == -1) + break; + + if (c == 'a') { + getheight = 1; + getlat = 1; + getlong = 1; + getpitch = 1; + getroll = 1; + getyaw = 1; + } + } + + if (needHelp) { + printf("Getsetpoint gets the height, lat, long, pitch, roll and yaw set point values for the quad.\n"); + printf("Usage Syntax : \n\t./Cli getsetpoint [options...]\n"); + printf("Symlink Usage Syntax : \n\t./getsetpoint [options...]\n\n"); + printf("Available options include the following\n"); + printf("\t[-a] : Gets all of the following setpoints\n"); + printf("\t[--height] : Gets the height setpoint\n"); + printf("\t[--lat] : Gets the latitude setpoint\n"); + printf("\t[--long] : Gets the longitude setpoint\n"); + printf("\t[--pitch] : Gets the pitch setpoint\n"); + printf("\t[--roll] : Gets the roll setpoint\n"); + printf("\t[--yaw] : Gets the yaw setpoint\n"); + return 0; + } + + if (argc < 2) { + printf("Incorrect Usage, run './cli getsetpoint --help' for correct usage.\n"); + return 1; + } + int result; + if(getheight) { + if ((result = getSetPointValues(conn, &setpoint_data, HEIGHT))) { + return result; + } + } + if(getlat) { + if ((result = getSetPointValues(conn, &setpoint_data, LAT))) { + return result; + } + } + if(getlong) { + if ((result = getSetPointValues(conn, &setpoint_data, LONGG))) { + return result; + } + } + if(getpitch) { + if ((result = getSetPointValues(conn, &setpoint_data, PITCH))) { + return result; + } + } + if(getroll) { + if ((result = getSetPointValues(conn, &setpoint_data, ROLL))) { + return result; + } + } + if(getyaw) { + if ((result = getSetPointValues(conn, &setpoint_data, YAW))) { + return result; + } + } + + return 0; +} + +int getSetPointValues(struct backend_conn * conn, struct frontend_setpoint_data * setpoint_data, int type) { + if(frontend_getsetpoint(conn, setpoint_data, type)) { + return 1; + } + + switch(type) { + case HEIGHT : + printf("Height: %f\n", + setpoint_data->height); + break; + case LAT : + printf("Latitude: %f\n", + setpoint_data->lat); + case LONGG : + printf("Longitude: %f\n", + setpoint_data->longg); + case PITCH : + printf("Pitch: %f\n", + setpoint_data->pitch); + break; + case ROLL : + printf("Roll: %f\n", + setpoint_data->roll); + case YAW : + printf("Yaw: %f\n", + setpoint_data->yaw); + default : + break; + } + return 0; +} diff --git a/groundStation/src/cli/cli_getsetpoint.h b/groundStation/src/cli/cli_getsetpoint.h new file mode 100644 index 0000000000000000000000000000000000000000..a852b37973c84b21ca985e89dbb90180f35907ba --- /dev/null +++ b/groundStation/src/cli/cli_getsetpoint.h @@ -0,0 +1,18 @@ +#ifndef __CLI_GETSETPOINT_H +#define __CLI_GETSETPOINT_H + +#include "frontend_getsetpoint.h" + +enum { + HEIGHT, + LAT, + LONGG, + PITCH, + ROLL, + YAW +}; + +int getSetPointValues(struct backend_conn *, struct frontend_setpoint_data *, int type); +int cli_getsetpoint(struct backend_conn * conn, int argc, char ** argv); + +#endif /* __CLI_GETSETPOINT_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_monitor.h b/groundStation/src/cli/cli_monitor.h index 308721bb89f177da345269971a8d63b32d9dc39c..694323739001d0b0e1b820c37b87ff95362f27e5 100644 --- a/groundStation/src/cli/cli_monitor.h +++ b/groundStation/src/cli/cli_monitor.h @@ -1,5 +1,5 @@ -#ifndef CLI_MONITOR_H -#define CLI_MONITOR_H +#ifndef __CLI_MONITOR_H +#define __CLI_MONITOR_H #include <time.h> @@ -11,4 +11,4 @@ int cli_monitor(struct backend_conn * conn, int argc, char **argv); // Return 0 on success and 1 otherwise int monitor(struct backend_conn * conn); -#endif \ No newline at end of file +#endif /* __CLI_MONITOR_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_setpid.h b/groundStation/src/cli/cli_setpid.h index 2ebdc9545e38f9f3d3697b02b22b8b1be2ef324e..d78fcc07042d7d571f35940f798493a5c8cb1c88 100644 --- a/groundStation/src/cli/cli_setpid.h +++ b/groundStation/src/cli/cli_setpid.h @@ -1,8 +1,8 @@ -#ifndef CLI_SETPID_H -#define CLI_SETPID_H +#ifndef __CLI_SETPID_H +#define __CLI_SETPID_H #include "frontend_setpid.h" int cli_setpid(struct backend_conn * conn, int argc, char ** argv); -#endif +#endif /* __CLI_SETPID_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_setsetpoint.c b/groundStation/src/cli/cli_setsetpoint.c index 85cd86d164712e0a83ef7bdc64bd1b50a0ffeee3..e0c43814ff98b2e5326b2d6feb0e14fa468d9032 100644 --- a/groundStation/src/cli/cli_setsetpoint.c +++ b/groundStation/src/cli/cli_setsetpoint.c @@ -4,15 +4,22 @@ #include "cli_setsetpoint.h" -int cli_set(struct backend_conn * conn, int argc, char **argv) { +int cli_setsetpoint(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; + static int setpitch = 0, setroll = 0, setyaw = 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}, + {"help", no_argument, &needHelp, 1}, + {"height", required_argument, 0, 'h'}, + {"long", required_argument, 0, 'l'}, + {"lat", required_argument, 0, 't'}, + {"pitch", required_argument, 0, 'p'}, + {"roll", required_argument, 0, 'r'}, + {"yaw", required_argument, 0, 'y'}, {0, 0, 0, 0} }; @@ -21,38 +28,54 @@ 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 'l' : + setpoint_data.longg = atof(optarg); + mask |= SET_LONG; + break; + case 'p' : + setpoint_data.pitch = atof(optarg); + mask |= SET_PITCH; break; - case 'z' : - setpoint_data.z = atof(optarg); - mask |= SET_Z; + case 'r' : + setpoint_data.roll = atof(optarg); + mask |= SET_ROLL; + break; + case 'y' : + setpoint_data.yaw = atof(optarg); + mask |= SET_YAW; break; default : break; } + } if (needHelp) { - printf("Setsetpoint sets the x, y , or z set point values for the quad.\n"); + printf("Setsetpoint sets the height, lat, long, pitch, roll, or yaw 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"); + printf("\t[--height] 'val' : Sets the height setpoint value to 'val'\n"); + printf("\t[--lat] 'val' : Sets the latitude setpoint value to 'val'\n"); + printf("\t[--long] 'val' : Sets the longitude setpoint value to 'val'\n"); + printf("\t[--pitch] 'val' : Sets the pitch setpoint value to 'val'\n"); + printf("\t[--roll] 'val' : Sets the roll setpoint value to 'val'\n"); + printf("\t[--yaw] 'val' : Sets the yaw setpoint value to 'val'\n"); return 0; } diff --git a/groundStation/src/cli/cli_setsetpoint.h b/groundStation/src/cli/cli_setsetpoint.h index 8f2657963222181f4fcf7e20fae9242d84b37b95..514145a9485733276fb1982418f5a44747103e74 100644 --- a/groundStation/src/cli/cli_setsetpoint.h +++ b/groundStation/src/cli/cli_setsetpoint.h @@ -1,8 +1,8 @@ -#ifndef CLI_SETSETPOINT_H -#define CLI_SETSETPOINT_H +#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 */ +#endif /* __CLI_SETSETPOINT_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_common.c b/groundStation/src/frontend/frontend_common.c index cbedbe42a6dcbed1622f2109d833a75a1ce6d7ba..e71bc425e28aaa8514474e6df7cc078b46261e24 100644 --- a/groundStation/src/frontend/frontend_common.c +++ b/groundStation/src/frontend/frontend_common.c @@ -33,7 +33,7 @@ struct backend_conn * ucart_backendConnect() struct backend_conn * conn = NULL; - printf("Trying to connect...\n"); + printf("Trying to connect..."); remote.sun_family = AF_UNIX; char * sock_env = getenv(SOCKET_ENV); @@ -60,6 +60,7 @@ struct backend_conn * ucart_backendConnect() warn("setvbuf"); } + printf("Success\n"); /* success */ goto fail_final; @@ -68,6 +69,7 @@ fail_malloc_conn: conn = NULL; fail_sock: close(s); + printf("Failure\n"); fail_final: return conn; } diff --git a/groundStation/src/frontend/frontend_common.h b/groundStation/src/frontend/frontend_common.h index c8ea7877190c29ff41f02f9aa92a3987c80e2de6..60ee336269ee95388ed4f334ac1e3dfbe6e143bb 100644 --- a/groundStation/src/frontend/frontend_common.h +++ b/groundStation/src/frontend/frontend_common.h @@ -1,5 +1,5 @@ -#ifndef FRONTEND_COMMON_H -#define FRONTEND_COMMON_H +#ifndef __FRONTEND_COMMON_H +#define __FRONTEND_COMMON_H #include <stdlib.h> struct backend_conn; @@ -19,4 +19,4 @@ char * ucart_backendGetline(struct backend_conn * conn); /* Write a line to the backend */ int ucart_backendWrite(struct backend_conn * backend, const char * line); -#endif +#endif /* __FRONTEND_COMMON_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_getimu.h b/groundStation/src/frontend/frontend_getimu.h index c95784a1d4aada157283aa40ca74cd0fb211d505..1747252bbc78a403799fb0744c91e2b04883c0cb 100644 --- a/groundStation/src/frontend/frontend_getimu.h +++ b/groundStation/src/frontend/frontend_getimu.h @@ -1,6 +1,6 @@ -#ifndef FRONTEND_GETIMU_H -#define FRONTEND_GETIMU_H +#ifndef __FRONTEND_GETIMU_H +#define __FRONTEND_GETIMU_H #include "frontend_common.h" -#endif \ No newline at end of file +#endif /* __FRONTEND_GETIMU_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_getpid.c b/groundStation/src/frontend/frontend_getpid.c index e7e21cfebbcaaae0e276e515f837716cd3d694c6..08827a528fdaec30b36910e5d91438100c12e4de 100644 --- a/groundStation/src/frontend/frontend_getpid.c +++ b/groundStation/src/frontend/frontend_getpid.c @@ -1,6 +1,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <err.h> #include "frontend_getpid.h" #include "pid_common.h" @@ -60,5 +61,23 @@ int frontend_getpid( return 1; } + char * response; + for (;;) { + response = ucart_backendGetline(conn); + if (response == NULL) { + warnx("Line not returned from backend"); + return 1; + } + printf("received : %s\n", response); + // if (strncmp(response, MAGIC, strlen(MAGIC)) == 0) { + // break; + // } + } + + // if (strncmp(response, MAGIC " ERROR", strlen(MAGIC " ERROR")) == 0) { + // warnx("Backend returned an error: %s", strstr(response, "ERROR")); + // return 1; + // } + return 0; } diff --git a/groundStation/src/frontend/frontend_getpid.h b/groundStation/src/frontend/frontend_getpid.h index 977ae97f314a3c5b3891f5d60e56929aa03d6db9..e7933f1abf1869ac7f3074d472c8a8a36106507c 100644 --- a/groundStation/src/frontend/frontend_getpid.h +++ b/groundStation/src/frontend/frontend_getpid.h @@ -1,5 +1,5 @@ -#ifndef FRONTEND_GETPID_H -#define FRONTEND_GETPID_H +#ifndef __FRONTEND_GETPID_H +#define __FRONTEND_GETPID_H #include "frontend_common.h" #include "pid_common.h" @@ -23,4 +23,4 @@ int frontend_getpid( struct frontend_pid_data * pid_data); -#endif +#endif /* __FRONTEND_GETPID_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_getsetpoint.c b/groundStation/src/frontend/frontend_getsetpoint.c new file mode 100644 index 0000000000000000000000000000000000000000..1268416f5a9e0a0a32d4735935691cba6be516ae --- /dev/null +++ b/groundStation/src/frontend/frontend_getsetpoint.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "frontend_getsetpoint.h" +#include "setpoint_common.h" +#include "cli_getsetpoint.h" + +/* Get a specified setpoint. + * + * Example: + * + * struct frontend_setpoint_data setpoint_data; + * if (frontend_getpid(conn, &pid_data)) { + * error + * } else { + * setpoint_data.height, setpoint_data.lat, and setpoint.long are filled + * } + * + * Returns 0 on success, 1 on error + */ +int frontend_getsetpoint( + struct backend_conn * conn, struct frontend_setpoint_data * setpoint_data, int type) { + + char line[25] = ""; + switch (type) { + case HEIGHT : + strncpy(line, "getheight\n", 10); + break; + case LAT : + strncpy(line, "getlat\n", 7); + break; + case LONGG : + strncpy(line, "getlong\n", 8); + break; + case PITCH : + strncpy(line, "getpitch\n", 9); + break; + case ROLL : + strncpy(line, "getroll\n", 8); + break; + case YAW : + strncpy(line, "getyaw\n", 7); + break; + } + int size; + if((size = ucart_backendWrite(conn, line)) < 0 ) { + return 1; + } + + return 0; +} diff --git a/groundStation/src/frontend/frontend_getsetpoint.h b/groundStation/src/frontend/frontend_getsetpoint.h new file mode 100644 index 0000000000000000000000000000000000000000..f8dfdc87b3df057d5fd43714c5b81a52831ce763 --- /dev/null +++ b/groundStation/src/frontend/frontend_getsetpoint.h @@ -0,0 +1,25 @@ +#ifndef __FRONTEND_GETSETPOINT_H +#define __FRONTEND_GETSETPOINT_H + +#include "frontend_common.h" +#include "setpoint_common.h" + +/* Get a specified setpoint. + * + * Example: + * + * struct frontend_setpoint_data setpoint_data; + * if (frontend_getpid(conn, &pid_data)) { + * error + * } else { + * setpoint_data.height, setpoint_data.lat, and setpoint.long are filled + * } + * + * Returns 0 on success, 1 on error + */ +int frontend_getsetpoint( + struct backend_conn * conn, + struct frontend_setpoint_data * setpoint_data, + int type); + +#endif /* __FRONTEND_GETPID_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_setpid.h b/groundStation/src/frontend/frontend_setpid.h index bd53cd4535e4aa5834e2841879fdf4dd6bdb014c..b9c6e073d3433a0350ebd9b2d9de8ee55a12f18e 100644 --- a/groundStation/src/frontend/frontend_setpid.h +++ b/groundStation/src/frontend/frontend_setpid.h @@ -1,5 +1,5 @@ -#ifndef FRONTEND_SETPID_H -#define FRONTEND_SETPID_H +#ifndef __FRONTEND_SETPID_H +#define __FRONTEND_SETPID_H #include "pid_common.h" #include "frontend_common.h" @@ -17,4 +17,4 @@ int frontend_setpid( #define SET_ALL (SET_P | SET_I | SET_D) #endif /* SET_ALL */ -#endif /* FRONTEND_SETPID_H */ \ No newline at end of file +#endif /* __FRONTEND_SETPID_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_setsetpoint.c b/groundStation/src/frontend/frontend_setsetpoint.c index f264479210dc801629bd27f14200a11709a38e1b..b9f43caed0ded4d80964dddcc39a12e165f5c54a 100644 --- a/groundStation/src/frontend/frontend_setsetpoint.c +++ b/groundStation/src/frontend/frontend_setsetpoint.c @@ -16,26 +16,50 @@ 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); + } + if (mask & SET_PITCH) { + if (snprintf(buffer, 2048, + "setpitch %f\n", + setpoint_data->pitch) >= 2048) { + errx(0, "Buffer to small to format!"); + } + ucart_backendWrite(conn, buffer); + } + if (mask & SET_ROLL) { + if (snprintf(buffer, 2048, + "setroll %f\n", + setpoint_data->roll) >= 2048) { + errx(0, "Buffer to small to format!"); + } + ucart_backendWrite(conn, buffer); + } + if (mask & SET_YAW) { + if (snprintf(buffer, 2048, + "setyaw %f\n", + setpoint_data->yaw) >= 2048) { errx(0, "Buffer to small to format!"); } ucart_backendWrite(conn, buffer); diff --git a/groundStation/src/frontend/frontend_setsetpoint.h b/groundStation/src/frontend/frontend_setsetpoint.h index 03806fdfe2bfb492a458475c36ffbb012586ebcd..2607c4d564e14b5c4baae8b9500a74d6b878b922 100644 --- a/groundStation/src/frontend/frontend_setsetpoint.h +++ b/groundStation/src/frontend/frontend_setsetpoint.h @@ -1,5 +1,5 @@ -#ifndef FRONTEND_SETSETPOINT_H -#define FRONTEND_SETSETPOINT_H +#ifndef __FRONTEND_SETSETPOINT_H +#define __FRONTEND_SETSETPOINT_H #include "setpoint_common.h" #include "frontend_common.h" @@ -9,12 +9,15 @@ 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 +#define SET_PITCH 0x08 +#define SET_ROLL 0x10 +#define SET_YAW 0x20 #ifndef SET_ALL -#define SET_ALL (SET_X | SET_Y | SET_Z) +#define SET_ALL (SET_LAT | SET_LONG | SET_HEIGHT | SET_PITCH | SET_ROLL | SET_YAW) #endif /* SET_ALL */ -#endif /* FRONTEND_SETSETPOINT_H */ \ No newline at end of file +#endif /* __FRONTEND_SETSETPOINT_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/frontend_tracker.h b/groundStation/src/frontend/frontend_tracker.h index 5fa82487cafb8650a4f990ef9fed0c4ea4154405..58284ca01dc1b4987b523fc125b60010209af930 100644 --- a/groundStation/src/frontend/frontend_tracker.h +++ b/groundStation/src/frontend/frontend_tracker.h @@ -1,5 +1,5 @@ -#ifndef _FRONTEND_TRACKER_H -#define _FRONTEND_TRACKER_H +#ifndef __FRONTEND_TRACKER_H +#define __FRONTEND_TRACKER_H #include "frontend_common.h" @@ -24,4 +24,4 @@ struct frontend_tracker_data { int frontend_track(struct backend_conn * conn, struct frontend_tracker_data *data); -#endif +#endif /* __FRONTEND_TRACKER_H */ \ No newline at end of file diff --git a/groundStation/src/frontend/pid_common.h b/groundStation/src/frontend/pid_common.h index c40c4fb42fb19bf7caf22a03effe091fb7621ece..b89e3b1cddc85bb8820520e91ea4fa1858becd3a 100644 --- a/groundStation/src/frontend/pid_common.h +++ b/groundStation/src/frontend/pid_common.h @@ -1,5 +1,5 @@ -#ifndef PID_COMMON_H -#define PID_COMMON_H +#ifndef __PID_COMMON_H +#define __PID_COMMON_H enum pid_controller { PID_PITCH, @@ -23,4 +23,4 @@ struct frontend_pid_data { }; -#endif +#endif /* __PID_COMMON_H */ diff --git a/groundStation/src/frontend/setpoint_common.h b/groundStation/src/frontend/setpoint_common.h index 25dc8c1ce8ee6ae76805ba10595c0e0139ea8a00..a661cb1cd6b2a3fe84edbba7fdf2ffac85e9c074 100644 --- a/groundStation/src/frontend/setpoint_common.h +++ b/groundStation/src/frontend/setpoint_common.h @@ -1,11 +1,15 @@ -#ifndef SETPOINT_COMMON_H -#define SETPOINT_COMMON_H +#ifndef __SETPOINT_COMMON_H +#define __SETPOINT_COMMON_H struct frontend_setpoint_data { - float x; - float y; - float z; + float height; + float lat; + /* named with two g's due to long type name */ + float longg; + float pitch; + float roll; + float yaw; }; -#endif /* SETPOINT_COMMON_H */ \ No newline at end of file +#endif /* __SETPOINT_COMMON_H */ \ No newline at end of file