From cbe4513b7c88aada07f594a5bf1e50e8f5750677 Mon Sep 17 00:00:00 2001
From: burneykb <burneykb@iastate.edu>
Date: Wed, 1 Feb 2017 19:02:27 -0600
Subject: [PATCH] Pushing changes made with jake

cmHandler ready for cmToStr() and strToCm() functions
---
 groundStation/src/backend/backend.c   |  24 +-----
 groundStation/src/backend/cmHandler.c |   1 +
 groundStation/src/backend/cmHandler.h |   7 ++
 groundStation/src/backend/logger.c    | 108 --------------------------
 groundStation/src/backend/logger.h    |  21 -----
 groundStation/src/backend/packet.c    |   2 +-
 6 files changed, 13 insertions(+), 150 deletions(-)
 create mode 100644 groundStation/src/backend/cmHandler.c
 create mode 100644 groundStation/src/backend/cmHandler.h
 delete mode 100644 groundStation/src/backend/logger.c
 delete mode 100644 groundStation/src/backend/logger.h

diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c
index a0ea26cfb..3a686e8c1 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 000000000..22bf01656
--- /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 000000000..a977c5bed
--- /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 028cfeac1..000000000
--- 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 9bbd06811..000000000
--- 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 2830f5902..f29e946e5 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
-- 
GitLab