diff --git a/Log.c b/Log.c index 0447db2..ca1e251 100644 --- a/Log.c +++ b/Log.c @@ -6,7 +6,7 @@ struct log_message_storage{ struct Log_message_data message; struct log_message_storage * next; -} * log_message_storage_envoi, log_message_storage_premier, *log_message_storage_courant; +} * log_message_envoi, log_message_storage_premier, *log_message_storage_courant; uint log_error = 0; @@ -20,7 +20,7 @@ void Log_init(void){ log_message_storage_premier.next = NULL; log_message_storage_courant = &log_message_storage_premier; - log_message_storage_envoi = &log_message_storage_premier; + log_message_envoi = &log_message_storage_premier; } @@ -55,11 +55,11 @@ void Log_message(char * message, enum Log_level log_level){ /// @brief Read messages in cache, store them and send them through the serial connection void Log_gestion(){ // Envoi 1 message par la liaison série - if(log_message_storage_envoi->next != NULL){ - log_message_storage_envoi = log_message_storage_envoi->next; - envoi_message(log_message_storage_envoi->message); + if(log_message_envoi->next != NULL){ + log_message_envoi = log_message_envoi->next; + envoi_message(log_message_envoi->message); // Si on est à la fin des messages, en envoie le statut de la fonction Log - if(log_message_storage_envoi->next == NULL){ + if(log_message_envoi->next == NULL){ if(log_error & LOG_ERROR_MEMORY_FULL){ printf("LOG ERROR : Memoire pleine !\n"); } @@ -67,6 +67,11 @@ void Log_gestion(){ } } +/// @brief Renvoie l'intégralité du journal de log. La fonction Log_gestion() doit être appelée continuellement pour que cette fonction fonctionne. +void Log_get_full_log(){ + log_message_envoi = &log_message_storage_premier; +} + void envoi_message(struct Log_message_data message){ printf("%u ms:%s\n", message.timestamp, message.message); } diff --git a/Log.h b/Log.h index 303bdc3..b856705 100644 --- a/Log.h +++ b/Log.h @@ -3,7 +3,6 @@ #define LOG_MAX_MESSAGE_SIZE 64 #define LOG_ERROR_MEMORY_FULL 1 -#define LOG_ERROR_CACHE_OVERFLOW 2 enum Log_level{ TELEPLOT, TRACE, DEBUG, INFO, WARN, ERROR, FATAL @@ -17,4 +16,5 @@ struct Log_message_data{ void Log_init(void); void Log_gestion(void); -void Log_message(char * message, enum Log_level log_level); \ No newline at end of file +void Log_message(char * message, enum Log_level log_level); +void Log_get_full_log(); \ No newline at end of file diff --git a/Test_log.c b/Test_log.c index 45207b4..5bb8922 100644 --- a/Test_log.c +++ b/Test_log.c @@ -28,6 +28,7 @@ int test_log(void){ printf("A : 1 message\n"); printf("B : 9 messages d'affilés\n"); printf("C : 100 messages à 100 µs d'intervalle\n"); + printf("D : Récupération du log stocké\n"); printf("Q : Quitter\n"); lettre = getchar_timeout_us(TEST_TIMEOUT_US); stdio_flush(); @@ -46,7 +47,7 @@ int test_log(void){ case 'b': printf("B : 9 messages d'affilés\n"); for(int i=0; i<9; i++){ - sprintf(message, "Test message %d/9", i); + sprintf(message, "Test message %d/9", i+1); Log_message(message, DEBUG); } break; @@ -55,12 +56,18 @@ int test_log(void){ case 'c': printf("C : 100 messages à 100 µs d'intervalle\n"); for(int i=0; i<100; i++){ - sprintf(message, "Test message %d/100", i); + sprintf(message, "Test message %d/100", i+1); Log_message(message, DEBUG); sleep_us(100); } break; + case 'D': + case 'd': + printf("D : Récupération du log stocké\n"); + Log_get_full_log(); + break; + case 'Q': case 'q': printf("Q : Quitter\n");