Skip to content
Snippets Groups Projects
Commit 21aa3f22 authored by dawehr's avatar dawehr
Browse files

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.
parent 754ed22e
No related branches found
No related tags found
No related merge requests found
...@@ -76,6 +76,13 @@ enum PIDType{ ...@@ -76,6 +76,13 @@ enum PIDType{
* pointers located in commands.c * pointers located in commands.c
*/ */
struct MessageType{ 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 ID;
char cmdText[MAX_CMD_TEXT_LENGTH]; char cmdText[MAX_CMD_TEXT_LENGTH];
char cmdDataType; char cmdDataType;
......
...@@ -3,31 +3,49 @@ ...@@ -3,31 +3,49 @@
#include "type_def.h" #include "type_def.h"
#include "uart.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) int debug(modular_structs_t *structs)
{ {
return 0; 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) { int cb_packetlog(modular_structs_t* structs) {
n_msg_received += 1; n_msg_received += 1;
total_payload_received += uart_buff_data_length(); total_payload_received += uart_buff_data_length();
return 0; return 0;
} }
/**
* Handles a get packet logs request and sends a response
* with the packet log data.
*/
int cb_getpacketlogs(modular_structs_t* structs) { int cb_getpacketlogs(modular_structs_t* structs) {
char buf[255]; char buf[255];
// Message logging number of messages received and size of payload received // 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); 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; return 0;
} }
/* Handles receiving new location updates */ /*
* Handles receiving new location updates.
*/
int cb_update(modular_structs_t *structs) int cb_update(modular_structs_t *structs)
{ {
//processUpdate(packet, &(structs->raw_sensor_struct.currentQuadPosition)); //processUpdate(packet, &(structs->raw_sensor_struct.currentQuadPosition));
...@@ -63,10 +81,9 @@ int cb_update(modular_structs_t *structs) ...@@ -63,10 +81,9 @@ int cb_update(modular_structs_t *structs)
return 0; 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) { int cb_beginupdate(modular_structs_t *structs) {
structs->user_input_struct.receivedBeginUpdate = 1; structs->user_input_struct.receivedBeginUpdate = 1;
return 0; return 0;
...@@ -75,19 +92,33 @@ int cb_beginupdate(modular_structs_t *structs) { ...@@ -75,19 +92,33 @@ int cb_beginupdate(modular_structs_t *structs) {
/* Callbacks for configuration */ /* 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) int cb_setval(modular_structs_t *structs)
{ {
//structs->parameter_struct.roll_angle_pid.Kp = uart_buff_data_get_float(0); //structs->parameter_struct.roll_angle_pid.Kp = uart_buff_data_get_float(0);
return 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) { int cb_getval(modular_structs_t* structs) {
char buf[255]; char buf[255];
// Message logging number of messages received and size of payload received // 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); 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; return 0;
} }
...@@ -147,7 +147,7 @@ void printLogging(){ ...@@ -147,7 +147,7 @@ void printLogging(){
strcat(buf,header); strcat(buf,header);
strcat(buf,units); 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)); //uart0_sendBytes(buf, strlen(buf));
//usleep(100000); //usleep(100000);
...@@ -155,7 +155,7 @@ void printLogging(){ ...@@ -155,7 +155,7 @@ void printLogging(){
/* print & send log data */ /* print & send log data */
for(i = 0; i < arrayIndex; i++){ for(i = 0; i < arrayIndex; i++){
char* logLine = format(logArray[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); free(logLine);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment