diff --git a/groundStation/src/backend/commands.h b/groundStation/src/backend/commands.h index 89b006705fd58cb11217b5a9595f0acf58dd7745..24d61f0a2adbe644b46a1422acb14a44c67b02ee 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 fd3dbf2f4a0b9c150ae073aaeb675bc0e2b7cc8f..b1519926a22182e515241e45105c8ce77b6a673c 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 5d8d1b5d3c10bc978cdbb612aae706d37c0040cd..9bbf7cd186a72b751fc85b02294bcfe046894ef4 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); } }