Something went wrong on our end
logger.c 1.29 KiB
/* Author: Kris Burney
*
* Logger file for holding functions pertaining to loging to a file.
*/
#include "logger.h"
#include <stdio.h>
int quadlog_file;
int createLogFile(int argc, char* argv)
{
char log_file[300] = {'l', 'o', 'g','s', '/'};
if(argc >= 2)
{
strcat(log_file, argv);
printf("Creating log file '%s'...\n",log_file);
quadlog_file = open(log_file, O_WRONLY | O_CREAT, 0666);
return quadlog_file;
}
else
{
time_t rawtime;
char timestr [30];
time(&rawtime);
sprintf(timestr,"%s",ctime(&rawtime));
// Lets convert space to _ in
char *p = timestr;
int 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 = open(log_file, O_WRONLY | O_CREAT, 0666);
return quadlog_file;
}
}
int updateLogFile(const struct ucart_vrpn_TrackerData * td)
{
return dprintf(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);
}
int writeStringToLog(const char * string)
{
return dprintf(quadlog_file, "%s", string);
}