Skip to content
Snippets Groups Projects
Commit cbe4513b authored by burneykb's avatar burneykb
Browse files

Pushing changes made with jake

cmHandler ready for cmToStr() and strToCm() functions
parent 003e10b6
No related branches found
No related tags found
No related merge requests found
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
#include "commands.h" #include "commands.h"
#include "vrpn_tracker.hpp" #include "vrpn_tracker.hpp"
#include "type_def.h" #include "type_def.h"
#include "logger.h"
#include "packet.h" #include "packet.h"
#include "respcontrol.h" #include "respcontrol.h"
#include "config.h" #include "config.h"
#include "cmHandler.h"
#define QUAD_BT_ADDR "00:06:66:64:61:D6" #define QUAD_BT_ADDR "00:06:66:64:61:D6"
#define QUAD_BT_CHANNEL 0x01 #define QUAD_BT_CHANNEL 0x01
...@@ -78,7 +78,7 @@ static int wasDisconnected(int fd); ...@@ -78,7 +78,7 @@ static int wasDisconnected(int fd);
/* Thread-safe wrappers */ /* Thread-safe wrappers */
pthread_mutex_t quadSocketMutex; 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); static ssize_t readQuad(char * buf, size_t count);
/* Functions for recording Latencies */ /* Functions for recording Latencies */
...@@ -120,7 +120,6 @@ static void cb(struct ucart_vrpn_TrackerData * td) { ...@@ -120,7 +120,6 @@ static void cb(struct ucart_vrpn_TrackerData * td) {
if(!(count % 10)) { if(!(count % 10)) {
sendVrpnPacket(td); sendVrpnPacket(td);
//updateLogFile(td);
} }
count++; count++;
} }
...@@ -165,7 +164,6 @@ int main(int argc, char **argv) ...@@ -165,7 +164,6 @@ int main(int argc, char **argv)
/* Add to socket set */ /* Add to socket set */
safe_fd_set(backendSocket, &rfds_master, &max_fd); safe_fd_set(backendSocket, &rfds_master, &max_fd);
/* Initialize client buffers */ /* Initialize client buffers */
for (int i = 0; i < MAX_CLIENTS; i++) { for (int i = 0; i < MAX_CLIENTS; i++) {
...@@ -191,13 +189,6 @@ int main(int argc, char **argv) ...@@ -191,13 +189,6 @@ int main(int argc, char **argv)
err(-2, "pthrtead_mutex_unlock (%s:%d):", __FILE__, __LINE__); 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 // watch for input from stdin (fd 0) to see when it has input
safe_fd_set(fileno(stdin), &rfds_master, &max_fd); safe_fd_set(fileno(stdin), &rfds_master, &max_fd);
...@@ -266,10 +257,7 @@ int main(int argc, char **argv) ...@@ -266,10 +257,7 @@ int main(int argc, char **argv)
} }
ucart_vrpn_tracker_freeInstance(tracker); ucart_vrpn_tracker_freeInstance(tracker);
safe_close_fd(zyboSocket, &quadSocketMutex); safe_close_fd(zyboSocket, &quadSocketMutex);
closeLogFile();
return 0; return 0;
} }
...@@ -280,7 +268,7 @@ void sendStartPacket() { ...@@ -280,7 +268,7 @@ void sendStartPacket() {
m.data_len = 0; m.data_len = 0;
m.msg_id = currMessageID++; m.msg_id = currMessageID++;
size_t psize; ssize_t psize;
if ((psize = EncodePacket(packet, 64, &m, NULL)) < 0) { if ((psize = EncodePacket(packet, 64, &m, NULL)) < 0) {
warnx("Big problems"); warnx("Big problems");
...@@ -424,7 +412,7 @@ int safe_fd_clr(int fd, fd_set* fds, int* max_fd) { ...@@ -424,7 +412,7 @@ int safe_fd_clr(int fd, fd_set* fds, int* max_fd) {
return 0; 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; ssize_t retval;
if (getenv(NOQUAD_ENV)) { if (getenv(NOQUAD_ENV)) {
return count; return count;
...@@ -735,8 +723,4 @@ void findTimeDiff(int respID) { ...@@ -735,8 +723,4 @@ void findTimeDiff(int respID) {
gettimeofday(&tend, NULL); gettimeofday(&tend, NULL);
timeval_subtract(&result, &tend, &timeArr[respID%MAX_HASH_SIZE]); timeval_subtract(&result, &tend, &timeArr[respID%MAX_HASH_SIZE]);
printf("(BackEnd): Elapsed time = %ld ms\n", result.tv_usec/1000); 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);
} }
#include "cmHandler.h"
\ No newline at end of file
#ifndef _CMHANDLER_H
#define _CMHANDLER_H
#endif /* _CMHANDLER_H */
\ No newline at end of file
/* 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__);
}
}
/* 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
...@@ -96,5 +96,5 @@ uint8_t PacketChecksum(const uint8_t * packet, size_t packet_size) ...@@ -96,5 +96,5 @@ uint8_t PacketChecksum(const uint8_t * packet, size_t packet_size)
size_t PacketSize(const struct metadata *m) 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
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