diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c index a0ea26cfbaa2079aacca4fb28e5bf68b6a6c70e6..3a686e8c1c0cf83dcd74e2fbd7aa188cfc4e6fc9 100644 --- a/groundStation/src/backend/backend.c +++ b/groundStation/src/backend/backend.c @@ -33,10 +33,10 @@ #include "commands.h" #include "vrpn_tracker.hpp" #include "type_def.h" -#include "logger.h" #include "packet.h" #include "respcontrol.h" #include "config.h" +#include "cmHandler.h" #define QUAD_BT_ADDR "00:06:66:64:61:D6" #define QUAD_BT_CHANNEL 0x01 @@ -78,7 +78,7 @@ static int wasDisconnected(int fd); /* Thread-safe wrappers */ pthread_mutex_t quadSocketMutex; -static ssize_t writeQuad(const char * buf, size_t count); +static ssize_t writeQuad(const uint8_t * buf, size_t count); static ssize_t readQuad(char * buf, size_t count); /* Functions for recording Latencies */ @@ -120,7 +120,6 @@ static void cb(struct ucart_vrpn_TrackerData * td) { if(!(count % 10)) { sendVrpnPacket(td); - //updateLogFile(td); } count++; } @@ -165,7 +164,6 @@ int main(int argc, char **argv) /* Add to socket set */ safe_fd_set(backendSocket, &rfds_master, &max_fd); - /* Initialize client buffers */ for (int i = 0; i < MAX_CLIENTS; i++) { @@ -191,13 +189,6 @@ int main(int argc, char **argv) err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); } - // open the log file - if(createLogFile(argc, argv[1])) - { - perror("Error creating log file..."); - exit(1); - } - // watch for input from stdin (fd 0) to see when it has input safe_fd_set(fileno(stdin), &rfds_master, &max_fd); @@ -266,10 +257,7 @@ int main(int argc, char **argv) } ucart_vrpn_tracker_freeInstance(tracker); - safe_close_fd(zyboSocket, &quadSocketMutex); - - closeLogFile(); return 0; } @@ -280,7 +268,7 @@ void sendStartPacket() { m.data_len = 0; m.msg_id = currMessageID++; - size_t psize; + ssize_t psize; if ((psize = EncodePacket(packet, 64, &m, NULL)) < 0) { warnx("Big problems"); @@ -424,7 +412,7 @@ int safe_fd_clr(int fd, fd_set* fds, int* max_fd) { return 0; } -static ssize_t writeQuad(const char * buf, size_t count) { +static ssize_t writeQuad(const uint8_t * buf, size_t count) { ssize_t retval; if (getenv(NOQUAD_ENV)) { return count; @@ -735,8 +723,4 @@ void findTimeDiff(int respID) { gettimeofday(&tend, NULL); timeval_subtract(&result, &tend, &timeArr[respID%MAX_HASH_SIZE]); printf("(BackEnd): Elapsed time = %ld ms\n", result.tv_usec/1000); - // printf("print to log\n"); - // char tmp[8]; - // snprintf(tmp, 8, "%ld \tms\n", result.tv_usec/1000); - // writeStringToLog(tmp); } diff --git a/groundStation/src/backend/cmHandler.c b/groundStation/src/backend/cmHandler.c new file mode 100644 index 0000000000000000000000000000000000000000..22bf01656f861a3238aa55b7ff26a3c014b048fc --- /dev/null +++ b/groundStation/src/backend/cmHandler.c @@ -0,0 +1 @@ +#include "cmHandler.h" \ No newline at end of file diff --git a/groundStation/src/backend/cmHandler.h b/groundStation/src/backend/cmHandler.h new file mode 100644 index 0000000000000000000000000000000000000000..a977c5bed22282d70b0e3e36804e448426771a22 --- /dev/null +++ b/groundStation/src/backend/cmHandler.h @@ -0,0 +1,7 @@ +#ifndef _CMHANDLER_H +#define _CMHANDLER_H + + + + +#endif /* _CMHANDLER_H */ \ No newline at end of file diff --git a/groundStation/src/backend/logger.c b/groundStation/src/backend/logger.c deleted file mode 100644 index 028cfeac16c173e59154a1c9c8321eeba29d0344..0000000000000000000000000000000000000000 --- a/groundStation/src/backend/logger.c +++ /dev/null @@ -1,108 +0,0 @@ -/* Author: Kris Burney - * - * Logger file for holding functions pertaining to loging to a file. - */ -#include "logger.h" -#include <stdio.h> -#include <err.h> -#include <pthread.h> - -static FILE * quadlog_file = NULL; -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - -int createLogFile(int argc, char* argv) -{ - if (quadlog_file != NULL) { - return -1; - } - - if (pthread_mutex_lock(&mutex)) { - err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); - } - - char log_file[300]; - strcpy(log_file, "logs/"); - if(argc >= 2) - { - strncat(log_file, argv, 294); - printf("Creating log file '%s'...\n",log_file); - quadlog_file = fopen(log_file, "a"); - } else { - time_t rawtime; - char timestr [30]; - time(&rawtime); - sprintf(timestr,"%s",ctime(&rawtime)); - - // Lets convert space to _ in - char *p = timestr; - size_t i = 0; - while(i < strlen(timestr)) - { - if (*p == ' ') - *p = '_'; - i++; - p++; - } - - // timestr has a weird char at the end of it. - // we will not include it in our file name - strncat(log_file, timestr, strlen(timestr) -1 ); - strcat(log_file, ".txt"); - printf("Creating log file '%s'...\n",log_file); - quadlog_file = fopen(log_file, "a"); - } - if (pthread_mutex_unlock(&mutex)) { - err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); - } - return 0; -} - -int updateLogFile(const struct ucart_vrpn_TrackerData * td) -{ - int retval; - - if (pthread_mutex_lock(&mutex)) { - err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); - } - - retval = fprintf(quadlog_file, - "FPS: %lf Pos (xyz): (%lf %lf %lf) Att (pry): (%lf %lf %lf)\n", - td->fps, td->x, td->y, td->z, td->pitch, td->roll, td->yaw); - - if (pthread_mutex_unlock(&mutex)) { - err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); - } - - return retval; -} - -int writeStringToLog(const char * string) -{ - int retval; - - if (pthread_mutex_lock(&mutex)) { - err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); - } - - retval = fprintf(quadlog_file, "%s", string); - - if (pthread_mutex_unlock(&mutex)) { - err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); - } - - return retval; -} - -void closeLogFile(void) -{ - if (pthread_mutex_lock(&mutex)) { - err(-2, "pthrtead_mutex_lock (%s:%d):", __FILE__, __LINE__); - } - - fclose(quadlog_file); - - if (pthread_mutex_unlock(&mutex)) { - err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); - } - -} diff --git a/groundStation/src/backend/logger.h b/groundStation/src/backend/logger.h deleted file mode 100644 index 9bbd068116482e4d693fdb519f27dffd7bc2fff7..0000000000000000000000000000000000000000 --- a/groundStation/src/backend/logger.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Author: Kris Burney - * - * Logger header file for holding info pertaining to loging to a file. - */ -#ifndef __LOGGER_H -#define __LOGGER_H - -#include <fcntl.h> -#include <time.h> -#include <stdio.h> -#include <string.h> - -#include "vrpn_tracker.hpp" - -int createLogFile(int, char*); -int writeStringToLog(const char*); -int updateLogFile(const struct ucart_vrpn_TrackerData* ); -void closeLogFile(); - - -#endif /* __LOGGER_H */ \ No newline at end of file diff --git a/groundStation/src/backend/packet.c b/groundStation/src/backend/packet.c index 2830f5902376c4b9282fd79d72f76ad402c34742..f29e946e5515cc1ae638ebd29f4ad61d3224d919 100644 --- a/groundStation/src/backend/packet.c +++ b/groundStation/src/backend/packet.c @@ -96,5 +96,5 @@ uint8_t PacketChecksum(const uint8_t * packet, size_t packet_size) size_t PacketSize(const struct metadata *m) { - return m.data_len + HDR_SIZE + CSUM_SIZE; + return m->data_len + HDR_SIZE + CSUM_SIZE; } \ No newline at end of file