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

end of log command implemented

parent 7488723c
No related branches found
No related tags found
No related merge requests found
......@@ -10,11 +10,6 @@ INCDIR=../quad/inc src/vrpn src/vrpn/quat src/vrpn/build $(BESRCDIR) $(CLISRCDIR
LIBS= -lpthread -lbluetooth -lvrpn -lquat -Lsrc/vrpn/build -Lsrc/vrpn/build/quat -lcomputation_graph -L../quad/lib -lcommands
OBJDIR=obj
# Common Objects
# COMSRCDIR=../common
# COMSOURCES := $(wildcard $(COMSRCDIR)/*.c )
# COMOBJECTS = $(COMSOURCES:$(COMSRCDIR)/%.c=$(OBJDIR)/%.o)
# Backend Specific Variables
BEBINARY=BackEnd
BESRCDIR=src/backend
......@@ -39,7 +34,10 @@ FECOBJECTS = $(FECSOURCES:$(FESRCDIR)/%.c=$(OBJDIR)/%.o)
OBJECTS=$(CLIOBJECTS) $(BECOBJECTS) $(BECPPOBJECTS) $(FECOBJECTS)
# Default target
all: logs objdir backend cli $(SYMLINKS)
all: quad logs objdir backend cli $(SYMLINKS)
quad:
$(MAKE) -C ../quad
$(SYMLINKS): $(CLIBINARY)
$(foreach symlink, $(SYMLINKS), ln -s $(CLIBINARY) $(symlink);)
......
......@@ -82,7 +82,8 @@ static void quad_recv();
static int wasDisconnected(int fd);
/* handle controller responses from quad to frontend */
static void handleResponse(struct metadata *m, uint8_t * data);
/* Create new dynamic logfile name */
char * create_log_name(char * buffer, size_t max);
/* Thread-safe wrappers */
pthread_mutex_t quadSocketMutex;
......@@ -113,6 +114,7 @@ fd_set rfds_master;
int max_fd = 0;
static FILE * quadlog_file;
static char user_specified_log_name[256] = "";
pthread_mutex_t quadResponseMutex, cliInputMutex ;
unsigned char *commandBuf;
......@@ -131,8 +133,6 @@ int main(int argc, char **argv)
{
int activity;
FD_ZERO(&rfds_master);
char log_file[256] = "logs/";
/*
* Create backend listening socket
*/
......@@ -203,28 +203,12 @@ int main(int argc, char **argv)
if(argc >= 2)
{
strncat(log_file, argv[1], strlen(argv[1]));
} 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");
strncat(user_specified_log_name, argv[1], strlen(argv[1]));
}
char log_file[256];
create_log_name(log_file, 256);
printf("Creating log file '%s'...\n",log_file);
quadlog_file = fopen(log_file, "a");
......@@ -823,6 +807,13 @@ static void quad_recv() {
case RESPADDNODE_ID:
handleResponse(&m, data);
break;
case LOG_END_ID:
fclose(quadlog_file);
char log_file[256];
create_log_name(log_file, 256);
printf("New log file created: '%s'\n", log_file);
quadlog_file = fopen(log_file, "a");
break;
default:
printf("(Backend): message type %d ignored from quad\n", m.msg_type);
}
......@@ -907,3 +898,25 @@ void findTimeDiff(int respID) {
timeval_subtract(&result, &tend, &timeArr[respID%MAX_HASH_SIZE]);
printf("(BackEnd): Elapsed time = %ld ms\n", result.tv_usec/1000);
}
char * create_log_name(char * buffer, size_t max) {
static const char * prefix = "logs";
static size_t num_logs = 0;
static const char * format_string = "%Y-%m-%e_%-l:%M";
time_t curr_time;
char c_time_string[256];
struct tm * tmp;
curr_time = time(NULL);
tmp = localtime(&curr_time);
strftime(c_time_string, 256, format_string, tmp);
if(strcmp(user_specified_log_name, "") == 0) {
sprintf(buffer, "%s/%s_%lu.txt", prefix, c_time_string, num_logs++);
} else {
sprintf(buffer, "%s/%s_%lu.txt", prefix, user_specified_log_name, num_logs++);
}
return buffer;
}
\ 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