From 4a42091df02c592d089a842b0ad21a0195cd5e58 Mon Sep 17 00:00:00 2001 From: burneykb <burneykb@iastate.edu> Date: Tue, 21 Mar 2017 04:41:11 -0500 Subject: [PATCH] Changes made to backend & commands.* files. Ready to make changes to CLI & FE --- common/commands.c | 3 +- common/controller.h | 34 -- groundStation/src/backend/backend.c | 121 +++--- .../src/backend}/bitwise.h | 0 groundStation/src/backend/callbacks.c | 377 +----------------- groundStation/src/backend/callbacks.h | 2 - groundStation/src/backend/cmHandler.c | 185 --------- groundStation/src/backend/cmHandler.h | 48 --- groundStation/src/backend/communication.c | 95 ----- groundStation/src/backend/communication.h | 16 - groundStation/src/backend/getparam.c | 54 --- groundStation/src/backend/getparam.h | 28 -- groundStation/src/backend/old_main.cold | 73 ---- groundStation/src/backend/output.c | 77 ++++ groundStation/src/backend/output.h | 28 ++ .../src/backend}/packet.c | 0 .../src/backend}/packet.h | 0 groundStation/src/backend/param.c | 126 ++++++ groundStation/src/backend/param.h | 36 ++ groundStation/src/backend/responseparam.c | 64 --- groundStation/src/backend/responseparam.h | 28 -- groundStation/src/backend/setparam.c | 65 --- groundStation/src/backend/setparam.h | 27 -- groundStation/src/backend/source.c | 114 ++++++ groundStation/src/backend/source.h | 35 ++ groundStation/src/backend/update.c | 2 +- groundStation/src/backend/update.h | 2 +- groundStation/src/cli/cli.h | 38 +- groundStation/src/cli/cli_getimu.c | 8 - groundStation/src/cli/cli_getimu.h | 8 - 30 files changed, 511 insertions(+), 1183 deletions(-) delete mode 100644 common/controller.h rename {common => groundStation/src/backend}/bitwise.h (100%) delete mode 100644 groundStation/src/backend/cmHandler.c delete mode 100644 groundStation/src/backend/cmHandler.h delete mode 100644 groundStation/src/backend/communication.c delete mode 100644 groundStation/src/backend/communication.h delete mode 100644 groundStation/src/backend/getparam.c delete mode 100644 groundStation/src/backend/getparam.h delete mode 100644 groundStation/src/backend/old_main.cold create mode 100644 groundStation/src/backend/output.c create mode 100644 groundStation/src/backend/output.h rename {common => groundStation/src/backend}/packet.c (100%) rename {common => groundStation/src/backend}/packet.h (100%) create mode 100644 groundStation/src/backend/param.c create mode 100644 groundStation/src/backend/param.h delete mode 100644 groundStation/src/backend/responseparam.c delete mode 100644 groundStation/src/backend/responseparam.h delete mode 100644 groundStation/src/backend/setparam.c delete mode 100644 groundStation/src/backend/setparam.h create mode 100644 groundStation/src/backend/source.c create mode 100644 groundStation/src/backend/source.h delete mode 100644 groundStation/src/cli/cli_getimu.c delete mode 100644 groundStation/src/cli/cli_getimu.h diff --git a/common/commands.c b/common/commands.c index 0128b8f12..09f18bcae 100644 --- a/common/commands.c +++ b/common/commands.c @@ -248,14 +248,13 @@ struct MessageType MessageTypes[MAX_TYPE_ID] = // Function pointer &cb_logend } - }; int findCommand(char * str) { int i; for (i = 0; i < MAX_TYPE_ID; i++) { - if (strcmp(str, MessageTypes[i].cmdText) == 0) { + if (strncmp(str, MessageTypes[i].cmdText, strlen(str)) == 0) { return i; } } diff --git a/common/controller.h b/common/controller.h deleted file mode 100644 index 13d12353c..000000000 --- a/common/controller.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _controller_h -#define _controller_h - - -/* For now, the enums come from commands.h */ -#include "commands.h" -#if 0 -enum ControllerID { - ROLL_ID, // 00 - Roll PID - PITCH_ID, // 01 - Pitch PID - YAW_ID, // 02 - Yaw PID - ROLL_RATE_ID, // 03 - Roll rate PID - PITCH_RATE_ID, // 04 - Pitch rate PID - YAW_RATE_ID, // 05 - Yaw rate PID - LOCAL_X_ID, // 06 - Local X PID - LOCAL_Y_ID, // 07 - Local Y PID - ALT_ID, // 08 - Altitude PID -}; - -enum ControllerValueID{ - KP_ID, // 00 - P constant - KI_ID, // 01 - I constant - KD_ID, // 02 - D constant - SP_ID, // 03 - Setpoint value -}; -#endif - -struct controller_message { - enum ControllerID id; - enum ControlParamID value_id; - float value; -}; - -#endif diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c index ab4b67920..cdd0727a2 100644 --- a/groundStation/src/backend/backend.c +++ b/groundStation/src/backend/backend.c @@ -29,18 +29,16 @@ #include <netinet/tcp.h> //user created includes -#include "communication.h" #include "../../../common/commands.h" #include "vrpn_tracker.hpp" #include "type_def.h" -#include "../../../common/packet.h" -#include "responseparam.h" +#include "packet.h" +#include "param.h" #include "update.h" #include "config.h" -#include "cmHandler.h" -#include "getparam.h" -#include "setparam.h" -#include "../../../common/bitwise.h" +#include "source.h" +#include "output.h" +#include "bitwise.h" #define QUAD_BT_ADDR "00:06:66:64:61:D6" #define QUAD_BT_CHANNEL 0x01 @@ -82,7 +80,7 @@ static void quad_recv(); /* Checks to see if socket has disconnected. Returns 1 on disconnect, else returns 0 */ static int wasDisconnected(int fd); /* handle controller responses from quad to frontend */ -static void handleResponseParam(struct metadata *m, uint8_t * data); +static void handleResponse(struct metadata *m, uint8_t * data); /* Thread-safe wrappers */ @@ -629,8 +627,18 @@ static void client_recv(int fd) { buffer[newline] = '\0'; printf("Client(%d) : '%s'\n",fd, buffer); - struct controller_message cm; - if (stringToCm(buffer, &cm) == NULL) { + char * first_word; + char * tmp = strdup(buffer); + first_word = strtok(tmp, " "); + free(tmp); + + ssize_t msg_type, i; + for (i = 0; i < MAX_TYPE_ID; ++i) { + if ((msg_type = findCommand(first_word)) != -1) + break; + } + + if (msg_type == -1) { /* buffer was not a quad command, handling internally to * backend instead of forwarding to quad */ @@ -668,14 +676,32 @@ static void client_recv(int fd) { uint8_t packet[64]; struct metadata m; 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) { - result = EncodeGetparam(&m, data, 128, &cm); - } else { - warnx("not implemented yet"); + ssize_t result; + ssize_t psize; + + switch (msg_type) { + case SETPARAM_ID: + result = EncodeSetParam(&m, data, 128, buffer); + break; + case GETPARAM_ID: + result = EncodeGetParam(&m, data, 128, buffer); + break; + case SETSOURCE_ID: + result = EncodeSetSource(&m, data, 128, buffer); + break; + case GETSOURCE_ID: + result = EncodeGetSource(&m, data, 128, buffer); + break; + case GETOUTPUT_ID: + result = EncodeGetOutput(&m, data, 128, buffer); + break; + case GETNODES_ID: + result = -1; + // result = EncodeGetnodes(&m, data, 128, buffer); + break; + default: + result = -1; + break; } if (result < 0) { @@ -683,16 +709,15 @@ static void client_recv(int fd) { return; } - ssize_t psize; + m.msg_id = currMessageID++; + if ((psize = EncodePacket(packet, 64, &m, data)) < 0) { warnx("Big problems. client_recv. EncodePacket"); return; } - m.msg_id = currMessageID++; - /* Only add the client to the pending responses if it was a getparam command */ - if (m.msg_type == GETPARAM_ID) { + if (m.msg_type == GETPARAM_ID || m.msg_type == GETOUTPUT_ID || m.msg_type == GETSOURCE_ID) { if (clientAddPendResponses(fd, BytesTo16(packet[ID_L], packet[ID_H])) == -1) { warnx("Ran out of room! Consider increasing CLIENT_MAX_PENDING_RESPONSES!\n"); } @@ -778,52 +803,52 @@ static void quad_recv() { respBufLen -= packetlen; switch (m.msg_type) { - case DEBUG_ID : - case PACKETLOG_ID : - case GETPACKETLOGS_ID : - case UPDATE_ID : - case BEGINUPDATE_ID : - printf("(Backend): Command '%s' ignored\n", MessageTypes[m.msg_type].cmdText); - break; case LOG_ID: /* something like this */ printf("(Quad) : Log found\n"); fwrite((char *) data, sizeof(char), m.data_len, quadlog_file); // fflush(quadlog_file); break; - case RESPONSE_ID: - printf("(Backend): response id found\n"); - break; - case SETPARAM_ID: - case GETPARAM_ID: - printf("(Backend): Command '%s' ignored\n", MessageTypes[m.msg_type].cmdText); - break; case RESPPARAM_ID: - handleResponseParam(&m, data); + case RESPSOURCE_ID: + case RESPOUTPUT_ID: + handleResponse(&m, data); break; + case RESPNODES_ID: default: - printf("(Backend): message type %d unrecognized\n", m.msg_type); + printf("(Backend): message type %d ignored from quad\n", m.msg_type); } } } -static void handleResponseParam(struct metadata *m, uint8_t * data) +static void handleResponse(struct metadata *m, uint8_t * data) { - struct controller_message cm; - if (DecodeResponseParam(&cm, m, data) < 0) { - warnx("DecodeResponse error"); - return; - } + ssize_t result; char buffer[128]; - const char * message = cmToString(RESPPARAM_ID, &cm); + switch (m->msg_type) { + case RESPPARAM_ID: + result = DecodeResponseParam(buffer, m, data); + break; + case RESPSOURCE_ID: + result = DecodeResponseSource(buffer, m, data); + break; + case RESPOUTPUT_ID: + result = DecodeResponseOutput(buffer, m, data); + break; + default: + result = -1; + } - size_t len = snprintf(buffer, 128, "%s %f\n", message, cm.value); + if (result < 0) { + warnx("DecodeResponse error"); + return; + } for(int fd = 0; fd <= max_fd; ++fd) { - if (get_client_index(fd) > -1) { + if (get_client_index(fd) < 0) { clientRemovePendResponses(fd, m->msg_id); - write(fd, buffer, len); + write(fd, buffer, result); } } } diff --git a/common/bitwise.h b/groundStation/src/backend/bitwise.h similarity index 100% rename from common/bitwise.h rename to groundStation/src/backend/bitwise.h diff --git a/groundStation/src/backend/callbacks.c b/groundStation/src/backend/callbacks.c index c5499fadb..875167b48 100644 --- a/groundStation/src/backend/callbacks.c +++ b/groundStation/src/backend/callbacks.c @@ -1,378 +1,3 @@ -#include "../../../common/commands.h" +#include "commands.h" /* New stuff - this is nice and clean */ - -/* Override any callbacks here */ - - -/****** LEGACY CODE BE VERY AFRAID ********/ - -// TAKE THESE OUT WHEN IMPLEMENTING ON THE QUAD SIDE -float getFloat(unsigned char* str, int pos) { - union { - float f; - int i; - } x; - x.i = ((str[pos+3] << 24) | (str[pos+2] << 16) | (str[pos+1] << 8) | (str[pos])); - return x.f; -} - -int getInt(unsigned char* str, int pos) { - int i = ((str[pos+3] << 24) | (str[pos+2] << 16) | (str[pos+1] << 8) | (str[pos])); - return i; -} -//------------------------------------------------ - -int cb_debug(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for debug\n"); - return 0; -} - -int cb_update(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - unsigned char update[28]; - memcpy(update, ((float *)packet), 28); - - int packetId = getInt(update, 0); - float y_pos = getFloat(update, 4); - float x_pos = getFloat(update, 8); - float alt_pos = getFloat(update, 12); - float roll = getFloat(update, 16); - float pitch = getFloat(update, 20); - float yaw = getFloat(update, 24); - - structs->log_struct.currentQuadPosition.packetId = packetId; - structs->log_struct.currentQuadPosition.y_pos = y_pos; - structs->log_struct.currentQuadPosition.x_pos = x_pos; - structs->log_struct.currentQuadPosition.alt_pos = alt_pos; - structs->log_struct.currentQuadPosition.roll = roll; - structs->log_struct.currentQuadPosition.pitch = pitch; - structs->log_struct.currentQuadPosition.yaw = yaw; - - printf("QUAD: VRPN Packet:"); - printf("Packet ID: %d\n", packetId); - printf("Y Position: %f\n", y_pos); - printf("X Position: %f\n", x_pos); - printf("Altitude Position: %f\n", alt_pos); - printf("Roll: %f\n", roll); - printf("Pitch: %f\n", pitch); - printf("Yaw: %f\n", yaw); - - printf("function for update\n"); - return 0; -} - -// Why is this here? -// This should be on the ground station side -int logdata(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("Logging: %s\n", packet); - return 0; -} - -int response(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("This is the response: %s\n", packet); - - return 0; -} - -// ------------------------------------------------------------------ - -int setyaw(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - - printf("%f\n", value); - - structs->setpoint_struct.desiredQuadPosition.yaw = value; - - printf("function for setyaw: %f\n", structs->setpoint_struct.desiredQuadPosition.yaw); - - return 0; -} - -int setyawp(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.yaw_angle_pid.Kp = value; - - printf("function for setyawp: %f\n", structs->parameter_struct.yaw_angle_pid.Kp); - - return 0; -} - -int setyawd(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.yaw_angle_pid.Kd = value; - - printf("function for setyawd: %f\n", structs->parameter_struct.yaw_angle_pid.Kd); - - return 0; -} - -int setroll(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->setpoint_struct.desiredQuadPosition.roll = value; - - printf("function for setroll: %f\n", structs->setpoint_struct.desiredQuadPosition.roll); - - return 0; -} - -int setrollp(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.local_y_pid.Kp = value; - - printf("function for setrollp: %f\n", structs->parameter_struct.local_y_pid.Kp); - - return 0; -} - -int setrolld(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.local_y_pid.Kd = value; - - printf("function for setrolld: %f\n", structs->parameter_struct.local_y_pid.Kd); - - return 0; -} - -int setpitch(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->setpoint_struct.desiredQuadPosition.pitch = value; - - printf("function for setpitch: %f\n", structs->setpoint_struct.desiredQuadPosition.pitch); - - return 0; -} - -int setpitchp(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.local_x_pid.Kp = value; - - printf("function for setpitchp: %f\n", structs->parameter_struct.local_x_pid.Kp); - - return 0; -} - -int setpitchd(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.local_x_pid.Kd = value; - - printf("function for setpitchd: %f\n", structs->parameter_struct.local_x_pid.Kd); - - return 0; -} - -// ------------------------------------------------------------ -// These should be renamed to altitude! -int setthrottle(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->setpoint_struct.desiredQuadPosition.alt_pos = value; - - printf("function for setthrottle: %f\n", structs->setpoint_struct.desiredQuadPosition.alt_pos); - - return 0; -} - -int setthrottlep(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.alt_pid.Kp = value; - - printf("function for setthrottlep: %f\n", structs->parameter_struct.alt_pid.Kp); - - return 0; -} - -int setthrottlei(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.alt_pid.Ki = value; - - printf("function for setthrottlei: %f\n", structs->parameter_struct.alt_pid.Ki); - - return 0; -} - -int setthrottled(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - float value; - - memcpy(&value, ((float *)packet), dataLen); - structs->parameter_struct.alt_pid.Kd = value; - - printf("function for setthrottled: %f\n", structs->parameter_struct.alt_pid.Kd); - - return 0; -} -int getyaw(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getyawp(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getyawd(unsigned char *packet, int dataLen, modular_structs_t *structs) { - return 0; -} -int getroll(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getrollp(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getrolld(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getpitch(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getpitchp(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getpitchd(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getthrottle(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getthrottlep(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getthrottlei(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int getthrottled(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} - -// These should be renamed to altitude! -// ------------------------------------------------------------ - - - - -int getgyro(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for getgyro\n"); - return 0; -} - -int getpitchangle(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for getpitchangle\n"); - return 0; -} - -int getrollangle(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for getrollangle\n"); - return 0; -} - - -int getaccel(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for getaccel\n"); - return 0; -} - - -int respgyro(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for respgyro\n"); - return 0; -} - -int resppitchangle(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for resppitchangle\n"); - return 0; -} - -int resprollangle(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for resprollangle\n"); - return 0; -} - - -int respaccel(unsigned char *packet, int dataLen, modular_structs_t *structs) -{ - printf("function for respaccel\n"); - return 0; -} - -int respyaw(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int respyawp(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int respyawd(unsigned char *packet, int dataLen, modular_structs_t *structs) { - return 0; -} -int resproll(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int resprollp(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int resprolld(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int resppitch(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int resppitchp(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int resppitchd(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int respthrottle(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int respthrottlep(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int respthrottlei(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} -int respthrottled(unsigned char *packet, int dataLen, modular_structs_t *structs){ - return 0; -} diff --git a/groundStation/src/backend/callbacks.h b/groundStation/src/backend/callbacks.h index 69510e0a8..cc5fd8cab 100644 --- a/groundStation/src/backend/callbacks.h +++ b/groundStation/src/backend/callbacks.h @@ -7,6 +7,4 @@ /* Make commands.c happy */ typedef void (command_cb)(void); -float getFloat(unsigned char * str, int pos); - #endif /* __CALLBACKS_H */ diff --git a/groundStation/src/backend/cmHandler.c b/groundStation/src/backend/cmHandler.c deleted file mode 100644 index a1159c183..000000000 --- a/groundStation/src/backend/cmHandler.c +++ /dev/null @@ -1,185 +0,0 @@ -#include <stdlib.h> - -#include "cmHandler.h" - -const char * respParamStrings[MAX_PARAM_COMMANDS] = { - "getrollp", - "getrolli", - "getrolld", - "getpitchp", - "getpitchi", - "getpitchd", - "getyawp", - "getyawi", - "getyawd", - "getrollratep", - "getrollratei", - "getrollrated", - "getpitchratep", - "getpitchratei", - "getpitchrated", - "getyawratep", - "getyawratei", - "getyawrated", - "getlatp", - "getlati", - "getlatd", - "getlongp", - "getlongi", - "getlongd", - "getheightp", - "getheighti", - "getheightd", - "getlat", - "getlong", - "getheight" -}; - -const char * setParamStrings[MAX_PARAM_COMMANDS] = { - "setrollp", - "setrolli", - "setrolld", - "setpitchp", - "setpitchi", - "setpitchd", - "setyawp", - "setyawi", - "setyawd", - "setrollratep", - "setrollratei", - "setrollrated", - "setpitchratep", - "setpitchratei", - "setpitchrated", - "setyawratep", - "setyawratei", - "setyawrated", - "setlatp", - "setlati", - "setlatd", - "setlongp", - "setlongi", - "setlongd", - "setheightp", - "setheighti", - "setheightd", - "setlat", - "setlong", - "setheight", -}; - -const char * cmToString(int msgType, const struct controller_message *cm) -{ - size_t index; - if (cm->id == X_SETPOINT_ID) { - index = PARAM_LOCAL_X; // This will change when we make node structure changes - } else if (cm->id == X_SETPOINT_ID) { - index = PARAM_LOCAL_Y; // This will change when we make node structure changes - } else if (cm->id == X_SETPOINT_ID) { - index = PARAM_ALT; // This will change when we make node structure changes - } else { - index = (cm->id * MAX_CONTROL_PARAM_ID) + cm->value_id; - } - switch (msgType) { - case DEBUG_ID : - case PACKETLOG_ID : - case GETPACKETLOGS_ID : - case UPDATE_ID : - case BEGINUPDATE_ID : - case LOG_ID: - case SETPARAM_ID: - return setParamStrings[index]; - case GETPARAM_ID: - return NULL; - break; - case RESPONSE_ID: - return NULL; - case RESPPARAM_ID: - return respParamStrings[index]; - default: - return NULL; - break; - } -} - -struct controller_message * stringToCm(const char * string, struct controller_message *cm) -{ - int result; - size_t i; - char cmdString[strlen(string)]; - strncpy(cmdString, string, strlen(string)); - - float cmdValue; - 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 && - strlen(cmdString) == strlen(respParamStrings[i])) { - index = i; - break; - } 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; - } - } - // printf("index = %d\n", index); - - /* Error, nothing found */ - if (index == -1) { - return NULL; - } else { - cm->value_id = i % MAX_CONTROL_PARAM_ID; // Default assuming not a setpoint command - if (i <= PARAM_ROLL_D) { - - cm->id = ROLL_ID; - } else if (i <= PARAM_PITCH_D) { - - cm->id = PITCH_ID; - } else if (i <= PARAM_YAW_D) { - - cm->id = YAW_ID; - } else if (i <= PARAM_ROLL_RATE_D) { - - cm->id = ROLL_RATE_ID; - } else if (i <= PARAM_PITCH_RATE_D) { - - cm->id = PITCH_RATE_ID; - } else if (i <= PARAM_YAW_RATE_D) { - - cm->id = YAW_RATE_ID; - } else if (i <= PARAM_LOCAL_X_D) { - - cm->id = LOCAL_X_ID; - } else if (i <= PARAM_LOCAL_Y_D) { - - cm->id = LOCAL_Y_ID; - } else if (i <= PARAM_ALT_D) { - - cm->id = ALT_ID; - } else if ( i == PARAM_LOCAL_X) { - - cm->id = X_SETPOINT_ID; - cm->value_id = 0; - } else if ( i == PARAM_LOCAL_Y) { - - cm->id = Y_SETPOINT_ID; - cm->value_id = 0; - } else if ( i == PARAM_ALT) { - - cm->id = ALT_SETPOINT_ID; - cm->value_id = 0; - } - } - // printf("cm->id = %d\ncm->value_id = %d\n", cm->id, cm->value_id); - return cm; -} \ No newline at end of file diff --git a/groundStation/src/backend/cmHandler.h b/groundStation/src/backend/cmHandler.h deleted file mode 100644 index de513f303..000000000 --- a/groundStation/src/backend/cmHandler.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _CMHANDLER_H -#define _CMHANDLER_H - -#include "../../../common/controller.h" - -enum paramIndices { - PARAM_ROLL_P , - PARAM_ROLL_I , - PARAM_ROLL_D , - PARAM_PITCH_P , - PARAM_PITCH_I , - PARAM_PITCH_D , - PARAM_YAW_P , - PARAM_YAW_I , - PARAM_YAW_D , - PARAM_ROLL_RATE_P, - PARAM_ROLL_RATE_I, - PARAM_ROLL_RATE_D, - PARAM_PITCH_RATE_P, - PARAM_PITCH_RATE_I, - PARAM_PITCH_RATE_D, - PARAM_YAW_RATE_P, - PARAM_YAW_RATE_I, - PARAM_YAW_RATE_D, - PARAM_LOCAL_X_P , - PARAM_LOCAL_X_I , - PARAM_LOCAL_X_D , - PARAM_LOCAL_Y_P , - PARAM_LOCAL_Y_I , - PARAM_LOCAL_Y_D , - PARAM_ALT_P, - PARAM_ALT_I, - PARAM_ALT_D, - PARAM_LOCAL_X , - PARAM_LOCAL_Y , - PARAM_ALT , - MAX_PARAM_COMMANDS -}; - -extern const char * respParamStrings[MAX_PARAM_COMMANDS]; - -extern const char * setParamStrings[MAX_PARAM_COMMANDS]; - -const char * cmToString(int msgType, const struct controller_message *cm); - -struct controller_message * stringToCm(const char * string, struct controller_message *cm); - -#endif /* _CMHANDLER_H */ diff --git a/groundStation/src/backend/communication.c b/groundStation/src/backend/communication.c deleted file mode 100644 index d0aa5c19a..000000000 --- a/groundStation/src/backend/communication.c +++ /dev/null @@ -1,95 +0,0 @@ -#include "communication.h" -#include "../../../common/commands.h" -#include <string.h> -#include <ctype.h> - -static int msgNum = 0; -//-------------------------------- -// Ground Station -//-------------------------------- - -// Formatting commands from ground station CLI -int formatCommand(char *command, unsigned char *formattedCommand) { - // fprintf(stderr, "length = %li , received '%s'\n", strlen(command), command); - char cmd[512]; - strncpy(cmd, command, 512); - - char * cmdText = strtok(cmd, " "); - - return -1; -} - -// returns the length of the data in bytes (datalen from packet) and fills data -// and metadata with the packet information -// use as follows: -// -// packet is the entire packet message (formatted) -// data is an unallocated (char *) (pass it to this function as &data) -// meta_data is a pointer to an instance of metadata_t -// -int parse_packet(unsigned char * packet, unsigned char * data, metadata_t * meta_data) -{ - //---------------------------------------------------------------------------------------------- - // index|| 0 | 1 | 2 | 3 & 4 | 5 & 6 | 7+ | end | - //---------------------------------------------------------------------------------------------| - // msg param|| beg char | msg type | msg id | data len (bytes) | data | checksum | - //-------------------------------------------------------------------------------------------- | - // bytes|| 1 | 1 | 1 | 2 | 2 | var | 1 | - //---------------------------------------------------------------------------------------------- - - // first byte must be the begin char - if(packet[0] != 0xBE) - return -1; - - // receive metadata - meta_data->begin_char = packet[0]; - meta_data->msg_type = packet[2] << 8 | packet[1]; - meta_data->msg_id = (packet[4] << 8) | (packet[3]); - meta_data->data_len = (packet[6] << 8) | (packet[5]); - unsigned char packet_checksum = packet[7+meta_data->data_len]; - //fprintf(stderr, "datalen: %d\n", meta_data->data_len); - - int i; - - // receive data - for(i = 0; i < meta_data->data_len; i++) - { - data[i] = packet[7+i]; - } - - // calculate checksum - unsigned char calculated_checksum = 0; - for(i = 0; i < meta_data->data_len + 7 - 1; i++) - { - calculated_checksum ^= packet[i]; - } - - // compare checksum - if(packet_checksum != calculated_checksum) { - return -2; - } - - return 0; -} - -// Process the command received -int processCommand(unsigned char *packet, modular_structs_t *structs) { - int validPacket; - unsigned char data[256]; - metadata_t metadata; - - // Validate the message is correctly formatted - validPacket = parse_packet(packet, data, &metadata); - if(validPacket != 0) { - return -1; - } - - if(metadata.data_len >= 0) { - (* (MessageTypes[(unsigned char)metadata.msg_type].functionPtr))(); - - return 0; - } - - // Only gets here if there is an error - return -1; -} diff --git a/groundStation/src/backend/communication.h b/groundStation/src/backend/communication.h deleted file mode 100644 index f3439f266..000000000 --- a/groundStation/src/backend/communication.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __COMMUNICATION_H -#define __COMMUNICATION_H - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <limits.h> -#include "type_def.h" - -int formatCommand(char *command, unsigned char *formattedCommand); -int formatPacket(metadata_t *metadata, void *data, unsigned char *formattedCommand); -int parse_packet(unsigned char * packet, unsigned char * data, metadata_t * meta_data); -int processCommand(unsigned char *command, modular_structs_t *structs); -int logData(unsigned char *log_msg, unsigned char *formattedCommand); - -#endif /* __COMMUNICATION_H */ diff --git a/groundStation/src/backend/getparam.c b/groundStation/src/backend/getparam.c deleted file mode 100644 index 16dc0c0a0..000000000 --- a/groundStation/src/backend/getparam.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "getparam.h" -#include "../../../common/commands.h" -#include "../../../common/bitwise.h" - -#include <sys/types.h> - -enum GetparamData { - CTRL_ID, - CTRLVAL_ID, - GP_DATA_SIZE -}; - -/* Creates data and metadata for a respcontrol packet - * Returns data size. - */ -ssize_t EncodeGetparam( - struct metadata * m, /* data_len and msg_type will be populated*/ - uint8_t * data, /* Output buffer */ - size_t data_size, /* Max buffer size */ - const struct controller_message * cm) /* Message to encode */ -{ - m->msg_type = GETPARAM_ID; - m->data_len = GP_DATA_SIZE; - - if (data_size < GP_DATA_SIZE) { - return -1; - } - - data[CTRL_ID] = cm->id; - data[CTRLVAL_ID] = cm->value_id; - - return GP_DATA_SIZE; -} - -/* Decode a metadata and data to populate a controller. - * Returns 0 on success, -1 on failure. - */ -int DecodeGetparam( - struct controller_message * cm, /* Decoded controller message */ - const struct metadata * m, /* Metadata to aid in decoding */ - const uint8_t * data) /* Data to decode */ -{ - if (m->data_len < GP_DATA_SIZE) { - return -1; - } - if (m->msg_type != GETPARAM_ID) { - return -1; - } - - cm->id = data[CTRL_ID]; - cm->value_id = data[CTRLVAL_ID]; - - return 0; -} diff --git a/groundStation/src/backend/getparam.h b/groundStation/src/backend/getparam.h deleted file mode 100644 index 7e068f167..000000000 --- a/groundStation/src/backend/getparam.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _getparam_h -#define _getparam_h - -#include "../../../common/packet.h" -#include "../../../common/controller.h" - -#include <sys/types.h> - - -/* Creates data and metadata for a getcontrol packet. - * Returns data size. - */ -ssize_t EncodeGetparam( - struct metadata *m, /* Out */ - uint8_t *data, /* Out */ - size_t data_size, /* Data buffer max size */ - const struct controller_message *cm); /* Value is not used; only IDs */ - -/* Decode a metadata and data to populate a message - * Returns 0 on success, -1 on failure - */ -int DecodeGetparam( - struct controller_message *cm, /* Out. Value is undefined */ - const struct metadata *m, /* In */ - const uint8_t * data); /* In */ - - -#endif diff --git a/groundStation/src/backend/old_main.cold b/groundStation/src/backend/old_main.cold deleted file mode 100644 index 5234bcc56..000000000 --- a/groundStation/src/backend/old_main.cold +++ /dev/null @@ -1,73 +0,0 @@ -#include <libcli.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <string.h> -#include <strings.h> -#include <signal.h> -#include <unistd.h> -#include <arpa/inet.h> - - -#define CLITEST_PORT 8000 - -int fn_help(struct cli_def *cli, const char *command, char *argv[], int argc); - -struct cli_def * cli; -int on = 1; - -int main(int argc, char **argv) -{ - int s, x; - struct sockaddr_in addr; - - if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) - { - perror("socket"); - return 1; - } - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(INADDR_ANY); - addr.sin_port = htons(CLITEST_PORT); - - if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) - { - perror("bind"); - return 1; - } - - if (listen(s, 50) < 0) - { - perror("listen"); - return 1; - } - - printf("Listening on port %d\n", CLITEST_PORT); - - cli = cli_init(); - cli_set_banner(cli, "Welcome to my test cli"); - - cli_register_command(cli, NULL, "helpme", fn_help, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "displays help info for a command"); - - - - - while((x = accept(s, NULL, NULL))) - { - cli_loop(cli, x); - close(x); - } - - - cli_done(cli); -} - - -int fn_help(struct cli_def *cli, const char *command, char *argv[], int argc) { - printf("you ran the help function!!\n"); - return 0; -} - diff --git a/groundStation/src/backend/output.c b/groundStation/src/backend/output.c new file mode 100644 index 000000000..0c3195c95 --- /dev/null +++ b/groundStation/src/backend/output.c @@ -0,0 +1,77 @@ +#include <sys/types.h> + +#include "output.h" +#include "../../../common/commands.h" +#include "bitwise.h" + + +enum GetoutputData { + GO_BLOCK_ID_L, + GO_BLOCK_ID_H, + GO_OUTPUT_ID_L, + GO_OUTPUT_ID_H, + GO_DATA_SIZE +}; + +/* Creates data and metadata for a setcontrol packet + * Returns data size. + */ +ssize_t EncodeGetOutput( + struct metadata * m, /* data_len and msg_type will be populated*/ + uint8_t * data, /* Output buffer */ + size_t data_size, /* Max buffer size */ + const char * msg) /* Message to encode */ +{ + m->msg_type = GETOUTPUT_ID; + m->data_len = GO_DATA_SIZE; + + if (data_size < GO_DATA_SIZE) { + return -1; + } + + uint16_t block, output; + + sscanf(msg, "getoutput %hu %hu", &block, &output); + + data[GO_BLOCK_ID_L] = LSByte16(block); + data[GO_BLOCK_ID_H] = MSByte16(block); + data[GO_OUTPUT_ID_L] = LSByte16(output); + data[GO_OUTPUT_ID_H] = MSByte16(output); + + return GO_DATA_SIZE; +} + +enum ResponseData { + RESP_BLOCK_ID_L, + RESP_BLOCK_ID_H, + RESP_OUTPUT_ID_L, + RESP_OUTPUT_ID_H, + RESP_VAL_1, + RESP_VAL_2, + RESP_VAL_3, + RESP_VAL_4, + RESP_DATA_SIZE +}; + +/* Decode a metadata and data to populate a controller. + * Returns bytes written to msg, -1 on failure. + */ +int DecodeResponseOutput( + char * msg, /* Decoded controller message */ + const struct metadata * m, /* Metadata to aid in decoding */ + const uint8_t * data) /* Data to decode */ +{ + if (m->data_len < RESP_DATA_SIZE) { + return -1; + } + if (m->msg_type != RESPOUTPUT_ID) { + return -1; + } + + return sprintf(msg, "getoutput %hu %hu %f\n", + BytesTo16(data[RESP_BLOCK_ID_L], data[RESP_BLOCK_ID_H]), + BytesTo16(data[RESP_OUTPUT_ID_L], data[RESP_OUTPUT_ID_H]), + BytesToFloat(data[RESP_VAL_1], data[RESP_VAL_2], + data[RESP_VAL_3], data[RESP_VAL_4])); +} + diff --git a/groundStation/src/backend/output.h b/groundStation/src/backend/output.h new file mode 100644 index 000000000..034d6ec15 --- /dev/null +++ b/groundStation/src/backend/output.h @@ -0,0 +1,28 @@ +#ifndef _getoutput_h +#define _getoutput_h + +#include "packet.h" + +#include <sys/types.h> + + +/* Creates data and metadata for a getcontrol packet. + * Returns data size. + */ +ssize_t EncodeGetOutput( + struct metadata *m, /* Out */ + uint8_t *data, /* Out */ + size_t data_size, /* Data buffer max size */ + const char * msg); /* Value is not used; only IDs */ + + +/* Decode a metadata and data to populate a controller. + * Returns bytes written to msg, -1 on failure. + */ +int DecodeResponseOutput( + char * msg, /* Out */ + const struct metadata *m, /* In */ + const uint8_t * data); /* In */ + + +#endif diff --git a/common/packet.c b/groundStation/src/backend/packet.c similarity index 100% rename from common/packet.c rename to groundStation/src/backend/packet.c diff --git a/common/packet.h b/groundStation/src/backend/packet.h similarity index 100% rename from common/packet.h rename to groundStation/src/backend/packet.h diff --git a/groundStation/src/backend/param.c b/groundStation/src/backend/param.c new file mode 100644 index 000000000..749960fe4 --- /dev/null +++ b/groundStation/src/backend/param.c @@ -0,0 +1,126 @@ +#include <sys/types.h> + +#include "param.h" +#include "../../../common/commands.h" +#include "bitwise.h" + +enum GetparamData { + GP_BLOCK_ID_L, + GP_BLOCK_ID_H, + GP_PARAM_ID_L, + GP_PARAM_ID_H, + GP_DATA_SIZE +}; + +/* Creates data and metadata for a respcontrol packet + * Returns data size. + */ +ssize_t EncodeGetParam( + struct metadata * m, /* data_len and msg_type will be populated*/ + uint8_t * data, /* Output buffer */ + size_t data_size, /* Max buffer size */ + const char * msg) /* Message to encode */ +{ + m->msg_type = GETPARAM_ID; + m->data_len = GP_DATA_SIZE; + + if (data_size < GP_DATA_SIZE) { + return -1; + } + + uint16_t block, param; + sscanf(msg, "getparam %hu %hu", &block, ¶m); + + + data[GP_BLOCK_ID_L] = LSByte16(block); + data[GP_BLOCK_ID_H] = MSByte16(block); + + data[GP_PARAM_ID_L] = LSByte16(param); + data[GP_PARAM_ID_H] = MSByte16(param); + + return GP_DATA_SIZE; +} + +enum SetparamData { + SP_BLOCK_ID_L, + SP_BLOCK_ID_H, + SP_PARAM_ID_L, + SP_PARAM_ID_H, + SP_VAL_1, + SP_VAL_2, + SP_VAL_3, + SP_VAL_4, + SP_DATA_SIZE +}; + +/* Creates data and metadata for a setcontrol packet + * Returns data size. + */ +ssize_t EncodeSetParam( + struct metadata * m, /* data_len and msg_type will be populated*/ + uint8_t * data, /* Output buffer */ + size_t data_size, /* Max buffer size */ + const char * msg) /* Message to encode */ +{ + m->msg_type = SETPARAM_ID; + m->data_len = SP_DATA_SIZE; + + if (data_size < SP_DATA_SIZE) { + return -1; + } + + uint16_t block, param; + float val; + + sscanf(msg, "setparam %hu %hu %f", &block, ¶m, &val); + + data[SP_BLOCK_ID_L] = LSByte16(block); + data[SP_BLOCK_ID_H] = MSByte16(block); + + data[SP_PARAM_ID_L] = LSByte16(param); + data[SP_PARAM_ID_H] = MSByte16(param); + + + data[SP_VAL_1] = FloatByte1(val); + data[SP_VAL_2] = FloatByte2(val); + data[SP_VAL_3] = FloatByte3(val); + data[SP_VAL_4] = FloatByte4(val); + + return SP_DATA_SIZE; +} + + + +enum ResponseData { + RESP_BLOCK_ID_L, + RESP_BLOCK_ID_H, + RESP_PARAM_ID_L, + RESP_PARAM_ID_H, + RESP_VAL_1, + RESP_VAL_2, + RESP_VAL_3, + RESP_VAL_4, + RESP_DATA_SIZE +}; + +/* Decode a metadata and data to populate a controller. + * Returns bytes written to msg, -1 on failure. + */ +int DecodeResponseParam( + char * msg, /* Decoded controller message */ + const struct metadata * m, /* Metadata to aid in decoding */ + const uint8_t * data) /* Data to decode */ +{ + if (m->data_len < RESP_DATA_SIZE) { + return -1; + } + if (m->msg_type != RESPPARAM_ID) { + return -1; + } + + return sprintf(msg, "getparam %hu %hu %f\n", + BytesTo16(data[RESP_BLOCK_ID_L], data[RESP_BLOCK_ID_H]), + BytesTo16(data[RESP_PARAM_ID_L], data[RESP_PARAM_ID_H]), + BytesToFloat(data[RESP_VAL_1], data[RESP_VAL_2], + data[RESP_VAL_3], data[RESP_VAL_4])); +} diff --git a/groundStation/src/backend/param.h b/groundStation/src/backend/param.h new file mode 100644 index 000000000..96ecc6332 --- /dev/null +++ b/groundStation/src/backend/param.h @@ -0,0 +1,36 @@ +#ifndef _param_h +#define _param_h + +#include "packet.h" + +#include <sys/types.h> + + +/* Creates data and metadata for a getcontrol packet. + * Returns data size. + */ +ssize_t EncodeGetParam( + struct metadata *m, /* Out */ + uint8_t *data, /* Out */ + size_t data_size, /* Data buffer max size */ + const char * msg); /* Value is not used; only IDs */ + +/* Creates data and metadata for a setcontrol packet + * Returns data size. + */ +ssize_t EncodeSetParam( + struct metadata * m, /* data_len and msg_type will be populated*/ + uint8_t * data, /* Output buffer */ + size_t data_size, /* Max buffer size */ + const char * msg); /* Message to encode */ + +/* Decode a metadata and data to populate a controller. + * Returns bytes written to msg, -1 on failure. + */ +int DecodeResponseParam( + char * msg, /* Out */ + const struct metadata *m, /* In */ + const uint8_t * data); /* In */ + + +#endif diff --git a/groundStation/src/backend/responseparam.c b/groundStation/src/backend/responseparam.c deleted file mode 100644 index e2f188c29..000000000 --- a/groundStation/src/backend/responseparam.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "responseparam.h" -#include "../../../common/commands.h" -#include "../../../common/bitwise.h" - -#include <sys/types.h> - -enum ResponseData { - CTRL_ID, - CTRLVAL_ID, - VAL_1, - VAL_2, - VAL_3, - VAL_4, - RESP_DATA_SIZE -}; - -/* Creates data and metadata for a respparam packet - * Returns data size. - */ -ssize_t EncodeResponseParam( - struct metadata * m, /* data_len and msg_type will be populated*/ - uint8_t * data, /* Output buffer */ - size_t data_size, /* Max buffer size */ - const struct controller_message * cm) /* Message to encode */ -{ - m->msg_type = RESPPARAM_ID; - m->data_len = RESP_DATA_SIZE; - - if (data_size < RESP_DATA_SIZE) { - return -1; - } - - data[CTRL_ID] = cm->id; - data[CTRLVAL_ID] = cm->value_id; - data[VAL_1] = FloatByte1(cm->value); - data[VAL_2] = FloatByte2(cm->value); - data[VAL_3] = FloatByte3(cm->value); - data[VAL_4] = FloatByte4(cm->value); - - return RESP_DATA_SIZE; -} - -/* Decode a metadata and data to populate a controller. - * Returns 0 on success, -1 on failure. - */ -int DecodeResponseParam( - struct controller_message * cm, /* Decoded controller message */ - const struct metadata * m, /* Metadata to aid in decoding */ - const uint8_t * data) /* Data to decode */ -{ - if (m->data_len < RESP_DATA_SIZE) { - return -1; - } - if (m->msg_type != RESPPARAM_ID) { - return -1; - } - - cm->id = data[CTRL_ID]; - cm->value_id = data[CTRLVAL_ID]; - cm->value = BytesToFloat(data[VAL_1], data[VAL_2], - data[VAL_3], data[VAL_4]); - - return 0; -} diff --git a/groundStation/src/backend/responseparam.h b/groundStation/src/backend/responseparam.h deleted file mode 100644 index 4daa8c3ed..000000000 --- a/groundStation/src/backend/responseparam.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _responseparam_h -#define _responseparam_h - -#include "../../../common/packet.h" -#include "../../../common/controller.h" - -#include <sys/types.h> - - -/* Creates data and metadata for a respcontrol packet. - * Returns data size. - */ -ssize_t EncodeResponseParam( - struct metadata *m, /* Out */ - uint8_t *data, /* Out */ - size_t data_size, /* Data buffer max size */ - const struct controller_message *cm); /* In */ - -/* Decode a metadata and data to populate a message - * Returns 0 on success, -1 on failure - */ -int DecodeResponseParam( - struct controller_message *cm, /* Out */ - const struct metadata *m, /* In */ - const uint8_t * data); /* In */ - - -#endif diff --git a/groundStation/src/backend/setparam.c b/groundStation/src/backend/setparam.c deleted file mode 100644 index 6aaa71b08..000000000 --- a/groundStation/src/backend/setparam.c +++ /dev/null @@ -1,65 +0,0 @@ -#include "setparam.h" -#include "../../../common/commands.h" -#include "../../../common/bitwise.h" - -#include <sys/types.h> - -enum SetparamData { - CTRL_ID, - CTRLVAL_ID, - VAL_1, - VAL_2, - VAL_3, - VAL_4, - SP_DATA_SIZE -}; - -/* Creates data and metadata for a setcontrol packet - * Returns data size. - */ -ssize_t EncodeSetparam( - struct metadata * m, /* data_len and msg_type will be populated*/ - uint8_t * data, /* Output buffer */ - size_t data_size, /* Max buffer size */ - const struct controller_message * cm) /* Message to encode */ -{ - m->msg_type = SETPARAM_ID; - m->data_len = SP_DATA_SIZE; - - if (data_size < SP_DATA_SIZE) { - return -1; - } - - data[CTRL_ID] = cm->id; - data[CTRLVAL_ID] = cm->value_id; - data[VAL_1] = FloatByte1(cm->value); - data[VAL_2] = FloatByte2(cm->value); - data[VAL_3] = FloatByte3(cm->value); - data[VAL_4] = FloatByte4(cm->value); - - return SP_DATA_SIZE; -} - -/* Decode a metadata and data to populate a controller. - * Returns 0 on success, -1 on failure. - */ -int DecodeSetparam( - struct controller_message * cm, /* Decoded controller message */ - const struct metadata * m, /* Metadata to aid in decoding */ - const uint8_t * data) /* Data to decode */ -{ - if (m->data_len < SP_DATA_SIZE) { - return -1; - } - if (m->msg_type != SETPARAM_ID) { - return -1; - } - - - cm->id = data[CTRL_ID]; - cm->value_id = data[CTRLVAL_ID]; - cm->value = BytesToFloat(data[VAL_1], data[VAL_2], - data[VAL_3], data[VAL_4]); - - return 0; -} diff --git a/groundStation/src/backend/setparam.h b/groundStation/src/backend/setparam.h deleted file mode 100644 index d3d251a2e..000000000 --- a/groundStation/src/backend/setparam.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _setparam_h -#define _setparam_h - -#include "../../../common/packet.h" -#include "../../../common/controller.h" - -#include <sys/types.h> - -/* Creates data and metadata for a setcontrol packet - * Returns data size. - */ -ssize_t EncodeSetparam( - struct metadata * m, /* data_len and msg_type will be populated*/ - uint8_t * data, /* Output buffer */ - size_t data_size, /* Max buffer size */ - const struct controller_message * cm); /* Message to encode */ - -/* Decode a metadata and data to populate a controller. - * Returns 0 on success, -1 on failure. - */ -int DecodeSetparam( - struct controller_message * cm, /* Decoded controller message */ - const struct metadata * m, /* Metadata to aid in decoding */ - const uint8_t * data); /* Data to decode */ - - -#endif diff --git a/groundStation/src/backend/source.c b/groundStation/src/backend/source.c new file mode 100644 index 000000000..dac52612d --- /dev/null +++ b/groundStation/src/backend/source.c @@ -0,0 +1,114 @@ +#include <sys/types.h> + +#include "source.h" +#include "../../../common/commands.h" +#include "bitwise.h" + + +enum GetsourceData { + GS_BLOCK_ID_L, + GS_BLOCK_ID_H, + GS_INPUT_ID_L, + GS_INPUT_ID_H, + GS_DATA_SIZE +}; + +/* Creates data and metadata for a setcontrol packet + * Returns data size. + */ +ssize_t EncodeGetSource( + struct metadata * m, /* data_len and msg_type will be populated*/ + uint8_t * data, /* Output buffer */ + size_t data_size, /* Max buffer size */ + const char * msg) /* Message to encode */ +{ + m->msg_type = GETSOURCE_ID; + m->data_len = GS_DATA_SIZE; + + if (data_size < GS_DATA_SIZE) { + return -1; + } + uint16_t block, input; + + sscanf(msg, "getsource %hu %hu", &block, &input); + + data[GS_BLOCK_ID_L] = LSByte16(block); + data[GS_BLOCK_ID_H] = MSByte16(block); + data[GS_INPUT_ID_L] = LSByte16(input); + data[GS_INPUT_ID_H] = MSByte16(input); + + return GS_DATA_SIZE; +} + +enum SetsourceData { + SS_DST_BLOCK_ID_L, + SS_DST_BLOCK_ID_H, + SS_DST_INPUT_ID_L, + SS_DST_INPUT_ID_H, + SS_SRC_BLOCK_ID_L, + SS_SRC_BLOCK_ID_H, + SS_SRC_OUTPUT_ID_L, + SS_SRC_OUTPUT_ID_H, + SS_DATA_SIZE +}; + +/* Creates data and metadata for a setcontrol packet + * Returns data size. + */ +ssize_t EncodeSetSource( + struct metadata * m, /* data_len and msg_type will be populated*/ + uint8_t * data, /* Output buffer */ + size_t data_size, /* Max buffer size */ + const char * msg) /* Message to encode */ +{ + m->msg_type = SETSOURCE_ID; + m->data_len = SS_DATA_SIZE; + + if (data_size < SS_DATA_SIZE) { + return -1; + } + + uint16_t dst_block, dst_input; + uint16_t src_block, src_output; + + sscanf(msg, "setsource %hu %hu %hu %hu", &dst_block, &dst_input, &src_block, &src_output); + + data[SS_DST_BLOCK_ID_L] = LSByte16(dst_block); + data[SS_DST_BLOCK_ID_H] = MSByte16(dst_block); + data[SS_DST_INPUT_ID_L] = LSByte16(dst_input); + data[SS_DST_INPUT_ID_H] = MSByte16(dst_input); + + data[SS_SRC_BLOCK_ID_L] = LSByte16(src_block); + data[SS_SRC_BLOCK_ID_H] = MSByte16(src_block); + data[SS_SRC_OUTPUT_ID_L] = LSByte16(src_output); + data[SS_SRC_OUTPUT_ID_H] = MSByte16(src_output); + + return SS_DATA_SIZE; +} + + +enum ResponseData { + RESP_DST_BLOCK_ID, + RESP_DST_INPUT_ID, + RESP_SRC_BLOCK_ID, + RESP_SRC_OUTPUT_ID, + RESP_DATA_SIZE +}; + +/* Decode a metadata and data to populate a controller. + * Returns bytes written to msg, -1 on failure. + */ +int DecodeResponseSource( + char * msg, /* Decoded controller message */ + const struct metadata * m, /* Metadata to aid in decoding */ + const uint8_t * data) /* Data to decode */ +{ + if (m->data_len < RESP_DATA_SIZE) { + return -1; + } + if (m->msg_type != RESPSOURCE_ID) { + return -1; + } + + return sprintf(msg, "getsource %d %d\n", data[RESP_SRC_BLOCK_ID], data[RESP_SRC_OUTPUT_ID]); +} diff --git a/groundStation/src/backend/source.h b/groundStation/src/backend/source.h new file mode 100644 index 000000000..577f27717 --- /dev/null +++ b/groundStation/src/backend/source.h @@ -0,0 +1,35 @@ +#ifndef _source_h +#define _source_h + +#include "packet.h" + +#include <sys/types.h> + + +/* Creates data and metadata for a getcontrol packet. + * Returns data size. + */ +ssize_t EncodeGetSource( + struct metadata *m, /* Out */ + uint8_t *data, /* Out */ + size_t data_size, /* Data buffer max size */ + const char * msg); /* Value is not used; only IDs */ + +/* Creates data and metadata for a setcontrol packet + * Returns data size. + */ +ssize_t EncodeSetSource( + struct metadata * m, /* data_len and msg_type will be populated*/ + uint8_t * data, /* Output buffer */ + size_t data_size, /* Max buffer size */ + const char * msg); /* Message to encode */ + +/* Decode a metadata and data to populate a controller. + * Returns bytes written to msg, -1 on failure. + */ +int DecodeResponseSource( + char * msg, /* Out */ + const struct metadata *m, /* In */ + const uint8_t * data); /* In */ + +#endif diff --git a/groundStation/src/backend/update.c b/groundStation/src/backend/update.c index c7553575f..1f51f0be7 100644 --- a/groundStation/src/backend/update.c +++ b/groundStation/src/backend/update.c @@ -1,6 +1,6 @@ #include "update.h" #include "../../../common/commands.h" -#include "../../../common/bitwise.h" +#include "bitwise.h" #include <sys/types.h> diff --git a/groundStation/src/backend/update.h b/groundStation/src/backend/update.h index 6491823d7..783a861ca 100644 --- a/groundStation/src/backend/update.h +++ b/groundStation/src/backend/update.h @@ -1,7 +1,7 @@ #ifndef _update_h #define _update_h -#include "../../../common/packet.h" +#include "packet.h" #include <sys/types.h> diff --git a/groundStation/src/cli/cli.h b/groundStation/src/cli/cli.h index e82bd5cda..707d16836 100644 --- a/groundStation/src/cli/cli.h +++ b/groundStation/src/cli/cli.h @@ -1,40 +1,38 @@ #ifndef __CLI_H #define __CLI_H -#include "cli_setsetpoint.h" -#include "cli_getsetpoint.h" #include "cli_monitor.h" -#include "cli_setpid.h" -#include "cli_getpid.h" -#include "cli_getimu.h" +#include "cli_source.h" +#include "cli_param.h" +#include "cli_output.h" enum CommandNameIds{ CMD_MONITOR, - CMD_GETPID, - CMD_SETPID, - CMD_GETIMU, - CMD_SETSETPOINT, - CMD_GETSETPOINT, + CMD_GETSOURCE, + CMD_SETSOURCE, + CMD_GETPARAM, + CMD_SETPARAM, + CMD_GETOUTPUT, MAX_COMMANDS }; typedef int (*cli_function_ptr)(struct backend_conn *, int, char **); static cli_function_ptr cli_functions[] = { &cli_monitor, - &cli_getpid, - &cli_setpid, - &cli_getimu, - &cli_setsetpoint, - &cli_getsetpoint + &cli_getsource, + &cli_setsource, + &cli_getparam, + &cli_setparam, + &cli_getoutput, }; static char* commandNames[MAX_COMMANDS] = { "monitor", - "getpid", - "setpid", - "getimu", - "setsetpoint", - "getsetpoint" + "getsource", + "setsource", + "getparam", + "setparam", + "getoutput" }; #endif /* __CLI_H */ \ No newline at end of file diff --git a/groundStation/src/cli/cli_getimu.c b/groundStation/src/cli/cli_getimu.c deleted file mode 100644 index 5825140af..000000000 --- a/groundStation/src/cli/cli_getimu.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> - -#include "cli_getimu.h" - -int cli_getimu(struct backend_conn * conn, int argc, char ** argv) { - printf("This functionality has not been added yet\n"); - return 0; -} diff --git a/groundStation/src/cli/cli_getimu.h b/groundStation/src/cli/cli_getimu.h deleted file mode 100644 index 2535f1ae8..000000000 --- a/groundStation/src/cli/cli_getimu.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __CLI_GETIMU_H -#define __CLI_GETIMU_H - -#include "frontend_getimu.h" - -int cli_getimu(struct backend_conn * conn, int argc, char ** argv); - -#endif /* __CLI_GETIMU_H */ \ No newline at end of file -- GitLab