1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-14 20:36:03 +01:00

Revamped debug interface

This commit is contained in:
Geoffrey Frogeye 2018-04-29 09:38:49 +02:00
parent b8f6d1e0bd
commit ad736b1a0e
7 changed files with 142 additions and 68 deletions

View file

@ -25,7 +25,7 @@ CFLAGS += -Wall -Wextra -pedantic -g -DDEBUG
# Génération des fichiers éxecutables # Génération des fichiers éxecutables
bin/%: obj/%.o bin/%: obj/%.o
$(CC) $(LDFLAGS_CUSTOM) $^ -o $@ $(CXX) $(LDFLAGS_CUSTOM) $^ -o $@
# On enlève les symboles inutiles pour gagner en temps de chargement de l'éxecutable # On enlève les symboles inutiles pour gagner en temps de chargement de l'éxecutable
ifeq ($(DEBUG),no) ifeq ($(DEBUG),no)
strip $@ strip $@
@ -34,13 +34,14 @@ endif
# RÈGLES DE COMPILATION # RÈGLES DE COMPILATION
# Règle éxecutée par défaut (quand on fait juste `make`) # Règle éxecutée par défaut (quand on fait juste `make`)
default: bin/testpin bin/premier bin/local default: bin/testpin bin/premier bin/local bin/testI2c bin/testLCD
# Binaires (dont il faut spécifier les objets explicitement) # Binaires (dont il faut spécifier les objets explicitement)
bin/premier: obj/CF.o obj/movement.o obj/debug.o obj/position.o bin/premier: obj/CF.o obj/movement.o obj/debug.o obj/position.o
bin/testPin: obj/testPin.o bin/testPin: obj/testPin.o
bin/testI2c: obj/testI2c.o obj/i2c.o obj/srf08.o obj/lcd.o
bin/local: obj/local.o obj/CF.o obj/position.o bin/local: obj/local.o obj/debug.o
$(CC) -lpthread $^ -o $@ $(CC) -lpthread $^ -o $@
# Génération des fichiers objets # Génération des fichiers objets

View file

@ -1,38 +1,64 @@
#include "debug.h"
#include <stdio.h>
#include <unistd.h> // sleep
#include <time.h>
#include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <unistd.h> // sleep
#include "position.h" #include "debug.h"
// Variables globales
pthread_t tDebug;
struct debugArg* listeDebugArgs = NULL;
FILE* debugFd;
void* TaskDebug(void* pdata) void* TaskDebug(void* pdata)
{ {
(void)pdata; (void)pdata;
clock_t debugStart;
debugStart = clock();
struct timespec tim; // 100 ms struct timespec tim; // 100 ms
tim.tv_sec = 0; tim.tv_sec = 0;
tim.tv_nsec = 100000000L; tim.tv_nsec = 100000000L;
/* tim.tv_sec = 1; */
/* tim.tv_nsec = 0; */
char line[1024]; fprintf(debugFd, "\n");
clock_t t;
for (;;) { for (;;) {
clock_t t = clock() - debugStart;
fprintf(debugFd, "%ld", t);
// Calculating time index struct debugArg* arg = listeDebugArgs;
t = clock() - debugStart; while (arg != NULL) {
switch (arg->type) {
case d:
fprintf(debugFd, ",%d", *((int*)arg->var));
break;
case ld:
fprintf(debugFd, ",%ld", *((long int*)arg->var));
break;
case f:
fprintf(debugFd, ",%f", *((float*)arg->var));
break;
case lf:
fprintf(debugFd, ",%f", *((double*)arg->var));
break;
case s:
fprintf(debugFd, ",%s", *((char**)arg->var));
break;
default:
fprintf(debugFd, ",?");
break;
}
// Generating line arg = arg->next;
sprintf(line, "%ld,%d,%ld,%ld\n", t, nbCalcPos, lCodTot, rCodTot); }
fprintf(debugFd, "\n");
// Writing
write(debugFd, line, strlen(line));
// Sleeping
nanosleep(&tim, NULL); nanosleep(&tim, NULL);
} }
@ -41,7 +67,6 @@ void* TaskDebug(void* pdata)
void configureDebug() void configureDebug()
{ {
debugStart = clock();
// Génération du nom de fichier // Génération du nom de fichier
char path[256]; char path[256];
@ -50,20 +75,41 @@ void configureDebug()
sprintf(path, "log/%ld.csv", startTime); sprintf(path, "log/%ld.csv", startTime);
// Open file // Open file
debugFd = open(path, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); debugFd = fopen(path, "w");
if (debugFd < 0) { if (debugFd == NULL) {
fprintf(stderr, "Impossible d'ouvrir le fichier '%s', debug désactivé.\n", path); perror("fopen debug file");
return; return;
} }
char header[] = "time,nbCalcPos,lCodTot,rCodTot\n"; fprintf(debugFd, "time");
write(debugFd, header, strlen(header)); }
void registerDebugVar(char* name, enum debugArgTypes type, void* var)
{
fprintf(debugFd, ",%s", name);
struct debugArg* arg = NULL;
struct debugArg** addrArg = &listeDebugArgs;
while (*addrArg != NULL) {
addrArg = &((*addrArg)->next);
}
arg = malloc(sizeof(struct debugArg));
arg->type = type;
arg->var = var;
arg->next = NULL;
*addrArg = arg;
}
void startDebug()
{
pthread_create(&tDebug, NULL, TaskDebug, NULL); pthread_create(&tDebug, NULL, TaskDebug, NULL);
} }
void deconfigureDebug() void deconfigureDebug()
{ {
pthread_cancel(tDebug); pthread_cancel(tDebug);
close(debugFd); fclose(debugFd);
// TODO Vider la liste des arguments
} }

View file

@ -4,13 +4,24 @@
#include <pthread.h> #include <pthread.h>
#include <time.h> #include <time.h>
clock_t debugStart;
int debugFd;
pthread_t tDebug; // Structures
enum debugArgTypes {d, f, ld, lf, s};
void* TaskDebug(void *pdata); struct debugArg {
void configureDebug(); enum debugArgTypes type;
void* var;
struct debugArg* next;
};
// Public
void configureDebug(); // Avant tous les configure
void registerDebugVar(char* name, enum debugArgTypes type, void* var);
void startDebug(); // Après tous les configure
void deconfigureDebug(); void deconfigureDebug();
// Private
void* TaskDebug(void *pdata);
#endif #endif

View file

@ -3,27 +3,34 @@
#include <pthread.h> #include <pthread.h>
#include <unistd.h> // sleep #include <unistd.h> // sleep
#include "CF.h" #include "debug.h"
#include "position.h"
#define TEMPSMAX 10 unsigned long int canard = 42;
double banane = 63;
char* artichaut = "Torticoli";
int main() int main()
{ {
printf("Démarrage...\n"); printf("Démarrage...\n");
configureCF();
configurePosition();
srand(time(NULL)); srand(time(NULL));
printf("C'est parti !\n"); configureDebug();
registerDebugVar("canard", ld, &canard);
registerDebugVar("banane", lf, &banane);
registerDebugVar("artichaut", s, &artichaut);
startDebug();
sleep(TEMPSMAX); for (int i = 0; i < 2; i++) {
printf("21 %d\n", i);
canard += 3;
banane /= 2;
sleep(1);
}
printf("Fin des %d secondes\n", TEMPSMAX); deconfigureDebug();
deconfigureCF();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -2,9 +2,22 @@
* Fonctions de calcul de la position du robot * Fonctions de calcul de la position du robot
*/ */
#include "position.h"
#include <stdio.h> #include <stdio.h>
#include "debug.h"
#include "position.h"
// Globales
struct position actuel;
struct F2CI_CODERs deltaCoders;
pthread_mutex_t posPolling;
pthread_t tPosition;
// Globales
unsigned int nbCalcPos;
long lCodTot, rCodTot;
void* TaskPosition(void* pData) void* TaskPosition(void* pData)
{ {
(void)pData; (void)pData;
@ -29,7 +42,6 @@ void* TaskPosition(void* pData)
nbCalcPos++; nbCalcPos++;
lCodTot += deltaCoders.dL; lCodTot += deltaCoders.dL;
rCodTot += deltaCoders.dR; rCodTot += deltaCoders.dR;
} }
return NULL; return NULL;
@ -43,8 +55,11 @@ void onF2CI_CODER()
void configurePosition() void configurePosition()
{ {
pthread_create(&tPosition, NULL, TaskPosition, NULL);
registerRxHandler(F2CI_CODER, onF2CI_CODER); registerRxHandler(F2CI_CODER, onF2CI_CODER);
registerDebugVar("lCodTot", ld, &lCodTot);
registerDebugVar("rCodTot", ld, &rCodTot);
registerDebugVar("nbCalcPos", d, &nbCalcPos);
pthread_create(&tPosition, NULL, TaskPosition, NULL);
} }
void deconfigurePosition() void deconfigurePosition()

View file

@ -9,23 +9,13 @@
#include <pthread.h> #include <pthread.h>
// Structures
struct __attribute__ ((packed)) position { struct __attribute__ ((packed)) position {
float x; float x;
float y; float y;
float o; float o;
}; };
struct position actuel;
struct F2CI_CODERs deltaCoders;
// Debug
unsigned int nbCalcPos;
long lCodTot, rCodTot;
//
pthread_mutex_t posPolling;
pthread_t tPosition;
// Fonctions // Fonctions
void configurePosition(); void configurePosition();
void deconfigurePosition(); void deconfigurePosition();

View file

@ -33,7 +33,7 @@ void* TaskParcours(void *pdata)
#define RAMP_TIME 100 #define RAMP_TIME 100
#define MAX_VIT MOT_MAX_V #define MAX_VIT MOT_MAX_V
for (;;) { /* for (;;) { */
// ↗ // ↗
for (int i = 0; i < RAMP_TIME; i++) { for (int i = 0; i < RAMP_TIME; i++) {
float p = (float) i / (float) RAMP_TIME; float p = (float) i / (float) RAMP_TIME;
@ -43,15 +43,15 @@ void* TaskParcours(void *pdata)
changerMoteurs(MOT_MAX_V, MOT_MAX_V); changerMoteurs(MOT_MAX_V, MOT_MAX_V);
// ↑ // ↑
sleep(2); sleep(2);
// ↘ /* // ↘ */
for (int i = 0; i < RAMP_TIME; i++) { /* for (int i = 0; i < RAMP_TIME; i++) { */
float p = (float) i / (float) RAMP_TIME; /* float p = (float) i / (float) RAMP_TIME; */
p = 1 - p; /* p = 1 - p; */
changerMoteurs(p * MOT_MAX_V, p * MOT_MAX_V); /* changerMoteurs(p * MOT_MAX_V, p * MOT_MAX_V); */
nanosleep(&tim, NULL); /* nanosleep(&tim, NULL); */
} /* } */
sleep(5); /* sleep(5); */
} /* } */
printf("Fin du parcours\n"); printf("Fin du parcours\n");
return NULL; return NULL;
@ -61,10 +61,11 @@ int main()
{ {
printf("Démarrage...\n"); printf("Démarrage...\n");
configureCF();
configureDebug(); configureDebug();
configureCF();
configureMovement(); configureMovement();
configurePosition(); configurePosition();
startDebug();
srand(time(NULL)); srand(time(NULL));
/* printf("En attente de la tirette...\n"); // TODO */ /* printf("En attente de la tirette...\n"); // TODO */
@ -78,12 +79,15 @@ int main()
printf("Fin des %d secondes\n", TEMPSMAX); printf("Fin des %d secondes\n", TEMPSMAX);
/* pthread_cancel(tParcours); */ /* pthread_cancel(tParcours); */
for (;;) {
}
/* stop(); */ /* stop(); */
deconfigureMovement(); deconfigureMovement();
deconfigurePosition(); deconfigurePosition();
deconfigureDebug();
deconfigureCF(); deconfigureCF();
deconfigureDebug();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }