forked from alvmon02/SO_Progetto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DESCRIZIONE: Aggiornati i componenti windshield-camera e foward-facing-radar secondo le specifiche, aggiunto documento con regole di struttura, strutturati processi di hmi (in e out)
- Loading branch information
Showing
11 changed files
with
203 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
PROCESSO PADRE: | ||
CENTRAL-ECU | ||
Questo processo INIZIALIZZERÀ IL SISTEMA, creando tutti i PIPE precedentemente alle chiamate dei processi figli. | ||
|
||
Il SERVER-SOCKET sarà creato dal sensore PARK-ASSIST al momento del bisogno. (Questo rallenterebbe l'attivazione di park assist, volendo potremmo creare il server-socket in central ECU e far si che park-assist si connetta come client una volta che si attiva, procedura più veloce. Comunque l'attivazione di park assist minimamente più lenta non dovrebbe essere un problema, ma gestendolo come facciamo per i pipe forse si genera meno confusione.) | ||
|
||
|
||
ATTUATORI: | ||
STEER...-> 1 volta al secondo controlla il pipe non bloccante e scrive nel log di conseguenza | ||
THRO.. e BRAKE.. -> attendono sulla read del pipe (quindi bloccante) di ricevere messaggi dalla ECU. La ECU dovrà gestire la sincronizzazione (inviare una volta al sec) | ||
|
||
SENSORI: | ||
WINDSHIELD..-> 1 volta al secondo legge e invia dati sul pipe bloccante (sola scrittura). La lettura dei dati da parte della ECU dovrà essere immediata e possibilmente supponendo che nel pipe ci siano già più di un solo dato (getline()?) | ||
FOWARD...-> 1 volta al secondo legge i dati da urandom, se legge 8 byte allora li invia tramite pipe bloccante (sola lettura) alla ECU che dovrà leggerli immediatamente. I dati inviati alla ECU saranno loggati, gli altri no. | ||
|
||
|
||
NOMI DEI FILE DI LOG: | ||
-steer.log | ||
-throttle.log | ||
-brake.log | ||
-camera.log (windshield camera) | ||
-radar.log (foward facing radar) | ||
-assist.log (park assist) | ||
-cameras.log (surround view cameras) | ||
|
||
NOMI DEI FILE TEMPORANEI: | ||
|
||
PIPE: | ||
-steer.pipe | ||
-throttle.pipe | ||
-brake.pipe | ||
-camera.pipe | ||
-radar.pipe | ||
-cameras.pipe | ||
-hmi-in.pipe | ||
-hmi-out.pipe | ||
|
||
SOCK: | ||
-assist.sock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#define _GNU_SOURCE | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
|
||
#define OUTPUT_MAX_LEN 11 | ||
|
||
int main() { | ||
|
||
int pipe_fd = open("../tmp/hmi-in.pipe", O_WRONLY); | ||
|
||
char * ECU_output = malloc(OUTPUT_MAX_LEN); | ||
int nread; | ||
|
||
printf("TERMINALE DI INPUT\n\n"); | ||
printf("Inserire una delle seguenti parole e premere invio:\n" | ||
"INIZIO\n" | ||
"PARCHEGGIO\n" | ||
"ARRESTO\n"); | ||
|
||
while(1){ | ||
scanf("%s", ECU_output); | ||
if(strcasecmp(ECU_output, "PARCHEGGIO\n") | ||
|| strcasecmp(ECU_output,"INIZIO\n") | ||
|| strcasecmp(ECU_output, "ARRESTO\n") ) | ||
write(pipe_fd, &ECU_output, OUTPUT_MAX_LEN); | ||
else { | ||
printf("Digitazione del comando errata, inserire una " | ||
"delle seguenti parole e premere invio:\n" | ||
"INIZIO\n" | ||
"PARCHEGGIO\n" | ||
"ARRESTO\n"); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
|
||
#define INPUT_MAX_LEN 13 | ||
|
||
int main() { | ||
|
||
int pipe_fd = open("../tmp/hmi-out.pipe", O_RDONLY); | ||
|
||
char * ECU_input = malloc(INPUT_MAX_LEN); | ||
int nread; | ||
|
||
printf("TERMINALE DI OUTPUT\n\n"); | ||
while(1) | ||
if((nread = read(pipe_fd, ECU_input, INPUT_MAX_LEN)) > 0 ) | ||
printf("%s", ECU_input); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,53 @@ | ||
#include <error.h> /*per funzione perror*/ | ||
#include <fcntl.h> /*per open*/ | ||
#include <signal.h> /*per la funzione kill*/ | ||
#include <stdio.h> /*per sprintf*/ | ||
#include <stdlib.h> /*per funzione exit*/ | ||
#include <sys/stat.h> /*per mknod (sys call per mkfifo)*/ | ||
#include <sys/types.h> /*per mkfifo*/ | ||
#include <time.h> /*per le funzioni e le strutture relative a time, vedi | ||
logging( ) */ | ||
#include <unistd.h> /*per sistem calls e pipe*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include "../../include/service-functions.h" | ||
|
||
// MACROS | ||
// INPUT_MAX_LEN: lunghezza massima della stringa proveniente dal file di | ||
// input: "PARCHEGGIO\0" | ||
#define INPUT_MAX_LEN 11 | ||
|
||
// File descriptor del log file | ||
short int log_fd; | ||
// File descriptor del pipe in scrittura | ||
short int pipe_fd; | ||
|
||
void broadcast_input(char [], int); | ||
void log_func(char *, int); | ||
|
||
int main() { // COMMENTI DA CAMBIARE TUTTI! | ||
|
||
unlink("../tmp/camera.pipe"); | ||
mkfifo("../tmp/camera.pipe", 0600); | ||
//La funzione main esegue le operazioni relative al componente windshield-camera | ||
int main ( ) { | ||
|
||
// Connessione del file descriptor del pipe per la comunicazione tra central | ||
// ECU e windshield-camera. Il protocollo impone che il pipe sia creato | ||
// durante la fase di inizializzazione del processo central-ECU e che venga | ||
// aperto in sola scrittura dal processo windshield-camera il quale vi scriva | ||
// una volta al secondo. | ||
pipe_fd = open("../tmp/camera.pipe", O_WRONLY); | ||
// Connessione del file descriptor del log file. Apertura in sola scrittura. | ||
// Qualora il file non esista viene creato. Qualora il file sia presente | ||
// si mantengono le precedenti scritture. Data l'esecuzione dell'unlink | ||
// da parte della central-ECU, non vi saranno scritture pendenti da | ||
// precedenti esecuzioni. | ||
log_fd = open("../log/camera.log", O_WRONLY | O_APPEND | O_CREAT, 0644); | ||
|
||
FILE *input_file = fopen("../include/frontCamera.data", "r"); | ||
|
||
// Connessione del file descriptor al file da cui ottenere i dati di input. | ||
// Apertura in sola lettura all'inizio del file. | ||
FILE *input_file = fopen("../include/frontCamera.data", "r"); | ||
// Inizializzazione della stringa di input che rappresenta il messaggio da | ||
// trasmettere alla central-ECU da parte del processo. | ||
char *camera_input = malloc(INPUT_MAX_LEN); | ||
size_t input_len; | ||
int nread; | ||
|
||
while (1) { | ||
if ((nread = getline(&camera_input, &input_len, input_file)) > 0) { | ||
/*stringa | ||
massima: "PARCHEGGIO\0"*/ | ||
broadcast_input(camera_input, input_len); | ||
log_func(camera_input, input_len); | ||
} | ||
// Il ciclo successivo rappresenta il cuore del processo. | ||
// Ad ogni lettura del file di input accadrà che il file non ha | ||
// raggiunto ancora la terminazione, ad eccezione dell'ultima lettura | ||
// nella quale verrà ottenuta una stringa EOF, quindi nread = 0. | ||
// Fintantoché il file non termina i dati vengono trasmessi alla | ||
// central-ECU, una volta terminato il processo termina con codice | ||
// EOF (=0). | ||
while ((nread = getline(&camera_input, &input_len, input_file)) > 0) { | ||
broad_log(pipe_fd, log_fd, camera_input, input_len); | ||
sleep(1); | ||
} | ||
} | ||
|
||
void broadcast_input(char message[], int size) { | ||
write(pipe_fd, &message, size); /*i caratteri contati nel caso della funzione | ||
getline sono comprensivi del \n o del EOF, quindi size comprende anche questi | ||
caratteri*/ | ||
return; | ||
} | ||
|
||
void log_func(char *log_phrase, int size) { | ||
write(log_fd, log_phrase, size); | ||
return; | ||
exit(EOF); | ||
} |
Oops, something went wrong.