1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-21 23:56:04 +01:00

Debug filename changed

This commit is contained in:
Geoffrey Frogeye 2018-05-01 13:34:05 +02:00
parent f3c90fad06
commit f6ef24e312
4 changed files with 77 additions and 44 deletions

View file

@ -40,7 +40,7 @@ bin/premier: obj/premier.o $(OBJS_O)
bin/test%: obj/test%.o $(OBJS_O) bin/test%: obj/test%.o $(OBJS_O)
# Programme de test sur PC, n'embarquant pas wiringPi # Programme de test sur PC, n'embarquant pas wiringPi
bin/local: obj/local.o obj/debug.o bin/local: obj/local.o
$(CC) $(CFLAGS) $(CFLAGS_CUSTOM) -lpthread $^ -o $@ $(CC) $(CFLAGS) $(CFLAGS_CUSTOM) -lpthread $^ -o $@
# Génération des fichiers objets # Génération des fichiers objets

View file

@ -1,3 +1,4 @@
#include <dirent.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
@ -5,6 +6,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h> // sleep #include <unistd.h> // sleep
#include <wiringPi.h>
#include "debug.h" #include "debug.h"
@ -15,22 +17,51 @@ struct debugArg* listeDebugArgs = NULL;
FILE* debugFd; FILE* debugFd;
int nextId()
{
DIR* d;
struct dirent* dir;
d = opendir("log");
int maxId = 0, id, ret;
if (d) {
while ((dir = readdir(d)) != NULL) {
ret = sscanf(dir->d_name, "%d", &id);
if (ret == 1 && id > maxId) {
maxId = id;
}
}
closedir(d);
}
return maxId + 1;
}
struct timespec debugStart;
struct timespec debugNow;
struct timespec debugEcoule;
void* TaskDebug(void* pdata) void* TaskDebug(void* pdata)
{ {
(void)pdata; (void)pdata;
clock_t debugStart; if (DEBUG_INTERVAL <= 0) {
debugStart = clock(); // TODO struct timespec return NULL;
}
struct timespec tim; // 100 ms clock_gettime(CLOCK_REALTIME, &debugStart);
tim.tv_sec = 0;
tim.tv_nsec = 100000000L;
fprintf(debugFd, "\n"); fprintf(debugFd, "\n");
for (;;) { for (;;) {
clock_t t = clock() - debugStart; clock_gettime(CLOCK_REALTIME, &debugNow);
fprintf(debugFd, "%ld", t); if ((debugNow.tv_nsec - debugStart.tv_nsec) < 0) {
debugEcoule.tv_sec = debugNow.tv_sec - debugStart.tv_sec - 1;
debugEcoule.tv_nsec = debugNow.tv_nsec - debugStart.tv_nsec + 1000000000UL;
} else {
debugEcoule.tv_sec = debugNow.tv_sec - debugStart.tv_sec;
debugEcoule.tv_nsec = debugNow.tv_nsec - debugStart.tv_nsec;
}
fprintf(debugFd, "%ld.%09ld", debugEcoule.tv_sec, debugEcoule.tv_nsec);
struct debugArg* arg = listeDebugArgs; struct debugArg* arg = listeDebugArgs;
while (arg != NULL) { while (arg != NULL) {
@ -58,8 +89,9 @@ void* TaskDebug(void* pdata)
arg = arg->next; arg = arg->next;
} }
fprintf(debugFd, "\n"); fprintf(debugFd, "\n");
fflush(debugFd);
nanosleep(&tim, NULL); delay(DEBUG_INTERVAL);
} }
return NULL; return NULL;
@ -70,9 +102,7 @@ void configureDebug()
// Génération du nom de fichier // Génération du nom de fichier
char path[256]; char path[256];
time_t startTime; sprintf(path, "log/%d.csv", nextId());
time(&startTime);
sprintf(path, "log/%ld.csv", startTime);
// Open file // Open file
debugFd = fopen(path, "w"); debugFd = fopen(path, "w");

View file

@ -4,6 +4,9 @@
#include <pthread.h> #include <pthread.h>
#include <time.h> #include <time.h>
// Constantes
#define DEBUG_INTERVAL 100
// Structures // Structures
enum debugArgTypes {d, f, ld, lf, s}; enum debugArgTypes {d, f, ld, lf, s};

View file

@ -25,22 +25,9 @@ void startIHM()
pthread_create(&tIHM, NULL, TaskIHM, NULL); pthread_create(&tIHM, NULL, TaskIHM, NULL);
} }
// t1 - t2
void diffTimespec(const struct timespec* t1, const struct timespec* t2, struct timespec* td)
{
if ((t1->tv_nsec - t2->tv_nsec) < 0) {
td->tv_sec = t1->tv_sec - t2->tv_sec - 1;
td->tv_nsec = t1->tv_nsec - t2->tv_nsec + 1000000000UL;
} else {
td->tv_sec = t1->tv_sec - t2->tv_sec;
td->tv_nsec = t1->tv_nsec - t2->tv_nsec;
}
}
bool isDebug = false; bool isDebug = false;
bool isOrange = true; bool isOrange = true;
bool annuler = false; bool annuler = false;
clock_t lastCalibrage = 0;
pthread_t tParcours; pthread_t tParcours;
char* orangeStr = "Orange"; char* orangeStr = "Orange";
@ -51,6 +38,10 @@ char* getCouleur()
return isOrange ? orangeStr : vertStr; return isOrange ? orangeStr : vertStr;
} }
struct timespec calibrageLast = {0, 0};
struct timespec calibrageNow;
struct timespec calibrageEcoule;
void* TaskIHM(void* pdata) void* TaskIHM(void* pdata)
{ {
(void)pdata; (void)pdata;
@ -58,21 +49,21 @@ void* TaskIHM(void* pdata)
enum boutons bout; enum boutons bout;
for (;;) { for (;;) {
// Debug /* // Debug */
for (;;) { /* for (;;) { */
clearLCD(); /* clearLCD(); */
printfToLCD(LCD_LINE_1, "Debug : %s", isDebug ? "On" : "Off"); /* printfToLCD(LCD_LINE_1, "Debug : %s", isDebug ? "On" : "Off"); */
if (isDebug) { /* if (isDebug) { */
printToLCD(LCD_LINE_2, "192.168.0.0 TODO"); /* printToLCD(LCD_LINE_2, "192.168.0.0 TODO"); */
} /* } */
bout = pressedButton(BUT_REFRESH_INTERVAL); /* bout = pressedButton(BUT_REFRESH_INTERVAL); */
/* */
if (bout == rouge) { /* if (bout == rouge) { */
isDebug = !isDebug; /* isDebug = !isDebug; */
} else if (bout == jaune) { /* } else if (bout == jaune) { */
break; /* break; */
} /* } */
} /* } */
// Couleur // Couleur
for (;;) { for (;;) {
@ -90,9 +81,18 @@ void* TaskIHM(void* pdata)
// Calibrage // Calibrage
for (;;) { for (;;) {
clearLCD(); clearLCD();
if (lastCalibrage != 0) { printf("84 %ld\n", calibrageLast.tv_sec);
if (calibrageLast.tv_sec > 0) {
clock_gettime(CLOCK_REALTIME, &calibrageNow);
if ((calibrageNow.tv_nsec - calibrageLast.tv_nsec) > 0) {
calibrageEcoule.tv_sec = calibrageNow.tv_sec - calibrageLast.tv_sec - 1;
calibrageEcoule.tv_nsec = calibrageNow.tv_nsec - calibrageLast.tv_nsec + 1000000000UL;
} else {
calibrageEcoule.tv_sec = calibrageNow.tv_sec - calibrageLast.tv_sec;
calibrageEcoule.tv_nsec = calibrageNow.tv_nsec - calibrageLast.tv_nsec;
}
printToLCD(LCD_LINE_1, "Calibre il y a"); printToLCD(LCD_LINE_1, "Calibre il y a");
printfToLCD(LCD_LINE_2, "%ld secondes", (clock() - lastCalibrage) / CLOCKS_PER_SEC); printfToLCD(LCD_LINE_2, "%ld secondes", calibrageEcoule.tv_sec);
} else { } else {
printToLCD(LCD_LINE_1, "Calibrer"); printToLCD(LCD_LINE_1, "Calibrer");
printfToLCD(LCD_LINE_2, "(%s)", getCouleur()); printfToLCD(LCD_LINE_2, "(%s)", getCouleur());
@ -103,7 +103,7 @@ void* TaskIHM(void* pdata)
clearLCD(); clearLCD();
printToLCD(LCD_LINE_1, "Calibrage..."); printToLCD(LCD_LINE_1, "Calibrage...");
delay(3000); // TODO delay(3000); // TODO
lastCalibrage = clock(); // TODO struct timespec clock_gettime(CLOCK_REALTIME, &calibrageLast);
} else if (bout == jaune) { } else if (bout == jaune) {
break; break;
} }