From 21aa3f2235c772d13c975ae8c2d6c70ca39540d2 Mon Sep 17 00:00:00 2001 From: "ucart@co3050-12" <dawehr@iastate.edu> Date: Sat, 28 Jan 2017 15:40:52 -0600 Subject: [PATCH] Added some comments in commands.c/h, callbacks.c/h - Added a comment saying that we may not need the ID parameter on the MessageType Struct anymore. - Removed calls of the nature: "MessageTypes[TYPE_ID].ID" and replaced them with "TYPE_ID" because it is the same thing.. - Added function comments in callbacks.c - Simplified the callbacks.c by having a more generic setval, getval, respval callback function instead of a billion of them for each PID value. --- groundStation/src/backend/commands.h | 7 ++++ quad/sw/modular_quad_pid/src/callbacks.c | 53 +++++++++++++++++++----- quad/sw/modular_quad_pid/src/log_data.c | 4 +- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/groundStation/src/backend/commands.h b/groundStation/src/backend/commands.h index 89b006705..24d61f0a2 100644 --- a/groundStation/src/backend/commands.h +++ b/groundStation/src/backend/commands.h @@ -76,6 +76,13 @@ enum PIDType{ * pointers located in commands.c */ struct MessageType{ + /* TODO The ID may not even be needed since it already an enumerated value + * I found some instances of this being used like the following: + * "MessageTypes[LOG_TYPE_ID].ID" which makes no sense since the ID member + * in the MessageType is already set to be equal to the enumeration value + * instead they could have just done "LOG_TYPE_ID" directly since + * MessageTypes[LOG_TYPE_ID].ID always == LOG_TYPE_ID + */ char ID; char cmdText[MAX_CMD_TEXT_LENGTH]; char cmdDataType; diff --git a/quad/sw/modular_quad_pid/src/callbacks.c b/quad/sw/modular_quad_pid/src/callbacks.c index fd3dbf2f4..b1519926a 100644 --- a/quad/sw/modular_quad_pid/src/callbacks.c +++ b/quad/sw/modular_quad_pid/src/callbacks.c @@ -3,31 +3,49 @@ #include "type_def.h" #include "uart.h" +/* + * Static variables used to keep track of packet counts + */ +static int n_msg_received = 0; +static size_t total_payload_received = 0; + + +/* Misc. callbacks */ + +/** + * Currently does nothing. + */ int debug(modular_structs_t *structs) { return 0; } -static int n_msg_received = 0; -static size_t total_payload_received = 0; - +/** + * counts the number of packet logs. + */ int cb_packetlog(modular_structs_t* structs) { n_msg_received += 1; total_payload_received += uart_buff_data_length(); return 0; } +/** + * Handles a get packet logs request and sends a response + * with the packet log data. + */ int cb_getpacketlogs(modular_structs_t* structs) { char buf[255]; // Message logging number of messages received and size of payload received int length = snprintf(buf, sizeof buf, "%d,%d", n_msg_received, total_payload_received); - send_data(MessageTypes[LOG_TYPE_ID].ID, 0, buf, length >= sizeof(buf) ? 255 : length + 1); + send_data(LOG_TYPE_ID, 0, buf, length >= sizeof(buf) ? 255 : length + 1); return 0; } -/* Handles receiving new location updates */ +/* + * Handles receiving new location updates. + */ int cb_update(modular_structs_t *structs) { //processUpdate(packet, &(structs->raw_sensor_struct.currentQuadPosition)); @@ -63,10 +81,9 @@ int cb_update(modular_structs_t *structs) return 0; } - -/* Misc. callbacks */ - -// This is called on the ground station to begin sending VRPN to the quad +/** + * This is called on the ground station to begin sending VRPN to the quad. + */ int cb_beginupdate(modular_structs_t *structs) { structs->user_input_struct.receivedBeginUpdate = 1; return 0; @@ -75,19 +92,33 @@ int cb_beginupdate(modular_structs_t *structs) { /* Callbacks for configuration */ +/** + * Handles a command to set a value on the quad. + * + * This function handles setting things like: + * - PID constants + * - set points + * - other things in the future, etc. + */ int cb_setval(modular_structs_t *structs) { - //structs->parameter_struct.roll_angle_pid.Kp = uart_buff_data_get_float(0); return 0; } +/** + * Handles a command to get a value from the quad. + * + * Used to get basically anything that setval can set. + * NOTE: This function sends a response command with the desired data + * back to the ground station. + */ int cb_getval(modular_structs_t* structs) { char buf[255]; // Message logging number of messages received and size of payload received int length = snprintf(buf, sizeof buf, "%f", structs->parameter_struct.yaw_angle_pid.Kp); - send_data(MessageTypes[GETVAL_TYPE_ID].ID, 0, buf, length >= sizeof(buf) ? 255 : length + 1); + send_data(GETVAL_TYPE_ID, 0, buf, length >= sizeof(buf) ? 255 : length + 1); return 0; } diff --git a/quad/sw/modular_quad_pid/src/log_data.c b/quad/sw/modular_quad_pid/src/log_data.c index 5d8d1b5d3..9bbf7cd18 100644 --- a/quad/sw/modular_quad_pid/src/log_data.c +++ b/quad/sw/modular_quad_pid/src/log_data.c @@ -147,7 +147,7 @@ void printLogging(){ strcat(buf,header); strcat(buf,units); - send_data(MessageTypes[LOG_TYPE_ID].ID, 0, buf, strlen(buf) + 1); + send_data(LOG_TYPE_ID, 0, buf, strlen(buf) + 1); //uart0_sendBytes(buf, strlen(buf)); //usleep(100000); @@ -155,7 +155,7 @@ void printLogging(){ /* print & send log data */ for(i = 0; i < arrayIndex; i++){ char* logLine = format(logArray[i]); - send_data(MessageTypes[LOG_TYPE_ID].ID, 0, logLine, strlen(logLine) + 1); + send_data(LOG_TYPE_ID, 0, logLine, strlen(logLine) + 1); free(logLine); } } -- GitLab