2018-02-16 15:44:45 +01:00
|
|
|
#include "debug.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h> // sleep
|
2018-04-04 16:17:13 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "position.h"
|
|
|
|
|
2018-02-16 15:44:45 +01:00
|
|
|
|
|
|
|
void* TaskDebug(void* pdata)
|
|
|
|
{
|
|
|
|
(void)pdata;
|
2018-04-04 16:17:13 +02:00
|
|
|
struct timespec tim; // 100 ms
|
|
|
|
tim.tv_sec = 0;
|
|
|
|
tim.tv_nsec = 100000000L;
|
|
|
|
/* tim.tv_sec = 1; */
|
|
|
|
/* tim.tv_nsec = 0; */
|
|
|
|
|
|
|
|
char line[1024];
|
|
|
|
clock_t t;
|
2018-02-16 15:44:45 +01:00
|
|
|
|
|
|
|
for (;;) {
|
2018-04-04 16:17:13 +02:00
|
|
|
|
|
|
|
// Calculating time index
|
|
|
|
t = clock() - debugStart;
|
|
|
|
|
|
|
|
// Generating line
|
|
|
|
sprintf(line, "%ld,%d,%ld,%ld\n", t, nbCalcPos, lCodTot, rCodTot);
|
|
|
|
|
|
|
|
// Writing
|
|
|
|
write(debugFd, line, strlen(line));
|
|
|
|
|
|
|
|
// Sleeping
|
2018-02-16 15:44:45 +01:00
|
|
|
nanosleep(&tim, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-04 16:17:13 +02:00
|
|
|
void configureDebug()
|
2018-02-16 15:44:45 +01:00
|
|
|
{
|
2018-04-04 16:17:13 +02:00
|
|
|
debugStart = clock();
|
|
|
|
|
|
|
|
// Génération du nom de fichier
|
|
|
|
char path[256];
|
|
|
|
time_t startTime;
|
|
|
|
time(&startTime);
|
|
|
|
sprintf(path, "log/%ld.csv", startTime);
|
|
|
|
|
|
|
|
// Open file
|
|
|
|
debugFd = open(path, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
|
|
|
if (debugFd < 0) {
|
|
|
|
fprintf(stderr, "Impossible d'ouvrir le fichier '%s', debug désactivé.\n", path);
|
|
|
|
return;
|
2018-02-16 15:44:45 +01:00
|
|
|
}
|
|
|
|
|
2018-04-04 16:17:13 +02:00
|
|
|
char header[] = "time,nbCalcPos,lCodTot,rCodTot\n";
|
|
|
|
write(debugFd, header, strlen(header));
|
2018-02-16 15:44:45 +01:00
|
|
|
|
|
|
|
pthread_create(&tDebug, NULL, TaskDebug, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deconfigureDebug()
|
|
|
|
{
|
|
|
|
pthread_cancel(tDebug);
|
2018-04-04 16:17:13 +02:00
|
|
|
close(debugFd);
|
2018-02-16 15:44:45 +01:00
|
|
|
}
|