1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-21 15:46:06 +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)
# 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 $@
# Génération des fichiers objets

View file

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

View file

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

View file

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