1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-05-03 12:46:43 +00:00

Diagnostics

This commit is contained in:
Geoffrey Frogeye 2018-05-01 14:51:41 +02:00
parent f6ef24e312
commit 69ceaba85e
7 changed files with 109 additions and 20 deletions

View file

@ -11,7 +11,7 @@ CFLAGS_CUSTOM += -g
## Générateurs de drapeaux pour les bibliothèques
PKG_CONFIG=pkg-config
## Nom des objets communs
OBJS=buttons CF debug i2c ihm lcd movement parcours points position
OBJS=buttons CF debug diagnostics i2c ihm lcd movement parcours points position
OBJS_O=$(addprefix obj/,$(addsuffix .o,$(OBJS)))
# VARIABLES AUTOMATIQUES

View file

@ -26,27 +26,49 @@ void configureFpga()
// Connection au port série
printf("Connexion à %s... ", FPGA_PORTNAME);
fflush(stdout);
fpga = open(FPGA_PORTNAME, O_RDWR | O_NOCTTY | O_NDELAY);
fpga = open(FPGA_PORTNAME, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
fpga = serialOpen(FPGA_PORTNAME, 9600);
if (fpga < 0) {
printf("Échec !\n");
exit(1);
}
// Configuration du port série
fcntl(fpga, F_SETFL, O_RDWR);
struct termios cfg;
bzero(&cfg, sizeof(cfg));
cfg.c_cflag = CLOCAL | CREAD | CF_BAUDRATE | CS8;
cfg.c_iflag = 0;
cfg.c_oflag = 0;
cfg.c_lflag = 0; /* set input mode (non-canonical, no echo,...) */
cfg.c_cc[VTIME] = 0; /* inter-character timer unused */
cfg.c_cc[VMIN] = 1; /* blocking read until 1 char received */
tcgetattr(fpga, &cfg);
cfmakeraw(&cfg);
cfsetispeed(&cfg, CF_BAUDRATE);
cfsetospeed(&cfg, CF_BAUDRATE);
cfg.c_cflag |= (CLOCAL | CREAD);
cfg.c_cflag &= ~PARENB;
cfg.c_cflag &= ~CSTOPB;
cfg.c_cflag &= ~CSIZE;
cfg.c_cflag |= CS8;
cfg.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
cfg.c_oflag &= ~OPOST;
cfg.c_cc[VMIN] = 0;
cfg.c_cc[VTIME] = 10;
if (tcsetattr(fpga, TCSANOW, &cfg) < 0) {
perror("serialConfig.tcsetattr");
exit(1);
}
sleep(1);
int status;
ioctl(fpga, TIOCMGET, &status);
status |= TIOCM_DTR;
status |= TIOCM_RTS;
ioctl(fpga, TIOCMSET, &status);
usleep(10 * 1000);
// Flush
unsigned char trash[1024];
@ -101,7 +123,6 @@ void setPret()
void doNothing()
{
}
void configureCF()
@ -116,16 +137,13 @@ void configureCF()
printf("Attente de réponse du Fpga... ");
fflush(stdout);
struct timespec tim;
tim.tv_sec = 0;
tim.tv_nsec = 100000000L;
// Dans le cas où on aurait laissé l'Fpga en attente de donnée,
// on envoie des pings en boucle jusqu'à ce qu'il nous réponde.
pret = false;
registerRxHandler(C2FD_PING, setPret);
while (!pret) {
sendCF(C2FD_PING, NULL, 0);
nanosleep(&tim, NULL);
usleep(100 * 1000);
}
registerRxHandler(C2FD_PING, doNothing); // TODO
registerRxHandler(C2FD_PING, NULL);

View file

@ -6,7 +6,6 @@
#include <string.h>
#include <time.h>
#include <unistd.h> // sleep
#include <wiringPi.h>
#include "debug.h"
@ -91,7 +90,7 @@ void* TaskDebug(void* pdata)
fprintf(debugFd, "\n");
fflush(debugFd);
delay(DEBUG_INTERVAL);
usleep(DEBUG_INTERVAL * 1000);
}
return NULL;

56
chef/src/diagnostics.c Normal file
View file

@ -0,0 +1,56 @@
#include <unistd.h>
#include "diagnostics.h"
#include "buttons.h"
#include "lcd.h"
#include "CF.h"
bool recu;
void setRecu()
{
recu = true;
}
bool diagFPGA()
{
recu = false;
registerRxHandler(C2FD_PING, setRecu);
sendCF(C2FD_PING, NULL, 0);
for (int i = 0; i <= DIAGNOSTIC_SERIAL_TIMEOUT; i += DIAGNOSTIC_POLL_INTERVAL) {
if (recu) {
break;
}
usleep(DIAGNOSTIC_POLL_INTERVAL * 1000);
}
return recu;
}
bool diagArduino()
{
return false;
}
void execDiagnostic(char *name, bool (*diagnostic)(void))
{
clearLCD();
printToLCD(LCD_LINE_1, name);
printToLCD(LCD_LINE_2, "...");
bool res = diagnostic();
if (res) {
printToLCD(LCD_LINE_2, "Ok!");
usleep(DIAGNOSTIC_INTERVAL * 1000);
} else {
printToLCD(LCD_LINE_2, "Echec!");
pressedButton(BUT_BLOCK);
}
}
void runDiagnostics()
{
execDiagnostic("Lien FPGA", diagFPGA);
/* execDiagnostic("Lien Arduino", diagArduino); */
}

17
chef/src/diagnostics.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef __DIAGNOSTICS_H_
#define __DIAGNOSTICS_H_
#include <stdbool.h>
// Constantes
#define DIAGNOSTIC_INTERVAL 500
#define DIAGNOSTIC_POLL_INTERVAL 100
#define DIAGNOSTIC_SERIAL_TIMEOUT 10000
// Public
void runDiagnostics();
// Private
void execDiagnostic(char *name, bool (*diagnostic)(void));
#endif

View file

@ -8,6 +8,7 @@
#include "points.h"
#include "lcd.h"
#include "buttons.h"
#include "diagnostics.h"
// Globales
pthread_t tIHM;
@ -117,8 +118,7 @@ void* TaskIHM(void* pdata)
if (bout == rouge) {
clearLCD();
printToLCD(LCD_LINE_1, "Diagnostics...");
delay(3000); // TODO
runDiagnostics();
} else if (bout == jaune) {
break;
}

View file

@ -40,7 +40,6 @@ NET "BACKECHO" LOC = "P73" | IOSTANDARD = LVTTL ;
# IO<20>
NET "ENA" LOC = "P5" | IOSTANDARD = LVTTL ;
# IO<21>
NET "IN1ENC" LOC = "P4" | IOSTANDARD = LVTTL ;